fix lint
This commit is contained in:
parent
d312604e97
commit
20dcb01f55
@ -3,9 +3,9 @@ package clients
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitea.pena/PenaSide/notifier/internal/models"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"gitea.pena/PenaSide/notifier/internal/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Customer struct {
|
type Customer struct {
|
||||||
@ -41,7 +41,7 @@ func (c *Customer) GetAccount(userID string) (models.Account, error) {
|
|||||||
|
|
||||||
statusCode, body, errs := resp.Bytes()
|
statusCode, body, errs := resp.Bytes()
|
||||||
if errs != nil {
|
if errs != nil {
|
||||||
c.logger.Error("Error sending request:", zap.Error(errs[0]))
|
c.logger.Error(errSendingRequest.Error(), zap.Error(errs[0]))
|
||||||
return account, errs[0]
|
return account, errs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
internal/clients/errors.go
Normal file
7
internal/clients/errors.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package clients
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
errSendingRequest = errors.New("error sending request")
|
||||||
|
)
|
@ -82,12 +82,12 @@ func (m *MailClient) MailSender(data SenderDeps) error {
|
|||||||
|
|
||||||
statusCode, body, errs := req.Bytes()
|
statusCode, body, errs := req.Bytes()
|
||||||
if errs != nil {
|
if errs != nil {
|
||||||
m.deps.Logger.Error("Error sending request:", zap.Error(errs[0]))
|
m.deps.Logger.Error(errSendingRequest.Error(), zap.Error(errs[0]))
|
||||||
return errs[0]
|
return errs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if statusCode != fiber.StatusOK {
|
if statusCode != fiber.StatusOK {
|
||||||
err = fmt.Errorf("the SMTP service returned an error: %s Response body: %s", statusCode, body)
|
err = fmt.Errorf("the SMTP service returned an error: %d Response body: %s", statusCode, body)
|
||||||
m.deps.Logger.Error("Error sending email:", zap.Error(err))
|
m.deps.Logger.Error("Error sending email:", zap.Error(err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package clients
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"gitea.pena/PenaSide/notifier/internal/proto/notifyer"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"gitea.pena/PenaSide/notifier/internal/proto/notifyer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type QuizClient struct {
|
type QuizClient struct {
|
||||||
@ -20,10 +20,13 @@ func NewQuizClient(address string, logger *zap.Logger) *QuizClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var coreRpcHost = "core rpc host"
|
||||||
|
var request = "request"
|
||||||
|
|
||||||
func (q *QuizClient) GetQuizzes(ctx context.Context, req *notifyer.GetQuizzesRequest) (*notifyer.GetQuizzesResponse, error) {
|
func (q *QuizClient) GetQuizzes(ctx context.Context, req *notifyer.GetQuizzesRequest) (*notifyer.GetQuizzesResponse, error) {
|
||||||
connection, err := grpc.Dial(q.address, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
connection, err := grpc.Dial(q.address, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.logger.Error("failed to connect on GetQuizzes of core rpc", zap.Error(err), zap.String("core rpc host", q.address))
|
q.logger.Error("failed to connect on GetQuizzes of core rpc", zap.Error(err), zap.String(coreRpcHost, q.address))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -36,7 +39,7 @@ func (q *QuizClient) GetQuizzes(ctx context.Context, req *notifyer.GetQuizzesReq
|
|||||||
|
|
||||||
response, err := client.GetQuizzes(ctx, req)
|
response, err := client.GetQuizzes(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.logger.Error("failed to GetQuizzes core rpc", zap.Error(err), zap.Any("request", req))
|
q.logger.Error("failed to GetQuizzes core rpc", zap.Error(err), zap.Any(request, req))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ func (q *QuizClient) GetQuizzes(ctx context.Context, req *notifyer.GetQuizzesReq
|
|||||||
func (q *QuizClient) GetStartedQuizzes(ctx context.Context, req *notifyer.GetStartedQuizzesRequest) (*notifyer.GetStartedQuizzesResponse, error) {
|
func (q *QuizClient) GetStartedQuizzes(ctx context.Context, req *notifyer.GetStartedQuizzesRequest) (*notifyer.GetStartedQuizzesResponse, error) {
|
||||||
connection, err := grpc.Dial(q.address, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
connection, err := grpc.Dial(q.address, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.logger.Error("failed to connect on GetStartedQuizzes of core rpc", zap.Error(err), zap.String("core rpc host", q.address))
|
q.logger.Error("failed to connect on GetStartedQuizzes of core rpc", zap.Error(err), zap.String(coreRpcHost, q.address))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -59,7 +62,7 @@ func (q *QuizClient) GetStartedQuizzes(ctx context.Context, req *notifyer.GetSta
|
|||||||
|
|
||||||
response, err := client.GetStartedQuizzes(ctx, req)
|
response, err := client.GetStartedQuizzes(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.logger.Error("failed to GetStartedQuizzes core rpc", zap.Error(err), zap.Any("request", req))
|
q.logger.Error("failed to GetStartedQuizzes core rpc", zap.Error(err), zap.Any(request, req))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gitea.pena/PenaSide/notifier/internal/models"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"gitea.pena/PenaSide/notifier/internal/models"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,18 +40,18 @@ func (r *Repository) GetMany(ctx context.Context) ([]models.Message, error) {
|
|||||||
from := time.Now().AddDate(0, 0, -7)
|
from := time.Now().AddDate(0, 0, -7)
|
||||||
|
|
||||||
filter := bson.D{
|
filter := bson.D{
|
||||||
{"$and", bson.A{
|
{Key: "$and", Value: bson.A{
|
||||||
bson.D{
|
bson.D{
|
||||||
{"$or", bson.A{
|
{Key: "$or", Value: bson.A{
|
||||||
bson.D{{"sendRegistration", false}},
|
bson.D{{Key: "sendRegistration", Value: false}},
|
||||||
bson.D{{"sendNoneCreated", false}},
|
bson.D{{Key: "sendNoneCreated", Value: false}},
|
||||||
bson.D{{"sendUnpublished", false}},
|
bson.D{{Key: "sendUnpublished", Value: false}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
bson.D{
|
bson.D{
|
||||||
{"sendAt", bson.D{
|
{Key: "sendAt", Value: bson.D{
|
||||||
{"$gte", to},
|
{Key: "$gte", Value: to},
|
||||||
{"$lte", from},
|
{Key: "$lte", Value: from},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
@ -58,7 +59,7 @@ func (r *Repository) GetMany(ctx context.Context) ([]models.Message, error) {
|
|||||||
|
|
||||||
cursor, err := r.mdb.Find(ctx, filter)
|
cursor, err := r.mdb.Find(ctx, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == mongo.ErrNoDocuments {
|
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||||
return []models.Message{}, nil
|
return []models.Message{}, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user