mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-11-11 07:41:10 +00:00
WA-9 - implemented wallet
This commit is contained in:
@@ -17,9 +17,9 @@ type UsersService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
func (us *UsersService) Create(registerBody *models.UserModel) (*models.UserModel, *models.ExceptionModel) {
|
||||
check := new(models.UserModel)
|
||||
exceptionReturn := new(models.ExceptionModel)
|
||||
func (us *UsersService) Create(registerBody *models.User) (*models.User, *models.Exception) {
|
||||
check := new(models.User)
|
||||
exceptionReturn := new(models.Exception)
|
||||
|
||||
us.Db.Model(check).Where("? = ?", pg.Ident("username"), registerBody.Username).WhereOr("? = ?", pg.Ident("email"), registerBody.Email).Select()
|
||||
if check.Username != "" || check.Email != "" {
|
||||
@@ -44,10 +44,10 @@ func (us *UsersService) Create(registerBody *models.UserModel) (*models.UserMode
|
||||
return registerBody, exceptionReturn
|
||||
}
|
||||
|
||||
func (us *UsersService) Login(loginBody *models.LoginModel) (*models.TokenModel, *models.ExceptionModel) {
|
||||
check := new(models.UserModel)
|
||||
exceptionReturn := new(models.ExceptionModel)
|
||||
tokenPayload := new(models.TokenModel)
|
||||
func (us *UsersService) Login(loginBody *models.Login) (*models.Token, *models.Exception) {
|
||||
check := new(models.User)
|
||||
exceptionReturn := new(models.Exception)
|
||||
tokenPayload := new(models.Token)
|
||||
|
||||
us.Db.Model(check).Where("? = ?", pg.Ident("email"), loginBody.Email).Select()
|
||||
if check.Email == "" {
|
||||
@@ -72,7 +72,7 @@ func (us *UsersService) Login(loginBody *models.LoginModel) (*models.TokenModel,
|
||||
return tokenPayload, exceptionReturn
|
||||
}
|
||||
|
||||
func CreateToken(user *models.UserModel) (string, error) {
|
||||
func CreateToken(user *models.User) (string, error) {
|
||||
atClaims := jwt.MapClaims{}
|
||||
atClaims["authorized"] = true
|
||||
atClaims["id"] = user.Id
|
||||
|
||||
@@ -11,30 +11,21 @@ type WalletService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
func (as *WalletService) New(am *models.AuthModel) *models.WalletModel {
|
||||
walletType := as.GetType()
|
||||
func (as *WalletService) New(am *models.NewWalletBody) *models.Wallet {
|
||||
|
||||
walletModel := new(models.WalletModel)
|
||||
walletModel := new(models.Wallet)
|
||||
walletModel.Init()
|
||||
walletModel.UserID = am.Id
|
||||
walletModel.WalletTypeID = walletType.Id
|
||||
walletModel.UserID = am.UserID
|
||||
walletModel.Name = am.Name
|
||||
as.Db.Model(walletModel).Insert()
|
||||
return walletModel
|
||||
}
|
||||
|
||||
func (as *WalletService) Get(am *models.AuthModel, embed string) *models.WalletModel {
|
||||
wm := new(models.WalletModel)
|
||||
func (as *WalletService) Get(am *models.Auth, embed string) *models.Wallet {
|
||||
wm := new(models.Wallet)
|
||||
|
||||
query := as.Db.Model(wm).Where("? = ?", pg.Ident("user_id"), am.Id)
|
||||
common.GenerateEmbed(query, embed).Select()
|
||||
|
||||
return wm
|
||||
}
|
||||
|
||||
func (as *WalletService) GetType() *models.WalletTypeModel {
|
||||
wt := new(models.WalletTypeModel)
|
||||
|
||||
as.Db.Model(wt).Select()
|
||||
|
||||
return wt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user