forked from ebhomengo/niki
1
0
Fork 0

fix(niki): internal, validator and structure refactor

This commit is contained in:
Iman Mirazimi 2024-08-01 13:50:18 +03:30
parent f82c85b455
commit 705adda09b
1523 changed files with 2347 additions and 648696 deletions

5
.gitignore vendored
View File

@ -9,6 +9,7 @@ niki
*.dll *.dll
*.so *.so
*.dylib *.dylib
activate.mise.toml
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test
@ -17,11 +18,13 @@ niki
*.out *.out
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ vendor/
.idea .idea
bin bin
#.env #.env
*.env *.env
# Logs
logs/ logs/
mise.log

View File

@ -0,0 +1,17 @@
package kavenegar
import "github.com/kavenegar/kavenegar-go"
type Config struct {
APIKey string `koanf:"api_key"`
Sender string `koanf:"sender"`
}
type Adapter struct {
config Config
adapter *kavenegar.Kavenegar
}
func New(config Config) *Adapter {
return &Adapter{config: config, adapter: kavenegar.New(config.APIKey)}
}

View File

@ -1,4 +1,4 @@
package kavenegarnotification package kavenegar
import ( import (
"fmt" "fmt"
@ -6,11 +6,11 @@ import (
"github.com/kavenegar/kavenegar-go" "github.com/kavenegar/kavenegar-go"
) )
func (a *Adapter) Send(phoneNumber, message string) { func (a Adapter) Send(phoneNumber, message string) {
const op = "kavenegarnotification.Send" const op = "kavenegarnotification.Send"
var params *kavenegar.MessageSendParam var params *kavenegar.MessageSendParam
if _, err := a.adapter.Client().Message.Send(a.adapter.Config().Sender, []string{phoneNumber}, message, params); err != nil { if _, err := a.adapter.Message.Send(a.config.Sender, []string{phoneNumber}, message, params); err != nil {
//nolint //nolint
switch err := err.(type) { switch err := err.(type) {
case *kavenegar.APIError: case *kavenegar.APIError:

View File

@ -17,16 +17,16 @@ type Adapter struct {
client *redis.Client client *redis.Client
} }
func New(config Config) Adapter { func New(config Config) *Adapter {
rdb := redis.NewClient(&redis.Options{ rdb := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", config.Host, config.Port), Addr: fmt.Sprintf("%s:%d", config.Host, config.Port),
Password: config.Password, Password: config.Password,
DB: config.DB, DB: config.DB,
}) })
return Adapter{client: rdb} return &Adapter{client: rdb}
} }
func (a Adapter) Client() *redis.Client { func (a *Adapter) Client() *redis.Client {
return a.client return a.client
} }

View File

@ -1,27 +0,0 @@
package kavenegar
import "github.com/kavenegar/kavenegar-go"
type Config struct {
APIKey string `koanf:"api_key"`
Sender string `koanf:"sender"`
OtpTemplateNewUser string `koanf:"otp_template_new_user"`
OtpTemplateRegisteredUser string `koanf:"otp_template_registered_user"`
}
type Adapter struct {
config Config
api *kavenegar.Kavenegar
}
func New(config Config) *Adapter {
return &Adapter{config: config, api: kavenegar.New(config.APIKey)}
}
func (a Adapter) Client() *kavenegar.Kavenegar {
return a.api
}
func (a Adapter) Config() Config {
return a.config
}

View File

@ -1,11 +0,0 @@
package kavenegarnotification
import "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
type Adapter struct {
adapter *kavenegar.Adapter
}
func New(adapter *kavenegar.Adapter) *Adapter {
return &Adapter{adapter: adapter}
}

View File

@ -1,13 +0,0 @@
package kavenegarotp
import (
smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
)
type Adapter struct {
adapter *smsprovider.Adapter
}
func New(conn *smsprovider.Adapter) *Adapter {
return &Adapter{adapter: conn}
}

View File

@ -1,50 +0,0 @@
package kavenegarotp
import (
"fmt"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
"github.com/kavenegar/kavenegar-go"
)
func (a Adapter) SendForNewUser(phoneNumber, code string) {
const op = richerror.Op("kavenegarotp.Send")
params := &kavenegar.VerifyLookupParam{}
if _, err := a.adapter.Client().Verify.Lookup(phoneNumber, a.adapter.Config().OtpTemplateNewUser, code, params); err != nil {
//nolint
switch err := err.(type) {
case *kavenegar.APIError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
case *kavenegar.HTTPError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
default:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
}
}
// TODO - log res res.Status
}
func (a Adapter) SendForRegisteredUser(phoneNumber, code string) {
const op = richerror.Op("kavenegarotp.Send")
params := &kavenegar.VerifyLookupParam{}
if _, err := a.adapter.Client().Verify.Lookup(phoneNumber, a.adapter.Config().OtpTemplateRegisteredUser, code, params); err != nil {
//nolint
switch err := err.(type) {
case *kavenegar.APIError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
case *kavenegar.HTTPError:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
default:
// log error
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
}
}
// TODO - log res res.Status
}

View File

View File

@ -1,7 +1,7 @@
--- ---
type: yml type: yml
auth: benefactor_auth:
sign_key: jwt_secret_test_nik sign_key: jwt_secret_test_nik
http_server: http_server:
@ -30,8 +30,6 @@ benefactor_service:
kavenegar_sms_provider: kavenegar_sms_provider:
api_key: insert_your_api_key api_key: insert_your_api_key
sender: insert_sender_number sender: insert_sender_number
otp_template_new_user: ebhomeverify
otp_template_registered_user: ebhomeverify
admin_auth: admin_auth:
sign_key: admin-jwt_secret_test_nik sign_key: admin-jwt_secret_test_nik

View File

@ -1,8 +1,8 @@
package config package config
import ( import (
smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/kavenegar"
"git.gocasts.ir/ebhomengo/niki/adapter/redis" "git.gocasts.ir/ebhomengo/niki/adapter/redis"
smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
"git.gocasts.ir/ebhomengo/niki/repository/mysql" "git.gocasts.ir/ebhomengo/niki/repository/mysql"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor" benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
@ -15,7 +15,7 @@ type HTTPServer struct {
type Config struct { type Config struct {
HTTPServer HTTPServer `koanf:"http_server"` HTTPServer HTTPServer `koanf:"http_server"`
Mysql mysql.Config `koanf:"mariadb"` Mysql mysql.Config `koanf:"mariadb"`
Auth authservice.Config `koanf:"auth"` BenefactorAuth authservice.Config `koanf:"benefactor_auth"`
AdminAuth authservice.Config `koanf:"admin_auth"` AdminAuth authservice.Config `koanf:"admin_auth"`
Redis redis.Config `koanf:"redis"` Redis redis.Config `koanf:"redis"`
KavenegarSmsProvider smsprovider.Config `koanf:"kavenegar_sms_provider"` KavenegarSmsProvider smsprovider.Config `koanf:"kavenegar_sms_provider"`

View File

@ -7,7 +7,7 @@ import (
func Default() Config { func Default() Config {
cfx := Config{ cfx := Config{
Auth: authservice.Config{ BenefactorAuth: authservice.Config{
AccessExpirationTime: AccessTokenExpireDuration, AccessExpirationTime: AccessTokenExpireDuration,
RefreshExpirationTime: RefreshTokenExpireDuration, RefreshExpirationTime: RefreshTokenExpireDuration,
AccessSubject: AccessTokenSubject, AccessSubject: AccessTokenSubject,

5
contract/sms/send.go Normal file
View File

@ -0,0 +1,5 @@
package smscontract
type SmsAdapter interface {
Send(phoneNumber string, message string)
}

View File

@ -4,26 +4,21 @@ import (
adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin" adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization" adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
adminauthservice "git.gocasts.ir/ebhomengo/niki/service/auth" adminauthservice "git.gocasts.ir/ebhomengo/niki/service/auth"
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
) )
type Handler struct { type Handler struct {
authConfig adminauthservice.Config
authSvc adminauthservice.Service authSvc adminauthservice.Service
adminSvc adminservice.Service adminSvc adminservice.Service
adminVld adminvalidator.Validator
adminAuthorizeSvc adminauthorizationservice.Service adminAuthorizeSvc adminauthorizationservice.Service
} }
func New(authConfig adminauthservice.Config, authSvc adminauthservice.Service, func New(authSvc adminauthservice.Service,
adminSvc adminservice.Service, adminVld adminvalidator.Validator, adminSvc adminservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service, adminAuthorizeSvc adminauthorizationservice.Service,
) Handler { ) Handler {
return Handler{ return Handler{
authConfig: authConfig,
authSvc: authSvc, authSvc: authSvc,
adminSvc: adminSvc, adminSvc: adminSvc,
adminVld: adminVld,
adminAuthorizeSvc: adminAuthorizeSvc, adminAuthorizeSvc: adminAuthorizeSvc,
} }
} }

View File

@ -24,17 +24,15 @@ func (h Handler) LoginByPhoneNumber(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminVld.ValidateLoginWithPhoneNumberRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminSvc.LoginWithPhoneNumber(c.Request().Context(), req) resp, sErr := h.adminSvc.LoginWithPhoneNumber(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -25,17 +25,15 @@ func (h Handler) Register(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminVld.ValidateRegisterRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminSvc.Register(c.Request().Context(), req) resp, sErr := h.adminSvc.Register(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -11,9 +11,8 @@ func (h Handler) SetRoutes(e *echo.Echo) {
//nolint:gocritic //nolint:gocritic
//r.POST("/", h.Add).Name = "admin-addkindboxreq" //r.POST("/", h.Add).Name = "admin-addkindboxreq"
r.POST("/register", h.Register, middleware.Auth(h.authSvc, h.authConfig), middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminAdminRegisterPermission)) r.POST("/register", h.Register, middleware.Auth(h.authSvc), middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminAdminRegisterPermission))
r.POST("/login-by-phone", h.LoginByPhoneNumber) r.POST("/login-by-phone", h.LoginByPhoneNumber)
//nolint:gocritic //nolint:gocritic
//r.PATCH("/:id", h.Update).Name = "admin-updatekindboxreq" //r.PATCH("/:id", h.Update).Name = "admin-updatekindboxreq"
r.GET("/agents", h.GetAllAgent, middleware.Auth(h.authSvc, h.authConfig), middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminAdminGetAllAgentPermission))
} }

View File

@ -1,8 +1,9 @@
package adminhandler package adminagenthandler
import ( import (
"net/http" "net/http"
adminagentparam "git.gocasts.ir/ebhomengo/niki/param/admin/agent"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -12,12 +13,13 @@ import (
// @Tags Admin // @Tags Admin
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} adminserviceparam.GetAllAgentResponse // @Success 200 {object} adminagentparam.GetAllAgentResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admins/agents [get]. // @Router /admins/agents [get].
func (h Handler) GetAllAgent(c echo.Context) error { func (h Handler) GetAllAgent(c echo.Context) error {
resp, sErr := h.adminSvc.GetAllAgent(c.Request().Context()) var resp adminagentparam.GetAllAgentResponse
resp, sErr := h.agentSvc.GetAllAgent(c.Request().Context())
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)

View File

@ -0,0 +1,24 @@
package adminagenthandler
import (
agentservice "git.gocasts.ir/ebhomengo/niki/service/admin/agent"
authorizeservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
)
type Handler struct {
authSvc authservice.Service
agentSvc agentservice.Service
authorizeSvc authorizeservice.Service
}
func New(authSvc authservice.Service,
agentSvc agentservice.Service,
authorizeSvc authorizeservice.Service,
) Handler {
return Handler{
authSvc: authSvc,
agentSvc: agentSvc,
authorizeSvc: authorizeSvc,
}
}

View File

@ -0,0 +1,13 @@
package adminagenthandler
import (
"git.gocasts.ir/ebhomengo/niki/delivery/http_server/middleware"
"git.gocasts.ir/ebhomengo/niki/entity"
"github.com/labstack/echo/v4"
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admins")
r.GET("/agents", h.GetAllAgent, middleware.Auth(h.authSvc), middleware.AdminAuthorization(h.authorizeSvc, entity.AdminAdminGetAllAgentPermission))
}

View File

@ -26,19 +26,16 @@ func (h Handler) AssignReceiverAgent(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminKindBoxVld.ValidateAssignReceiverAgent(req); err != nil { resp, sErr := h.adminKindBoxSvc.AssignReceiverAgent(c.Request().Context(), req)
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
sErr := h.adminKindBoxSvc.AssignReceiverAgent(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -30,22 +30,19 @@ func (h Handler) Enumerate(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminKindBoxVld.ValidateEnumerate(req); err != nil { resp, sErr := h.adminKindBoxSvc.Enumerate(c.Request().Context(), req)
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
sErr := h.adminKindBoxSvc.Enumerate(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }
return c.JSON(http.StatusNoContent, nil) return c.JSON(http.StatusNoContent, resp)
} }

View File

@ -24,17 +24,16 @@ func (h Handler) Get(c echo.Context) error {
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminKindBoxVld.ValidateGetRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxSvc.Get(c.Request().Context(), req) resp, sErr := h.adminKindBoxSvc.Get(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -48,18 +48,16 @@ func (h Handler) GetAll(c echo.Context) error {
} }
req.Filter = queryparam.GetFilterParams(c) req.Filter = queryparam.GetFilterParams(c)
if fieldErrors, err := h.adminKindBoxVld.ValidateGetAll(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxSvc.GetAll(c.Request().Context(), req) resp, sErr := h.adminKindBoxSvc.GetAll(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -4,26 +4,21 @@ import (
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization" adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box" adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
) )
type Handler struct { type Handler struct {
authConfig authservice.Config
authSvc authservice.Service authSvc authservice.Service
adminKindBoxSvc adminkindboxservice.Service adminKindBoxSvc adminkindboxservice.Service
adminKindBoxVld adminkindboxvalidator.Validator
adminAuthorizeSvc adminauthorizationservice.Service adminAuthorizeSvc adminauthorizationservice.Service
} }
func New(authConfig authservice.Config, authSvc authservice.Service, func New(authSvc authservice.Service,
adminKindBoxSvc adminkindboxservice.Service, adminKindBoxVld adminkindboxvalidator.Validator, adminKindBoxSvc adminkindboxservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service, adminAuthorizeSvc adminauthorizationservice.Service,
) Handler { ) Handler {
return Handler{ return Handler{
authConfig: authConfig,
authSvc: authSvc, authSvc: authSvc,
adminKindBoxSvc: adminKindBoxSvc, adminKindBoxSvc: adminKindBoxSvc,
adminKindBoxVld: adminKindBoxVld,
adminAuthorizeSvc: adminAuthorizeSvc, adminAuthorizeSvc: adminAuthorizeSvc,
} }
} }

View File

@ -9,7 +9,7 @@ import (
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admin/kindboxes") r := e.Group("/admin/kindboxes")
r.Use(middleware.Auth(h.authSvc, h.authConfig)) r.Use(middleware.Auth(h.authSvc))
r.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetPermission)) r.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetPermission))
r.PATCH("/assign-receiver-agent/:id", h.AssignReceiverAgent, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxAssignReceiverAgentPermission)) r.PATCH("/assign-receiver-agent/:id", h.AssignReceiverAgent, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxAssignReceiverAgentPermission))

View File

@ -32,18 +32,16 @@ func (h Handler) Accept(c echo.Context) error {
return c.JSON(http.StatusBadRequest, errmsg.ErrorMsgInvalidInput) return c.JSON(http.StatusBadRequest, errmsg.ErrorMsgInvalidInput)
} }
req.ID = uint(num) req.ID = uint(num)
if fieldErrors, err := h.adminKindBoxReqVld.ValidateAcceptRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.Accept(c.Request().Context(), req) resp, sErr := h.adminKindBoxReqSvc.Accept(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -24,18 +24,16 @@ func (h Handler) AddKindBoxReq(c echo.Context) error {
if err := c.Bind(&req); err != nil { if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, errmsg.ErrBadRequest) return echo.NewHTTPError(http.StatusBadRequest, errmsg.ErrBadRequest)
} }
result := h.adminKindBoxReqVld.ValidateAddRequest(req)
if result != nil {
msg, code := httpmsg.Error(result.Err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": result.Fields,
})
}
resp, sErr := h.adminKindBoxReqSvc.Add(c.Request().Context(), req) resp, sErr := h.adminKindBoxReqSvc.Add(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -36,19 +36,16 @@ func (h Handler) AssignSenderAgent(c echo.Context) error {
req.KindBoxReqID = uint(id) req.KindBoxReqID = uint(id)
if fieldErrors, err := h.adminKindBoxReqVld.ValidateAssignSenderAgent(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.AssignSenderAgent(c.Request().Context(), req) resp, sErr := h.adminKindBoxReqSvc.AssignSenderAgent(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -29,24 +29,21 @@ func (h Handler) Deliver(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminKindBoxReqVld.ValidateDeliver(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
q := querier.GetQuerierFromContextOrNew(c.Request().Context()).Begin() q := querier.GetQuerierFromContextOrNew(c.Request().Context()).Begin()
ctx := context.WithValue(c.Request().Context(), querier.QuerierContextKey, q) ctx := context.WithValue(c.Request().Context(), querier.QuerierContextKey, q)
resp, sErr := h.adminKindBoxReqSvc.Deliver(ctx, req) resp, sErr := h.adminKindBoxReqSvc.Deliver(ctx, req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
rErr := q.Rollback() rErr := q.Rollback()
if rErr != nil { if rErr != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errmsg.ErrorMsgSomethingWentWrong) return echo.NewHTTPError(http.StatusInternalServerError, errmsg.ErrorMsgSomethingWentWrong)
} }
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -28,18 +28,15 @@ func (h Handler) Get(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, httpmsg.ErrorResponse{
Message: msg,
Errors: fieldErrors,
})
}
resp, err := h.adminKindBoxReqSvc.Get(c.Request().Context(), req) resp, err := h.adminKindBoxReqSvc.Get(c.Request().Context(), req)
if err != nil { if err != nil {
msg, code := httpmsg.Error(err) msg, code := httpmsg.Error(err)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -46,18 +46,16 @@ func (h Handler) GetAll(c echo.Context) error {
} }
req.Filter = queryparam.GetFilterParams(c) req.Filter = queryparam.GetFilterParams(c)
if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetAll(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, httpmsg.ErrorResponse{
Message: msg,
Errors: fieldErrors,
})
}
resp, err := h.adminKindBoxReqSvc.GetAll(c.Request().Context(), req) resp, err := h.adminKindBoxReqSvc.GetAll(c.Request().Context(), req)
if err != nil { if err != nil {
msg, code := httpmsg.Error(err) msg, code := httpmsg.Error(err)
if resp.FieldErrors != nil {
return c.JSON(code, httpmsg.ErrorResponse{
Message: msg,
Errors: resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -39,22 +39,18 @@ func (h Handler) GetAllAwaitingDelivery(c echo.Context) error {
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
req.Filter = queryparam.GetFilterParams(c) req.Filter = queryparam.GetFilterParams(c)
if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetAllAwaitingDelivery(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
req.Filter["sender_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID req.Filter["sender_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID
req.Filter["status"] = entity.KindBoxReqAssignedSenderAgentStatus.String() req.Filter["status"] = entity.KindBoxReqAssignedSenderAgentStatus
resp, sErr := h.adminKindBoxReqSvc.GetAllAwaitingDelivery(c.Request().Context(), req) resp, sErr := h.adminKindBoxReqSvc.GetAllAwaitingDelivery(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -28,18 +28,15 @@ func (h Handler) GetAwaitingDelivery(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.AgentID = claims.UserID req.AgentID = claims.UserID
if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetAwaitingDeliveryRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.GetAwaitingDelivery(c.Request().Context(), req) resp, sErr := h.adminKindBoxReqSvc.GetAwaitingDelivery(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -5,27 +5,22 @@ import (
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req" adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification" "git.gocasts.ir/ebhomengo/niki/service/notification"
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
) )
type Handler struct { type Handler struct {
authConfig authservice.Config
authSvc authservice.Service authSvc authservice.Service
adminKindBoxReqSvc adminkindboxreqservice.Service adminKindBoxReqSvc adminkindboxreqservice.Service
adminKindBoxReqVld adminkindboxreqvalidator.Validator
adminAuthorizeSvc adminauthorizationservice.Service adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service notificationSvc notification.Service
} }
func New(authConfig authservice.Config, authSvc authservice.Service, func New(authSvc authservice.Service,
adminKindBoxReqSvc adminkindboxreqservice.Service, adminKindBoxReqVld adminkindboxreqvalidator.Validator, adminKindBoxReqSvc adminkindboxreqservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service, notificationSvc notification.Service, adminAuthorizeSvc adminauthorizationservice.Service, notificationSvc notification.Service,
) Handler { ) Handler {
return Handler{ return Handler{
authConfig: authConfig,
authSvc: authSvc, authSvc: authSvc,
adminKindBoxReqSvc: adminKindBoxReqSvc, adminKindBoxReqSvc: adminKindBoxReqSvc,
adminKindBoxReqVld: adminKindBoxReqVld,
adminAuthorizeSvc: adminAuthorizeSvc, adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc, notificationSvc: notificationSvc,
} }

View File

@ -31,18 +31,16 @@ func (h Handler) Reject(c echo.Context) error {
return c.JSON(http.StatusBadRequest, errmsg.ErrorMsgInvalidInput) return c.JSON(http.StatusBadRequest, errmsg.ErrorMsgInvalidInput)
} }
req.ID = uint(num) req.ID = uint(num)
if fieldErrors, err := h.adminKindBoxReqVld.ValidateRejectRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.Reject(c.Request().Context(), req) resp, sErr := h.adminKindBoxReqSvc.Reject(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -9,7 +9,7 @@ import (
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admins/kindboxreqs") r := e.Group("/admins/kindboxreqs")
r.Use(middleware.Auth(h.authSvc, h.authConfig)) r.Use(middleware.Auth(h.authSvc))
r.POST("", h.AddKindBoxReq, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission)) r.POST("", h.AddKindBoxReq, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission))
r.PATCH("/accept-kind-box-req/:id", h.Accept, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAcceptPermission)) r.PATCH("/accept-kind-box-req/:id", h.Accept, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAcceptPermission))
r.PATCH("/reject-kind-box-req/:id", h.Reject, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqRejectPermission)) r.PATCH("/reject-kind-box-req/:id", h.Reject, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqRejectPermission))

View File

@ -25,18 +25,15 @@ func (h Handler) Update(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.adminKindBoxReqVld.ValidateUpdateRequest(req); err != nil { resp, sErr := h.adminKindBoxReqSvc.Update(c.Request().Context(), req)
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
sErr := h.adminKindBoxReqSvc.Update(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -32,18 +32,15 @@ func (h Handler) Get(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.AgentID = claims.UserID req.AgentID = claims.UserID
if fieldErrors, err := h.agentKindBoxVld.ValidateGetRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, httpmsg.ErrorResponse{
Message: msg,
Errors: fieldErrors,
})
}
resp, sErr := h.agentKindBoxSvc.Get(c.Request().Context(), req) resp, sErr := h.agentKindBoxSvc.Get(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, httpmsg.ErrorResponse{
Message: msg,
Errors: resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -44,20 +44,18 @@ func (h Handler) GetAll(c echo.Context) error {
} }
req.Filter = queryparam.GetFilterParams(c) req.Filter = queryparam.GetFilterParams(c)
if fieldErrors, err := h.agentKindBoxVld.ValidateGetAll(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, httpmsg.ErrorResponse{
Message: msg,
Errors: fieldErrors,
})
}
req.Filter["receiver_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID req.Filter["receiver_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID
req.Filter["status"] = entity.KindBoxAssignedReceiverAgentStatus.String() req.Filter["status"] = entity.KindBoxAssignedReceiverAgentStatus
resp, err := h.agentKindBoxSvc.GetAll(c.Request().Context(), req) resp, err := h.agentKindBoxSvc.GetAll(c.Request().Context(), req)
if err != nil { if err != nil {
msg, code := httpmsg.Error(err) msg, code := httpmsg.Error(err)
if resp.FieldErrors != nil {
return c.JSON(code, httpmsg.ErrorResponse{
Message: msg,
Errors: resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -4,26 +4,21 @@ import (
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization" adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box" agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
) )
type Handler struct { type Handler struct {
authConfig authservice.Config
authSvc authservice.Service authSvc authservice.Service
agentKindBoxSvc agentkindboxservice.Service agentKindBoxSvc agentkindboxservice.Service
agentKindBoxVld agentkindboxvalidator.Validator
adminAuthorizeSvc adminauthorizationservice.Service adminAuthorizeSvc adminauthorizationservice.Service
} }
func New(authConfig authservice.Config, authSvc authservice.Service, func New(authSvc authservice.Service,
agentKindBoxSvc agentkindboxservice.Service, agentKindBoxVld agentkindboxvalidator.Validator, agentKindBoxSvc agentkindboxservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service, adminAuthorizeSvc adminauthorizationservice.Service,
) Handler { ) Handler {
return Handler{ return Handler{
authConfig: authConfig,
authSvc: authSvc, authSvc: authSvc,
agentKindBoxSvc: agentKindBoxSvc, agentKindBoxSvc: agentKindBoxSvc,
agentKindBoxVld: agentKindBoxVld,
adminAuthorizeSvc: adminAuthorizeSvc, adminAuthorizeSvc: adminAuthorizeSvc,
} }
} }

View File

@ -33,18 +33,15 @@ func (h Handler) Return(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.AgentID = claims.UserID req.AgentID = claims.UserID
if fieldErrors, err := h.agentKindBoxVld.ValidateReturn(req); err != nil { resp, sErr := h.agentKindBoxSvc.Return(c.Request().Context(), req)
msg, code := httpmsg.Error(err) if sErr != nil {
msg, code := httpmsg.Error(sErr)
return c.JSON(code, httpmsg.ErrorResponse{ if resp.FieldErrors != nil {
Message: msg, return c.JSON(code, httpmsg.ErrorResponse{
Errors: fieldErrors, Message: msg,
}) Errors: resp.FieldErrors,
} })
}
err := h.agentKindBoxSvc.Return(c.Request().Context(), req)
if err != nil {
msg, code := httpmsg.Error(err)
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -9,7 +9,7 @@ import (
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/agents/kindboxes") r := e.Group("/agents/kindboxes")
r.Use(middleware.Auth(h.authSvc, h.authConfig)) r.Use(middleware.Auth(h.authSvc))
r.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetAwaitingReturnPermission)) r.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetAwaitingReturnPermission))
r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetAwaitingReturnPermission)) r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetAwaitingReturnPermission))

View File

@ -28,18 +28,16 @@ func (h Handler) AddAddress(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.addressVld.ValidateAddAddress(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.addressSvc.Add(c.Request().Context(), req) resp, sErr := h.addressSvc.Add(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -26,17 +26,16 @@ func (h Handler) DeleteAddress(c echo.Context) error {
} }
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.addressVld.ValidateDeleteRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{ resp, dErr := h.addressSvc.Delete(c.Request().Context(), req)
"message": msg,
"errors": fieldErrors,
})
}
dErr := h.addressSvc.Delete(c.Request().Context(), req)
if dErr != nil { if dErr != nil {
msg, code := httpmsg.Error(dErr) msg, code := httpmsg.Error(dErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -27,17 +27,15 @@ func (h Handler) GetAddress(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.addressVld.ValidateGetAddress(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.addressSvc.Get(c.Request().Context(), req) resp, sErr := h.addressSvc.Get(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -3,26 +3,19 @@ package benefactoraddresshandler
import ( import (
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address" benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address"
benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address"
) )
type Handler struct { type Handler struct {
authConfig authservice.Config
authSvc authservice.Service authSvc authservice.Service
addressSvc benefactoraddressservice.Service addressSvc benefactoraddressservice.Service
addressVld benefactoraddressvalidator.Validator
} }
func New( func New(
authConfig authservice.Config,
authSvc authservice.Service, authSvc authservice.Service,
addressSvc benefactoraddressservice.Service, addressSvc benefactoraddressservice.Service,
addressVld benefactoraddressvalidator.Validator,
) Handler { ) Handler {
return Handler{ return Handler{
authConfig: authConfig,
authSvc: authSvc, authSvc: authSvc,
addressSvc: addressSvc, addressSvc: addressSvc,
addressVld: addressVld,
} }
} }

View File

@ -11,14 +11,14 @@ func (h Handler) SetRoutes(e *echo.Echo) {
r.GET("/provinces", h.GetAllProvinces) r.GET("/provinces", h.GetAllProvinces)
r.GET("/cities", h.GetAllCities) r.GET("/cities", h.GetAllCities)
r.POST("/", h.AddAddress, middleware.Auth(h.authSvc, h.authConfig), r.POST("/", h.AddAddress, middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole)) middleware.BenefactorAuthorization(entity.UserBenefactorRole))
r.GET("/:id", h.GetAddress, middleware.Auth(h.authSvc, h.authConfig), r.GET("/:id", h.GetAddress, middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole)) middleware.BenefactorAuthorization(entity.UserBenefactorRole))
r.GET("/", h.GetAddresses, middleware.Auth(h.authSvc, h.authConfig), r.GET("/", h.GetAddresses, middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole)) middleware.BenefactorAuthorization(entity.UserBenefactorRole))
r.DELETE("/:id", h.DeleteAddress, middleware.Auth(h.authSvc, h.authConfig), r.DELETE("/:id", h.DeleteAddress, middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole)) middleware.BenefactorAuthorization(entity.UserBenefactorRole))
r.PATCH("/:id", h.UpdateAddress, middleware.Auth(h.authSvc, h.authConfig), r.PATCH("/:id", h.UpdateAddress, middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole)) middleware.BenefactorAuthorization(entity.UserBenefactorRole))
} }

View File

@ -33,18 +33,15 @@ func (h Handler) UpdateAddress(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.addressVld.ValidateUpdateAddress(req); err != nil { resp, sErr := h.addressSvc.Update(c.Request().Context(), req)
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
sErr := h.addressSvc.Update(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -3,25 +3,19 @@ package benefactorhandler
import ( import (
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor" benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
) )
type Handler struct { type Handler struct {
authConfig authservice.Config
authSvc authservice.Service authSvc authservice.Service
benefactorSvc benefactorservice.Service benefactorSvc benefactorservice.Service
benefactorVld benefactorvalidator.Validator
} }
func New(authConfig authservice.Config, func New(
authSvc authservice.Service, authSvc authservice.Service,
benefactorSvc benefactorservice.Service, benefactorSvc benefactorservice.Service,
benefactorVld benefactorvalidator.Validator,
) Handler { ) Handler {
return Handler{ return Handler{
authConfig: authConfig,
authSvc: authSvc, authSvc: authSvc,
benefactorSvc: benefactorSvc, benefactorSvc: benefactorSvc,
benefactorVld: benefactorVld,
} }
} }

View File

@ -3,7 +3,7 @@ package benefactorhandler
import ( import (
"net/http" "net/http"
benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore" benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -24,17 +24,16 @@ func (h Handler) loginOrRegister(c echo.Context) error {
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.benefactorVld.ValidateLoginRegisterRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorSvc.LoginOrRegister(c.Request().Context(), req) resp, sErr := h.benefactorSvc.LoginOrRegister(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -3,7 +3,7 @@ package benefactorhandler
import ( import (
"net/http" "net/http"
benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore" benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -24,17 +24,15 @@ func (h Handler) SendOtp(c echo.Context) error {
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.benefactorVld.ValidateSendOtpRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorSvc.SendOtp(c.Request().Context(), req) resp, sErr := h.benefactorSvc.SendOtp(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -24,17 +24,16 @@ func (h Handler) Get(c echo.Context) error {
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
if fieldErrors, err := h.benefactorKindBoxVld.ValidateGetRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxSvc.Get(c.Request().Context(), req) resp, sErr := h.benefactorKindBoxSvc.Get(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -49,18 +49,16 @@ func (h Handler) GetAll(c echo.Context) error {
} }
req.Filter = queryparam.GetFilterParams(c) req.Filter = queryparam.GetFilterParams(c)
if fieldErrors, err := h.benefactorKindBoxVld.ValidateGetAll(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
req.Filter["benefactor_id"] = claim.GetClaimsFromEchoContext(c).UserID req.Filter["benefactor_id"] = claim.GetClaimsFromEchoContext(c).UserID
resp, sErr := h.benefactorKindBoxSvc.GetAll(c.Request().Context(), req) resp, sErr := h.benefactorKindBoxSvc.GetAll(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

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

View File

@ -29,17 +29,15 @@ func (h Handler) RegisterEmptyingRequest(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.benefactorKindBoxVld.ValidateRegisterEmptyingRequest(req); err != nil { resp, sErr := h.benefactorKindBoxSvc.RegisterEmptyingRequest(c.Request().Context(), req)
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
sErr := h.benefactorKindBoxSvc.RegisterEmptyingRequest(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -10,7 +10,7 @@ func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactor/kindboxes") r := e.Group("/benefactor/kindboxes")
r.Use( r.Use(
middleware.Auth(h.authSvc, h.authConfig), middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole), middleware.BenefactorAuthorization(entity.UserBenefactorRole),
) )

View File

@ -31,17 +31,15 @@ func (h Handler) Add(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateAddRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxReqSvc.Add(c.Request().Context(), req) resp, sErr := h.benefactorKindBoxReqSvc.Add(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -1,153 +0,0 @@
package benefactorkindboxreqhandler_test
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"git.gocasts.ir/ebhomengo/niki/delivery/http_server/middleware"
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore"
benefactorkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
testutils "git.gocasts.ir/ebhomengo/niki/test"
"git.gocasts.ir/ebhomengo/niki/test/seed"
"github.com/brianvoe/gofakeit/v6"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)
func TestAdd(t *testing.T) {
testutils.SetupEnd2EndTest(t)
respSendOTP := testutils.SendOTP(t)
loginOrRegisterRequest := benefactoreparam.LoginOrRegisterRequest{
PhoneNumber: respSendOTP.PhoneNumber,
VerificationCode: respSendOTP.Code,
}
benefactor, cleanupBenefactor := testutils.CreateBenefactorWithSvc(t, loginOrRegisterRequest)
defer cleanupBenefactor()
benefactorAddAddressRequest := addressparam.BenefactorAddAddressRequest{
PostalCode: gofakeit.Address().Zip,
Address: gofakeit.Address().Address,
Lat: float32(gofakeit.Address().Latitude),
Lon: float32(gofakeit.Address().Longitude),
CityID: gofakeit.UintRange(1, 100),
ProvinceID: gofakeit.UintRange(1, 31),
BenefactorID: benefactor.BenefactorInfo.ID,
}
address, cleanupAddress := testutils.CreateAddressWithSvc(t, benefactorAddAddressRequest)
defer cleanupAddress()
kindboxreqResponse, _ := json.Marshal(entity.KindBoxReq{
ID: 1,
KindBoxType: entity.KindBoxCylindrical,
CountRequested: gofakeit.UintRange(1, 100),
CountAccepted: 0,
BenefactorID: benefactor.BenefactorInfo.ID,
Status: entity.KindBoxReqPendingStatus,
Description: "",
ReferDate: time.Time{},
AddressID: address.Address.ID,
})
type testCase struct {
name string
requestBody interface{}
expectedStatus int
expectedBody string
err bool
token string
}
testCases := []testCase{
{
name: "invalid payload",
requestBody: `invalid payload`,
expectedStatus: http.StatusBadRequest,
expectedBody: `{"message": "Bad request"}`,
err: true,
token: "Bearer " + benefactor.Tokens.AccessToken,
},
{
name: "invalid or expired jwt",
requestBody: benefactorkindboxreqparam.KindBoxReqAddRequest{
KindBoxType: 1,
AddressID: address.Address.ID,
ReferDate: time.Now(),
CountRequested: 1,
},
token: "Bearer 12" + benefactor.Tokens.AccessToken,
expectedStatus: http.StatusUnauthorized,
err: true,
expectedBody: `{"message":"invalid or expired jwt"}`,
},
{
name: "Validation Failed",
requestBody: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: address.Address.ID,
ReferDate: time.Now(),
CountRequested: 2,
},
err: true,
token: "Bearer " + benefactor.Tokens.AccessToken,
expectedStatus: http.StatusUnprocessableEntity,
expectedBody: `{
"errors":{
"kind_box_type":"cannot be blank"
},
"message":"invalid input"
}`,
},
{
name: "Added successfully",
requestBody: benefactorkindboxreqparam.KindBoxReqAddRequest{
KindBoxType: 2,
AddressID: address.Address.ID,
ReferDate: time.Now(),
CountRequested: 2,
},
token: "Bearer " + benefactor.Tokens.AccessToken,
expectedStatus: http.StatusCreated,
expectedBody: string(kindboxreqResponse),
},
}
e := echo.New()
r := e.Group("/benefactor/kindboxreqs")
r.POST("/", testutils.BenefactorkindBoxReqHandler.Add, middleware.Auth(testutils.AuthSvc, testutils.AuthConfig),
middleware.BenefactorAuthorization(entity.UserBenefactorRole))
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
requestBody, _ := json.Marshal(tc.requestBody)
req := httptest.NewRequest(http.MethodPost, "/benefactor/kindboxreqs/", bytes.NewBuffer(requestBody))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
req.Header.Set(echo.HeaderAuthorization, tc.token)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
// Assertion
assert.Equal(t, tc.expectedStatus, rec.Code)
if tc.err {
assert.JSONEq(t, tc.expectedBody, rec.Body.String())
return
}
response := &benefactorkindboxreqparam.KindBoxReqAddResponse{}
err := json.Unmarshal(
rec.Body.Bytes(),
response,
)
assert.Nil(t, err, "error in deserializing the request")
seed.DeleteBenefactor(t, testutils.MysqlRepo, response.KindBoxReq.ID)
assert.NotEmpty(t, response.KindBoxReq)
})
}
}

View File

@ -27,17 +27,16 @@ func (h Handler) Delete(c echo.Context) error {
} }
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateDeleteRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, dErr := h.benefactorKindBoxReqSvc.Delete(c.Request().Context(), req) resp, dErr := h.benefactorKindBoxReqSvc.Delete(c.Request().Context(), req)
if dErr != nil { if dErr != nil {
msg, code := httpmsg.Error(dErr) msg, code := httpmsg.Error(dErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -27,17 +27,15 @@ func (h Handler) Get(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateGetRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorKindBoxReqSvc.Get(c.Request().Context(), req) resp, sErr := h.benefactorKindBoxReqSvc.Get(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -41,19 +41,17 @@ func (h Handler) GetAll(c echo.Context) error {
} }
req.Filter = queryparam.GetFilterParams(c) req.Filter = queryparam.GetFilterParams(c)
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateGetAll(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
req.Filter["benefactor_id"] = claim.GetClaimsFromEchoContext(c).UserID req.Filter["benefactor_id"] = claim.GetClaimsFromEchoContext(c).UserID
resp, sErr := h.benefactorKindBoxReqSvc.GetAll(c.Request().Context(), req) resp, sErr := h.benefactorKindBoxReqSvc.GetAll(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -3,23 +3,18 @@ package benefactorkindboxreqhandler
import ( import (
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req" 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 { type Handler struct {
authConfig authservice.Config
authSvc authservice.Service authSvc authservice.Service
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service benefactorKindBoxReqSvc benefactorkindboxreqservice.Service
benefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator
} }
func New(authConfig authservice.Config, authSvc authservice.Service, func New(authSvc authservice.Service,
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service, benefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator, benefactorKindBoxReqSvc benefactorkindboxreqservice.Service,
) Handler { ) Handler {
return Handler{ return Handler{
authConfig: authConfig,
authSvc: authSvc, authSvc: authSvc,
benefactorKindBoxReqSvc: benefactorKindBoxReqSvc, benefactorKindBoxReqSvc: benefactorKindBoxReqSvc,
benefactorKindBoxReqVld: benefactorKindBoxReqVld,
} }
} }

View File

@ -10,7 +10,7 @@ func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactor/kindboxreqs") r := e.Group("/benefactor/kindboxreqs")
r.Use( r.Use(
middleware.Auth(h.authSvc, h.authConfig), middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole), middleware.BenefactorAuthorization(entity.UserBenefactorRole),
) )

View File

@ -33,18 +33,15 @@ func (h Handler) Update(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID req.BenefactorID = claims.UserID
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateUpdateRequest(req); err != nil { resp, sErr := h.benefactorKindBoxReqSvc.Update(c.Request().Context(), req)
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
sErr := h.benefactorKindBoxReqSvc.Update(c.Request().Context(), req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
})
}
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }

View File

@ -17,7 +17,7 @@ func AdminAuthorization(service adminauthorizationservice.Service,
return func(c echo.Context) (err error) { return func(c echo.Context) (err error) {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
isAllowed, err := service.CheckAccess(claims.UserID, entity.MapToAdminRole(claims.Role), permissions...) isAllowed, err := service.CheckAccess(c.Request().Context(), claims.UserID, entity.MapToAdminRole(claims.Role), permissions...)
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, errmsg.ErrorMsgSomethingWentWrong) return echo.NewHTTPError(http.StatusInternalServerError, errmsg.ErrorMsgSomethingWentWrong)
} }

View File

@ -7,10 +7,10 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
func Auth(service authservice.Service, cfg authservice.Config) echo.MiddlewareFunc { func Auth(service authservice.Service) echo.MiddlewareFunc {
return mw.WithConfig(mw.Config{ return mw.WithConfig(mw.Config{
ContextKey: config.AuthMiddlewareContextKey, ContextKey: config.AuthMiddlewareContextKey,
SigningKey: []byte(cfg.SignKey), SigningKey: []byte(service.Config.SignKey),
// TODO - as sign method string to config // TODO - as sign method string to config
SigningMethod: "HS256", SigningMethod: "HS256",
ParseTokenFunc: func(c echo.Context, auth string) (interface{}, error) { ParseTokenFunc: func(c echo.Context, auth string) (interface{}, error) {

View File

@ -5,6 +5,7 @@ import (
"git.gocasts.ir/ebhomengo/niki/config" "git.gocasts.ir/ebhomengo/niki/config"
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin" adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
adminagenthandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/agent"
adminKindBoxHandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box" adminKindBoxHandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box"
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req" adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
agentkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box" agentkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box"
@ -13,25 +14,7 @@ import (
benefactorkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box" benefactorkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box"
benefactorkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box_req" benefactorkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/docs" "git.gocasts.ir/ebhomengo/niki/docs"
adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin" "git.gocasts.ir/ebhomengo/niki/service"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address"
benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box"
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/service/notification"
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address"
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
benefactorkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box"
benefactorkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box_req"
echo "github.com/labstack/echo/v4" echo "github.com/labstack/echo/v4"
middleware "github.com/labstack/echo/v4/middleware" middleware "github.com/labstack/echo/v4/middleware"
echoSwagger "github.com/swaggo/echo-swagger" echoSwagger "github.com/swaggo/echo-swagger"
@ -40,50 +23,33 @@ import (
type Server struct { type Server struct {
config config.Config config config.Config
Router *echo.Echo Router *echo.Echo
adminHandler adminhandler.Handler
adminKindBoxReqHandler adminkindboxreqhandler.Handler
adminKindBoxHandler adminKindBoxHandler.Handler
adminAgentHandler adminagenthandler.Handler
agentKindBoxHandler agentkindboxhandler.Handler
benefactorHandler benefactorhandler.Handler benefactorHandler benefactorhandler.Handler
benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler
benefactorAddressHandler benefactoraddresshandler.Handler benefactorAddressHandler benefactoraddresshandler.Handler
benefactorKindBoxHandler benefactorkindboxhandler.Handler benefactorKindBoxHandler benefactorkindboxhandler.Handler
adminHandler adminhandler.Handler
adminKindBoxReqHandler adminkindboxreqhandler.Handler
adminKindBoxHandler adminKindBoxHandler.Handler
agentKindBoxHandler agentkindboxhandler.Handler
} }
func New( func New(
cfg config.Config, cfg config.Config,
benefactorSvc benefactorservice.Service, svc *service.Service,
benefactorVld benefactorvalidator.Validator, ) *Server {
benefactorAuthSvc authservice.Service, return &Server{
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service,
benefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator,
benefactorAddressSvc benefactoraddressservice.Service,
benefactorAddressVld benefactoraddressvalidator.Validator,
benefactorKindBoxSvc benefactorkindboxservice.Service,
benefactorKindBoxVld benefactorkindboxvalidator.Validator,
adminSvc adminservice.Service,
adminVld adminvalidator.Validator,
adminAuthSvc authservice.Service,
adminKinBoxReqSvc adminkindboxreqservice.Service,
adminKinBoxReqVld adminkindboxreqvalidator.Validator,
adminAuthorizeSvc adminauthorizationservice.Service,
adminKindBoxSvc adminkindboxservice.Service,
adminKindBoxVld adminkindboxvalidator.Validator,
agentKindBoxSvc agentkindboxservice.Service,
agentKindBoxVld agentkindboxvalidator.Validator,
notificationSvc notification.Service,
) Server {
return Server{
Router: echo.New(), Router: echo.New(),
config: cfg, config: cfg,
benefactorHandler: benefactorhandler.New(cfg.Auth, benefactorAuthSvc, benefactorSvc, benefactorVld), adminHandler: adminhandler.New(svc.AdminAuthSvc, svc.AdminSvc, svc.AdminAuthorizeSvc),
benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(cfg.Auth, benefactorAuthSvc, benefactorKindBoxReqSvc, benefactorKindBoxReqVld), adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
benefactorAddressHandler: benefactoraddresshandler.New(cfg.Auth, benefactorAuthSvc, benefactorAddressSvc, benefactorAddressVld), adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc),
benefactorKindBoxHandler: benefactorkindboxhandler.New(cfg.Auth, benefactorAuthSvc, benefactorKindBoxSvc, benefactorKindBoxVld), adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
adminHandler: adminhandler.New(cfg.AdminAuth, adminAuthSvc, adminSvc, adminVld, adminAuthorizeSvc), agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc),
adminKindBoxReqHandler: adminkindboxreqhandler.New(cfg.Auth, adminAuthSvc, adminKinBoxReqSvc, adminKinBoxReqVld, adminAuthorizeSvc, notificationSvc), benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc),
adminKindBoxHandler: adminKindBoxHandler.New(cfg.Auth, adminAuthSvc, adminKindBoxSvc, adminKindBoxVld, adminAuthorizeSvc), benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxReqSvc),
agentKindBoxHandler: agentkindboxhandler.New(cfg.AdminAuth, adminAuthSvc, agentKindBoxSvc, agentKindBoxVld, adminAuthorizeSvc), benefactorAddressHandler: benefactoraddresshandler.New(svc.BenefactorAuthSvc, svc.BenefactorAddressSvc),
benefactorKindBoxHandler: benefactorkindboxhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxSvc),
} }
} }

View File

@ -810,11 +810,11 @@ const docTemplate = `{
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_kind_box_type", "name": "filter_kind_box_type",
@ -1119,7 +1119,7 @@ const docTemplate = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminserviceparam.GetAllAgentResponse" "$ref": "#/definitions/adminagentparam.GetAllAgentResponse"
} }
}, },
"400": { "400": {
@ -1170,11 +1170,11 @@ const docTemplate = `{
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_kind_box_type", "name": "filter_kind_box_type",
@ -1182,13 +1182,13 @@ const docTemplate = `{
}, },
{ {
"enum": [ "enum": [
1, "pending",
2, "accepted",
3, "assigned-sender-agent",
4, "rejected",
5 "delivered"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBoxReq status", "description": "Filter by KindBoxReq status",
"name": "filter_status", "name": "filter_status",
@ -1496,11 +1496,11 @@ const docTemplate = `{
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_type", "name": "filter_type",
@ -2075,11 +2075,11 @@ const docTemplate = `{
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_kind_box_type", "name": "filter_kind_box_type",
@ -2495,6 +2495,12 @@ const docTemplate = `{
"properties": { "properties": {
"address": { "address": {
"$ref": "#/definitions/entity.Address" "$ref": "#/definitions/entity.Address"
},
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
} }
} }
}, },
@ -2503,6 +2509,12 @@ const docTemplate = `{
"properties": { "properties": {
"address": { "address": {
"$ref": "#/definitions/entity.Address" "$ref": "#/definitions/entity.Address"
},
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
} }
} }
}, },
@ -2568,6 +2580,38 @@ const docTemplate = `{
} }
} }
}, },
"adminagentparam.Agent": {
"type": "object",
"properties": {
"first_name": {
"type": "string",
"example": "John"
},
"id": {
"type": "integer",
"example": 1
},
"last_name": {
"type": "string",
"example": "Doe"
},
"phone_number": {
"type": "string",
"example": "09123456789"
}
}
},
"adminagentparam.GetAllAgentResponse": {
"type": "object",
"properties": {
"agents": {
"type": "array",
"items": {
"$ref": "#/definitions/adminagentparam.Agent"
}
}
}
},
"adminkindboxparam.AssignReceiverRequest": { "adminkindboxparam.AssignReceiverRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -2593,6 +2637,12 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBox" "$ref": "#/definitions/entity.KindBox"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -2619,6 +2669,12 @@ const docTemplate = `{
"deliveredAt": { "deliveredAt": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -2663,7 +2719,15 @@ const docTemplate = `{
} }
}, },
"adminkindboxreqparam.AssignSenderResponse": { "adminkindboxreqparam.AssignSenderResponse": {
"type": "object" "type": "object",
"properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}, },
"adminkindboxreqparam.DeliverKindBoxReqRequest": { "adminkindboxreqparam.DeliverKindBoxReqRequest": {
"type": "object", "type": "object",
@ -2682,7 +2746,15 @@ const docTemplate = `{
} }
}, },
"adminkindboxreqparam.DeliverKindBoxReqResponse": { "adminkindboxreqparam.DeliverKindBoxReqResponse": {
"type": "object" "type": "object",
"properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}, },
"adminkindboxreqparam.DeliveryAwaitingGetAllResponse": { "adminkindboxreqparam.DeliveryAwaitingGetAllResponse": {
"type": "object", "type": "object",
@ -2693,6 +2765,12 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -2725,6 +2803,12 @@ const docTemplate = `{
"description": { "description": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -2766,6 +2850,12 @@ const docTemplate = `{
"description": { "description": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -2803,6 +2893,12 @@ const docTemplate = `{
"deliver_refer_date": { "deliver_refer_date": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kind_box_req_id": { "kind_box_req_id": {
"type": "integer" "type": "integer"
}, },
@ -2836,13 +2932,19 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 1 "example": "on-table"
} }
} }
}, },
"adminkindboxreqparam.KindBoxReqAddResponse": { "adminkindboxreqparam.KindBoxReqAddResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kindBoxReq": { "kindBoxReq": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
@ -2857,6 +2959,12 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -2894,6 +3002,12 @@ const docTemplate = `{
"type": "string", "type": "string",
"example": "description" "example": "description"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer", "type": "integer",
"example": 1 "example": 1
@ -2904,7 +3018,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 1 "example": "on-table"
}, },
"status": { "status": {
"allOf": [ "allOf": [
@ -2912,7 +3026,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxReqStatus" "$ref": "#/definitions/entity.KindBoxReqStatus"
} }
], ],
"example": 1 "example": "pending"
} }
} }
}, },
@ -2949,7 +3063,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 2 "example": "cylindrical"
}, },
"sender_agent_id": { "sender_agent_id": {
"type": "integer", "type": "integer",
@ -2978,7 +3092,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.Gender" "$ref": "#/definitions/entity.Gender"
} }
], ],
"example": 1 "example": "male"
}, },
"id": { "id": {
"type": "integer", "type": "integer",
@ -3006,39 +3120,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.AdminStatus" "$ref": "#/definitions/entity.AdminStatus"
} }
], ],
"example": 1 "example": "active"
}
}
},
"adminserviceparam.Agent": {
"type": "object",
"properties": {
"first_name": {
"type": "string",
"example": "John"
},
"id": {
"type": "integer",
"example": 1
},
"last_name": {
"type": "string",
"example": "Doe"
},
"phone_number": {
"type": "string",
"example": "09123456789"
}
}
},
"adminserviceparam.GetAllAgentResponse": {
"type": "object",
"properties": {
"agents": {
"type": "array",
"items": {
"$ref": "#/definitions/adminserviceparam.Agent"
}
} }
} }
}, },
@ -3061,6 +3143,12 @@ const docTemplate = `{
"admin_info": { "admin_info": {
"$ref": "#/definitions/adminserviceparam.AdminInfo" "$ref": "#/definitions/adminserviceparam.AdminInfo"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"tokens": { "tokens": {
"$ref": "#/definitions/adminserviceparam.Tokens" "$ref": "#/definitions/adminserviceparam.Tokens"
} }
@ -3087,7 +3175,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.Gender" "$ref": "#/definitions/entity.Gender"
} }
], ],
"example": 1 "example": "male"
}, },
"last_name": { "last_name": {
"type": "string", "type": "string",
@ -3115,7 +3203,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.AdminStatus" "$ref": "#/definitions/entity.AdminStatus"
} }
], ],
"example": 1 "example": "active"
} }
} }
}, },
@ -3124,6 +3212,12 @@ const docTemplate = `{
"properties": { "properties": {
"admin": { "admin": {
"$ref": "#/definitions/entity.Admin" "$ref": "#/definitions/entity.Admin"
},
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
} }
} }
}, },
@ -3147,6 +3241,12 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBox" "$ref": "#/definitions/entity.KindBox"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -3173,6 +3273,12 @@ const docTemplate = `{
"deliveredAt": { "deliveredAt": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -3232,7 +3338,11 @@ const docTemplate = `{
"example": "rez" "example": "rez"
}, },
"role": { "role": {
"type": "string", "allOf": [
{
"$ref": "#/definitions/entity.UserRole"
}
],
"example": "benefactor" "example": "benefactor"
} }
} }
@ -3256,6 +3366,12 @@ const docTemplate = `{
"benefactore_info": { "benefactore_info": {
"$ref": "#/definitions/benefactoreparam.BenefactroInfo" "$ref": "#/definitions/benefactoreparam.BenefactroInfo"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"tokens": { "tokens": {
"$ref": "#/definitions/benefactoreparam.Tokens" "$ref": "#/definitions/benefactoreparam.Tokens"
} }
@ -3277,6 +3393,12 @@ const docTemplate = `{
"description": "this just use in test .env\n\t\tTODO - remove it after test", "description": "this just use in test .env\n\t\tTODO - remove it after test",
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"phone_number": { "phone_number": {
"type": "string", "type": "string",
"example": "09198829528" "example": "09198829528"
@ -3303,6 +3425,12 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBox" "$ref": "#/definitions/entity.KindBox"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -3329,6 +3457,12 @@ const docTemplate = `{
"deliveredAt": { "deliveredAt": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -3390,6 +3524,12 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -3424,24 +3564,44 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 1 "example": "on-table"
} }
} }
}, },
"benefactorkindboxreqparam.KindBoxReqAddResponse": { "benefactorkindboxreqparam.KindBoxReqAddResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kind_box_req": { "kind_box_req": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
} }
}, },
"benefactorkindboxreqparam.KindBoxReqDeleteResponse": { "benefactorkindboxreqparam.KindBoxReqDeleteResponse": {
"type": "object" "type": "object",
"properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}, },
"benefactorkindboxreqparam.KindBoxReqGetResponse": { "benefactorkindboxreqparam.KindBoxReqGetResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kind_box_req": { "kind_box_req": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
@ -3476,7 +3636,7 @@ const docTemplate = `{
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 2 "example": "cylindrical"
} }
} }
}, },
@ -3561,10 +3721,10 @@ const docTemplate = `{
] ]
}, },
"entity.AdminStatus": { "entity.AdminStatus": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "active",
2 "inactive"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"AdminActiveStatus", "AdminActiveStatus",
@ -3586,10 +3746,10 @@ const docTemplate = `{
} }
}, },
"entity.Gender": { "entity.Gender": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "male",
2 "female"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"MaleGender", "MaleGender",
@ -3694,13 +3854,13 @@ const docTemplate = `{
} }
}, },
"entity.KindBoxReqStatus": { "entity.KindBoxReqStatus": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "pending",
2, "accepted",
3, "assigned-sender-agent",
4, "rejected",
5 "delivered"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"KindBoxReqPendingStatus", "KindBoxReqPendingStatus",
@ -3711,13 +3871,13 @@ const docTemplate = `{
] ]
}, },
"entity.KindBoxStatus": { "entity.KindBoxStatus": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "delivered",
2, "ready-to-return",
3, "assigned-receiver-agent",
4, "returned",
5 "enumerated"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"KindBoxDeliveredStatus", "KindBoxDeliveredStatus",
@ -3728,11 +3888,11 @@ const docTemplate = `{
] ]
}, },
"entity.KindBoxType": { "entity.KindBoxType": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"KindBoxOnTable", "KindBoxOnTable",
@ -3751,6 +3911,15 @@ const docTemplate = `{
} }
} }
}, },
"entity.UserRole": {
"type": "string",
"enum": [
"benefactor"
],
"x-enum-varnames": [
"UserBenefactorRole"
]
},
"httpmsg.ErrorResponse": { "httpmsg.ErrorResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3785,7 +3954,7 @@ const docTemplate = `{
}, },
"securityDefinitions": { "securityDefinitions": {
"AuthBearerAdmin": { "AuthBearerAdmin": {
"description": "Type the word 'Bearer' followed by a space and Admin JWT token", "description": "Type the word 'Bearer' followed by a space and Admin JWT token.",
"type": "apiKey", "type": "apiKey",
"name": "Authorization", "name": "Authorization",
"in": "header" "in": "header"

View File

@ -799,11 +799,11 @@
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_kind_box_type", "name": "filter_kind_box_type",
@ -1108,7 +1108,7 @@
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminserviceparam.GetAllAgentResponse" "$ref": "#/definitions/adminagentparam.GetAllAgentResponse"
} }
}, },
"400": { "400": {
@ -1159,11 +1159,11 @@
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_kind_box_type", "name": "filter_kind_box_type",
@ -1171,13 +1171,13 @@
}, },
{ {
"enum": [ "enum": [
1, "pending",
2, "accepted",
3, "assigned-sender-agent",
4, "rejected",
5 "delivered"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBoxReq status", "description": "Filter by KindBoxReq status",
"name": "filter_status", "name": "filter_status",
@ -1485,11 +1485,11 @@
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_type", "name": "filter_type",
@ -2064,11 +2064,11 @@
}, },
{ {
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"type": "integer", "type": "string",
"format": "enum", "format": "enum",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_kind_box_type", "name": "filter_kind_box_type",
@ -2484,6 +2484,12 @@
"properties": { "properties": {
"address": { "address": {
"$ref": "#/definitions/entity.Address" "$ref": "#/definitions/entity.Address"
},
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
} }
} }
}, },
@ -2492,6 +2498,12 @@
"properties": { "properties": {
"address": { "address": {
"$ref": "#/definitions/entity.Address" "$ref": "#/definitions/entity.Address"
},
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
} }
} }
}, },
@ -2557,6 +2569,38 @@
} }
} }
}, },
"adminagentparam.Agent": {
"type": "object",
"properties": {
"first_name": {
"type": "string",
"example": "John"
},
"id": {
"type": "integer",
"example": 1
},
"last_name": {
"type": "string",
"example": "Doe"
},
"phone_number": {
"type": "string",
"example": "09123456789"
}
}
},
"adminagentparam.GetAllAgentResponse": {
"type": "object",
"properties": {
"agents": {
"type": "array",
"items": {
"$ref": "#/definitions/adminagentparam.Agent"
}
}
}
},
"adminkindboxparam.AssignReceiverRequest": { "adminkindboxparam.AssignReceiverRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -2582,6 +2626,12 @@
"$ref": "#/definitions/entity.KindBox" "$ref": "#/definitions/entity.KindBox"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -2608,6 +2658,12 @@
"deliveredAt": { "deliveredAt": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -2652,7 +2708,15 @@
} }
}, },
"adminkindboxreqparam.AssignSenderResponse": { "adminkindboxreqparam.AssignSenderResponse": {
"type": "object" "type": "object",
"properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}, },
"adminkindboxreqparam.DeliverKindBoxReqRequest": { "adminkindboxreqparam.DeliverKindBoxReqRequest": {
"type": "object", "type": "object",
@ -2671,7 +2735,15 @@
} }
}, },
"adminkindboxreqparam.DeliverKindBoxReqResponse": { "adminkindboxreqparam.DeliverKindBoxReqResponse": {
"type": "object" "type": "object",
"properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}, },
"adminkindboxreqparam.DeliveryAwaitingGetAllResponse": { "adminkindboxreqparam.DeliveryAwaitingGetAllResponse": {
"type": "object", "type": "object",
@ -2682,6 +2754,12 @@
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -2714,6 +2792,12 @@
"description": { "description": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -2755,6 +2839,12 @@
"description": { "description": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -2792,6 +2882,12 @@
"deliver_refer_date": { "deliver_refer_date": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kind_box_req_id": { "kind_box_req_id": {
"type": "integer" "type": "integer"
}, },
@ -2825,13 +2921,19 @@
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 1 "example": "on-table"
} }
} }
}, },
"adminkindboxreqparam.KindBoxReqAddResponse": { "adminkindboxreqparam.KindBoxReqAddResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kindBoxReq": { "kindBoxReq": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
@ -2846,6 +2948,12 @@
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -2883,6 +2991,12 @@
"type": "string", "type": "string",
"example": "description" "example": "description"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer", "type": "integer",
"example": 1 "example": 1
@ -2893,7 +3007,7 @@
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 1 "example": "on-table"
}, },
"status": { "status": {
"allOf": [ "allOf": [
@ -2901,7 +3015,7 @@
"$ref": "#/definitions/entity.KindBoxReqStatus" "$ref": "#/definitions/entity.KindBoxReqStatus"
} }
], ],
"example": 1 "example": "pending"
} }
} }
}, },
@ -2938,7 +3052,7 @@
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 2 "example": "cylindrical"
}, },
"sender_agent_id": { "sender_agent_id": {
"type": "integer", "type": "integer",
@ -2967,7 +3081,7 @@
"$ref": "#/definitions/entity.Gender" "$ref": "#/definitions/entity.Gender"
} }
], ],
"example": 1 "example": "male"
}, },
"id": { "id": {
"type": "integer", "type": "integer",
@ -2995,39 +3109,7 @@
"$ref": "#/definitions/entity.AdminStatus" "$ref": "#/definitions/entity.AdminStatus"
} }
], ],
"example": 1 "example": "active"
}
}
},
"adminserviceparam.Agent": {
"type": "object",
"properties": {
"first_name": {
"type": "string",
"example": "John"
},
"id": {
"type": "integer",
"example": 1
},
"last_name": {
"type": "string",
"example": "Doe"
},
"phone_number": {
"type": "string",
"example": "09123456789"
}
}
},
"adminserviceparam.GetAllAgentResponse": {
"type": "object",
"properties": {
"agents": {
"type": "array",
"items": {
"$ref": "#/definitions/adminserviceparam.Agent"
}
} }
} }
}, },
@ -3050,6 +3132,12 @@
"admin_info": { "admin_info": {
"$ref": "#/definitions/adminserviceparam.AdminInfo" "$ref": "#/definitions/adminserviceparam.AdminInfo"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"tokens": { "tokens": {
"$ref": "#/definitions/adminserviceparam.Tokens" "$ref": "#/definitions/adminserviceparam.Tokens"
} }
@ -3076,7 +3164,7 @@
"$ref": "#/definitions/entity.Gender" "$ref": "#/definitions/entity.Gender"
} }
], ],
"example": 1 "example": "male"
}, },
"last_name": { "last_name": {
"type": "string", "type": "string",
@ -3104,7 +3192,7 @@
"$ref": "#/definitions/entity.AdminStatus" "$ref": "#/definitions/entity.AdminStatus"
} }
], ],
"example": 1 "example": "active"
} }
} }
}, },
@ -3113,6 +3201,12 @@
"properties": { "properties": {
"admin": { "admin": {
"$ref": "#/definitions/entity.Admin" "$ref": "#/definitions/entity.Admin"
},
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
} }
} }
}, },
@ -3136,6 +3230,12 @@
"$ref": "#/definitions/entity.KindBox" "$ref": "#/definitions/entity.KindBox"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -3162,6 +3262,12 @@
"deliveredAt": { "deliveredAt": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -3221,7 +3327,11 @@
"example": "rez" "example": "rez"
}, },
"role": { "role": {
"type": "string", "allOf": [
{
"$ref": "#/definitions/entity.UserRole"
}
],
"example": "benefactor" "example": "benefactor"
} }
} }
@ -3245,6 +3355,12 @@
"benefactore_info": { "benefactore_info": {
"$ref": "#/definitions/benefactoreparam.BenefactroInfo" "$ref": "#/definitions/benefactoreparam.BenefactroInfo"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"tokens": { "tokens": {
"$ref": "#/definitions/benefactoreparam.Tokens" "$ref": "#/definitions/benefactoreparam.Tokens"
} }
@ -3266,6 +3382,12 @@
"description": "this just use in test .env\n\t\tTODO - remove it after test", "description": "this just use in test .env\n\t\tTODO - remove it after test",
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"phone_number": { "phone_number": {
"type": "string", "type": "string",
"example": "09198829528" "example": "09198829528"
@ -3292,6 +3414,12 @@
"$ref": "#/definitions/entity.KindBox" "$ref": "#/definitions/entity.KindBox"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -3318,6 +3446,12 @@
"deliveredAt": { "deliveredAt": {
"type": "string" "type": "string"
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"id": { "id": {
"type": "integer" "type": "integer"
}, },
@ -3379,6 +3513,12 @@
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
}, },
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
@ -3413,24 +3553,44 @@
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 1 "example": "on-table"
} }
} }
}, },
"benefactorkindboxreqparam.KindBoxReqAddResponse": { "benefactorkindboxreqparam.KindBoxReqAddResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kind_box_req": { "kind_box_req": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
} }
}, },
"benefactorkindboxreqparam.KindBoxReqDeleteResponse": { "benefactorkindboxreqparam.KindBoxReqDeleteResponse": {
"type": "object" "type": "object",
"properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}, },
"benefactorkindboxreqparam.KindBoxReqGetResponse": { "benefactorkindboxreqparam.KindBoxReqGetResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"fieldErrors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"kind_box_req": { "kind_box_req": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
} }
@ -3465,7 +3625,7 @@
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"
} }
], ],
"example": 2 "example": "cylindrical"
} }
} }
}, },
@ -3550,10 +3710,10 @@
] ]
}, },
"entity.AdminStatus": { "entity.AdminStatus": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "active",
2 "inactive"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"AdminActiveStatus", "AdminActiveStatus",
@ -3575,10 +3735,10 @@
} }
}, },
"entity.Gender": { "entity.Gender": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "male",
2 "female"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"MaleGender", "MaleGender",
@ -3683,13 +3843,13 @@
} }
}, },
"entity.KindBoxReqStatus": { "entity.KindBoxReqStatus": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "pending",
2, "accepted",
3, "assigned-sender-agent",
4, "rejected",
5 "delivered"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"KindBoxReqPendingStatus", "KindBoxReqPendingStatus",
@ -3700,13 +3860,13 @@
] ]
}, },
"entity.KindBoxStatus": { "entity.KindBoxStatus": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "delivered",
2, "ready-to-return",
3, "assigned-receiver-agent",
4, "returned",
5 "enumerated"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"KindBoxDeliveredStatus", "KindBoxDeliveredStatus",
@ -3717,11 +3877,11 @@
] ]
}, },
"entity.KindBoxType": { "entity.KindBoxType": {
"type": "integer", "type": "string",
"enum": [ "enum": [
1, "on-table",
2, "cylindrical",
3 "stand-up"
], ],
"x-enum-varnames": [ "x-enum-varnames": [
"KindBoxOnTable", "KindBoxOnTable",
@ -3740,6 +3900,15 @@
} }
} }
}, },
"entity.UserRole": {
"type": "string",
"enum": [
"benefactor"
],
"x-enum-varnames": [
"UserBenefactorRole"
]
},
"httpmsg.ErrorResponse": { "httpmsg.ErrorResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3774,7 +3943,7 @@
}, },
"securityDefinitions": { "securityDefinitions": {
"AuthBearerAdmin": { "AuthBearerAdmin": {
"description": "Type the word 'Bearer' followed by a space and Admin JWT token", "description": "Type the word 'Bearer' followed by a space and Admin JWT token.",
"type": "apiKey", "type": "apiKey",
"name": "Authorization", "name": "Authorization",
"in": "header" "in": "header"

View File

@ -24,11 +24,19 @@ definitions:
properties: properties:
address: address:
$ref: '#/definitions/entity.Address' $ref: '#/definitions/entity.Address'
fieldErrors:
additionalProperties:
type: string
type: object
type: object type: object
addressparam.GetAddressResponse: addressparam.GetAddressResponse:
properties: properties:
address: address:
$ref: '#/definitions/entity.Address' $ref: '#/definitions/entity.Address'
fieldErrors:
additionalProperties:
type: string
type: object
type: object type: object
addressparam.GetAllAddressesResponse: addressparam.GetAllAddressesResponse:
properties: properties:
@ -72,6 +80,28 @@ definitions:
example: "1234567890" example: "1234567890"
type: string type: string
type: object type: object
adminagentparam.Agent:
properties:
first_name:
example: John
type: string
id:
example: 1
type: integer
last_name:
example: Doe
type: string
phone_number:
example: "09123456789"
type: string
type: object
adminagentparam.GetAllAgentResponse:
properties:
agents:
items:
$ref: '#/definitions/adminagentparam.Agent'
type: array
type: object
adminkindboxparam.AssignReceiverRequest: adminkindboxparam.AssignReceiverRequest:
properties: properties:
receiver_agent_id: receiver_agent_id:
@ -88,6 +118,10 @@ definitions:
items: items:
$ref: '#/definitions/entity.KindBox' $ref: '#/definitions/entity.KindBox'
type: array type: array
fieldErrors:
additionalProperties:
type: string
type: object
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
@ -105,6 +139,10 @@ definitions:
type: integer type: integer
deliveredAt: deliveredAt:
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
id: id:
type: integer type: integer
kindBoxReqID: kindBoxReqID:
@ -134,6 +172,11 @@ definitions:
type: integer type: integer
type: object type: object
adminkindboxreqparam.AssignSenderResponse: adminkindboxreqparam.AssignSenderResponse:
properties:
fieldErrors:
additionalProperties:
type: string
type: object
type: object type: object
adminkindboxreqparam.DeliverKindBoxReqRequest: adminkindboxreqparam.DeliverKindBoxReqRequest:
properties: properties:
@ -147,6 +190,11 @@ definitions:
type: array type: array
type: object type: object
adminkindboxreqparam.DeliverKindBoxReqResponse: adminkindboxreqparam.DeliverKindBoxReqResponse:
properties:
fieldErrors:
additionalProperties:
type: string
type: object
type: object type: object
adminkindboxreqparam.DeliveryAwaitingGetAllResponse: adminkindboxreqparam.DeliveryAwaitingGetAllResponse:
properties: properties:
@ -154,6 +202,10 @@ definitions:
items: items:
$ref: '#/definitions/entity.KindBoxReq' $ref: '#/definitions/entity.KindBoxReq'
type: array type: array
fieldErrors:
additionalProperties:
type: string
type: object
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
@ -175,6 +227,10 @@ definitions:
type: string type: string
description: description:
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
id: id:
type: integer type: integer
kindBoxType: kindBoxType:
@ -202,6 +258,10 @@ definitions:
type: string type: string
description: description:
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
id: id:
type: integer type: integer
kindBoxType: kindBoxType:
@ -226,6 +286,10 @@ definitions:
type: integer type: integer
deliver_refer_date: deliver_refer_date:
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
kind_box_req_id: kind_box_req_id:
type: integer type: integer
kind_box_req_status: kind_box_req_status:
@ -248,10 +312,14 @@ definitions:
kind_box_type: kind_box_type:
allOf: allOf:
- $ref: '#/definitions/entity.KindBoxType' - $ref: '#/definitions/entity.KindBoxType'
example: 1 example: on-table
type: object type: object
adminkindboxreqparam.KindBoxReqAddResponse: adminkindboxreqparam.KindBoxReqAddResponse:
properties: properties:
fieldErrors:
additionalProperties:
type: string
type: object
kindBoxReq: kindBoxReq:
$ref: '#/definitions/entity.KindBoxReq' $ref: '#/definitions/entity.KindBoxReq'
type: object type: object
@ -261,6 +329,10 @@ definitions:
items: items:
$ref: '#/definitions/entity.KindBoxReq' $ref: '#/definitions/entity.KindBoxReq'
type: array type: array
fieldErrors:
additionalProperties:
type: string
type: object
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
@ -287,17 +359,21 @@ definitions:
description: description:
example: description example: description
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
id: id:
example: 1 example: 1
type: integer type: integer
kind_box_type: kind_box_type:
allOf: allOf:
- $ref: '#/definitions/entity.KindBoxType' - $ref: '#/definitions/entity.KindBoxType'
example: 1 example: on-table
status: status:
allOf: allOf:
- $ref: '#/definitions/entity.KindBoxReqStatus' - $ref: '#/definitions/entity.KindBoxReqStatus'
example: 1 example: pending
type: object type: object
adminkindboxreqparam.KindBoxReqUpdateRequest: adminkindboxreqparam.KindBoxReqUpdateRequest:
properties: properties:
@ -322,7 +398,7 @@ definitions:
kind_box_type: kind_box_type:
allOf: allOf:
- $ref: '#/definitions/entity.KindBoxType' - $ref: '#/definitions/entity.KindBoxType'
example: 2 example: cylindrical
sender_agent_id: sender_agent_id:
example: 1 example: 1
type: integer type: integer
@ -341,7 +417,7 @@ definitions:
gender: gender:
allOf: allOf:
- $ref: '#/definitions/entity.Gender' - $ref: '#/definitions/entity.Gender'
example: 1 example: male
id: id:
example: 1 example: 1
type: integer type: integer
@ -358,29 +434,7 @@ definitions:
status: status:
allOf: allOf:
- $ref: '#/definitions/entity.AdminStatus' - $ref: '#/definitions/entity.AdminStatus'
example: 1 example: active
type: object
adminserviceparam.Agent:
properties:
first_name:
example: John
type: string
id:
example: 1
type: integer
last_name:
example: Doe
type: string
phone_number:
example: "09123456789"
type: string
type: object
adminserviceparam.GetAllAgentResponse:
properties:
agents:
items:
$ref: '#/definitions/adminserviceparam.Agent'
type: array
type: object type: object
adminserviceparam.LoginWithPhoneNumberRequest: adminserviceparam.LoginWithPhoneNumberRequest:
properties: properties:
@ -395,6 +449,10 @@ definitions:
properties: properties:
admin_info: admin_info:
$ref: '#/definitions/adminserviceparam.AdminInfo' $ref: '#/definitions/adminserviceparam.AdminInfo'
fieldErrors:
additionalProperties:
type: string
type: object
tokens: tokens:
$ref: '#/definitions/adminserviceparam.Tokens' $ref: '#/definitions/adminserviceparam.Tokens'
type: object type: object
@ -412,7 +470,7 @@ definitions:
gender: gender:
allOf: allOf:
- $ref: '#/definitions/entity.Gender' - $ref: '#/definitions/entity.Gender'
example: 1 example: male
last_name: last_name:
example: shahi example: shahi
type: string type: string
@ -429,12 +487,16 @@ definitions:
status: status:
allOf: allOf:
- $ref: '#/definitions/entity.AdminStatus' - $ref: '#/definitions/entity.AdminStatus'
example: 1 example: active
type: object type: object
adminserviceparam.RegisterResponse: adminserviceparam.RegisterResponse:
properties: properties:
admin: admin:
$ref: '#/definitions/entity.Admin' $ref: '#/definitions/entity.Admin'
fieldErrors:
additionalProperties:
type: string
type: object
type: object type: object
adminserviceparam.Tokens: adminserviceparam.Tokens:
properties: properties:
@ -449,6 +511,10 @@ definitions:
items: items:
$ref: '#/definitions/entity.KindBox' $ref: '#/definitions/entity.KindBox'
type: array type: array
fieldErrors:
additionalProperties:
type: string
type: object
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
@ -466,6 +532,10 @@ definitions:
type: integer type: integer
deliveredAt: deliveredAt:
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
id: id:
type: integer type: integer
kindBoxReqID: kindBoxReqID:
@ -506,8 +576,9 @@ definitions:
example: rez example: rez
type: string type: string
role: role:
allOf:
- $ref: '#/definitions/entity.UserRole'
example: benefactor example: benefactor
type: string
type: object type: object
benefactoreparam.LoginOrRegisterRequest: benefactoreparam.LoginOrRegisterRequest:
properties: properties:
@ -522,6 +593,10 @@ definitions:
properties: properties:
benefactore_info: benefactore_info:
$ref: '#/definitions/benefactoreparam.BenefactroInfo' $ref: '#/definitions/benefactoreparam.BenefactroInfo'
fieldErrors:
additionalProperties:
type: string
type: object
tokens: tokens:
$ref: '#/definitions/benefactoreparam.Tokens' $ref: '#/definitions/benefactoreparam.Tokens'
type: object type: object
@ -536,6 +611,10 @@ definitions:
code: code:
description: "this just use in test .env\n\t\tTODO - remove it after test" description: "this just use in test .env\n\t\tTODO - remove it after test"
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
phone_number: phone_number:
example: "09198829528" example: "09198829528"
type: string type: string
@ -553,6 +632,10 @@ definitions:
items: items:
$ref: '#/definitions/entity.KindBox' $ref: '#/definitions/entity.KindBox'
type: array type: array
fieldErrors:
additionalProperties:
type: string
type: object
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
@ -570,6 +653,10 @@ definitions:
type: integer type: integer
deliveredAt: deliveredAt:
type: string type: string
fieldErrors:
additionalProperties:
type: string
type: object
id: id:
type: integer type: integer
kindBoxReqID: kindBoxReqID:
@ -611,6 +698,10 @@ definitions:
items: items:
$ref: '#/definitions/entity.KindBoxReq' $ref: '#/definitions/entity.KindBoxReq'
type: array type: array
fieldErrors:
additionalProperties:
type: string
type: object
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
@ -634,17 +725,30 @@ definitions:
kind_box_type: kind_box_type:
allOf: allOf:
- $ref: '#/definitions/entity.KindBoxType' - $ref: '#/definitions/entity.KindBoxType'
example: 1 example: on-table
type: object type: object
benefactorkindboxreqparam.KindBoxReqAddResponse: benefactorkindboxreqparam.KindBoxReqAddResponse:
properties: properties:
fieldErrors:
additionalProperties:
type: string
type: object
kind_box_req: kind_box_req:
$ref: '#/definitions/entity.KindBoxReq' $ref: '#/definitions/entity.KindBoxReq'
type: object type: object
benefactorkindboxreqparam.KindBoxReqDeleteResponse: benefactorkindboxreqparam.KindBoxReqDeleteResponse:
properties:
fieldErrors:
additionalProperties:
type: string
type: object
type: object type: object
benefactorkindboxreqparam.KindBoxReqGetResponse: benefactorkindboxreqparam.KindBoxReqGetResponse:
properties: properties:
fieldErrors:
additionalProperties:
type: string
type: object
kind_box_req: kind_box_req:
$ref: '#/definitions/entity.KindBoxReq' $ref: '#/definitions/entity.KindBoxReq'
type: object type: object
@ -668,7 +772,7 @@ definitions:
kind_box_type: kind_box_type:
allOf: allOf:
- $ref: '#/definitions/entity.KindBoxType' - $ref: '#/definitions/entity.KindBoxType'
example: 2 example: cylindrical
type: object type: object
entity.Address: entity.Address:
properties: properties:
@ -726,9 +830,9 @@ definitions:
- AdminAgentRole - AdminAgentRole
entity.AdminStatus: entity.AdminStatus:
enum: enum:
- 1 - active
- 2 - inactive
type: integer type: string
x-enum-varnames: x-enum-varnames:
- AdminActiveStatus - AdminActiveStatus
- AdminInactiveStatus - AdminInactiveStatus
@ -743,9 +847,9 @@ definitions:
type: object type: object
entity.Gender: entity.Gender:
enum: enum:
- 1 - male
- 2 - female
type: integer type: string
x-enum-varnames: x-enum-varnames:
- MaleGender - MaleGender
- FemaleGender - FemaleGender
@ -815,12 +919,12 @@ definitions:
type: object type: object
entity.KindBoxReqStatus: entity.KindBoxReqStatus:
enum: enum:
- 1 - pending
- 2 - accepted
- 3 - assigned-sender-agent
- 4 - rejected
- 5 - delivered
type: integer type: string
x-enum-varnames: x-enum-varnames:
- KindBoxReqPendingStatus - KindBoxReqPendingStatus
- KindBoxReqAcceptedStatus - KindBoxReqAcceptedStatus
@ -829,12 +933,12 @@ definitions:
- KindBoxReqDeliveredStatus - KindBoxReqDeliveredStatus
entity.KindBoxStatus: entity.KindBoxStatus:
enum: enum:
- 1 - delivered
- 2 - ready-to-return
- 3 - assigned-receiver-agent
- 4 - returned
- 5 - enumerated
type: integer type: string
x-enum-varnames: x-enum-varnames:
- KindBoxDeliveredStatus - KindBoxDeliveredStatus
- KindBoxReadyToReturnStatus - KindBoxReadyToReturnStatus
@ -843,10 +947,10 @@ definitions:
- KindBoxEnumeratedStatus - KindBoxEnumeratedStatus
entity.KindBoxType: entity.KindBoxType:
enum: enum:
- 1 - on-table
- 2 - cylindrical
- 3 - stand-up
type: integer type: string
x-enum-varnames: x-enum-varnames:
- KindBoxOnTable - KindBoxOnTable
- KindBoxCylindrical - KindBoxCylindrical
@ -858,6 +962,12 @@ definitions:
name: name:
type: string type: string
type: object type: object
entity.UserRole:
enum:
- benefactor
type: string
x-enum-varnames:
- UserBenefactorRole
httpmsg.ErrorResponse: httpmsg.ErrorResponse:
properties: properties:
errors: errors:
@ -1424,13 +1534,13 @@ paths:
type: integer type: integer
- description: Filter by KindBox type - description: Filter by KindBox type
enum: enum:
- 1 - on-table
- 2 - cylindrical
- 3 - stand-up
format: enum format: enum
in: query in: query
name: filter_kind_box_type name: filter_kind_box_type
type: integer type: string
- description: Filter by count requested - description: Filter by count requested
in: query in: query
name: filter_count_requested name: filter_count_requested
@ -1596,7 +1706,7 @@ paths:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/adminserviceparam.GetAllAgentResponse' $ref: '#/definitions/adminagentparam.GetAllAgentResponse'
"400": "400":
description: Bad request description: Bad request
schema: schema:
@ -1627,24 +1737,24 @@ paths:
type: integer type: integer
- description: Filter by KindBox type - description: Filter by KindBox type
enum: enum:
- 1 - on-table
- 2 - cylindrical
- 3 - stand-up
format: enum format: enum
in: query in: query
name: filter_kind_box_type name: filter_kind_box_type
type: integer type: string
- description: Filter by KindBoxReq status - description: Filter by KindBoxReq status
enum: enum:
- 1 - pending
- 2 - accepted
- 3 - assigned-sender-agent
- 4 - rejected
- 5 - delivered
format: enum format: enum
in: query in: query
name: filter_status name: filter_status
type: integer type: string
- description: Filter by count requested - description: Filter by count requested
in: query in: query
name: filter_count_requested name: filter_count_requested
@ -1845,13 +1955,13 @@ paths:
type: integer type: integer
- description: Filter by KindBox type - description: Filter by KindBox type
enum: enum:
- 1 - on-table
- 2 - cylindrical
- 3 - stand-up
format: enum format: enum
in: query in: query
name: filter_type name: filter_type
type: integer type: string
- description: Filter by serial number - description: Filter by serial number
in: query in: query
name: filter_serial_number name: filter_serial_number
@ -2235,13 +2345,13 @@ paths:
type: integer type: integer
- description: Filter by KindBox type - description: Filter by KindBox type
enum: enum:
- 1 - on-table
- 2 - cylindrical
- 3 - stand-up
format: enum format: enum
in: query in: query
name: filter_kind_box_type name: filter_kind_box_type
type: integer type: string
- description: Filter by KindBoxReq Status - description: Filter by KindBoxReq Status
enum: enum:
- pending - pending
@ -2497,7 +2607,7 @@ paths:
- Benefactor - Benefactor
securityDefinitions: securityDefinitions:
AuthBearerAdmin: AuthBearerAdmin:
description: Type the word 'Bearer' followed by a space and Admin JWT token description: Type the word 'Bearer' followed by a space and Admin JWT token.
in: header in: header
name: Authorization name: Authorization
type: apiKey type: apiKey

View File

@ -22,16 +22,6 @@ func (s AdminRole) IsValid() bool {
return s > 0 && int(s) <= len(AdminRoleStrings) return s > 0 && int(s) <= len(AdminRoleStrings)
} }
// AllAdminRole returns a slice containing all string values of AdminRole.
func AllAdminRole() []string {
roleStrings := make([]string, len(AdminRoleStrings))
for role, str := range AdminRoleStrings {
roleStrings[int(role)-1] = str
}
return roleStrings
}
// MapToAdminRole converts a string to the corresponding AdminRole value. // MapToAdminRole converts a string to the corresponding AdminRole value.
func MapToAdminRole(roleStr string) AdminRole { func MapToAdminRole(roleStr string) AdminRole {
for role, str := range AdminRoleStrings { for role, str := range AdminRoleStrings {

View File

@ -1,10 +1,10 @@
package entity package entity
type AdminStatus uint type AdminStatus string
const ( const (
AdminActiveStatus AdminStatus = iota + 1 AdminActiveStatus = AdminStatus("active")
AdminInactiveStatus AdminInactiveStatus = AdminStatus("inactive")
) )
var AdminStatusStrings = map[AdminStatus]string{ var AdminStatusStrings = map[AdminStatus]string{
@ -12,31 +12,8 @@ var AdminStatusStrings = map[AdminStatus]string{
AdminInactiveStatus: "inactive", AdminInactiveStatus: "inactive",
} }
func (s AdminStatus) String() string { func (a AdminStatus) IsValid() bool {
return AdminStatusStrings[s] _, ok := AdminStatusStrings[a]
}
return ok
func (s AdminStatus) IsValid() bool {
return s > 0 && int(s) <= len(AdminStatusStrings)
}
// AllAdminStatus returns a slice containing all string values of AdminStatus.
func AllAdminStatus() []string {
statusStrings := make([]string, len(AdminStatusStrings))
for status, str := range AdminStatusStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
// MapToAdminStatus converts a string to the corresponding AdminStatus value.
func MapToAdminStatus(statusStr string) AdminStatus {
for status, str := range AdminStatusStrings {
if str == statusStr {
return status
}
}
return AdminStatus(0)
} }

View File

@ -1,10 +1,10 @@
package entity package entity
type Gender uint type Gender string
const ( const (
MaleGender Gender = iota + 1 MaleGender = Gender("male")
FemaleGender FemaleGender = Gender("female")
) )
var GenderStrings = map[Gender]string{ var GenderStrings = map[Gender]string{
@ -12,31 +12,8 @@ var GenderStrings = map[Gender]string{
FemaleGender: "female", FemaleGender: "female",
} }
func (s Gender) String() string { func (g Gender) IsValid() bool {
return GenderStrings[s] _, ok := GenderStrings[g]
}
return ok
// AllGender returns a slice containing all string values of Gender.
func AllGender() []string {
statusStrings := make([]string, len(GenderStrings))
for status, str := range GenderStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
func (s Gender) IsValid() bool {
return s > 0 && int(s) <= len(GenderStrings)
}
// MapToGender converts a string to the corresponding Gender value.
func MapToGender(statusStr string) Gender {
for status, str := range GenderStrings {
if str == statusStr {
return status
}
}
return Gender(0)
} }

View File

@ -1,44 +1,11 @@
package entity package entity
type KindBoxReqStatus uint type KindBoxReqStatus string
const ( const (
KindBoxReqPendingStatus KindBoxReqStatus = iota + 1 KindBoxReqPendingStatus = KindBoxReqStatus("pending")
KindBoxReqAcceptedStatus KindBoxReqAcceptedStatus = KindBoxReqStatus("accepted")
KindBoxReqAssignedSenderAgentStatus KindBoxReqAssignedSenderAgentStatus = KindBoxReqStatus("assigned-sender-agent")
KindBoxReqRejectedStatus KindBoxReqRejectedStatus = KindBoxReqStatus("rejected")
KindBoxReqDeliveredStatus KindBoxReqDeliveredStatus = KindBoxReqStatus("delivered")
) )
var kindBoxReqStatusStrings = map[KindBoxReqStatus]string{
KindBoxReqPendingStatus: "pending",
KindBoxReqAcceptedStatus: "accepted",
KindBoxReqAssignedSenderAgentStatus: "assigned-sender-agent",
KindBoxReqRejectedStatus: "rejected",
KindBoxReqDeliveredStatus: "delivered",
}
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(kindBoxStatusStrings))
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 {
for status, str := range kindBoxReqStatusStrings {
if str == statusStr {
return status
}
}
return KindBoxReqStatus(0)
}

View File

@ -1,44 +1,11 @@
package entity package entity
type KindBoxStatus uint type KindBoxStatus string
const ( const (
KindBoxDeliveredStatus KindBoxStatus = iota + 1 KindBoxDeliveredStatus = KindBoxStatus("delivered")
KindBoxReadyToReturnStatus KindBoxReadyToReturnStatus = KindBoxStatus("ready-to-return")
KindBoxAssignedReceiverAgentStatus KindBoxAssignedReceiverAgentStatus = KindBoxStatus("assigned-receiver-agent")
KindBoxReturnedStatus KindBoxReturnedStatus = KindBoxStatus("returned")
KindBoxEnumeratedStatus KindBoxEnumeratedStatus = KindBoxStatus("enumerated")
) )
var kindBoxStatusStrings = map[KindBoxStatus]string{
KindBoxDeliveredStatus: "delivered",
KindBoxReadyToReturnStatus: "ready-to-return",
KindBoxAssignedReceiverAgentStatus: "assigned-receiver-agent",
KindBoxReturnedStatus: "returned",
KindBoxEnumeratedStatus: "enumerated",
}
func (s KindBoxStatus) String() string {
return kindBoxStatusStrings[s]
}
// AllKindBoxStatus returns a slice containing all string values of KindBoxStatus.
func AllKindBoxStatus() []string {
statusStrings := make([]string, len(kindBoxStatusStrings))
for status, str := range kindBoxStatusStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
// MapToKindBoxStatus converts a string to the corresponding KindBoxStatus value.
func MapToKindBoxStatus(statusStr string) KindBoxStatus {
for status, str := range kindBoxStatusStrings {
if str == statusStr {
return status
}
}
return KindBoxStatus(0)
}

View File

@ -1,11 +1,11 @@
package entity package entity
type KindBoxType uint type KindBoxType string
const ( const (
KindBoxOnTable KindBoxType = iota + 1 KindBoxOnTable = KindBoxType("on-table")
KindBoxCylindrical KindBoxCylindrical = KindBoxType("cylindrical")
KindBoxStandUp KindBoxStandUp = KindBoxType("stand-up")
) )
var KindBoxTypeStrings = map[KindBoxType]string{ var KindBoxTypeStrings = map[KindBoxType]string{
@ -14,31 +14,8 @@ var KindBoxTypeStrings = map[KindBoxType]string{
KindBoxStandUp: "stand-up", KindBoxStandUp: "stand-up",
} }
func (s KindBoxType) String() string {
return KindBoxTypeStrings[s]
}
func (s KindBoxType) IsValid() bool { func (s KindBoxType) IsValid() bool {
return s > 0 && int(s) <= len(KindBoxTypeStrings) _, ok := KindBoxTypeStrings[s]
}
return ok
// AllKindBoxType returns a slice containing all string values of KindBoxType.
func AllKindBoxType() []string {
statusStrings := make([]string, len(KindBoxTypeStrings))
for status, str := range KindBoxTypeStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
// MapToKindBoxType converts a string to the corresponding KindBoxType value.
func MapToKindBoxType(statusStr string) KindBoxType {
for status, str := range KindBoxTypeStrings {
if str == statusStr {
return status
}
}
return KindBoxType(0)
} }

View File

@ -1,42 +1,13 @@
package entity package entity
type ReferTimeStatus uint type ReferTimeStatus string
const ( const (
ReferTimeActiveStatus ReferTimeStatus = iota + 1 ReferTimeActiveStatus = ReferTimeStatus("active")
ReferTimeInactiveStatus ReferTimeInactiveStatus = ReferTimeStatus("inactive")
) )
var ReferTimeStatusStrings = map[ReferTimeStatus]string{ var ReferTimeStatusStrings = map[ReferTimeStatus]string{
ReferTimeActiveStatus: "active", ReferTimeActiveStatus: "active",
ReferTimeInactiveStatus: "inactive", ReferTimeInactiveStatus: "inactive",
} }
func (s ReferTimeStatus) String() string {
return ReferTimeStatusStrings[s]
}
func (s ReferTimeStatus) IsValid() bool {
return s > 0 && int(s) <= len(ReferTimeStatusStrings)
}
// AllReferTimeStatus returns a slice containing all string values of ReferTimeStatus.
func AllReferTimeStatus() []string {
statusStrings := make([]string, len(ReferTimeStatusStrings))
for status, str := range ReferTimeStatusStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
// MapToReferTimeStatus converts a string to the corresponding ReferTimeStatus value.
func MapToReferTimeStatus(statusStr string) ReferTimeStatus {
for status, str := range ReferTimeStatusStrings {
if str == statusStr {
return status
}
}
return ReferTimeStatus(0)
}

View File

@ -1,9 +1,9 @@
package entity package entity
type UserRole uint type UserRole string
const ( const (
UserBenefactorRole UserRole = iota + 1 UserBenefactorRole = UserRole("benefactor")
) )
var UserRoleStrings = map[UserRole]string{ var UserRoleStrings = map[UserRole]string{
@ -13,24 +13,3 @@ var UserRoleStrings = map[UserRole]string{
func (s UserRole) String() string { func (s UserRole) String() string {
return UserRoleStrings[s] return UserRoleStrings[s]
} }
// AllUserRole returns a slice containing all string values of UserRole.
func AllUserRole() []string {
roleStrings := make([]string, len(UserRoleStrings))
for role, str := range UserRoleStrings {
roleStrings[int(role)-1] = str
}
return roleStrings
}
// MapToUserRole converts a string to the corresponding UserRole value.
func MapToUserRole(roleStr string) UserRole {
for role, str := range UserRoleStrings {
if str == roleStr {
return role
}
}
return UserRole(0)
}

4
go.mod
View File

@ -3,7 +3,6 @@ module git.gocasts.ir/ebhomengo/niki
go 1.21.3 go 1.21.3
require ( require (
github.com/brianvoe/gofakeit/v6 v6.28.0
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
@ -14,7 +13,6 @@ require (
github.com/labstack/echo/v4 v4.12.0 github.com/labstack/echo/v4 v4.12.0
github.com/redis/go-redis/v9 v9.4.0 github.com/redis/go-redis/v9 v9.4.0
github.com/rubenv/sql-migrate v1.6.0 github.com/rubenv/sql-migrate v1.6.0
github.com/stretchr/testify v1.9.0
github.com/swaggo/echo-swagger v1.4.1 github.com/swaggo/echo-swagger v1.4.1
github.com/swaggo/swag v1.16.3 github.com/swaggo/swag v1.16.3
golang.org/x/crypto v0.23.0 golang.org/x/crypto v0.23.0
@ -25,7 +23,6 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect github.com/KyleBanks/depth v1.2.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/structs v1.1.0 // indirect github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect
@ -45,7 +42,6 @@ require (
github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect

2
go.sum
View File

@ -29,8 +29,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=

View File

@ -1,19 +0,0 @@
package initial
import (
"git.gocasts.ir/ebhomengo/niki/config"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
)
type Auth struct {
BenefactorAuthSvc authservice.Service
AdminAuthSvc authservice.Service
}
func InitBenefactorAuthService(cfg config.Config) authservice.Service {
return authservice.New(cfg.Auth)
}
func InitAdminAuthService(cfg config.Config) authservice.Service {
return authservice.New(cfg.AdminAuth)
}

View File

@ -1,14 +0,0 @@
package initial
import (
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
)
type AdminAuthorization struct {
AdminAuthorizationSvc adminauthorizationservice.Service
}
func InitAdminAuthorizationService(db *mysql.DB) adminauthorizationservice.Service {
return adminauthorizationservice.New(InitAdminMysql(db))
}

View File

@ -1,42 +0,0 @@
package initial
import (
"git.gocasts.ir/ebhomengo/niki/config"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
mysqladdress "git.gocasts.ir/ebhomengo/niki/repository/mysql/address"
mysqladmin "git.gocasts.ir/ebhomengo/niki/repository/mysql/admin"
mysqlkindbox "git.gocasts.ir/ebhomengo/niki/repository/mysql/kind_box"
mysqlkindboxreq "git.gocasts.ir/ebhomengo/niki/repository/mysql/kind_box_req"
mysqlrefertime "git.gocasts.ir/ebhomengo/niki/repository/mysql/refer_time"
)
type Databases struct {
BenefactorAddressDB *mysqladdress.DB
BenefactorKindBoxReqDB *mysqlkindboxreq.DB
KindBoxRepo *mysqlkindbox.DB
AdminMysql *mysqladmin.DB
}
func InitMysql(cfg config.Config) *mysql.DB {
return mysql.New(cfg.Mysql)
}
func InitBenefactorAddressDB(db *mysql.DB) *mysqladdress.DB {
return mysqladdress.New(db)
}
func InitBenefactorKindBoxReqDB(db *mysql.DB) *mysqlkindboxreq.DB {
return mysqlkindboxreq.New(db)
}
func InitKindBoxRepo(db *mysql.DB) *mysqlkindbox.DB {
return mysqlkindbox.New(db)
}
func InitAdminMysql(db *mysql.DB) *mysqladmin.DB {
return mysqladmin.New(db)
}
func InitAdminReferTimeDB(db *mysql.DB) *mysqlrefertime.DB {
return mysqlrefertime.New(db)
}

View File

@ -1,99 +0,0 @@
package initial
import (
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
kavenegarnotification "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar/notification"
kavenegarotp "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar/otp"
"git.gocasts.ir/ebhomengo/niki/config"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
mysqladdress "git.gocasts.ir/ebhomengo/niki/repository/mysql/address"
mysqlbenefactor "git.gocasts.ir/ebhomengo/niki/repository/mysql/benefactor"
mysqlkindbox "git.gocasts.ir/ebhomengo/niki/repository/mysql/kind_box"
mysqlkindboxreq "git.gocasts.ir/ebhomengo/niki/repository/mysql/kind_box_req"
redisotp "git.gocasts.ir/ebhomengo/niki/repository/redis/redis_otp"
adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin"
benefactorforadminservice "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor"
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
adminrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time"
agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address"
benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box"
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/service/notification"
)
type Services struct {
BenefactorSvc benefactorservice.Service
BenefactorKindBoxReqSvc benefactorkindboxreqservice.Service
BenefactorAddressSvc benefactoraddressservice.Service
BenefactorKindBoxSvc benefactorkindboxservice.Service
AdminKindBoxSvc adminkindboxservice.Service
AgentKindBoxSvc agentkindboxservice.Service
AdminSvc adminservice.Service
AdminKindBoxReqSvc adminkindboxreqservice.Service
AdminReferTimeSvc adminrefertimeservice.Service
NotificationSvc notification.Service
}
func initSmsOtp(cfg config.Config) *kavenegarotp.Adapter {
return kavenegarotp.New(smsprovider.New(cfg.KavenegarSmsProvider))
}
func initSmsNotification(cfg config.Config) *kavenegarnotification.Adapter {
return kavenegarnotification.New(smsprovider.New(cfg.KavenegarSmsProvider))
}
func InitAdminService(cfg config.Config, db *mysql.DB) adminservice.Service {
return adminservice.New(InitAdminMysql(db), InitAdminAuthService(cfg))
}
func InitBenefactorForAdminService(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactorforadminservice.Service {
return benefactorforadminservice.New(InitAdminMysql(db), InitBenefactorService(cfg, redisAdapter, db))
}
func InitBenefactorService(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactorservice.Service {
return benefactorservice.New(
cfg.BenefactorSvc,
redisotp.New(redisAdapter),
initSmsOtp(cfg),
InitBenefactorAuthService(cfg),
mysqlbenefactor.New(db),
)
}
func InitBenefactorAddressService(db *mysql.DB) benefactoraddressservice.Service {
return benefactoraddressservice.New(mysqladdress.New(db))
}
func InitBenefactorKindBoxReqService(db *mysql.DB) benefactorkindboxreqservice.Service {
return benefactorkindboxreqservice.New(mysqlkindboxreq.New(db))
}
func InitAdminKindBoxService(db *mysql.DB) adminkindboxservice.Service {
return adminkindboxservice.New(InitKindBoxRepo(db))
}
func InitAgentKindBoxService(db *mysql.DB) agentkindboxservice.Service {
return agentkindboxservice.New(InitKindBoxRepo(db))
}
func InitAdminKindBoxReqService(db *mysql.DB) adminkindboxreqservice.Service {
return adminkindboxreqservice.New(InitBenefactorKindBoxReqDB(db), InitAdminKindBoxService(db))
}
func InitAdminReferTimeService(db *mysql.DB) adminrefertimeservice.Service {
return adminrefertimeservice.New(
InitAdminReferTimeDB(db),
)
}
func InitBenefactorKindBoxService(db *mysql.DB) benefactorkindboxservice.Service {
return benefactorkindboxservice.New(mysqlkindbox.New(db))
}
func InitNotificationService(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) notification.Service {
return notification.New(initSmsNotification(cfg), InitAdminKindBoxReqService(db), InitBenefactorForAdminService(cfg, redisAdapter, db))
}

View File

@ -1,71 +0,0 @@
package initial
import (
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
"git.gocasts.ir/ebhomengo/niki/config"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address"
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
benefactorkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box"
benefactorkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box_req"
)
type Validators struct {
BenefactorVld benefactorvalidator.Validator
BenefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator
BenefactorAddressVld benefactoraddressvalidator.Validator
BenefactorKindBoxVld benefactorkindboxvalidator.Validator
AdminKindBoxReqVld adminkindboxreqvalidator.Validator
AdminVld adminvalidator.Validator
AdminKindBoxVld adminkindboxvalidator.Validator
AgentKindBoxVld agentkindboxvalidator.Validator
}
func InitAdminKindBoxReqValidator(db *mysql.DB, cfg config.Config, redisAdapter redis.Adapter) adminkindboxreqvalidator.Validator {
return adminkindboxreqvalidator.New(InitBenefactorKindBoxReqDB(db), InitAdminService(cfg, db), InitBenefactorForAdminService(cfg, redisAdapter, db), InitAdminReferTimeService(db), InitBenefactorAddressService(db))
}
func InitAdminValidator(db *mysql.DB) adminvalidator.Validator {
return adminvalidator.New(InitAdminMysql(db))
}
func InitBenefactorValidator() benefactorvalidator.Validator {
return benefactorvalidator.New()
}
func InitBenefactorKindBoxReqValidator(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactorkindboxreqvalidator.Validator {
return benefactorkindboxreqvalidator.New(
InitBenefactorService(cfg, redisAdapter, db),
InitBenefactorAddressService(db),
InitAdminReferTimeService(db),
InitBenefactorKindBoxReqDB(db),
)
}
func InitBenefactorAddressValidator(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactoraddressvalidator.Validator {
return benefactoraddressvalidator.New(
InitBenefactorService(cfg, redisAdapter, db),
InitBenefactorAddressDB(db),
)
}
func InitAdminKindBoxValidator(db *mysql.DB, cfg config.Config) adminkindboxvalidator.Validator {
return adminkindboxvalidator.New(InitKindBoxRepo(db), InitAdminService(cfg, db))
}
func InitAgentKindBoxValidator(db *mysql.DB) agentkindboxvalidator.Validator {
return agentkindboxvalidator.New(InitKindBoxRepo(db))
}
func InitBenefactorKindBoxValidator(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactorkindboxvalidator.Validator {
return benefactorkindboxvalidator.New(
InitKindBoxRepo(db),
InitBenefactorService(cfg, redisAdapter, db),
InitBenefactorAddressService(db),
InitAdminReferTimeService(db),
)
}

114
main.go
View File

@ -4,30 +4,17 @@ import (
"flag" "flag"
"fmt" "fmt"
"git.gocasts.ir/ebhomengo/niki/adapter/kavenegar"
"git.gocasts.ir/ebhomengo/niki/adapter/redis" "git.gocasts.ir/ebhomengo/niki/adapter/redis"
"git.gocasts.ir/ebhomengo/niki/config" "git.gocasts.ir/ebhomengo/niki/config"
smscontract "git.gocasts.ir/ebhomengo/niki/contract/sms"
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server" httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
"git.gocasts.ir/ebhomengo/niki/internal/initial"
"git.gocasts.ir/ebhomengo/niki/repository/migrator" "git.gocasts.ir/ebhomengo/niki/repository/migrator"
"git.gocasts.ir/ebhomengo/niki/repository/mysql" "git.gocasts.ir/ebhomengo/niki/repository/mysql"
"git.gocasts.ir/ebhomengo/niki/service"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
) )
type Dependencies struct {
initial.Auth
initial.Databases
initial.Validators
initial.Services
initial.AdminAuthorization
}
func parseFlags() bool {
migrateFlag := flag.Bool("migrate", false, "perform database migration")
flag.Parse()
return *migrateFlag
}
// @securityDefinitions.apikey AuthBearerBenefactor // @securityDefinitions.apikey AuthBearerBenefactor
// @in header // @in header
// @name Authorization // @name Authorization
@ -37,89 +24,46 @@ func parseFlags() bool {
// @name Authorization // @name Authorization
// @description Type the word 'Bearer' followed by a space and Admin JWT token. // @description Type the word 'Bearer' followed by a space and Admin JWT token.
func main() { func main() {
migrate := parseFlags() cfg := Config()
db := MariaDB(cfg)
cfg := config.C()
db := initDatabase(cfg, migrate)
defer func() { defer func() {
if err := db.CloseStatements(); err != nil { if err := db.CloseStatements(); err != nil {
fmt.Printf("Error closing statements: %v\n", err) fmt.Printf("Error closing statements: %v\n", err)
} }
}() }()
redisAdapter := initRedis(cfg) rds := Redis(cfg)
kvn := Kavenegar(cfg)
dependencies := initDependencies(cfg, redisAdapter, db) svc := Service(cfg, db, rds, kvn)
httpServer := HTTPServer(cfg, svc)
initAndRunServer(cfg, dependencies) httpServer.Serve()
} }
func initDependencies(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) *Dependencies { func Config() config.Config {
return &Dependencies{ return config.C()
initial.Auth{
BenefactorAuthSvc: initial.InitBenefactorAuthService(cfg),
AdminAuthSvc: initial.InitAdminAuthService(cfg),
},
initial.Databases{
BenefactorAddressDB: initial.InitBenefactorAddressDB(db),
BenefactorKindBoxReqDB: initial.InitBenefactorKindBoxReqDB(db),
KindBoxRepo: initial.InitKindBoxRepo(db),
AdminMysql: initial.InitAdminMysql(db),
},
initial.Validators{
BenefactorVld: initial.InitBenefactorValidator(),
BenefactorKindBoxReqVld: initial.InitBenefactorKindBoxReqValidator(cfg, redisAdapter, db),
BenefactorAddressVld: initial.InitBenefactorAddressValidator(cfg, redisAdapter, db),
BenefactorKindBoxVld: initial.InitBenefactorKindBoxValidator(cfg, redisAdapter, db),
AdminKindBoxReqVld: initial.InitAdminKindBoxReqValidator(db, cfg, redisAdapter),
AdminVld: initial.InitAdminValidator(db),
AdminKindBoxVld: initial.InitAdminKindBoxValidator(db, cfg),
AgentKindBoxVld: initial.InitAgentKindBoxValidator(db),
},
initial.Services{
BenefactorSvc: initial.InitBenefactorService(cfg, redisAdapter, db),
BenefactorKindBoxReqSvc: initial.InitBenefactorKindBoxReqService(db),
BenefactorAddressSvc: initial.InitBenefactorAddressService(db),
BenefactorKindBoxSvc: initial.InitBenefactorKindBoxService(db),
AdminKindBoxSvc: initial.InitAdminKindBoxService(db),
AgentKindBoxSvc: initial.InitAgentKindBoxService(db),
AdminKindBoxReqSvc: initial.InitAdminKindBoxReqService(db),
AdminSvc: initial.InitAdminService(cfg, db),
AdminReferTimeSvc: initial.InitAdminReferTimeService(db),
NotificationSvc: initial.InitNotificationService(cfg, redisAdapter, db),
},
initial.AdminAuthorization{
AdminAuthorizationSvc: initial.InitAdminAuthorizationService(db),
},
}
} }
func initAndRunServer(cfg config.Config, dependencies *Dependencies) { func MariaDB(cfg config.Config) *mysql.DB {
server := httpserver.New(cfg, migrate := flag.Bool("migrate", false, "perform database migration")
dependencies.BenefactorSvc, dependencies.BenefactorVld, dependencies.BenefactorAuthSvc, flag.Parse()
dependencies.BenefactorKindBoxReqSvc, dependencies.BenefactorKindBoxReqVld, if *migrate {
dependencies.BenefactorAddressSvc, dependencies.BenefactorAddressVld, migrator.New(cfg.Mysql).Up()
dependencies.BenefactorKindBoxSvc, dependencies.BenefactorKindBoxVld,
dependencies.AdminSvc, dependencies.AdminVld, dependencies.AdminAuthSvc,
dependencies.AdminKindBoxReqSvc, dependencies.AdminKindBoxReqVld, dependencies.AdminAuthorizationSvc,
dependencies.AdminKindBoxSvc, dependencies.AdminKindBoxVld,
dependencies.AgentKindBoxSvc, dependencies.AgentKindBoxVld, dependencies.NotificationSvc)
server.Serve()
}
func initDatabase(cfg config.Config, migrate bool) *mysql.DB {
if migrate {
migrateDatabase(cfg)
} }
return initial.InitMysql(cfg) return mysql.New(cfg.Mysql)
} }
func initRedis(cfg config.Config) redis.Adapter { func Redis(cfg config.Config) *redis.Adapter {
return redis.New(cfg.Redis) return redis.New(cfg.Redis)
} }
func migrateDatabase(cfg config.Config) { func Kavenegar(cfg config.Config) *kavenegar.Adapter {
migratorDB := migrator.New(cfg.Mysql) return kavenegar.New(cfg.KavenegarSmsProvider)
migratorDB.Up() }
func Service(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *service.Service {
return service.New(cfg, db, rds, smsAdapter)
}
func HTTPServer(cfg config.Config, svc *service.Service) *httpserver.Server {
return httpserver.New(cfg, svc)
} }

4276
mise.log

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
package adminaddressparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type AddressGetRequest struct {
AddressID uint
}
type AddressGetResponse struct {
Address entity.Address
}

View File

@ -1,10 +0,0 @@
package adminserviceparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type GetAddressByIDRequest struct {
ID uint
}
type GetAddressByIDResponse struct {
Address *entity.Address
}

View File

@ -8,8 +8,9 @@ type LoginWithPhoneNumberRequest struct {
} }
type LoginWithPhoneNumberResponse struct { type LoginWithPhoneNumberResponse struct {
AdminInfo AdminInfo `json:"admin_info"` AdminInfo AdminInfo `json:"admin_info"`
Tokens Tokens `json:"tokens"` Tokens Tokens `json:"tokens"`
FieldErrors map[string]string `json:"field_errors,omitempty"`
} }
type AdminInfo struct { type AdminInfo struct {
@ -20,6 +21,6 @@ type AdminInfo struct {
Role entity.AdminRole `json:"role" example:"2"` Role entity.AdminRole `json:"role" example:"2"`
Description string `json:"description" example:"This is a description"` Description string `json:"description" example:"This is a description"`
Email string `json:"email" example:"example@gmail.com"` Email string `json:"email" example:"example@gmail.com"`
Gender entity.Gender `json:"gender" example:"1"` Gender entity.Gender `json:"gender" example:"male"`
Status entity.AdminStatus `json:"status" example:"1"` Status entity.AdminStatus `json:"status" example:"active"`
} }

View File

@ -10,10 +10,11 @@ type RegisterRequest struct {
Role *entity.AdminRole `json:"role" example:"2"` Role *entity.AdminRole `json:"role" example:"2"`
Description *string `json:"description" example:"this is a description"` Description *string `json:"description" example:"this is a description"`
Email *string `json:"email" example:"miaad.66@gmail.com"` Email *string `json:"email" example:"miaad.66@gmail.com"`
Gender *entity.Gender `json:"gender" example:"1"` Gender *entity.Gender `json:"gender" example:"male"`
Status *entity.AdminStatus `json:"status" example:"1"` Status *entity.AdminStatus `json:"status" example:"active"`
} }
type RegisterResponse struct { type RegisterResponse struct {
Admin entity.Admin `json:"admin"` Admin entity.Admin `json:"admin"`
FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -0,0 +1,9 @@
package adminagentparam
type AdminAgentExistByIDRequest struct {
AgentID uint
}
type AdminAgentExistByIDResponse struct {
Exist bool
}

View File

@ -1,4 +1,4 @@
package adminserviceparam package adminagentparam
type GetAllAgentResponse struct { type GetAllAgentResponse struct {
Agents []Agent `json:"agents"` Agents []Agent `json:"agents"`

View File

@ -1,4 +1,4 @@
package adminserviceparam package adminbenefactoreparam
type BenefactorExistByIDRequest struct { type BenefactorExistByIDRequest struct {
ID uint ID uint

View File

@ -4,3 +4,7 @@ type AssignReceiverRequest struct {
KindBoxID uint `json:"-" param:"id"` KindBoxID uint `json:"-" param:"id"`
ReceiverAgentID uint `json:"receiver_agent_id"` ReceiverAgentID uint `json:"receiver_agent_id"`
} }
type AssignReceiverResponse struct {
FieldErrors map[string]string `json:"field_errors,omitempty"`
}

View File

@ -4,3 +4,7 @@ type EnumerateKindBoxRequest struct {
KindBoxID uint `json:"-" param:"id"` KindBoxID uint `json:"-" param:"id"`
Amount uint `json:"amount"` Amount uint `json:"amount"`
} }
type EnumerateKindBoxResponse struct {
FieldErrors map[string]string `json:"field_errors,omitempty"`
}

View File

@ -8,4 +8,5 @@ type KindBoxGetRequest struct {
type KindBoxGetResponse struct { type KindBoxGetResponse struct {
entity.KindBox entity.KindBox
FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

Some files were not shown because too many files have changed in this diff Show More