Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions api/controllers/gameController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()})
Expand Down
4 changes: 4 additions & 0 deletions api/dtos/gameDtos.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ type GetGameByIdResponseBody struct {
Status shared.GameStatus `json:"status"`
Url string `json:"url"`
}

type UploadGameRequestBody struct {
Title string `json:"title"`
}