feat(display-attendies): save in db
The waiting list is now saved in the db because before doing so the wating list was calculated on each request on the ui AFTER getting only the attendies that allowed the display which leads to false results. And it is now possible to get if an attendie is on the waiting list even if we only want do get one attendie via the API
This commit is contained in:
parent
bd6e60d461
commit
123f9c5957
7 changed files with 61 additions and 24 deletions
|
@ -1,15 +1,11 @@
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"ulmer-furs.de/pretix-proxy/v2/app/service"
|
"ulmer-furs.de/pretix-proxy/v2/app/service"
|
||||||
"ulmer-furs.de/pretix-proxy/v2/app/util"
|
|
||||||
"ulmer-furs.de/pretix-proxy/v2/config"
|
"ulmer-furs.de/pretix-proxy/v2/config"
|
||||||
"ulmer-furs.de/pretix-proxy/v2/entities"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Description Get the attendies of an event by the name
|
// @Description Get the attendies of an event by the name
|
||||||
|
@ -100,22 +96,10 @@ func GetAttendiesByEventPublicTable(c *fiber.Ctx) error {
|
||||||
MessageID: "No",
|
MessageID: "No",
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
sort.Sort(entities.ByRegistrationTime(attendies))
|
|
||||||
roleSuiter, _ := service.GetRoleByName("Suiter")
|
|
||||||
roleSpotter, _ := service.GetRoleByName("Spotter")
|
|
||||||
roleSpecialAnimal, _ := service.GetRoleByName("SpecialAnimal")
|
|
||||||
suiterWaitingList := util.CreateSuiterWaitingList(
|
|
||||||
&attendies,
|
|
||||||
event.SuiterPerSpotter,
|
|
||||||
&roleSuiter,
|
|
||||||
&roleSpotter,
|
|
||||||
&roleSpecialAnimal,
|
|
||||||
)
|
|
||||||
return c.Render("app/views/index", fiber.Map{
|
return c.Render("app/views/index", fiber.Map{
|
||||||
"Event Name": event.Name,
|
"Event Name": event.Name,
|
||||||
"Attendies": attendies,
|
"Attendies": attendies,
|
||||||
"SuiterWaitingList": suiterWaitingList,
|
"Locals": localizations,
|
||||||
"Locals": localizations,
|
"EventType": *(event).EventType,
|
||||||
"EventType": *(event).EventType,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,3 +23,19 @@ func CreateSuiterWaitingList(attendiesList *entities.AttendiesList, suiterPerSpo
|
||||||
}
|
}
|
||||||
return suiterWatinglist
|
return suiterWatinglist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MarkWatingListAttendies(attendiesList *entities.AttendiesList, suiterPerSpotter *int, suiter, spotter, specialAnimal *entities.Role) {
|
||||||
|
spotterCount := attendiesList.CountByRole(*spotter)
|
||||||
|
suiterCount := spotterCount * *suiterPerSpotter
|
||||||
|
var suiterCounter int
|
||||||
|
var i int
|
||||||
|
for i < len(*attendiesList) {
|
||||||
|
if (*attendiesList)[i].Role == *suiter || (*attendiesList)[i].Role == *specialAnimal {
|
||||||
|
suiterCounter++
|
||||||
|
}
|
||||||
|
if suiterCounter > suiterCount && ((*attendiesList)[i].Role == *suiter || (*attendiesList)[i].Role == *specialAnimal) {
|
||||||
|
(*attendiesList)[i].OnWaitingList = true
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
@ -78,7 +79,7 @@ func GetAttendieListFromPretixJson(pretixEvent entities.Pretix_Event, event enti
|
||||||
}
|
}
|
||||||
|
|
||||||
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.Db_Attendies, error) {
|
||||||
var attendies []entities.Db_Attendies
|
var attendies entities.AttendiesList
|
||||||
for _, order := range pretixEvent.Results {
|
for _, order := range pretixEvent.Results {
|
||||||
if order.Status == "c" || order.Status == "e" {
|
if order.Status == "c" || order.Status == "e" {
|
||||||
continue
|
continue
|
||||||
|
@ -129,11 +130,14 @@ func GetAttendiesFromPretixJsonWithRoleQuestion(pretixEvent *entities.Pretix_Eve
|
||||||
|
|
||||||
attendies = append(attendies, attendie)
|
attendies = append(attendies, attendie)
|
||||||
}
|
}
|
||||||
|
_, spotter, suiter, _, specialAnimal := GetRoles()
|
||||||
|
sort.Sort(entities.ByRegistrationTime(attendies))
|
||||||
|
MarkWatingListAttendies(&attendies, (*event).SuiterPerSpotter, &suiter, &spotter, &specialAnimal)
|
||||||
return attendies, nil
|
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.Db_Attendies, error) {
|
||||||
var attendies []entities.Db_Attendies
|
var attendies entities.AttendiesList
|
||||||
for _, order := range pretixEvent.Results {
|
for _, order := range pretixEvent.Results {
|
||||||
if order.Status == "c" || order.Status == "e" {
|
if order.Status == "c" || order.Status == "e" {
|
||||||
continue
|
continue
|
||||||
|
@ -182,5 +186,8 @@ func GetAttendiesFromPretixJsonWithRoleProduct(pretixEvent *entities.Pretix_Even
|
||||||
|
|
||||||
attendies = append(attendies, attendie)
|
attendies = append(attendies, attendie)
|
||||||
}
|
}
|
||||||
|
_, spotter, suiter, _, specialAnimal := GetRoles()
|
||||||
|
sort.Sort(entities.ByRegistrationTime(attendies))
|
||||||
|
MarkWatingListAttendies(&attendies, (*event).SuiterPerSpotter, &suiter, &spotter, &specialAnimal)
|
||||||
return attendies, nil
|
return attendies, nil
|
||||||
}
|
}
|
||||||
|
|
15
src/app/util/roleHelper.go
Normal file
15
src/app/util/roleHelper.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ulmer-furs.de/pretix-proxy/v2/app/service"
|
||||||
|
"ulmer-furs.de/pretix-proxy/v2/entities"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetRoles() (guest, spotter, suiter, photograph, specialAnimal entities.Role) {
|
||||||
|
guest, _ = service.GetRoleByName("Guest")
|
||||||
|
spotter, _ = service.GetRoleByName("Spotter")
|
||||||
|
suiter, _ = service.GetRoleByName("Suiter")
|
||||||
|
photograph, _ = service.GetRoleByName("Photograph")
|
||||||
|
specialAnimal, _ = service.GetRoleByName("SpecialAnimal")
|
||||||
|
return
|
||||||
|
}
|
|
@ -13,6 +13,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range $suiter := .Attendies }}
|
{{range $suiter := .Attendies }}
|
||||||
|
{{if not $suiter.OnWaitingList }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ $suiter.Nickname }}</td>
|
<td>{{ $suiter.Nickname }}</td>
|
||||||
{{ if eq $suiter.Role.Name "Suiter" }}
|
{{ if eq $suiter.Role.Name "Suiter" }}
|
||||||
|
@ -35,9 +36,10 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{{ if .SuiterWaitingList }}
|
{{ if gt .Attendies.CountWaitingList 0 }}
|
||||||
<h2 class="textWhite">{{ .Locals.SuiterWaitinglist }}</h2>
|
<h2 class="textWhite">{{ .Locals.SuiterWaitinglist }}</h2>
|
||||||
<p class="textWhite">{{ .Locals.WaitinglistDesc}}</p>
|
<p class="textWhite">{{ .Locals.WaitinglistDesc}}</p>
|
||||||
<table>
|
<table>
|
||||||
|
@ -51,7 +53,8 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range $suiter := .SuiterWaitingList }}
|
{{range $suiter := .Attendies }}
|
||||||
|
{{if $suiter.OnWaitingList }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ $suiter.Nickname }}</td>
|
<td>{{ $suiter.Nickname }}</td>
|
||||||
{{ if eq $suiter.Role.Name "Suiter" }}
|
{{ if eq $suiter.Role.Name "Suiter" }}
|
||||||
|
@ -74,6 +77,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -11,3 +11,13 @@ func (a AttendiesList) CountByRole(role Role) int {
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AttendiesList) CountWaitingList() int {
|
||||||
|
var count int
|
||||||
|
for _, attendie := range a {
|
||||||
|
if attendie.OnWaitingList {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
|
@ -30,4 +30,5 @@ type Db_Attendies struct {
|
||||||
AttendsRestaurant bool `gorm:"column:attends_restaurant;not null"`
|
AttendsRestaurant bool `gorm:"column:attends_restaurant;not null"`
|
||||||
Privacy bool `gorm:"column:privacy;not null"`
|
Privacy bool `gorm:"column:privacy;not null"`
|
||||||
RegistrationTime time.Time `gorm:"column:registration_time;not null;default:CURRENT_TIMESTAMP"`
|
RegistrationTime time.Time `gorm:"column:registration_time;not null;default:CURRENT_TIMESTAMP"`
|
||||||
|
OnWaitingList bool `gorm:"column:on_wating_list;not null;default:false"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue