Merge branch 'develop' into stage/rezoo/e2e-test/benefactor

This commit is contained in:
Reza Mobaraki 2024-10-02 09:50:35 +03:30
commit ebd05c16f7
No known key found for this signature in database
GPG Key ID: 922CBCF25B541A6F
1947 changed files with 578132 additions and 4532 deletions

2
.gitignore vendored
View File

@ -18,9 +18,9 @@ activate.mise.toml
*.out *.out
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
vendor/
.idea .idea
bin bin
tmp
#.env #.env
*.env *.env

View File

@ -1,37 +1,29 @@
# Build Stage # Build Stage
# First pull Golang image FROM golang:1.23.0-alpine AS builder
FROM golang:1.21.3-alpine as builder
# Set environment variable # Set environment variable
ENV APP_NAME niki ENV APP_NAME niki
ENV CMD_PATH main.go
# Add a work directory # Add a work directory
WORKDIR /$APP_NAME WORKDIR /$APP_NAME
## Cache and install dependencies
#COPY go.mod go.sum ./
#RUN go mod download
# Copy app files # Copy app files
COPY . . COPY . .
# Budild application # Budild application
RUN CGO_ENABLED=0 go build -mod=mod -v -o $APP_NAME . RUN CGO_ENABLED=0 go build -mod=vendor -v -o $APP_NAME .
# Run Stage # Run Stage
FROM alpine:3.20 AS runtime
FROM alpine:3.18 as development # Copy the binary from the builder stage
COPY --from=builder /niki/niki .
# Copy migration files
# Set environment variable COPY --from=builder /niki/repository/mysql/migration ./repository/mysql/migration
ENV APP_NAME niki
# Copy only required data into this image
COPY --from=builder /$APP_NAME .
# Expose application port # Expose application port
EXPOSE 1313 EXPOSE 8313
# Start app # Start the application
CMD ./$APP_NAME CMD ["./niki", "--migrate"]

View File

@ -18,7 +18,7 @@ format:
@which gofumpt || (go install mvdan.cc/gofumpt@latest) @which gofumpt || (go install mvdan.cc/gofumpt@latest)
@gofumpt -l -w $(ROOT) @gofumpt -l -w $(ROOT)
@which gci || (go install github.com/daixiang0/gci@latest) @which gci || (go install github.com/daixiang0/gci@latest)
@gci write $(ROOT) @gci write $(ROOT) --skip-generated --skip-vendor
@which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0) @which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0)
@golangci-lint run --fix @golangci-lint run --fix

View File

@ -20,10 +20,6 @@ redis:
password: "" password: ""
db: 0 db: 0
sms_provider:
host: localhost
port: 443
benefactor_service: benefactor_service:
length_of_otp_code: 5 length_of_otp_code: 5

View File

