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:03:03 +05:00
parent 02a7a49ac3
commit b7147a2c19
6 changed files with 14 additions and 25 deletions

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

@ -1,13 +0,0 @@
package models
type Language struct {
Name string
CompileCmd []string //source: src;result:executable
RunCmd []string //source: executable
}
var languages = [...]Language {
{Name : "gcc std=c90",
CompileCmd : []string{"gcc", "src","-std=c90","-o","executable"},
RunCmd : []string{"executable"}},
}

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)
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, "no such language")
}
return &language, nil
return &languages.Languages[id], nil
}

BIN
ms-tester Executable file

Binary file not shown.