feat: move languages to submodule;fix:storage:replace postgres query with array query when getting language

This commit is contained in:
dragonmuffin 2024-08-25 18:13:57 +05:00
parent 02a7a49ac3
commit 75acb422af
5 changed files with 16 additions and 13 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
.env
.idea
/pkg/go/gen
/pkg/go/gen
/ms-tester

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "proto"]
path = proto
url = https://git.sch9.ru/new_gate/contracts
[submodule "internal/languages"]
path = internal/languages
url = https://git.sch9.ru/new_gate/languages

1
internal/languages Submodule

@ -0,0 +1 @@
Subproject commit e4171bacc4d22e80c91eab79f2b8140c2cdf4d95

View file

@ -2,11 +2,11 @@ package services
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/models"
"git.sch9.ru/new_gate/ms-tester/internal/languages"
)
type LanguageStorage interface {
ReadLanguageById(ctx context.Context, id int32) (*models.Language, error)
ReadLanguageById(ctx context.Context, id int32) (*languages.Language, error)
}
type LanguageService struct {
@ -21,7 +21,7 @@ func NewLanguageService(
}
}
func (service *LanguageService) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
func (service *LanguageService) ReadLanguageById(ctx context.Context, id int32) (*languages.Language, error) {
//userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet")
return service.languageStorage.ReadLanguageById(ctx, id)

View file

@ -2,7 +2,8 @@ package storage
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/models"
"git.sch9.ru/new_gate/ms-tester/internal/languages"
"git.sch9.ru/new_gate/ms-tester/internal/lib"
"github.com/jmoiron/sqlx"
"go.uber.org/zap"
)
@ -19,12 +20,9 @@ func NewLanguageStorage(db *sqlx.DB, logger *zap.Logger) *LanguageStorage {
}
}
func (storage *LanguageStorage) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
var language models.Language
query := storage.db.Rebind("SELECT * from languages WHERE id=? LIMIT 1")
err := storage.db.GetContext(ctx, &language, query, id)
if err != nil {
return nil, handlePgErr(err)
}
return &language, nil
func (storage *LanguageStorage) ReadLanguageById(ctx context.Context, id int32) (*languages.Language, error) {
if(id<=int32(len(languages.Languages))) {
return nil,lib.StorageError(nil,lib.ErrNotFound,"language not found")
}
return &languages.Languages[id], nil
}