Dima 2 роки тому
батько
коміт
1bbf0c3ff1

+ 1 - 1
internal/helpers/trans.go

@@ -2,7 +2,7 @@ package helpers
 
 import (
 	"github.com/go-playground/locales/ru"
-	"github.com/go-playground/universal-translator"
+	ut "github.com/go-playground/universal-translator"
 	"github.com/go-playground/validator/v10"
 	ruTranslations "github.com/go-playground/validator/v10/translations/ru"
 )

+ 1 - 1
internal/helpers/validate.go

@@ -3,7 +3,7 @@ package helpers
 import (
 	"unicode"
 
-	"github.com/go-playground/universal-translator"
+	ut "github.com/go-playground/universal-translator"
 	"github.com/go-playground/validator/v10"
 )
 

+ 2 - 2
internal/repositories/article.go

@@ -111,14 +111,14 @@ func (a articleRepository) GetByURL(ctx context.Context, url string) (*models.Ar
 	return &res, nil
 }
 
-func (a articleRepository) GetByID(ctx context.Context, ID int) (*models.Article, error) {
+func (a articleRepository) GetByID(ctx context.Context, id int) (*models.Article, error) {
 	var res models.Article
 
 	query := "SELECT id, url, publish_time, title, image, text, preview_text, meta_keywords, meta_desc, is_active " +
 		"FROM " + articleTableName + " " +
 		"WHERE id = ? LIMIT 1"
 
-	err := a.db.QueryRowContext(ctx, query, ID).
+	err := a.db.QueryRowContext(ctx, query, id).
 		Scan(&res.ID, &res.URL, &res.PublishTime, &res.Title, &res.Image, &res.Text, &res.PreviewText, &res.MetaKeywords, &res.MetaDescription, &res.IsActive)
 
 	if err != nil {

+ 8 - 8
internal/repositories/tag.go

@@ -72,7 +72,7 @@ func (t tagRepository) GetByURL(ctx context.Context, tag string) (*models.Tag, e
 	return &res, nil
 }
 
-func (t tagRepository) GetByID(ctx context.Context, ID int) (*models.Tag, error) {
+func (t tagRepository) GetByID(ctx context.Context, id int) (*models.Tag, error) {
 	var res models.Tag
 
 	query := "SELECT id, url, tag " +
@@ -80,7 +80,7 @@ func (t tagRepository) GetByID(ctx context.Context, ID int) (*models.Tag, error)
 		"WHERE id = ? " +
 		"LIMIT 1"
 
-	err := t.db.QueryRowContext(ctx, query, ID).
+	err := t.db.QueryRowContext(ctx, query, id).
 		Scan(&res.ID, &res.URL, &res.Tag)
 
 	if err != nil {
@@ -124,14 +124,14 @@ func (t tagRepository) GetAll(ctx context.Context) ([]models.Tag, error) {
 	return res, nil
 }
 
-func (t tagRepository) GetByArticleID(ctx context.Context, ID int) ([]models.Tag, error) {
+func (t tagRepository) GetByArticleID(ctx context.Context, id int) ([]models.Tag, error) {
 	var res []models.Tag
 
 	query := "SELECT t.id, t.url, t.tag " +
 		"FROM " + articleTagTableName + " at, " + tagTableName + " t " +
 		"WHERE t.id = at.tag_id AND at.article_id = ?"
 
-	rows, err := t.db.QueryContext(ctx, query, ID)
+	rows, err := t.db.QueryContext(ctx, query, id)
 	if err != nil {
 		return nil, err
 	}
@@ -160,12 +160,12 @@ func (t tagRepository) GetByArticleID(ctx context.Context, ID int) ([]models.Tag
 	return res, nil
 }
 
-func (t tagRepository) IsUsed(ctx context.Context, ID int) (bool, error) {
+func (t tagRepository) IsUsed(ctx context.Context, id int) (bool, error) {
 	var count int
 
 	query := "SELECT COUNT(tag_id) FROM " + articleTagTableName + " WHERE tag_id = ?"
 
-	if err := t.db.QueryRowContext(ctx, query, ID).Scan(&count); err != nil {
+	if err := t.db.QueryRowContext(ctx, query, id).Scan(&count); err != nil {
 		return false, err
 	}
 
@@ -188,10 +188,10 @@ func (t tagRepository) Update(ctx context.Context, m models.Tag) error {
 	return err
 }
 
-func (t tagRepository) Delete(ctx context.Context, ID int) error {
+func (t tagRepository) Delete(ctx context.Context, id int) error {
 	query := "DELETE FROM " + tagTableName + " WHERE id = ?"
 
-	_, err := t.db.ExecContext(ctx, query, ID)
+	_, err := t.db.ExecContext(ctx, query, id)
 
 	return err
 }

+ 4 - 2
internal/services/handler/admin/tag.go

@@ -11,6 +11,8 @@ import (
 	"github.com/gofiber/fiber/v2"
 )
 
+const errTagExists = "Тег с данным URL уже существует"
+
 func TagHandler(app interfaces.IApp) fiber.Handler {
 	return func(ctx *fiber.Ctx) error {
 		tags, err := app.GetTagRepository().GetAll(ctx.Context())
@@ -51,7 +53,7 @@ func AddTagHandler(app interfaces.IApp) fiber.Handler {
 			}
 
 			if res, _ := app.GetTagRepository().GetByURL(ctx.Context(), form.URL); res != nil {
-				validateErrors["TagForm.URL"] = "Тег с данным URL уже существует"
+				validateErrors["TagForm.URL"] = errTagExists
 			}
 
 			if len(validateErrors) == 0 {
@@ -114,7 +116,7 @@ func EditTagHandler(app interfaces.IApp) fiber.Handler {
 
 			if res, _ := app.GetTagRepository().GetByURL(ctx.Context(), form.URL); res != nil {
 				if res.ID != ID {
-					validateErrors["TagForm.URL"] = "Тег с данным URL уже существует"
+					validateErrors["TagForm.URL"] = errTagExists
 				}
 			}