Fix tests failing (#36)

Reviewed-on: #36
This commit was merged in pull request #36.
This commit is contained in:
2025-05-13 19:34:43 +02:00
parent f29eeae9d9
commit 94a20af04d
2 changed files with 16 additions and 8 deletions

View File

@@ -62,15 +62,15 @@ func getUser(c *gin.Context) {
}
user, err := db.GetUser(userId)
if errors.Is(err, mysqlite.ErrNoRows) {
c.JSON(http.StatusNotFound, gin.H{"error": ErrUserNotFound})
return
}
if err != nil {
log.Printf("Error getting user: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": ErrInternalServerError})
return
}
if user == nil {
c.JSON(http.StatusNotFound, gin.H{"error": ErrUserNotFound})
return
}
c.IndentedJSON(http.StatusOK, user)
}
@@ -305,6 +305,17 @@ func postAllowance(c *gin.Context) {
return
}
exists, err := db.UserExists(userId)
if err != nil {
log.Printf(ErrCheckingUserExist, err)
c.JSON(http.StatusInternalServerError, gin.H{"error": ErrInternalServerError})
return
}
if !exists {
c.JSON(http.StatusNotFound, gin.H{"error": ErrUserNotFound})
return
}
err = db.AddAllowance(userId, &allowanceRequest)
if err != nil {
log.Printf("Error updating allowance: %v", err)