Skip to content

Commit 9f8048d

Browse files
committed
[Minor Fixes]
1 parent 9fabb02 commit 9f8048d

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

handlers/competitions/competition_management.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"api/database"
55
"api/middleware"
66
"api/models"
7+
"api/utils"
78
"api/utils/permissions"
89
"api/utils/response"
910
"log"
@@ -257,6 +258,8 @@ func UpdateCompetition(c *gin.Context) {
257258
return
258259
}
259260

261+
utils.DisplayBodyContent(c)
262+
260263
var req UpdateCompetitionRequest
261264
if err := c.ShouldBindJSON(&req); err != nil {
262265
response.Error(c, http.StatusBadRequest, ErrInvalidRequest)
@@ -290,6 +293,17 @@ func UpdateCompetition(c *gin.Context) {
290293
if req.Show != nil {
291294
updateData["show"] = *req.Show
292295
}
296+
if len(req.GroupsIDs) > 0 {
297+
var groups []models.Group
298+
if err := database.DB.Where("id IN ?", req.GroupsIDs).Find(&groups).Error; err != nil {
299+
response.Error(c, http.StatusBadRequest, ErrGroupNotFound)
300+
return
301+
}
302+
if err := database.DB.Model(&competition).Association("Groups").Replace(groups); err != nil {
303+
response.Error(c, http.StatusInternalServerError, ErrFailedAddGroup)
304+
return
305+
}
306+
}
293307

294308
if err := database.DB.Model(&competition).Updates(updateData).Error; err != nil {
295309
response.Error(c, http.StatusInternalServerError, ErrFailedUpdateCompetition)

handlers/competitions/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type UpdateCompetitionRequest struct {
5252
Description string `json:"description"`
5353
CatalogTheme string `json:"catalog_theme"`
5454
CatalogID string `json:"catalog_id"`
55+
GroupsIDs []string `json:"groups_ids"`
5556
Finished *bool `json:"finished"`
5657
Show *bool `json:"show"`
5758
}

handlers/users/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ type UserProfileUpdate struct {
5858
GroupIDs []string `json:"groups_ids"`
5959
}
6060

61+
// Create a struct to match the incoming JSON format
62+
type UserIDsRequest struct {
63+
UserIDs []string `json:"user_ids"`
64+
}
6165

6266
// PasswordUpdate represents a password update request
6367
type PasswordUpdate struct {

handlers/users/user_groups.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ func ImportUsersFromXLSXToGroup(c *gin.Context) {
403403
var lastNameIdx, firstNameIdx, emailIdx int = -1, -1, -1
404404
for i, cell := range rows[0] {
405405
switch cell {
406-
case "Nom", "Nom de famille", "Last Name", "LastName":
406+
case "Nom", "NOM", "Nom de famille", "Last Name", "LastName":
407407
lastNameIdx = i
408-
case "Prénom 1", "Prénom", "First Name", "FirstName":
408+
case "Prénom 1", "Prénom", "PRENOM", "First Name", "FirstName":
409409
firstNameIdx = i
410-
case "E-mail personnel", "E-mail", "Email", "Personal Email":
410+
case "E-mail personnel", "E-mail", "Email", "MAIL", "Personal Email":
411411
emailIdx = i
412412
}
413413
}

handlers/users/user_management.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,17 @@ func BulkDeleteUsers(c *gin.Context) {
250250
return // Error already handled by middleware
251251
}
252252

253+
utils.DisplayBodyContent(c)
254+
253255
// Parse user IDs from request body
254-
var userIDs []string
255-
if err := c.ShouldBindJSON(&userIDs); err != nil {
256+
var reqBody UserIDsRequest
257+
if err := c.ShouldBindJSON(&reqBody); err != nil {
256258
response.Error(c, http.StatusBadRequest, ErrInvalidUserIDs)
257259
return
258260
}
259261

262+
userIDs := reqBody.UserIDs
263+
260264
if len(userIDs) == 0 {
261265
response.Error(c, http.StatusBadRequest, ErrEmptyUserIDs)
262266
return

0 commit comments

Comments
 (0)