From 6853ddaf647bb26a9abbd05a6fa9ebae8b739610 Mon Sep 17 00:00:00 2001 From: Abolfazl Nourzad Date: Thu, 25 Jan 2024 21:29:18 +0330 Subject: [PATCH] fix linter errors --- delivery/http_server/admin/kind_box/get.go | 2 +- delivery/http_server/admin/kind_box/get_all.go | 2 +- delivery/http_server/admin/kind_box/route.go | 5 ++--- delivery/http_server/admin/kind_box/update.go | 2 +- main.go | 1 - repository/mysql/kind_box/kind_box.go | 1 + repository/mysql/kind_box_req/kind_box_req.go | 18 +++++++++++++++--- service/admin/kind_box_req/accept.go | 4 +++- validator/admin/kind_box/validator.go | 4 ++-- validator/admin/kind_box_req/validator.go | 2 +- 10 files changed, 27 insertions(+), 14 deletions(-) diff --git a/delivery/http_server/admin/kind_box/get.go b/delivery/http_server/admin/kind_box/get.go index 518abfa..1ff0ff5 100644 --- a/delivery/http_server/admin/kind_box/get.go +++ b/delivery/http_server/admin/kind_box/get.go @@ -8,7 +8,7 @@ package adminkindboxhandler // echo "github.com/labstack/echo/v4" //) // -//func (h Handler) Get(c echo.Context) error { +// func (h Handler) Get(c echo.Context) error { // var req param.KindBoxGetRequest // if bErr := c.Bind(&req); bErr != nil { // return echo.NewHTTPError(http.StatusBadRequest) diff --git a/delivery/http_server/admin/kind_box/get_all.go b/delivery/http_server/admin/kind_box/get_all.go index 2e04c65..c39e2a2 100644 --- a/delivery/http_server/admin/kind_box/get_all.go +++ b/delivery/http_server/admin/kind_box/get_all.go @@ -9,7 +9,7 @@ package adminkindboxhandler // echo "github.com/labstack/echo/v4" //) // -//func (h Handler) GetAll(c echo.Context) error { +// func (h Handler) GetAll(c echo.Context) error { // var req param.KindBoxGetAllRequest // if bErr := c.Bind(&req); bErr != nil { // return echo.NewHTTPError(http.StatusBadRequest) diff --git a/delivery/http_server/admin/kind_box/route.go b/delivery/http_server/admin/kind_box/route.go index 4bad945..72d97ce 100644 --- a/delivery/http_server/admin/kind_box/route.go +++ b/delivery/http_server/admin/kind_box/route.go @@ -4,9 +4,8 @@ import ( echo "github.com/labstack/echo/v4" ) -func (h Handler) SetRoutes(e *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" diff --git a/delivery/http_server/admin/kind_box/update.go b/delivery/http_server/admin/kind_box/update.go index 0f640c6..e52ad0a 100644 --- a/delivery/http_server/admin/kind_box/update.go +++ b/delivery/http_server/admin/kind_box/update.go @@ -8,7 +8,7 @@ package adminkindboxhandler // echo "github.com/labstack/echo/v4" //) // -//func (h Handler) Update(c echo.Context) error { +// func (h Handler) Update(c echo.Context) error { // var req param.KindBoxUpdateRequest // if bErr := c.Bind(&req); bErr != nil { // return echo.NewHTTPError(http.StatusBadRequest) diff --git a/main.go b/main.go index f7d65e0..ed797ce 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,6 @@ func setupServices(cfg config.Config) ( adminSvc adminservice.Service, adminVld adminvalidator.Validator, adminAuthSvc adminauthservice.Service, adminKindBoxReqSvc adminkindboxreqservice.Service, adminKindBoxReqVld adminkindboxreqvalidator.Validator, - ) { authSvc = authservice.New(cfg.Auth) diff --git a/repository/mysql/kind_box/kind_box.go b/repository/mysql/kind_box/kind_box.go index 98a49f6..c910f3f 100644 --- a/repository/mysql/kind_box/kind_box.go +++ b/repository/mysql/kind_box/kind_box.go @@ -2,6 +2,7 @@ package mysqlkindbox import ( "context" + "git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/logger" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" diff --git a/repository/mysql/kind_box_req/kind_box_req.go b/repository/mysql/kind_box_req/kind_box_req.go index 0a86519..9889051 100644 --- a/repository/mysql/kind_box_req/kind_box_req.go +++ b/repository/mysql/kind_box_req/kind_box_req.go @@ -6,6 +6,7 @@ import ( "errors" "git.gocasts.ir/ebhomengo/niki/entity" + "git.gocasts.ir/ebhomengo/niki/logger" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) @@ -32,7 +33,11 @@ func (d DB) AcceptKindBoxReq(ctx context.Context, kindBoxReqID, countAccepted ui op := richerror.Op("mysqlkindboxreq.AcceptKindBoxReq") statement, err := d.conn.Conn(). Prepare(`update kind_box_reqs set count_accepted = ? , status = ? where id = ?`) - defer statement.Close() + defer func() { + dErr := statement.Close() + logger.L().Error(dErr.Error()) + }() + if err != nil { return richerror.New(op).WithErr(err). WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) @@ -78,7 +83,10 @@ func (d DB) RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description op := richerror.Op("mysqlkindboxreq.RejectKindBoxReq") statement, err := d.conn.Conn(). Prepare(`update kind_box_reqs set description = ? , status = ? where id = ?`) - defer statement.Close() + defer func() { + dErr := statement.Close() + logger.L().Error(dErr.Error()) + }() if err != nil { return richerror.New(op).WithErr(err). WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) @@ -96,7 +104,10 @@ func (d DB) RollbackKindBoxRequestStatus(ctx context.Context, id uint) error { op := richerror.Op("mysqlkindboxreq.RollbackKindBoxRequestStatus") statement, err := d.conn.Conn(). Prepare(`update kind_box_reqs set status = ? where id = ?`) - defer statement.Close() + defer func() { + dErr := statement.Close() + logger.L().Error(dErr.Error()) + }() if err != nil { return richerror.New(op).WithErr(err). WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) @@ -106,5 +117,6 @@ func (d DB) RollbackKindBoxRequestStatus(ctx context.Context, id uint) error { return richerror.New(op).WithErr(eErr). WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected) } + return nil } diff --git a/service/admin/kind_box_req/accept.go b/service/admin/kind_box_req/accept.go index e284e02..c39e55f 100644 --- a/service/admin/kind_box_req/accept.go +++ b/service/admin/kind_box_req/accept.go @@ -2,13 +2,14 @@ package adminkindboxreqservice import ( "context" + "git.gocasts.ir/ebhomengo/niki/logger" adminkindboxparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) -//@see +// @see // When confirming a request, should the senderID field, which represents the person sending the kind-box to the beneficiary, // be filled at the same time? Or is it acceptable to confirm the request first and fill in the senderID field later? // @@ -38,6 +39,7 @@ func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest) // log error logger.L().Error(rErr.Error()) } + return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(kErr) } diff --git a/validator/admin/kind_box/validator.go b/validator/admin/kind_box/validator.go index 66d837e..7d23ca2 100644 --- a/validator/admin/kind_box/validator.go +++ b/validator/admin/kind_box/validator.go @@ -57,7 +57,7 @@ func New(repo Repository) Validator { // return nil //} // -//func (v Validator) doesKindBoxExist(value interface{}) error { +// func (v Validator) doesKindBoxExist(value interface{}) error { // kindboxID, ok := value.(uint) // if !ok { // return fmt.Errorf(errmsg.ErrorMsgNotFound) @@ -70,7 +70,7 @@ func New(repo Repository) Validator { // return nil //} // -//func (v Validator) doesKindBoxBelongToBenefactor(benefactorID uint) validation.RuleFunc { +// func (v Validator) doesKindBoxBelongToBenefactor(benefactorID uint) validation.RuleFunc { // return func(value interface{}) error { // kbID, ok := value.(uint) // if !ok { diff --git a/validator/admin/kind_box_req/validator.go b/validator/admin/kind_box_req/validator.go index c208c1d..50a2f0d 100644 --- a/validator/admin/kind_box_req/validator.go +++ b/validator/admin/kind_box_req/validator.go @@ -4,8 +4,8 @@ import ( "context" "errors" "fmt" - "git.gocasts.ir/ebhomengo/niki/entity" + "git.gocasts.ir/ebhomengo/niki/entity" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" )