Add GET /user/:userId/allowance/:allowanceId (#50)

Reviewed-on: #50
This commit was merged in pull request #50.
This commit is contained in:
2025-05-15 15:49:08 +02:00
parent 361baac8f3
commit 8fedac21bb
3 changed files with 96 additions and 0 deletions

View File

@@ -86,6 +86,17 @@ func (db *Db) GetUserAllowances(userId int) ([]Allowance, error) {
return allowances, nil
}
func (db *Db) GetUserAllowanceById(userId int, allowanceId int) (*Allowance, error) {
allowance := &Allowance{}
err := db.db.Query("select id, name, target, progress, weight from allowances where user_id = ? and id = ?").
Bind(userId, allowanceId).
ScanSingle(&allowance.ID, &allowance.Name, &allowance.Target, &allowance.Progress, &allowance.Weight)
if err != nil {
return nil, err
}
return allowance, nil
}
func (db *Db) CreateAllowance(userId int, allowance *CreateAllowanceRequest) (int, error) {
// Check if user exists before attempting to create an allowance
exists, err := db.UserExists(userId)