Merge pull request 'feat(niki): add api to fetch refer time list for benefactor and admin' (#190) from stage/hamed/get-all-refer-time into develop

Reviewed-on: ebhomengo/niki#190
This commit is contained in:
hossein 2024-10-09 05:21:28 +00:00
commit cf27483182
21 changed files with 563 additions and 3 deletions

View File

@ -0,0 +1,31 @@
package adminrefertimehandler
import (
"net/http"
refertimeparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
echo "github.com/labstack/echo/v4"
)
// GetAll godoc
// @Summary Get all refer times
// @Tags Admins ReferTimes
// @Accept json
// @Produce json
// @Success 200 {object} adminrefertimeparam.GetAllReferTimeResponse
// @Failure 400 {string} "Bad request"
// @Security AuthBearerAdmin
// @Router /admins/refer-times [get].
func (h Handler) GetAll(c echo.Context) error {
var req refertimeparam.GetAllReferTimeRequest
listCities, err := h.adminReferTimeSvc.GetAll(c.Request().Context(), req)
if err != nil {
msg, code := httpmsg.Error(err)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusOK, listCities)
}

View File

@ -0,0 +1,24 @@
package adminrefertimehandler
import (
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
adminrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
)
type Handler struct {
authSvc authservice.Service
adminReferTimeSvc adminrefertimeservice.Service
adminAuthorizeSvc adminauthorizationservice.Service
}
func New(authSvc authservice.Service,
adminReferTimeSvc adminrefertimeservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service,
) Handler {
return Handler{
authSvc: authSvc,
adminReferTimeSvc: adminReferTimeSvc,
adminAuthorizeSvc: adminAuthorizeSvc,
}
}

View File

@ -0,0 +1,19 @@
package adminrefertimehandler
import (
"git.gocasts.ir/ebhomengo/niki/delivery/http_server/middleware"
"git.gocasts.ir/ebhomengo/niki/entity"
echo "github.com/labstack/echo/v4"
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admins/refer-times")
r.Use(middleware.Auth(h.authSvc))
r.Use(
middleware.Auth(h.authSvc),
middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission),
)
r.GET("", h.GetAll)
}

View File

@ -0,0 +1,31 @@
package benefactorrefertimehandler
import (
"net/http"
refertimeparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/refer_time"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"github.com/labstack/echo/v4"
)
// GetAll godoc
// @Summary Get all refer times
// @Tags Benefactors ReferTimes
// @Accept json
// @Produce json
// @Success 200 {object} benefactorrefertimeparam.GetAllReferTimeResponse
// @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor
// @Router /benefactors/refer-times [get].
func (h Handler) GetAll(c echo.Context) error {
var req refertimeparam.GetAllReferTimeRequest
listReferTimes, err := h.benefactorReferTimeSvc.GetAll(c.Request().Context(), req)
if err != nil {
msg, code := httpmsg.Error(err)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusOK, listReferTimes)
}

View File

@ -0,0 +1,20 @@
package benefactorrefertimehandler
import (
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
benefactorrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/refer_time"
)
type Handler struct {
authSvc authservice.Service
benefactorReferTimeSvc benefactorrefertimeservice.Service
}
func New(authSvc authservice.Service,
benefactorReferTimeSvc benefactorrefertimeservice.Service,
) Handler {
return Handler{
authSvc: authSvc,
benefactorReferTimeSvc: benefactorReferTimeSvc,
}
}

View File

@ -0,0 +1,18 @@
package benefactorrefertimehandler
import (
"git.gocasts.ir/ebhomengo/niki/delivery/http_server/middleware"
"git.gocasts.ir/ebhomengo/niki/entity"
"github.com/labstack/echo/v4"
)
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactors/refer-times")
r.Use(
middleware.Auth(h.authSvc),
middleware.BenefactorAuthorization(entity.UserBenefactorRole),
)
r.GET("", h.GetAll)
}

View File

