Deleting the commented codes

This commit is contained in:
Abolfazl Nourzad 2024-01-26 09:32:25 +03:30
parent 85b9a7254e
commit ed5c165040
Signed by: abolfazl
GPG Key ID: 183534166EB62E0B
41 changed files with 1 additions and 1070 deletions

View File

@ -1,24 +1 @@
package adminkindboxhandler package adminkindboxhandler
// func (h Handler) Add(c echo.Context) error {
// var req param.KindBoxAddRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.adminKindBoxVld.ValidateAddRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.adminKindBoxSvc.Add(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -1,32 +1 @@
package adminkindboxhandler package adminkindboxhandler
// import (
// "net/http"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
// echo "github.com/labstack/echo/v4"
//)
//
// func (h Handler) Get(c echo.Context) error {
// var req param.KindBoxGetRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.adminKindBoxVld.ValidateGetRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.adminKindBoxSvc.Get(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -1,26 +1 @@
package adminkindboxhandler package adminkindboxhandler
//
// import (
// "net/http"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
// echo "github.com/labstack/echo/v4"
//)
//
// func (h Handler) GetAll(c echo.Context) error {
// var req param.KindBoxGetAllRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
//
// resp, sErr := h.adminKindBoxSvc.GetAll(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -5,9 +5,4 @@ import (
) )
func (h Handler) SetRoutes(_ *echo.Echo) { func (h Handler) SetRoutes(_ *echo.Echo) {
//nolint
// r.POST("/", h.Add).Name = "admin-addkindbox"
// r.GET("/:id", h.Get).Name = "admin-getkindboxbyid"
// r.GET("/", h.GetAll).Name = "admin-getallkindbox"
// r.PATCH("/:id", h.Update).Name = "admin-updatekindbox"
} }

View File

@ -1,32 +1 @@
package adminkindboxhandler package adminkindboxhandler
// import (
// "net/http"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
// echo "github.com/labstack/echo/v4"
//)
//
// func (h Handler) Update(c echo.Context) error {
// var req param.KindBoxUpdateRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.adminKindBoxVld.ValidateUpdateRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.adminKindBoxSvc.Update(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -1,32 +1 @@
package adminkindboxreqhandler package adminkindboxreqhandler
// import (
// "net/http"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
// echo "github.com/labstack/echo/v4"
//)
//
// func (h Handler) Add(c echo.Context) error {
// var req param.KindBoxReqAddRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.adminKindBoxReqVld.ValidateAddRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.adminKindBoxReqSvc.Add(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -1,24 +1 @@
package adminkindboxreqhandler package adminkindboxreqhandler
// func (h Handler) Get(c echo.Context) error {
// var req param.KindBoxReqGetRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.adminKindBoxReqVld.ValidateGetRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.adminKindBoxReqSvc.Get(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -1,25 +1 @@
package adminkindboxreqhandler package adminkindboxreqhandler
// import (
// "net/http"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
// echo "github.com/labstack/echo/v4"
//)
//
// func (h Handler) GetAll(c echo.Context) error {
// var req param.KindBoxReqGetAllRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
//
// resp, sErr := h.adminKindBoxReqSvc.GetAll(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -7,12 +7,6 @@ import (
func (h Handler) SetRoutes(e *echo.Echo) { func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/admin/kindboxreqs") r := e.Group("/admin/kindboxreqs")
//nolint:gocritic
//r.POST("/", h.Add).Name = "admin-addkindboxreq"
//r.GET("/:id", h.Get).Name = "admin-getkindboxreqbyid"
//r.GET("/", h.GetAll).Name = "admin-getallkindboxreq"
//nolint:gocritic
//r.PATCH("/:id", h.Update).Name = "admin-updatekindboxreq"
// todo - add acl // todo - add acl
r.PATCH("/accept-kind-box-req/:id", h.Accept) r.PATCH("/accept-kind-box-req/:id", h.Accept)
r.PATCH("/reject-kind-box-req/:id", h.Reject) r.PATCH("/reject-kind-box-req/:id", h.Reject)

View File

@ -1,32 +1 @@
package adminkindboxreqhandler package adminkindboxreqhandler
// import (
// "net/http"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
// echo "github.com/labstack/echo/v4"
//)
//
// func (h Handler) Update(c echo.Context) error {
// var req param.KindBoxReqUpdateRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.adminKindBoxReqVld.ValidateUpdateRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.adminKindBoxReqSvc.Update(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -1,24 +1 @@
package benefactorkindboxreqhandler package benefactorkindboxreqhandler
// func (h Handler) Get(c echo.Context) error {
// var req param.KindBoxReqGetRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateGetRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.benefactorKindBoxReqSvc.Get(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -1,17 +1 @@
package benefactorkindboxreqhandler package benefactorkindboxreqhandler
// func (h Handler) GetAll(c echo.Context) error {
// var req param.KindBoxReqGetAllRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
//
// resp, sErr := h.benefactorKindBoxReqSvc.GetAll(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -11,8 +11,4 @@ func (h Handler) SetRoutes(e *echo.Echo) {
r.POST("/", h.Add, middleware.Auth(h.authSvc, h.authConfig), r.POST("/", h.Add, middleware.Auth(h.authSvc, h.authConfig),
middleware.BenefactorAuthorization(entity.UserBenefactorRole)) middleware.BenefactorAuthorization(entity.UserBenefactorRole))
//nolint:gocritic
// r.GET("/:id", h.Get)
// r.GET("/", h.GetAll)
// r.PATCH("/:id", h.Update)
} }

