added documentation comments to methods

This commit is contained in:
Fran Jurmanovic
2021-08-02 10:19:58 -07:00
parent 05a13112f1
commit 0195528428
31 changed files with 175 additions and 33 deletions

View File

@@ -11,6 +11,7 @@ type ApiController struct {
ApiService *services.ApiService
}
// Initializes ApiController.
func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiController {
ac := new(ApiController)
ac.ApiService = as
@@ -21,11 +22,15 @@ func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiControlle
return ac
}
// ROUTE (GET /api).
func (ac *ApiController) getFirst(c *gin.Context) {
apiModel := ac.ApiService.GetFirst(c)
c.JSON(200, apiModel)
}
// ROUTE (POST /api/migrate).
//
// Requires "SECRET_CODE", "VERSION" (optional) from body.
func (ac *ApiController) postMigrate(c *gin.Context) {
migrateModel := c.MustGet("migrate")
version := migrateModel.(middleware.SecretCodeModel).Version

View File

@@ -13,6 +13,7 @@ type AuthController struct {
UsersService *services.UsersService
}
// Initializes AuthController.
func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthController {
rc := new(AuthController)
rc.UsersService = rs
@@ -25,6 +26,7 @@ func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthContr
return rc
}
// ROUTE (POST /auth/login).
func (rc *AuthController) PostLogin(c *gin.Context) {
body := new(models.Login)
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) {
body := new(models.User)
body.Init()
@@ -56,6 +59,8 @@ func (rc *AuthController) PostRegister(c *gin.Context) {
c.JSON(200, returnedUser.Payload())
}
}
// ROUTE (DELETE /auth/deactivate).
func (rc *AuthController) Delete(c *gin.Context) {
auth := new(models.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) {
token, _ := c.GetQuery("token")
re := new(models.CheckToken)

View File

@@ -10,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
)
// Gets query parameters and populates FilteredResponse model.
func FilteredResponse(c *gin.Context) *models.FilteredResponse {
filtered := new(models.FilteredResponse)
page, _ := c.GetQuery("page")

View File

@@ -12,6 +12,7 @@ type SubscriptionTypeController struct {
SubscriptionTypeService *services.SubscriptionTypeService
}
// Initializes SubscriptionTypeController.
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.RouterGroup) *SubscriptionTypeController {
wc := new(SubscriptionTypeController)
wc.SubscriptionTypeService = as
@@ -22,6 +23,7 @@ func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.
return wc
}
// ROUTE (POST /subscription-types)
func (wc *SubscriptionTypeController) New(c *gin.Context) {
body := new(models.NewSubscriptionTypeBody)
if err := c.ShouldBind(body); err != nil {
@@ -33,6 +35,7 @@ func (wc *SubscriptionTypeController) New(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (GET /subscription-types)
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
embed, _ := c.GetQuery("embed")

View File

@@ -12,6 +12,7 @@ type SubscriptionController struct {
SubscriptionService *services.SubscriptionService
}
// Initializes SubscriptionController.
func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGroup) *SubscriptionController {
wc := new(SubscriptionController)
wc.SubscriptionService = as
@@ -21,14 +22,15 @@ func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGr
s.GET("/:id", wc.Get)
s.GET("", wc.GetAll)
se := s.Group("/end")
se := s.Group("/end")
{
se.POST("", wc.End)
se.PUT("/:id", wc.End)
}
return wc
}
// ROUTE (POST /subscription)
func (wc *SubscriptionController) New(c *gin.Context) {
body := new(models.NewSubscriptionBody)
if err := c.ShouldBind(body); err != nil {
@@ -40,6 +42,7 @@ func (wc *SubscriptionController) New(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (PUT /subscription/:id)
func (wc *SubscriptionController) Edit(c *gin.Context) {
body := new(models.SubscriptionEdit)
if err := c.ShouldBind(body); err != nil {
@@ -53,6 +56,7 @@ func (wc *SubscriptionController) Edit(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (GET /subscription/:id)
func (wc *SubscriptionController) Get(c *gin.Context) {
body := new(models.Auth)
params := new(models.Params)
@@ -70,6 +74,7 @@ func (wc *SubscriptionController) Get(c *gin.Context) {
c.JSON(200, fr)
}
// ROUTE (PUT /subscription/end/:id)
func (wc *SubscriptionController) End(c *gin.Context) {
body := new(models.Auth)
@@ -82,13 +87,14 @@ func (wc *SubscriptionController) End(c *gin.Context) {
return
}
id := end.Id
id := c.Param("id")
fr := wc.SubscriptionService.End(c, id)
c.JSON(200, fr)
}
// ROUTE (GET /subscription)
func (wc *SubscriptionController) GetAll(c *gin.Context) {
body := new(models.Auth)
auth := c.MustGet("auth")

View File

@@ -12,6 +12,7 @@ type TransactionTypeController struct {
TransactionTypeService *services.TransactionTypeService
}
// Initializes TransactionTypeController.
func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.RouterGroup) *TransactionTypeController {
wc := new(TransactionTypeController)
wc.TransactionTypeService = as
@@ -22,6 +23,7 @@ func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.Ro
return wc
}
// ROUTE (POST /transaction-types)
func (wc *TransactionTypeController) New(c *gin.Context) {
body := new(models.NewTransactionTypeBody)
if err := c.ShouldBind(body); err != nil {
@@ -33,6 +35,7 @@ func (wc *TransactionTypeController) New(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (GET /transaction-types)
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
embed, _ := c.GetQuery("embed")

View File

@@ -12,6 +12,7 @@ type TransactionController struct {
TransactionService *services.TransactionService
}
// Initializes TransactionController.
func NewTransactionController(as *services.TransactionService, s *gin.RouterGroup) *TransactionController {
wc := new(TransactionController)
wc.TransactionService = as
@@ -24,6 +25,7 @@ func NewTransactionController(as *services.TransactionService, s *gin.RouterGrou
return wc
}
// ROUTE (POST /transactions)
func (wc *TransactionController) New(c *gin.Context) {
body := new(models.NewTransactionBody)
if err := c.ShouldBind(body); err != nil {
@@ -35,6 +37,7 @@ func (wc *TransactionController) New(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (GET /transactions)
func (wc *TransactionController) GetAll(c *gin.Context) {
body := new(models.Auth)
auth := c.MustGet("auth")
@@ -48,6 +51,7 @@ func (wc *TransactionController) GetAll(c *gin.Context) {
c.JSON(200, fr)
}
// ROUTE (PUT /transactions/:id)
func (wc *TransactionController) Edit(c *gin.Context) {
body := new(models.TransactionEdit)
if err := c.ShouldBind(body); err != nil {
@@ -61,6 +65,7 @@ func (wc *TransactionController) Edit(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (GET /transactions/:id)
func (wc *TransactionController) Get(c *gin.Context) {
body := new(models.Auth)
params := new(models.Params)

View File

@@ -11,6 +11,7 @@ type WalletsHeaderController struct {
WalletService *services.WalletService
}
// Initializes WalletsHeaderController.
func NewWalletsHeaderController(as *services.WalletService, s *gin.RouterGroup) *WalletsHeaderController {
wc := new(WalletsHeaderController)
wc.WalletService = as
@@ -20,6 +21,7 @@ func NewWalletsHeaderController(as *services.WalletService, s *gin.RouterGroup)
return wc
}
// ROUTE (GET /wallet/wallet-header)
func (wc *WalletsHeaderController) Get(c *gin.Context) {
body := new(models.Auth)

View File

@@ -12,6 +12,7 @@ type WalletsController struct {
WalletService *services.WalletService
}
// Initializes WalletsController.
func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *WalletsController {
wc := new(WalletsController)
wc.WalletService = as
@@ -24,6 +25,7 @@ func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *Walle
return wc
}
// ROUTE (POST /wallet)
func (wc *WalletsController) New(c *gin.Context) {
body := new(models.NewWalletBody)
@@ -39,6 +41,7 @@ func (wc *WalletsController) New(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (GET /wallet)
func (wc *WalletsController) GetAll(c *gin.Context) {
body := new(models.Auth)
auth := c.MustGet("auth")
@@ -51,6 +54,7 @@ func (wc *WalletsController) GetAll(c *gin.Context) {
c.JSON(200, fr)
}
// ROUTE (PUT /wallet/:id)
func (wc *WalletsController) Edit(c *gin.Context) {
body := new(models.WalletEdit)
if err := c.ShouldBind(body); err != nil {
@@ -64,6 +68,7 @@ func (wc *WalletsController) Edit(c *gin.Context) {
c.JSON(200, wm)
}
// ROUTE (GET /wallet/:id)
func (wc *WalletsController) Get(c *gin.Context) {
params := new(models.Params)