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:
BIN
cmd/api/__debug_bin
Executable file
BIN
cmd/api/__debug_bin
Executable file
Binary file not shown.
@@ -11,6 +11,7 @@ type ApiController struct {
|
|||||||
ApiService *services.ApiService
|
ApiService *services.ApiService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes ApiController.
|
||||||
func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiController {
|
func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiController {
|
||||||
ac := new(ApiController)
|
ac := new(ApiController)
|
||||||
ac.ApiService = as
|
ac.ApiService = as
|
||||||
@@ -21,11 +22,15 @@ func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiControlle
|
|||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /api).
|
||||||
func (ac *ApiController) getFirst(c *gin.Context) {
|
func (ac *ApiController) getFirst(c *gin.Context) {
|
||||||
apiModel := ac.ApiService.GetFirst(c)
|
apiModel := ac.ApiService.GetFirst(c)
|
||||||
c.JSON(200, apiModel)
|
c.JSON(200, apiModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /api/migrate).
|
||||||
|
//
|
||||||
|
// Requires "SECRET_CODE", "VERSION" (optional) from body.
|
||||||
func (ac *ApiController) postMigrate(c *gin.Context) {
|
func (ac *ApiController) postMigrate(c *gin.Context) {
|
||||||
migrateModel := c.MustGet("migrate")
|
migrateModel := c.MustGet("migrate")
|
||||||
version := migrateModel.(middleware.SecretCodeModel).Version
|
version := migrateModel.(middleware.SecretCodeModel).Version
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ type AuthController struct {
|
|||||||
UsersService *services.UsersService
|
UsersService *services.UsersService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes AuthController.
|
||||||
func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthController {
|
func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthController {
|
||||||
rc := new(AuthController)
|
rc := new(AuthController)
|
||||||
rc.UsersService = rs
|
rc.UsersService = rs
|
||||||
@@ -25,6 +26,7 @@ func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthContr
|
|||||||
return rc
|
return rc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /auth/login).
|
||||||
func (rc *AuthController) PostLogin(c *gin.Context) {
|
func (rc *AuthController) PostLogin(c *gin.Context) {
|
||||||
body := new(models.Login)
|
body := new(models.Login)
|
||||||
if err := c.ShouldBind(&body); err != nil {
|
if err := c.ShouldBind(&body); err != nil {
|
||||||
@@ -40,6 +42,7 @@ func (rc *AuthController) PostLogin(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /auth/register).
|
||||||
func (rc *AuthController) PostRegister(c *gin.Context) {
|
func (rc *AuthController) PostRegister(c *gin.Context) {
|
||||||
body := new(models.User)
|
body := new(models.User)
|
||||||
body.Init()
|
body.Init()
|
||||||
@@ -56,6 +59,8 @@ func (rc *AuthController) PostRegister(c *gin.Context) {
|
|||||||
c.JSON(200, returnedUser.Payload())
|
c.JSON(200, returnedUser.Payload())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (DELETE /auth/deactivate).
|
||||||
func (rc *AuthController) Delete(c *gin.Context) {
|
func (rc *AuthController) Delete(c *gin.Context) {
|
||||||
auth := new(models.Auth)
|
auth := new(models.Auth)
|
||||||
authGet := c.MustGet("auth")
|
authGet := c.MustGet("auth")
|
||||||
@@ -70,6 +75,7 @@ func (rc *AuthController) Delete(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /auth/check-token).
|
||||||
func (rc *AuthController) CheckToken(c *gin.Context) {
|
func (rc *AuthController) CheckToken(c *gin.Context) {
|
||||||
token, _ := c.GetQuery("token")
|
token, _ := c.GetQuery("token")
|
||||||
re := new(models.CheckToken)
|
re := new(models.CheckToken)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Gets query parameters and populates FilteredResponse model.
|
||||||
func FilteredResponse(c *gin.Context) *models.FilteredResponse {
|
func FilteredResponse(c *gin.Context) *models.FilteredResponse {
|
||||||
filtered := new(models.FilteredResponse)
|
filtered := new(models.FilteredResponse)
|
||||||
page, _ := c.GetQuery("page")
|
page, _ := c.GetQuery("page")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type SubscriptionTypeController struct {
|
|||||||
SubscriptionTypeService *services.SubscriptionTypeService
|
SubscriptionTypeService *services.SubscriptionTypeService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes SubscriptionTypeController.
|
||||||
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.RouterGroup) *SubscriptionTypeController {
|
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.RouterGroup) *SubscriptionTypeController {
|
||||||
wc := new(SubscriptionTypeController)
|
wc := new(SubscriptionTypeController)
|
||||||
wc.SubscriptionTypeService = as
|
wc.SubscriptionTypeService = as
|
||||||
@@ -22,6 +23,7 @@ func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.
|
|||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /subscription-types)
|
||||||
func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
||||||
body := new(models.NewSubscriptionTypeBody)
|
body := new(models.NewSubscriptionTypeBody)
|
||||||
if err := c.ShouldBind(body); err != nil {
|
if err := c.ShouldBind(body); err != nil {
|
||||||
@@ -33,6 +35,7 @@ func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /subscription-types)
|
||||||
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type SubscriptionController struct {
|
|||||||
SubscriptionService *services.SubscriptionService
|
SubscriptionService *services.SubscriptionService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes SubscriptionController.
|
||||||
func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGroup) *SubscriptionController {
|
func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGroup) *SubscriptionController {
|
||||||
wc := new(SubscriptionController)
|
wc := new(SubscriptionController)
|
||||||
wc.SubscriptionService = as
|
wc.SubscriptionService = as
|
||||||
@@ -23,12 +24,13 @@ func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGr
|
|||||||
|
|
||||||
se := s.Group("/end")
|
se := s.Group("/end")
|
||||||
{
|
{
|
||||||
se.POST("", wc.End)
|
se.PUT("/:id", wc.End)
|
||||||
}
|
}
|
||||||
|
|
||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /subscription)
|
||||||
func (wc *SubscriptionController) New(c *gin.Context) {
|
func (wc *SubscriptionController) New(c *gin.Context) {
|
||||||
body := new(models.NewSubscriptionBody)
|
body := new(models.NewSubscriptionBody)
|
||||||
if err := c.ShouldBind(body); err != nil {
|
if err := c.ShouldBind(body); err != nil {
|
||||||
@@ -40,6 +42,7 @@ func (wc *SubscriptionController) New(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (PUT /subscription/:id)
|
||||||
func (wc *SubscriptionController) Edit(c *gin.Context) {
|
func (wc *SubscriptionController) Edit(c *gin.Context) {
|
||||||
body := new(models.SubscriptionEdit)
|
body := new(models.SubscriptionEdit)
|
||||||
if err := c.ShouldBind(body); err != nil {
|
if err := c.ShouldBind(body); err != nil {
|
||||||
@@ -53,6 +56,7 @@ func (wc *SubscriptionController) Edit(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /subscription/:id)
|
||||||
func (wc *SubscriptionController) Get(c *gin.Context) {
|
func (wc *SubscriptionController) Get(c *gin.Context) {
|
||||||
body := new(models.Auth)
|
body := new(models.Auth)
|
||||||
params := new(models.Params)
|
params := new(models.Params)
|
||||||
@@ -70,6 +74,7 @@ func (wc *SubscriptionController) Get(c *gin.Context) {
|
|||||||
c.JSON(200, fr)
|
c.JSON(200, fr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (PUT /subscription/end/:id)
|
||||||
func (wc *SubscriptionController) End(c *gin.Context) {
|
func (wc *SubscriptionController) End(c *gin.Context) {
|
||||||
body := new(models.Auth)
|
body := new(models.Auth)
|
||||||
|
|
||||||
@@ -82,13 +87,14 @@ func (wc *SubscriptionController) End(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id := end.Id
|
id := c.Param("id")
|
||||||
|
|
||||||
fr := wc.SubscriptionService.End(c, id)
|
fr := wc.SubscriptionService.End(c, id)
|
||||||
|
|
||||||
c.JSON(200, fr)
|
c.JSON(200, fr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /subscription)
|
||||||
func (wc *SubscriptionController) GetAll(c *gin.Context) {
|
func (wc *SubscriptionController) GetAll(c *gin.Context) {
|
||||||
body := new(models.Auth)
|
body := new(models.Auth)
|
||||||
auth := c.MustGet("auth")
|
auth := c.MustGet("auth")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type TransactionTypeController struct {
|
|||||||
TransactionTypeService *services.TransactionTypeService
|
TransactionTypeService *services.TransactionTypeService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes TransactionTypeController.
|
||||||
func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.RouterGroup) *TransactionTypeController {
|
func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.RouterGroup) *TransactionTypeController {
|
||||||
wc := new(TransactionTypeController)
|
wc := new(TransactionTypeController)
|
||||||
wc.TransactionTypeService = as
|
wc.TransactionTypeService = as
|
||||||
@@ -22,6 +23,7 @@ func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.Ro
|
|||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /transaction-types)
|
||||||
func (wc *TransactionTypeController) New(c *gin.Context) {
|
func (wc *TransactionTypeController) New(c *gin.Context) {
|
||||||
body := new(models.NewTransactionTypeBody)
|
body := new(models.NewTransactionTypeBody)
|
||||||
if err := c.ShouldBind(body); err != nil {
|
if err := c.ShouldBind(body); err != nil {
|
||||||
@@ -33,6 +35,7 @@ func (wc *TransactionTypeController) New(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /transaction-types)
|
||||||
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type TransactionController struct {
|
|||||||
TransactionService *services.TransactionService
|
TransactionService *services.TransactionService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes TransactionController.
|
||||||
func NewTransactionController(as *services.TransactionService, s *gin.RouterGroup) *TransactionController {
|
func NewTransactionController(as *services.TransactionService, s *gin.RouterGroup) *TransactionController {
|
||||||
wc := new(TransactionController)
|
wc := new(TransactionController)
|
||||||
wc.TransactionService = as
|
wc.TransactionService = as
|
||||||
@@ -24,6 +25,7 @@ func NewTransactionController(as *services.TransactionService, s *gin.RouterGrou
|
|||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /transactions)
|
||||||
func (wc *TransactionController) New(c *gin.Context) {
|
func (wc *TransactionController) New(c *gin.Context) {
|
||||||
body := new(models.NewTransactionBody)
|
body := new(models.NewTransactionBody)
|
||||||
if err := c.ShouldBind(body); err != nil {
|
if err := c.ShouldBind(body); err != nil {
|
||||||
@@ -35,6 +37,7 @@ func (wc *TransactionController) New(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /transactions)
|
||||||
func (wc *TransactionController) GetAll(c *gin.Context) {
|
func (wc *TransactionController) GetAll(c *gin.Context) {
|
||||||
body := new(models.Auth)
|
body := new(models.Auth)
|
||||||
auth := c.MustGet("auth")
|
auth := c.MustGet("auth")
|
||||||
@@ -48,6 +51,7 @@ func (wc *TransactionController) GetAll(c *gin.Context) {
|
|||||||
c.JSON(200, fr)
|
c.JSON(200, fr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (PUT /transactions/:id)
|
||||||
func (wc *TransactionController) Edit(c *gin.Context) {
|
func (wc *TransactionController) Edit(c *gin.Context) {
|
||||||
body := new(models.TransactionEdit)
|
body := new(models.TransactionEdit)
|
||||||
if err := c.ShouldBind(body); err != nil {
|
if err := c.ShouldBind(body); err != nil {
|
||||||
@@ -61,6 +65,7 @@ func (wc *TransactionController) Edit(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /transactions/:id)
|
||||||
func (wc *TransactionController) Get(c *gin.Context) {
|
func (wc *TransactionController) Get(c *gin.Context) {
|
||||||
body := new(models.Auth)
|
body := new(models.Auth)
|
||||||
params := new(models.Params)
|
params := new(models.Params)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type WalletsHeaderController struct {
|
|||||||
WalletService *services.WalletService
|
WalletService *services.WalletService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes WalletsHeaderController.
|
||||||
func NewWalletsHeaderController(as *services.WalletService, s *gin.RouterGroup) *WalletsHeaderController {
|
func NewWalletsHeaderController(as *services.WalletService, s *gin.RouterGroup) *WalletsHeaderController {
|
||||||
wc := new(WalletsHeaderController)
|
wc := new(WalletsHeaderController)
|
||||||
wc.WalletService = as
|
wc.WalletService = as
|
||||||
@@ -20,6 +21,7 @@ func NewWalletsHeaderController(as *services.WalletService, s *gin.RouterGroup)
|
|||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /wallet/wallet-header)
|
||||||
func (wc *WalletsHeaderController) Get(c *gin.Context) {
|
func (wc *WalletsHeaderController) Get(c *gin.Context) {
|
||||||
body := new(models.Auth)
|
body := new(models.Auth)
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type WalletsController struct {
|
|||||||
WalletService *services.WalletService
|
WalletService *services.WalletService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes WalletsController.
|
||||||
func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *WalletsController {
|
func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *WalletsController {
|
||||||
wc := new(WalletsController)
|
wc := new(WalletsController)
|
||||||
wc.WalletService = as
|
wc.WalletService = as
|
||||||
@@ -24,6 +25,7 @@ func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *Walle
|
|||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (POST /wallet)
|
||||||
func (wc *WalletsController) New(c *gin.Context) {
|
func (wc *WalletsController) New(c *gin.Context) {
|
||||||
body := new(models.NewWalletBody)
|
body := new(models.NewWalletBody)
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ func (wc *WalletsController) New(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /wallet)
|
||||||
func (wc *WalletsController) GetAll(c *gin.Context) {
|
func (wc *WalletsController) GetAll(c *gin.Context) {
|
||||||
body := new(models.Auth)
|
body := new(models.Auth)
|
||||||
auth := c.MustGet("auth")
|
auth := c.MustGet("auth")
|
||||||
@@ -51,6 +54,7 @@ func (wc *WalletsController) GetAll(c *gin.Context) {
|
|||||||
c.JSON(200, fr)
|
c.JSON(200, fr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (PUT /wallet/:id)
|
||||||
func (wc *WalletsController) Edit(c *gin.Context) {
|
func (wc *WalletsController) Edit(c *gin.Context) {
|
||||||
body := new(models.WalletEdit)
|
body := new(models.WalletEdit)
|
||||||
if err := c.ShouldBind(body); err != nil {
|
if err := c.ShouldBind(body); err != nil {
|
||||||
@@ -64,6 +68,7 @@ func (wc *WalletsController) Edit(c *gin.Context) {
|
|||||||
c.JSON(200, wm)
|
c.JSON(200, wm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ROUTE (GET /wallet/:id)
|
||||||
func (wc *WalletsController) Get(c *gin.Context) {
|
func (wc *WalletsController) Get(c *gin.Context) {
|
||||||
params := new(models.Params)
|
params := new(models.Params)
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Auth Middleware.
|
||||||
|
//
|
||||||
|
// Checks if token from header is valid and extracts the id.
|
||||||
func Auth(c *gin.Context) {
|
func Auth(c *gin.Context) {
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
tokenString := ExtractToken(c)
|
tokenString := ExtractToken(c)
|
||||||
@@ -34,6 +37,7 @@ func Auth(c *gin.Context) {
|
|||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extracts token from header
|
||||||
func ExtractToken(c *gin.Context) string {
|
func ExtractToken(c *gin.Context) string {
|
||||||
bearerToken := c.GetHeader("Authorization")
|
bearerToken := c.GetHeader("Authorization")
|
||||||
tokenArr := strings.Split(bearerToken, " ")
|
tokenArr := strings.Split(bearerToken, " ")
|
||||||
@@ -46,6 +50,7 @@ func ExtractToken(c *gin.Context) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if token is valid
|
||||||
func CheckToken(tokenString string) (*jwt.Token, error) {
|
func CheckToken(tokenString string) (*jwt.Token, error) {
|
||||||
secret := os.Getenv("ACCESS_SECRET")
|
secret := os.Getenv("ACCESS_SECRET")
|
||||||
if secret == "" {
|
if secret == "" {
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package middleware
|
|||||||
|
|
||||||
import "github.com/gin-gonic/gin"
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
// CORS Middleware.
|
||||||
|
//
|
||||||
|
// Add needed headers to make cors functioning.
|
||||||
func CORSMiddleware() gin.HandlerFunc {
|
func CORSMiddleware() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Secret Code Middleware.
|
||||||
|
//
|
||||||
|
// Checks if secret code from body is valid.
|
||||||
func SecretCode(c *gin.Context) {
|
func SecretCode(c *gin.Context) {
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
secretCode := ExtractCode(c)
|
secretCode := ExtractCode(c)
|
||||||
@@ -26,6 +29,7 @@ func SecretCode(c *gin.Context) {
|
|||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extracts the secret code from body
|
||||||
func ExtractCode(c *gin.Context) SecretCodeModel {
|
func ExtractCode(c *gin.Context) SecretCodeModel {
|
||||||
secret := new(SecretCodeModel)
|
secret := new(SecretCodeModel)
|
||||||
if err := c.ShouldBindJSON(&secret); err != nil {
|
if err := c.ShouldBindJSON(&secret); err != nil {
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"log"
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10/orm"
|
"github.com/go-pg/pg/v10/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates api table if it does not exist.
|
||||||
func CreateTableApi(db pg.DB) error {
|
func CreateTableApi(db pg.DB) error {
|
||||||
|
|
||||||
models := []interface{}{
|
models := []interface{}{
|
||||||
@@ -20,10 +22,10 @@ func CreateTableApi(db pg.DB) error {
|
|||||||
IfNotExists: true,
|
IfNotExists: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error Creating Table: %s", err)
|
log.Printf("Error creating table \"api\": %s", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Table created successfully")
|
fmt.Println("Table \"api\" created successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"log"
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10/orm"
|
"github.com/go-pg/pg/v10/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates api users if it does not exist.
|
||||||
func CreateTableUsers(db pg.DB) error {
|
func CreateTableUsers(db pg.DB) error {
|
||||||
models := []interface{}{
|
models := []interface{}{
|
||||||
(*models.User)(nil),
|
(*models.User)(nil),
|
||||||
@@ -20,10 +21,10 @@ func CreateTableUsers(db pg.DB) error {
|
|||||||
IfNotExists: true,
|
IfNotExists: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error Creating Table: %s", err)
|
log.Printf("Error creating table \"users\": %s", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Table created successfully")
|
fmt.Println("Table \"users\" created successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"log"
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10/orm"
|
"github.com/go-pg/pg/v10/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates wallets table if it does not exist.
|
||||||
func CreateTableWallets(db pg.DB) error {
|
func CreateTableWallets(db pg.DB) error {
|
||||||
models := []interface{}{
|
models := []interface{}{
|
||||||
(*models.Wallet)(nil),
|
(*models.Wallet)(nil),
|
||||||
@@ -20,10 +22,10 @@ func CreateTableWallets(db pg.DB) error {
|
|||||||
FKConstraints: true,
|
FKConstraints: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error Creating Table: %s", err)
|
log.Printf("Error creating table \"wallets\": %s", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Table created successfully")
|
fmt.Println("Table \"wallets\" created successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"log"
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10/orm"
|
"github.com/go-pg/pg/v10/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates transactionTypes table if it does not exist.
|
||||||
func CreateTableTransactionTypes(db pg.DB) error {
|
func CreateTableTransactionTypes(db pg.DB) error {
|
||||||
models := []interface{}{
|
models := []interface{}{
|
||||||
(*models.TransactionType)(nil),
|
(*models.TransactionType)(nil),
|
||||||
@@ -20,10 +22,10 @@ func CreateTableTransactionTypes(db pg.DB) error {
|
|||||||
FKConstraints: true,
|
FKConstraints: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error Creating Table: %s", err)
|
log.Printf("Error creating table \"api\": %s", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Table created successfully")
|
fmt.Println("Table \"api\" created successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"log"
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10/orm"
|
"github.com/go-pg/pg/v10/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates api transactions if it does not exist.
|
||||||
func CreateTableTransactions(db pg.DB) error {
|
func CreateTableTransactions(db pg.DB) error {
|
||||||
models := []interface{}{
|
models := []interface{}{
|
||||||
(*models.Transaction)(nil),
|
(*models.Transaction)(nil),
|
||||||
@@ -21,10 +22,10 @@ func CreateTableTransactions(db pg.DB) error {
|
|||||||
FKConstraints: true,
|
FKConstraints: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error Creating Table: %s", err)
|
log.Printf("Error creating table \"transactions\": %s", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Table created successfully")
|
fmt.Println("Table \"transactions\" created successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"log"
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10/orm"
|
"github.com/go-pg/pg/v10/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates subscriptionTypes table if it does not exist.
|
||||||
func CreateTableSubscriptionTypes(db pg.DB) error {
|
func CreateTableSubscriptionTypes(db pg.DB) error {
|
||||||
models := []interface{}{
|
models := []interface{}{
|
||||||
(*models.SubscriptionType)(nil),
|
(*models.SubscriptionType)(nil),
|
||||||
@@ -20,10 +22,10 @@ func CreateTableSubscriptionTypes(db pg.DB) error {
|
|||||||
FKConstraints: true,
|
FKConstraints: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error Creating Table: %s", err)
|
log.Printf("Error creating table \"subscriptionTypes\": %s", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Table created successfully")
|
fmt.Println("Table \"subscriptionTypes\" created successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-pg/pg/v10"
|
|
||||||
"github.com/go-pg/pg/v10/orm"
|
|
||||||
"log"
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
"github.com/go-pg/pg/v10/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates subscriptions table if it does not exist.
|
||||||
func CreateTableSubscriptions(db pg.DB) error {
|
func CreateTableSubscriptions(db pg.DB) error {
|
||||||
models := []interface{}{
|
models := []interface{}{
|
||||||
(*models.Subscription)(nil),
|
(*models.Subscription)(nil),
|
||||||
@@ -19,10 +21,10 @@ func CreateTableSubscriptions(db pg.DB) error {
|
|||||||
FKConstraints: true,
|
FKConstraints: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error Creating Table: %s", err)
|
log.Printf("Error creating table \"subscriptions\": %s", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Table created successfully")
|
fmt.Println("Table \"subscriptions\" created successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package migrate
|
package migrate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-pg/pg/v10"
|
"fmt"
|
||||||
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Populates subscriptionTypes table if it does not exist.
|
||||||
func PopulateSubscriptionTypes(db pg.DB) error {
|
func PopulateSubscriptionTypes(db pg.DB) error {
|
||||||
daily := new(models.SubscriptionType)
|
daily := new(models.SubscriptionType)
|
||||||
weekly := new(models.SubscriptionType)
|
weekly := new(models.SubscriptionType)
|
||||||
@@ -28,12 +32,35 @@ func PopulateSubscriptionTypes(db pg.DB) error {
|
|||||||
yearly.Type = "yearly"
|
yearly.Type = "yearly"
|
||||||
|
|
||||||
_, err := db.Model(daily).Where("? = ?", pg.Ident("type"), daily.Type).SelectOrInsert()
|
_, err := db.Model(daily).Where("? = ?", pg.Ident("type"), daily.Type).SelectOrInsert()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
|
||||||
|
}
|
||||||
_, err = db.Model(weekly).Where("? = ?", pg.Ident("type"), weekly.Type).SelectOrInsert()
|
_, err = db.Model(weekly).Where("? = ?", pg.Ident("type"), weekly.Type).SelectOrInsert()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = db.Model(monthly).Where("? = ?", pg.Ident("type"), monthly.Type).SelectOrInsert()
|
_, err = db.Model(monthly).Where("? = ?", pg.Ident("type"), monthly.Type).SelectOrInsert()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = db.Model(yearly).Where("? = ?", pg.Ident("type"), yearly.Type).SelectOrInsert()
|
_, err = db.Model(yearly).Where("? = ?", pg.Ident("type"), yearly.Type).SelectOrInsert()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error inserting row into \"subscriptionTypes\" table: %s", err)
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
fmt.Println("Row inserted successfully into \"subscriptionTypes\" table.")
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package migrate
|
package migrate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-pg/pg/v10"
|
"fmt"
|
||||||
|
"log"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Populates transactionTypes table if it does not exist.
|
||||||
func PopulateTransactionTypes(db pg.DB) error {
|
func PopulateTransactionTypes(db pg.DB) error {
|
||||||
gain := new(models.TransactionType)
|
gain := new(models.TransactionType)
|
||||||
expense := new(models.TransactionType)
|
expense := new(models.TransactionType)
|
||||||
@@ -18,8 +22,20 @@ func PopulateTransactionTypes(db pg.DB) error {
|
|||||||
expense.Type = "expense"
|
expense.Type = "expense"
|
||||||
|
|
||||||
_, err := db.Model(gain).Where("? = ?", pg.Ident("type"), gain.Type).SelectOrInsert()
|
_, err := db.Model(gain).Where("? = ?", pg.Ident("type"), gain.Type).SelectOrInsert()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error inserting row into \"transactionTypes\" table: %s", err)
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
fmt.Println("Row inserted successfully into \"transactionTypes\" table.")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = db.Model(expense).Where("? = ?", pg.Ident("type"), expense.Type).SelectOrInsert()
|
_, err = db.Model(expense).Where("? = ?", pg.Ident("type"), expense.Type).SelectOrInsert()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error inserting row into \"transactionTypes\" table: %s", err)
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
fmt.Println("Row inserted successfully into \"transactionTypes\" table.")
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/go-pg/pg/v10"
|
"github.com/go-pg/pg/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Starts database migration.
|
||||||
func Start(conn *pg.DB, version string) {
|
func Start(conn *pg.DB, version string) {
|
||||||
migration001 := Migration{
|
migration001 := Migration{
|
||||||
Version: "001",
|
Version: "001",
|
||||||
@@ -46,4 +47,3 @@ type Migration struct {
|
|||||||
Version string
|
Version string
|
||||||
Migrations []interface{}
|
Migrations []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type ApiService struct {
|
|||||||
Db *pg.DB
|
Db *pg.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets first row from API table.
|
||||||
func (as *ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
func (as *ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -20,6 +21,9 @@ func (as *ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
|||||||
return apiModel
|
return apiModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starts database migration.
|
||||||
|
//
|
||||||
|
// Takes migration version.
|
||||||
func (as *ApiService) PostMigrate(ctx context.Context, version string) (*models.MessageResponse, *models.Exception) {
|
func (as *ApiService) PostMigrate(ctx context.Context, version string) (*models.MessageResponse, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/go-pg/pg/v10"
|
"github.com/go-pg/pg/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Adds filters to query and executes it.
|
||||||
func FilteredResponse(qry *pg.Query, mdl interface{}, filtered *models.FilteredResponse) {
|
func FilteredResponse(qry *pg.Query, mdl interface{}, filtered *models.FilteredResponse) {
|
||||||
if filtered.Page == 0 {
|
if filtered.Page == 0 {
|
||||||
filtered.Page = 1
|
filtered.Page = 1
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type SubscriptionTypeService struct {
|
|||||||
Db *pg.DB
|
Db *pg.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts new row to subscription type table.
|
||||||
func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubscriptionTypeBody) *models.SubscriptionType {
|
func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubscriptionTypeBody) *models.SubscriptionType {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubs
|
|||||||
return tm
|
return tm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets all rows from subscription type table.
|
||||||
func (as *SubscriptionTypeService) GetAll(ctx context.Context, embed string) *[]models.SubscriptionType {
|
func (as *SubscriptionTypeService) GetAll(ctx context.Context, embed string) *[]models.SubscriptionType {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type SubscriptionService struct {
|
|||||||
Db *pg.DB
|
Db *pg.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts new row to subscription table.
|
||||||
func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscriptionBody) *models.Subscription {
|
func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscriptionBody) *models.Subscription {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscrip
|
|||||||
return tm
|
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 {
|
func (as *SubscriptionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) *models.Subscription {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -69,6 +71,7 @@ func (as *SubscriptionService) Get(ctx context.Context, am *models.Auth, id stri
|
|||||||
return wm
|
return wm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets filtered rows from subscription table.
|
||||||
func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
|
func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -91,6 +94,7 @@ func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, wall
|
|||||||
tx.Commit()
|
tx.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updates row from subscription table by id.
|
||||||
func (as *SubscriptionService) Edit(ctx context.Context, body *models.SubscriptionEdit, id string) *models.Subscription {
|
func (as *SubscriptionService) Edit(ctx context.Context, body *models.SubscriptionEdit, id string) *models.Subscription {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -114,6 +118,9 @@ func (as *SubscriptionService) Edit(ctx context.Context, body *models.Subscripti
|
|||||||
return tm
|
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 {
|
func (as *SubscriptionService) End(ctx context.Context, id string) *models.Subscription {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -132,6 +139,7 @@ func (as *SubscriptionService) End(ctx context.Context, id string) *models.Subsc
|
|||||||
return tm
|
return tm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates and Inserts new Transaction rows from the subscription model.
|
||||||
func (as *SubscriptionService) SubToTrans(subModel *models.Subscription, tx *pg.Tx) {
|
func (as *SubscriptionService) SubToTrans(subModel *models.Subscription, tx *pg.Tx) {
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type TransactionTypeService struct {
|
|||||||
Db *pg.DB
|
Db *pg.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts new row to transaction type table.
|
||||||
func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTransactionTypeBody) *models.TransactionType {
|
func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTransactionTypeBody) *models.TransactionType {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTrans
|
|||||||
return tm
|
return tm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets all rows from transaction type table.
|
||||||
func (as *TransactionTypeService) GetAll(ctx context.Context, embed string) *[]models.TransactionType {
|
func (as *TransactionTypeService) GetAll(ctx context.Context, embed string) *[]models.TransactionType {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type TransactionService struct {
|
|||||||
Ss *SubscriptionService
|
Ss *SubscriptionService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts new row to transaction table.
|
||||||
func (as *TransactionService) New(ctx context.Context, body *models.NewTransactionBody) *models.Transaction {
|
func (as *TransactionService) New(ctx context.Context, body *models.NewTransactionBody) *models.Transaction {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ func (as *TransactionService) New(ctx context.Context, body *models.NewTransacti
|
|||||||
return tm
|
return tm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets filtered rows from transaction table.
|
||||||
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
|
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -73,6 +75,7 @@ func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walle
|
|||||||
tx.Commit()
|
tx.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updates row in transaction table by id.
|
||||||
func (as *TransactionService) Edit(ctx context.Context, body *models.TransactionEdit, id string) *models.Transaction {
|
func (as *TransactionService) Edit(ctx context.Context, body *models.TransactionEdit, id string) *models.Transaction {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -96,6 +99,7 @@ func (as *TransactionService) Edit(ctx context.Context, body *models.Transaction
|
|||||||
return tm
|
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 {
|
func (as *TransactionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) *models.Transaction {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type UsersService struct {
|
|||||||
Db *pg.DB
|
Db *pg.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts new row to users table.
|
||||||
func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (*models.User, *models.Exception) {
|
func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (*models.User, *models.Exception) {
|
||||||
db := us.Db.WithContext(ctx)
|
db := us.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (
|
|||||||
return registerBody, exceptionReturn
|
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) {
|
func (us *UsersService) Login(ctx context.Context, loginBody *models.Login) (*models.Token, *models.Exception) {
|
||||||
db := us.Db.WithContext(ctx)
|
db := us.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -89,6 +91,9 @@ func (us *UsersService) Login(ctx context.Context, loginBody *models.Login) (*mo
|
|||||||
return tokenPayload, exceptionReturn
|
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) {
|
func (us *UsersService) Deactivate(ctx context.Context, auth *models.Auth) (*models.MessageResponse, *models.Exception) {
|
||||||
db := us.Db.WithContext(ctx)
|
db := us.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -124,6 +129,9 @@ func (us *UsersService) Deactivate(ctx context.Context, auth *models.Auth) (*mod
|
|||||||
return mm, me
|
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) {
|
func CreateToken(user *models.User, rememberMe bool) (string, error) {
|
||||||
atClaims := jwt.MapClaims{}
|
atClaims := jwt.MapClaims{}
|
||||||
atClaims["authorized"] = true
|
atClaims["authorized"] = true
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type WalletService struct {
|
|||||||
Ss *SubscriptionService
|
Ss *SubscriptionService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts row to wallets table.
|
||||||
func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) *models.Wallet {
|
func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) *models.Wallet {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) *mod
|
|||||||
return walletModel
|
return walletModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updates row in wallets table by id.
|
||||||
func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id string) *models.Wallet {
|
func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id string) *models.Wallet {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id s
|
|||||||
return tm
|
return tm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets row in wallets table by id.
|
||||||
func (as *WalletService) Get(ctx context.Context, id string, params *models.Params) *models.Wallet {
|
func (as *WalletService) Get(ctx context.Context, id string, params *models.Params) *models.Wallet {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -59,6 +62,7 @@ func (as *WalletService) Get(ctx context.Context, id string, params *models.Para
|
|||||||
return wm
|
return wm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets filtered rows from wallets table.
|
||||||
func (as *WalletService) GetAll(ctx context.Context, am *models.Auth, filtered *models.FilteredResponse) {
|
func (as *WalletService) GetAll(ctx context.Context, am *models.Auth, filtered *models.FilteredResponse) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
wm := new([]models.Wallet)
|
wm := new([]models.Wallet)
|
||||||
@@ -67,6 +71,9 @@ func (as *WalletService) GetAll(ctx context.Context, am *models.Auth, filtered *
|
|||||||
FilteredResponse(query, wm, 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 {
|
func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletId string) *models.WalletHeader {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.Db.WithContext(ctx)
|
||||||
|
|
||||||
@@ -174,6 +181,9 @@ func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletI
|
|||||||
return wm
|
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) {
|
func addWhere(s *[]models.WalletTransactions, walletId string, e models.Transaction) {
|
||||||
var exists bool
|
var exists bool
|
||||||
for a := range *s {
|
for a := range *s {
|
||||||
|
|||||||
Reference in New Issue
Block a user