test audit add
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-15 09:54:42 +11:00
parent 5920db48d8
commit 95125b691d
4 changed files with 56 additions and 13 deletions

View File

@@ -75,6 +75,7 @@ func DeleteUser(c *gin.Context) {
func AddUser(c *gin.Context) {
var input AddUserInput
var RequestingUserId int
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
@@ -91,6 +92,13 @@ func AddUser(c *gin.Context) {
return
}
if val, ok := c.Get("user-id"); !ok {
c.JSON(http.StatusBadRequest, gin.H{"error": "error determining user"})
return
} else {
RequestingUserId = val.(int)
}
u := models.User{}
u.UserName = input.UserName
u.Password = input.Password
@@ -155,6 +163,13 @@ func AddUser(c *gin.Context) {
return
}
// Create audit record
a := models.Audit{
UserId: RequestingUserId,
EventText: fmt.Sprintf("Created User Id %d", u.UserId),
}
a.AuditAdd()
c.JSON(http.StatusOK, gin.H{"message": "user registration success", "data": u})
}