forked from ebhomengo/niki
1
0
Fork 0

fix(niki): refactor folder structure

This commit is contained in:
imirazimi 2023-12-25 20:38:19 +03:30
parent 72bdffc962
commit 1a093a6d69
43 changed files with 430 additions and 152 deletions

View File

@ -1,6 +1,6 @@
package param package adminkindboxparam
import "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxAddRequest struct { type KindBoxAddRequest struct {
KindBoxReqID uint KindBoxReqID uint

View File

@ -1,4 +1,4 @@
package param package adminkindboxparam
type KindBoxDeleteRequest struct { type KindBoxDeleteRequest struct {
KindBoxID uint KindBoxID uint

View File

@ -0,0 +1,11 @@
package adminkindboxparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxGetRequest struct {
KindBoxID uint
}
type KindBoxGetResponse struct {
entity.KindBox
}

View File

@ -1,6 +1,6 @@
package param package adminkindboxparam
import "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxGetAllRequest struct{} type KindBoxGetAllRequest struct{}

View File

@ -0,0 +1,15 @@
package adminkindboxparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxUpdateRequest struct {
TotalAmount uint
ReceiverID uint
SenderID uint
SerialNumber string
Status KindBoxStatus
}
type KindBoxUpdateResponse struct {
KindBox entity.KindBox
}

View File

@ -0,0 +1,13 @@
package adminkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqAddRequest struct {
BenefactorID uint
TypeID uint
CountRequested uint
}
type KindBoxReqAddResponse struct {
KindBoxReq entity.KindBoxReq
}

View File

@ -1,4 +1,4 @@
package param package adminkindboxreqparam
type KindBoxReqDeleteRequest struct { type KindBoxReqDeleteRequest struct {
KindBoxReqID uint KindBoxReqID uint

View File

@ -0,0 +1,11 @@
package adminkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqGetRequest struct {
KindBoxReqID uint
}
type KindBoxReqGetResponse struct {
entity.KindBoxReq
}

View File

@ -0,0 +1,9 @@
package adminkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqGetAllRequest struct {}
type KindBoxReqGetAllResponse struct {
AllKindBoxReq []entity.KindBoxReq
}

View File

@ -0,0 +1,14 @@
package adminkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqUpdateRequest struct {
BenefactorID uint
KindBoxReqID uint
TypeID uint
CountRequested uint
}
type KindBoxReqUpdateResponse struct {
KindBoxReq entity.KindBoxReq
}

View File

@ -1,11 +1,11 @@
package param package userkindboxreqparam
import "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqAddRequest struct { type KindBoxReqAddRequest struct {
CountRequested uint
BenefactorID uint BenefactorID uint
TypeID uint TypeID uint
CountRequested uint
} }
type KindBoxReqAddResponse struct { type KindBoxReqAddResponse struct {

View File

@ -0,0 +1,8 @@
package userkindboxreqparam
type KindBoxReqDeleteRequest struct {
BenfactorID uint
KindBoxReqID uint
}
type KindBoxReqDeleteResponse struct{}

View File

@ -0,0 +1,12 @@
package userkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqGetRequest struct {
BenefactorID uint
KindBoxReqID uint
}
type KindBoxReqGetResponse struct {
entity.KindBoxReq
}

View File

@ -0,0 +1,11 @@
package userkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqGetAllRequest struct {
BenefactorID uint
}
type KindBoxReqGetAllResponse struct {
AllKindBoxReq []entity.KindBoxReq
}

View File

@ -0,0 +1,14 @@
package userkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqUpdateRequest struct {
BenefactorID uint
KindBoxReqID uint
TypeID uint
CountRequested uint
}
type KindBoxReqUpdateResponse struct {
KindBoxReq entity.KindBoxReq
}

View File

@ -1,11 +0,0 @@
package param
import "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxGetByIDRequest struct {
KindBoxID uint
}
type KindBoxGetByIDResponse struct {
entity.KindBox
}

View File

@ -1,11 +0,0 @@
package param
import "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxUpdateRequest struct {
KindBox entity.KindBox
}
type KindBoxUpdateResponse struct {
KindBox entity.KindBox
}

View File

@ -1,9 +0,0 @@
package param
import "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqGetAllRequest struct{}
type KindBoxReqGetAllResponse struct {
AllKindBoxReq []entity.KindBoxReq
}

View File

@ -1,11 +0,0 @@
package param
import "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqGetByIDRequest struct {
KindBoxReqID uint
}
type KindBoxReqGetByIDResponse struct {
entity.KindBoxReq
}

View File

@ -1,11 +0,0 @@
package param
import "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqUpdateRequest struct {
KindBoxReq entity.KindBoxReq
}
type KindBoxReqUpdateResponse struct {
KindBoxReq entity.KindBoxReq
}

