forked from ebhomengo/niki
1
0
Fork 0

fix(niki): major refactoring and bug fixes

This commit is contained in:
Erfan Mohammadi 2024-05-17 23:46:28 +03:30
parent 51693db30d
commit 26d44dd7eb
50 changed files with 579 additions and 373 deletions

View File

@ -9,11 +9,11 @@ import (
) )
// LoginByPhoneNumber godoc // LoginByPhoneNumber godoc
// @Summary Login By PhoneNumber admin // @Summary Admin login by PhoneNumber
// @Tags admin // @Tags Admin
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body adminserviceparam.LoginWithPhoneNumberRequest true "Login By PhoneNumber admin" // @Param Request body adminserviceparam.LoginWithPhoneNumberRequest true "Admin login request body"
// @Success 200 {object} adminserviceparam.LoginWithPhoneNumberResponse // @Success 200 {object} adminserviceparam.LoginWithPhoneNumberResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /admins/login-by-phone [post] // @Router /admins/login-by-phone [post]

View File

@ -9,13 +9,14 @@ import (
) )
// Register godoc // Register godoc
// @Summary super-admin register admin // @Summary Register an admin by super-admin
// @Tags admin // @Tags Admin
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body adminserviceparam.RegisterRequest true "super-admin register admin" // @Param Request body adminserviceparam.RegisterRequest true "Admin Register Request Body"
// @Success 200 {object} adminserviceparam.RegisterResponse // @Success 200 {object} adminserviceparam.RegisterResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin
// @Router /admins/register [post] // @Router /admins/register [post]
func (h Handler) Register(c echo.Context) error { func (h Handler) Register(c echo.Context) error {
var req adminserviceparam.RegisterRequest var req adminserviceparam.RegisterRequest

View File

@ -11,16 +11,16 @@ import (
) )
// Accept godoc // Accept godoc
// @Summary admin Accept kindboxreq // @Summary Accept kind box request by admin
// @Tags kindboxreq // @Tags KindBoxReq
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Id" // @Param id path int true "KindBoxReq ID"
// @Param Request body param.KindBoxReqAcceptRequest true "admin Accept kindboxreq" // @Param Request body param.KindBoxReqAcceptRequest true "Accept KindBoxReq Request Body"
// @Success 200 {object} param.KindBoxReqAcceptResponse // @Success 200 {object} param.KindBoxReqAcceptResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /admin/kindboxreqs/accept-kind-box-req/{id} [patch] // @Security AuthBearerAdmin
// @Security AuthBearerAdmin // @Router /admin/kindboxreqs/accept-kind-box-req/{id} [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,16 +11,16 @@ import (
) )
// AssignSenderAgent godoc // AssignSenderAgent godoc
// @Summary admin AssignSenderAgent kindboxreq // @Summary Admin Assign Sender Agent to kindboxreq
// @Tags kindboxreq // @Tags KindBoxReq
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Id" // @Param id path int true "KindBoxReq ID"
// @Param Request body param.AssignSenderRequest true "admin AssignSenderAgent kindboxreq" // @Param Request body param.AssignSenderRequest true "Assign Sender Agent Request Body"
// @Success 200 {object} param.DeliverKindBoxReqResponse // @Success 200 {object} param.AssignSenderResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /admin/kindboxreqs/assign-sender-agent/{id} [patch] // @Security AuthBearerAdmin
// @Security AuthBearerAdmin // @Router /admin/kindboxreqs/assign-sender-agent/{id} [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

@ -11,15 +11,15 @@ import (
) )
// Deliver godoc // Deliver godoc
// @Summary admin Deliver kindboxreq // @Summary Admin deliver a kindboxreq
// @Tags kindboxreq // @Tags KindBoxReq
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Id" // @Param id path int true "KindBoxReq ID"
// @Success 200 {object} param.DeliverKindBoxReqResponse // @Success 200 {object} param.DeliverKindBoxReqResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /admin/kindboxreqs/deliver-kind-box-req/{id} [patch] // @Security AuthBearerAdmin
// @Security AuthBearerAdmin // @Router /admin/kindboxreqs/deliver-kind-box-req/{id} [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

View File

@ -11,16 +11,16 @@ import (
) )
// GetAll godoc // GetAll godoc
// @Summary admin get All kindboxreq // @Summary Admin get all kindboxreq
// @Tags kindboxreq // @Tags KindBoxReq
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param page_number query int false "page_number" // @Param page_number query int false "page_number"
// @Param page_size query int false "page_size" // @Param page_size query int false "page_size"
// @Success 200 {object} param.KindBoxReqGetAllResponse // @Success 200 {object} param.KindBoxReqGetAllResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /admin/kindboxreqs/ [get] // @Security AuthBearerAdmin
// @Security AuthBearerAdmin // @Router /admin/kindboxreqs/ [get]
func (h Handler) GetAll(c echo.Context) error { func (h Handler) GetAll(c echo.Context) error {
var req param.KindBoxReqGetAllRequest var req param.KindBoxReqGetAllRequest
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -11,16 +11,16 @@ import (
) )
// Reject godoc // Reject godoc
// @Summary admin Reject kindboxreq // @Summary Reject a kindboxreq by admin
// @Tags kindboxreq // @Tags KindBoxReq
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Id" // @Param id path int true "KindBoxReq id"
// @Param Request body param.KindBoxReqRejectRequest true "admin Reject kindboxreq" // @Param Request body param.KindBoxReqRejectRequest true "KindBoxReq Reject Request Body"
// @Success 200 {object} param.KindBoxReqRejectResponse // @Success 200 {object} param.KindBoxReqRejectResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /admin/kindboxreqs/reject-kind-box-req/{id} [patch] // @Security AuthBearerAdmin
// @Security AuthBearerAdmin // @Router /admin/kindboxreqs/reject-kind-box-req/{id} [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

@ -10,15 +10,16 @@ import (
) )
// AddAddress godoc // AddAddress godoc
// @Summary Add Address benefactor // @Summary Add a new address for a benefactor
// @Tags address // @Description This endpoint allows an authenticated benefactor to add a new address to their account.
// @Tags Address
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body param.BenefactorAddAddressRequest true "Add Address benefactor" // @Param Request body param.BenefactorAddAddressRequest true "New address details"
// @Success 200 {object} param.BenefactorAddAddressResponse // @Success 201 {object} param.BenefactorAddAddressResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /address/ [post]
// @Security AuthBearerBenefactor // @Security AuthBearerBenefactor
// @Router /address/ [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

@ -9,8 +9,8 @@ import (
) )
// GetAllCities godoc // GetAllCities godoc
// @Summary get all cities // @Summary Get all cities
// @Tags address // @Tags Address
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} addressparam.GetAllCitiesResponse // @Success 200 {object} addressparam.GetAllCitiesResponse

View File

@ -9,8 +9,8 @@ import (
) )
// GetAllProvinces godoc // GetAllProvinces godoc
// @Summary get all provinces // @Summary Get all provinces
// @Tags address // @Tags Address
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} addressparam.GetAllProvincesResponse // @Success 200 {object} addressparam.GetAllProvincesResponse

View File

@ -9,11 +9,12 @@ import (
) )
// loginOrRegister godoc // loginOrRegister godoc
// @Summary login Or Register benefactor // @Summary Login or register a benefactor
// @Tags benefactor // @Description This endpoint is used to authenticate an existing benefactor account or register a new one.
// @Tags Benefactor
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body benefactoreparam.LoginOrRegisterRequest true "login Or Register benefactor" // @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 /benefactor/login-register [post]

View File

@ -9,11 +9,12 @@ import (
) )
// SendOtp godoc // SendOtp godoc
// @Summary send otp benefactor // @Summary Send OTP to benefactor
// @Tags benefactor // @Description This endpoint sends an OTP to the benefactor's phone number for verification purposes.
// @Tags Benefactor
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body benefactoreparam.SendOtpRequest true "send otp benefactor" // @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 /benefactor/send-otp [post]

View File

