From 72bdffc962fc3dc32857d2c6def596283e3d85e5 Mon Sep 17 00:00:00 2001 From: imirazimi Date: Sat, 23 Dec 2023 01:12:57 +0330 Subject: [PATCH] fix(service): add ctx to kind_box and kind_box_req services --- service/kind_box/add.go | 6 ++++-- service/kind_box/delete.go | 8 ++++++-- service/kind_box/get_all.go | 6 ++++-- service/kind_box/get_by_id.go | 6 ++++-- service/kind_box/service.go | 16 ++++++++++------ service/kind_box/update.go | 4 +++- service/kind_box_req/add.go | 6 ++++-- service/kind_box_req/delete.go | 8 ++++++-- service/kind_box_req/get_all.go | 6 ++++-- service/kind_box_req/get_by_id.go | 6 ++++-- service/kind_box_req/service.go | 16 ++++++++++------ service/kind_box_req/update.go | 5 +++-- 12 files changed, 62 insertions(+), 31 deletions(-) diff --git a/service/kind_box/add.go b/service/kind_box/add.go index 82a6582..36c2836 100644 --- a/service/kind_box/add.go +++ b/service/kind_box/add.go @@ -1,14 +1,16 @@ package kindboxservice import ( + "context" + entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/kind_box" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) -func (s Service) Add(req param.KindBoxAddRequest) (param.KindBoxAddResponse, error) { +func (s Service) Add(ctx context.Context, req param.KindBoxAddRequest) (param.KindBoxAddResponse, error) { const op = "kindboxservice.Add" - kindBox, err := s.repo.AddKindBox(entity.KindBox{ + kindBox, err := s.repo.AddKindBox(ctx, entity.KindBox{ KindBoxReqID: req.KindBoxReqID, SenderID: req.SenderID, SerialNumber: req.SerialNumber, diff --git a/service/kind_box/delete.go b/service/kind_box/delete.go index a81829b..3f03290 100644 --- a/service/kind_box/delete.go +++ b/service/kind_box/delete.go @@ -1,8 +1,12 @@ package kindboxservice -import param "git.gocasts.ir/ebhomengo/niki/param/kind_box" +import ( + "context" -func (s Service) Delete(param.KindBoxDeleteRequest) error { + param "git.gocasts.ir/ebhomengo/niki/param/kind_box" +) + +func (s Service) Delete(ctx context.Context, req param.KindBoxDeleteRequest) error { // some code panic("not implemented") } diff --git a/service/kind_box/get_all.go b/service/kind_box/get_all.go index a1f10f7..e24a816 100644 --- a/service/kind_box/get_all.go +++ b/service/kind_box/get_all.go @@ -1,13 +1,15 @@ 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) GetAll() (param.KindBoxGetAllResponse, error) { +func (s Service) GetAll(ctx context.Context) (param.KindBoxGetAllResponse, error) { const op = "kindboxservice.GetAll" - allKindBox, err := s.repo.GetAllKindBox() + allKindBox, err := s.repo.GetAllKindBox(ctx) if err != nil { return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } diff --git a/service/kind_box/get_by_id.go b/service/kind_box/get_by_id.go index 5d68dd7..e069534 100644 --- a/service/kind_box/get_by_id.go +++ b/service/kind_box/get_by_id.go @@ -1,13 +1,15 @@ 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(req param.KindBoxGetByIDRequest) (param.KindBoxGetByIDResponse, error) { +func (s Service) GetByID(ctx context.Context, req param.KindBoxGetByIDRequest) (param.KindBoxGetByIDResponse, error) { const op = "kindboxservice.GetByID" - kindBox, err := s.repo.GetKindBoxByID(req.KindBoxID) + kindBox, err := s.repo.GetKindBoxByID(ctx, req.KindBoxID) if err != nil { return param.KindBoxGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } diff --git a/service/kind_box/service.go b/service/kind_box/service.go index b2230f7..6addb7a 100644 --- a/service/kind_box/service.go +++ b/service/kind_box/service.go @@ -1,13 +1,17 @@ package kindboxservice -import "git.gocasts.ir/ebhomengo/niki/entity" +import ( + "context" + + "git.gocasts.ir/ebhomengo/niki/entity" +) type Repository interface { - AddKindBox(kindBox entity.KindBox) (entity.KindBox, error) - EditKindBox(kindBoxID uint, kindBoxInput entity.KindBox) (entity.KindBox, error) - DeleteKindBox(kindBoxID uint) error - GetAllKindBox() ([]entity.KindBox, error) - GetKindBoxByID(kindBox uint) (entity.KindBox, error) + AddKindBox(ctx context.Context, kindBox entity.KindBox) (entity.KindBox, error) + EditKindBox(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) + GetKindBoxByID(ctx context.Context, kindBox uint) (entity.KindBox, error) } type Service struct { diff --git a/service/kind_box/update.go b/service/kind_box/update.go index 89b78f5..e8f7505 100644 --- a/service/kind_box/update.go +++ b/service/kind_box/update.go @@ -1,10 +1,12 @@ package kindboxservice import ( + "context" + param "git.gocasts.ir/ebhomengo/niki/param/kind_box" ) -func (s Service) Update(updatedKindBox param.KindBoxUpdateRequest) (param.KindBoxUpdateResponse, error) { +func (s Service) Update(ctx context.Context, req param.KindBoxUpdateRequest) (param.KindBoxUpdateResponse, error) { // some code panic("not implement") } diff --git a/service/kind_box_req/add.go b/service/kind_box_req/add.go index 0b715a0..0825b2d 100644 --- a/service/kind_box_req/add.go +++ b/service/kind_box_req/add.go @@ -1,14 +1,16 @@ package kindboxreqservice import ( + "context" + entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) -func (s Service) Add(req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) { +func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) { const op = "kindboxreqservice.Add" - kindBoxReq, err := s.repo.AddKindBoxReq(entity.KindBoxReq{ + kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ TypeID: req.TypeID, CountRequested: req.CountRequested, BenefactorID: req.BenefactorID, diff --git a/service/kind_box_req/delete.go b/service/kind_box_req/delete.go index d3cd031..a4cec7d 100644 --- a/service/kind_box_req/delete.go +++ b/service/kind_box_req/delete.go @@ -1,8 +1,12 @@ package kindboxreqservice -import param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req" +import ( + "context" -func (s Service) Delete(kindBoxReqID param.KindBoxReqDeleteRequest) error { + 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") } diff --git a/service/kind_box_req/get_all.go b/service/kind_box_req/get_all.go index 5cf8106..3552357 100644 --- a/service/kind_box_req/get_all.go +++ b/service/kind_box_req/get_all.go @@ -1,13 +1,15 @@ 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) GetAll() (param.KindBoxReqGetAllResponse, error) { +func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) { const op = "kindboxreqservice.GetAll" - allKindBoxReq, err := s.repo.GetAllKindBoxReq() + allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx) if err != nil { return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } diff --git a/service/kind_box_req/get_by_id.go b/service/kind_box_req/get_by_id.go index 11b1170..a038d27 100644 --- a/service/kind_box_req/get_by_id.go +++ b/service/kind_box_req/get_by_id.go @@ -1,13 +1,15 @@ 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(req param.KindBoxReqGetByIDRequest) (param.KindBoxReqGetByIDResponse, error) { +func (s Service) GetByID(ctx context.Context, req param.KindBoxReqGetByIDRequest) (param.KindBoxReqGetByIDResponse, error) { const op = "kindboxreqservice.GetByID" - kindBoxReq, err := s.repo.GetKindBoxReqByID(req.KindBoxReqID) + kindBoxReq, err := s.repo.GetKindBoxReqByID(ctx, req.KindBoxReqID) if err != nil { return param.KindBoxReqGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } diff --git a/service/kind_box_req/service.go b/service/kind_box_req/service.go index 654f021..8a1fd34 100644 --- a/service/kind_box_req/service.go +++ b/service/kind_box_req/service.go @@ -1,13 +1,17 @@ package kindboxreqservice -import "git.gocasts.ir/ebhomengo/niki/entity" +import ( + "context" + + "git.gocasts.ir/ebhomengo/niki/entity" +) type Repository interface { - AddKindBoxReq(kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) - EditKindBoxReq(kindBoxReqID uint, kindBoxReqInput entity.KindBoxReq) (entity.KindBoxReq, error) - DeleteKindBoxReq(kindBoxReqID uint) error - GetAllKindBoxReq() ([]entity.KindBoxReq, error) - GetKindBoxReqByID(kindBoxReq uint) (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) + DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error + GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error) + GetKindBoxReqByID(ctx context.Context, kindBoxReq uint) (entity.KindBoxReq, error) } type Service struct { diff --git a/service/kind_box_req/update.go b/service/kind_box_req/update.go index e410256..c47d22f 100644 --- a/service/kind_box_req/update.go +++ b/service/kind_box_req/update.go @@ -1,11 +1,12 @@ 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) Update(req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) { +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 {