View File

@ -1,24 +1 @@
package benefactorkindboxreqhandler package benefactorkindboxreqhandler
// func (h Handler) Update(c echo.Context) error {
// var req param.KindBoxReqUpdateRequest
// if bErr := c.Bind(&req); bErr != nil {
// return echo.NewHTTPError(http.StatusBadRequest)
// }
// if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateUpdateRequest(req); err != nil {
// msg, code := httpmsg.Error(err)
//
// return c.JSON(code, echo.Map{
// "message": msg,
// "errors": fieldErrors,
// })
// }
// resp, sErr := h.benefactorKindBoxReqSvc.Update(c.Request().Context(), req)
// if sErr != nil {
// msg, code := httpmsg.Error(sErr)
//
// return echo.NewHTTPError(code, msg)
// }
//
// return c.JSON(http.StatusCreated, resp)
//}

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"

View File

@ -1,20 +1 @@
package adminkindboxservice package adminkindboxservice
// import (
// "context"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
// func (s Service) Delete(ctx context.Context, req param.KindBoxDeleteRequest) (param.KindBoxDeleteResponse, error) {
// // TODO: Does business domain need to delete an kindbox ?
// const op = "adminkindboxservice.Delete"
//
// dErr := s.repo.DeleteKindBox(ctx, req.KindBoxID)
// if dErr != nil {
// return param.KindBoxDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxDeleteResponse{}, nil
//}

View File

@ -1,19 +1 @@
package adminkindboxservice package adminkindboxservice
// import (
// "context"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
// func (s Service) Get(ctx context.Context, req param.KindBoxGetRequest) (param.KindBoxGetResponse, error) {
// const op = "adminkindboxservice.Get"
//
// kindBox, err := s.repo.GetKindBox(ctx, req.KindBoxID)
// if err != nil {
// return param.KindBoxGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxGetResponse{KindBox: kindBox}, nil
//}

View File

@ -1,18 +1 @@
package adminkindboxservice package adminkindboxservice
// import (
// "context"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
// func (s Service) GetAll(ctx context.Context, _ param.KindBoxGetAllRequest) (param.KindBoxGetAllResponse, error) {
// const op = "adminkindboxservice.GetAll"
// allKindBox, err := s.repo.GetAllKindBox(ctx)
// if err != nil {
// return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxGetAllResponse{AllKindBox: allKindBox}, nil
//}

View File