View File

@ -1,7 +1,15 @@
package errmsg package errmsg
const ( const (
ErrorMsgNotFound = "record not found" ErrorMsgNotFound = "record not found"
ErrorMsgSomethingWentWrong = "something went wrong" ErrorMsgSomethingWentWrong = "something went wrong"
ErrorMsgInvalidInput = "invalid input" ErrorMsgInvalidInput = "invalid input"
ErrorMsgInvalidStatus = "invalid status"
ErrorMsgPhoneNumberIsNotUnique = "phone number is not unique"
ErrorMsgPhoneNumberIsNotValid = "phone number is not valid"
ErrorMsgUserNotAllowed = "user not allowed"
) )
// const (
// ErrorMsgCantScanQueryResult = "can't scan query result"
// )

View File

@ -1,15 +1,15 @@
package kindboxservice package adminkindboxservice
import ( import (
"context" "context"
entity "git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
) )
func (s Service) Add(ctx context.Context, req param.KindBoxAddRequest) (param.KindBoxAddResponse, error) { func (s Service) Add(ctx context.Context, req param.KindBoxAddRequest) (param.KindBoxAddResponse, error) {
const op = "kindboxservice.Add" const op = "adminkindboxservice.Add"
kindBox, err := s.repo.AddKindBox(ctx, entity.KindBox{ kindBox, err := s.repo.AddKindBox(ctx, entity.KindBox{
KindBoxReqID: req.KindBoxReqID, KindBoxReqID: req.KindBoxReqID,
SenderID: req.SenderID, SenderID: req.SenderID,

View File

@ -1,9 +1,9 @@
package kindboxservice package adminkindboxservice
import ( import (
"context" "context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
) )
func (s Service) Delete(ctx context.Context, req param.KindBoxDeleteRequest) error { func (s Service) Delete(ctx context.Context, req param.KindBoxDeleteRequest) error {

View File

@ -0,0 +1,17 @@
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,14 +1,14 @@
package kindboxservice package adminkindboxservice
import ( import (
"context" "context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
) )
func (s Service) GetAll(ctx context.Context) (param.KindBoxGetAllResponse, error) { func (s Service) GetAll(ctx context.Context) (param.KindBoxGetAllResponse, error) {
const op = "kindboxservice.GetAll" const op = "adminkindboxservice.GetAll"
allKindBox, err := s.repo.GetAllKindBox(ctx) allKindBox, err := s.repo.GetAllKindBox(ctx)
if err != nil { if err != nil {
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)

View File

@ -1,9 +1,9 @@
package kindboxservice package adminkindboxservice
import ( import (
"context" "context"
"git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
) )
type Repository interface { type Repository interface {
@ -11,7 +11,7 @@ type Repository interface {
EditKindBox(ctx context.Context, kindBoxID uint, kindBoxInput entity.KindBox) (entity.KindBox, error) EditKindBox(ctx context.Context, kindBoxID uint, kindBoxInput entity.KindBox) (entity.KindBox, error)
DeleteKindBox(ctx context.Context, kindBoxID uint) error DeleteKindBox(ctx context.Context, kindBoxID uint) error
GetAllKindBox(ctx context.Context) ([]entity.KindBox, error) GetAllKindBox(ctx context.Context) ([]entity.KindBox, error)
GetKindBoxByID(ctx context.Context, kindBox uint) (entity.KindBox, error) GetKindBox(ctx context.Context, kindBox uint) (entity.KindBox, error)
} }
type Service struct { type Service struct {

View File

@ -1,9 +1,9 @@
package kindboxservice package adminkindboxservice
import ( import (
"context" "context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
) )
func (s Service) Update(ctx context.Context, req param.KindBoxUpdateRequest) (param.KindBoxUpdateResponse, error) { func (s Service) Update(ctx context.Context, req param.KindBoxUpdateRequest) (param.KindBoxUpdateResponse, error) {

View File

@ -0,0 +1,26 @@
package adminkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
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,
TypeID: 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

@ -0,0 +1,21 @@
package adminkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/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 bussiness 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(err).WithKind(richerror.KindUnexpected)
}
return param.KindBoxReqDeleteResponse{KindBoxReq: kindBoxReq}, nil
}

View File

@ -0,0 +1,21 @@
package adminkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/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"
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,17 +1,21 @@
package kindboxreqservice package adminkindboxreqservice
import ( import (
"context" "context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
) )
// TODO: Pagination, Filters, Sort
func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) { func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) {
const op = "kindboxreqservice.GetAll"
const op = "adminkindboxreqservice.GetAll"
allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx) allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx)
if err != nil { if err != nil {
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
} }
return param.KindBoxReqGetAllResponse{AllKindBoxReq: allKindBoxReq}, nil return param.KindBoxReqGetAllResponse{AllKindBoxReq: allKindBoxReq}, nil
} }

View File

@ -1,17 +1,18 @@
package kindboxreqservice package adminkindboxreqservice
import ( import (
"context" "context"
"git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
) )
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)
EditKindBoxReq(ctx context.Context, kindBoxReqID uint, kindBoxReqInput 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 DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error
GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error) GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error)
GetKindBoxReqByID(ctx context.Context, kindBoxReq uint) (entity.KindBoxReq, error) GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
} }
type Service struct { type Service struct {

View File

@ -0,0 +1,37 @@
package adminkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
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"
kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
if gErr != nil {
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
}
if kbr.Status != KindBoxReqPendingStatus {
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid)
}
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,23 +1,25 @@
package kindboxreqservice package userkindboxreqservice
import ( import (
"context" "context"
entity "git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
) )
func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) { func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
const op = "kindboxreqservice.Add" const op = "userkindboxreqservice.Add"
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
BenefactorID: req.BenefactorID,
TypeID: req.TypeID, TypeID: req.TypeID,
CountRequested: req.CountRequested, CountRequested: req.CountRequested,
BenefactorID: req.BenefactorID,
Status: entity.KindBoxReqPendingStatus, Status: entity.KindBoxReqPendingStatus,
}) })
if err != nil { if err != nil {
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
} }
return param.KindBoxReqAddResponse{KindBoxReq: kindBoxReq}, nil return param.KindBoxReqAddResponse{KindBoxReq: kindBoxReq}, nil
} }

View File

@ -0,0 +1,32 @@
package userkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/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 bussiness domain need to delete an kindboxreq ?
const op = "userkindboxreqservice.Delete"
kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
if gErr != nil {
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
}
if kbr.Status != KindBoxReqPendingStatus {
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid)
}
if kbr.BenefactorID != req.BenefactorID {
return param.KindBoxReqGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
}
dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
if dErr != nil {
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
return param.KindBoxReqDeleteResponse{KindBoxReq: kindBoxReq}, nil
}