@ -2,18 +2,20 @@ package httpserver
import ( import (
"fmt" "fmt"
agentkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/config" "git.gocasts.ir/ebhomengo/niki/config"
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin" adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
adminagenthandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/agent" adminagenthandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/agent"
adminKindBoxHandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box" adminKindBoxHandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box"
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req" adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
adminrefertimehandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/refer_time"
agentkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box" agentkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box"
agentkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box_req"
benefactoraddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/address" benefactoraddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/address"
benefactorhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/benefactor" benefactorhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/benefactor"
benefactorkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box" benefactorkindboxhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box"
benefactorkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box_req" benefactorkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box_req"
benefactorrefertimehandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/refer_time"
"git.gocasts.ir/ebhomengo/niki/docs" "git.gocasts.ir/ebhomengo/niki/docs"
"git.gocasts.ir/ebhomengo/niki/service" "git.gocasts.ir/ebhomengo/niki/service"
echo "github.com/labstack/echo/v4" echo "github.com/labstack/echo/v4"
@ -28,12 +30,14 @@ type Server struct {
adminKindBoxReqHandler adminkindboxreqhandler.Handler adminKindBoxReqHandler adminkindboxreqhandler.Handler
adminKindBoxHandler adminKindBoxHandler.Handler adminKindBoxHandler adminKindBoxHandler.Handler
adminAgentHandler adminagenthandler.Handler adminAgentHandler adminagenthandler.Handler
adminReferTimeHandler adminrefertimehandler.Handler
agentKindBoxHandler agentkindboxhandler.Handler agentKindBoxHandler agentkindboxhandler.Handler
agentKindBoxReqHandler agentkindboxreqhandler.Handler agentKindBoxReqHandler agentkindboxreqhandler.Handler
benefactorHandler benefactorhandler.Handler benefactorHandler benefactorhandler.Handler
benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler
benefactorAddressHandler benefactoraddresshandler.Handler benefactorAddressHandler benefactoraddresshandler.Handler
benefactorKindBoxHandler benefactorkindboxhandler.Handler benefactorKindBoxHandler benefactorkindboxhandler.Handler
benefactorReferTimeHandler benefactorrefertimehandler.Handler
} }
func New( func New(
@ -47,12 +51,14 @@ func New(
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc), adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc), adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc), adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc), agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc), agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc), benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc),
benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxReqSvc, svc.NotificationSvc), benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxReqSvc, svc.NotificationSvc),
benefactorAddressHandler: benefactoraddresshandler.New(svc.BenefactorAuthSvc, svc.BenefactorAddressSvc), benefactorAddressHandler: benefactoraddresshandler.New(svc.BenefactorAuthSvc, svc.BenefactorAddressSvc),
benefactorKindBoxHandler: benefactorkindboxhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxSvc, svc.NotificationSvc), benefactorKindBoxHandler: benefactorkindboxhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxSvc, svc.NotificationSvc),
benefactorReferTimeHandler: benefactorrefertimehandler.New(svc.BenefactorAuthSvc, svc.BenefactorReferTimeSvc),
} }
} }
@ -81,10 +87,12 @@ func (s Server) RegisterRoutes() {
s.benefactorKindBoxReqHandler.SetRoutes(s.Router) s.benefactorKindBoxReqHandler.SetRoutes(s.Router)
s.benefactorAddressHandler.SetRoutes(s.Router) s.benefactorAddressHandler.SetRoutes(s.Router)
s.benefactorKindBoxHandler.SetRoutes(s.Router) s.benefactorKindBoxHandler.SetRoutes(s.Router)
s.benefactorReferTimeHandler.SetRoutes(s.Router)
s.adminHandler.SetRoutes(s.Router) s.adminHandler.SetRoutes(s.Router)
s.adminAgentHandler.SetRoutes(s.Router) s.adminAgentHandler.SetRoutes(s.Router)
s.adminKindBoxReqHandler.SetRoutes(s.Router) s.adminKindBoxReqHandler.SetRoutes(s.Router)
s.adminKindBoxHandler.SetRoutes(s.Router) s.adminKindBoxHandler.SetRoutes(s.Router)
s.adminReferTimeHandler.SetRoutes(s.Router)
s.agentKindBoxHandler.SetRoutes(s.Router) s.agentKindBoxHandler.SetRoutes(s.Router)
s.agentKindBoxReqHandler.SetRoutes(s.Router) s.agentKindBoxReqHandler.SetRoutes(s.Router)
} }

