feat(display-attendies): Begin fuction to get attendies

Begin writing the function to get the attendies in an array from the pretix json
This commit is contained in:
nikurasu 2024-02-22 21:58:42 +01:00
parent 5b247d39a3
commit 411d51122a
Signed by: Nikurasu
GPG key ID: 9E7F14C03EF1F271
4 changed files with 44 additions and 6 deletions

View file

@ -17,6 +17,15 @@ func GetRoleById(id int) (entities.Role, error) {
return role, nil return role, nil
} }
func GetRoleByName(name string) (entities.Role, error) {
var role entities.Role
result := config.Database.First(&role, "name = ?", name)
if result.RowsAffected == 0 {
return role, errors.New("role not found")
}
return role, nil
}
func GetAllRoles() ([]entities.Role, error) { func GetAllRoles() ([]entities.Role, error) {
var roles []entities.Role var roles []entities.Role
result := config.Database.Find(&roles) result := config.Database.Find(&roles)

View file

@ -6,8 +6,10 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strconv"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"ulmer-furs.de/pretix-proxy/v2/app/service"
"ulmer-furs.de/pretix-proxy/v2/config" "ulmer-furs.de/pretix-proxy/v2/config"
"ulmer-furs.de/pretix-proxy/v2/entities" "ulmer-furs.de/pretix-proxy/v2/entities"
) )
@ -74,14 +76,41 @@ func GetAttendieListFromPretixJson(pretixEvent entities.Pretix_Event, event enti
return attendies return attendies
} }
/*func GetAttendiesFromPretixJson(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) []entities.Db_Attendies { func GetAttendiesFromPretixJson(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) ([]entities.Db_Attendies, error) {
var attendies []entities.Db_Attendies var attendies []entities.Db_Attendies
for _, order := range pretixEvent.Results { for _, order := range pretixEvent.Results {
var attendie entities.Db_Attendies
attendie.Event = *event
indexParticipation := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdParticipation }) indexParticipation := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdParticipation })
indexBadge := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdBadge }) indexBadge := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdBadge })
indexRestaurant := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdRestaurant }) indexRestaurant := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdRestaurant })
indexName := slices.IndexFunc(order.Positions[indexBadge].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 })
name := order.Positions[indexBadge].Answers[indexName].Answer attendie.Nickname = order.Positions[indexParticipation].Answers[indexName].Answer
indexRole := slices.IndexFunc(order.Positions[indexParticipation].Answers, func(a entities.Pretix_Answer) bool { return a.QuestionsIdentififer == *event.QuestionIdRole })
roleAnswer := order.Positions[indexParticipation].Answers[indexRole].OptionIdentifiers
if slices.Contains(roleAnswer, *event.OptionIdSuiter) {
attendie.Role, _ = service.GetRoleByName("Suiter")
} else if slices.Contains(roleAnswer, *event.OptionIdSpotter) {
attendie.Role, _ = service.GetRoleByName("Spotter")
} else if slices.Contains(roleAnswer, *event.OptionIdPhotograph) {
attendie.Role, _ = service.GetRoleByName("Photograph")
} else if slices.Contains(roleAnswer, *event.OptionIdSpecialAnimal) {
attendie.Role, _ = service.GetRoleByName("SpecialAnimal")
} else if slices.Contains(roleAnswer, *event.OptionIdGuest) {
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
} }
}*/

View file

@ -9,5 +9,5 @@ type Db_Attendies struct {
Nickname string `gorm:"column:nickname;not null"` Nickname string `gorm:"column:nickname;not null"`
Event Db_Event `gorm:"column:event_id;not null"` Event Db_Event `gorm:"column:event_id;not null"`
Role Role `gorm:"column:role_id;not_null"` Role Role `gorm:"column:role_id;not_null"`
IsPublic bool `gorm:"column:is_public;not null"` Privacy bool `gorm:"column:is_public;not null"`
} }

View file

@ -12,7 +12,7 @@ type Db_Event struct {
ItemIdParticipation *int `gorm:"column:item_id_participation"` ItemIdParticipation *int `gorm:"column:item_id_participation"`
QuestionIdRole *string `gorm:"column:question_id_role"` QuestionIdRole *string `gorm:"column:question_id_role"`
QuestionIdName *string `gorm:"column:question_id_name"` QuestionIdName *string `gorm:"column:question_id_name"`
QuestionIdIsPrivate *string `gorm:"column:question_id_is_private"` QuestionIdPrivacy *string `gorm:"column:question_id_is_private"`
OptionIdSuiter *string `gorm:"column:option_id_suiter"` OptionIdSuiter *string `gorm:"column:option_id_suiter"`
OptionIdGuest *string `gorm:"column:option_id_guest"` OptionIdGuest *string `gorm:"column:option_id_guest"`
OptionIdSpotter *string `gorm:"column:option_id_spotter"` OptionIdSpotter *string `gorm:"column:option_id_spotter"`