From 6e90d0d3ebdc4c3e3c2622baebd39917eb72212f Mon Sep 17 00:00:00 2001 From: Nabil Ould Hamou <38989045+NabilOuldHamou@users.noreply.github.com> Date: Mon, 8 Apr 2024 22:47:55 +0200 Subject: [PATCH] Update userController.go --- controllers/userController.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/controllers/userController.go b/controllers/userController.go index 332ae78..9d2bb04 100644 --- a/controllers/userController.go +++ b/controllers/userController.go @@ -98,13 +98,6 @@ func UpdateUser(c *gin.Context) { return } - if len(uploadedFiles) == 0 { - c.JSON(http.StatusBadRequest, gin.H{ - "error": "No files were uploaded.", - }) - return - } - files, err := uploadFiles(c, uploadedFiles) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ @@ -116,7 +109,10 @@ func UpdateUser(c *gin.Context) { currentUserId := c.GetString("userId") id, _ := uuid.Parse(currentUserId) - initializers.DB.Model(&files[0]).Update("user_id", id.String()) + if len(uploadedFiles) == 1 { + initializers.DB.Model(&files[0]).Update("user_id", id.String()) + return + } var user models.User result := initializers.DB.Preload("Avatar").First(&user, "id = ?", id)