fix(service): add ctx to kind_box and kind_box_req services

This commit is contained in:
imirazimi 2023-12-23 01:12:57 +03:30
parent 7d76ea2d50
commit 72bdffc962
12 changed files with 62 additions and 31 deletions

View File

@ -1,14 +1,16 @@
package kindboxservice package kindboxservice
import ( import (
"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/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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" const op = "kindboxservice.Add"
kindBox, err := s.repo.AddKindBox(entity.KindBox{ kindBox, err := s.repo.AddKindBox(ctx, entity.KindBox{
KindBoxReqID: req.KindBoxReqID, KindBoxReqID: req.KindBoxReqID,
SenderID: req.SenderID, SenderID: req.SenderID,
SerialNumber: req.SerialNumber, SerialNumber: req.SerialNumber,

View File

@ -1,8 +1,12 @@
package kindboxservice 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 // some code
panic("not implemented") panic("not implemented")
} }

View File

@ -1,13 +1,15 @@
package kindboxservice package kindboxservice
import ( import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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" const op = "kindboxservice.GetAll"
allKindBox, err := s.repo.GetAllKindBox() 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,13 +1,15 @@
package kindboxservice package kindboxservice
import ( import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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" const op = "kindboxservice.GetByID"
kindBox, err := s.repo.GetKindBoxByID(req.KindBoxID) kindBox, err := s.repo.GetKindBoxByID(ctx, req.KindBoxID)
if err != nil { if err != nil {
return param.KindBoxGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return param.KindBoxGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
} }

View File

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

View File

@ -1,10 +1,12 @@
package kindboxservice package kindboxservice
import ( import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box" 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 // some code
panic("not implement") panic("not implement")
} }

View File

@ -1,14 +1,16 @@
package kindboxreqservice package kindboxreqservice
import ( import (
"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/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(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 = "kindboxreqservice.Add"
kindBoxReq, err := s.repo.AddKindBoxReq(entity.KindBoxReq{ kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
TypeID: req.TypeID, TypeID: req.TypeID,
CountRequested: req.CountRequested, CountRequested: req.CountRequested,
BenefactorID: req.BenefactorID, BenefactorID: req.BenefactorID,

View File

@ -1,8 +1,12 @@
package kindboxreqservice 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 // some code
panic("not implemented") panic("not implemented")
} }

View File

@ -1,13 +1,15 @@
package kindboxreqservice package kindboxreqservice
import ( import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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" const op = "kindboxreqservice.GetAll"
allKindBoxReq, err := s.repo.GetAllKindBoxReq() 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)
} }

View File

@ -1,13 +1,15 @@
package kindboxreqservice package kindboxreqservice
import ( import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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" const op = "kindboxreqservice.GetByID"
kindBoxReq, err := s.repo.GetKindBoxReqByID(req.KindBoxReqID) kindBoxReq, err := s.repo.GetKindBoxReqByID(ctx, req.KindBoxReqID)
if err != nil { if err != nil {
return param.KindBoxReqGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return param.KindBoxReqGetByIDResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
} }

View File

@ -1,13 +1,17 @@
package kindboxreqservice package kindboxreqservice
import "git.gocasts.ir/ebhomengo/niki/entity" import (
"context"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Repository interface { type Repository interface {
AddKindBoxReq(kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
EditKindBoxReq(kindBoxReqID uint, kindBoxReqInput entity.KindBoxReq) (entity.KindBoxReq, error) EditKindBoxReq(ctx context.Context, kindBoxReqID uint, kindBoxReqInput entity.KindBoxReq) (entity.KindBoxReq, error)
DeleteKindBoxReq(kindBoxReqID uint) error DeleteKindBoxReq(ctx context.Context, kindBoxReqID uint) error
GetAllKindBoxReq() ([]entity.KindBoxReq, error) GetAllKindBoxReq(ctx context.Context) ([]entity.KindBoxReq, error)
GetKindBoxReqByID(kindBoxReq uint) (entity.KindBoxReq, error) GetKindBoxReqByID(ctx context.Context, kindBoxReq uint) (entity.KindBoxReq, error)
} }
type Service struct { type Service struct {

View File

@ -1,11 +1,12 @@
package kindboxreqservice package kindboxreqservice
import ( import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/kind_box_req" 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" // const op = "kindboxreqservice.Update"
// kindBoxReq, err := s.repo.EditKindBoxReq(req.KindBoxReq.ID, req.KindBoxReq) // kindBoxReq, err := s.repo.EditKindBoxReq(req.KindBoxReq.ID, req.KindBoxReq)
// if err != nil { // if err != nil {