forked from ebhomengo/niki
1
0
Fork 0

Compare commits

..

4 Commits

Author SHA1 Message Date
mamad bf99fbed6d test(agent-kindbox-e2e): adding e2e test for "/agents/kindboxes" GET api 2024-09-02 22:35:44 +03:30
mamad f3eeb124f9 test(agent-kindbox-e2e): adding e2e test for
"agents/kinboxes/return/:id" api
2024-09-02 18:56:22 +03:30
mamad d0aa6a6fe3 fix(agent-kindbox-e2e): fixing file name
changing "agent_kindbox_get_test" ->
                        "agent_kindbox_test" to cover more tests
2024-09-02 18:12:26 +03:30
mamad 6c82aac02d chore(agent-kindbox-e2e): adding e2e test for get api 2024-09-02 15:28:58 +03:30
228 changed files with 4597 additions and 7432 deletions

1
.gitignore vendored
View File

@ -20,7 +20,6 @@ activate.mise.toml
# Dependency directories (remove the comment below to include it)
.idea
bin
tmp
#.env
*.env

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,37 +0,0 @@
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
// @Summary Register an admin by super-admin
// @Tags Admins
// @Tags Admin
// @Accept json
// @Produce json
// @Param Request body adminserviceparam.RegisterRequest true "Admin Register Request Body"

View File

@ -13,7 +13,6 @@ func (h Handler) SetRoutes(e *echo.Echo) {
//r.POST("/", h.Add).Name = "admin-addkindboxreq"
r.POST("/register", h.Register, middleware.Auth(h.authSvc), middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminAdminRegisterPermission))
r.POST("/login-by-phone", h.LoginByPhoneNumber)
r.POST("/refresh-access", h.RefreshAccess)
//nolint:gocritic
//r.PATCH("/:id", h.Update).Name = "admin-updatekindboxreq"
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,10 +11,13 @@ func (h Handler) SetRoutes(e *echo.Echo) {
r.Use(middleware.Auth(h.authSvc))
r.POST("", h.AddKindBoxReq, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission))
r.PATCH("/:id/accept-kind-box-req", h.Accept, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAcceptPermission))
r.PATCH("/:id/reject-kind-box-req", h.Reject, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqRejectPermission))
r.PATCH("/:id/assign-sender-agent", h.AssignSenderAgent, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAssignSenderAgentPermission))
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("/deliver-kind-box-req/:id", h.Deliver, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqDeliverPermission))
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("/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.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetPermission))
}

View File

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

View File

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

View File