@ -9,15 +9,16 @@ import (
) )
// Get godoc // Get godoc
// @Summary benefactor get kindbox // @Summary Get a specific kind box for a benefactor
// @Tags kindbox // @Description This endpoint retrieves a specific kind box associated with an authenticated benefactor.
// @Tags KindBox
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "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"
// @Router /benefactor/kindboxes/{id} [get] // @Security AuthBearerBenefactor
// @Security AuthBearerBenefactor // @Router /benefactor/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

@ -9,14 +9,14 @@ import (
) )
// GetAll godoc // GetAll godoc
// @Summary benefactor get All kindbox // @Summary Get all kind boxes for a benefactor
// @Tags kindbox // @Tags KindBox
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} param.KindBoxGetResponse // @Success 200 {object} param.KindBoxGetResponse
// @Failure 400 {string} "Bad request" // @Failure 400 {string} "Bad request"
// @Router /benefactor/kindboxes/ [get] // @Security AuthBearerBenefactor
// @Security AuthBearerBenefactor // @Router /benefactor/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
if bErr := c.Bind(&req); bErr != nil { if bErr := c.Bind(&req); bErr != nil {

View File

@ -1,7 +1,6 @@
package benefactorkindboxreqhandler package benefactorkindboxreqhandler
import ( import (
"fmt"
"net/http" "net/http"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
@ -12,19 +11,18 @@ import (
) )
// Add godoc // Add godoc
// @Summary benefactor Add kindboxreq // @Summary Add a new kind box request for a benefactor
// @Tags kindboxreq // @Tags KindBoxReq
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Request body param.KindBoxReqAddRequest true "benefactor Add kindboxreq" // @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"
// @Router /benefactor/kindboxreqs/ [post] // @Security AuthBearerBenefactor
// @Security AuthBearerBenefactor // @Router /benefactor/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 {
fmt.Println("err", err, req)
return c.JSON(http.StatusBadRequest, echo.Map{ return c.JSON(http.StatusBadRequest, echo.Map{
"message": errmsg.ErrBadRequest, "message": errmsg.ErrBadRequest,

View File

@ -10,15 +10,15 @@ import (
) )
// Get godoc // Get godoc
// @Summary benefactor get kindboxreq // @Summary Get a kind box request for a benefactor
// @Tags kindboxreq // @Tags KindBoxReq
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path int true "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"
// @Router /benefactor/kindboxreqs/{id} [get] // @Security AuthBearerBenefactor
// @Security AuthBearerBenefactor // @Router /benefactor/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

@ -84,10 +84,12 @@ func (s Server) Serve() {
} }
func RegisterSwagger(s *echo.Echo, config config.Config) { func RegisterSwagger(s *echo.Echo, config config.Config) {
docs.SwaggerInfo.Title = "NIKI Api" //TODO: move this to a better place and make it more dynamic and configurable
docs.SwaggerInfo.Description = " This is swagger api documentation for niki project" 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.Version = "1.0.0"
//docs.SwaggerInfo.BasePath = "/api" //docs.SwaggerInfo.BasePath = "/api/v1"
docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%d", config.HTTPServer.Port) docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%d", config.HTTPServer.Port)
s.GET("/swagger/*any", echoSwagger.WrapHandler) s.GET("/swagger/*any", echoSwagger.WrapHandler)
} }

View File

@ -22,6 +22,7 @@ const docTemplate = `{
"AuthBearerBenefactor": [] "AuthBearerBenefactor": []
} }
], ],
"description": "This endpoint allows an authenticated benefactor to add a new address to their account.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -29,12 +30,12 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"address" "Address"
], ],
"summary": "Add Address benefactor", "summary": "Add a new address for a benefactor",
"parameters": [ "parameters": [
{ {
"description": "Add Address benefactor", "description": "New address details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -44,8 +45,8 @@ const docTemplate = `{
} }
], ],
"responses": { "responses": {
"200": { "201": {
"description": "OK", "description": "Created",
"schema": { "schema": {
"$ref": "#/definitions/addressparam.BenefactorAddAddressResponse" "$ref": "#/definitions/addressparam.BenefactorAddAddressResponse"
} }
@ -68,9 +69,9 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"address" "Address"
], ],
"summary": "get all cities", "summary": "Get all cities",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -96,9 +97,9 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"address" "Address"
], ],
"summary": "get all provinces", "summary": "Get all provinces",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -129,9 +130,9 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin get All kindboxreq", "summary": "Admin get all kindboxreq",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
@ -176,19 +177,19 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin Accept kindboxreq", "summary": "Accept kind box request by admin",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
}, },
{ {
"description": "admin Accept kindboxreq", "description": "Accept KindBoxReq Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -227,19 +228,19 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin AssignSenderAgent kindboxreq", "summary": "Admin Assign Sender Agent to kindboxreq",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
}, },
{ {
"description": "admin AssignSenderAgent kindboxreq", "description": "Assign Sender Agent Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -252,7 +253,7 @@ const docTemplate = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminkindboxreqparam.DeliverKindBoxReqResponse" "$ref": "#/definitions/adminkindboxreqparam.AssignSenderResponse"
} }
}, },
"400": { "400": {
@ -278,13 +279,13 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin Deliver kindboxreq", "summary": "Admin deliver a kindboxreq",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@ -320,19 +321,19 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin Reject kindboxreq", "summary": "Reject a kindboxreq by admin",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq id",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
}, },
{ {
"description": "admin Reject kindboxreq", "description": "KindBoxReq Reject Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -366,12 +367,12 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"admin" "Admin"
], ],
"summary": "Login By PhoneNumber admin", "summary": "Admin login by\tPhoneNumber",
"parameters": [ "parameters": [
{ {
"description": "Login By PhoneNumber admin", "description": "Admin login request body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -398,6 +399,11 @@ const docTemplate = `{
}, },
"/admins/register": { "/admins/register": {
"post": { "post": {
"security": [
{
"AuthBearerAdmin": []
}
],
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -405,12 +411,12 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"admin" "Admin"
], ],
"summary": "super-admin register admin", "summary": "Register an admin by super-admin",
"parameters": [ "parameters": [
{ {
"description": "super-admin register admin", "description": "Admin Register Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -449,9 +455,9 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindbox" "KindBox"
], ],
"summary": "benefactor get All kindbox", "summary": "Get all kind boxes for a benefactor",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -475,6 +481,7 @@ const docTemplate = `{
"AuthBearerBenefactor": [] "AuthBearerBenefactor": []
} }
], ],
"description": "This endpoint retrieves a specific kind box associated with an authenticated benefactor.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -482,13 +489,13 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindbox" "KindBox"
], ],
"summary": "benefactor get kindbox", "summary": "Get a specific kind box for a benefactor",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "id", "description": "Kind box ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@ -524,12 +531,12 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "benefactor Add kindboxreq", "summary": "Add a new kind box request for a benefactor",
"parameters": [ "parameters": [
{ {
"description": "benefactor Add kindboxreq", "description": "New kind box request details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -568,13 +575,13 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "benefactor get kindboxreq", "summary": "Get a kind box request for a benefactor",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "Kind box request ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@ -598,6 +605,7 @@ const docTemplate = `{
}, },
"/benefactor/login-register": { "/benefactor/login-register": {
"post": { "post": {
"description": "This endpoint is used to authenticate an existing benefactor account or register a new one.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -605,12 +613,12 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"benefactor" "Benefactor"
], ],
"summary": "login Or Register benefactor", "summary": "Login or register a benefactor",
"parameters": [ "parameters": [
{ {
"description": "login Or Register benefactor", "description": "Login or register request details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -637,6 +645,7 @@ const docTemplate = `{
}, },
"/benefactor/send-otp": { "/benefactor/send-otp": {
"post": { "post": {
"description": "This endpoint sends an OTP to the benefactor's phone number for verification purposes.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -644,12 +653,12 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"benefactor" "Benefactor"
], ],
"summary": "send otp benefactor", "summary": "Send OTP to benefactor",
"parameters": [ "parameters": [
{ {
"description": "send otp benefactor", "description": "Send OTP request details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -750,6 +759,9 @@ const docTemplate = `{
} }
} }
}, },
"adminkindboxreqparam.AssignSenderResponse": {
"type": "object"
},
"adminkindboxreqparam.DeliverKindBoxReqResponse": { "adminkindboxreqparam.DeliverKindBoxReqResponse": {
"type": "object" "type": "object"
}, },
@ -805,10 +817,12 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"description": { "description": {
"type": "string" "type": "string",
"example": "description"
}, },
"id": { "id": {
"type": "integer" "type": "integer",
"example": 1
} }
} }
}, },
@ -816,28 +830,44 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"benefactor_id": { "benefactor_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"count_requested": { "count_requested": {
"type": "integer" "type": "integer",
"example": 1
}, },
"deliver_address_id": { "deliver_address_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"deliver_refer_date": { "deliver_refer_date": {
"type": "string" "type": "string",
"example": "2025-01-02 15:04:05"
}, },
"description": { "description": {
"type": "string" "type": "string",
"example": "description"
}, },
"id": { "id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"kind_box_type": { "kind_box_type": {
"$ref": "#/definitions/entity.KindBoxType" "allOf": [
{
"$ref": "#/definitions/entity.KindBoxType"
}
],
"example": 1
}, },
"status": { "status": {
"$ref": "#/definitions/entity.KindBoxReqStatus" "allOf": [
{
"$ref": "#/definitions/entity.KindBoxReqStatus"
}
],
"example": 1
} }
} }
}, },
@ -845,10 +875,12 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"password": { "password": {
"type": "string" "type": "string",
"example": "password123"
}, },
"phone_number": { "phone_number": {
"type": "string" "type": "string",
"example": "09123456789"
} }
} }
}, },
@ -867,31 +899,52 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"description": { "description": {
"type": "string" "type": "string",
"example": "this is a description"
}, },
"email": { "email": {
"type": "string" "type": "string",
"example": "miaad.66@gmail.com"
}, },
"first_name": { "first_name": {
"type": "string" "type": "string",
"example": "miaad"
}, },
"gender": { "gender": {
"$ref": "#/definitions/entity.Gender" "allOf": [
{
"$ref": "#/definitions/entity.Gender"
}
],
"example": 1
}, },
"last_name": { "last_name": {
"type": "string" "type": "string",
"example": "shahi"
}, },
"password": { "password": {
"type": "string" "type": "string",
"example": "Abc123456"
}, },
"phone_number": { "phone_number": {
"type": "string" "type": "string",
"example": "09183723447"
}, },
"role": { "role": {
"$ref": "#/definitions/entity.AdminRole" "allOf": [
{
"$ref": "#/definitions/entity.AdminRole"
}
],
"example": 2
}, },
"status": { "status": {
"$ref": "#/definitions/entity.AdminStatus" "allOf": [
{
"$ref": "#/definitions/entity.AdminStatus"
}
],
"example": 1
} }
} }
}, },
@ -944,7 +997,7 @@ const docTemplate = `{
}, },
"verification_code": { "verification_code": {
"type": "string", "type": "string",
"example": "123456" "example": "12345"
} }
} }
}, },
@ -1046,19 +1099,28 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"benefactor_id": { "benefactor_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"count_requested": { "count_requested": {
"type": "integer" "type": "integer",
"example": 2
}, },
"deliver_address_id": { "deliver_address_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"deliver_refer_date": { "deliver_refer_date": {
"type": "string" "type": "string",
"example": "2025-01-02 15:04:05"
}, },
"type_id": { "type_id": {
"$ref": "#/definitions/entity.KindBoxType" "allOf": [
{
"$ref": "#/definitions/entity.KindBoxType"
}
],
"example": 1
} }
} }
}, },
@ -1337,13 +1399,15 @@ const docTemplate = `{
}, },
"securityDefinitions": { "securityDefinitions": {
"AuthBearerAdmin": { "AuthBearerAdmin": {
"description": "Type the word 'Bearer' followed by a space and Admin JWT token",
"type": "apiKey", "type": "apiKey",
"name": "Authorization admin", "name": "Authorization",
"in": "header" "in": "header"
}, },
"AuthBearerBenefactor": { "AuthBearerBenefactor": {
"description": "Type the word 'Bearer' followed by a space and Benefactor JWT token",
"type": "apiKey", "type": "apiKey",
"name": "Authorization Benefactor", "name": "Authorization",
"in": "header" "in": "header"
} }
} }

