diff --git a/.gitmodules b/.gitmodules index b358abe..2c4bdfa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/internal/languages b/internal/languages new file mode 160000 index 0000000..e4171ba --- /dev/null +++ b/internal/languages @@ -0,0 +1 @@ +Subproject commit e4171bacc4d22e80c91eab79f2b8140c2cdf4d95 diff --git a/internal/models/language.go b/internal/models/language.go deleted file mode 100644 index d3f000a..0000000 --- a/internal/models/language.go +++ /dev/null @@ -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"}}, -} diff --git a/internal/services/language.go b/internal/services/language.go index dd83807..8ef50a3 100644 --- a/internal/services/language.go +++ b/internal/services/language.go @@ -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) diff --git a/internal/storage/language.go b/internal/storage/language.go index 2b4df77..1dd342c 100644 --- a/internal/storage/language.go +++ b/internal/storage/language.go @@ -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, "no such language") + } + return &languages.Languages[id], nil } diff --git a/ms-tester b/ms-tester new file mode 100755 index 0000000..79e7159 Binary files /dev/null and b/ms-tester differ