@ -14,7 +14,7 @@ import (
// GetAll godoc
// @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
// @Tags Agents KindBoxes
// @Tags KindBox
// @Accept json
// @Produce json
// @Param filter_id query int false "Filter by ID"

View File

@ -4,25 +4,21 @@ import (
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification"
)
type Handler struct {
authSvc authservice.Service
agentKindBoxSvc agentkindboxservice.Service
adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
}
func New(authSvc authservice.Service,
agentKindBoxSvc agentkindboxservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler {
return Handler{
authSvc: authSvc,
agentKindBoxSvc: agentKindBoxSvc,
adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
}
}

View File

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

View File

@ -1,28 +0,0 @@
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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,36 +0,0 @@
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,9 +5,8 @@ import (
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactors")
r := e.Group("/benefactor")
r.POST("/send-otp", h.SendOtp)
r.POST("/login-register", h.loginOrRegister)
r.POST("/refresh-access", h.RefreshAccess)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,14 +13,14 @@ import (
// Add godoc
// @Summary Add a new kind box request for a benefactor
// @Tags Benefactors KindBoxReqs
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param Request body param.KindBoxReqAddRequest true "New kind box request details"
// @Success 200 {object} param.KindBoxReqAddResponse
// @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor
// @Router /benefactors/kindboxreqs [post].
// @Router /benefactor/kindboxreqs/ [post].
func (h Handler) Add(c echo.Context) error {
req := param.KindBoxReqAddRequest{}
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{
KindBoxReqID: resp.Data.ID,
KindBoxReqID: resp.KindBoxReq.ID,
})
return c.JSON(http.StatusCreated, resp)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,150 @@
//go:build end2end
// +build end2end
package end2end
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"net/http/httptest"
"testing"
"git.gocasts.ir/ebhomengo/niki/delivery/http_server/end2end/setup"
"git.gocasts.ir/ebhomengo/niki/entity"
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
adminParam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
agentParam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)
const (
agentPhoneNumber = "09384664403"
agentPassword = "Abc123456"
agentID uint = 4
)
func TestAgent_KindBox_Get(t *testing.T) {
kindBox := entity.KindBox{
ID: 2,
SerialNumber: "serial-2",
ReceiverAgentID: agentID,
Status: entity.KindBoxAssignedReceiverAgentStatus,
}
url := fmt.Sprintf("/agents/kindboxes/%d", kindBox.ID)
teardown := setup.SeedMariaDB(testContainer.GetMariaDBConfig())
t.Cleanup(teardown)
token, err := getToken()
if err != nil {
t.Fatalf("could not login: %s", err)
}
resRecord := createRequest(http.MethodGet, url, token, nil)
var res agentParam.GetKindBoxResponse
err = json.NewDecoder(resRecord.Body).Decode(&res)
assert.NoError(t, err, "could not decode response body")
assert.Equal(t, http.StatusOK, resRecord.Code)
assert.Equal(t, kindBox.ID, res.ID)
assert.Equal(t, kindBox.ReceiverAgentID, res.ReceiverAgentID)
assert.Equal(t, kindBox.SerialNumber, res.SerialNumber)
assert.Equal(t, kindBox.Status, res.Status)
}
// TODO: we can add more tests for return.
// we can get check if the data is updated in db as expects
// or api should return error if the kindbox is not for this agent
// CHECK: is the flow correct? agent can change kindbox status to return no matter what was the previous status?
func TestAgent_KindBox_Return(t *testing.T) {
kindBoxReqBody := agentParam.ReturnKindBoxRequest{SerialNumber: "new-serial"}
var kindBoxID uint = 2
url := fmt.Sprintf("/agents/kindboxes/return/%d", kindBoxID)
teardown := setup.SeedMariaDB(testContainer.GetMariaDBConfig())
t.Cleanup(teardown)
token, err := getToken()
if err != nil {
t.Fatalf("could not login: %s", err)
}
resRecord := createRequest(http.MethodPatch, url, token, kindBoxReqBody)
updatedKindBox, err := services.AdminKindBoxSvc.Get(
context.Background(),
adminParam.KindBoxGetRequest{KindBoxID: kindBoxID},
)
assert.Equal(t, http.StatusNoContent, resRecord.Code)
assert.Equal(t, kindBoxReqBody.SerialNumber, updatedKindBox.SerialNumber)
assert.Equal(t, agentID, updatedKindBox.ReceiverAgentID)
assert.Equal(t, entity.KindBoxReturnedStatus, updatedKindBox.Status)
}
func getToken() (string, error) {
res, err := services.AdminSvc.LoginWithPhoneNumber(
context.Background(),
adminserviceparam.LoginWithPhoneNumberRequest{
PhoneNumber: agentPhoneNumber,
Password: agentPassword,
},
)
if err != nil {
return "", err
}
return res.Tokens.AccessToken, nil
}
// TODO: if anyone add a new kindbox for this agent, then this test will fail because count will change.
// somehow we should link seed data with test data.
// maybe not use sql seed data and create data in each test
func TestAgent_KindBox_Get_All(t *testing.T) {
kindBoxesCount := 1
url := "/agents/kindboxes"
teardown := setup.SeedMariaDB(testContainer.GetMariaDBConfig())
t.Cleanup(teardown)
token, err := getToken()
if err != nil {
t.Fatalf("could not login: %s", err)
}
resRecord := createRequest(http.MethodGet, url, token, nil)
var res agentParam.GetAllResponse
err = json.NewDecoder(resRecord.Body).Decode(&res)
assert.NoError(t, err, "could not decode response body")
assert.Equal(t, http.StatusOK, resRecord.Code)
assert.Equal(t, kindBoxesCount, len(res.AllKindBoxes))
}
func createRequest(
method string,
url string,
token string,
body any,
) *httptest.ResponseRecorder {
var buf bytes.Buffer
if body != nil {
err := json.NewEncoder(&buf).Encode(body)
if err != nil {
log.Fatalf("could not encode body: %v", err)
}
}
req := httptest.NewRequest(method, url, &buf)
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
req.Header.Set(echo.HeaderAuthorization, fmt.Sprintf("Bearer %s", token))
res := httptest.NewRecorder()
// Serve the request
testServer.Serve(res, req)
return res
}

View File

@ -1,8 +1,10 @@
-- +migrate Up
INSERT INTO `kind_boxes` (`id`, `kind_box_req_id`, `benefactor_id`, `type`, `serial_number`, `status`, `deliver_refer_time_id`, `deliver_refer_date`, `deliver_address_id`, `sender_agent_id`, `delivered_at`)
INSERT INTO `kind_boxes` (`id`, `kind_box_req_id`, `benefactor_id`, `type`, `serial_number`, `status`, `deliver_refer_time_id`, `deliver_refer_date`, `deliver_address_id`, `sender_agent_id`, `receiver_agent_id`, `delivered_at`)
VALUES
-- delivered kindbox for benefactor 1
(1, 1, 1, 'on-table', 'serial-1', 'delivered', 1, NOW() - INTERVAL 7 DAY, 1, 1, NOW());
(1, 1, 1, 'on-table', 'serial-1', 'delivered', 1, NOW() - INTERVAL 7 DAY, 1, 1, NULL, NOW()),
(2, 1, 1, 'on-table', 'serial-2', 'assigned-receiver-agent', 1, NOW() - INTERVAL 7 DAY, 1, 1, 4, NOW());
-- +migrate Down
DELETE FROM `kind_boxes`;
DELETE FROM `kind_boxes`;

View File

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

View File

@ -14,7 +14,7 @@ func Auth(service authservice.Service) echo.MiddlewareFunc {
// TODO - as sign method string to config
SigningMethod: "HS256",
ParseTokenFunc: func(c echo.Context, auth string) (interface{}, error) {
claims, err := service.ParseBearerToken(auth)
claims, err := service.ParseToken(auth)
if err != nil {
return nil, err
}

View File

@ -9,7 +9,7 @@ import (
"github.com/labstack/echo/v4"
)
// nolint
//nolint
func BenefactorAuthorization(role entity.UserRole) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {

View File

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

View File

@ -1,11 +0,0 @@
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

@ -1,15 +0,0 @@
---
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,26 +1,12 @@
version: '3.9'
version: '3.7'
services:
niki_app_stage:
image: niki:${STAGE_NIKI_IMAGE_VERSION?error}
image: niki:${STAGE_NIKI_IMAGE_VERSION}
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
ports:
- "127.0.0.1:8313:1313"
- '127.0.0.1:8198:1313'
networks:
- niki-stage
volumes:

36
deploy/stage/config.yml Normal file
View File

@ -0,0 +1,36 @@
---
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

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

View File

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

View File

@ -1,17 +1,18 @@
version: '3.9'
version: '3.1'
services:
niki_stage_redis:
image: bitnami/redis:6.2
container_name: niki_stage_redis
restart: always
command: redis-server --loglevel warning --protected-mode no
ports:
- '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:
REDIS_PASSWORD: ${COMPOSE_REDIS_PASSWORD?error}
- ALLOW_EMPTY_PASSWORD=yes
networks:
- niki-stage
expose:
- "6379"
- core
volumes:
- niki__stage_redis_data:/data

40
docker-compose.dev.yaml Normal file
View File

@ -0,0 +1,40 @@
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,5 +20,4 @@ const (
AdminKindBoxGetAwaitingReturnPermission = AdminPermission("kindbox-get_awaiting_return")
AdminKindBoxReturnPermission = AdminPermission("kindbox-return")
AdminKindBoxEnumeratePermission = AdminPermission("kindbox-enumerate")
AdminKindBoxUpdatePermission = AdminPermission("kindbox-update")
)

View File

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

View File

@ -1,19 +0,0 @@
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
}

2
go.mod
View File

@ -2,6 +2,8 @@ module git.gocasts.ir/ebhomengo/niki
go 1.23
toolchain go1.23.0
require (
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.3.0

View File

@ -1,15 +0,0 @@
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,12 +1,26 @@
package adminserviceparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type LoginWithPhoneNumberRequest struct {
PhoneNumber string `json:"phone_number" example:"09123456789"`
Password string `json:"password" example:"password123"`
}
type LoginWithPhoneNumberResponse struct {
Data Data `json:"data"`
AdminInfo AdminInfo `json:"admin_info"`
Tokens Tokens `json:"tokens"`
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

@ -1,9 +0,0 @@
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 {
Data Data `json:"data"`
Admin entity.Admin `json:"admin"`
FieldErrors map[string]string `json:"field_errors,omitempty"`
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,22 @@
package adminkindboxreqparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type KindBoxReqAcceptRequest struct {
ID uint `json:"-"`
CountAccepted uint `json:"count_accepted"`
}
type KindBoxReqAcceptResponse struct {
Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"`
KindBoxReqID uint `json:"kind_box_req_id"`
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"`
}

View File

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

View File

@ -1,22 +0,0 @@
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,4 +1,4 @@
package agentkindboxreqparam
package adminkindboxreqparam
type DeliverKindBoxReqRequest struct {
KindBoxReqID uint `json:"-" param:"id"`

View File

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

View File

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

View File

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

View File

@ -1,11 +1,24 @@
package adminkindboxreqparam
import (
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type KindBoxReqRejectRequest struct {
ID uint `json:"-"`
Description string `json:"description" example:"description"`
}
type KindBoxReqRejectResponse struct {
Data Data `json:"data"`
FieldErrors map[string]string `json:"field_errors,omitempty"`
ID uint `json:"id" example:"1"`
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"`
}

View File

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

View File

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

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