View File

@ -11,6 +11,7 @@
"AuthBearerBenefactor": [] "AuthBearerBenefactor": []
} }
], ],
"description": "This endpoint allows an authenticated benefactor to add a new address to their account.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -18,12 +19,12 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"address" "Address"
], ],
"summary": "Add Address benefactor", "summary": "Add a new address for a benefactor",
"parameters": [ "parameters": [
{ {
"description": "Add Address benefactor", "description": "New address details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -33,8 +34,8 @@
} }
], ],
"responses": { "responses": {
"200": { "201": {
"description": "OK", "description": "Created",
"schema": { "schema": {
"$ref": "#/definitions/addressparam.BenefactorAddAddressResponse" "$ref": "#/definitions/addressparam.BenefactorAddAddressResponse"
} }
@ -57,9 +58,9 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"address" "Address"
], ],
"summary": "get all cities", "summary": "Get all cities",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -85,9 +86,9 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"address" "Address"
], ],
"summary": "get all provinces", "summary": "Get all provinces",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -118,9 +119,9 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin get All kindboxreq", "summary": "Admin get all kindboxreq",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
@ -165,19 +166,19 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin Accept kindboxreq", "summary": "Accept kind box request by admin",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
}, },
{ {
"description": "admin Accept kindboxreq", "description": "Accept KindBoxReq Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -216,19 +217,19 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin AssignSenderAgent kindboxreq", "summary": "Admin Assign Sender Agent to kindboxreq",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
}, },
{ {
"description": "admin AssignSenderAgent kindboxreq", "description": "Assign Sender Agent Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -241,7 +242,7 @@
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminkindboxreqparam.DeliverKindBoxReqResponse" "$ref": "#/definitions/adminkindboxreqparam.AssignSenderResponse"
} }
}, },
"400": { "400": {
@ -267,13 +268,13 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin Deliver kindboxreq", "summary": "Admin deliver a kindboxreq",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@ -309,19 +310,19 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "admin Reject kindboxreq", "summary": "Reject a kindboxreq by admin",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "KindBoxReq id",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
}, },
{ {
"description": "admin Reject kindboxreq", "description": "KindBoxReq Reject Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -355,12 +356,12 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"admin" "Admin"
], ],
"summary": "Login By PhoneNumber admin", "summary": "Admin login by\tPhoneNumber",
"parameters": [ "parameters": [
{ {
"description": "Login By PhoneNumber admin", "description": "Admin login request body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -387,6 +388,11 @@
}, },
"/admins/register": { "/admins/register": {
"post": { "post": {
"security": [
{
"AuthBearerAdmin": []
}
],
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -394,12 +400,12 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"admin" "Admin"
], ],
"summary": "super-admin register admin", "summary": "Register an admin by super-admin",
"parameters": [ "parameters": [
{ {
"description": "super-admin register admin", "description": "Admin Register Request Body",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -438,9 +444,9 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindbox" "KindBox"
], ],
"summary": "benefactor get All kindbox", "summary": "Get all kind boxes for a benefactor",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -464,6 +470,7 @@
"AuthBearerBenefactor": [] "AuthBearerBenefactor": []
} }
], ],
"description": "This endpoint retrieves a specific kind box associated with an authenticated benefactor.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -471,13 +478,13 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindbox" "KindBox"
], ],
"summary": "benefactor get kindbox", "summary": "Get a specific kind box for a benefactor",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "id", "description": "Kind box ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@ -513,12 +520,12 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "benefactor Add kindboxreq", "summary": "Add a new kind box request for a benefactor",
"parameters": [ "parameters": [
{ {
"description": "benefactor Add kindboxreq", "description": "New kind box request details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -557,13 +564,13 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"kindboxreq" "KindBoxReq"
], ],
"summary": "benefactor get kindboxreq", "summary": "Get a kind box request for a benefactor",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
"description": "Id", "description": "Kind box request ID",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
@ -587,6 +594,7 @@
}, },
"/benefactor/login-register": { "/benefactor/login-register": {
"post": { "post": {
"description": "This endpoint is used to authenticate an existing benefactor account or register a new one.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -594,12 +602,12 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"benefactor" "Benefactor"
], ],
"summary": "login Or Register benefactor", "summary": "Login or register a benefactor",
"parameters": [ "parameters": [
{ {
"description": "login Or Register benefactor", "description": "Login or register request details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -626,6 +634,7 @@
}, },
"/benefactor/send-otp": { "/benefactor/send-otp": {
"post": { "post": {
"description": "This endpoint sends an OTP to the benefactor's phone number for verification purposes.",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -633,12 +642,12 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"benefactor" "Benefactor"
], ],
"summary": "send otp benefactor", "summary": "Send OTP to benefactor",
"parameters": [ "parameters": [
{ {
"description": "send otp benefactor", "description": "Send OTP request details",
"name": "Request", "name": "Request",
"in": "body", "in": "body",
"required": true, "required": true,
@ -739,6 +748,9 @@
} }
} }
}, },
"adminkindboxreqparam.AssignSenderResponse": {
"type": "object"
},
"adminkindboxreqparam.DeliverKindBoxReqResponse": { "adminkindboxreqparam.DeliverKindBoxReqResponse": {
"type": "object" "type": "object"
}, },
@ -794,10 +806,12 @@
"type": "object", "type": "object",
"properties": { "properties": {
"description": { "description": {
"type": "string" "type": "string",
"example": "description"
}, },
"id": { "id": {
"type": "integer" "type": "integer",
"example": 1
} }
} }
}, },
@ -805,28 +819,44 @@
"type": "object", "type": "object",
"properties": { "properties": {
"benefactor_id": { "benefactor_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"count_requested": { "count_requested": {
"type": "integer" "type": "integer",
"example": 1
}, },
"deliver_address_id": { "deliver_address_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"deliver_refer_date": { "deliver_refer_date": {
"type": "string" "type": "string",
"example": "2025-01-02 15:04:05"
}, },
"description": { "description": {
"type": "string" "type": "string",
"example": "description"
}, },
"id": { "id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"kind_box_type": { "kind_box_type": {
"$ref": "#/definitions/entity.KindBoxType" "allOf": [
{
"$ref": "#/definitions/entity.KindBoxType"
}
],
"example": 1
}, },
"status": { "status": {
"$ref": "#/definitions/entity.KindBoxReqStatus" "allOf": [
{
"$ref": "#/definitions/entity.KindBoxReqStatus"
}
],
"example": 1
} }
} }
}, },
@ -834,10 +864,12 @@
"type": "object", "type": "object",
"properties": { "properties": {
"password": { "password": {
"type": "string" "type": "string",
"example": "password123"
}, },
"phone_number": { "phone_number": {
"type": "string" "type": "string",
"example": "09123456789"
} }
} }
}, },
@ -856,31 +888,52 @@
"type": "object", "type": "object",
"properties": { "properties": {
"description": { "description": {
"type": "string" "type": "string",
"example": "this is a description"
}, },
"email": { "email": {
"type": "string" "type": "string",
"example": "miaad.66@gmail.com"
}, },
"first_name": { "first_name": {
"type": "string" "type": "string",
"example": "miaad"
}, },
"gender": { "gender": {
"$ref": "#/definitions/entity.Gender" "allOf": [
{
"$ref": "#/definitions/entity.Gender"
}
],
"example": 1
}, },
"last_name": { "last_name": {
"type": "string" "type": "string",
"example": "shahi"
}, },
"password": { "password": {
"type": "string" "type": "string",
"example": "Abc123456"
}, },
"phone_number": { "phone_number": {
"type": "string" "type": "string",
"example": "09183723447"
}, },
"role": { "role": {
"$ref": "#/definitions/entity.AdminRole" "allOf": [
{
"$ref": "#/definitions/entity.AdminRole"
}
],
"example": 2
}, },
"status": { "status": {
"$ref": "#/definitions/entity.AdminStatus" "allOf": [
{
"$ref": "#/definitions/entity.AdminStatus"
}
],
"example": 1
} }
} }
}, },
@ -933,7 +986,7 @@
}, },
"verification_code": { "verification_code": {
"type": "string", "type": "string",
"example": "123456" "example": "12345"
} }
} }
}, },
@ -1035,19 +1088,28 @@
"type": "object", "type": "object",
"properties": { "properties": {
"benefactor_id": { "benefactor_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"count_requested": { "count_requested": {
"type": "integer" "type": "integer",
"example": 2
}, },
"deliver_address_id": { "deliver_address_id": {
"type": "integer" "type": "integer",
"example": 1
}, },
"deliver_refer_date": { "deliver_refer_date": {
"type": "string" "type": "string",
"example": "2025-01-02 15:04:05"
}, },
"type_id": { "type_id": {
"$ref": "#/definitions/entity.KindBoxType" "allOf": [
{
"$ref": "#/definitions/entity.KindBoxType"
}
],
"example": 1
} }
} }
}, },
@ -1326,13 +1388,15 @@
}, },
"securityDefinitions": { "securityDefinitions": {
"AuthBearerAdmin": { "AuthBearerAdmin": {
"description": "Type the word 'Bearer' followed by a space and Admin JWT token",
"type": "apiKey", "type": "apiKey",
"name": "Authorization admin", "name": "Authorization",
"in": "header" "in": "header"
}, },
"AuthBearerBenefactor": { "AuthBearerBenefactor": {
"description": "Type the word 'Bearer' followed by a space and Benefactor JWT token",
"type": "apiKey", "type": "apiKey",
"name": "Authorization Benefactor", "name": "Authorization",
"in": "header" "in": "header"
} }
} }

