mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
added documentation comments to methods
This commit is contained in:
@@ -12,6 +12,7 @@ type ApiService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
// Gets first row from API table.
|
||||
func (as *ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -20,6 +21,9 @@ func (as *ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
||||
return apiModel
|
||||
}
|
||||
|
||||
// Starts database migration.
|
||||
//
|
||||
// Takes migration version.
|
||||
func (as *ApiService) PostMigrate(ctx context.Context, version string) (*models.MessageResponse, *models.Exception) {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
|
||||
// Adds filters to query and executes it.
|
||||
func FilteredResponse(qry *pg.Query, mdl interface{}, filtered *models.FilteredResponse) {
|
||||
if filtered.Page == 0 {
|
||||
filtered.Page = 1
|
||||
|
||||
@@ -12,6 +12,7 @@ type SubscriptionTypeService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
// Inserts new row to subscription type table.
|
||||
func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubscriptionTypeBody) *models.SubscriptionType {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -26,6 +27,7 @@ func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubs
|
||||
return tm
|
||||
}
|
||||
|
||||
// Gets all rows from subscription type table.
|
||||
func (as *SubscriptionTypeService) GetAll(ctx context.Context, embed string) *[]models.SubscriptionType {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ type SubscriptionService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
// Inserts new row to subscription table.
|
||||
func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscriptionBody) *models.Subscription {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -48,6 +49,7 @@ func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscrip
|
||||
return tm
|
||||
}
|
||||
|
||||
// Gets row from subscription table by id.
|
||||
func (as *SubscriptionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) *models.Subscription {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -69,6 +71,7 @@ func (as *SubscriptionService) Get(ctx context.Context, am *models.Auth, id stri
|
||||
return wm
|
||||
}
|
||||
|
||||
// Gets filtered rows from subscription table.
|
||||
func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -91,6 +94,7 @@ func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, wall
|
||||
tx.Commit()
|
||||
}
|
||||
|
||||
// Updates row from subscription table by id.
|
||||
func (as *SubscriptionService) Edit(ctx context.Context, body *models.SubscriptionEdit, id string) *models.Subscription {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -114,6 +118,9 @@ func (as *SubscriptionService) Edit(ctx context.Context, body *models.Subscripti
|
||||
return tm
|
||||
}
|
||||
|
||||
// Updates row in subscription table by id.
|
||||
//
|
||||
// Ends subscription with current date.
|
||||
func (as *SubscriptionService) End(ctx context.Context, id string) *models.Subscription {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -132,6 +139,7 @@ func (as *SubscriptionService) End(ctx context.Context, id string) *models.Subsc
|
||||
return tm
|
||||
}
|
||||
|
||||
// Generates and Inserts new Transaction rows from the subscription model.
|
||||
func (as *SubscriptionService) SubToTrans(subModel *models.Subscription, tx *pg.Tx) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
@@ -12,6 +12,7 @@ type TransactionTypeService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
// Inserts new row to transaction type table.
|
||||
func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTransactionTypeBody) *models.TransactionType {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -26,6 +27,7 @@ func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTrans
|
||||
return tm
|
||||
}
|
||||
|
||||
// Gets all rows from transaction type table.
|
||||
func (as *TransactionTypeService) GetAll(ctx context.Context, embed string) *[]models.TransactionType {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ type TransactionService struct {
|
||||
Ss *SubscriptionService
|
||||
}
|
||||
|
||||
// Inserts new row to transaction table.
|
||||
func (as *TransactionService) New(ctx context.Context, body *models.NewTransactionBody) *models.Transaction {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -42,6 +43,7 @@ func (as *TransactionService) New(ctx context.Context, body *models.NewTransacti
|
||||
return tm
|
||||
}
|
||||
|
||||
// Gets filtered rows from transaction table.
|
||||
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -73,6 +75,7 @@ func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walle
|
||||
tx.Commit()
|
||||
}
|
||||
|
||||
// Updates row in transaction table by id.
|
||||
func (as *TransactionService) Edit(ctx context.Context, body *models.TransactionEdit, id string) *models.Transaction {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -96,6 +99,7 @@ func (as *TransactionService) Edit(ctx context.Context, body *models.Transaction
|
||||
return tm
|
||||
}
|
||||
|
||||
// Gets row from transaction table by id.
|
||||
func (as *TransactionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) *models.Transaction {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ type UsersService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
// Inserts new row to users table.
|
||||
func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (*models.User, *models.Exception) {
|
||||
db := us.Db.WithContext(ctx)
|
||||
|
||||
@@ -52,6 +53,7 @@ func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (
|
||||
return registerBody, exceptionReturn
|
||||
}
|
||||
|
||||
// Gets row from users table by email and valid password.
|
||||
func (us *UsersService) Login(ctx context.Context, loginBody *models.Login) (*models.Token, *models.Exception) {
|
||||
db := us.Db.WithContext(ctx)
|
||||
|
||||
@@ -89,6 +91,9 @@ func (us *UsersService) Login(ctx context.Context, loginBody *models.Login) (*mo
|
||||
return tokenPayload, exceptionReturn
|
||||
}
|
||||
|
||||
// Updates row in users table.
|
||||
//
|
||||
// IsActive column is set to false
|
||||
func (us *UsersService) Deactivate(ctx context.Context, auth *models.Auth) (*models.MessageResponse, *models.Exception) {
|
||||
db := us.Db.WithContext(ctx)
|
||||
|
||||
@@ -124,6 +129,9 @@ func (us *UsersService) Deactivate(ctx context.Context, auth *models.Auth) (*mod
|
||||
return mm, me
|
||||
}
|
||||
|
||||
// Generates new jwt token.
|
||||
//
|
||||
// It encodes the user id. Based on rememberMe it is valid through 48hours or 2hours.
|
||||
func CreateToken(user *models.User, rememberMe bool) (string, error) {
|
||||
atClaims := jwt.MapClaims{}
|
||||
atClaims["authorized"] = true
|
||||
|
||||
@@ -14,6 +14,7 @@ type WalletService struct {
|
||||
Ss *SubscriptionService
|
||||
}
|
||||
|
||||
// Inserts row to wallets table.
|
||||
func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) *models.Wallet {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -25,6 +26,7 @@ func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) *mod
|
||||
return walletModel
|
||||
}
|
||||
|
||||
// Updates row in wallets table by id.
|
||||
func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id string) *models.Wallet {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -42,6 +44,7 @@ func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id s
|
||||
return tm
|
||||
}
|
||||
|
||||
// Gets row in wallets table by id.
|
||||
func (as *WalletService) Get(ctx context.Context, id string, params *models.Params) *models.Wallet {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -59,6 +62,7 @@ func (as *WalletService) Get(ctx context.Context, id string, params *models.Para
|
||||
return wm
|
||||
}
|
||||
|
||||
// Gets filtered rows from wallets table.
|
||||
func (as *WalletService) GetAll(ctx context.Context, am *models.Auth, filtered *models.FilteredResponse) {
|
||||
db := as.Db.WithContext(ctx)
|
||||
wm := new([]models.Wallet)
|
||||
@@ -67,6 +71,9 @@ func (as *WalletService) GetAll(ctx context.Context, am *models.Auth, filtered *
|
||||
FilteredResponse(query, wm, filtered)
|
||||
}
|
||||
|
||||
// Gets row from wallets table.
|
||||
//
|
||||
// Calculates previous month, current and next month totals.
|
||||
func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletId string) *models.WalletHeader {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
@@ -174,6 +181,9 @@ func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletI
|
||||
return wm
|
||||
}
|
||||
|
||||
// Appends Transaction to the belonging walletId
|
||||
//
|
||||
// If missing, it creates the item list.
|
||||
func addWhere(s *[]models.WalletTransactions, walletId string, e models.Transaction) {
|
||||
var exists bool
|
||||
for a := range *s {
|
||||
|
||||
Reference in New Issue
Block a user