@ -11,6 +11,11 @@ import (
type HTTPServer struct { type HTTPServer struct {
Port int `koanf:"port"` Port int `koanf:"port"`
Cors Cors `koanf:"cors"`
}
type Cors struct {
AllowOrigins []string `koanf:"allow_origins"`
} }
type Config struct { type Config struct {

View File

@ -10,7 +10,7 @@ import (
// LoginByPhoneNumber godoc // LoginByPhoneNumber godoc
// @Summary Admin login by PhoneNumber // @Summary Admin login by PhoneNumber
// @Tags Admin // @Tags Admins
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body adminserviceparam.LoginWithPhoneNumberRequest true "Admin login request body" // @Param Request body adminserviceparam.LoginWithPhoneNumberRequest true "Admin login request body"

View File

@ -0,0 +1,37 @@
package adminhandler
import (
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
"net/http"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"github.com/labstack/echo/v4"
)
// RefreshAccess godoc
// @Summary Get a new access token by providing a refresh token
// @Tags Admins
// @Accept json
// @Produce json
// @Param Request body adminserviceparam.RefreshAccessRequest true "Refresh access request body"
// @Success 200 {object} adminserviceparam.RefreshAccessResponse
// @Failure 400 {string} "Bad Request"
// @Failure 422 {string} "invalid or expired jwt"
// @Failure 500 {string} "something went wrong"
// @Router /admins/refresh-access [post].
func (h Handler) RefreshAccess(c echo.Context) error {
var req adminserviceparam.RefreshAccessRequest
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, err := h.adminSvc.RefreshAccess(c.Request().Context(), req)
if err != nil {
msg, code := httpmsg.Error(err)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusOK, resp)
}

View File

@ -10,7 +10,7 @@ import (
// Register godoc // Register godoc
// @Summary Register an admin by super-admin // @Summary Register an admin by super-admin
// @Tags Admin // @Tags Admins
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body adminserviceparam.RegisterRequest true "Admin Register Request Body" // @Param Request body adminserviceparam.RegisterRequest true "Admin Register Request Body"

View File

@ -13,6 +13,7 @@ func (h Handler) SetRoutes(e *echo.Echo) {
//r.POST("/", h.Add).Name = "admin-addkindboxreq" //r.POST("/", h.Add).Name = "admin-addkindboxreq"
r.POST("/register", h.Register, middleware.Auth(h.authSvc), 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)
r.POST("/refresh-access", h.RefreshAccess)
//nolint:gocritic //nolint:gocritic
//r.PATCH("/:id", h.Update).Name = "admin-updatekindboxreq" //r.PATCH("/:id", h.Update).Name = "admin-updatekindboxreq"
} }

View File

@ -10,7 +10,7 @@ import (
// GetAllAgent godoc // GetAllAgent godoc
// @Summary Get all agents by admin // @Summary Get all agents by admin
// @Tags Admin // @Tags Admins
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} adminagentparam.GetAllAgentResponse // @Success 200 {object} adminagentparam.GetAllAgentResponse

View File

@ -11,7 +11,7 @@ import (
// AssignReceiverAgent godoc // AssignReceiverAgent godoc
// @Summary Admin assign receiver agent to kindbox // @Summary Admin assign receiver agent to kindbox
// @Tags KindBox // @Tags Admins KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBox ID" // @Param id path int true "KindBox ID"
@ -19,7 +19,7 @@ import (
// @Success 204 // @Success 204
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxes/assign-receiver-agent/{id} [patch]. // @Router /admins/kindboxes/{id}/assign-receiver-agent [patch].
func (h Handler) AssignReceiverAgent(c echo.Context) error { func (h Handler) AssignReceiverAgent(c echo.Context) error {
var req param.AssignReceiverRequest var req param.AssignReceiverRequest

View File

@ -11,7 +11,7 @@ import (
// Enumerate godoc // Enumerate godoc
// @Summary Admin enumerate kindbox // @Summary Admin enumerate kindbox
// @Tags KindBox // @Tags Admins KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBox ID" // @Param id path int true "KindBox ID"
@ -23,7 +23,7 @@ import (
// @Failure 422 {object} httpmsg.ErrorResponse // @Failure 422 {object} httpmsg.ErrorResponse
// @Failure 500 {string} "something went wrong" // @Failure 500 {string} "something went wrong"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxes/{id}/enumerate [patch]. // @Router /admins/kindboxes/{id}/enumerate [patch].
func (h Handler) Enumerate(c echo.Context) error { func (h Handler) Enumerate(c echo.Context) error {
var req param.EnumerateKindBoxRequest var req param.EnumerateKindBoxRequest

View File

@ -11,14 +11,14 @@ import (
// Get godoc // Get godoc
// @Summary Get a specific kind box by admin // @Summary Get a specific kind box by admin
// @Description This endpoint retrieves a specific kind box by admin // @Description This endpoint retrieves a specific kind box by admin
// @Tags KindBox // @Tags Admins KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Kind box ID" // @Param id path int true "Kind box ID"
// @Success 200 {object} param.KindBoxGetResponse // @Success 200 {object} param.KindBoxGetResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxes/{id} [get]. // @Router /admins/kindboxes/{id} [get].
func (h Handler) Get(c echo.Context) error { func (h Handler) Get(c echo.Context) error {
var req param.KindBoxGetRequest var req param.KindBoxGetRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -12,7 +12,7 @@ import (
// GetAll godoc // GetAll godoc
// @Summary Get all KindBoxes by admin // @Summary Get all KindBoxes by admin
// @Description Retrieves a list of all KindBoxes with filtering, sorting, and pagination options // @Description Retrieves a list of all KindBoxes with filtering, sorting, and pagination options
// @Tags KindBox // @Tags Admins KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param filter_id query int false "Filter by ID" // @Param filter_id query int false "Filter by ID"
@ -39,7 +39,7 @@ import (
// @Success 200 {object} param.KindBoxGetAllResponse // @Success 200 {object} param.KindBoxGetAllResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxes [get]. // @Router /admins/kindboxes [get].
func (h Handler) GetAll(c echo.Context) error { func (h Handler) GetAll(c echo.Context) error {
var req param.KindBoxGetAllRequest var req param.KindBoxGetAllRequest

View File

@ -7,12 +7,13 @@ import (
) )
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admin/kindboxes") r := e.Group("/admins/kindboxes")
r.Use(middleware.Auth(h.authSvc)) 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("/:id/assign-receiver-agent", h.AssignReceiverAgent, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxAssignReceiverAgentPermission))
r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetAllPermission)) r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxGetAllPermission))
r.PATCH("/:id/enumerate", h.Enumerate, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxEnumeratePermission)) r.PATCH("/:id/enumerate", h.Enumerate, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxEnumeratePermission))
r.PUT("/update/:id", h.Update, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxUpdatePermission))
} }

View File

@ -0,0 +1,50 @@
package adminkindboxhandler
import (
"net/http"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"github.com/labstack/echo/v4"
)
// Update godoc
// @Summary Update kind Box by admin
// @Tags Admins KindBoxes
// @Accept json
// @Produce json
// @Param id path int true "Kind Box ID"
// @Param Request body param.KindBoxUpdateRequest true "Update KindBox Request Body"
// @Success 204
// @Failure 400 {string} "Bad Request"
// @Failure 401 {string} "invalid or expired jwt"
// @Failure 403 {string} "user not allowed"
// @Failure 422 {object} httpmsg.ErrorResponse
// @Failure 500 {string} "something went wrong"
// @Security AuthBearerAdmin
// @Router /admins/kindboxes/update/{id} [put].
func (h Handler) Update(c echo.Context) error {
var req param.KindBoxUpdateRequest
if bErr := c.Bind(&req); bErr != nil {
return c.JSON(http.StatusBadRequest, httpmsg.ErrorResponse{
Message: "Invalid request body",
})
}
resp, sErr := h.adminKindBoxSvc.Update(c.Request().Context(), req)
if sErr != nil {
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 c.JSON(http.StatusNoContent, nil)
}

View File

@ -13,7 +13,7 @@ import (
// Accept godoc // Accept godoc
// @Summary Accept kind box request by admin // @Summary Accept kind box request by admin
// @Tags KindBoxReq // @Tags Admins KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"
@ -21,7 +21,7 @@ import (
// @Success 200 {object} param.KindBoxReqAcceptResponse // @Success 200 {object} param.KindBoxReqAcceptResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs/accept-kind-box-req/{id} [patch]. // @Router /admins/kindboxreqs/{id}/accept-kind-box-req [patch].
func (h Handler) Accept(c echo.Context) error { func (h Handler) Accept(c echo.Context) error {
var req param.KindBoxReqAcceptRequest var req param.KindBoxReqAcceptRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -11,14 +11,14 @@ import (
// AddKindBoxReq godoc // AddKindBoxReq godoc
// @Summary Add a new kind box request for a benefactor by admin // @Summary Add a new kind box request for a benefactor by admin
// @Tags KindBoxReq // @Tags Admins KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body param.KindBoxReqAddRequest true "New kind box request details" // @Param Request body param.KindBoxReqAddRequest true "New kind box request details"
// @Success 200 {object} param.KindBoxReqAddResponse // @Success 200 {object} param.KindBoxReqAddResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs [post]. // @Router /admins/kindboxreqs [post].
func (h Handler) AddKindBoxReq(c echo.Context) error { func (h Handler) AddKindBoxReq(c echo.Context) error {
req := param.KindBoxReqAddRequest{} req := param.KindBoxReqAddRequest{}
if err := c.Bind(&req); err != nil { if err := c.Bind(&req); err != nil {

View File

@ -13,7 +13,7 @@ import (
// AssignSenderAgent godoc // AssignSenderAgent godoc
// @Summary Admin Assign Sender Agent to kindboxreq // @Summary Admin Assign Sender Agent to kindboxreq
// @Tags KindBoxReq // @Tags Admins KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"
@ -21,7 +21,7 @@ import (
// @Success 200 {object} param.AssignSenderResponse // @Success 200 {object} param.AssignSenderResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs/assign-sender-agent/{id} [patch]. // @Router /admins/kindboxreqs/{id}/assign-sender-agent [patch].
func (h Handler) AssignSenderAgent(c echo.Context) error { func (h Handler) AssignSenderAgent(c echo.Context) error {
var req param.AssignSenderRequest var req param.AssignSenderRequest

View File

@ -10,7 +10,7 @@ import (
// Get godoc // Get godoc
// @Summary Get a specific kind box req by ID // @Summary Get a specific kind box req by ID
// @Tags KindBoxReq // @Tags Admins KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"

View File

@ -12,7 +12,7 @@ import (
// GetAll godoc // GetAll godoc
// @Summary Admin get all kindboxreq // @Summary Admin get all kindboxreq
// @Description Retrieves a list of all KindBox requests with filtering, sorting, and pagination options // @Description Retrieves a list of all KindBox requests with filtering, sorting, and pagination options
// @Tags KindBoxReq // @Tags Admins KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param filter_id query int false "Filter by ID" // @Param filter_id query int false "Filter by ID"

View File

@ -13,7 +13,7 @@ import (
// Reject godoc // Reject godoc
// @Summary Reject a kindboxreq by admin // @Summary Reject a kindboxreq by admin
// @Tags KindBoxReq // @Tags Admins KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq id" // @Param id path int true "KindBoxReq id"
@ -21,7 +21,7 @@ import (
// @Success 200 {object} param.KindBoxReqRejectResponse // @Success 200 {object} param.KindBoxReqRejectResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs/reject-kind-box-req/{id} [patch]. // @Router /admins/kindboxreqs/{id}/reject-kind-box-req [patch].
func (h Handler) Reject(c echo.Context) error { func (h Handler) Reject(c echo.Context) error {
var req param.KindBoxReqRejectRequest var req param.KindBoxReqRejectRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -11,13 +11,10 @@ func (h Handler) SetRoutes(e *echo.Echo) {
r.Use(middleware.Auth(h.authSvc)) 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("/:id/accept-kind-box-req", 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("/:id/reject-kind-box-req", h.Reject, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqRejectPermission))
r.PATCH("/deliver-kind-box-req/:id", h.Deliver, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqDeliverPermission)) r.PATCH("/:id/assign-sender-agent", h.AssignSenderAgent, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAssignSenderAgentPermission))
r.PATCH("/assign-sender-agent/:id", h.AssignSenderAgent, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAssignSenderAgentPermission))
r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAllPermission)) r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAllPermission))
r.GET("/awaiting-delivery/:id", h.GetAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission))
r.GET("/awaiting-delivery", h.GetAllAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission))
r.PUT("/:id", h.Update, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqUpdatePermission)) r.PUT("/:id", h.Update, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqUpdatePermission))
r.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetPermission)) r.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetPermission))
} }

View File

@ -10,7 +10,7 @@ import (
// Update godoc // Update godoc
// @Summary Update kind box request by admin // @Summary Update kind box request by admin
// @Tags KindBoxReq // @Tags Admins KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"
@ -18,7 +18,7 @@ import (
// @Success 204 // @Success 204
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs/{id} [put]. // @Router /admins/kindboxreqs/{id} [put].
func (h Handler) Update(c echo.Context) error { func (h Handler) Update(c echo.Context) error {
var req param.KindBoxReqUpdateRequest var req param.KindBoxReqUpdateRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -14,7 +14,7 @@ import (
// GetAll godoc // GetAll godoc
// @Summary Get all awaiting return KindBoxes by agent // @Summary Get all awaiting return KindBoxes by agent
// @Description Retrieves a list of all awaiting return KindBoxes for agent with filtering, sorting, and pagination options // @Description Retrieves a list of all awaiting return KindBoxes for agent with filtering, sorting, and pagination options
// @Tags KindBox // @Tags Agents KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param filter_id query int false "Filter by ID" // @Param filter_id query int false "Filter by ID"

View File

@ -11,7 +11,7 @@ import (
// Get godoc // Get godoc
// @Summary Get a kind box that is awaiting return by agent // @Summary Get a kind box that is awaiting return by agent
// @Tags KindBox // @Tags Agents KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBox ID" // @Param id path int true "KindBox ID"

View File

@ -4,21 +4,25 @@ 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"
"git.gocasts.ir/ebhomengo/niki/service/notification"
) )
type Handler struct { type Handler struct {
authSvc authservice.Service authSvc authservice.Service
agentKindBoxSvc agentkindboxservice.Service agentKindBoxSvc agentkindboxservice.Service
adminAuthorizeSvc adminauthorizationservice.Service adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
} }
func New(authSvc authservice.Service, func New(authSvc authservice.Service,
agentKindBoxSvc agentkindboxservice.Service, agentKindBoxSvc agentkindboxservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service, adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler { ) Handler {
return Handler{ return Handler{
authSvc: authSvc, authSvc: authSvc,
agentKindBoxSvc: agentKindBoxSvc, agentKindBoxSvc: agentKindBoxSvc,
adminAuthorizeSvc: adminAuthorizeSvc, adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
} }
} }

View File

@ -3,6 +3,7 @@ package agentkindboxhandler
import ( import (
"net/http" "net/http"
params "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
"git.gocasts.ir/ebhomengo/niki/pkg/claim" "git.gocasts.ir/ebhomengo/niki/pkg/claim"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
@ -11,7 +12,7 @@ import (
// Return godoc // Return godoc
// @Summary Return KindBox from benefactor by agent // @Summary Return KindBox from benefactor by agent
// @Tags KindBox // @Tags Agents KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBox ID" // @Param id path int true "KindBox ID"
@ -23,7 +24,7 @@ import (
// @Failure 422 {object} httpmsg.ErrorResponse // @Failure 422 {object} httpmsg.ErrorResponse
// @Failure 500 {string} "something went wrong" // @Failure 500 {string} "something went wrong"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /agents/kindboxes/return/{id} [patch]. // @Router /agents/kindboxes/{id}/return [patch].
func (h Handler) Return(c echo.Context) error { func (h Handler) Return(c echo.Context) error {
var req param.ReturnKindBoxRequest var req param.ReturnKindBoxRequest
if err := c.Bind(&req); err != nil { if err := c.Bind(&req); err != nil {
@ -46,5 +47,9 @@ func (h Handler) Return(c echo.Context) error {
return echo.NewHTTPError(code, msg) return echo.NewHTTPError(code, msg)
} }
go h.notificationSvc.KindBoxReturned(params.NotificationKindBoxReturned{
KindBoxID: req.KindBoxID,
})
return c.NoContent(http.StatusNoContent) return c.NoContent(http.StatusNoContent)
} }

View File

@ -13,5 +13,5 @@ func (h Handler) SetRoutes(e *echo.Echo) {
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))
r.PATCH("/return/:id", h.Return, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReturnPermission)) r.PATCH("/:id/return", h.Return, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReturnPermission))
} }

View File

@ -1,10 +1,11 @@
package adminkindboxreqhandler package agentkindboxreqhandler
import ( import (
"context" "context"
params "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
"net/http" "net/http"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
querier "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql" querier "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql"
@ -12,8 +13,8 @@ import (
) )
// Deliver godoc // Deliver godoc
// @Summary Admin deliver a kindboxreq // @Summary Agent deliver a kindboxreq
// @Tags KindBoxReq // @Tags Agents KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"
@ -21,7 +22,7 @@ import (
// @Success 200 {object} param.DeliverKindBoxReqResponse // @Success 200 {object} param.DeliverKindBoxReqResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs/deliver-kind-box-req/{id} [patch]. // @Router /agents/kindboxreqs/{id}/deliver-kind-box-req [patch].
func (h Handler) Deliver(c echo.Context) error { func (h Handler) Deliver(c echo.Context) error {
var req param.DeliverKindBoxReqRequest var req param.DeliverKindBoxReqRequest
@ -31,7 +32,7 @@ func (h Handler) Deliver(c echo.Context) error {
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.agentKindBoxReqSvc.Deliver(ctx, req)
if sErr != nil { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil { if resp.FieldErrors != nil {
@ -52,5 +53,9 @@ func (h Handler) Deliver(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, errmsg.ErrorMsgSomethingWentWrong) return echo.NewHTTPError(http.StatusInternalServerError, errmsg.ErrorMsgSomethingWentWrong)
} }
go h.notificationSvc.KindBoxReqDelivered(params.NotificationKindBoxReqDelivered{
KindBoxReqID: req.KindBoxReqID,
})
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }

View File

@ -1,10 +1,10 @@
package adminkindboxreqhandler package agentkindboxreqhandler
import ( import (
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
"net/http" "net/http"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/pkg/claim" "git.gocasts.ir/ebhomengo/niki/pkg/claim"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param" queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param"
@ -14,7 +14,7 @@ import (
// GetAllAwaitingDelivery godoc // GetAllAwaitingDelivery godoc
// @Summary Get all awaiting delivery KindBox requests // @Summary Get all awaiting delivery KindBox requests
// @Description Retrieves a list of all awaiting KindBox requests with filtering, sorting, and pagination options // @Description Retrieves a list of all awaiting KindBox requests with filtering, sorting, and pagination options
// @Tags KindBoxReq // @Tags Agents KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param filter_id query int false "Filter by ID" // @Param filter_id query int false "Filter by ID"
@ -32,7 +32,7 @@ import (
// @Success 200 {object} param.DeliveryAwaitingGetAllResponse // @Success 200 {object} param.DeliveryAwaitingGetAllResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs/awaiting-delivery [get]. // @Router /agents/kindboxreqs/awaiting-delivery [get].
func (h Handler) GetAllAwaitingDelivery(c echo.Context) error { func (h Handler) GetAllAwaitingDelivery(c echo.Context) error {
var req param.DeliveryAwaitingGetAllRequest var req param.DeliveryAwaitingGetAllRequest
@ -42,7 +42,7 @@ func (h Handler) GetAllAwaitingDelivery(c echo.Context) error {
req.Filter = queryparam.GetFilterParams(c) req.Filter = queryparam.GetFilterParams(c)
req.Filter["sender_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID req.Filter["sender_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID
req.Filter["status"] = entity.KindBoxReqAssignedSenderAgentStatus req.Filter["status"] = entity.KindBoxReqAssignedSenderAgentStatus
resp, sErr := h.adminKindBoxReqSvc.GetAllAwaitingDelivery(c.Request().Context(), req) resp, sErr := h.agentKindBoxReqSvc.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 { if resp.FieldErrors != nil {

View File

@ -1,9 +1,9 @@
package adminkindboxreqhandler package agentkindboxreqhandler
import ( import (
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
"net/http" "net/http"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/pkg/claim" "git.gocasts.ir/ebhomengo/niki/pkg/claim"
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"
@ -11,14 +11,14 @@ import (
// GetAwaitingDelivery godoc // GetAwaitingDelivery godoc
// @Summary Get a kind box reqs that is awaiting delivery by agent // @Summary Get a kind box reqs that is awaiting delivery by agent
// @Tags KindBoxReq // @Tags Agents KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"
// @Success 200 {object} param.DeliveryAwaitingGetResponse // @Success 200 {object} param.DeliveryAwaitingGetResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin // @Security AuthBearerAdmin
// @Router /admin/kindboxreqs/awaiting-delivery/{id} [get]. // @Router /agents/kindboxreqs/awaiting-delivery/{id} [get].
func (h Handler) GetAwaitingDelivery(c echo.Context) error { func (h Handler) GetAwaitingDelivery(c echo.Context) error {
var req param.DeliveryAwaitingGetRequest var req param.DeliveryAwaitingGetRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
@ -28,7 +28,7 @@ func (h Handler) GetAwaitingDelivery(c echo.Context) error {
claims := claim.GetClaimsFromEchoContext(c) claims := claim.GetClaimsFromEchoContext(c)
req.AgentID = claims.UserID req.AgentID = claims.UserID
resp, sErr := h.adminKindBoxReqSvc.GetAwaitingDelivery(c.Request().Context(), req) resp, sErr := h.agentKindBoxReqSvc.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 { if resp.FieldErrors != nil {

View File

@ -0,0 +1,28 @@
package agentkindboxreqhandler
import (
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
agentkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box_req"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification"
)
type Handler struct {
authSvc authservice.Service
agentKindBoxReqSvc agentkindboxreqservice.Service
adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
}
func New(authSvc authservice.Service,
agentKindBoxReqSvc agentkindboxreqservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler {
return Handler{
authSvc: authSvc,
agentKindBoxReqSvc: agentKindBoxReqSvc,
adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
}
}

View File

@ -0,0 +1,16 @@
package agentkindboxreqhandler
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("/agents/kindboxreqs")
r.Use(middleware.Auth(h.authSvc))
r.GET("/awaiting-delivery/:id", h.GetAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission))
r.GET("/awaiting-delivery", h.GetAllAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission))
r.PATCH("/:id/deliver-kind-box-req", h.Deliver, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqDeliverPermission))
}

View File

@ -12,14 +12,14 @@ import (
// AddAddress godoc // AddAddress godoc
// @Summary Add a new address for a benefactor // @Summary Add a new address for a benefactor
// @Description This endpoint allows an authenticated benefactor to add a new address to their account. // @Description This endpoint allows an authenticated benefactor to add a new address to their account.
// @Tags Address // @Tags Benefactors Addresses
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body param.BenefactorAddAddressRequest true "New address details" // @Param Request body param.BenefactorAddAddressRequest true "New address details"
// @Success 201 {object} param.BenefactorAddAddressResponse // @Success 201 {object} param.BenefactorAddAddressResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /address/ [post]. // @Router /benefactors/addresses [post].
func (h Handler) AddAddress(c echo.Context) error { func (h Handler) AddAddress(c echo.Context) error {
req := param.BenefactorAddAddressRequest{} req := param.BenefactorAddAddressRequest{}
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -12,12 +12,12 @@ import (
// DeleteAddress godoc // DeleteAddress godoc
// @Summary Delete address by benefactor // @Summary Delete address by benefactor
// @Description This endpoint is used to delete an address by benefactor // @Description This endpoint is used to delete an address by benefactor
// @Tags Address // @Tags Benefactors Addresses
// @Param id path int true "Address ID" // @Param id path int true "Address ID"
// @Success 204 // @Success 204
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /address/{id} [delete]. // @Router /benefactors/addresses/{id} [delete].
func (h Handler) DeleteAddress(c echo.Context) error { func (h Handler) DeleteAddress(c echo.Context) error {
var req param.DeleteAddressRequest var req param.DeleteAddressRequest

View File

@ -11,14 +11,14 @@ import (
// GetAddress godoc // GetAddress godoc
// @Summary Get a benefactor address // @Summary Get a benefactor address
// @Tags Address // @Tags Benefactors Addresses
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Address ID" // @Param id path int true "Address ID"
// @Success 200 {object} param.GetAddressResponse // @Success 200 {object} param.GetAddressResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /address/{id} [get]. // @Router /benefactors/addresses/{id} [get].
func (h Handler) GetAddress(c echo.Context) error { func (h Handler) GetAddress(c echo.Context) error {
var req param.GetAddressRequest var req param.GetAddressRequest
if bErr := echo.PathParamsBinder(c).Uint("id", &req.AddressID).BindError(); bErr != nil { if bErr := echo.PathParamsBinder(c).Uint("id", &req.AddressID).BindError(); bErr != nil {

View File

@ -11,13 +11,13 @@ import (
// GetAddresses godoc // GetAddresses godoc
// @Summary Get all benefactor addresses // @Summary Get all benefactor addresses
// @Tags Address // @Tags Benefactors Addresses
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} param.GetAllAddressesResponse // @Success 200 {object} param.GetAllAddressesResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /address/ [get]. // @Router /benefactors/addresses [get].
func (h Handler) GetAddresses(c echo.Context) error { func (h Handler) GetAddresses(c echo.Context) error {
var req param.GetAllAddressesRequest var req param.GetAllAddressesRequest

View File

@ -10,12 +10,12 @@ import (
// GetAllCities godoc // GetAllCities godoc
// @Summary Get all cities // @Summary Get all cities
// @Tags Address // @Tags Benefactors Addresses
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} addressparam.GetAllCitiesResponse // @Success 200 {object} addressparam.GetAllCitiesResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /address/cities [get]. // @Router /benefactors/addresses/cities [get].
func (h Handler) GetAllCities(c echo.Context) error { func (h Handler) GetAllCities(c echo.Context) error {
var req addressparam.GetAllCitiesRequest var req addressparam.GetAllCitiesRequest

View File

@ -10,12 +10,12 @@ import (
// GetAllProvinces godoc // GetAllProvinces godoc
// @Summary Get all provinces // @Summary Get all provinces
// @Tags Address // @Tags Benefactors Addresses
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} addressparam.GetAllProvincesResponse // @Success 200 {object} addressparam.GetAllProvincesResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /address/provinces [get]. // @Router /benefactors/addresses/provinces [get].
func (h Handler) GetAllProvinces(c echo.Context) error { func (h Handler) GetAllProvinces(c echo.Context) error {
var req addressparam.GetAllProvincesRequest var req addressparam.GetAllProvincesRequest

View File

@ -7,18 +7,18 @@ import (
) )
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/address") r := e.Group("/benefactors/addresses")
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), 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), 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), 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), 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), r.PUT("/:id", h.UpdateAddress, middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole)) middleware.BenefactorAuthorization(entity.UserBenefactorRole))
} }

View File

@ -10,8 +10,8 @@ import (
) )
// UpdateAddress godoc // UpdateAddress godoc
// @Summary Edit benefactor address // @Summary Update benefactor address
// @Tags Address // @Tags Benefactors Addresses
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Address ID" // @Param id path int true "Address ID"
@ -19,7 +19,7 @@ import (
// @Success 204 // @Success 204
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /address/{id} [patch]. // @Router /benefactors/addresses/{id} [put].
func (h Handler) UpdateAddress(c echo.Context) error { func (h Handler) UpdateAddress(c echo.Context) error {
var req param.UpdateAddressRequest var req param.UpdateAddressRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -11,13 +11,13 @@ import (
// loginOrRegister godoc // loginOrRegister godoc
// @Summary Login or register a benefactor // @Summary Login or register a benefactor
// @Description This endpoint is used to authenticate an existing benefactor account or register a new one. // @Description This endpoint is used to authenticate an existing benefactor account or register a new one.
// @Tags Benefactor // @Tags Benefactors
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body benefactoreparam.LoginOrRegisterRequest true "Login or register request details" // @Param Request body benefactoreparam.LoginOrRegisterRequest true "Login or register request details"
// @Success 200 {object} benefactoreparam.LoginOrRegisterResponse // @Success 200 {object} benefactoreparam.LoginOrRegisterResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /benefactor/login-register [post]. // @Router /benefactors/login-register [post].
func (h Handler) loginOrRegister(c echo.Context) error { func (h Handler) loginOrRegister(c echo.Context) error {
var req benefactoreparam.LoginOrRegisterRequest var req benefactoreparam.LoginOrRegisterRequest

View File

@ -0,0 +1,36 @@
package benefactorhandler
import (
benefactorparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"net/http"
"github.com/labstack/echo/v4"
)
// RefreshAccess godoc
// @Summary Get a new access token by providing your refresh token
// @Tags Benefactors
// @Accept json
// @Produce json
// @Param Request body benefactorparam.RefreshAccessRequest true "Refresh access token request body"
// @Success 200 {object} benefactorparam.RefreshAccessResponse
// @Failure 400 {string} "Bad Request"
// @Failure 500 {string} "something went wrong"
// @Router /benefactors/refresh-access [post].
func (h Handler) RefreshAccess(c echo.Context) error {
var req benefactorparam.RefreshAccessRequest
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, err := h.benefactorSvc.RefreshAccess(c.Request().Context(), req)
if err != nil {
msg, code := httpmsg.Error(err)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusOK, resp)
}

View File

@ -5,8 +5,9 @@ import (
) )
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactor") r := e.Group("/benefactors")
r.POST("/send-otp", h.SendOtp) r.POST("/send-otp", h.SendOtp)
r.POST("/login-register", h.loginOrRegister) r.POST("/login-register", h.loginOrRegister)
r.POST("/refresh-access", h.RefreshAccess)
} }

View File

@ -11,13 +11,13 @@ import (
// SendOtp godoc // SendOtp godoc
// @Summary Send OTP to benefactor // @Summary Send OTP to benefactor
// @Description This endpoint sends an OTP to the benefactor's phone number for verification purposes. // @Description This endpoint sends an OTP to the benefactor's phone number for verification purposes.
// @Tags Benefactor // @Tags Benefactors
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body benefactoreparam.SendOtpRequest true "Send OTP request details" // @Param Request body benefactoreparam.SendOtpRequest true "Send OTP request details"
// @Success 200 {object} benefactoreparam.SendOtpResponse // @Success 200 {object} benefactoreparam.SendOtpResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /benefactor/send-otp [post]. // @Router /benefactors/send-otp [post].
func (h Handler) SendOtp(c echo.Context) error { func (h Handler) SendOtp(c echo.Context) error {
var req benefactoreparam.SendOtpRequest var req benefactoreparam.SendOtpRequest

View File

@ -1,6 +1,7 @@
package benefactorkindboxhandler package benefactorkindboxhandler
import ( import (
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
"net/http" "net/http"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
@ -11,19 +12,21 @@ import (
// Get godoc // Get godoc
// @Summary Get a specific kind box for a benefactor // @Summary Get a specific kind box for a benefactor
// @Description This endpoint retrieves a specific kind box associated with an authenticated benefactor. // @Description This endpoint retrieves a specific kind box associated with an authenticated benefactor.
// @Tags KindBox // @Tags Benefactors KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Kind box ID" // @Param id path int true "Kind box ID"
// @Success 200 {object} param.KindBoxGetResponse // @Success 200 {object} param.KindBoxGetResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxes/{id} [get]. // @Router /benefactors/kindboxes/{id} [get].
func (h Handler) Get(c echo.Context) error { func (h Handler) Get(c echo.Context) error {
var req param.KindBoxGetRequest var req param.KindBoxGetRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest) return echo.NewHTTPError(http.StatusBadRequest)
} }
claims := claim.GetClaimsFromEchoContext(c)
req.BenefactorID = claims.UserID
resp, sErr := h.benefactorKindBoxSvc.Get(c.Request().Context(), req) resp, sErr := h.benefactorKindBoxSvc.Get(c.Request().Context(), req)
if sErr != nil { if sErr != nil {

View File

@ -13,7 +13,7 @@ import (
// GetAll godoc // GetAll godoc
// @Summary Get all KindBoxes by benefactor // @Summary Get all KindBoxes by benefactor
// @Description Retrieves a list of all KindBoxes with filtering, sorting, and pagination options // @Description Retrieves a list of all KindBoxes with filtering, sorting, and pagination options
// @Tags KindBox // @Tags Benefactors KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param filter_id query int false "Filter by ID" // @Param filter_id query int false "Filter by ID"
@ -40,7 +40,7 @@ import (
// @Success 200 {object} param.KindBoxGetAllResponse // @Success 200 {object} param.KindBoxGetAllResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxes [get]. // @Router /benefactors/kindboxes [get].
func (h Handler) GetAll(c echo.Context) error { func (h Handler) GetAll(c echo.Context) error {
var req param.KindBoxGetAllRequest var req param.KindBoxGetAllRequest

View File

@ -12,7 +12,7 @@ import (
// RegisterEmptyingRequest godoc // RegisterEmptyingRequest godoc
// @Summary Register a new emptying request for a kind box by benefactor // @Summary Register a new emptying request for a kind box by benefactor
// @Tags Benefactor // @Tags Benefactors KindBoxes
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBox ID" // @Param id path int true "KindBox ID"
@ -20,7 +20,7 @@ import (
// @Success 204 {string} "No content" // @Success 204 {string} "No content"
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxes/{id}/emptying-requests [patch]. // @Router /benefactors/kindboxes/{id}/emptying-requests [patch].
func (h Handler) RegisterEmptyingRequest(c echo.Context) error { func (h Handler) RegisterEmptyingRequest(c echo.Context) error {
var req param.KindBoxRegisterEmptyingRequest var req param.KindBoxRegisterEmptyingRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {
@ -44,7 +44,7 @@ func (h Handler) RegisterEmptyingRequest(c echo.Context) error {
} }
go h.notificationSvc.KindBoxRegisteredEmptyingRequest(params.NotificationKindBoxRegisteredEmptyingRequest{ go h.notificationSvc.KindBoxRegisteredEmptyingRequest(params.NotificationKindBoxRegisteredEmptyingRequest{
KindBoxID: resp.ID, KindBoxID: resp.Data.ID,
}) })
return c.JSON(http.StatusNoContent, nil) return c.JSON(http.StatusNoContent, nil)

View File

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

View File

@ -13,14 +13,14 @@ import (
// Add godoc // Add godoc
// @Summary Add a new kind box request for a benefactor // @Summary Add a new kind box request for a benefactor
// @Tags KindBoxReq // @Tags Benefactors KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body param.KindBoxReqAddRequest true "New kind box request details" // @Param Request body param.KindBoxReqAddRequest true "New kind box request details"
// @Success 200 {object} param.KindBoxReqAddResponse // @Success 200 {object} param.KindBoxReqAddResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxreqs/ [post]. // @Router /benefactors/kindboxreqs [post].
func (h Handler) Add(c echo.Context) error { func (h Handler) Add(c echo.Context) error {
req := param.KindBoxReqAddRequest{} req := param.KindBoxReqAddRequest{}
if err := c.Bind(&req); err != nil { if err := c.Bind(&req); err != nil {
@ -46,7 +46,7 @@ func (h Handler) Add(c echo.Context) error {
} }
go h.notificationSvc.KindBoxReqAdded(params.NotificationKindBoxReqAdded{ go h.notificationSvc.KindBoxReqAdded(params.NotificationKindBoxReqAdded{
KindBoxReqID: resp.KindBoxReq.ID, KindBoxReqID: resp.Data.ID,
}) })
return c.JSON(http.StatusCreated, resp) return c.JSON(http.StatusCreated, resp)

View File

@ -9,17 +9,17 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
// delete godoc // Delete godoc
// @Summary delete kindboxreq by benefactor // @Summary Delete kindboxreq by benefactor
// @Description This endpoint is used to delete benefactor's kindboxreq at pending status // @Description This endpoint is used to delete benefactor's kindboxreq at pending status
// @Tags KindBoxReq // @Tags Benefactors KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Kind box request ID" // @Param id path int true "Kind box request ID"
// @Success 200 {object} param.KindBoxReqDeleteResponse // @Success 200 {object} param.KindBoxReqDeleteResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxreqs/{id} [delete]. // @Router /benefactors/kindboxreqs/{id} [delete].
func (h Handler) Delete(c echo.Context) error { func (h Handler) Delete(c echo.Context) error {
req := param.KindBoxReqDeleteRequest{} req := param.KindBoxReqDeleteRequest{}
if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil { if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil {

View File

@ -11,14 +11,14 @@ import (
// Get godoc // Get godoc
// @Summary Get a kind box request for a benefactor // @Summary Get a kind box request for a benefactor
// @Tags KindBoxReq // @Tags Benefactors KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Kind box request ID" // @Param id path int true "Kind box request ID"
// @Success 200 {object} param.KindBoxReqGetResponse // @Success 200 {object} param.KindBoxReqGetResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxreqs/{id} [get]. // @Router /benefactors/kindboxreqs/{id} [get].
func (h Handler) Get(c echo.Context) error { func (h Handler) Get(c echo.Context) error {
var req param.KindBoxReqGetRequest var req param.KindBoxReqGetRequest
if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil { if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil {

View File

@ -13,7 +13,7 @@ import (
// GetAll godoc // GetAll godoc
// @Summary Get all KindBox requests // @Summary Get all KindBox requests
// @Description Retrieves a list of all KindBox requests with filtering, sorting, and pagination options // @Description Retrieves a list of all KindBox requests with filtering, sorting, and pagination options
// @Tags KindBoxReq // @Tags Benefactors KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param filter_id query int false "Filter by ID" // @Param filter_id query int false "Filter by ID"
@ -32,7 +32,7 @@ import (
// @Success 200 {object} param.GetAllResponse // @Success 200 {object} param.GetAllResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxreqs/ [get]. // @Router /benefactors/kindboxreqs [get].
func (h Handler) GetAll(c echo.Context) error { func (h Handler) GetAll(c echo.Context) error {
var req param.GetAllRequest var req param.GetAllRequest

View File

@ -7,16 +7,16 @@ import (
) )
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactor/kindboxreqs") r := e.Group("/benefactors/kindboxreqs")
r.Use( r.Use(
middleware.Auth(h.authSvc), middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole), middleware.BenefactorAuthorization(entity.UserBenefactorRole),
) )
r.POST("/", h.Add) r.POST("", h.Add)
r.GET("/:id", h.Get) r.GET("/:id", h.Get)
r.DELETE("/:id", h.Delete) r.DELETE("/:id", h.Delete)
r.GET("/", h.GetAll) r.GET("", h.GetAll)
r.PUT("/:id", h.Update) r.PUT("/:id", h.Update)
} }

View File

@ -11,7 +11,7 @@ import (
// Update godoc // Update godoc
// @Summary Update kind box request by benefactor // @Summary Update kind box request by benefactor
// @Tags KindBoxReq // @Tags Benefactors KindBoxReqs
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"
@ -23,7 +23,7 @@ import (
// @Failure 422 {object} httpmsg.ErrorResponse // @Failure 422 {object} httpmsg.ErrorResponse
// @Failure 500 {string} "something went wrong" // @Failure 500 {string} "something went wrong"
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /benefactor/kindboxreqs/{id} [put]. // @Router /benefactors/kindboxreqs/{id} [put].
func (h Handler) Update(c echo.Context) error { func (h Handler) Update(c echo.Context) error {
var req param.KindBoxReqUpdateRequest var req param.KindBoxReqUpdateRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -1,12 +1,12 @@
package setup package setup
import ( import (
"github.com/labstack/echo/v4"
"net/http" "net/http"
"git.gocasts.ir/ebhomengo/niki/config" "git.gocasts.ir/ebhomengo/niki/config"
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server" httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
"git.gocasts.ir/ebhomengo/niki/service" "git.gocasts.ir/ebhomengo/niki/service"
"github.com/labstack/echo/v4"
) )
type TestServer struct { type TestServer struct {

View File

@ -14,7 +14,7 @@ func Auth(service authservice.Service) echo.MiddlewareFunc {
// 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) {
claims, err := service.ParseToken(auth) claims, err := service.ParseBearerToken(auth)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,6 +2,7 @@ package httpserver
import ( import (
"fmt" "fmt"
agentkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box_req"
"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"
@ -28,6 +29,7 @@ type Server struct {
adminKindBoxHandler adminKindBoxHandler.Handler adminKindBoxHandler adminKindBoxHandler.Handler
adminAgentHandler adminagenthandler.Handler adminAgentHandler adminagenthandler.Handler
agentKindBoxHandler agentkindboxhandler.Handler agentKindBoxHandler agentkindboxhandler.Handler
agentKindBoxReqHandler agentkindboxreqhandler.Handler
benefactorHandler benefactorhandler.Handler benefactorHandler benefactorhandler.Handler
benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler
benefactorAddressHandler benefactoraddresshandler.Handler benefactorAddressHandler benefactoraddresshandler.Handler
@ -45,7 +47,8 @@ func New(
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc), adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc), adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc), adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc), agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc), benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc),
benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxReqSvc, svc.NotificationSvc), benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxReqSvc, svc.NotificationSvc),
benefactorAddressHandler: benefactoraddresshandler.New(svc.BenefactorAuthSvc, svc.BenefactorAddressSvc), benefactorAddressHandler: benefactoraddresshandler.New(svc.BenefactorAuthSvc, svc.BenefactorAddressSvc),
@ -67,7 +70,10 @@ func (s Server) Serve() {
func (s Server) RegisterRoutes() { func (s Server) RegisterRoutes() {
s.Router.Use(middleware.RequestID()) s.Router.Use(middleware.RequestID())
s.Router.Use(middleware.Recover()) s.Router.Use(middleware.Recover())
registerSwagger(s.Router, s.config) s.Router.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: s.config.HTTPServer.Cors.AllowOrigins,
}))
registerSwagger(s.Router)
// Routes // Routes
s.Router.GET("/health-check", s.healthCheck) s.Router.GET("/health-check", s.healthCheck)
@ -76,17 +82,18 @@ func (s Server) RegisterRoutes() {
s.benefactorAddressHandler.SetRoutes(s.Router) s.benefactorAddressHandler.SetRoutes(s.Router)
s.benefactorKindBoxHandler.SetRoutes(s.Router) s.benefactorKindBoxHandler.SetRoutes(s.Router)
s.adminHandler.SetRoutes(s.Router) s.adminHandler.SetRoutes(s.Router)
s.adminAgentHandler.SetRoutes(s.Router)
s.adminKindBoxReqHandler.SetRoutes(s.Router) s.adminKindBoxReqHandler.SetRoutes(s.Router)
s.adminKindBoxHandler.SetRoutes(s.Router) s.adminKindBoxHandler.SetRoutes(s.Router)
s.agentKindBoxHandler.SetRoutes(s.Router) s.agentKindBoxHandler.SetRoutes(s.Router)
s.agentKindBoxReqHandler.SetRoutes(s.Router)
} }
func registerSwagger(s *echo.Echo, c config.Config) { func registerSwagger(s *echo.Echo) {
// TODO: move this to a better place and make it more dynamic and configurable // TODO: move this to a better place and make it more dynamic and configurable
docs.SwaggerInfo.Title = "NIKI API" docs.SwaggerInfo.Title = "NIKI API"
docs.SwaggerInfo.Description = "This is the API documentation for the NIKI project" docs.SwaggerInfo.Description = "This is the API documentation for the NIKI project"
docs.SwaggerInfo.Version = "1.0.0" docs.SwaggerInfo.Version = "1.0.0"
docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%d", c.HTTPServer.Port)
s.GET("/swagger/*any", echoSwagger.WrapHandler) s.GET("/swagger/*any", echoSwagger.WrapHandler)
} }

View File

@ -0,0 +1,11 @@
COMPOSE_MARIADB_PORT=3306
COMPOSE_MARIADB_DATABASE=niki_db
COMPOSE_MARIADB_USER=niki
COMPOSE_MARIADB_UR_PASSWORD=n0ki2agd23
COMPOSE_REDIS_PORT=6379
COMPOSE_REDIS_DB=0
COMPOSE_REDIS_PASSWORD=n0ki2agd23
COMPOSE_AUTH_SIGN_KEY=jwt_secret_stage_nik
COMPOSE_ADMIN_AUTH_SIGN_KEY=admin-jwt_secret_stage_nik

View File

@ -0,0 +1,15 @@
---
type: yml
http_server:
port: 1313
cors:
allow_origins:
- "*"
benefactor_service:
length_of_otp_code: 5
kavenegar_sms_provider:
api_key: insert_your_api_key
sender: insert_sender_number

View File

@ -1,12 +1,26 @@
version: '3.7' version: '3.9'
services: services:
niki_app_stage: niki_app_stage:
image: niki:${STAGE_NIKI_IMAGE_VERSION} image: niki:${STAGE_NIKI_IMAGE_VERSION?error}
container_name: niki_app_stage container_name: niki_app_stage
environment:
EB_MARIADB__HOST: niki_stage_mariadb
EB_MARIADB__PORT: ${COMPOSE_MARIADB_PORT?error}
EB_MARIADB__DB_NAME: ${COMPOSE_MARIADB_DATABASE?error}
EB_MARIADB__USERNAME: ${COMPOSE_MARIADB_USER?error}
EB_MARIADB__PASSWORD: ${COMPOSE_MARIADB_UR_PASSWORD?error}
EB_REDIS__HOST: niki_stage_redis
EB_REDIS__PORT: ${COMPOSE_REDIS_PORT?error}
EB_REDIS__DB: ${COMPOSE_REDIS_DB?error}
EB_REDIS__PASSWORD: ${COMPOSE_REDIS_PASSWORD?error}
EB_AUTH__SIGN_KEY: ${COMPOSE_AUTH_SIGN_KEY?error}
EB_ADMIN_AUTH__SIGN_KEY: ${COMPOSE_ADMIN_AUTH_SIGN_KEY?error}
restart: always restart: always
ports: ports:
- '127.0.0.1:8198:1313' - "127.0.0.1:8313:1313"
networks: networks:
- niki-stage - niki-stage
volumes: volumes:

View File

@ -1,36 +0,0 @@
---
type: yml
auth:
sign_key: jwt_secret_stage_nik
http_server:
port: 1313
mysql:
port: 3306
host: niki_stage_mariadb
db_name: niki_db
username: niki
password: n0ki2agd23
redis:
port: 6379
host: niki_stage_redis
password: ""
db: 0
sms_provider:
host: localhost
port: 443
benefactor_service:
length_of_otp_code: 5
kavenegar_sms_provider:
api_key: insert_your_api_key
otp_template_new_user: ebhomeverify
otp_template_registered_user: ebhomeverify
admin_auth:
sign_key: admin-jwt_secret_test_nik

View File

@ -0,0 +1,4 @@
COMPOSE_MARIADB_DATABASE=niki_db
COMPOSE_MARIADB_USER=niki
COMPOSE_MARIADB_UR_PASSWORD=n0ki2agd23
COMPOSE_MARIADB_RT_PASSWORD=n0ki2agd23

View File

@ -1,22 +1,22 @@
version: '3.1' version: '3.9'
services: services:
niki_stage_mariadb: niki_stage_mariadb:
image: docker.io/bitnami/mariadb:11.1 image: docker.io/bitnami/mariadb:11.1
container_name: niki_stage_mariadb container_name: niki_stage_mariadb
restart: always restart: always
ports:
- '127.0.0.1:3429:3306'
networks: networks:
- niki-stage - niki-stage
expose:
- "3306"
volumes: volumes:
- 'niki_stage_mariadb_data:/bitnami/mariadb' - 'niki_stage_mariadb_data:/bitnami/mariadb'
environment: environment:
- MARIADB_USER=niki MARIADB_USER: ${COMPOSE_MARIADB_USER?error}
- MARIADB_PASSWORD=${NIKI_STAGE_MARIADB_UR_PASSWORD} MARIADB_PASSWORD: ${COMPOSE_MARIADB_UR_PASSWORD?error}
- MARIADB_DATABASE=niki_db MARIADB_DATABASE: ${COMPOSE_MARIADB_DATABASE?error}
- MARIADB_ROOT_PASSWORD=${NIKI_STAGE_MARIADB_RT_PASSWORD} MARIADB_ROOT_PASSWORD: ${COMPOSE_MARIADB_RT_PASSWORD?error}
- ALLOW_EMPTY_PASSWORD=no ALLOW_EMPTY_PASSWORD: no
healthcheck: healthcheck:
test: ['CMD', '/opt/bitnami/scripts/mariadb/healthcheck.sh'] test: ['CMD', '/opt/bitnami/scripts/mariadb/healthcheck.sh']
interval: 15s interval: 15s

View File

@ -0,0 +1 @@
COMPOSE_REDIS_PASSWORD=n0ki2agd23

View File

@ -1,18 +1,17 @@
version: '3.1' version: '3.9'
services: services:
niki_stage_redis: niki_stage_redis:
image: bitnami/redis:6.2 image: bitnami/redis:6.2
container_name: niki_stage_redis container_name: niki_stage_redis
restart: always restart: always
ports: command: redis-server --loglevel warning --protected-mode no
- '127.0.0.1:6380:6379'
# TODO - remove `--save "" --appendonly no` from command to persist data
command: redis-server --loglevel warning --protected-mode no --save "" --appendonly no
environment: environment:
- ALLOW_EMPTY_PASSWORD=yes REDIS_PASSWORD: ${COMPOSE_REDIS_PASSWORD?error}
networks: networks:
- core - niki-stage
expose:
- "6379"
volumes: volumes:
- niki__stage_redis_data:/data - niki__stage_redis_data:/data

View File

@ -1,40 +0,0 @@
version: '3.9'
services:
mysqltest:
image: mysql:8.0
ports:
- "3305:3306"
container_name: niki-database-test
volumes:
- dbdatatest:/var/lib/mysql
restart: always
command: [ 'mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ]
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: test_db
MYSQL_USER: testuser
MYSQL_PASSWORD: test1234
niki-redis-test:
image: bitnami/redis:6.2
container_name: niki-redis-test
restart: always
ports:
- '6381:6379'
# TODO - remove `--save "" --appendonly no` from command to persist data
command: redis-server --loglevel warning --protected-mode no --save "" --appendonly no
environment:
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- niki-redis-data-test:/data
volumes:
dbdatatest:
niki-redis-data-test:
# docker-compose -f docker-compose.dev.yaml up -d

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -20,4 +20,5 @@ const (
AdminKindBoxGetAwaitingReturnPermission = AdminPermission("kindbox-get_awaiting_return") AdminKindBoxGetAwaitingReturnPermission = AdminPermission("kindbox-get_awaiting_return")
AdminKindBoxReturnPermission = AdminPermission("kindbox-return") AdminKindBoxReturnPermission = AdminPermission("kindbox-return")
AdminKindBoxEnumeratePermission = AdminPermission("kindbox-enumerate") AdminKindBoxEnumeratePermission = AdminPermission("kindbox-enumerate")
AdminKindBoxUpdatePermission = AdminPermission("kindbox-update")
) )

View File

@ -12,4 +12,5 @@ type Benefactor struct {
Gender Gender Gender Gender
BirthDate time.Time BirthDate time.Time
Role UserRole Role UserRole
Status BenefactorStatus
} }

View File

@ -0,0 +1,19 @@
package entity
type BenefactorStatus string
const (
BenefactorActiveStatus = BenefactorStatus("active")
BenefactorInactiveStatus = BenefactorStatus("inactive")
)
var BenefactorStatusStrings = map[BenefactorStatus]string{
BenefactorActiveStatus: "active",
BenefactorInactiveStatus: "inactive",
}
func (b BenefactorStatus) IsValid() bool {
_, ok := BenefactorStatusStrings[b]
return ok
}

4
go.mod
View File

@ -1,8 +1,6 @@
module git.gocasts.ir/ebhomengo/niki module git.gocasts.ir/ebhomengo/niki
go 1.22 go 1.23
toolchain go1.22.4
require ( require (
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible github.com/go-ozzo/ozzo-validation v3.6.0+incompatible

15
param/admin/admin/data.go Normal file
View File

@ -0,0 +1,15 @@
package adminserviceparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type Data struct {
ID uint `json:"id" example:"1"`
FirstName string `json:"first_name" example:"John"`
LastName string `json:"last_name" example:"Doe"`
PhoneNumber string `json:"phone_number" example:"09123456789"`
Role entity.AdminRole `json:"role" example:"2"`
Description string `json:"description" example:"This is a description"`
Email string `json:"email" example:"example@gmail.com"`
Gender entity.Gender `json:"gender" example:"male"`
Status entity.AdminStatus `json:"status" example:"active"`
}

View File

@ -1,26 +1,12 @@
package adminserviceparam package adminserviceparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type LoginWithPhoneNumberRequest struct { type LoginWithPhoneNumberRequest struct {
PhoneNumber string `json:"phone_number" example:"09123456789"` PhoneNumber string `json:"phone_number" example:"09123456789"`
Password string `json:"password" example:"password123"` Password string `json:"password" example:"password123"`
} }
type LoginWithPhoneNumberResponse struct { type LoginWithPhoneNumberResponse struct {
AdminInfo AdminInfo `json:"admin_info"` Data Data `json:"data"`
Tokens Tokens `json:"tokens"` Tokens Tokens `json:"tokens"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }
type AdminInfo struct {
ID uint `json:"id" example:"1"`
FirstName string `json:"first_name" example:"John"`
LastName string `json:"last_name" example:"Doe"`
PhoneNumber string `json:"phone_number" example:"09123456789"`
Role entity.AdminRole `json:"role" example:"2"`
Description string `json:"description" example:"This is a description"`
Email string `json:"email" example:"example@gmail.com"`
Gender entity.Gender `json:"gender" example:"male"`
Status entity.AdminStatus `json:"status" example:"active"`
}

View File

@ -0,0 +1,9 @@
package adminserviceparam
type RefreshAccessRequest struct {
RefreshToken string `json:"refresh_token"`
}
type RefreshAccessResponse struct {
AccessToken string `json:"access_token"`
}

View File

@ -15,6 +15,6 @@ type RegisterRequest struct {
} }
type RegisterResponse struct { type RegisterResponse struct {
Admin entity.Admin `json:"admin"` Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,10 +1,10 @@
package adminagentparam package adminagentparam
type GetAllAgentResponse struct { type GetAllAgentResponse struct {
Agents []Agent `json:"agents"` Data []Data `json:"data"`
} }
type Agent struct { type Data struct {
ID uint `json:"id" example:"1"` ID uint `json:"id" example:"1"`
FirstName string `json:"first_name" example:"John"` FirstName string `json:"first_name" example:"John"`
LastName string `json:"last_name" example:"Doe"` LastName string `json:"last_name" example:"Doe"`

View File

@ -0,0 +1,27 @@
package adminkindboxparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Data struct {
ID uint `json:"id"`
KindBoxReqID uint `json:"kind_box_req_id"`
BenefactorID uint `json:"benefactor_id"`
KindBoxType entity.KindBoxType `json:"kind_box_type"`
Amount uint `json:"amount"`
SerialNumber string `json:"serial_number"`
Status entity.KindBoxStatus `json:"status"`
DeliverReferTimeID uint `json:"deliver_refer_time_id"`
DeliverReferDate time.Time `json:"deliver_refer_date"`
DeliverAddressID uint `json:"deliver_address_id"`
SenderAgentID uint `json:"sender_agent_id"`
DeliveredAt time.Time `json:"delivered_at"`
ReturnReferTimeID uint `json:"return_refer_time_id"`
ReturnReferDate time.Time `json:"return_refer_date"`
ReturnAddressID uint `json:"return_address_id"`
ReceiverAgentID uint `json:"receiver_agent_id"`
ReturnedAt time.Time `json:"returned_at"`
}

View File

@ -1,12 +1,10 @@
package adminkindboxparam package adminkindboxparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxGetRequest struct { type KindBoxGetRequest struct {
KindBoxID uint `param:"id"` KindBoxID uint `param:"id"`
} }
type KindBoxGetResponse struct { type KindBoxGetResponse struct {
entity.KindBox Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,7 +1,6 @@
package adminkindboxparam package adminkindboxparam
import ( import (
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/param" "git.gocasts.ir/ebhomengo/niki/param"
) )
@ -12,7 +11,7 @@ type KindBoxGetAllRequest struct {
} }
type KindBoxGetAllResponse struct { type KindBoxGetAllResponse struct {
AllKindBox []entity.KindBox `json:"all_kind_box"` Data []Data `json:"data"`
Pagination param.PaginationResponse `json:"pagination"` Pagination param.PaginationResponse `json:"pagination"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,17 +1,20 @@
package adminkindboxparam package adminkindboxparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import (
"time"
)
//when kindbox creates, which fields are
type KindBoxUpdateRequest struct { type KindBoxUpdateRequest struct {
BenefactorID uint KindBoxID uint `json:"-" param:"id" example:"1"` // ID is passed in the URL path
KindBoxID uint BenefactorID uint `json:"benefactor_id" example:"1"`
Amount uint ReturnReferTimeID uint `json:"return_refere_time_id" example:"3"`
ReceiverAgentID uint ReturnReferDate time.Time `json:"return_refer_date" example:"2025-01-02T15:04:05Z"`
SenderAgentID uint ReturnAddressID uint `json:"return_address_id" example:"1"`
SerialNumber string ReceiverAgentID uint `json:"receiver_agent_id" example:"23"`
Status entity.KindBoxStatus Amount uint `json:"amount" example:"3"`
} }
type KindBoxUpdateResponse struct { type KindBoxUpdateResponse struct {
KindBox entity.KindBox FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,22 +1,11 @@
package adminkindboxreqparam package adminkindboxreqparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type KindBoxReqAcceptRequest struct { type KindBoxReqAcceptRequest struct {
ID uint `json:"-"` ID uint `json:"-"`
CountAccepted uint `json:"count_accepted"` CountAccepted uint `json:"count_accepted"`
} }
type KindBoxReqAcceptResponse struct { type KindBoxReqAcceptResponse struct {
KindBoxReqID uint `json:"kind_box_req_id"` Data Data `json:"data"`
KindBoxReqStatus entity.KindBoxReqStatus `json:"kind_box_req_status"`
CountRequested uint `json:"count_requested"`
CountAccepted uint `json:"count_accepted"`
DeliverReferDate time.Time `json:"deliver_refer_date"`
DeliverAddressID uint `json:"deliver_address_id"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,16 +1,20 @@
package adminkindboxreqparam package adminkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import (
entity "git.gocasts.ir/ebhomengo/niki/entity"
"time"
)
type KindBoxReqAddRequest struct { type KindBoxReqAddRequest struct {
BenefactorID uint `json:"benefactor_id" example:"1"` BenefactorID uint `json:"benefactor_id" example:"1"`
KindBoxType entity.KindBoxType `json:"kind_box_type" example:"on-table"` KindBoxType entity.KindBoxType `json:"kind_box_type" example:"on-table"`
DeliverAddressID uint `json:"deliver_address_id" example:"1"` DeliverAddressID uint `json:"deliver_address_id" example:"1"`
DeliverReferDate string `json:"deliver_refer_date" example:"2025-01-02 15:04:05"` DeliverReferDate time.Time `json:"deliver_refer_date" example:"2025-01-02T15:04:05Z"`
DeliverReferTimeID uint `json:"deliver_refer_time_id" example:"1"`
CountRequested uint `json:"count_requested" example:"2"` CountRequested uint `json:"count_requested" example:"2"`
} }
type KindBoxReqAddResponse struct { type KindBoxReqAddResponse struct {
KindBoxReq entity.KindBoxReq Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -0,0 +1,22 @@
package adminkindboxreqparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Data struct {
ID uint `json:"id"`
BenefactorID uint `json:"benefactor_id"`
KindBoxType entity.KindBoxType `json:"kind_box_type"`
CountRequested uint `json:"count_requested"`
CountAccepted uint `json:"count_accepted"`
Description string `json:"description"`
Status entity.KindBoxReqStatus `json:"status"`
DeliverReferTimeID uint `json:"deliver_refer_time_id"`
DeliverReferDate time.Time `json:"deliver_refer_date"`
DeliverAddressID uint `json:"deliver_address_id"`
SenderAgentID uint `json:"sender_agent_id"`
DeliveredAt time.Time `json:"delivered_at"`
}

View File

@ -1,12 +1,10 @@
package adminkindboxreqparam package adminkindboxreqparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type GetKindBoxReqRequest struct { type GetKindBoxReqRequest struct {
KindBoxID uint `param:"id"` KindBoxID uint `param:"id"`
} }
type GetKindBoxReqResponse struct { type GetKindBoxReqResponse struct {
entity.KindBoxReq Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,7 +1,6 @@
package adminkindboxreqparam package adminkindboxreqparam
import ( import (
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/param" "git.gocasts.ir/ebhomengo/niki/param"
) )
@ -12,7 +11,7 @@ type KindBoxReqGetAllRequest struct {
} }
type KindBoxReqGetAllResponse struct { type KindBoxReqGetAllResponse struct {
AllKindBoxReq []entity.KindBoxReq `json:"all_awaiting_kind_box_req"` Data []Data `json:"data"`
Pagination param.PaginationResponse `json:"pagination"` Pagination param.PaginationResponse `json:"pagination"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,18 +0,0 @@
package adminkindboxreqparam
import (
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/param"
)
type DeliveryAwaitingGetAllRequest struct {
Pagination param.PaginationRequest
Sort param.SortRequest
Filter param.FilterRequest
}
type DeliveryAwaitingGetAllResponse struct {
AllAwaitingKindBoxReq []entity.KindBoxReq `json:"all_awaiting_kind_box_req"`
Pagination param.PaginationResponse `json:"pagination"`
FieldErrors map[string]string `json:"field_errors,omitempty"`
}

View File

@ -1,24 +1,11 @@
package adminkindboxreqparam package adminkindboxreqparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type KindBoxReqRejectRequest struct { type KindBoxReqRejectRequest struct {
ID uint `json:"-"` ID uint `json:"-"`
Description string `json:"description" example:"description"` Description string `json:"description" example:"description"`
} }
type KindBoxReqRejectResponse struct { type KindBoxReqRejectResponse struct {
ID uint `json:"id" example:"1"` Data Data `json:"data"`
KindBoxType entity.KindBoxType `json:"kind_box_type" example:"on-table"`
CountRequested uint `json:"count_requested" example:"1"`
BenefactorID uint `json:"benefactor_id" example:"1"`
Status entity.KindBoxReqStatus `json:"status" example:"pending"`
Description string `json:"description" example:"description"`
DeliverReferDate time.Time `json:"deliver_refer_date" example:"2025-01-02 15:04:05"`
DeliverAddressID uint `json:"deliver_address_id" example:"1"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,4 +1,4 @@
package adminkindboxparam package agentkindboxparam
import ( import (
"time" "time"

View File

@ -0,0 +1,27 @@
package agentkindboxparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Data struct {
ID uint `json:"id"`
KindBoxReqID uint `json:"kind_box_req_id"`
BenefactorID uint `json:"benefactor_id"`
KindBoxType entity.KindBoxType `json:"kind_box_type"`
Amount uint `json:"amount"`
SerialNumber string `json:"serial_number"`
Status entity.KindBoxStatus `json:"status"`
DeliverReferTimeID uint `json:"deliver_refer_time_id"`
DeliverReferDate time.Time `json:"deliver_refer_date"`
DeliverAddressID uint `json:"deliver_address_id"`
SenderAgentID uint `json:"sender_agent_id"`
DeliveredAt time.Time `json:"delivered_at"`
ReturnReferTimeID uint `json:"return_refer_time_id"`
ReturnReferDate time.Time `json:"return_refer_date"`
ReturnAddressID uint `json:"return_address_id"`
ReceiverAgentID uint `json:"receiver_agent_id"`
ReturnedAt time.Time `json:"returned_at"`
}

View File

@ -1,7 +1,6 @@
package agentkindboxparam package agentkindboxparam
import ( import (
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/param" "git.gocasts.ir/ebhomengo/niki/param"
) )
@ -12,7 +11,7 @@ type GetAllRequest struct {
} }
type GetAllResponse struct { type GetAllResponse struct {
AllKindBoxes []entity.KindBox `json:"all_kind_boxes"` Data []Data `json:"data"`
Pagination param.PaginationResponse `json:"pagination"` Pagination param.PaginationResponse `json:"pagination"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,13 +1,11 @@
package agentkindboxparam package agentkindboxparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type GetKindBoxRequest struct { type GetKindBoxRequest struct {
KindBoxID uint `param:"id"` KindBoxID uint `param:"id"`
AgentID uint AgentID uint
} }
type GetKindBoxResponse struct { type GetKindBoxResponse struct {
entity.KindBox Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -0,0 +1,22 @@
package agentkindboxreqparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Data struct {
ID uint `json:"id"`
BenefactorID uint `json:"benefactor_id"`
KindBoxType entity.KindBoxType `json:"kind_box_type"`
CountRequested uint `json:"count_requested"`
CountAccepted uint `json:"count_accepted"`
Description string `json:"description"`
Status entity.KindBoxReqStatus `json:"status"`
DeliverReferTimeID uint `json:"deliver_refer_time_id"`
DeliverReferDate time.Time `json:"deliver_refer_date"`
DeliverAddressID uint `json:"deliver_address_id"`
SenderAgentID uint `json:"sender_agent_id"`
DeliveredAt time.Time `json:"delivered_at"`
}

View File

@ -1,4 +1,4 @@
package adminkindboxreqparam package agentkindboxreqparam
type DeliverKindBoxReqRequest struct { type DeliverKindBoxReqRequest struct {
KindBoxReqID uint `json:"-" param:"id"` KindBoxReqID uint `json:"-" param:"id"`

View File

@ -0,0 +1,17 @@
package agentkindboxreqparam
import (
"git.gocasts.ir/ebhomengo/niki/param"
)
type DeliveryAwaitingGetAllRequest struct {
Pagination param.PaginationRequest
Sort param.SortRequest
Filter param.FilterRequest
}
type DeliveryAwaitingGetAllResponse struct {
Data []Data `json:"data"`
Pagination param.PaginationResponse `json:"pagination"`
FieldErrors map[string]string `json:"field_errors,omitempty"`
}

View File

@ -1,6 +1,4 @@
package adminkindboxreqparam package agentkindboxreqparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type DeliveryAwaitingGetRequest struct { type DeliveryAwaitingGetRequest struct {
KindBoxReqID uint `param:"id"` KindBoxReqID uint `param:"id"`
@ -8,6 +6,6 @@ type DeliveryAwaitingGetRequest struct {
} }
type DeliveryAwaitingGetResponse struct { type DeliveryAwaitingGetResponse struct {
entity.KindBoxReq Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

View File

@ -1,7 +1,5 @@
package addressparam package addressparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type BenefactorAddAddressRequest struct { type BenefactorAddAddressRequest struct {
PostalCode string `json:"postal_code" example:"1234567890"` PostalCode string `json:"postal_code" example:"1234567890"`
Address string `json:"address" example:"tehran"` Address string `json:"address" example:"tehran"`
@ -13,6 +11,6 @@ type BenefactorAddAddressRequest struct {
} }
type BenefactorAddAddressResponse struct { type BenefactorAddAddressResponse struct {
Address entity.Address `json:"address"` Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"` FieldErrors map[string]string `json:"field_errors,omitempty"`
} }

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