partial repository layer added

This commit is contained in:
Fran Jurmanović
2022-09-27 00:33:44 +02:00
parent 13ce0735d0
commit 82e97fc97f
73 changed files with 2686 additions and 1216 deletions

View File

@@ -0,0 +1,75 @@
package controller
import (
"net/http"
"wallet-api/pkg/model"
"wallet-api/pkg/service"
"wallet-api/pkg/utl/common"
"github.com/gin-gonic/gin"
)
type TransactionStatusController struct {
service *service.TransactionStatusService
}
/*
NewTransactionStatusController
Initializes TransactionStatusController.
Args:
*services.TransactionStatusService: Transaction Staus service
*gin.RouterGroup: Gin Router Group
Returns:
*TransactionStatusController: Controller for "transaction-status" route interactions
*/
func NewTransactionStatusController(as *service.TransactionStatusService, routeGroups *common.RouteGroups) *TransactionStatusController {
wc := &TransactionStatusController{
service: as,
}
routeGroups.TransactionStatus.POST("", wc.New)
routeGroups.TransactionStatus.GET("", wc.GetAll)
return wc
}
/*
New
Args:
*gin.Context: Gin Application Context
*/
// ROUTE (POST /transaction-status)
func (wc *TransactionStatusController) New(c *gin.Context) {
body := new(model.NewTransactionStatusBody)
if err := c.ShouldBind(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
wm, exception := wc.service.New(c, body)
if exception != nil {
c.JSON(exception.StatusCode, exception)
return
}
c.JSON(200, wm)
}
/*
GetAll
Args:
*gin.Context: Gin Application Context
*/
// ROUTE (GET /transaction-status)
func (wc *TransactionStatusController) GetAll(c *gin.Context) {
embed, _ := c.GetQuery("embed")
wm, exception := wc.service.GetAll(c, embed)
if exception != nil {
c.JSON(exception.StatusCode, exception)
return
}
c.JSON(200, wm)
}