View File

@ -0,0 +1,25 @@
package userkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/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 = "userkindboxreqservice.Get"
kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
if err != nil {
return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
// TODO : ref to service.Update()
if kindBoxReq.BenefactorID != req.BenefactorID {
return param.KindBoxReqGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
}
return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil
}

View File

@ -0,0 +1,21 @@
package userkindboxreqservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
// TODO: Pagination, Filters, Sort
func (s Service) GetAll(ctx context.Context) (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

@ -0,0 +1,26 @@
package userkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
)
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, benefactorID uint) ([]entity.KindBoxReq, error)
GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
}
type Service struct {
repo Repository
}
func New(repository Repository) Service {
return Service{
repo: repository,
}
}

View File

@ -0,0 +1,35 @@
package userkindboxreqservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
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 ?
const op = "userkindboxreqservice.Update"
kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
if gErr != nil {
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
}
if kbr.Status != KindBoxReqPendingStatus {
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid)
}
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,17 +0,0 @@
package kindboxservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetByID(ctx context.Context, req param.KindBoxGetByIDRequest) (param.KindBoxGetByIDResponse, error) {
const op = "kindboxservice.GetByID"
kindBox, err := s.repo.GetKindBoxByID(ctx, req.KindBoxID)
if err != nil {
return param.KindBoxGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
return param.KindBoxGetByIDResponse{KindBox: kindBox}, nil
}

View File

@ -1,12 +0,0 @@
package kindboxreqservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req"
)
func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) error {
// some code
panic("not implemented")
}

View File

@ -1,17 +0,0 @@
package kindboxreqservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetByID(ctx context.Context, req param.KindBoxReqGetByIDRequest) (param.KindBoxReqGetByIDResponse, error) {
const op = "kindboxreqservice.GetByID"
kindBoxReq, err := s.repo.GetKindBoxReqByID(ctx, req.KindBoxReqID)
if err != nil {
return param.KindBoxReqGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
return param.KindBoxReqGetByIDResponse{KindBoxReq: kindBoxReq}, nil
}

View File

@ -1,17 +0,0 @@
package kindboxreqservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req"
)
func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) {
// const op = "kindboxreqservice.Update"
// kindBoxReq, err := s.repo.EditKindBoxReq(req.KindBoxReq.ID, req.KindBoxReq)
// if err != nil {
// return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
// }
// return param.KindBoxReqUpdateResponse{KindBoxReq: kindBoxReq}, nil
panic("not implemented")
}