ADD: added database connection for players data handling and started login funtion with database

This commit is contained in:
hwinkel
2025-05-30 15:02:23 +02:00
parent 4158b87576
commit 1a2eec44a9
19 changed files with 924 additions and 58 deletions

View File

@@ -4,6 +4,8 @@ import (
"net/http"
"volleyball/internal/common"
"slices"
"github.com/gin-gonic/gin"
)
@@ -17,7 +19,7 @@ var tournaments = []Tournament{
{ID: "t1", Name: "Smasher"},
{ID: "t2", Name: "Blockbuster"},
},
OrganizerId: "system-user-id",
OrganizerId: []string{"example-user"},
},
{
ID: "2",
@@ -25,7 +27,7 @@ var tournaments = []Tournament{
Location: "Hamburg",
MaxParticipants: 10,
Teams: []Team{},
OrganizerId: "other-user",
OrganizerId: []string{"example-user"},
},
}
@@ -74,7 +76,8 @@ func UpdateTournament(c *gin.Context) {
for i, t := range tournaments {
if t.ID == id {
if t.OrganizerId != userId {
isOrganizer := slices.Contains(t.OrganizerId, userId)
if !isOrganizer {
c.JSON(http.StatusForbidden, gin.H{"error": "No permission"})
return
}

View File

@@ -6,10 +6,10 @@ type Team struct {
}
type Tournament struct {
ID string `json:"id"`
Name string `json:"name"`
Location string `json:"location"`
MaxParticipants int `json:"maxParticipants"`
Teams []Team `json:"teams"`
OrganizerId string `json:"organizerId"`
ID string `json:"id"`
Name string `json:"name"`
Location string `json:"location"`
MaxParticipants int `json:"maxParticipants"`
Teams []Team `json:"teams"`
OrganizerId []string `json:"PlayerId"` // List of player IDs who are organizers
}