Add function for Erding Event
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Nikurasu 2024-06-14 00:44:28 +02:00
parent 246f0046ae
commit 1d20377ee6
Signed by: Nikurasu
GPG key ID: 9E7F14C03EF1F271
5 changed files with 84 additions and 0 deletions

View file

@ -137,6 +137,37 @@ func PostPretixSpecialEventWithRoles(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
}
func PostPretixEventWithoutMainProduct(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.GetAttendiesFromPretixJsonFindNameInSubproducts(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) {
pretixOrders, err := util.GetPretixOrders(organizer, event)
for link := pretixOrders.Next; link != nil; {

View file

@ -16,6 +16,7 @@ func PublicRoutes(app *fiber.App) {
webhooks.Post("/pretix/role_product", controller.PostPretixRoleProduct)
webhooks.Post("/pretix/subproduct", controller.PostPretixRegularsTable)
webhooks.Post("/pretix/speicalEventRoles", controller.PostPretixSpecialEventWithRoles)
webhooks.Post("/pretix/specialEventWithoutMain", controller.PostPretixEventWithoutMainProduct)
apiv1.Post("/login", controller.LoginUser)
apiv1.Get("/event", controller.ReturnAllEventsPublic)
apiv1.Get("/ping", controller.Ping)

View file

@ -300,6 +300,56 @@ func GetAttendiesFromPretixJsonWithRoleQuestionNoSubproducts(pretixEvent *entiti
return attendies, nil
}
func GetAttendiesFromPretixJsonFindNameInSubproducts(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) (entities.AttendiesList, error) {
var attendies entities.AttendiesList
for _, order := range pretixEvent.Results {
if checkCanceled(order) {
continue
}
var attendie entities.Db_Attendies
attendie.Event = event
if event.ItemIdEvent == nil {
return attendies, errors.New("event has no ItemIdEvent")
}
if event.ItemIdRestaurant == nil {
return attendies, errors.New("event has no ItemIdRestaurant")
}
indexEvent := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdEvent })
indexRestaurant := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdRestaurant })
var indexName int
var indexPrivacy int
if indexEvent != -1 {
indexName = slices.IndexFunc(order.Positions[indexEvent].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
indexPrivacy = slices.IndexFunc(order.Positions[indexEvent].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
attendie.AttendsEvent = true
attendie.Nickname = getAttendieNickname(&order, &indexName, &indexEvent)
privacy, err := getAttendiePrivacy(&order, &indexPrivacy, &indexEvent)
if err != nil {
return nil, err
}
attendie.Privacy = privacy
}
if indexRestaurant != -1 {
indexName = slices.IndexFunc(order.Positions[indexRestaurant].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
indexPrivacy = slices.IndexFunc(order.Positions[indexRestaurant].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdName })
attendie.AttendsRestaurant = true
attendie.Nickname = getAttendieNickname(&order, &indexName, &indexRestaurant)
privacy, err := getAttendiePrivacy(&order, &indexPrivacy, &indexRestaurant)
if err != nil {
return nil, err
}
attendie.Privacy = privacy
}
attendie.RegistrationTime = order.Datetime
attendies = append(attendies, attendie)
}
return attendies, nil
}
func checkCanceled(pretixResult entities.Pretix_Result) bool {
return pretixResult.Status == "c" || pretixResult.Status == "e"
}
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) {

View file

@ -29,6 +29,7 @@ type Db_Attendies struct {
Role *Role
AttendsRestaurant bool `gorm:"column:attends_restaurant;not null;default:false"`
AttendsBar bool `gorm:"attends_restaurant;not null;default:false"`
AttendsEvent bool `gorm:"attends_event;not null;default:false"`
Privacy bool `gorm:"column:privacy;not null;default:false"`
RegistrationTime time.Time `gorm:"column:registration_time;not null;default:CURRENT_TIMESTAMP"`
OnWaitingList bool `gorm:"column:on_wating_list;not null;default:false"`

View file

@ -14,6 +14,7 @@ type Db_Event struct {
ItemIdBar *int `gorm:"column:item_id_bar"`
ItemIdParticipation *int `gorm:"column:item_id_participation"`
ItemIdRole *int `gorm:"column:item_id_role"`
ItemIdEvent *int `gorm:"column:item_id_event"`
QuestionIdRole *string `gorm:"column:question_id_role"`
QuestionIdName *string `gorm:"column:question_id_name"`
QuestionIdPrivacy *string `gorm:"column:question_id_is_private"`