From 25ede25480bb58d23d3309ca35e54053af6fda8c Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 12 Jun 2024 12:41:35 +0200 Subject: [PATCH 1/2] UploadGameRequestBody dto --- api/dtos/gameDtos.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/dtos/gameDtos.go b/api/dtos/gameDtos.go index 91700b7..21606ad 100644 --- a/api/dtos/gameDtos.go +++ b/api/dtos/gameDtos.go @@ -18,3 +18,7 @@ type GetGameByIdResponseBody struct { Status shared.GameStatus `json:"status"` Url string `json:"url"` } + +type UploadGameRequestBody struct { + Title string `json:"title"` +} From 305df0edbcc4b002b8e136a5a5ad0eab9dda77c8 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 12 Jun 2024 12:42:01 +0200 Subject: [PATCH 2/2] read title from body and alternatively from query --- api/controllers/gameController.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/api/controllers/gameController.go b/api/controllers/gameController.go index 612ccb8..5c50f42 100644 --- a/api/controllers/gameController.go +++ b/api/controllers/gameController.go @@ -78,9 +78,16 @@ func (g gameController) GetGameById(c *gin.Context) { } func (g gameController) UploadGame(c *gin.Context) { + var requestBody dtos.UploadGameRequestBody - title := c.Query("title") - if len(title) == 0 { + //Try to read the title from body + err := c.ShouldBindJSON(&requestBody) + if err != nil { + //If it is not in the body, check if it is a query parameter + requestBody.Title = c.GetString("title") + } + + if len(requestBody.Title) == 0 { c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"message": "Title is required"}) return } @@ -97,7 +104,7 @@ func (g gameController) UploadGame(c *gin.Context) { return } - game, err := g.service.Save(file, title, sub) + game, err := g.service.Save(file, requestBody.Title, sub) if err != nil { c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"message": err.Error()})