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
// @Summary Login By PhoneNumber admin
// @Tags admin
// @Summary Admin login by PhoneNumber
// @Tags Admin
// @Accept 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
// @Failure 400 {string} "Bad request"
// @Router /admins/login-by-phone [post]

View File

@ -9,13 +9,14 @@ import (
)
// Register godoc
// @Summary super-admin register admin
// @Tags admin
// @Summary Register an admin by super-admin
// @Tags Admin
// @Accept 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
// @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin
// @Router /admins/register [post]
func (h Handler) Register(c echo.Context) error {
var req adminserviceparam.RegisterRequest

View File

@ -11,16 +11,16 @@ import (
)
// Accept godoc
// @Summary admin Accept kindboxreq
// @Tags kindboxreq
// @Summary Accept kind box request by admin
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param id path int true "Id"
// @Param Request body param.KindBoxReqAcceptRequest true "admin Accept kindboxreq"
// @Param id path int true "KindBoxReq ID"
// @Param Request body param.KindBoxReqAcceptRequest true "Accept KindBoxReq Request Body"
// @Success 200 {object} param.KindBoxReqAcceptResponse
// @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 {
var req param.KindBoxReqAcceptRequest
if bErr := c.Bind(&req); bErr != nil {

View File

@ -11,16 +11,16 @@ import (
)
// AssignSenderAgent godoc
// @Summary admin AssignSenderAgent kindboxreq
// @Tags kindboxreq
// @Summary Admin Assign Sender Agent to kindboxreq
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param id path int true "Id"
// @Param Request body param.AssignSenderRequest true "admin AssignSenderAgent kindboxreq"
// @Success 200 {object} param.DeliverKindBoxReqResponse
// @Param id path int true "KindBoxReq ID"
// @Param Request body param.AssignSenderRequest true "Assign Sender Agent Request Body"
// @Success 200 {object} param.AssignSenderResponse
// @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 {
var req param.AssignSenderRequest

View File

@ -11,15 +11,15 @@ import (
)
// Deliver godoc
// @Summary admin Deliver kindboxreq
// @Tags kindboxreq
// @Summary Admin deliver a kindboxreq
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param id path int true "Id"
// @Param id path int true "KindBoxReq ID"
// @Success 200 {object} param.DeliverKindBoxReqResponse
// @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 {
var req param.DeliverKindBoxReqRequest

View File

@ -11,16 +11,16 @@ import (
)
// GetAll godoc
// @Summary admin get All kindboxreq
// @Tags kindboxreq
// @Summary Admin get all kindboxreq
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param page_number query int false "page_number"
// @Param page_size query int false "page_size"
// @Param page_number query int false "page_number"
// @Param page_size query int false "page_size"
// @Success 200 {object} param.KindBoxReqGetAllResponse
// @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 {
var req param.KindBoxReqGetAllRequest
if bErr := c.Bind(&req); bErr != nil {

View File

@ -11,16 +11,16 @@ import (
)
// Reject godoc
// @Summary admin Reject kindboxreq
// @Tags kindboxreq
// @Summary Reject a kindboxreq by admin
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param id path int true "Id"
// @Param Request body param.KindBoxReqRejectRequest true "admin Reject kindboxreq"
// @Param id path int true "KindBoxReq id"
// @Param Request body param.KindBoxReqRejectRequest true "KindBoxReq Reject Request Body"
// @Success 200 {object} param.KindBoxReqRejectResponse
// @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 {
var req param.KindBoxReqRejectRequest
if bErr := c.Bind(&req); bErr != nil {

View File

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

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

View File

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

View File

@ -9,11 +9,12 @@ import (
)
// loginOrRegister godoc
// @Summary login Or Register benefactor
// @Tags benefactor
// @Summary Login or register a benefactor
// @Description This endpoint is used to authenticate an existing benefactor account or register a new one.
// @Tags Benefactor
// @Accept 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
// @Failure 400 {string} "Bad request"
// @Router /benefactor/login-register [post]

View File

@ -9,11 +9,12 @@ import (
)
// SendOtp godoc
// @Summary send otp benefactor
// @Tags benefactor
// @Summary Send OTP to benefactor
// @Description This endpoint sends an OTP to the benefactor's phone number for verification purposes.
// @Tags Benefactor
// @Accept 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
// @Failure 400 {string} "Bad request"
// @Router /benefactor/send-otp [post]

View File

@ -9,15 +9,16 @@ import (
)
// Get godoc
// @Summary benefactor get kindbox
// @Tags kindbox
// @Summary Get a specific kind box for a benefactor
// @Description This endpoint retrieves a specific kind box associated with an authenticated benefactor.
// @Tags KindBox
// @Accept json
// @Produce json
// @Param id path int true "id"
// @Param id path int true "Kind box ID"
// @Success 200 {object} param.KindBoxGetResponse
// @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 {
var req param.KindBoxGetRequest
if bErr := c.Bind(&req); bErr != nil {

View File

@ -9,14 +9,14 @@ import (
)
// GetAll godoc
// @Summary benefactor get All kindbox
// @Tags kindbox
// @Summary Get all kind boxes for a benefactor
// @Tags KindBox
// @Accept json
// @Produce json
// @Success 200 {object} param.KindBoxGetResponse
// @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 {
var req param.KindBoxGetAllRequest
if bErr := c.Bind(&req); bErr != nil {

View File

@ -1,7 +1,6 @@
package benefactorkindboxreqhandler
import (
"fmt"
"net/http"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
@ -12,19 +11,18 @@ import (
)
// Add godoc
// @Summary benefactor Add kindboxreq
// @Tags kindboxreq
// @Summary Add a new kind box request for a benefactor
// @Tags KindBoxReq
// @Accept 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
// @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 {
req := param.KindBoxReqAddRequest{}
if err := c.Bind(&req); err != nil {
fmt.Println("err", err, req)
return c.JSON(http.StatusBadRequest, echo.Map{
"message": errmsg.ErrBadRequest,

View File

@ -10,15 +10,15 @@ import (
)
// Get godoc
// @Summary benefactor get kindboxreq
// @Tags kindboxreq
// @Summary Get a kind box request for a benefactor
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param id path int true "Id"
// @Param id path int true "Kind box request ID"
// @Success 200 {object} param.KindBoxReqGetResponse
// @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 {
var req param.KindBoxReqGetRequest
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) {
docs.SwaggerInfo.Title = "NIKI Api"
docs.SwaggerInfo.Description = " This is swagger api documentation for niki project"
//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.BasePath = "/api"
//docs.SwaggerInfo.BasePath = "/api/v1"
docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%d", config.HTTPServer.Port)
s.GET("/swagger/*any", echoSwagger.WrapHandler)
}

View File

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

View File

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

View File

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

View File

@ -58,5 +58,5 @@ func InitAdminKindBoxService(db *mysql.DB) adminkindboxservice.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
}
func InitAdminKindBoxReqValidator(db *mysql.DB) adminkindboxreqvalidator.Validator {
return adminkindboxreqvalidator.New(InitBenefactorKindBoxReqDB(db))
func InitAdminKindBoxReqValidator(db *mysql.DB, cfg config.Config) adminkindboxreqvalidator.Validator {
return adminkindboxreqvalidator.New(InitBenefactorKindBoxReqDB(db), InitAdminService(cfg, db))
}
func InitAdminValidator(db *mysql.DB) adminvalidator.Validator {

View File

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

View File

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

View File

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

View File

@ -7,17 +7,17 @@ import (
)
type KindBoxReqRejectRequest struct {
ID uint `json:"id"`
Description string `json:"description"`
ID uint `json:"id" example:"1"`
Description string `json:"description" example:"description"`
}
type KindBoxReqRejectResponse struct {
ID uint `json:"id"`
KindBoxType entity.KindBoxType `json:"kind_box_type"`
CountRequested uint `json:"count_requested"`
BenefactorID uint `json:"benefactor_id"`
Status entity.KindBoxReqStatus `json:"status"`
Description string `json:"description"`
DeliverReferDate time.Time `json:"deliver_refer_date"`
DeliverAddressID uint `json:"deliver_address_id"`
ID uint `json:"id" example:"1"`
KindBoxType entity.KindBoxType `json:"kind_box_type" example:"1"`
CountRequested uint `json:"count_requested" example:"1"`
BenefactorID uint `json:"benefactor_id" example:"1"`
Status entity.KindBoxReqStatus `json:"status" example:"1"`
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"`
}

View File

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

View File

@ -5,11 +5,11 @@ import (
)
type KindBoxReqAddRequest struct {
BenefactorID uint `json:"benefactor_id"`
TypeID entity.KindBoxType `json:"type_id"`
DeliverAddressID uint `json:"deliver_address_id"`
DeliverReferDate string `json:"deliver_refer_date"`
CountRequested uint `json:"count_requested"`
BenefactorID uint `json:"benefactor_id" example:"1"`
TypeID entity.KindBoxType `json:"type_id" example:"1"`
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 {

View File

@ -42,10 +42,10 @@ func (d *DB) GetAllCities(ctx context.Context) ([]entity.City, error) {
}
func scanCity(scanner mysql.Scanner) (entity.City, error) {
var createdAt time.Time
var createdAt, updatedAt time.Time
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
}

View File

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

View File

@ -2,7 +2,6 @@ package mysqladmin
import (
"context"
"git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
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) {
var createdAt time.Time
var createdAt, updatedAt time.Time
var admin entity.Admin
var roleStr, statusStr, password string
// 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,
&roleStr, &adminNullableFields.description,
&adminNullableFields.email, &adminNullableFields.genderStr,
&statusStr, &createdAt)
&statusStr, &createdAt, &updatedAt)
admin.Role = entity.MapToAdminRole(roleStr)
admin.Status = entity.MapToAdminStatus(statusStr)

View File

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

View File

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

View File

@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"errors"
"git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
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) {
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())
if err != nil {
return entity.KindBoxReq{}, richerror.New(op).WithErr(err).

View File

@ -2,6 +2,7 @@ package mysqlkindboxreq
import (
"database/sql"
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
@ -9,22 +10,50 @@ import (
func scanKindBoxReq(scanner mysql.Scanner) (entity.KindBoxReq, error) {
var kindBoxReq entity.KindBoxReq
var kindBoxStatus string
var kindBoxType string
var countAccept sql.NullInt64
var desc sql.NullString
err := scanner.Scan(&kindBoxReq.ID, &kindBoxReq.BenefactorID, &kindBoxType, &kindBoxReq.DeliverAddressID, &kindBoxReq.CountRequested, &countAccept,
&desc,
&kindBoxReq.DeliverReferDate, &kindBoxStatus)
var (
kindBoxType string
countAccepted sql.NullInt64
description sql.NullString
status string
senderAgentID sql.NullInt64
deliveredAt sql.NullTime
createdAt time.Time
updatedAt time.Time
)
if countAccept.Valid {
kindBoxReq.CountAccepted = uint(countAccept.Int64)
err := scanner.Scan(
&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)
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,
`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',
`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

View File

@ -6,7 +6,7 @@ CREATE TABLE `admin_access_controls` (
`permission` ENUM('') NOT NULL,
`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

View File

@ -4,7 +4,7 @@ CREATE TABLE `provinces` (
`name` VARCHAR(191) NOT NULL,
`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

View File

@ -5,7 +5,7 @@ CREATE TABLE `cities` (
`province_id` INT NOT NULL,
`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`)
);

View File

@ -11,7 +11,7 @@ CREATE TABLE `addresses` (
`benefactor_id` INT NOT NULL,
`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 (`city_id`) REFERENCES `cities` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`)

View File

@ -13,7 +13,7 @@ CREATE TABLE `kind_box_reqs` (
`delivered_at` DATETIME,
`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 (`deliver_address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`sender_agent_id`) REFERENCES `admins` (`id`)

View File

@ -17,6 +17,7 @@ CREATE TABLE `kind_boxes` (
`returned_at` DATETIME,
`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 (`benefactor_id`) REFERENCES `benefactors` (`id`),
FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`),

View File

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

View File

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

View File

@ -27,8 +27,9 @@ type Service struct {
kindBoxSvc KindBoxSvc
}
func New(repository Repository) Service {
func New(repository Repository, kindBoxSvc KindBoxSvc) 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)
}
if adminExisted {
return fmt.Errorf(errmsg.ErrorMsgPhoneNumberIsNotUnique)
return fmt.Errorf(errmsg.ErrorMsgEmailIsNotUnique)
}
return nil

View File

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