feat(attendies): New view and backend
Add an importer for special events with a role selection
This commit is contained in:
parent
8206d16be0
commit
beeb22dc42
6 changed files with 172 additions and 14 deletions
|
@ -75,7 +75,7 @@ func PostPretixRoleProduct(c *fiber.Ctx) error {
|
||||||
func PostPretixRegularsTable(c *fiber.Ctx) error {
|
func PostPretixRegularsTable(c *fiber.Ctx) error {
|
||||||
data := new(entities.Pretix_Webhook)
|
data := new(entities.Pretix_Webhook)
|
||||||
if err := c.BodyParser(data); err != nil {
|
if err := c.BodyParser(data); err != nil {
|
||||||
return c.Status(fiber.ErrBadGateway.Code).SendString(err.Error())
|
return c.Status(fiber.ErrBadRequest.Code).SendString(err.Error())
|
||||||
}
|
}
|
||||||
pretixOrders, err := getAllPretixOrders(&data.Organizer, &data.Event)
|
pretixOrders, err := getAllPretixOrders(&data.Organizer, &data.Event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -103,6 +103,40 @@ func PostPretixRegularsTable(c *fiber.Ctx) error {
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PostPretixSpecialEventWithRoles(c *fiber.Ctx) error {
|
||||||
|
data := new(entities.Pretix_Webhook)
|
||||||
|
if err := c.BodyParser(data); err != nil {
|
||||||
|
return c.Status(fiber.ErrBadRequest.Code).SendString(err.Error())
|
||||||
|
}
|
||||||
|
pretixOrders, err := getAllPretixOrders(&data.Organizer, &data.Event)
|
||||||
|
if err != nil {
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
event, err := service.Get_db_event_by_event(data.Event)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusNotFound).SendString("Event not found")
|
||||||
|
}
|
||||||
|
attendies, err := util.GetAttendiesFromPretixJsonWithRoleQuestionNoSubproducts(
|
||||||
|
pretixOrders,
|
||||||
|
&event,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
if err := service.DeleteAttendiesByEvent(event); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
for _, attendie := range attendies {
|
||||||
|
if err := service.CreateNewAttendie(attendie); err != nil {
|
||||||
|
fmt.Print(err)
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
func getAllPretixOrders(organizer, event *string) (*entities.Pretix_Event, error) {
|
func getAllPretixOrders(organizer, event *string) (*entities.Pretix_Event, error) {
|
||||||
pretixOrders, err := util.GetPretixOrders(organizer, event)
|
pretixOrders, err := util.GetPretixOrders(organizer, event)
|
||||||
for link := pretixOrders.Next; link != nil; {
|
for link := pretixOrders.Next; link != nil; {
|
||||||
|
|
|
@ -15,6 +15,7 @@ func PublicRoutes(app *fiber.App) {
|
||||||
webhooks.Post("/pretix/role_question", controller.PostPretixRoleQuestion)
|
webhooks.Post("/pretix/role_question", controller.PostPretixRoleQuestion)
|
||||||
webhooks.Post("/pretix/role_product", controller.PostPretixRoleProduct)
|
webhooks.Post("/pretix/role_product", controller.PostPretixRoleProduct)
|
||||||
webhooks.Post("/pretix/subproduct", controller.PostPretixRegularsTable)
|
webhooks.Post("/pretix/subproduct", controller.PostPretixRegularsTable)
|
||||||
|
webhooks.Post("pretix/speicalEventRoles", controller.PostPretixSpecialEventWithRoles)
|
||||||
apiv1.Post("/login", controller.LoginUser)
|
apiv1.Post("/login", controller.LoginUser)
|
||||||
apiv1.Get("/event", controller.ReturnAllEventsPublic)
|
apiv1.Get("/event", controller.ReturnAllEventsPublic)
|
||||||
apiv1.Get("/ping", controller.Ping)
|
apiv1.Get("/ping", controller.Ping)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"ulmer-furs.de/pretix-proxy/v2/config"
|
"ulmer-furs.de/pretix-proxy/v2/config"
|
||||||
|
@ -55,11 +54,6 @@ func GetAttendiesByEventPrivacy(event entities.Db_Event, privacy bool) (entities
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateNewAttendie(attendie entities.Db_Attendies) error {
|
func CreateNewAttendie(attendie entities.Db_Attendies) error {
|
||||||
if attendie.Privacy {
|
|
||||||
fmt.Println("Privacy activated")
|
|
||||||
} else {
|
|
||||||
fmt.Println("Noone needs privacy")
|
|
||||||
}
|
|
||||||
result := config.Database.Create(&attendie)
|
result := config.Database.Create(&attendie)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
|
|
|
@ -250,20 +250,80 @@ func GetAttendiesFromPretixJsonWithSeperateSubProducts(pretixEvent *entities.Pre
|
||||||
}
|
}
|
||||||
indexName := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
|
indexName := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
|
||||||
indexPrivacy := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdPrivacy })
|
indexPrivacy := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdPrivacy })
|
||||||
|
attendie.RegistrationTime = order.Datetime
|
||||||
attendie.Nickname = order.Positions[indexParticipation].Answers[indexName].Answer
|
attendie.Nickname = order.Positions[indexParticipation].Answers[indexName].Answer
|
||||||
var err error
|
var err error
|
||||||
attendie.Privacy, err = strconv.ParseBool(order.Positions[indexParticipation].Answers[indexPrivacy].Answer)
|
attendie.Privacy, err = strconv.ParseBool(order.Positions[indexParticipation].Answers[indexPrivacy].Answer)
|
||||||
if attendie.Privacy {
|
|
||||||
fmt.Println("Yey, privacy")
|
|
||||||
} else {
|
|
||||||
fmt.Println("no privacy")
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return attendies, err
|
return attendies, err
|
||||||
}
|
}
|
||||||
attendies = append(attendies, attendie)
|
attendies = append(attendies, attendie)
|
||||||
}
|
}
|
||||||
fmt.Printf("%+v", attendies)
|
|
||||||
return attendies, nil
|
return attendies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAttendiesFromPretixJsonWithRoleQuestionNoSubproducts(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) (entities.AttendiesList, error) {
|
||||||
|
var attendies entities.AttendiesList
|
||||||
|
for _, order := range pretixEvent.Results {
|
||||||
|
if order.Status == "c" || order.Status == "e" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var attendie entities.Db_Attendies
|
||||||
|
attendie.Event = event
|
||||||
|
if event.ItemIdParticipation == nil {
|
||||||
|
return attendies, errors.New("event has no ItemIdParticipation")
|
||||||
|
}
|
||||||
|
indexParticipation := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdParticipation })
|
||||||
|
|
||||||
|
indexName := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
|
||||||
|
indexPrivacy := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdPrivacy })
|
||||||
|
indexRole := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdRole })
|
||||||
|
attendie.Nickname = getAttendieNickname(&order, &indexName, &indexParticipation)
|
||||||
|
attendieRole, err := getAttendieRole(&order, event, &indexRole, &indexParticipation)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
attendie.Role = attendieRole
|
||||||
|
attendie.RegistrationTime = order.Datetime
|
||||||
|
privacy, err := getAttendiePrivacy(&order, &indexPrivacy, &indexParticipation)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
attendie.Privacy = privacy
|
||||||
|
attendies = append(attendies, attendie)
|
||||||
|
}
|
||||||
|
_, spotter, suiter, _, specialAnimal := GetRoles()
|
||||||
|
sort.Sort(entities.ByRegistrationTime(attendies))
|
||||||
|
if *event.SuiterPerSpotter != -1 {
|
||||||
|
MarkWatingListAttendies(&attendies, (*event).SuiterPerSpotter, suiter, spotter, specialAnimal)
|
||||||
|
}
|
||||||
|
return attendies, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAttendieRole(order *entities.Pretix_Result, event *entities.Db_Event, indexRole, indexParticipation *int) (*entities.Role, error) {
|
||||||
|
roleAnswer := order.Positions[*indexParticipation].Answers[*indexRole].OptionIdentifiers
|
||||||
|
if slices.Contains(roleAnswer, *event.OptionIdSuiter) {
|
||||||
|
return service.GetRoleByName("Suiter")
|
||||||
|
} else if slices.Contains(roleAnswer, *event.OptionIdSpotter) {
|
||||||
|
return service.GetRoleByName("Spotter")
|
||||||
|
} else if slices.Contains(roleAnswer, *event.OptionIdPhotograph) {
|
||||||
|
return service.GetRoleByName("Photograph")
|
||||||
|
} else if slices.Contains(roleAnswer, *event.OptionIdSpecialAnimal) {
|
||||||
|
return service.GetRoleByName("SpecialAnimal")
|
||||||
|
} else if slices.Contains(roleAnswer, *event.OptionIdGuest) {
|
||||||
|
return service.GetRoleByName("Guest")
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("role not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAttendieNickname(order *entities.Pretix_Result, indexName, indexParticipation *int) string {
|
||||||
|
return order.Positions[*indexParticipation].Answers[*indexName].Answer
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAttendiePrivacy(order *entities.Pretix_Result, indexPrivacy, indexParticipation *int) (bool, error) {
|
||||||
|
privacy, err := strconv.ParseBool(order.Positions[*indexParticipation].Answers[*indexPrivacy].Answer)
|
||||||
|
if err != nil {
|
||||||
|
return privacy, err
|
||||||
|
}
|
||||||
|
return privacy, err
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
{{template "suitwalk" .}}
|
{{template "suitwalk" .}}
|
||||||
{{ else if eq .EventType "RegularsTable" }}
|
{{ else if eq .EventType "RegularsTable" }}
|
||||||
{{ template "regularstable" .}}
|
{{ template "regularstable" .}}
|
||||||
|
{{ else if eq .EventType "SpecialEventRoles" }}
|
||||||
|
{{ template "specialEventRoles" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
67
src/app/views/specialEventRoles.html
Normal file
67
src/app/views/specialEventRoles.html
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
{{define "specialEventRoles"}}
|
||||||
|
<h1 class="textWhite">{{ .EventName }} {{ .Locals.Attendie }}</h1>
|
||||||
|
<h2 class="textWhite">{{ .Locals.Registered }}</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr class="tableHeading">
|
||||||
|
<th>{{ .Locals.Name }}</th>
|
||||||
|
<th>{{ .Locals.Role }}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{range $suiter := .Attendies }}
|
||||||
|
{{if not $suiter.OnWaitingList }}
|
||||||
|
<tr>
|
||||||
|
<td>{{ $suiter.Nickname }}</td>
|
||||||
|
{{ if eq $suiter.Role.Name "Suiter" }}
|
||||||
|
<td>{{ $.Locals.Suiter }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "SpecialAnimal" }}
|
||||||
|
<td>{{ $.Locals.SpecialAnimal }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "Spotter" }}
|
||||||
|
<td>{{ $.Locals.Spotter }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "Photograph" }}
|
||||||
|
<td>{{ $.Locals.Photographer }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "Guest" }}
|
||||||
|
<td>{{ $.Locals.Guest }}</td>
|
||||||
|
{{ end }}
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{ if gt .Attendies.CountWaitingList 0 }}
|
||||||
|
<h2 class="textWhite">{{ .Locals.SuiterWaitinglist }}</h2>
|
||||||
|
<p class="textWhite">{{ .Locals.WaitinglistDesc}}</p>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr class="tableHeading">
|
||||||
|
<th>{{ .Locals.Name }}</th>
|
||||||
|
<th>{{ .Locals.Role }}</th>
|
||||||
|
{{ if eq .EventType "Suitwalk" }}
|
||||||
|
<th>{{ .Locals.Restaurant }}</th>
|
||||||
|
{{ end }}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{range $suiter := .Attendies }}
|
||||||
|
{{if $suiter.OnWaitingList }}
|
||||||
|
<tr>
|
||||||
|
<td>{{ $suiter.Nickname }}</td>
|
||||||
|
{{ if eq $suiter.Role.Name "Suiter" }}
|
||||||
|
<td>{{ $.Locals.Suiter }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "SpecialAnimal" }}
|
||||||
|
<td>{{ $.Locals.SpecialAnimal }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "Spotter" }}
|
||||||
|
<td>{{ $.Locals.Spotter }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "Photograph" }}
|
||||||
|
<td>{{ $.Locals.Photographer }}</td>
|
||||||
|
{{ else if eq $suiter.Role.Name "Guest" }}
|
||||||
|
<td>{{ $.Locals.Guest }}</td>
|
||||||
|
{{ end }}
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
Loading…
Reference in a new issue