From 87bc32ca8045f411c3e75da628e8f36fb0117522 Mon Sep 17 00:00:00 2001 From: pasha1coil Date: Fri, 1 Dec 2023 14:27:44 +0300 Subject: [PATCH] fix linter --- internal/interface/client/templategen.go | 3 +-- internal/interface/client/verification.go | 1 - .../interface/controller/rest/history/history.go | 4 ++-- internal/interface/repository/history.go | 14 +++++++++++--- internal/models/verification.go | 2 +- internal/service/history/history.go | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/interface/client/templategen.go b/internal/interface/client/templategen.go index 19914b0..a625593 100644 --- a/internal/interface/client/templategen.go +++ b/internal/interface/client/templategen.go @@ -23,7 +23,6 @@ type TemplateClient struct { } func NewTemplateClient(deps TemplateClientDeps) *TemplateClient { - if deps.Logger == nil { log.Panicln("logger is nil on ") } @@ -72,7 +71,7 @@ func (receiver *TemplateClient) SendData(ctx context.Context, data models.RespGe return errors.New(err, errors.ErrInternalError) } - req, err := http.NewRequestWithContext(ctx, "POST", tmplURL, body) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, tmplURL, body) if err != nil { return errors.New(err, errors.ErrInternalError) } diff --git a/internal/interface/client/verification.go b/internal/interface/client/verification.go index 2608f8e..3b8212a 100644 --- a/internal/interface/client/verification.go +++ b/internal/interface/client/verification.go @@ -22,7 +22,6 @@ type VerificationClient struct { } func NewVerificationClient(deps VerificationClientDeps) *VerificationClient { - if deps.Logger == nil { log.Panicln("logger is nil on ") } diff --git a/internal/interface/controller/rest/history/history.go b/internal/interface/controller/rest/history/history.go index 8807d59..5a3d07a 100644 --- a/internal/interface/controller/rest/history/history.go +++ b/internal/interface/controller/rest/history/history.go @@ -16,7 +16,7 @@ import ( type historyService interface { GetHistoryList(context.Context, *dto.GetHistories) (*models.PaginationResponse[models.History], errors.Error) GetRecentTariffs(context.Context, string) ([]models.TariffID, errors.Error) // new - GetHistoryById(context.Context, string) errors.Error // new + GetHistoryByID(context.Context, string) errors.Error // new } type Deps struct { @@ -98,7 +98,7 @@ func (receiver *Controller) GetRecentTariffs(ctx echo.Context) error { func (receiver *Controller) SendReport(ctx echo.Context) error { historyID := ctx.Param("id") - err := receiver.historyService.GetHistoryById(ctx.Request().Context(), historyID) + err := receiver.historyService.GetHistoryByID(ctx.Request().Context(), historyID) if err != nil { receiver.logger.Error("failed to send report on of ", zap.Error(err)) return errors.HTTP(ctx, err) diff --git a/internal/interface/repository/history.go b/internal/interface/repository/history.go index c8ff32c..714b6b8 100644 --- a/internal/interface/repository/history.go +++ b/internal/interface/repository/history.go @@ -157,7 +157,7 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID return result, nil } -// TODO:tests +// TODO:tests. func (receiver *HistoryRepository) GetHistoryById(ctx context.Context, historyID string) (*models.ReportHistory, errors.Error) { history := &models.ReportHistory{} err := receiver.mongoDB.FindOne(ctx, bson.M{"_id": historyID}).Decode(history) @@ -184,7 +184,7 @@ func (receiver *HistoryRepository) GetHistoryById(ctx context.Context, historyID return history, nil } -// TODO:tests +// TODO:tests. func (receiver *HistoryRepository) GetDocNumber(ctx context.Context, userID string) (map[string]int, errors.Error) { findOptions := options.Find() findOptions.SetSort(bson.D{{Key: "createdAt", Value: 1}}) @@ -204,7 +204,15 @@ func (receiver *HistoryRepository) GetDocNumber(ctx context.Context, userID stri errors.ErrInternalError, ) } - defer cursor.Close(ctx) + + defer func() { + if err := cursor.Close(ctx); err != nil { + receiver.logger.Error("failed to close cursor on of ", + zap.String("userId", userID), + zap.Error(err), + ) + } + }() result := make(map[string]int) var count int diff --git a/internal/models/verification.go b/internal/models/verification.go index ef987ae..240a7a0 100644 --- a/internal/models/verification.go +++ b/internal/models/verification.go @@ -15,5 +15,5 @@ type Verification struct { type VerificationFile struct { Name string `json:"name" bson:"name"` - Url string `json:"url" bson:"url"` + URL string `json:"url" bson:"url"` } diff --git a/internal/service/history/history.go b/internal/service/history/history.go index b82d1f3..8bfcb0f 100644 --- a/internal/service/history/history.go +++ b/internal/service/history/history.go @@ -142,7 +142,7 @@ func (receiver *Service) GetRecentTariffs(ctx context.Context, userID string) ([ return tariffs, nil } -func (receiver *Service) GetHistoryById(ctx context.Context, historyID string) errors.Error { +func (receiver *Service) GetHistoryByID(ctx context.Context, historyID string) errors.Error { if historyID == "" { receiver.logger.Error("history id is missing in of ") return errors.New(