View File

@ -49,6 +49,8 @@ definitions:
sender_agent_id: sender_agent_id:
type: integer type: integer
type: object type: object
adminkindboxreqparam.AssignSenderResponse:
type: object
adminkindboxreqparam.DeliverKindBoxReqResponse: adminkindboxreqparam.DeliverKindBoxReqResponse:
type: object type: object
adminkindboxreqparam.KindBoxReqAcceptRequest: adminkindboxreqparam.KindBoxReqAcceptRequest:
@ -85,34 +87,48 @@ definitions:
adminkindboxreqparam.KindBoxReqRejectRequest: adminkindboxreqparam.KindBoxReqRejectRequest:
properties: properties:
description: description:
example: description
type: string type: string
id: id:
example: 1
type: integer type: integer
type: object type: object
adminkindboxreqparam.KindBoxReqRejectResponse: adminkindboxreqparam.KindBoxReqRejectResponse:
properties: properties:
benefactor_id: benefactor_id:
example: 1
type: integer type: integer
count_requested: count_requested:
example: 1
type: integer type: integer
deliver_address_id: deliver_address_id:
example: 1
type: integer type: integer
deliver_refer_date: deliver_refer_date:
example: "2025-01-02 15:04:05"
type: string type: string
description: description:
example: description
type: string type: string
id: id:
example: 1
type: integer type: integer
kind_box_type: kind_box_type:
$ref: '#/definitions/entity.KindBoxType' allOf:
- $ref: '#/definitions/entity.KindBoxType'
example: 1
status: status:
$ref: '#/definitions/entity.KindBoxReqStatus' allOf:
- $ref: '#/definitions/entity.KindBoxReqStatus'
example: 1
type: object type: object
adminserviceparam.LoginWithPhoneNumberRequest: adminserviceparam.LoginWithPhoneNumberRequest:
properties: properties:
password: password:
example: password123
type: string type: string
phone_number: phone_number:
example: "09123456789"
type: string type: string
type: object type: object
adminserviceparam.LoginWithPhoneNumberResponse: adminserviceparam.LoginWithPhoneNumberResponse:
@ -125,23 +141,35 @@ definitions:
adminserviceparam.RegisterRequest: adminserviceparam.RegisterRequest:
properties: properties:
description: description:
example: this is a description
type: string type: string
email: email:
example: miaad.66@gmail.com
type: string type: string
first_name: first_name:
example: miaad
type: string type: string
gender: gender:
$ref: '#/definitions/entity.Gender' allOf:
- $ref: '#/definitions/entity.Gender'
example: 1
last_name: last_name:
example: shahi
type: string type: string
password: password:
example: Abc123456
type: string type: string
phone_number: phone_number:
example: "09183723447"
type: string type: string
role: role:
$ref: '#/definitions/entity.AdminRole' allOf:
- $ref: '#/definitions/entity.AdminRole'
example: 2
status: status:
$ref: '#/definitions/entity.AdminStatus' allOf:
- $ref: '#/definitions/entity.AdminStatus'
example: 1
type: object type: object
adminserviceparam.RegisterResponse: adminserviceparam.RegisterResponse:
properties: properties:
@ -176,7 +204,7 @@ definitions:
example: "09198829528" example: "09198829528"
type: string type: string
verification_code: verification_code:
example: "123456" example: "12345"
type: string type: string
type: object type: object
benefactoreparam.LoginOrRegisterResponse: benefactoreparam.LoginOrRegisterResponse:
@ -244,15 +272,21 @@ definitions:
benefactorkindboxreqparam.KindBoxReqAddRequest: benefactorkindboxreqparam.KindBoxReqAddRequest:
properties: properties:
benefactor_id: benefactor_id:
example: 1
type: integer type: integer
count_requested: count_requested:
example: 2
type: integer type: integer
deliver_address_id: deliver_address_id:
example: 1
type: integer type: integer
deliver_refer_date: deliver_refer_date:
example: "2025-01-02 15:04:05"
type: string type: string
type_id: type_id:
$ref: '#/definitions/entity.KindBoxType' allOf:
- $ref: '#/definitions/entity.KindBoxType'
example: 1
type: object type: object
benefactorkindboxreqparam.KindBoxReqAddResponse: benefactorkindboxreqparam.KindBoxReqAddResponse:
properties: properties:
@ -449,8 +483,10 @@ paths:
post: post:
consumes: consumes:
- application/json - application/json
description: This endpoint allows an authenticated benefactor to add a new address
to their account.
parameters: parameters:
- description: Add Address benefactor - description: New address details
in: body in: body
name: Request name: Request
required: true required: true
@ -459,8 +495,8 @@ paths:
produces: produces:
- application/json - application/json
responses: responses:
"200": "201":
description: OK description: Created
schema: schema:
$ref: '#/definitions/addressparam.BenefactorAddAddressResponse' $ref: '#/definitions/addressparam.BenefactorAddAddressResponse'
"400": "400":
@ -469,9 +505,9 @@ paths:
type: string type: string
security: security:
- AuthBearerBenefactor: [] - AuthBearerBenefactor: []
summary: Add Address benefactor summary: Add a new address for a benefactor
tags: tags:
- address - Address
/address/cities: /address/cities:
get: get:
consumes: consumes:
@ -487,9 +523,9 @@ paths:
description: Bad request description: Bad request
schema: schema:
type: string type: string
summary: get all cities summary: Get all cities
tags: tags:
- address - Address
/address/provinces: /address/provinces:
get: get:
consumes: consumes:
@ -505,9 +541,9 @@ paths:
description: Bad request description: Bad request
schema: schema:
type: string type: string
summary: get all provinces summary: Get all provinces
tags: tags:
- address - Address
/admin/kindboxreqs/: /admin/kindboxreqs/:
get: get:
consumes: consumes:
@ -534,20 +570,20 @@ paths:
type: string type: string
security: security:
- AuthBearerAdmin: [] - AuthBearerAdmin: []
summary: admin get All kindboxreq summary: Admin get all kindboxreq
tags: tags:
- kindboxreq - KindBoxReq
/admin/kindboxreqs/accept-kind-box-req/{id}: /admin/kindboxreqs/accept-kind-box-req/{id}:
patch: patch:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: Id - description: KindBoxReq ID
in: path in: path
name: id name: id
required: true required: true
type: integer type: integer
- description: admin Accept kindboxreq - description: Accept KindBoxReq Request Body
in: body in: body
name: Request name: Request
required: true required: true
@ -566,20 +602,20 @@ paths:
type: string type: string
security: security:
- AuthBearerAdmin: [] - AuthBearerAdmin: []
summary: admin Accept kindboxreq summary: Accept kind box request by admin
tags: tags:
- kindboxreq - KindBoxReq
/admin/kindboxreqs/assign-sender-agent/{id}: /admin/kindboxreqs/assign-sender-agent/{id}:
patch: patch:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: Id - description: KindBoxReq ID
in: path in: path
name: id name: id
required: true required: true
type: integer type: integer
- description: admin AssignSenderAgent kindboxreq - description: Assign Sender Agent Request Body
in: body in: body
name: Request name: Request
required: true required: true
@ -591,22 +627,22 @@ paths:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/adminkindboxreqparam.DeliverKindBoxReqResponse' $ref: '#/definitions/adminkindboxreqparam.AssignSenderResponse'
"400": "400":
description: Bad request description: Bad request
schema: schema:
type: string type: string
security: security:
- AuthBearerAdmin: [] - AuthBearerAdmin: []
summary: admin AssignSenderAgent kindboxreq summary: Admin Assign Sender Agent to kindboxreq
tags: tags:
- kindboxreq - KindBoxReq
/admin/kindboxreqs/deliver-kind-box-req/{id}: /admin/kindboxreqs/deliver-kind-box-req/{id}:
patch: patch:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: Id - description: KindBoxReq ID
in: path in: path
name: id name: id
required: true required: true
@ -624,20 +660,20 @@ paths:
type: string type: string
security: security:
- AuthBearerAdmin: [] - AuthBearerAdmin: []
summary: admin Deliver kindboxreq summary: Admin deliver a kindboxreq
tags: tags:
- kindboxreq - KindBoxReq
/admin/kindboxreqs/reject-kind-box-req/{id}: /admin/kindboxreqs/reject-kind-box-req/{id}:
patch: patch:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: Id - description: KindBoxReq id
in: path in: path
name: id name: id
required: true required: true
type: integer type: integer
- description: admin Reject kindboxreq - description: KindBoxReq Reject Request Body
in: body in: body
name: Request name: Request
required: true required: true
@ -656,15 +692,15 @@ paths:
type: string type: string
security: security:
- AuthBearerAdmin: [] - AuthBearerAdmin: []
summary: admin Reject kindboxreq summary: Reject a kindboxreq by admin
tags: tags:
- kindboxreq - KindBoxReq
/admins/login-by-phone: /admins/login-by-phone:
post: post:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: Login By PhoneNumber admin - description: Admin login request body
in: body in: body
name: Request name: Request
required: true required: true
@ -681,15 +717,15 @@ paths:
description: Bad request description: Bad request
schema: schema:
type: string type: string
summary: Login By PhoneNumber admin summary: "Admin login by\tPhoneNumber"
tags: tags:
- admin - Admin
/admins/register: /admins/register:
post: post:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: super-admin register admin - description: Admin Register Request Body
in: body in: body
name: Request name: Request
required: true required: true
@ -706,9 +742,11 @@ paths:
description: Bad request description: Bad request
schema: schema:
type: string type: string
summary: super-admin register admin security:
- AuthBearerAdmin: []
summary: Register an admin by super-admin
tags: tags:
- admin - Admin
/benefactor/kindboxes/: /benefactor/kindboxes/:
get: get:
consumes: consumes:
@ -726,15 +764,17 @@ paths:
type: string type: string
security: security:
- AuthBearerBenefactor: [] - AuthBearerBenefactor: []
summary: benefactor get All kindbox summary: Get all kind boxes for a benefactor
tags: tags:
- kindbox - KindBox
/benefactor/kindboxes/{id}: /benefactor/kindboxes/{id}:
get: get:
consumes: consumes:
- application/json - application/json
description: This endpoint retrieves a specific kind box associated with an
authenticated benefactor.
parameters: parameters:
- description: id - description: Kind box ID
in: path in: path
name: id name: id
required: true required: true
@ -752,15 +792,15 @@ paths:
type: string type: string
security: security:
- AuthBearerBenefactor: [] - AuthBearerBenefactor: []
summary: benefactor get kindbox summary: Get a specific kind box for a benefactor
tags: tags:
- kindbox - KindBox
/benefactor/kindboxreqs/: /benefactor/kindboxreqs/:
post: post:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: benefactor Add kindboxreq - description: New kind box request details
in: body in: body
name: Request name: Request
required: true required: true
@ -779,15 +819,15 @@ paths:
type: string type: string
security: security:
- AuthBearerBenefactor: [] - AuthBearerBenefactor: []
summary: benefactor Add kindboxreq summary: Add a new kind box request for a benefactor
tags: tags:
- kindboxreq - KindBoxReq
/benefactor/kindboxreqs/{id}: /benefactor/kindboxreqs/{id}:
get: get:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: Id - description: Kind box request ID
in: path in: path
name: id name: id
required: true required: true
@ -805,15 +845,17 @@ paths:
type: string type: string
security: security:
- AuthBearerBenefactor: [] - AuthBearerBenefactor: []
summary: benefactor get kindboxreq summary: Get a kind box request for a benefactor
tags: tags:
- kindboxreq - KindBoxReq
/benefactor/login-register: /benefactor/login-register:
post: post:
consumes: consumes:
- application/json - application/json
description: This endpoint is used to authenticate an existing benefactor account
or register a new one.
parameters: parameters:
- description: login Or Register benefactor - description: Login or register request details
in: body in: body
name: Request name: Request
required: true required: true
@ -830,15 +872,17 @@ paths:
description: Bad request description: Bad request
schema: schema:
type: string type: string
summary: login Or Register benefactor summary: Login or register a benefactor
tags: tags:
- benefactor - Benefactor
/benefactor/send-otp: /benefactor/send-otp:
post: post:
consumes: consumes:
- application/json - application/json
description: This endpoint sends an OTP to the benefactor's phone number for
verification purposes.
parameters: parameters:
- description: send otp benefactor - description: Send OTP request details
in: body in: body
name: Request name: Request
required: true required: true
@ -855,16 +899,18 @@ paths:
description: Bad request description: Bad request
schema: schema:
type: string type: string
summary: send otp benefactor summary: Send OTP to benefactor
tags: tags:
- benefactor - Benefactor
securityDefinitions: securityDefinitions:
AuthBearerAdmin: AuthBearerAdmin:
description: Type the word 'Bearer' followed by a space and Admin JWT token
in: header in: header
name: Authorization admin name: Authorization
type: apiKey type: apiKey
AuthBearerBenefactor: AuthBearerBenefactor:
description: Type the word 'Bearer' followed by a space and Benefactor JWT token
in: header in: header
name: Authorization Benefactor name: Authorization
type: apiKey type: apiKey
swagger: "2.0" swagger: "2.0"

