feat(display-attendies): new function for role-product
This commit is contained in:
parent
c0f4455d05
commit
5c69c91c4e
5 changed files with 113 additions and 19 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
"ulmer-furs.de/pretix-proxy/v2/entities"
|
||||
)
|
||||
|
||||
func PostPretix(c *fiber.Ctx) error {
|
||||
func PostPretixRoleQuestion(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())
|
||||
|
@ -24,7 +24,39 @@ func PostPretix(c *fiber.Ctx) error {
|
|||
if err != nil {
|
||||
return c.Status(fiber.StatusNotFound).SendString("Event not found")
|
||||
}
|
||||
attendies, err := util.GetAttendiesFromPretixJson(pretixOrders, &event)
|
||||
attendies, err := util.GetAttendiesFromPretixJsonWithRoleQuestion(pretixOrders, &event)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err := service.DeleteAttendiesByEvent(event); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
for _, attendie := range attendies {
|
||||
if err := service.CreateNewAttendie(attendie); err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
}
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func PostPretixRoleProduct(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())
|
||||
}
|
||||
//TODO: Update attendies from pretix
|
||||
pretixOrders, err := util.GetPretixOrders(&data.Organizer, &data.Event)
|
||||
_ = pretixOrders
|
||||
if err != nil {
|
||||
return c.Status(500).SendString("Internal Server Error")
|
||||
}
|
||||
event, err := service.Get_db_event_by_event(data.Event)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusNotFound).SendString("Event not found")
|
||||
}
|
||||
fmt.Printf("%+v\n", pretixOrders)
|
||||
attendies, err := util.GetAttendiesFromPretixJsonWithRoleProduct(pretixOrders, &event)
|
||||
fmt.Printf("%+v\n", attendies)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ func PublicRoutes(app *fiber.App) {
|
|||
apiv1 := app.Group("/api/v1/public")
|
||||
attendies := apiv1.Group("/attendies")
|
||||
webhooks := apiv1.Group("/webhooks")
|
||||
webhooks.Post("/pretix", controller.PostPretix)
|
||||
webhooks.Post("/pretix/role_question", controller.PostPretixRoleQuestion)
|
||||
webhooks.Post("/pretix/role_product", controller.PostPretixRoleProduct)
|
||||
apiv1.Post("/login", controller.LoginUser)
|
||||
apiv1.Get("/event", controller.ReturnAllEventsPublic)
|
||||
apiv1.Get("/ping", controller.Ping)
|
||||
|
|
|
@ -76,9 +76,10 @@ func GetAttendieListFromPretixJson(pretixEvent entities.Pretix_Event, event enti
|
|||
return attendies
|
||||
}
|
||||
|
||||
func GetAttendiesFromPretixJson(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) ([]entities.Db_Attendies, error) {
|
||||
func GetAttendiesFromPretixJsonWithRoleQuestion(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) ([]entities.Db_Attendies, error) {
|
||||
var attendies []entities.Db_Attendies
|
||||
for _, order := range pretixEvent.Results {
|
||||
fmt.Println("Here")
|
||||
if order.Status == "c" || order.Status == "e" {
|
||||
continue
|
||||
}
|
||||
|
@ -128,3 +129,56 @@ func GetAttendiesFromPretixJson(pretixEvent *entities.Pretix_Event, event *entit
|
|||
}
|
||||
return attendies, nil
|
||||
}
|
||||
|
||||
func GetAttendiesFromPretixJsonWithRoleProduct(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) ([]entities.Db_Attendies, error) {
|
||||
var attendies []entities.Db_Attendies
|
||||
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("no participation found")
|
||||
}
|
||||
indexParticipation := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdParticipation })
|
||||
if event.ItemIdRestaurant == nil {
|
||||
attendie.AttendsRestaurant = false
|
||||
} else {
|
||||
indexRestaurant := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdRestaurant })
|
||||
if indexRestaurant != -1 {
|
||||
attendie.AttendsRestaurant = true
|
||||
} else {
|
||||
attendie.AttendsRestaurant = false
|
||||
}
|
||||
}
|
||||
indexRole := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdRole })
|
||||
|
||||
indexName := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
|
||||
attendie.Nickname = order.Positions[indexParticipation].Answers[indexName].Answer
|
||||
|
||||
roleProduct := order.Positions[indexRole]
|
||||
|
||||
if roleProduct.Variation == *event.VariationIdSuiter {
|
||||
attendie.Role, _ = service.GetRoleByName("Suiter")
|
||||
} else if roleProduct.Variation == *event.VariationIdSpotter {
|
||||
attendie.Role, _ = service.GetRoleByName("Spotter")
|
||||
} else if roleProduct.Variation == *event.VariationIdPhotograph {
|
||||
attendie.Role, _ = service.GetRoleByName("Photograph")
|
||||
} else if roleProduct.Variation == *event.VariationIdSpecialAnimal {
|
||||
attendie.Role, _ = service.GetRoleByName("SpecialAnimal")
|
||||
} else if roleProduct.Variation == *event.VariationIdGuest {
|
||||
attendie.Role, _ = service.GetRoleByName("Guest")
|
||||
}
|
||||
|
||||
indexPrivacy := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdPrivacy })
|
||||
var err error
|
||||
attendie.Privacy, err = strconv.ParseBool(order.Positions[indexParticipation].Answers[indexPrivacy].Answer)
|
||||
if err != nil {
|
||||
return attendies, err
|
||||
}
|
||||
|
||||
attendies = append(attendies, attendie)
|
||||
}
|
||||
return attendies, nil
|
||||
}
|
||||
|
|
|
@ -6,21 +6,27 @@ import (
|
|||
|
||||
type Db_Event struct {
|
||||
gorm.Model
|
||||
Name *string `gorm:"column:name;unique;not null" validate:"required"`
|
||||
Organizer *string `gorm:"column:organizer;not null" validate:"required"`
|
||||
Event *string `gorm:"column:event;not null" validate:"required"`
|
||||
ItemIdBadge *int `gorm:"column:item_id_badge"`
|
||||
ItemIdRestaurant *int `gorm:"column:item_id_restaurant"`
|
||||
ItemIdParticipation *int `gorm:"column:item_id_participation"`
|
||||
QuestionIdRole *string `gorm:"column:question_id_role"`
|
||||
QuestionIdName *string `gorm:"column:question_id_name"`
|
||||
QuestionIdPrivacy *string `gorm:"column:question_id_is_private"`
|
||||
OptionIdSuiter *string `gorm:"column:option_id_suiter"`
|
||||
OptionIdGuest *string `gorm:"column:option_id_guest"`
|
||||
OptionIdSpotter *string `gorm:"column:option_id_spotter"`
|
||||
OptionIdPhotograph *string `gorm:"column:option_id_photograph"`
|
||||
OptionIdSpecialAnimal *string `gorm:"column:option_id_special_animal"`
|
||||
EventType *string `gorm:"cloumn:event_type;not null" validate:"required"`
|
||||
Name *string `gorm:"column:name;unique;not null" validate:"required"`
|
||||
Organizer *string `gorm:"column:organizer;not null" validate:"required"`
|
||||
Event *string `gorm:"column:event;not null" validate:"required"`
|
||||
ItemIdBadge *int `gorm:"column:item_id_badge"`
|
||||
ItemIdRestaurant *int `gorm:"column:item_id_restaurant"`
|
||||
ItemIdParticipation *int `gorm:"column:item_id_participation"`
|
||||
ItemIdRole *int `gorm:"column:item_id_role"`
|
||||
QuestionIdRole *string `gorm:"column:question_id_role"`
|
||||
QuestionIdName *string `gorm:"column:question_id_name"`
|
||||
QuestionIdPrivacy *string `gorm:"column:question_id_is_private"`
|
||||
OptionIdSuiter *string `gorm:"column:option_id_suiter"`
|
||||
OptionIdGuest *string `gorm:"column:option_id_guest"`
|
||||
OptionIdSpotter *string `gorm:"column:option_id_spotter"`
|
||||
OptionIdPhotograph *string `gorm:"column:option_id_photograph"`
|
||||
OptionIdSpecialAnimal *string `gorm:"column:option_id_special_animal"`
|
||||
VariationIdSuiter *int `gorm:"variation_id_suiter"`
|
||||
VariationIdGuest *int `gorm:"variation_id_guest"`
|
||||
VariationIdSpotter *int `gorm:"variation_id_spotter"`
|
||||
VariationIdPhotograph *int `gorm:"variation_id_photograph"`
|
||||
VariationIdSpecialAnimal *int `gorm:"variation_id_special_animal"`
|
||||
EventType *string `gorm:"cloumn:event_type;not null" validate:"required"`
|
||||
}
|
||||
|
||||
type Db_Event_Public struct {
|
||||
|
|
|
@ -13,6 +13,7 @@ type Pretix_Result struct {
|
|||
type Pretix_Position struct {
|
||||
Item int `json:"item"`
|
||||
AttendieName string `json:"attendee_name"`
|
||||
Variation int `json:"variation"`
|
||||
Answers []Pretix_Answer `json:"answers"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue