fix linter

This commit is contained in:
pasha1coil 2023-12-01 14:27:44 +03:00
parent 8b1a064e26
commit 87bc32ca80
6 changed files with 16 additions and 10 deletions

@ -23,7 +23,6 @@ type TemplateClient struct {
} }
func NewTemplateClient(deps TemplateClientDeps) *TemplateClient { func NewTemplateClient(deps TemplateClientDeps) *TemplateClient {
if deps.Logger == nil { if deps.Logger == nil {
log.Panicln("logger is nil on <NewTemplateClient>") log.Panicln("logger is nil on <NewTemplateClient>")
} }
@ -72,7 +71,7 @@ func (receiver *TemplateClient) SendData(ctx context.Context, data models.RespGe
return errors.New(err, errors.ErrInternalError) 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 { if err != nil {
return errors.New(err, errors.ErrInternalError) return errors.New(err, errors.ErrInternalError)
} }

@ -22,7 +22,6 @@ type VerificationClient struct {
} }
func NewVerificationClient(deps VerificationClientDeps) *VerificationClient { func NewVerificationClient(deps VerificationClientDeps) *VerificationClient {
if deps.Logger == nil { if deps.Logger == nil {
log.Panicln("logger is nil on <NewVerificationClient>") log.Panicln("logger is nil on <NewVerificationClient>")
} }

@ -16,7 +16,7 @@ import (
type historyService interface { type historyService interface {
GetHistoryList(context.Context, *dto.GetHistories) (*models.PaginationResponse[models.History], errors.Error) GetHistoryList(context.Context, *dto.GetHistories) (*models.PaginationResponse[models.History], errors.Error)
GetRecentTariffs(context.Context, string) ([]models.TariffID, errors.Error) // new 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 { type Deps struct {
@ -98,7 +98,7 @@ func (receiver *Controller) GetRecentTariffs(ctx echo.Context) error {
func (receiver *Controller) SendReport(ctx echo.Context) error { func (receiver *Controller) SendReport(ctx echo.Context) error {
historyID := ctx.Param("id") historyID := ctx.Param("id")
err := receiver.historyService.GetHistoryById(ctx.Request().Context(), historyID) err := receiver.historyService.GetHistoryByID(ctx.Request().Context(), historyID)
if err != nil { if err != nil {
receiver.logger.Error("failed to send report on <SendReport> of <HistoryController>", zap.Error(err)) receiver.logger.Error("failed to send report on <SendReport> of <HistoryController>", zap.Error(err))
return errors.HTTP(ctx, err) return errors.HTTP(ctx, err)

@ -157,7 +157,7 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
return result, nil return result, nil
} }
// TODO:tests // TODO:tests.
func (receiver *HistoryRepository) GetHistoryById(ctx context.Context, historyID string) (*models.ReportHistory, errors.Error) { func (receiver *HistoryRepository) GetHistoryById(ctx context.Context, historyID string) (*models.ReportHistory, errors.Error) {
history := &models.ReportHistory{} history := &models.ReportHistory{}
err := receiver.mongoDB.FindOne(ctx, bson.M{"_id": historyID}).Decode(history) 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 return history, nil
} }
// TODO:tests // TODO:tests.
func (receiver *HistoryRepository) GetDocNumber(ctx context.Context, userID string) (map[string]int, errors.Error) { func (receiver *HistoryRepository) GetDocNumber(ctx context.Context, userID string) (map[string]int, errors.Error) {
findOptions := options.Find() findOptions := options.Find()
findOptions.SetSort(bson.D{{Key: "createdAt", Value: 1}}) findOptions.SetSort(bson.D{{Key: "createdAt", Value: 1}})
@ -204,7 +204,15 @@ func (receiver *HistoryRepository) GetDocNumber(ctx context.Context, userID stri
errors.ErrInternalError, errors.ErrInternalError,
) )
} }
defer cursor.Close(ctx)
defer func() {
if err := cursor.Close(ctx); err != nil {
receiver.logger.Error("failed to close cursor on <GetDocNumber> of <HistoryRepository>",
zap.String("userId", userID),
zap.Error(err),
)
}
}()
result := make(map[string]int) result := make(map[string]int)
var count int var count int

@ -15,5 +15,5 @@ type Verification struct {
type VerificationFile struct { type VerificationFile struct {
Name string `json:"name" bson:"name"` Name string `json:"name" bson:"name"`
Url string `json:"url" bson:"url"` URL string `json:"url" bson:"url"`
} }

@ -142,7 +142,7 @@ func (receiver *Service) GetRecentTariffs(ctx context.Context, userID string) ([
return tariffs, nil 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 == "" { if historyID == "" {
receiver.logger.Error("history id is missing in <GetHistoryById> of <HistoryService>") receiver.logger.Error("history id is missing in <GetHistoryById> of <HistoryService>")
return errors.New( return errors.New(