mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Changes response of POST
,PUT
and DELETE
:
For being able to easily debug and test the checkpoints which are adding, modifying or deleting a user the response should be the affected user object. Not only its ID.
This commit is contained in:
parent
d3aa873732
commit
02f2156c1e
2 changed files with 12 additions and 13 deletions
|
@ -56,7 +56,7 @@ func (r *updateUserRequest) updatedUser(role interface{},
|
||||||
// Only the Admin must be able to update user's role
|
// Only the Admin must be able to update user's role
|
||||||
if role != "Admin" && r.Role != u.Role {
|
if role != "Admin" && r.Role != u.Role {
|
||||||
return u, fmt.Errorf("Only Admin can update user's Role")
|
return u, fmt.Errorf("Only Admin can update user's Role")
|
||||||
} else {
|
} else if role == "Admin" && r.Role != "" {
|
||||||
u.Role = r.Role
|
u.Role = r.Role
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,10 @@ func (r *updateUserRequest) updatedUser(role interface{},
|
||||||
if err := u.ByUsername(r.Username); err == nil {
|
if err := u.ByUsername(r.Username); err == nil {
|
||||||
return u, fmt.Errorf("Username is alreaday taken")
|
return u, fmt.Errorf("Username is alreaday taken")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.Username != "" {
|
||||||
u.Username = r.Username
|
u.Username = r.Username
|
||||||
|
}
|
||||||
|
|
||||||
// If there is a new password then hash it and update it
|
// If there is a new password then hash it and update it
|
||||||
if r.Password != "" {
|
if r.Password != "" {
|
||||||
|
@ -74,8 +77,10 @@ func (r *updateUserRequest) updatedUser(role interface{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update male
|
// Update mail
|
||||||
|
if r.Mail != "" {
|
||||||
u.Mail = r.Mail
|
u.Mail = r.Mail
|
||||||
|
}
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,9 +225,7 @@ func addUser(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{"user": newUser.User})
|
||||||
"id": newUser.ID,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser godoc
|
// UpdateUser godoc
|
||||||
|
@ -319,9 +317,7 @@ func updateUser(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{"user": updatedUser.User})
|
||||||
"id": updatedUser.ID,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUser godoc
|
// GetUser godoc
|
||||||
|
@ -393,7 +389,5 @@ func deleteUser(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{"user": user})
|
||||||
"id": user.ID,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue