feat(niki): add handlers for kind_box and kind_box_req domains

This commit is contained in:
Iman Mirazimi 2024-01-02 17:34:16 +03:30
parent fa3ec8bb10
commit 7e5f49e63e
64 changed files with 726 additions and 63 deletions

View File

@ -0,0 +1,30 @@
package adminkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) Add(c echo.Context) error {
var req param.KindBoxAddRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.adminKindBoxVld.ValidateAdminAddRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxSvc.Add(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,30 @@
package adminkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) Get(c echo.Context) error {
var req param.KindBoxGetRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.adminKindBoxVld.ValidateAdminGetRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxSvc.Get(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,24 @@
package adminkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) GetAll(c echo.Context) error {
var req param.KindBoxGetAllRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, sErr := h.adminKindBoxSvc.GetAll(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,25 @@
package adminkindboxhandler
import (
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
)
type Handler struct {
authConfig authservice.Config
authSvc authservice.Service
adminKindBoxSvc adminkindboxservice.Service
adminKindBoxVld adminkindboxvalidator.Validator
}
func New(authConfig authservice.Config, authSvc authservice.Service,
adminKindBoxSvc adminkindboxservice.Service, adminKindBoxVld adminkindboxvalidator.Validator,
) Handler {
return Handler{
authConfig: authConfig,
authSvc: authSvc,
adminKindBoxSvc: adminKindBoxSvc,
adminKindBoxVld: adminKindBoxVld,
}
}

View File

@ -0,0 +1,15 @@
package adminkindboxhandler
import (
"github.com/labstack/echo/v4"
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admin/kindboxes")
r.POST("/", h.Add).Name = "admin-addkindbox"
r.GET("/:id", h.Get).Name = "admin-getkindboxbyid"
r.GET("/", h.GetAll).Name = "admin-getallkindbox"
r.PATCH("/:id", h.Update).Name = "admin-updatekindbox"
// r.DELETE("/:id",h.Delete).Name = "admin-deletekindbox"
}

View File

@ -0,0 +1,30 @@
package adminkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) Update(c echo.Context) error {
var req param.KindBoxUpdateRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.adminKindBoxVld.ValidateAdminUpdateRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxSvc.Update(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,30 @@
package adminkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) Add(c echo.Context) error {
var req param.KindBoxReqAddRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.adminKindBoxReqVld.ValidateAdminAddRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.Add(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,30 @@
package adminkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) Get(c echo.Context) error {
var req param.KindBoxReqGetRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.adminKindBoxReqVld.ValidateAdminGetRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.Get(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,24 @@
package adminkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) GetAll(c echo.Context) error {
var req param.KindBoxReqGetAllRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, sErr := h.adminKindBoxReqSvc.GetAll(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,25 @@
package adminkindboxreqhandler
import (
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
)
type Handler struct {
authConfig authservice.Config
authSvc authservice.Service
adminKindBoxReqSvc adminkindboxreqservice.Service
adminKindBoxReqVld adminkindboxreqvalidator.Validator
}
func New(authConfig authservice.Config, authSvc authservice.Service,
adminKindBoxReqSvc adminkindboxreqservice.Service, adminKindBoxReqVld adminkindboxvalidator.Validator,
) Handler {
return Handler{
authConfig: authConfig,
authSvc: authSvc,
adminKindBoxReqSvc: adminKindBoxReqSvc,
adminKindBoxReqVld: adminKindBoxReqVld,
}
}

View File

@ -0,0 +1,15 @@
package adminkindboxreqhandler
import (
"github.com/labstack/echo/v4"
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admin/kindboxreqs")
r.POST("/").Name = "admin-addkindboxreq"
r.GET("/:id").Name = "admin-getkindboxreqbyid"
r.GET("/").Name = "admin-getallkindboxreq"
r.PUT("/:id").Name = "admin-updatekindboxreq"
// r.DELETE("/:id").Name = "admin-deletekindbox"
}

View File

@ -0,0 +1,30 @@
package adminkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) Update(c echo.Context) error {
var req param.KindBoxReqUpdateRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.adminKindBoxReqVld.ValidateAdminUpdateRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.Update(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,30 @@
package benefactorkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) Add(c echo.Context) error {
var req param.KindBoxAddRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.benefactorKindBoxVld.ValidateBenefactorAddRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxSvc.Add(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,30 @@
package benefactorkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) Get(c echo.Context) error {
var req param.KindBoxGetRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.benefactorKindBoxVld.ValidateBenefactorGetRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxSvc.Get(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,24 @@
package benefactorkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) GetAll(c echo.Context) error {
var req param.KindBoxGetAllRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, sErr := h.benefactorKindBoxSvc.GetAll(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,25 @@
package benefactorkindboxhandler
import (
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box"
benefactorkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box"
)
type Handler struct {
authConfig authservice.Config
authSvc authservice.Service
benefactorKindBoxSvc benefactorkindboxservice.Service
benefactorKindBoxVld benefactorkindboxvalidator.Validator
}
func New(authConfig authservice.Config, authSvc authservice.Service,
benefactorKindBoxSvc benefactorkindboxservice.Service, benefactorKindBoxVld benefactorkindboxvalidator.Validator,
) Handler {
return Handler{
authConfig: authConfig,
authSvc: authSvc,
benefactorKindBoxSvc: benefactorKindBoxSvc,
benefactorKindBoxVld: benefactorKindBoxVld,
}
}

View File

@ -0,0 +1,15 @@
package benefactorkindboxhandler
import (
"github.com/labstack/echo/v4"
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactor/kindboxes")
r.POST("/").Name = "benefactor-addkindbox"
r.GET("/:id").Name = "benefactor-getkindboxbyid"
r.GET("/").Name = "benefactor-getallkindbox"
r.PUT("/:id").Name = "benefactor-updatekindbox"
// r.DELETE("/:id").Name = "benefactor-deletekindbox"
}

View File

@ -0,0 +1,30 @@
package benefactorkindboxhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
"github.com/labstack/echo/v4"
)
func (h Handler) Update(c echo.Context) error {
var req param.KindBoxUpdateRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.benefactorKindBoxVld.ValidateBenefactorUpdateRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxSvc.Update(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,30 @@
package benefactorkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) Add(c echo.Context) error {
var req param.KindBoxReqAddRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateBenefactorAddRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxReqSvc.Add(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,30 @@
package benefactorkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) Get(c echo.Context) error {
var req param.KindBoxReqGetRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateBenefactorGetRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxReqSvc.Get(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,24 @@
package benefactorkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) GetAll(c echo.Context) error {
var req param.KindBoxReqGetAllRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, sErr := h.benefactorKindBoxReqSvc.GetAll(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,25 @@
package benefactorkindboxreqhandler
import (
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
benefactorkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box_req"
)
type Handler struct {
authConfig authservice.Config
authSvc authservice.Service
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service
benefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator
}
func New(authConfig authservice.Config, authSvc authservice.Service,
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service, benefactorKindBoxReqVld benefactorkindboxvalidator.Validator,
) Handler {
return Handler{
authConfig: authConfig,
authSvc: authSvc,
benefactorKindBoxReqSvc: benefactorKindBoxReqSvc,
benefactorKindBoxReqVld: benefactorKindBoxReqVld,
}
}

View File

@ -0,0 +1,15 @@
package benefactorkindboxreqhandler
import (
"github.com/labstack/echo/v4"
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactor/kindboxreqs")
r.POST("/").Name = "benefactor-addkindboxreq"
r.GET("/:id").Name = "benefactor-get-kindboxreqbyid"
r.GET("/").Name = "benefactor-getallkindboxreq"
r.PUT("/:id").Name = "benefactor-updatekindboxreq"
// r.DELETE("/:id").Name = "benefactor-deletekindreqbox"
}

View File

@ -0,0 +1,30 @@
package benefactorkindboxreqhandler
import (
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
"github.com/labstack/echo/v4"
)
func (h Handler) Update(c echo.Context) error {
var req param.KindBoxReqUpdateRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateBenefactorUpdateRequest(c, req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxReqSvc.Update(c, req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}

View File

@ -0,0 +1,13 @@
package httpserver
import (
"net/http"
"github.com/labstack/echo/v4"
)
func (s Server) healthCheck(c echo.Context) error {
return c.JSON(http.StatusOK, echo.Map{
"message": "everything is good!",
})
}

View File

@ -1,16 +1,37 @@
package httpserver package httpserver
import "git.gocasts.ir/ebhomengo/niki/config" import (
"fmt"
"git.gocasts.ir/ebhomengo/niki/config"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
type Server struct { type Server struct {
config config.Config config config.Config
Router *echo.Echo
} }
func New(cfg config.Config) Server { func New(cfg Config) Server {
return Server{ return Server{
Router: echo.New(),
config: cfg, config: cfg,
} }
} }
func (s Server) Serve() { func (s Server) Serve() {
s.Router.Use(middleware.RequestID())
s.Router.Use(middleware.Recover())
// Routes
s.Router.GET("/health-check", s.healthCheck)
// Start server
address := fmt.Sprintf(":%d", s.config.HTTPServer.Port)
fmt.Printf("start echo server on %s\n", address)
if err := s.Router.Start(address); err != nil {
fmt.Println("router start error", err)
}
} }

View File

@ -11,5 +11,5 @@ type KindBox struct {
SenderID uint SenderID uint
SerialNumber string SerialNumber string
Status KindBoxStatus Status KindBoxStatus
StatusChangedAt *time.Time StatusChangedAt time.Time
} }

View File

@ -10,5 +10,5 @@ type KindBoxReq struct {
BenefactorID uint BenefactorID uint
Status KindBoxReqStatus Status KindBoxReqStatus
Description string Description string
StatusChangedAt *time.Time StatusChangedAt time.Time
} }

View File

@ -14,27 +14,27 @@ const (
kindBoxReqRejectedStatusStr = "rejected" kindBoxReqRejectedStatusStr = "rejected"
) )
func (s KindBoxReqStatus) String() string {
switch s {
case KindBoxReqPendingStatus:
return kindBoxReqPendingStatusStr
case KindBoxReqAcceptedStatus:
return kindBoxReqAcceptedStatusStr
case KindBoxReqRejectedStatus:
return kindBoxReqRejectedStatusStr
}
return "" func (s KindBoxReqStatus) String() string {
return KindBoxReqStatusStrings[s]
} }
// AllKindBoxReqStatus returns a slice containing all string values of KindBoxReqStatus.
func AllKindBoxReqStatus() []string {
statusStrings := make([]string, len(KindBoxReqStatusStrings))
for status, str := range KindBoxReqStatusStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
// MapToKindBoxReqStatus converts a string to the corresponding KindBoxReqStatus value.
func MapToKindBoxReqStatus(statusStr string) KindBoxReqStatus { func MapToKindBoxReqStatus(statusStr string) KindBoxReqStatus {
switch statusStr { for status, str := range KindBoxReqStatusStrings {
case kindBoxReqPendingStatusStr: if str == statusStr {
return KindBoxReqPendingStatus return status
case kindBoxReqAcceptedStatusStr: }
return KindBoxReqAcceptedStatus
case kindBoxReqRejectedStatusStr:
return KindBoxReqRejectedStatus
} }
return KindBoxReqStatus(0) return KindBoxReqStatus(0)

View File

@ -1,4 +1,4 @@
package userkindboxparam package benefactorkindboxparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -1,4 +1,4 @@
package userkindboxparam package benefactorkindboxparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -1,4 +1,4 @@
package userkindboxreqparam package benefactorkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -1,4 +1,4 @@
package userkindboxreqparam package benefactorkindboxreqparam
type KindBoxReqDeleteRequest struct { type KindBoxReqDeleteRequest struct {
BenefactorID uint BenefactorID uint

View File

@ -1,4 +1,4 @@
package userkindboxreqparam package benefactorkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -1,4 +1,4 @@
package userkindboxreqparam package benefactorkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -1,4 +1,4 @@
package userkindboxreqparam package benefactorkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -7,7 +7,7 @@ import (
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
) )
func (s Service) GetAll(ctx context.Context) (param.KindBoxGetAllResponse, error) { func (s Service) GetAll(ctx context.Context, _ param.KindBoxGetAllRequest) (param.KindBoxGetAllResponse, error) {
const op = "adminkindboxservice.GetAll" const op = "adminkindboxservice.GetAll"
allKindBox, err := s.repo.GetAllKindBox(ctx) allKindBox, err := s.repo.GetAllKindBox(ctx)
if err != nil { if err != nil {

View File

@ -8,7 +8,7 @@ import (
) )
// TODO: Pagination, Filters, Sort. // TODO: Pagination, Filters, Sort.
func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) { func (s Service) GetAll(ctx context.Context, _ param.KindBoxReqGetAllRequest) (param.KindBoxReqGetAllResponse, error) {
const op = "adminkindboxreqservice.GetAll" const op = "adminkindboxreqservice.GetAll"
allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx) allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx)

View File

@ -1,4 +1,4 @@
package userkindboxservice package benefactorkindboxservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxservice package benefactorkindboxservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxservice package benefactorkindboxservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxreqservice package benefactorkindboxreqservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxreqservice package benefactorkindboxreqservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxreqservice package benefactorkindboxreqservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxreqservice package benefactorkindboxreqservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxreqservice package benefactorkindboxreqservice
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package userkindboxreqservice package benefactorkindboxreqservice
import ( import (
"context" "context"

View File

@ -1,6 +1,7 @@
package adminkindboxvalidator package adminkindboxvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
@ -10,7 +11,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateAdminAddRequest(req param.KindBoxAddRequest) (map[string]string, error) { func (v Validator) ValidateAdminAddRequest(ctx context.Context, req param.KindBoxAddRequest) (map[string]string, error) {
const op = "adminkindboxvalidator.KindBoxAddRequest" const op = "adminkindboxvalidator.KindBoxAddRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package adminkindboxvalidator package adminkindboxvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateDeleteRequest(req param.KindBoxDeleteRequest) (map[string]string, error) { func (v Validator) ValidateDeleteRequest(ctx context.Context, req param.KindBoxDeleteRequest) (map[string]string, error) {
const op = "adminkindboxvalidator.ValidateDeleteRequest" const op = "adminkindboxvalidator.ValidateDeleteRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package adminkindboxvalidator package adminkindboxvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateGetByIDRequest(req param.KindBoxGetRequest) (map[string]string, error) { func (v Validator) ValidateGetByIDRequest(ctx context.Context, req param.KindBoxGetRequest) (map[string]string, error) {
const op = "adminkindboxvalidator.ValidateGetRequest" const op = "adminkindboxvalidator.ValidateGetRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -11,7 +11,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateUpdateRequest(req param.KindBoxUpdateRequest) (map[string]string, error) { func (v Validator) ValidateUpdateRequest(ctx context.Context, req param.KindBoxUpdateRequest) (map[string]string, error) {
const op = "adminkindboxvalidator.ValidateUpdateRequest" const op = "adminkindboxvalidator.ValidateUpdateRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateAddRequest(req param.KindBoxReqAddRequest) (map[string]string, error) { func (v Validator) ValidateAddRequest(ctx context.Context, req param.KindBoxReqAddRequest) (map[string]string, error) {
const op = "adminkindboxreqvalidator.ValidateAddRequest" const op = "adminkindboxreqvalidator.ValidateAddRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateDeleteRequest(req param.KindBoxReqDeleteRequest) (map[string]string, error) { func (v Validator) ValidateDeleteRequest(ctx context.Context, req param.KindBoxReqDeleteRequest) (map[string]string, error) {
const op = "adminkindboxreqvalidator.ValidateDeleteRequest" const op = "adminkindboxreqvalidator.ValidateDeleteRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateGetByIDRequest(req param.KindBoxReqGetRequest) (map[string]string, error) { func (v Validator) ValidateGetByIDRequest(ctx context.Context, req param.KindBoxReqGetRequest) (map[string]string, error) {
const op = "adminkindboxreqvalidator.ValidateGetRequest" const op = "adminkindboxreqvalidator.ValidateGetRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateUpdateRequest(req param.KindBoxReqUpdateRequest) (map[string]string, error) { func (v Validator) ValidateUpdateRequest(ctx context.Context, req param.KindBoxReqUpdateRequest) (map[string]string, error) {
const op = "adminkindboxreqvalidator.ValidateUpdateRequest" const op = "adminkindboxreqvalidator.ValidateUpdateRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package userkindboxvalidator package benefactorkindboxvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateGetByIDRequest(req param.KindBoxGetRequest) (map[string]string, error) { func (v Validator) ValidateGetByIDRequest(ctx context.Context, req param.KindBoxGetRequest) (map[string]string, error) {
const op = "userkindboxvalidator.ValidateGetRequest" const op = "userkindboxvalidator.ValidateGetRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package userkindboxvalidator package benefactorkindboxvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateUpdateRequest(req param.KindBoxGetAllRequest) (map[string]string, error) { func (v Validator) ValidateUpdateRequest(ctx context.Context, req param.KindBoxGetAllRequest) (map[string]string, error) {
const op = "userkindboxvalidator.ValidateGetAllRequest" const op = "userkindboxvalidator.ValidateGetAllRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,4 +1,4 @@
package userkindboxvalidator package benefactorkindboxvalidator
import ( import (
"fmt" "fmt"

View File

@ -1,6 +1,7 @@
package userkindboxreqvalidator package benefactorkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateAddRequest(req param.KindBoxReqAddRequest) (map[string]string, error) { func (v Validator) ValidateAddRequest(ctx context.Context, req param.KindBoxReqAddRequest) (map[string]string, error) {
const op = "userkindboxreqvalidator.ValidateAddRequest" const op = "userkindboxreqvalidator.ValidateAddRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package userkindboxreqvalidator package benefactorkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateDeleteRequest(req param.KindBoxReqDeleteRequest) (map[string]string, error) { func (v Validator) ValidateDeleteRequest(ctx context.Context, req param.KindBoxReqDeleteRequest) (map[string]string, error) {
const op = "userkindboxreqvalidator.ValidateDeleteRequest" const op = "userkindboxreqvalidator.ValidateDeleteRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,4 +1,4 @@
package userkindboxreqvalidator package benefactorkindboxreqvalidator
import ( import (
"errors" "errors"
@ -9,7 +9,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateGetRequest(req param.KindBoxReqGetRequest) (map[string]string, error) { func (v Validator) ValidateGetRequest(ctx context.Context, req param.KindBoxReqGetRequest) (map[string]string, error) {
const op = "userkindboxreqvalidator.ValidateGetRequest" const op = "userkindboxreqvalidator.ValidateGetRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package userkindboxreqvalidator package benefactorkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateGetAllRequest(req param.KindBoxReqGetAllRequest) (map[string]string, error) { func (v Validator) ValidateGetAllRequest(ctx context.Context, req param.KindBoxReqGetAllRequest) (map[string]string, error) {
const op = "userkindboxreqvalidator.ValidateGetAllRequest" const op = "userkindboxreqvalidator.ValidateGetAllRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,6 +1,7 @@
package userkindboxreqvalidator package benefactorkindboxreqvalidator
import ( import (
"context"
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
@ -9,7 +10,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateUpdateRequest(req param.KindBoxReqUpdateRequest) (map[string]string, error) { func (v Validator) ValidateUpdateRequest(ctx context.Context, req param.KindBoxReqUpdateRequest) (map[string]string, error) {
const op = "userkindboxreqvalidator.ValidateUpdateRequest" const op = "userkindboxreqvalidator.ValidateUpdateRequest"
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,

View File

@ -1,4 +1,4 @@
package userkindboxreqvalidator package benefactorkindboxreqvalidator
import ( import (
"fmt" "fmt"