From 26d44dd7eb96852e2e8810c0374e6bf5cc5e4e8b Mon Sep 17 00:00:00 2001 From: ErfanTech Date: Fri, 17 May 2024 23:46:28 +0330 Subject: [PATCH] fix(niki): major refactoring and bug fixes --- delivery/http_server/admin/admin/login.go | 6 +- delivery/http_server/admin/admin/register.go | 7 +- .../http_server/admin/kind_box_req/accept.go | 12 +- .../admin/kind_box_req/assign_sender_agent.go | 14 +- .../http_server/admin/kind_box_req/deliver.go | 10 +- .../http_server/admin/kind_box_req/get_all.go | 12 +- .../http_server/admin/kind_box_req/reject.go | 12 +- .../benefactor/address/add_address.go | 11 +- .../benefactor/address/get_all_cities.go | 4 +- .../benefactor/address/get_all_provinces.go | 4 +- .../benefactor/benefactor/login_register.go | 7 +- .../benefactor/benefactor/send_otp.go | 7 +- .../http_server/benefactor/kind_box/get.go | 11 +- .../benefactor/kind_box/get_all.go | 8 +- .../benefactor/kind_box_req/add.go | 12 +- .../benefactor/kind_box_req/get.go | 10 +- delivery/http_server/server.go | 8 +- docs/docs.go | 222 +++++++++++------- docs/swagger.json | 222 +++++++++++------- docs/swagger.yaml | 164 ++++++++----- internal/initial/service.go | 2 +- internal/initial/validator.go | 4 +- main.go | 8 +- param/admin/admin/login.go | 4 +- param/admin/admin/register.go | 18 +- param/admin/kind_box_req/reject.go | 20 +- .../benefactor/benefactore/login_register.go | 2 +- param/benefactor/kind_box_req/add.go | 10 +- repository/mysql/address/get_all_cities.go | 4 +- repository/mysql/address/get_all_provinces.go | 4 +- repository/mysql/admin/authorization.go | 3 +- repository/mysql/admin/create.go | 1 - repository/mysql/admin/get.go | 4 +- .../mysql/kind_box_req/assign_sender_agent.go | 6 +- repository/mysql/kind_box_req/deliver.go | 4 +- repository/mysql/kind_box_req/kind_box_req.go | 3 +- repository/mysql/kind_box_req/scan.go | 57 +++-- .../1705244014_create_benefactors_table.sql | 2 +- .../1705244015_create_admins_table.sql | 2 +- ...016_create_admin_access_controls_table.sql | 2 +- .../1705399194_create_provinces_table.sql | 2 +- .../1705399195_create_cities_table.sql | 2 +- .../1705399370_create_addresses_table.sql | 2 +- .../1705400111_create_kind_box_reqs_table.sql | 2 +- .../1705992494_create_kind_boxes_table.sql | 1 + ..._insert_admins_table_super_admin_value.sql | 2 +- service/admin/admin/register.go | 7 +- service/admin/kind_box_req/service.go | 5 +- validator/admin/admin/validator.go | 2 +- validator/admin/kind_box_req/validator.go | 4 +- 50 files changed, 579 insertions(+), 373 deletions(-) diff --git a/delivery/http_server/admin/admin/login.go b/delivery/http_server/admin/admin/login.go index 3cf82f1..2b34ac6 100644 --- a/delivery/http_server/admin/admin/login.go +++ b/delivery/http_server/admin/admin/login.go @@ -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] diff --git a/delivery/http_server/admin/admin/register.go b/delivery/http_server/admin/admin/register.go index 2bd40bf..cf5a782 100644 --- a/delivery/http_server/admin/admin/register.go +++ b/delivery/http_server/admin/admin/register.go @@ -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 diff --git a/delivery/http_server/admin/kind_box_req/accept.go b/delivery/http_server/admin/kind_box_req/accept.go index 807650b..6908e4d 100644 --- a/delivery/http_server/admin/kind_box_req/accept.go +++ b/delivery/http_server/admin/kind_box_req/accept.go @@ -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 { diff --git a/delivery/http_server/admin/kind_box_req/assign_sender_agent.go b/delivery/http_server/admin/kind_box_req/assign_sender_agent.go index 49f9e40..8c59779 100644 --- a/delivery/http_server/admin/kind_box_req/assign_sender_agent.go +++ b/delivery/http_server/admin/kind_box_req/assign_sender_agent.go @@ -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 diff --git a/delivery/http_server/admin/kind_box_req/deliver.go b/delivery/http_server/admin/kind_box_req/deliver.go index dcf86a1..0051f91 100644 --- a/delivery/http_server/admin/kind_box_req/deliver.go +++ b/delivery/http_server/admin/kind_box_req/deliver.go @@ -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 diff --git a/delivery/http_server/admin/kind_box_req/get_all.go b/delivery/http_server/admin/kind_box_req/get_all.go index 705cead..90b300e 100644 --- a/delivery/http_server/admin/kind_box_req/get_all.go +++ b/delivery/http_server/admin/kind_box_req/get_all.go @@ -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 { diff --git a/delivery/http_server/admin/kind_box_req/reject.go b/delivery/http_server/admin/kind_box_req/reject.go index 2927703..f3dc7d9 100644 --- a/delivery/http_server/admin/kind_box_req/reject.go +++ b/delivery/http_server/admin/kind_box_req/reject.go @@ -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 { diff --git a/delivery/http_server/benefactor/address/add_address.go b/delivery/http_server/benefactor/address/add_address.go index 2cb5657..00badd6 100644 --- a/delivery/http_server/benefactor/address/add_address.go +++ b/delivery/http_server/benefactor/address/add_address.go @@ -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 { diff --git a/delivery/http_server/benefactor/address/get_all_cities.go b/delivery/http_server/benefactor/address/get_all_cities.go index 9bf9f7b..3fe2bf7 100644 --- a/delivery/http_server/benefactor/address/get_all_cities.go +++ b/delivery/http_server/benefactor/address/get_all_cities.go @@ -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 diff --git a/delivery/http_server/benefactor/address/get_all_provinces.go b/delivery/http_server/benefactor/address/get_all_provinces.go index 9d86632..d54c30e 100644 --- a/delivery/http_server/benefactor/address/get_all_provinces.go +++ b/delivery/http_server/benefactor/address/get_all_provinces.go @@ -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 diff --git a/delivery/http_server/benefactor/benefactor/login_register.go b/delivery/http_server/benefactor/benefactor/login_register.go index 31a3a66..2284952 100644 --- a/delivery/http_server/benefactor/benefactor/login_register.go +++ b/delivery/http_server/benefactor/benefactor/login_register.go @@ -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] diff --git a/delivery/http_server/benefactor/benefactor/send_otp.go b/delivery/http_server/benefactor/benefactor/send_otp.go index 7e15dd2..e65f7e2 100644 --- a/delivery/http_server/benefactor/benefactor/send_otp.go +++ b/delivery/http_server/benefactor/benefactor/send_otp.go @@ -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] diff --git a/delivery/http_server/benefactor/kind_box/get.go b/delivery/http_server/benefactor/kind_box/get.go index 8a67719..08f6510 100644 --- a/delivery/http_server/benefactor/kind_box/get.go +++ b/delivery/http_server/benefactor/kind_box/get.go @@ -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 { diff --git a/delivery/http_server/benefactor/kind_box/get_all.go b/delivery/http_server/benefactor/kind_box/get_all.go index 5a87e28..3a47bdc 100644 --- a/delivery/http_server/benefactor/kind_box/get_all.go +++ b/delivery/http_server/benefactor/kind_box/get_all.go @@ -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 { diff --git a/delivery/http_server/benefactor/kind_box_req/add.go b/delivery/http_server/benefactor/kind_box_req/add.go index 9994abc..a89add6 100644 --- a/delivery/http_server/benefactor/kind_box_req/add.go +++ b/delivery/http_server/benefactor/kind_box_req/add.go @@ -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, diff --git a/delivery/http_server/benefactor/kind_box_req/get.go b/delivery/http_server/benefactor/kind_box_req/get.go index e1e75cd..ebe862b 100644 --- a/delivery/http_server/benefactor/kind_box_req/get.go +++ b/delivery/http_server/benefactor/kind_box_req/get.go @@ -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 { diff --git a/delivery/http_server/server.go b/delivery/http_server/server.go index 28962ff..2a05a5e 100644 --- a/delivery/http_server/server.go +++ b/delivery/http_server/server.go @@ -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) } diff --git a/docs/docs.go b/docs/docs.go index c179811..3659d1c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -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" } } diff --git a/docs/swagger.json b/docs/swagger.json index 120bbcd..647447f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -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" } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index c1ff468..52724df 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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" diff --git a/internal/initial/service.go b/internal/initial/service.go index 02f322b..596bd33 100644 --- a/internal/initial/service.go +++ b/internal/initial/service.go @@ -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)) } diff --git a/internal/initial/validator.go b/internal/initial/validator.go index b11a9e3..487f2d7 100644 --- a/internal/initial/validator.go +++ b/internal/initial/validator.go @@ -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 { diff --git a/main.go b/main.go index 5ef4f9b..1170cb8 100644 --- a/main.go +++ b/main.go @@ -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{ diff --git a/param/admin/admin/login.go b/param/admin/admin/login.go index f3261ba..28b17ef 100644 --- a/param/admin/admin/login.go +++ b/param/admin/admin/login.go @@ -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 { diff --git a/param/admin/admin/register.go b/param/admin/admin/register.go index b01ea49..f77b9ab 100644 --- a/param/admin/admin/register.go +++ b/param/admin/admin/register.go @@ -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 { diff --git a/param/admin/kind_box_req/reject.go b/param/admin/kind_box_req/reject.go index 194b966..a438913 100644 --- a/param/admin/kind_box_req/reject.go +++ b/param/admin/kind_box_req/reject.go @@ -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"` } diff --git a/param/benefactor/benefactore/login_register.go b/param/benefactor/benefactore/login_register.go index c34933b..cd10427 100644 --- a/param/benefactor/benefactore/login_register.go +++ b/param/benefactor/benefactore/login_register.go @@ -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 { diff --git a/param/benefactor/kind_box_req/add.go b/param/benefactor/kind_box_req/add.go index b9ab864..c45f8b0 100644 --- a/param/benefactor/kind_box_req/add.go +++ b/param/benefactor/kind_box_req/add.go @@ -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 { diff --git a/repository/mysql/address/get_all_cities.go b/repository/mysql/address/get_all_cities.go index e869e73..156cba9 100644 --- a/repository/mysql/address/get_all_cities.go +++ b/repository/mysql/address/get_all_cities.go @@ -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 } diff --git a/repository/mysql/address/get_all_provinces.go b/repository/mysql/address/get_all_provinces.go index 26b40d3..98eadeb 100644 --- a/repository/mysql/address/get_all_provinces.go +++ b/repository/mysql/address/get_all_provinces.go @@ -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 } diff --git a/repository/mysql/admin/authorization.go b/repository/mysql/admin/authorization.go index 560784f..cf8ff8f 100644 --- a/repository/mysql/admin/authorization.go +++ b/repository/mysql/admin/authorization.go @@ -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 } diff --git a/repository/mysql/admin/create.go b/repository/mysql/admin/create.go index 96ed635..d51b06a 100644 --- a/repository/mysql/admin/create.go +++ b/repository/mysql/admin/create.go @@ -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" diff --git a/repository/mysql/admin/get.go b/repository/mysql/admin/get.go index 750bf7b..417ae77 100644 --- a/repository/mysql/admin/get.go +++ b/repository/mysql/admin/get.go @@ -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) diff --git a/repository/mysql/kind_box_req/assign_sender_agent.go b/repository/mysql/kind_box_req/assign_sender_agent.go index 90136b3..14d56b9 100644 --- a/repository/mysql/kind_box_req/assign_sender_agent.go +++ b/repository/mysql/kind_box_req/assign_sender_agent.go @@ -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) diff --git a/repository/mysql/kind_box_req/deliver.go b/repository/mysql/kind_box_req/deliver.go index 7ff8024..8f0b381 100644 --- a/repository/mysql/kind_box_req/deliver.go +++ b/repository/mysql/kind_box_req/deliver.go @@ -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) diff --git a/repository/mysql/kind_box_req/kind_box_req.go b/repository/mysql/kind_box_req/kind_box_req.go index 8036060..acab110 100644 --- a/repository/mysql/kind_box_req/kind_box_req.go +++ b/repository/mysql/kind_box_req/kind_box_req.go @@ -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). diff --git a/repository/mysql/kind_box_req/scan.go b/repository/mysql/kind_box_req/scan.go index b965601..1cb0343 100644 --- a/repository/mysql/kind_box_req/scan.go +++ b/repository/mysql/kind_box_req/scan.go @@ -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 } diff --git a/repository/mysql/migration/1705244014_create_benefactors_table.sql b/repository/mysql/migration/1705244014_create_benefactors_table.sql index 2a36197..ac0834b 100644 --- a/repository/mysql/migration/1705244014_create_benefactors_table.sql +++ b/repository/mysql/migration/1705244014_create_benefactors_table.sql @@ -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 ); diff --git a/repository/mysql/migration/1705244015_create_admins_table.sql b/repository/mysql/migration/1705244015_create_admins_table.sql index 1b66193..7b6a853 100644 --- a/repository/mysql/migration/1705244015_create_admins_table.sql +++ b/repository/mysql/migration/1705244015_create_admins_table.sql @@ -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 diff --git a/repository/mysql/migration/1705244016_create_admin_access_controls_table.sql b/repository/mysql/migration/1705244016_create_admin_access_controls_table.sql index c98b59d..51ddc26 100644 --- a/repository/mysql/migration/1705244016_create_admin_access_controls_table.sql +++ b/repository/mysql/migration/1705244016_create_admin_access_controls_table.sql @@ -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 diff --git a/repository/mysql/migration/1705399194_create_provinces_table.sql b/repository/mysql/migration/1705399194_create_provinces_table.sql index 9387c57..1656076 100644 --- a/repository/mysql/migration/1705399194_create_provinces_table.sql +++ b/repository/mysql/migration/1705399194_create_provinces_table.sql @@ -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 diff --git a/repository/mysql/migration/1705399195_create_cities_table.sql b/repository/mysql/migration/1705399195_create_cities_table.sql index bf9da44..1ca5a97 100644 --- a/repository/mysql/migration/1705399195_create_cities_table.sql +++ b/repository/mysql/migration/1705399195_create_cities_table.sql @@ -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`) ); diff --git a/repository/mysql/migration/1705399370_create_addresses_table.sql b/repository/mysql/migration/1705399370_create_addresses_table.sql index 77b3093..729b869 100644 --- a/repository/mysql/migration/1705399370_create_addresses_table.sql +++ b/repository/mysql/migration/1705399370_create_addresses_table.sql @@ -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`) diff --git a/repository/mysql/migration/1705400111_create_kind_box_reqs_table.sql b/repository/mysql/migration/1705400111_create_kind_box_reqs_table.sql index 1c29e7b..de4ca8a 100644 --- a/repository/mysql/migration/1705400111_create_kind_box_reqs_table.sql +++ b/repository/mysql/migration/1705400111_create_kind_box_reqs_table.sql @@ -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`) diff --git a/repository/mysql/migration/1705992494_create_kind_boxes_table.sql b/repository/mysql/migration/1705992494_create_kind_boxes_table.sql index c5ecc4d..dc5054e 100644 --- a/repository/mysql/migration/1705992494_create_kind_boxes_table.sql +++ b/repository/mysql/migration/1705992494_create_kind_boxes_table.sql @@ -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`), diff --git a/repository/mysql/migration/1708712563_insert_admins_table_super_admin_value.sql b/repository/mysql/migration/1708712563_insert_admins_table_super_admin_value.sql index 950adee..0f929e2 100644 --- a/repository/mysql/migration/1708712563_insert_admins_table_super_admin_value.sql +++ b/repository/mysql/migration/1708712563_insert_admins_table_super_admin_value.sql @@ -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 diff --git a/service/admin/admin/register.go b/service/admin/admin/register.go index 709acf1..9ff633c 100644 --- a/service/admin/admin/register.go +++ b/service/admin/admin/register.go @@ -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 } diff --git a/service/admin/kind_box_req/service.go b/service/admin/kind_box_req/service.go index 2128d05..1820aae 100644 --- a/service/admin/kind_box_req/service.go +++ b/service/admin/kind_box_req/service.go @@ -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, } } diff --git a/validator/admin/admin/validator.go b/validator/admin/admin/validator.go index b295ee7..6e4c921 100644 --- a/validator/admin/admin/validator.go +++ b/validator/admin/admin/validator.go @@ -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 diff --git a/validator/admin/kind_box_req/validator.go b/validator/admin/kind_box_req/validator.go index e9b615c..df0a7bc 100644 --- a/validator/admin/kind_box_req/validator.go +++ b/validator/admin/kind_box_req/validator.go @@ -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 {