Update userController.go

This commit is contained in:
Nabil Ould Hamou 2024-04-08 22:47:55 +02:00 committed by GitHub
parent 42fa4d23e0
commit 6e90d0d3eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)
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)