From 616a151764fd1780eb0b6dc039d5a21539a8a01a Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 3 Sep 2023 00:19:03 +0530 Subject: added login with id --- user/service.go | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'user/service.go') diff --git a/user/service.go b/user/service.go index 8b3b712..5e0632b 100644 --- a/user/service.go +++ b/user/service.go @@ -17,23 +17,42 @@ package user +import ( + e "vidhukant.com/openbills/errors" +) + func (u *User) Create() error { res := db.Create(u) // TODO: handle potential errors return res.Error } -//func (c *Customer) del() error { -// res := db.Delete(c) -// -// // TODO: handle potential errors -// if res.Error != nil { -// return res.Error -// } -// -// if res.RowsAffected == 0 { -// return e.ErrNotFound -// } -// -// return nil -//} +func GetUser(user *User, id uint) error { + res := db.Find(&user, id) + + // TODO: handle potential errors + if res.Error != nil { + return res.Error + } + + if res.RowsAffected == 0 { + return e.ErrNotFound + } + + return nil +} + +func (u *User) del() error { + res := db.Delete(u) + + // TODO: handle potential errors + if res.Error != nil { + return res.Error + } + + if res.RowsAffected == 0 { + return e.ErrNotFound + } + + return nil +} -- cgit v1.2.3