feat(view): add view and backend for regulars tables
This commit is contained in:
parent
3fde58c143
commit
8206d16be0
16 changed files with 198 additions and 40 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ go.sum
|
|||
.env
|
||||
pretix-proxy
|
||||
main.db
|
||||
src/db.db
|
||||
|
|
|
@ -95,9 +95,13 @@ func GetAttendiesByEventPublicTable(c *fiber.Ctx) error {
|
|||
"No": localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "No",
|
||||
}),
|
||||
"AfterParty": localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "AfterParty",
|
||||
PluralCount: 1,
|
||||
}),
|
||||
}
|
||||
return c.Render("app/views/index", fiber.Map{
|
||||
"Event Name": event.Name,
|
||||
"EventName": *(event).Name,
|
||||
"Attendies": attendies,
|
||||
"Locals": localizations,
|
||||
"EventType": *(event).EventType,
|
||||
|
|
|
@ -14,17 +14,10 @@ func PostPretixRoleQuestion(c *fiber.Ctx) error {
|
|||
if err := c.BodyParser(data); err != nil {
|
||||
return c.Status(fiber.ErrBadRequest.Code).SendString(err.Error())
|
||||
}
|
||||
pretixOrders, err := util.GetPretixOrders(&data.Organizer, &data.Event)
|
||||
pretixOrders, err := getAllPretixOrders(&data.Organizer, &data.Event)
|
||||
if err != nil {
|
||||
return c.Status(500).SendString("Internal Server Error")
|
||||
}
|
||||
for link := pretixOrders.Next; link != nil; {
|
||||
next_page, err := util.GetPretixOrdersByLink(link)
|
||||
if err != nil {
|
||||
return c.Status(500).SendString("Internal Server Error")
|
||||
}
|
||||
pretixOrders.Results = append(pretixOrders.Results, next_page.Results...)
|
||||
link = next_page.Next
|
||||
fmt.Println(err)
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
event, err := service.Get_db_event_by_event(data.Event)
|
||||
if err != nil {
|
||||
|
@ -33,13 +26,16 @@ func PostPretixRoleQuestion(c *fiber.Ctx) error {
|
|||
attendies, err := util.GetAttendiesFromPretixJsonWithRoleQuestion(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)
|
||||
|
@ -50,9 +46,7 @@ func PostPretixRoleProduct(c *fiber.Ctx) error {
|
|||
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
|
||||
pretixOrders, err := getAllPretixOrders(&data.Organizer, &data.Event)
|
||||
if err != nil {
|
||||
return c.Status(500).SendString("Internal Server Error")
|
||||
}
|
||||
|
@ -63,14 +57,61 @@ func PostPretixRoleProduct(c *fiber.Ctx) error {
|
|||
attendies, err := util.GetAttendiesFromPretixJsonWithRoleProduct(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 PostPretixRegularsTable(c *fiber.Ctx) error {
|
||||
data := new(entities.Pretix_Webhook)
|
||||
if err := c.BodyParser(data); err != nil {
|
||||
return c.Status(fiber.ErrBadGateway.Code).SendString(err.Error())
|
||||
}
|
||||
pretixOrders, err := getAllPretixOrders(&data.Organizer, &data.Event)
|
||||
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")
|
||||
}
|
||||
attendies, err := util.GetAttendiesFromPretixJsonWithSeperateSubProducts(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; {
|
||||
next_page, err := util.GetPretixOrdersByLink(link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pretixOrders.Results = append(pretixOrders.Results, next_page.Results...)
|
||||
link = next_page.Next
|
||||
}
|
||||
return pretixOrders, err
|
||||
}
|
||||
|
|
|
@ -15,8 +15,9 @@ func PrivateRoutes(app *fiber.App) {
|
|||
event.Get("/:id", controller.ReturnEventById)
|
||||
event.Delete("/:id", controller.DeleteEventById)
|
||||
event.Put("/:id", controller.UpdateEventById)
|
||||
event.Put("", controller.CreateEvent)
|
||||
event.Post("", controller.CreateEvent)
|
||||
role := apiv1.Group("/role")
|
||||
role.Use(config.JwtMiddleware)
|
||||
role.Get("", controller.ReturnAllRoles)
|
||||
role.Get("/:id", controller.ReturnRoleById)
|
||||
role.Delete("/:id", controller.DeleteRoleById)
|
||||
|
@ -24,5 +25,5 @@ func PrivateRoutes(app *fiber.App) {
|
|||
role.Put("", controller.CreateRole)
|
||||
user := apiv1.Group("/user")
|
||||
user.Use(config.AuthMiddleware)
|
||||
user.Put("", controller.CreateUser)
|
||||
user.Post("", controller.CreateUser)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ func PublicRoutes(app *fiber.App) {
|
|||
webhooks := apiv1.Group("/webhooks")
|
||||
webhooks.Post("/pretix/role_question", controller.PostPretixRoleQuestion)
|
||||
webhooks.Post("/pretix/role_product", controller.PostPretixRoleProduct)
|
||||
webhooks.Post("/pretix/subproduct", controller.PostPretixRegularsTable)
|
||||
apiv1.Post("/login", controller.LoginUser)
|
||||
apiv1.Get("/event", controller.ReturnAllEventsPublic)
|
||||
apiv1.Get("/ping", controller.Ping)
|
||||
|
|
|
@ -2,6 +2,7 @@ package service
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"ulmer-furs.de/pretix-proxy/v2/config"
|
||||
|
@ -46,7 +47,7 @@ func GetAttendiesByEvent(event entities.Db_Event) ([]entities.Db_Attendies, erro
|
|||
|
||||
func GetAttendiesByEventPrivacy(event entities.Db_Event, privacy bool) (entities.AttendiesList, error) {
|
||||
var attendies []entities.Db_Attendies
|
||||
result := config.Database.Model(&entities.Db_Attendies{}).Preload("Event").Preload("Role").Where("event_id = ?", event.ID).Where("privacy = ?", privacy).Find(&attendies)
|
||||
result := config.Database.Model(&entities.Db_Attendies{}).Preload("Role").Where("event_id = ?", event.ID).Where("privacy = ?", privacy).Find(&attendies)
|
||||
if result.Error != nil {
|
||||
return attendies, result.Error
|
||||
}
|
||||
|
@ -54,6 +55,11 @@ func GetAttendiesByEventPrivacy(event entities.Db_Event, privacy bool) (entities
|
|||
}
|
||||
|
||||
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)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
|
|
|
@ -100,16 +100,16 @@ func GetAttendieListFromPretixJson(pretixEvent entities.Pretix_Event, event enti
|
|||
return attendies
|
||||
}
|
||||
|
||||
func GetAttendiesFromPretixJsonWithRoleQuestion(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) ([]entities.Db_Attendies, error) {
|
||||
func GetAttendiesFromPretixJsonWithRoleQuestion(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
|
||||
attendie.Event = event
|
||||
if event.ItemIdParticipation == nil {
|
||||
return attendies, errors.New("no participation found")
|
||||
return attendies, errors.New("event has no ItemIdParticipation")
|
||||
}
|
||||
indexParticipation := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdParticipation })
|
||||
if indexParticipation == -1 {
|
||||
|
@ -160,16 +160,16 @@ func GetAttendiesFromPretixJsonWithRoleQuestion(pretixEvent *entities.Pretix_Eve
|
|||
return attendies, nil
|
||||
}
|
||||
|
||||
func GetAttendiesFromPretixJsonWithRoleProduct(pretixEvent *entities.Pretix_Event, event *entities.Db_Event) ([]entities.Db_Attendies, error) {
|
||||
func GetAttendiesFromPretixJsonWithRoleProduct(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
|
||||
attendie.Event = event
|
||||
if event.ItemIdParticipation == nil {
|
||||
return attendies, errors.New("no participation found")
|
||||
return attendies, errors.New("event has no ItemIdParticipation")
|
||||
}
|
||||
indexParticipation := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdParticipation })
|
||||
if event.ItemIdRestaurant == nil {
|
||||
|
@ -215,3 +215,55 @@ func GetAttendiesFromPretixJsonWithRoleProduct(pretixEvent *entities.Pretix_Even
|
|||
MarkWatingListAttendies(&attendies, (*event).SuiterPerSpotter, suiter, spotter, specialAnimal)
|
||||
return attendies, nil
|
||||
}
|
||||
|
||||
func GetAttendiesFromPretixJsonWithSeperateSubProducts(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 })
|
||||
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
|
||||
}
|
||||
}
|
||||
if event.ItemIdBar == nil {
|
||||
attendie.AttendsBar = false
|
||||
} else {
|
||||
indexBar := slices.IndexFunc(order.Positions, func(p entities.Pretix_Position) bool { return p.Item == *event.ItemIdRestaurant })
|
||||
if indexBar != -1 {
|
||||
attendie.AttendsBar = true
|
||||
} else {
|
||||
attendie.AttendsBar = false
|
||||
}
|
||||
}
|
||||
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 })
|
||||
|
||||
attendie.Nickname = order.Positions[indexParticipation].Answers[indexName].Answer
|
||||
var err error
|
||||
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 {
|
||||
return attendies, err
|
||||
}
|
||||
attendies = append(attendies, attendie)
|
||||
}
|
||||
fmt.Printf("%+v", attendies)
|
||||
return attendies, nil
|
||||
}
|
||||
|
|
|
@ -9,7 +9,11 @@
|
|||
<body>
|
||||
<main>
|
||||
<h1 class="textWhite">{{.Title}}</h1>
|
||||
{{template "table" .}}
|
||||
{{ if eq .EventType "Suitwalk" }}
|
||||
{{template "suitwalk" .}}
|
||||
{{ else if eq .EventType "RegularsTable" }}
|
||||
{{ template "regularstable" .}}
|
||||
{{ end }}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
32
src/app/views/regularstable.html
Normal file
32
src/app/views/regularstable.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{{ define "regularstable" }}
|
||||
<h1 class="textWhite">{{ .EventName }} {{ .Locals.Attendie }}</h1>
|
||||
<h2 class="textWhite">{{ .Locals.Registered }}</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr class="tableHeading">
|
||||
<th>{{ .Locals.Name }}</th>
|
||||
<th>{{ .Locals.Restaurant }}</th>
|
||||
<th>{{ .Locals.AfterParty }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $suiter := .Attendies }}
|
||||
{{if not $suiter.OnWaitingList }}
|
||||
<tr>
|
||||
<td>{{ $suiter.Nickname }}</td>
|
||||
{{ if $suiter.AttendsRestaurant }}
|
||||
<td class="tdgreen">✓ {{ $.Locals.Yes }}</td>
|
||||
{{ else }}
|
||||
<td class="tdred">❌ {{ $.Locals.No }}</td>
|
||||
{{ end }}
|
||||
{{ if $suiter.AttendsBar }}
|
||||
<td class="tdgreen">✓ {{ $.Locals.Yes }}</td>
|
||||
{{ else }}
|
||||
<td class="tdred">❌ {{ $.Locals.No }}</td>
|
||||
{{ end }}
|
||||
</tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
|
@ -1,5 +1,5 @@
|
|||
{{define "table"}}
|
||||
<h1 class="textWhite">{{ index . "Event Name" }} {{ .Locals.Attendie }}</h1>
|
||||
{{define "suitwalk"}}
|
||||
<h1 class="textWhite">{{ .EventName }} {{ .Locals.Attendie }}</h1>
|
||||
<h2 class="textWhite">{{ .Locals.Registered }}</h2>
|
||||
<table>
|
||||
<thead>
|
|
@ -89,4 +89,9 @@ var defaultMessages = []i18n.Message{
|
|||
ID: "No",
|
||||
Other: "No",
|
||||
},
|
||||
{
|
||||
ID: "AfterParty",
|
||||
One: "AfterParty",
|
||||
Other: "AfterParties",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -24,11 +24,12 @@ type Db_Attendies struct {
|
|||
gorm.Model
|
||||
Nickname string `gorm:"column:nickname;not null"`
|
||||
EventID int `gorm:"not null"`
|
||||
Event Db_Event
|
||||
RoleID int `gorm:"not null"`
|
||||
Event *Db_Event
|
||||
RoleID int `gorm:""`
|
||||
Role *Role
|
||||
AttendsRestaurant bool `gorm:"column:attends_restaurant;not null"`
|
||||
Privacy bool `gorm:"column:privacy;not null"`
|
||||
AttendsRestaurant bool `gorm:"column:attends_restaurant;not null;default:false"`
|
||||
AttendsBar bool `gorm:"attends_restaurant;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"`
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ type Db_Event struct {
|
|||
Event *string `gorm:"column:event;not null" validate:"required"`
|
||||
ItemIdBadge *int `gorm:"column:item_id_badge"`
|
||||
ItemIdRestaurant *int `gorm:"column:item_id_restaurant"`
|
||||
ItemIdBar *int `gorm:"column:item_id_bar"`
|
||||
ItemIdParticipation *int `gorm:"column:item_id_participation"`
|
||||
ItemIdRole *int `gorm:"column:item_id_role"`
|
||||
QuestionIdRole *string `gorm:"column:question_id_role"`
|
||||
|
@ -27,7 +28,7 @@ type Db_Event struct {
|
|||
VariationIdPhotograph *int `gorm:"variation_id_photograph"`
|
||||
VariationIdSpecialAnimal *int `gorm:"variation_id_special_animal"`
|
||||
EventType *string `gorm:"cloumn:event_type;not null" validate:"required"`
|
||||
SuiterPerSpotter *int `gorm:"column:suiter_per_spotter;not null;default:5" validate:"required"`
|
||||
SuiterPerSpotter *int `gorm:"column:suiter_per_spotter;not null;default:5"`
|
||||
}
|
||||
|
||||
type Db_Event_Public struct {
|
||||
|
|
|
@ -9,7 +9,9 @@ require (
|
|||
github.com/golang-jwt/jwt/v5 v5.1.0
|
||||
github.com/jinzhu/copier v0.4.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/nicksnyder/go-i18n/v2 v2.4.0
|
||||
golang.org/x/crypto v0.15.0
|
||||
golang.org/x/text v0.14.0
|
||||
gorm.io/driver/sqlite v1.5.3
|
||||
gorm.io/gorm v1.25.4
|
||||
)
|
||||
|
@ -20,9 +22,7 @@ require (
|
|||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
{
|
||||
"AfterParty": {
|
||||
"hash": "sha1-78064d491b346faba9074905e42300788f3b2de7",
|
||||
"one": "AfterStammi",
|
||||
"other": "AfterStammis"
|
||||
},
|
||||
"Attendie": {
|
||||
"hash": "sha1-4c29d6c952ccd2b114d1792c7b18fa7f7052ebed",
|
||||
"one": "Teilnehmer*in",
|
||||
|
@ -32,9 +37,9 @@
|
|||
"other": "Angemeldet"
|
||||
},
|
||||
"Restaurant": {
|
||||
"hash": "sha1-2b8fd2cb645ab1f1b09fbecda98978ec3518a9d9",
|
||||
"hash": "sha1-b19c390d03b991e33ecbb225687fcaf21da87a89",
|
||||
"one": "Restaurant",
|
||||
"other": "Restaurnts"
|
||||
"other": "Restaurants"
|
||||
},
|
||||
"Role": {
|
||||
"hash": "sha1-47dcc27d6e87ece8baebe7e3877a261a5467093d",
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"AfterParty": {
|
||||
"one": "AfterParty",
|
||||
"other": "AfterParties"
|
||||
},
|
||||
"Attendie": {
|
||||
"one": "Attendie",
|
||||
"other": "Attendies"
|
||||
|
@ -20,7 +24,7 @@
|
|||
"Registered": "Registered",
|
||||
"Restaurant": {
|
||||
"one": "Restaurant",
|
||||
"other": "Restaurnts"
|
||||
"other": "Restaurantes"
|
||||
},
|
||||
"Role": {
|
||||
"one": "Role",
|
||||
|
|
Loading…
Reference in a new issue