View File

@ -1013,6 +1013,39 @@ const docTemplate = `{
} }
} }
}, },
"/admins/refer-times": {
"get": {
"security": [
{
"AuthBearerAdmin": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admins ReferTimes"
],
"summary": "Get all refer times",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminrefertimeparam.GetAllReferTimeResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/admins/refresh-access": { "/admins/refresh-access": {
"post": { "post": {
"consumes": [ "consumes": [
@ -2526,6 +2559,39 @@ const docTemplate = `{
} }
} }
}, },
"/benefactors/refer-times": {
"get": {
"security": [
{
"AuthBearerBenefactor": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Benefactors ReferTimes"
],
"summary": "Get all refer times",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/benefactorrefertimeparam.GetAllReferTimeResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/benefactors/refresh-access": { "/benefactors/refresh-access": {
"post": { "post": {
"consumes": [ "consumes": [
@ -3158,6 +3224,17 @@ const docTemplate = `{
} }
} }
}, },
"adminrefertimeparam.GetAllReferTimeResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.ReferTime"
}
}
}
},
"adminserviceparam.Data": { "adminserviceparam.Data": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3914,6 +3991,17 @@ const docTemplate = `{
} }
} }
}, },
"benefactorrefertimeparam.GetAllReferTimeResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.ReferTime"
}
}
}
},
"entity.AdminRole": { "entity.AdminRole": {
"type": "integer", "type": "integer",
"enum": [ "enum": [
@ -4021,6 +4109,31 @@ const docTemplate = `{
} }
} }
}, },
"entity.ReferTime": {
"type": "object",
"properties": {
"duration": {
"type": "string"
},
"id": {
"type": "integer"
},
"status": {
"$ref": "#/definitions/entity.ReferTimeStatus"
}
}
},
"entity.ReferTimeStatus": {
"type": "string",
"enum": [
"active",
"inactive"
],
"x-enum-varnames": [
"ReferTimeActiveStatus",
"ReferTimeInactiveStatus"
]
},
"entity.UserRole": { "entity.UserRole": {
"type": "string", "type": "string",
"enum": [ "enum": [

View File

@ -1002,6 +1002,39 @@
} }
} }
}, },
"/admins/refer-times": {
"get": {
"security": [
{
"AuthBearerAdmin": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admins ReferTimes"
],
"summary": "Get all refer times",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminrefertimeparam.GetAllReferTimeResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/admins/refresh-access": { "/admins/refresh-access": {
"post": { "post": {
"consumes": [ "consumes": [
@ -2515,6 +2548,39 @@
} }
} }
}, },
"/benefactors/refer-times": {
"get": {
"security": [
{
"AuthBearerBenefactor": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Benefactors ReferTimes"
],
"summary": "Get all refer times",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/benefactorrefertimeparam.GetAllReferTimeResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/benefactors/refresh-access": { "/benefactors/refresh-access": {
"post": { "post": {
"consumes": [ "consumes": [
@ -3147,6 +3213,17 @@
} }
} }
}, },
"adminrefertimeparam.GetAllReferTimeResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.ReferTime"
}
}
}
},
"adminserviceparam.Data": { "adminserviceparam.Data": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3903,6 +3980,17 @@
} }
} }
}, },
"benefactorrefertimeparam.GetAllReferTimeResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.ReferTime"
}
}
}
},
"entity.AdminRole": { "entity.AdminRole": {
"type": "integer", "type": "integer",
"enum": [ "enum": [
@ -4010,6 +4098,31 @@
} }
} }
}, },
"entity.ReferTime": {
"type": "object",
"properties": {
"duration": {
"type": "string"
},
"id": {
"type": "integer"
},
"status": {
"$ref": "#/definitions/entity.ReferTimeStatus"
}
}
},
"entity.ReferTimeStatus": {
"type": "string",
"enum": [
"active",
"inactive"
],
"x-enum-varnames": [
"ReferTimeActiveStatus",
"ReferTimeInactiveStatus"
]
},
"entity.UserRole": { "entity.UserRole": {
"type": "string", "type": "string",
"enum": [ "enum": [

View File

@ -362,6 +362,13 @@ definitions:
example: 1 example: 1
type: integer type: integer
type: object type: object
adminrefertimeparam.GetAllReferTimeResponse:
properties:
data:
items:
$ref: '#/definitions/entity.ReferTime'
type: array
type: object
adminserviceparam.Data: adminserviceparam.Data:
properties: properties:
description: description:
@ -854,6 +861,13 @@ definitions:
- $ref: '#/definitions/entity.KindBoxType' - $ref: '#/definitions/entity.KindBoxType'
example: cylindrical example: cylindrical
type: object type: object
benefactorrefertimeparam.GetAllReferTimeResponse:
properties:
data:
items:
$ref: '#/definitions/entity.ReferTime'
type: array
type: object
entity.AdminRole: entity.AdminRole:
enum: enum:
- 1 - 1
@ -934,6 +948,23 @@ definitions:
name: name:
type: string type: string
type: object type: object
entity.ReferTime:
properties:
duration:
type: string
id:
type: integer
status:
$ref: '#/definitions/entity.ReferTimeStatus'
type: object
entity.ReferTimeStatus:
enum:
- active
- inactive
type: string
x-enum-varnames:
- ReferTimeActiveStatus
- ReferTimeInactiveStatus
entity.UserRole: entity.UserRole:
enum: enum:
- benefactor - benefactor
@ -1621,6 +1652,26 @@ paths:
summary: "Admin login by\tPhoneNumber" summary: "Admin login by\tPhoneNumber"
tags: tags:
- Admins - Admins
/admins/refer-times:
get:
consumes:
- application/json
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/adminrefertimeparam.GetAllReferTimeResponse'
"400":
description: Bad request
schema:
type: string
security:
- AuthBearerAdmin: []
summary: Get all refer times
tags:
- Admins ReferTimes
/admins/refresh-access: /admins/refresh-access:
post: post:
consumes: consumes:
@ -2619,6 +2670,26 @@ paths:
summary: Login or register a benefactor summary: Login or register a benefactor
tags: tags:
- Benefactors - Benefactors
/benefactors/refer-times:
get:
consumes:
- application/json
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/benefactorrefertimeparam.GetAllReferTimeResponse'
"400":
description: Bad request
schema:
type: string
security:
- AuthBearerBenefactor: []
summary: Get all refer times
tags:
- Benefactors ReferTimes
/benefactors/refresh-access: /benefactors/refresh-access:
post: post:
consumes: consumes:

View File

@ -1,4 +1,4 @@
package param package adminrefertimeparam
import "git.gocasts.ir/ebhomengo/niki/entity" import "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -0,0 +1,9 @@
package adminrefertimeparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type GetAllReferTimeRequest struct{}
type GetAllReferTimeResponse struct {
Data []entity.ReferTime `json:"data"`
}

View File

@ -1,4 +1,4 @@
package param package benefactorrefertimeparam
import "git.gocasts.ir/ebhomengo/niki/entity" import "git.gocasts.ir/ebhomengo/niki/entity"

View File

@ -0,0 +1,9 @@
package benefactorrefertimeparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type GetAllReferTimeRequest struct{}
type GetAllReferTimeResponse struct {
Data []entity.ReferTime `json:"data"`
}

View File

@ -44,4 +44,5 @@ const (
StatementKeyKindBoxReqUpdate StatementKeyKindBoxReqUpdate
StatementKeyKindBoxUpdate StatementKeyKindBoxUpdate
StatementKeyReferTimeGetByID StatementKeyReferTimeGetByID
StatementKeyReferTimeGetAll
) )

View File

@ -0,0 +1,47 @@
package mysqlrefertime
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"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
)
func (d *DB) GetAll(ctx context.Context) ([]entity.ReferTime, error) {
const op = "mysqlrefertime.GetAll"
query := `SELECT * FROM refer_times where status = 'active';`
//nolint
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyReferTimeGetAll, query)
if err != nil {
return nil, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
}
rows, err := stmt.QueryContext(ctx)
if err != nil {
return nil, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
}
defer rows.Close()
referTimes := make([]entity.ReferTime, 0)
for rows.Next() {
referTime, err := scanReferTime(rows)
if err != nil {
return nil, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
}
referTimes = append(referTimes, referTime)
}
if err = rows.Err(); err != nil {
return nil, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
}
return referTimes, nil
}

View File

@ -0,0 +1,19 @@
package adminrefertimeservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetAll(ctx context.Context, _ param.GetAllReferTimeRequest) (param.GetAllReferTimeResponse, error) {
const op = "adminrefertimeservice.GetAllReferTime"
referTimes, err := s.repo.GetAll(ctx)
if err != nil {
return param.GetAllReferTimeResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
return param.GetAllReferTimeResponse{Data: referTimes}, nil
}

View File

@ -11,6 +11,7 @@ type Service struct {
} }
type Repository interface { type Repository interface {
Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error) Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error)
GetAll(ctx context.Context) ([]entity.ReferTime, error)
} }
func New(repo Repository) Service { func New(repo Repository) Service {

View File

@ -0,0 +1,19 @@
package benefactorrefertimeservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/refer_time"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetAll(ctx context.Context, _ param.GetAllReferTimeRequest) (param.GetAllReferTimeResponse, error) {
const op = "benefactorrefertimeservice.GetAllReferTime"
referTimes, err := s.repo.GetAll(ctx)
if err != nil {
return param.GetAllReferTimeResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
return param.GetAllReferTimeResponse{Data: referTimes}, nil
}

View File

@ -11,6 +11,7 @@ type Service struct {
} }
type Repository interface { type Repository interface {
Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error) Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error)
GetAll(ctx context.Context) ([]entity.ReferTime, error)
} }
func New(repo Repository) Service { func New(repo Repository) Service {

View File

@ -56,6 +56,8 @@ type Service struct {
BenefactorAddressSvc benefactoraddressservice.Service BenefactorAddressSvc benefactoraddressservice.Service
BenefactorSvc benefactorservice.Service BenefactorSvc benefactorservice.Service
NotificationSvc notification.Service NotificationSvc notification.Service
BenefactorReferTimeSvc benefactorrefertimeservice.Service
AdminReferTimeSvc adminrefertimeservice.Service
} }
func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service { func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service {
@ -102,6 +104,8 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
BenefactorKindBoxReqSvc = benefactorkindboxreqservice.New(kindBoxReqRepo, BenefactorKindBoxReqVld) BenefactorKindBoxReqSvc = benefactorkindboxreqservice.New(kindBoxReqRepo, BenefactorKindBoxReqVld)
BenefactorKindBoxVld = benefactorkindboxvalidator.New(kindBoxRepo, BenefactorSvc, BenefactorAddressSvc, BenefactorReferTimeSvc) BenefactorKindBoxVld = benefactorkindboxvalidator.New(kindBoxRepo, BenefactorSvc, BenefactorAddressSvc, BenefactorReferTimeSvc)
BenefactorKindBoxSvc = benefactorkindboxservice.New(kindBoxRepo, BenefactorKindBoxVld) BenefactorKindBoxSvc = benefactorkindboxservice.New(kindBoxRepo, BenefactorKindBoxVld)
benefactorReferTimeSvc = benefactorrefertimeservice.New(referTimeRepo)
adminReferTimeSvc = adminrefertimeservice.New(referTimeRepo)
) )
NotificationSvc := notification.New(cfg.NotificationSvc, smsAdapter, AdminKindBoxReqSvc, AdminBenefactorSvc, AdminSvc, AdminKindBoxSvc) NotificationSvc := notification.New(cfg.NotificationSvc, smsAdapter, AdminKindBoxReqSvc, AdminBenefactorSvc, AdminSvc, AdminKindBoxSvc)
@ -120,5 +124,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
BenefactorAddressSvc: BenefactorAddressSvc, BenefactorAddressSvc: BenefactorAddressSvc,
BenefactorSvc: BenefactorSvc, BenefactorSvc: BenefactorSvc,
NotificationSvc: NotificationSvc, NotificationSvc: NotificationSvc,
BenefactorReferTimeSvc: benefactorReferTimeSvc,
AdminReferTimeSvc: adminReferTimeSvc,
} }
} }