View File

@ -58,5 +58,5 @@ func InitAdminKindBoxService(db *mysql.DB) adminkindboxservice.Service {
} }
func InitAdminKindBoxReqService(db *mysql.DB) adminkindboxreqservice.Service { func InitAdminKindBoxReqService(db *mysql.DB) adminkindboxreqservice.Service {
return adminkindboxreqservice.New(InitBenefactorKindBoxReqDB(db)) return adminkindboxreqservice.New(InitBenefactorKindBoxReqDB(db), InitAdminKindBoxService(db))
} }

View File

@ -19,8 +19,8 @@ type Validators struct {
AdminVld adminvalidator.Validator AdminVld adminvalidator.Validator
} }
func InitAdminKindBoxReqValidator(db *mysql.DB) adminkindboxreqvalidator.Validator { func InitAdminKindBoxReqValidator(db *mysql.DB, cfg config.Config) adminkindboxreqvalidator.Validator {
return adminkindboxreqvalidator.New(InitBenefactorKindBoxReqDB(db)) return adminkindboxreqvalidator.New(InitBenefactorKindBoxReqDB(db), InitAdminService(cfg, db))
} }
func InitAdminValidator(db *mysql.DB) adminvalidator.Validator { func InitAdminValidator(db *mysql.DB) adminvalidator.Validator {

View File

@ -28,10 +28,12 @@ func parseFlags() bool {
// @securityDefinitions.apikey AuthBearerBenefactor // @securityDefinitions.apikey AuthBearerBenefactor
// @in header // @in header
// @name Authorization Benefactor // @name Authorization
// @description Type the word 'Bearer' followed by a space and Benefactor JWT token
// @securityDefinitions.apikey AuthBearerAdmin // @securityDefinitions.apikey AuthBearerAdmin
// @in header // @in header
// @name Authorization admin // @name Authorization
// @description Type the word 'Bearer' followed by a space and Admin JWT token
func main() { func main() {
migrate := parseFlags() migrate := parseFlags()
@ -60,7 +62,7 @@ func initDependencies(cfg config.Config, redisAdapter redis.Adapter, db *mysql.D
BenefactorVld: initial.InitBenefactorValidator(), BenefactorVld: initial.InitBenefactorValidator(),
BenefactorKindBoxReqVld: initial.InitBenefactorKindBoxReqValidator(cfg, redisAdapter, db), BenefactorKindBoxReqVld: initial.InitBenefactorKindBoxReqValidator(cfg, redisAdapter, db),
BenefactorAddressVld: initial.InitBenefactorAddressValidator(cfg, redisAdapter, db), BenefactorAddressVld: initial.InitBenefactorAddressValidator(cfg, redisAdapter, db),
AdminKindBoxReqVld: initial.InitAdminKindBoxReqValidator(db), AdminKindBoxReqVld: initial.InitAdminKindBoxReqValidator(db, cfg),
AdminVld: initial.InitAdminValidator(db), AdminVld: initial.InitAdminValidator(db),
}, },
initial.Services{ initial.Services{

View File

@ -3,8 +3,8 @@ package adminserviceparam
import "git.gocasts.ir/ebhomengo/niki/entity" import "git.gocasts.ir/ebhomengo/niki/entity"
type LoginWithPhoneNumberRequest struct { type LoginWithPhoneNumberRequest struct {
PhoneNumber string `json:"phone_number"` PhoneNumber string `json:"phone_number" example:"09123456789"`
Password string `json:"password"` Password string `json:"password" example:"password123"`
} }
type LoginWithPhoneNumberResponse struct { type LoginWithPhoneNumberResponse struct {

View File

@ -3,15 +3,15 @@ package adminserviceparam
import "git.gocasts.ir/ebhomengo/niki/entity" import "git.gocasts.ir/ebhomengo/niki/entity"
type RegisterRequest struct { type RegisterRequest struct {
FirstName *string `json:"first_name"` FirstName *string `json:"first_name" example:"miaad"`
LastName *string `json:"last_name"` LastName *string `json:"last_name" example:"shahi"`
Password *string `json:"password"` Password *string `json:"password" example:"Abc123456"`
PhoneNumber *string `json:"phone_number"` PhoneNumber *string `json:"phone_number" example:"09183723447"`
Role *entity.AdminRole `json:"role"` Role *entity.AdminRole `json:"role" example:"2"`
Description *string `json:"description"` Description *string `json:"description" example:"this is a description"`
Email *string `json:"email"` Email *string `json:"email" example:"miaad.66@gmail.com"`
Gender *entity.Gender `json:"gender"` Gender *entity.Gender `json:"gender" example:"1"`
Status *entity.AdminStatus `json:"status"` Status *entity.AdminStatus `json:"status" example:"1"`
} }
type RegisterResponse struct { type RegisterResponse struct {

View File

@ -7,17 +7,17 @@ import (
) )
type KindBoxReqRejectRequest struct { type KindBoxReqRejectRequest struct {
ID uint `json:"id"` ID uint `json:"id" example:"1"`
Description string `json:"description"` Description string `json:"description" example:"description"`
} }
type KindBoxReqRejectResponse struct { type KindBoxReqRejectResponse struct {
ID uint `json:"id"` ID uint `json:"id" example:"1"`
KindBoxType entity.KindBoxType `json:"kind_box_type"` KindBoxType entity.KindBoxType `json:"kind_box_type" example:"1"`
CountRequested uint `json:"count_requested"` CountRequested uint `json:"count_requested" example:"1"`
BenefactorID uint `json:"benefactor_id"` BenefactorID uint `json:"benefactor_id" example:"1"`
Status entity.KindBoxReqStatus `json:"status"` Status entity.KindBoxReqStatus `json:"status" example:"1"`
Description string `json:"description"` Description string `json:"description" example:"description"`
DeliverReferDate time.Time `json:"deliver_refer_date"` DeliverReferDate time.Time `json:"deliver_refer_date" example:"2025-01-02 15:04:05"`
DeliverAddressID uint `json:"deliver_address_id"` DeliverAddressID uint `json:"deliver_address_id" example:"1"`
} }

View File

@ -2,7 +2,7 @@ package benefactoreparam
type LoginOrRegisterRequest struct { type LoginOrRegisterRequest struct {
PhoneNumber string `json:"phone_number" example:"09198829528"` PhoneNumber string `json:"phone_number" example:"09198829528"`
VerificationCode string `json:"verification_code" example:"123456"` VerificationCode string `json:"verification_code" example:"12345"`
} }
type LoginOrRegisterResponse struct { type LoginOrRegisterResponse struct {

View File

@ -5,11 +5,11 @@ import (
) )
type KindBoxReqAddRequest struct { type KindBoxReqAddRequest struct {
BenefactorID uint `json:"benefactor_id"` BenefactorID uint `json:"benefactor_id" example:"1"`
TypeID entity.KindBoxType `json:"type_id"` TypeID entity.KindBoxType `json:"type_id" example:"1"`
DeliverAddressID uint `json:"deliver_address_id"` DeliverAddressID uint `json:"deliver_address_id" example:"1"`
DeliverReferDate string `json:"deliver_refer_date"` DeliverReferDate string `json:"deliver_refer_date" example:"2025-01-02 15:04:05"`
CountRequested uint `json:"count_requested"` CountRequested uint `json:"count_requested" example:"2"`
} }
type KindBoxReqAddResponse struct { type KindBoxReqAddResponse struct {

View File

@ -42,10 +42,10 @@ func (d *DB) GetAllCities(ctx context.Context) ([]entity.City, error) {
} }
func scanCity(scanner mysql.Scanner) (entity.City, error) { func scanCity(scanner mysql.Scanner) (entity.City, error) {
var createdAt time.Time var createdAt, updatedAt time.Time
var city entity.City var city entity.City
err := scanner.Scan(&city.ID, &city.Name, &city.ProvinceID, &createdAt) err := scanner.Scan(&city.ID, &city.Name, &city.ProvinceID, &createdAt, &updatedAt)
return city, err return city, err
} }

View File

@ -42,10 +42,10 @@ func (d *DB) GetAllProvinces(ctx context.Context) ([]entity.Province, error) {
} }
func scanProvince(scanner mysql.Scanner) (entity.Province, error) { func scanProvince(scanner mysql.Scanner) (entity.Province, error) {
var createdAt time.Time var createdAt, updatedAt time.Time
var province entity.Province var province entity.Province
err := scanner.Scan(&province.ID, &province.Name, &createdAt) err := scanner.Scan(&province.ID, &province.Name, &createdAt, &updatedAt)
return province, err return province, err
} }

View File

@ -89,10 +89,11 @@ func (d *DB) GetAdminPermissions(adminID uint, role entity.AdminRole) ([]entity.
func scanAccessControl(scanner mysql.Scanner) (entity.AdminAccessControl, error) { func scanAccessControl(scanner mysql.Scanner) (entity.AdminAccessControl, error) {
var ( var (
createdAt time.Time createdAt time.Time
updateAt time.Time
acl entity.AdminAccessControl acl entity.AdminAccessControl
) )
err := scanner.Scan(&acl.ID, &acl.ActorID, &acl.ActorType, &acl.Permission, &createdAt) err := scanner.Scan(&acl.ID, &acl.ActorID, &acl.ActorType, &acl.Permission, &createdAt, &updateAt)
return acl, err return acl, err
} }

View File

@ -2,7 +2,6 @@ package mysqladmin
import ( import (
"context" "context"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"

View File

@ -36,7 +36,7 @@ func (d DB) GetAdminByPhoneNumber(ctx context.Context, phoneNumber string) (enti
} }
func scanAdmin(scanner mysql.Scanner) (entity.Admin, error) { func scanAdmin(scanner mysql.Scanner) (entity.Admin, error) {
var createdAt time.Time var createdAt, updatedAt time.Time
var admin entity.Admin var admin entity.Admin
var roleStr, statusStr, password string var roleStr, statusStr, password string
// TODO - use db model and mapper between entity and db model OR use this approach // TODO - use db model and mapper between entity and db model OR use this approach
@ -47,7 +47,7 @@ func scanAdmin(scanner mysql.Scanner) (entity.Admin, error) {
&adminNullableFields.lastName, &password, &admin.PhoneNumber, &adminNullableFields.lastName, &password, &admin.PhoneNumber,
&roleStr, &adminNullableFields.description, &roleStr, &adminNullableFields.description,
&adminNullableFields.email, &adminNullableFields.genderStr, &adminNullableFields.email, &adminNullableFields.genderStr,
&statusStr, &createdAt) &statusStr, &createdAt, &updatedAt)
admin.Role = entity.MapToAdminRole(roleStr) admin.Role = entity.MapToAdminRole(roleStr)
admin.Status = entity.MapToAdminStatus(statusStr) admin.Status = entity.MapToAdminStatus(statusStr)

View File

@ -2,8 +2,6 @@ package mysqlkindboxreq
import ( import (
"context" "context"
"time"
entity "git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -12,8 +10,8 @@ import (
func (d DB) AssignSenderAgentToKindBoxReq(ctx context.Context, kindBoxReqID, senderAgentID uint) error { func (d DB) AssignSenderAgentToKindBoxReq(ctx context.Context, kindBoxReqID, senderAgentID uint) error {
const op = "mysqlkindboxreq.AssignSenderAgentToKindBoxReq" const op = "mysqlkindboxreq.AssignSenderAgentToKindBoxReq"
_, err := d.conn.Conn().ExecContext(ctx, `update kind_box_reqs set sender_agent_id = ?, status = ?, updated_at= ? where id = ?`, _, err := d.conn.Conn().ExecContext(ctx, `update kind_box_reqs set sender_agent_id = ?, status = ? where id = ?`,
senderAgentID, entity.KindBoxReqAssignedSenderAgentStatus.String(), time.Now(), kindBoxReqID) senderAgentID, entity.KindBoxReqAssignedSenderAgentStatus.String(), kindBoxReqID)
if err != nil { if err != nil {
return richerror.New(op).WithErr(err). return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)

View File

@ -12,8 +12,8 @@ import (
func (d DB) DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error { func (d DB) DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error {
const op = "mysqlkindboxreq.DeliverKindBoxReq" const op = "mysqlkindboxreq.DeliverKindBoxReq"
_, err := d.conn.Conn().ExecContext(ctx, `update kind_box_reqs set status = ?, delivered_at = ?, updated_at = ?, where id = ?`, _, err := d.conn.Conn().ExecContext(ctx, `update kind_box_reqs set status = ?, delivered_at = ? where id = ?`,
entity.KindBoxReqDeliveredStatus.String(), time.Now(), time.Now(), kindBoxReqID) entity.KindBoxReqDeliveredStatus.String(), time.Now(), kindBoxReqID)
if err != nil { if err != nil {
return richerror.New(op).WithErr(err). return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -13,7 +12,7 @@ import (
func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) { func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) {
const op = "mysqlkindboxreq.AddKindBoxReq" const op = "mysqlkindboxreq.AddKindBoxReq"
res, err := d.conn.Conn().ExecContext(ctx, `insert into kind_box_reqs(benefactor_id,kind_box_type,address_id,count_requested,refer_date,status) values (?,?,?,?,?,?)`, res, err := d.conn.Conn().ExecContext(ctx, `insert into kind_box_reqs(benefactor_id,kind_box_type,deliver_address_id,count_requested,deliver_refer_date,status) values (?,?,?,?,?,?)`,
kindBoxReq.BenefactorID, kindBoxReq.KindBoxType.String(), kindBoxReq.DeliverAddressID, kindBoxReq.CountRequested, kindBoxReq.DeliverReferDate, kindBoxReq.Status.String()) kindBoxReq.BenefactorID, kindBoxReq.KindBoxType.String(), kindBoxReq.DeliverAddressID, kindBoxReq.CountRequested, kindBoxReq.DeliverReferDate, kindBoxReq.Status.String())
if err != nil { if err != nil {
return entity.KindBoxReq{}, richerror.New(op).WithErr(err). return entity.KindBoxReq{}, richerror.New(op).WithErr(err).

View File

@ -2,6 +2,7 @@ package mysqlkindboxreq
import ( import (
"database/sql" "database/sql"
"time"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/repository/mysql" "git.gocasts.ir/ebhomengo/niki/repository/mysql"
@ -9,22 +10,50 @@ import (
func scanKindBoxReq(scanner mysql.Scanner) (entity.KindBoxReq, error) { func scanKindBoxReq(scanner mysql.Scanner) (entity.KindBoxReq, error) {
var kindBoxReq entity.KindBoxReq var kindBoxReq entity.KindBoxReq
var kindBoxStatus string var (
var kindBoxType string kindBoxType string
var countAccept sql.NullInt64 countAccepted sql.NullInt64
var desc sql.NullString description sql.NullString
err := scanner.Scan(&kindBoxReq.ID, &kindBoxReq.BenefactorID, &kindBoxType, &kindBoxReq.DeliverAddressID, &kindBoxReq.CountRequested, &countAccept, status string
&desc, senderAgentID sql.NullInt64
&kindBoxReq.DeliverReferDate, &kindBoxStatus) deliveredAt sql.NullTime
createdAt time.Time
updatedAt time.Time
)
if countAccept.Valid { err := scanner.Scan(
kindBoxReq.CountAccepted = uint(countAccept.Int64) &kindBoxReq.ID,
&kindBoxReq.BenefactorID,
&kindBoxType,
&kindBoxReq.CountRequested,
&countAccepted,
&description,
&status,
&kindBoxReq.DeliverReferDate,
&kindBoxReq.DeliverAddressID,
&senderAgentID,
&deliveredAt,
&createdAt,
&updatedAt,
)
if err != nil {
return entity.KindBoxReq{}, err
} }
if desc.Valid {
kindBoxReq.Description = desc.String
}
kindBoxReq.Status = entity.MapToKindBoxReqStatus(kindBoxStatus)
kindBoxReq.KindBoxType = entity.MapToKindBoxType(kindBoxType) kindBoxReq.KindBoxType = entity.MapToKindBoxType(kindBoxType)
if countAccepted.Valid {
kindBoxReq.CountAccepted = uint(countAccepted.Int64)
}
if description.Valid {
kindBoxReq.Description = description.String
}
kindBoxReq.Status = entity.MapToKindBoxReqStatus(status)
if senderAgentID.Valid {
kindBoxReq.SenderAgentID = uint(senderAgentID.Int64)
}
if deliveredAt.Valid {
kindBoxReq.DeliveredAt = deliveredAt.Time
}
return kindBoxReq, err return kindBoxReq, nil
} }

View File

@ -12,7 +12,7 @@ CREATE TABLE `benefactors` (
`birth_date` TIMESTAMP, `birth_date` TIMESTAMP,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
); );

View File

@ -12,7 +12,7 @@ CREATE TABLE `admins` (
`status` ENUM('active','inactive') NOT NULL DEFAULT 'active', `status` ENUM('active','inactive') NOT NULL DEFAULT 'active',
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
); );
-- +migrate Down -- +migrate Down

View File

@ -6,7 +6,7 @@ CREATE TABLE `admin_access_controls` (
`permission` ENUM('') NOT NULL, `permission` ENUM('') NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
); );
-- +migrate Down -- +migrate Down

View File

@ -4,7 +4,7 @@ CREATE TABLE `provinces` (
`name` VARCHAR(191) NOT NULL, `name` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
); );
-- +migrate Down -- +migrate Down

View File

@ -5,7 +5,7 @@ CREATE TABLE `cities` (
`province_id` INT NOT NULL, `province_id` INT NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (`province_id`) REFERENCES `provinces`(`id`) FOREIGN KEY (`province_id`) REFERENCES `provinces`(`id`)
); );

View File

@ -11,7 +11,7 @@ CREATE TABLE `addresses` (
`benefactor_id` INT NOT NULL, `benefactor_id` INT NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`), FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`), FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`) FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`)

View File

@ -13,7 +13,7 @@ CREATE TABLE `kind_box_reqs` (
`delivered_at` DATETIME, `delivered_at` DATETIME,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`), FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`),
FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`), FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`sender_agent_id`) REFERENCES `admins` (`id`) FOREIGN KEY (`sender_agent_id`) REFERENCES `admins` (`id`)

View File

@ -17,6 +17,7 @@ CREATE TABLE `kind_boxes` (
`returned_at` DATETIME, `returned_at` DATETIME,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (`kind_box_req_id`) REFERENCES `kind_box_reqs` (`id`), FOREIGN KEY (`kind_box_req_id`) REFERENCES `kind_box_reqs` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`), FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`),
FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`), FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`),

View File

@ -2,7 +2,7 @@
-- what can we do for password? -- what can we do for password?
INSERT INTO `admins` (`id`, `phone_number`, `email`,`password`,`role`,`status`) INSERT INTO `admins` (`id`, `phone_number`, `email`,`password`,`role`,`status`)
VALUES VALUES
(1, '09122702856', 'keshvari@gmail.com','Abc123456','super-admin','active'); (1, '09122702856', 'keshvari@gmail.com','$2a$10$qVjYHVYolxXTeTYD2pwzHukbffR/heH8m9QdAsP92U7Moi2Pub1hm','super-admin','active');
-- +migrate Down -- +migrate Down
DELETE DELETE

View File

@ -25,7 +25,7 @@ func (s Service) Register(ctx context.Context, req adminserviceparam.RegisterReq
newAdmin.Role = *req.Role newAdmin.Role = *req.Role
} }
if req.Description != nil { if req.Description != nil {
newAdmin.LastName = *req.Description newAdmin.Description = *req.Description
} }
if req.Email != nil { if req.Email != nil {
newAdmin.Email = *req.Email newAdmin.Email = *req.Email
@ -33,10 +33,7 @@ func (s Service) Register(ctx context.Context, req adminserviceparam.RegisterReq
if req.Gender != nil { if req.Gender != nil {
newAdmin.Gender = *req.Gender newAdmin.Gender = *req.Gender
} }
if req.Description != nil { if req.Status != nil {
newAdmin.LastName = *req.Description
}
if req.Email != nil {
newAdmin.Status = *req.Status newAdmin.Status = *req.Status
} }

View File

@ -27,8 +27,9 @@ type Service struct {
kindBoxSvc KindBoxSvc kindBoxSvc KindBoxSvc
} }
func New(repository Repository) Service { func New(repository Repository, kindBoxSvc KindBoxSvc) Service {
return Service{ return Service{
repo: repository, repo: repository,
kindBoxSvc: kindBoxSvc,
} }
} }

View File

@ -72,7 +72,7 @@ func (v Validator) doesAdminExistByEmail(value interface{}) error {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
} }
if adminExisted { if adminExisted {
return fmt.Errorf(errmsg.ErrorMsgPhoneNumberIsNotUnique) return fmt.Errorf(errmsg.ErrorMsgEmailIsNotUnique)
} }
return nil return nil

View File

@ -29,8 +29,8 @@ type Validator struct {
adminSvc AdminSvc adminSvc AdminSvc
} }
func New(repo Repository) Validator { func New(repo Repository, adminSvc AdminSvc) Validator {
return Validator{repo: repo} return Validator{repo: repo, adminSvc: adminSvc}
} }
func (v Validator) doesKindBoxRequestExist(value interface{}) error { func (v Validator) doesKindBoxRequestExist(value interface{}) error {