@ -8,21 +8,12 @@ import (
type Repository interface { type Repository interface {
AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) ([]entity.KindBox, error) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) ([]entity.KindBox, error)
// UpdateKindBox(ctx context.Context, kindBoxID uint, kindBoxInput entity.KindBox) (entity.KindBox, error)
// DeleteKindBox(ctx context.Context, kindBoxID uint) error
// GetAllKindBox(ctx context.Context) ([]entity.KindBox, error)
// GetKindBox(ctx context.Context, kindBox uint) (entity.KindBox, error)
} }
type Service struct { type Service struct {
repo Repository repo Repository
} }
// TODO: check validation.
// type BenefactorService interface {
// IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error)
// }
func New(repository Repository) Service { func New(repository Repository) Service {
return Service{ return Service{
repo: repository, repo: repository,

View File

@ -1,29 +1 @@
package adminkindboxservice package adminkindboxservice
// import (
// "context"
//
// entity "git.gocasts.ir/ebhomengo/niki/entity"
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
// func (s Service) Update(ctx context.Context, req param.KindBoxUpdateRequest) (param.KindBoxUpdateResponse, error) {
// // TODO: can benefactor update its Request ?
// // TODO: Is Update Mothod Service Responsible to check which kindboxreqID belongs to benefactorID ?
// // TODO: updating data(s) may have side-effect on other entities by masood-keshvary accepted -> rejected
// const op = "adminkindboxservice.Update"
//
// kindBox, uErr := s.repo.UpdateKindBox(ctx, req.KindBoxID, entity.KindBox{
// TotalAmount: req.TotalAmount,
// ReceiverID: req.ReceiverID,
// SenderID: req.SenderID,
// SerialNumber: req.SerialNumber,
// Status: req.Status,
// })
// if uErr != nil {
// return param.KindBoxUpdateResponse{}, richerror.New(op).WithErr(uErr).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxUpdateResponse{KindBox: kindBox}, nil
//}

View File

@ -1,17 +1 @@
package adminkindboxreqservice package adminkindboxreqservice
// func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
// const op = "adminkindboxreqservice.Add"
//
// kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
// BenefactorID: req.BenefactorID,
// KindBoxType: req.TypeID,
// CountRequested: req.CountRequested,
// Status: entity.KindBoxReqPendingStatus,
// })
// if err != nil {
// return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqAddResponse{KindBoxReq: kindBoxReq}, nil
//}

View File

@ -1,21 +1 @@
package adminkindboxreqservice package adminkindboxreqservice
//
// import (
// "context"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
// func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) (param.KindBoxReqDeleteResponse, error) {
// // TODO: Does business domain need to delete an kindboxreq ?
// const op = "adminkindboxreqservice.Delete"
//
// dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
// if dErr != nil {
// return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqDeleteResponse{}, nil
//}

View File

@ -1,21 +1 @@
package adminkindboxreqservice package adminkindboxreqservice
//
// import (
// "context"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
// func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
// const op = "adminkindboxreqservice.Get"
//
// // TODO : ref to service.Update()
// kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
// if err != nil {
// return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil
//}

View File

@ -1,21 +1 @@
package adminkindboxreqservice package adminkindboxreqservice
//
// import (
// "context"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
//// TODO: Pagination, Filters, Sort.
// func (s Service) GetAll(ctx context.Context, _ param.KindBoxReqGetAllRequest) (param.KindBoxReqGetAllResponse, error) {
// const op = "adminkindboxreqservice.GetAll"
//
// allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx)
// if err != nil {
// return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqGetAllResponse{AllKindBoxReq: allKindBoxReq}, nil
//}

View File

@ -8,12 +8,6 @@ import (
) )
type Repository interface { type Repository interface {
// AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
// UpdateKindBoxReq(ctx context.Context, kindBoxReqID uint, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
// TODO: can benefactor cancel its request ?
// DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error
// GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error)
// GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
AcceptKindBoxReq(ctx context.Context, kindBoxReqID uint, countAccepted uint) error AcceptKindBoxReq(ctx context.Context, kindBoxReqID uint, countAccepted uint) error
GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error) GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error)
RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error

View File

@ -1,29 +1 @@
package adminkindboxreqservice package adminkindboxreqservice
//
// import (
// "context"
//
// entity "git.gocasts.ir/ebhomengo/niki/entity"
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
//)
//
// func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) {
// // TODO: can benefactor update its request ?
// // TODO: Is Update Mothod Service Responsible to check which kindboxreqID belongs to benefactorID ?
// // TODO: updating data(s) may have side-effect on other entities by masood-keshvary accepted -> rejected
//
// const op = "adminkindboxreqservice.Update"
//
// kindBoxReq, uErr := s.repo.UpdateKindBoxReq(ctx, req.KindBoxReqID, entity.KindBoxReq{
// BenefactorID: req.BenefactorID,
// TypeID: req.TypeID,
// CountRequested: req.CountRequested,
// })
// if uErr != nil {
// return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(uErr).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqUpdateResponse{KindBoxReq: kindBoxReq}, nil
//}

View File

@ -1,13 +1 @@
package benefactorkindboxreqservice package benefactorkindboxreqservice
// func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) (param.KindBoxReqDeleteResponse, error) {
// // TODO: Does business domain need to delete an kindboxreq ?
// const op = "userkindboxreqservice.Delete"
//
// dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
// if dErr != nil {
// return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqDeleteResponse{}, nil
//}

View File

@ -1,12 +1 @@
package benefactorkindboxreqservice package benefactorkindboxreqservice
// func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
// const op = "userkindboxreqservice.Get"
//
// kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
// if err != nil {
// return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil
//}

View File

@ -1,13 +1 @@
package benefactorkindboxreqservice package benefactorkindboxreqservice
//// TODO: Pagination, Filters, Sort.
// func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest) (param.KindBoxReqGetAllResponse, error) {
// const op = "userkindboxreqservice.GetAll"
//
// allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx, req.BenefactorID)
// if err != nil {
// return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqGetAllResponse{AllKindBoxReq: allKindBoxReq}, nil
//}

View File

@ -8,11 +8,6 @@ import (
type Repository interface { type Repository interface {
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
// UpdateKindBoxReq(ctx context.Context, kindBoxReqID uint, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
// TODO: can benefactor cancel its request ?
// DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error
// GetAllKindBoxReq(ctx context.Context, benefactorID uint) ([]entity.KindBoxReq, error)
// GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
} }
type Service struct { type Service struct {

View File

@ -1,18 +1 @@
package benefactorkindboxreqservice package benefactorkindboxreqservice
// func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) {
// // TODO: can benefactor update its request ?
// // TODO: Is Update Mothod Service Responsible to check which kindboxreqID belongs to benefactorID ?
// const op = "userkindboxreqservice.Update"
//
// kindBoxReq, uErr := s.repo.UpdateKindBoxReq(ctx, req.KindBoxReqID, entity.KindBoxReq{
// BenefactorID: req.BenefactorID,
// KindBoxType: req.TypeID,
// CountRequested: req.CountRequested,
// })
// if uErr != nil {
// return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(uErr).WithKind(richerror.KindUnexpected)
// }
//
// return param.KindBoxReqUpdateResponse{KindBoxReq: kindBoxReq}, nil
//}

View File

@ -1,39 +1 @@
package adminkindboxvalidator package adminkindboxvalidator
// func (v Validator) ValidateAddRequest(req param.KindBoxAddRequest) (map[string]string, error) {
// const op = "adminkindboxvalidator.KindBoxAddRequest"
//
// if err := validation.ValidateStruct(&req,
// validation.Field(&req.SerialNumber, validation.Required, is.Alphanumeric),
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.SenderID,
// validation.Required,
// validation.By(v.doesEmployeeExist)),
//
// validation.Field(&req.KindBoxReqID,
// validation.Required,
// validation.By(v.doesKindBoxRequestExist)),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -1,45 +1 @@
package adminkindboxvalidator package adminkindboxvalidator
// import (
// "errors"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
// validation "github.com/go-ozzo/ozzo-validation/v4"
//)
//
// func (v Validator) ValidateDeleteRequest(req param.KindBoxDeleteRequest) (map[string]string, error) {
// const op = "adminkindboxvalidator.ValidateDeleteRequest"
//
// if err := validation.ValidateStruct(&req,
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.KindBoxID,
// validation.Required,
// validation.By(v.hasPendingStatus),
// validation.By(v.doesKindBoxExist),
// validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID))),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -1,44 +1 @@
package adminkindboxvalidator package adminkindboxvalidator
// import (
// "errors"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
// validation "github.com/go-ozzo/ozzo-validation/v4"
//)
//
// func (v Validator) ValidateGetRequest(req param.KindBoxGetRequest) (map[string]string, error) {
// const op = "adminkindboxvalidator.ValidateGetRequest"
//
// if err := validation.ValidateStruct(&req,
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.KindBoxID,
// validation.Required,
// validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID)),
// validation.By(v.doesKindBoxExist)),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -1,59 +1 @@
package adminkindboxvalidator package adminkindboxvalidator
// import (
// "errors"
//
// "git.gocasts.ir/ebhomengo/niki/entity"
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
// errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
// "github.com/go-ozzo/ozzo-validation/is"
// validation "github.com/go-ozzo/ozzo-validation/v4"
//)
//
// func (v Validator) ValidateUpdateRequest(req param.KindBoxUpdateRequest) (map[string]string, error) {
// const op = "adminkindboxvalidator.ValidateUpdateRequest"
//
// if err := validation.ValidateStruct(&req,
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.KindBoxID,
// validation.Required,
// validation.By(v.doesKindBoxExist),
// validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID))),
//
// validation.Field(&req.SerialNumber, is.Alphanumeric),
//
// validation.Field(&req.TotalAmount, validation.Min(0)),
//
// validation.Field(&req.SenderID,
// validation.By(v.doesEmployeeExist)),
//
// validation.Field(&req.ReceiverID,
// validation.By(v.doesEmployeeExist)),
//
// validation.Field(&req.Status,
// validation.In(entity.AllKindBoxStatus())),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -17,97 +17,3 @@ type Validator struct {
func New(repo Repository) Validator { func New(repo Repository) Validator {
return Validator{repo: repo} return Validator{repo: repo}
} }
// func (v Validator) doesKindBoxRequestExist(value interface{}) error {
// receiverID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.KindBoxRequestExist(receiverID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
//}
//
// func (v Validator) doesEmployeeExist(value interface{}) error {
// senderID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.EmployeeExist(senderID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
//}
//
// func (v Validator) doesBenefactorExist(value interface{}) error {
// benefactorID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.BenefactorExist(benefactorID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
//}
//
// func (v Validator) doesKindBoxExist(value interface{}) error {
// kindboxID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
// _, err := v.repo.KindBoxExist(kindboxID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
//}
//
// func (v Validator) doesKindBoxBelongToBenefactor(benefactorID uint) validation.RuleFunc {
// return func(value interface{}) error {
// kbID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
// _, err := v.repo.KindBoxBelongToBenefactor(benefactorID, kbID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
// }
//}
// TODO: this temperary to ignore linter error. (unused function)
// func (v Validator) hasCorrectStatus(value interface{}) error {
// status, ok := value.(string)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.CheckStatus(status)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
// return nil
// }
// func (v Validator) hasPendingStatus(value interface{}) error {
// kindboxID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.PendingStatus(kindboxID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
//}

View File

@ -1,46 +1 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
// import (
// "errors"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
// validation "github.com/go-ozzo/ozzo-validation/v4"
//)
//
// func (v Validator) ValidateAddRequest(req param.KindBoxReqAddRequest) (map[string]string, error) {
// const op = "adminkindboxreqvalidator.ValidateAddRequest"
//
// if err := validation.ValidateStruct(&req,
//
// validation.Field(&req.CountRequested, validation.Required, validation.Min(MinKindBoxReq), validation.Max(MaxKindBoxReq)),
//
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.TypeID,
// validation.Required,
// validation.By(v.doesTypeExist)),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -1,45 +1 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
// import (
// "errors"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
// validation "github.com/go-ozzo/ozzo-validation/v4"
//)
//
// func (v Validator) ValidateDeleteRequest(req param.KindBoxReqDeleteRequest) (map[string]string, error) {
// const op = "adminkindboxreqvalidator.ValidateDeleteRequest"
//
// if err := validation.ValidateStruct(&req,
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.KindBoxReqID,
// validation.Required,
// validation.By(v.hasPendingStatus),
// validation.By(v.doesKindBoxRequestExist),
// validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID))),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -1,44 +1 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
// import (
// "errors"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
// validation "github.com/go-ozzo/ozzo-validation/v4"
//)
//
// func (v Validator) ValidateGetRequest(req param.KindBoxReqGetRequest) (map[string]string, error) {
// const op = "adminkindboxreqvalidator.ValidateGetRequest"
//
// if err := validation.ValidateStruct(&req,
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.KindBoxReqID,
// validation.Required,
// validation.By(v.doesKindBoxRequestExist),
// validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID))),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -1,50 +1 @@
package adminkindboxreqvalidator package adminkindboxreqvalidator
// import (
// "errors"
//
// param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
// errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
// richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
// validation "github.com/go-ozzo/ozzo-validation/v4"
//)
//
// func (v Validator) ValidateUpdateRequest(req param.KindBoxReqUpdateRequest) (map[string]string, error) {
// const op = "adminkindboxreqvalidator.ValidateUpdateRequest"
//
// if err := validation.ValidateStruct(&req,
// validation.Field(&req.CountRequested, validation.Min(MinKindBoxReq), validation.Max(MaxKindBoxReq)),
//
// validation.Field(&req.BenefactorID,
// validation.Required,
// validation.By(v.doesBenefactorExist)),
//
// validation.Field(&req.KindBoxReqID,
// validation.Required,
// validation.By(v.doesKindBoxRequestExist),
// validation.By(v.hasPendingStatus),
// validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID))),
//
// validation.Field(&req.TypeID,
// validation.By(v.doesTypeExist)),
// ); err != nil {
// fieldErrors := make(map[string]string)
//
// var errV validation.Errors
// if errors.As(err, &errV) {
// for key, value := range errV {
// if value != nil {
// fieldErrors[key] = value.Error()
// }
// }
// }
//
// return fieldErrors, richerror.New(op).
// WithMessage(errmsg.ErrorMsgInvalidInput).
// WithKind(richerror.KindInvalid).
// WithMeta(map[string]interface{}{"req": req}).
// WithErr(err)
// }
//
// return map[string]string{}, nil
//}

View File

@ -15,11 +15,7 @@ const (
) )
type Repository interface { type Repository interface {
// BenefactorExist(id int) (bool, error)
KindBoxRequestExist(id uint) (bool, error) KindBoxRequestExist(id uint) (bool, error)
// TypeExist(id int) (bool, error)
// KindBoxBelongToBenefactor(benefactorID uint, kindboxID uint) (bool, error)
// PendingStatus(id uint) (bool, error)
GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error) GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error)
} }
@ -31,33 +27,6 @@ func New(repo Repository) Validator {
return Validator{repo: repo} return Validator{repo: repo}
} }
// func (v Validator) doesBenefactorExist(value interface{}) error {
// benefactorID, ok := value.(int)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.BenefactorExist(benefactorID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
// }
//
// func (v Validator) doesKindBoxBelongToBenefactor(benefactorID uint) validation.RuleFunc {
// return func(value interface{}) error {
// kbID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
// _, err := v.repo.KindBoxBelongToBenefactor(benefactorID, kbID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
// }
// }
func (v Validator) doesKindBoxRequestExist(value interface{}) error { func (v Validator) doesKindBoxRequestExist(value interface{}) error {
kindboxreqID, ok := value.(uint) kindboxreqID, ok := value.(uint)
if !ok { if !ok {
@ -106,30 +75,3 @@ func (v Validator) CheckKindBoxReqStatusForRejecting(value interface{}) error {
return nil return nil
} }
//
// func (v Validator) doesTypeExist(value interface{}) error {
// typeID, ok := value.(int)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.TypeExist(typeID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
//}
//
// func (v Validator) hasPendingStatus(value interface{}) error {
// kindboxID, ok := value.(uint)
// if !ok {
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
// }
// _, err := v.repo.PendingStatus(kindboxID)
// if err != nil {
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
// }
//
// return nil
//}