fix: make it runnable

This commit is contained in:
Vyacheslav1557 2024-08-21 03:54:46 +05:00
parent c9c4fc65e7
commit bf508a5f1f
23 changed files with 311 additions and 286 deletions

8
go.mod
View file

@ -1,9 +1,10 @@
module git.sch9.ru/new_gate/ms-tester module git.sch9.ru/new_gate/ms-tester
go 1.19 go 1.21.3
toolchain go1.22.0
require ( require (
git.sch9.ru/new_gate/ms-auth v0.0.0-20240816164331-331e413afa6a
github.com/ilyakaznacheev/cleanenv v1.5.0 github.com/ilyakaznacheev/cleanenv v1.5.0
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438 github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438
github.com/open-policy-agent/opa v0.67.1 github.com/open-policy-agent/opa v0.67.1
@ -25,6 +26,7 @@ require (
github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/mux v1.8.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/common v0.48.0 // indirect
@ -42,6 +44,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.25.0 // indirect golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
@ -51,7 +54,6 @@ require (
require ( require (
github.com/BurntSushi/toml v1.2.1 // indirect github.com/BurntSushi/toml v1.2.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/jackc/pgx/v5 v5.6.0 github.com/jackc/pgx/v5 v5.6.0
github.com/jmoiron/sqlx v1.4.0 github.com/jmoiron/sqlx v1.4.0
github.com/joho/godotenv v1.5.1 // indirect github.com/joho/godotenv v1.5.1 // indirect

6
go.sum
View file

@ -1,7 +1,5 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.sch9.ru/new_gate/ms-auth v0.0.0-20240816164331-331e413afa6a h1:Gvi3+Qh2VW3iWG3TZWQLjkWeW/4gb621SLLr9BroOro=
git.sch9.ru/new_gate/ms-auth v0.0.0-20240816164331-331e413afa6a/go.mod h1:BL4MiDqgmLngmQqUcKQ1cK1XCJr9DlAOpWnrlGidDdE=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8= github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
@ -51,8 +49,6 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4= github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4=
github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
@ -82,6 +78,8 @@ github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=

View file

@ -1,22 +1,9 @@
package lib package lib
import (
"fmt"
"github.com/ilyakaznacheev/cleanenv"
)
type Config struct { type Config struct {
Env string `env:"ENV" env-default:"prod"` Env string `env:"ENV" env-default:"prod"`
Pandoc string `env:"PANDOC" required:"true"` Pandoc string `env:"PANDOC" required:"true"`
Auth string `env:"PANDOC" required:"true"`
Address string `env:"ADDRESS" required:"true"`
PostgresDSN string `env:"POSTGRES_DSN" required:"true"` PostgresDSN string `env:"POSTGRES_DSN" required:"true"`
JWTSecret string `env:"JWT_SECRET" required:"true"`
}
func MustSetupConfig() *Config {
var cfg Config
err := cleanenv.ReadConfig(".env", &cfg)
if err != nil {
panic(fmt.Sprintf("error reading config: %s", err.Error()))
}
return &cfg
} }

View file

@ -16,4 +16,5 @@ var (
var ( var (
ErrBadTestingStrategy = errors.New("bad testing strategy") ErrBadTestingStrategy = errors.New("bad testing strategy")
ErrBadResult = errors.New("bad result")
) )

View file

@ -1,5 +1,7 @@
package models package models
import "time"
type Contest struct { type Contest struct {
Id *int `db:"id"` Id *int `db:"id"`
Name *string `db:"name"` Name *string `db:"name"`

View file

@ -1,8 +1,6 @@
package models package models
import "time" type Participant struct {
type Solution struct {
Id *int32 `db:"id"` Id *int32 `db:"id"`
UserId *int32 `db:"user_id"` UserId *int32 `db:"user_id"`
ContestId *int32 `db:"contest_id"` ContestId *int32 `db:"contest_id"`

View file

@ -1,6 +1,6 @@
package models package models
import "time" import "git.sch9.ru/new_gate/ms-tester/internal/lib"
type Result int32 type Result int32
@ -16,7 +16,7 @@ const (
func (result Result) Valid() error { func (result Result) Valid() error {
switch result { switch result {
case NotTested, Accepted, TimeLimitExceeded, MemoryLimitExceede, CompilationError, SystemFailDuringTesting: case NotTested, Accepted, TimeLimitExceeded, MemoryLimitExceeded, CompilationError, SystemFailDuringTesting:
return nil return nil
} }
return lib.ErrBadResult return lib.ErrBadResult

View file

@ -1,6 +1,6 @@
package models package models
type Task struct { type SubTask struct {
Id *int32 `db:"id"` Id *int32 `db:"id"`
ContestId *int32 `db:"contest_id"` ContestId *int32 `db:"contest_id"`
TestgroupId *int32 `db:"testgroup_id"` TestgroupId *int32 `db:"testgroup_id"`

View file

@ -1,12 +1,12 @@
package models package models
import "time" import "git.sch9.ru/new_gate/ms-tester/internal/lib"
type TestingStrategy int32 type TestingStrategy int32
const ( const (
EachTestTS TestingStrategy = 1; EachTestTS TestingStrategy = 1
CompleteGroupTS TestingStrategy = 2; CompleteGroupTS TestingStrategy = 2
) )
type Testgroup struct { type Testgroup struct {
@ -15,12 +15,12 @@ type Testgroup struct {
TestingStrategy *TestingStrategy `db:"testing_strategy"` TestingStrategy *TestingStrategy `db:"testing_strategy"`
} }
type TestgroupData struct { type TestGroupData struct {
Ts TestingStrategy Ts TestingStrategy
TestAmount int32 TestAmount int32
} }
func (TestingStrategy ts) Valid() error { func (ts TestingStrategy) Valid() error {
switch ts { switch ts {
case EachTestTS, CompleteGroupTS: case EachTestTS, CompleteGroupTS:
return nil return nil

View file

@ -25,26 +25,25 @@ func NewContestService(
} }
func (service *ContestService) CreateContest(ctx context.Context, contest *models.Contest) (int32, error) { func (service *ContestService) CreateContest(ctx context.Context, contest *models.Contest) (int32, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.contestStorage.CreateContest(ctx, contest) return service.contestStorage.CreateContest(ctx, contest)
} }
func (service *ContestService) ReadContestById(ctx context.Context, id int32) (*models.Contest, error) { func (service *ContestService) ReadContestById(ctx context.Context, id int32) (*models.Contest, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.contestStorage.ReadContestById(ctx, id) return service.contestStorage.ReadContestById(ctx, id)
} }
func (service *ContestService) UpdateContest(ctx context.Context, contest *models.Contest) error { func (service *ContestService) UpdateContest(ctx context.Context, contest *models.Contest) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.contestStorage.UpdateContest(ctx, contest) return service.contestStorage.UpdateContest(ctx, contest)
} }
func (service *ContestService) DeleteContest(ctx context.Context, id int32) error { func (service *ContestService) DeleteContest(ctx context.Context, id int32) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.contestStorage.DeleteContest(ctx, id) return service.contestStorage.DeleteContest(ctx, id)
} }

View file

@ -25,25 +25,25 @@ func NewLanguageService(
} }
func (service *LanguageService) CreateLanguage(ctx context.Context, language *models.Language) (int32, error) { func (service *LanguageService) CreateLanguage(ctx context.Context, language *models.Language) (int32, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.languageStorage.CreateLanguage(ctx, language) return service.languageStorage.CreateLanguage(ctx, language)
} }
func (service *LanguageService) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) { func (service *LanguageService) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.languageStorage.ReadLanguageById(ctx, id) return service.languageStorage.ReadLanguageById(ctx, id)
} }
func (service *LanguageService) UpdateLanguage(ctx context.Context, language *models.Language) error { func (service *LanguageService) UpdateLanguage(ctx context.Context, language *models.Language) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.languageStorage.UpdateLanguage(ctx, language) return service.languageStorage.UpdateLanguage(ctx, language)
} }
func (service *LanguageService) DeleteLanguage(ctx context.Context, id int32) error { func (service *LanguageService) DeleteLanguage(ctx context.Context, id int32) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.languageStorage.DeleteLanguage(ctx, id) return service.languageStorage.DeleteLanguage(ctx, id)
} }

View file

@ -25,25 +25,25 @@ func NewParticipantService(
} }
func (service *ParticipantService) CreateParticipant(ctx context.Context, participant *models.Participant) (int32, error) { func (service *ParticipantService) CreateParticipant(ctx context.Context, participant *models.Participant) (int32, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.participantStorage.CreateParticipant(ctx, participant) return service.participantStorage.CreateParticipant(ctx, participant)
} }
func (service *ParticipantService) ReadParticipantById(ctx context.Context, id int32) (*models.Participant, error) { func (service *ParticipantService) ReadParticipantById(ctx context.Context, id int32) (*models.Participant, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.participantStorage.ReadParticipantById(ctx, id) return service.participantStorage.ReadParticipantById(ctx, id)
} }
func (service *ParticipantService) UpdateParticipant(ctx context.Context, participant *models.Participant) error { func (service *ParticipantService) UpdateParticipant(ctx context.Context, participant *models.Participant) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.participantStorage.UpdateParticipant(ctx, participant) return service.participantStorage.UpdateParticipant(ctx, participant)
} }
func (service *ParticipantService) DeleteParticipant(ctx context.Context, id int32) error { func (service *ParticipantService) DeleteParticipant(ctx context.Context, id int32) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.participantStorage.DeleteParticipant(ctx, id) return service.participantStorage.DeleteParticipant(ctx, id)
} }

View file

@ -6,14 +6,14 @@ import (
) )
type ProblemStorage interface { type ProblemStorage interface {
CreateProblem(ctx context.Context, problem *models.Problem) (int32, error) CreateProblem(ctx context.Context, problem *models.Problem, testGroupData []models.TestGroupData) (int32, error)
ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) ReadProblemById(ctx context.Context, id int32) (*models.Problem, error)
UpdateProblem(ctx context.Context, problem *models.Problem) error UpdateProblem(ctx context.Context, problem *models.Problem) error
DeleteProblem(ctx context.Context, id int32) error DeleteProblem(ctx context.Context, id int32) error
} }
type PandocClient interface { type PandocClient interface {
ConvertLatexToHtml5(text string) (string, error) ConvertLatexToHtml5(ctx context.Context, text string) (string, error)
} }
type ProblemService struct { type ProblemService struct {
@ -32,29 +32,29 @@ func NewProblemService(
} }
func (service *ProblemService) CreateProblem(ctx context.Context, problem *models.Problem, ch <-chan []byte) (int32, error) { func (service *ProblemService) CreateProblem(ctx context.Context, problem *models.Problem, ch <-chan []byte) (int32, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
html, err := service.pandocClient.ConvertLatexToHtml5(*problem.Description) //html, err := service.pandocClient.ConvertLatexToHtml5(*problem.Description)
if err != nil { //if err != nil {
return 0, err // return 0, err
} //}
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.problemStorage.CreateProblem(ctx, problem) //return service.problemStorage.CreateProblem(ctx, problem)
} }
func (service *ProblemService) ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) { func (service *ProblemService) ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.problemStorage.ReadProblemById(ctx, id) //return service.problemStorage.ReadProblemById(ctx, id)
} }
func (service *ProblemService) UpdateProblem(ctx context.Context, problem *models.Problem) error { func (service *ProblemService) UpdateProblem(ctx context.Context, problem *models.Problem) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.problemStorage.UpdateProblem(ctx, problem) //return service.problemStorage.UpdateProblem(ctx, problem)
} }
func (service *ProblemService) DeleteProblem(ctx context.Context, id int32) error { func (service *ProblemService) DeleteProblem(ctx context.Context, id int32) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.problemStorage.DeleteProblem(ctx, id) //return service.problemStorage.DeleteProblem(ctx, id)
} }

View file

@ -6,7 +6,7 @@ import (
) )
type SolutionStorage interface { type SolutionStorage interface {
CreateSolution(ctx context.Context, models.Solution) (int32, error) CreateSolution(ctx context.Context, solution models.Solution) (int32, error)
ReadSolutionById(ctx context.Context, id int32) (models.Solution, error) ReadSolutionById(ctx context.Context, id int32) (models.Solution, error)
RejudgeSolution(ctx context.Context, id int32) error RejudgeSolution(ctx context.Context, id int32) error
DeleteSolution(ctx context.Context, id int32) error DeleteSolution(ctx context.Context, id int32) error
@ -25,26 +25,25 @@ func NewSolutionService(
} }
func (service *SolutionService) CreateSolution(ctx context.Context, solution models.Solution) (int32, error) { func (service *SolutionService) CreateSolution(ctx context.Context, solution models.Solution) (int32, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.solutionStorage.CreateSolution(ctx, solution) return service.solutionStorage.CreateSolution(ctx, solution)
} }
func (service *SolutionService) ReadSolutionById(ctx context.Context, id int32) (models.Solution, error) { func (service *SolutionService) ReadSolutionById(ctx context.Context, id int32) (models.Solution, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.solutionStorage.ReadSolutionById(ctx, id) return service.solutionStorage.ReadSolutionById(ctx, id)
} }
func (service *SolutionService) RejudgeSolution(ctx context.Context, id int32) error { func (service *SolutionService) RejudgeSolution(ctx context.Context, id int32) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.solutionStorage.RejudgeSolution(ctx, id) return service.solutionStorage.RejudgeSolution(ctx, id)
} }
func (service *SolutionService) DeleteSolution(ctx context.Context, id int32) error { func (service *SolutionService) DeleteSolution(ctx context.Context, id int32) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.solutionStorage.DeleteSolution(ctx, id) return service.solutionStorage.DeleteSolution(ctx, id)
} }

View file

@ -6,7 +6,7 @@ import (
) )
type TaskStorage interface { type TaskStorage interface {
CreateTask(ctx context.Context, models.Task) (int32, error) CreateTask(ctx context.Context, task models.Task) (int32, error)
DeleteTask(ctx context.Context, id int32) error DeleteTask(ctx context.Context, id int32) error
} }
@ -23,14 +23,13 @@ func NewTaskService(
} }
func (service *TaskService) CreateTask(ctx context.Context, task models.Task) (int32, error) { func (service *TaskService) CreateTask(ctx context.Context, task models.Task) (int32, error) {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.taskStorage.CreateTask(ctx, task) return service.taskStorage.CreateTask(ctx, task)
} }
func (service *TaskService) DeleteTask(ctx context.Context, id int32) error { func (service *TaskService) DeleteTask(ctx context.Context, id int32) error {
userId := ctx.Value("user_id").(int32) //userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet") panic("access control is not implemented yet")
return service.taskStorage.DeleteTask(ctx, id) return service.taskStorage.DeleteTask(ctx, id)
} }

View file

@ -57,12 +57,14 @@ func (storage *ContestStorage) ReadContestById(ctx context.Context, id int32) (*
return &contest, nil return &contest, nil
} }
func (storage *ContestStorage) UpdateContest(ctx context.Context, id int32, contest models.Contest) error { func (storage *ContestStorage) UpdateContest(ctx context.Context, contest *models.Contest) error {
query := storage.db.Rebind("UPDATE contests SET name=?") query := storage.db.Rebind("UPDATE contests SET name=? WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, contest.Name) _, err := storage.db.ExecContext(ctx, query, contest.Name, contest.Id)
if err != nil { if err != nil {
return handlePgErr(err) return handlePgErr(err)
} }
return nil
} }
func (storage *ContestStorage) DeleteContest(ctx context.Context, id int32) error { func (storage *ContestStorage) DeleteContest(ctx context.Context, id int32) error {

View file

@ -2,14 +2,9 @@ package storage
import ( import (
"context" "context"
"errors" "git.sch9.ru/new_gate/ms-tester/internal/models"
"git.sch9.ru/new_gate/ms-auth/internal/lib"
"git.sch9.ru/new_gate/ms-auth/internal/models"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type LanguageStorage struct { type LanguageStorage struct {
@ -37,17 +32,17 @@ RETURNING id
query, query,
language.Name, language.Name,
"", //FIXME "", //FIXME
"" "",
) )
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
defer rows.Close() defer rows.Close()
var id int32 var id int32
err = rows.StructScan(&id) err = rows.StructScan(&id)
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
return id, nil return id, nil
@ -59,7 +54,7 @@ func (storage *LanguageStorage) ReadLanguageById(ctx context.Context, id int32)
query := storage.db.Rebind("SELECT * from languages WHERE id=? LIMIT 1") query := storage.db.Rebind("SELECT * from languages WHERE id=? LIMIT 1")
err := storage.db.GetContext(ctx, &language, query, id) err := storage.db.GetContext(ctx, &language, query, id)
if err != nil { if err != nil {
return nil, storage.HandlePgErr(err) return nil, handlePgErr(err)
} }
return &language, nil return &language, nil
} }
@ -68,17 +63,18 @@ func (storage *LanguageStorage) UpdateLanguage(ctx context.Context, id int32,lan
query := storage.db.Rebind("UPDATE languages SET name=?") //FIXME add build file and execute file loading query := storage.db.Rebind("UPDATE languages SET name=?") //FIXME add build file and execute file loading
_, err := storage.db.ExecContext(ctx, query, language.Name) _, err := storage.db.ExecContext(ctx, query, language.Name)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil
} }
func (storage *LanguageStorage) DeleteLanguage(ctx context.Context, id int32) error { func (storage *LanguageStorage) DeleteLanguage(ctx context.Context, id int32) error {
query := storage.db.Rebind("DELETE FROM languages WHERE id=?") query := storage.db.Rebind("DELETE FROM languages WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, id) _, err := storage.db.ExecContext(ctx, query, id)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil return nil
} }

View file

@ -2,14 +2,9 @@ package storage
import ( import (
"context" "context"
"errors" "git.sch9.ru/new_gate/ms-tester/internal/models"
"git.sch9.ru/new_gate/ms-auth/internal/lib"
"git.sch9.ru/new_gate/ms-auth/internal/models"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type ParticipantStorage struct { type ParticipantStorage struct {
@ -37,17 +32,17 @@ RETURNING id
query, query,
participant.UserId, participant.UserId,
participant.ContestId, participant.ContestId,
participant.Name participant.Name,
) )
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
defer rows.Close() defer rows.Close()
var id int32 var id int32
err = rows.StructScan(&id) err = rows.StructScan(&id)
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
return id, nil return id, nil
@ -59,7 +54,7 @@ func (storage *ParticipantStorage) ReadParticipantById(ctx context.Context, id i
query := storage.db.Rebind("SELECT * from participants WHERE id=? LIMIT 1") query := storage.db.Rebind("SELECT * from participants WHERE id=? LIMIT 1")
err := storage.db.GetContext(ctx, &participant, query, id) err := storage.db.GetContext(ctx, &participant, query, id)
if err != nil { if err != nil {
return nil, storage.HandlePgErr(err) return nil, handlePgErr(err)
} }
return &participant, nil return &participant, nil
} }
@ -68,17 +63,17 @@ func (storage *ParticipantStorage) UpdateParticipant(ctx context.Context, id int
query := storage.db.Rebind("UPDATE participants SET name=?") query := storage.db.Rebind("UPDATE participants SET name=?")
_, err := storage.db.ExecContext(ctx, query, participant.Name) _, err := storage.db.ExecContext(ctx, query, participant.Name)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil
} }
func (storage *ParticipantStorage) DeleteParticipant(ctx context.Context, id int32) error { func (storage *ParticipantStorage) DeleteParticipant(ctx context.Context, id int32) error {
query := storage.db.Rebind("DELETE FROM participants WHERE id=?") query := storage.db.Rebind("DELETE FROM participants WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, id) _, err := storage.db.ExecContext(ctx, query, id)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil return nil
} }

View file

@ -2,14 +2,9 @@ package storage
import ( import (
"context" "context"
"errors" "git.sch9.ru/new_gate/ms-tester/internal/models"
"git.sch9.ru/new_gate/ms-auth/internal/lib"
"git.sch9.ru/new_gate/ms-auth/internal/models"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type ProblemStorage struct { type ProblemStorage struct {
@ -24,8 +19,8 @@ func NewProblemStorage(db *sqlx.DB, logger *zap.Logger) *ProblemStorage {
} }
} }
func (storage *ProblemStorage) CreateProblem(ctx context.Context, problem *models.Problem, testgroupData []models.TestGroupData, testchan <-chan []byte) (int32, error) { func (storage *ProblemStorage) CreateProblem(ctx context.Context, problem *models.Problem, testGroupData []models.TestGroupData) (int32, error) {
tx,err := storage.db.Begin() tx, err := storage.db.Beginx()
query := tx.Rebind(` query := tx.Rebind(`
INSERT INTO problems INSERT INTO problems
(name,description,time_limit,memory_limit) (name,description,time_limit,memory_limit)
@ -38,32 +33,33 @@ RETURNING id
problem.Name, problem.Name,
problem.Description, problem.Description,
problem.TimeLimit, problem.TimeLimit,
problem.MemoryLimit problem.MemoryLimit,
) )
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
for _,tgd := testGroupData { for _, tgd := range testGroupData {
query := tx.Rebind(` query := tx.Rebind(`
INSERT INTO testgroups INSERT INTO testgroups
(problem_id,testing_strategy) (problem_id,testing_strategy)
VALUES ((select last_value from problems_id_seq),?) VALUES ((select last_value from problems_id_seq),?)
RETURNING id RETURNING id
`) `)
rows, err := tx.QueryxContext(ctx, query, tgd.Ts) rows, err = tx.QueryxContext(ctx, query, tgd.Ts)
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
for i:=0;i<tgd.testAmount;i++ { var i int32 = 0
for ; i < tgd.TestAmount; i++ {
query := tx.Rebind(` query := tx.Rebind(`
INSERT INTO tests INSERT INTO tests
(testgroup_id) (testgroup_id)
VALUES ((select last_value from testgroups_id_seq)) VALUES ((select last_value from testgroups_id_seq))
RETURNING id RETURNING id
`) `)
rows, err := tx.QueryxContext(ctx, query, tgd.Ts) rows, err = tx.QueryxContext(ctx, query, tgd.Ts)
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
} }
} }
@ -74,7 +70,7 @@ RETURNING id
var id int32 var id int32
err = rows.StructScan(&id) err = rows.StructScan(&id)
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
return id, nil return id, nil
@ -85,26 +81,26 @@ func (storage *ProblemStorage) ReadProblemById(ctx context.Context, id int32) (*
query := storage.db.Rebind("SELECT * from problems WHERE id=? LIMIT 1") query := storage.db.Rebind("SELECT * from problems WHERE id=? LIMIT 1")
err := storage.db.GetContext(ctx, &problem, query, id) err := storage.db.GetContext(ctx, &problem, query, id)
if err != nil { if err != nil {
return nil, storage.HandlePgErr(err) return nil, handlePgErr(err)
} }
return &problem, nil return &problem, nil
} }
func (storage *ProblemStorage) UpdateProblem(ctx context.Context, id int32,problem models.Problem) error { func (storage *ProblemStorage) UpdateProblem(ctx context.Context, problem *models.Problem) error {
query := storage.db.Rebind("UPDATE problems SET name=?,description=?,time_limit=?,memory_limit=?") query := storage.db.Rebind("UPDATE problems SET name=?,description=?,time_limit=?,memory_limit=? WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, problem.Name,Problem.Description,problem.TimeLimit,problem.MemoryLimit) _, err := storage.db.ExecContext(ctx, query, problem.Name, problem.Description, problem.TimeLimit, problem.MemoryLimit, problem.Id)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil
} }
func (storage *ProblemStorage) DeleteProblem(ctx context.Context, id int32) error { func (storage *ProblemStorage) DeleteProblem(ctx context.Context, id int32) error {
query := storage.db.Rebind("DELETE FROM problems WHERE id=?") query := storage.db.Rebind("DELETE FROM problems WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, id) _, err := storage.db.ExecContext(ctx, query, id)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil return nil
} }

View file

@ -2,14 +2,9 @@ package storage
import ( import (
"context" "context"
"errors" "git.sch9.ru/new_gate/ms-tester/internal/models"
"git.sch9.ru/new_gate/ms-auth/internal/lib"
"git.sch9.ru/new_gate/ms-auth/internal/models"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type SolutionStorage struct { type SolutionStorage struct {
@ -26,10 +21,10 @@ func NewSolutionStorage(db *sqlx.DB, logger *zap.Logger) *SolutionStorage {
// TODO: testing graph // TODO: testing graph
func updateResult(ctx context.Context, participantId int32, taskId int32) error { func (storage *SolutionStorage) updateResult(ctx context.Context, participantId int32, taskId int32) error {
tx,err := storage.db.Begin() tx, err := storage.db.Beginx()
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
query := tx.Rebind("UPDATE participant_subtask AS ps SET best_score = (SELECT COALESCE(max(score),0) FROM subtaskruns WHERE subtask_id = ps.subtask_id AND solution_id IN (SELECT id FROM solutions WHERE participant_id=ps.participant_id)) WHERE participant_id = 2 AND subtask_id IN (SELECT id FROM subtasks WHERE task_id = 2)") query := tx.Rebind("UPDATE participant_subtask AS ps SET best_score = (SELECT COALESCE(max(score),0) FROM subtaskruns WHERE subtask_id = ps.subtask_id AND solution_id IN (SELECT id FROM solutions WHERE participant_id=ps.participant_id)) WHERE participant_id = 2 AND subtask_id IN (SELECT id FROM subtasks WHERE task_id = 2)")
tx.QueryxContext(ctx, query, participantId, taskId) tx.QueryxContext(ctx, query, participantId, taskId)
@ -37,8 +32,10 @@ func updateResult(ctx context.Context, participantId int32, taskId int32) error
tx.QueryxContext(ctx, query, participantId, taskId, participantId, taskId) tx.QueryxContext(ctx, query, participantId, taskId, participantId, taskId)
err = tx.Commit() err = tx.Commit()
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil
} }
func (storage *SolutionStorage) CreateSolution(ctx context.Context, solution *models.Solution) (int32, error) { func (storage *SolutionStorage) CreateSolution(ctx context.Context, solution *models.Solution) (int32, error) {
@ -60,14 +57,14 @@ RETURNING id
) )
//TODO: add testing tree //TODO: add testing tree
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
defer rows.Close() defer rows.Close()
var id int32 var id int32
err = rows.StructScan(&id) err = rows.StructScan(&id)
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
return id, nil return id, nil
@ -78,15 +75,15 @@ func (storage *SolutionStorage) ReadSolutionById(ctx context.Context, id int32)
query := storage.db.Rebind("SELECT * from solutions WHERE id=? LIMIT 1") query := storage.db.Rebind("SELECT * from solutions WHERE id=? LIMIT 1")
err := storage.db.GetContext(ctx, &solution, query, id) err := storage.db.GetContext(ctx, &solution, query, id)
if err != nil { if err != nil {
return nil, storage.HandlePgErr(err) return nil, handlePgErr(err)
} }
return &solution, nil return &solution, nil
} }
func (storage *SolutionStorage) RejudgeSolution(ctx context.Context, id int32) error { func (storage *SolutionStorage) RejudgeSolution(ctx context.Context, id int32) error {
tx,err := storage.db.Begin() tx, err := storage.db.Beginx()
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
query := tx.Rebind("UPDATE solutions SET result = ? WHERE id = ?") query := tx.Rebind("UPDATE solutions SET result = ? WHERE id = ?")
tx.QueryxContext(ctx, query, models.NotTested, id) tx.QueryxContext(ctx, query, models.NotTested, id)
@ -96,12 +93,12 @@ func (storage *SolutionStorage) RejudgeSolution(ctx context.Context, id int32) e
tx.QueryxContext(ctx, query, models.NotTested, id) tx.QueryxContext(ctx, query, models.NotTested, id)
err = tx.Commit() err = tx.Commit()
var solution models.Solution var solution models.Solution
query := storage.db.Rebind("SELECT * from solutions WHERE id=? LIMIT 1") query = storage.db.Rebind("SELECT * from solutions WHERE id=? LIMIT 1")
err := storage.db.GetContext(ctx, &solution, query, id) err = storage.db.GetContext(ctx, &solution, query, id)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
updateResult(ctx,solution.ParticipantId,TaskId); storage.updateResult(ctx, *solution.ParticipantId, *solution.TaskId)
return nil return nil
} }
@ -110,9 +107,8 @@ func (storage *SolutionStorage) DeleteSolution(ctx context.Context, id int32) er
query := storage.db.Rebind("DELETE FROM solutions WHERE id=?") query := storage.db.Rebind("DELETE FROM solutions WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, id) _, err := storage.db.ExecContext(ctx, query, id)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil return nil
} }

View file

@ -2,14 +2,9 @@ package storage
import ( import (
"context" "context"
"errors" "git.sch9.ru/new_gate/ms-tester/internal/models"
"git.sch9.ru/new_gate/ms-auth/internal/lib"
"git.sch9.ru/new_gate/ms-auth/internal/models"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type TaskStorage struct { type TaskStorage struct {
@ -38,17 +33,17 @@ RETURNING id
task.ContestId, task.ContestId,
task.ProblemId, task.ProblemId,
task.Position, task.Position,
task.PositionName task.PositionName,
) )
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
defer rows.Close() defer rows.Close()
var id int32 var id int32
err = rows.StructScan(&id) err = rows.StructScan(&id)
if err != nil { if err != nil {
return 0, storage.HandlePgErr(err) return 0, handlePgErr(err)
} }
return id, nil return id, nil
@ -60,7 +55,7 @@ func (storage *TaskStorage) ReadTaskById(ctx context.Context, id int32) (*models
query := storage.db.Rebind("SELECT * from tasks WHERE id=? LIMIT 1") query := storage.db.Rebind("SELECT * from tasks WHERE id=? LIMIT 1")
err := storage.db.GetContext(ctx, &task, query, id) err := storage.db.GetContext(ctx, &task, query, id)
if err != nil { if err != nil {
return nil, storage.HandlePgErr(err) return nil, handlePgErr(err)
} }
return &task, nil return &task, nil
} }
@ -69,17 +64,17 @@ func (storage *TaskStorage) UpdateTask(ctx context.Context, id int32,task models
query := storage.db.Rebind("UPDATE tasks SET position=?,position_name=?") query := storage.db.Rebind("UPDATE tasks SET position=?,position_name=?")
_, err := storage.db.ExecContext(ctx, query, task.Position, task.PositionName) _, err := storage.db.ExecContext(ctx, query, task.Position, task.PositionName)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil
} }
func (storage *TaskStorage) DeleteTask(ctx context.Context, id int32) error { func (storage *TaskStorage) DeleteTask(ctx context.Context, id int32) error {
query := storage.db.Rebind("DELETE FROM tasks WHERE id=?") query := storage.db.Rebind("DELETE FROM tasks WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, id) _, err := storage.db.ExecContext(ctx, query, id)
if err != nil { if err != nil {
return storage.HandlePgErr(err) return handlePgErr(err)
} }
return nil return nil
} }

View file

@ -7,6 +7,7 @@ import (
sessionv1 "git.sch9.ru/new_gate/ms-tester/pkg/go/gen/proto/session/v1" sessionv1 "git.sch9.ru/new_gate/ms-tester/pkg/go/gen/proto/session/v1"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
"net"
"time" "time"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -51,13 +52,14 @@ type TesterServer struct {
func NewTesterServer( func NewTesterServer(
problemService ProblemService, problemService ProblemService,
sessionClient SessionClient, sessionClient SessionClient,
permissionService PermissionService,
userService UserService, userService UserService,
logger *zap.Logger, logger *zap.Logger,
) *TesterServer { ) *TesterServer {
server := &TesterServer{ server := &TesterServer{
problemService: problemService, problemService: problemService,
sessionClient: sessionClient, sessionClient: sessionClient,
permissionService: permissionService,
userService: userService, userService: userService,
logger: logger, logger: logger,
} }
@ -69,9 +71,19 @@ func NewTesterServer(
problemv1.RegisterProblemServiceServer(grpcServer, server) problemv1.RegisterProblemServiceServer(grpcServer, server)
server.grpcServer = grpcServer
return server return server
} }
func (s *TesterServer) Start(lis net.Listener) error {
return s.grpcServer.Serve(lis)
}
func (s *TesterServer) Stop() {
s.grpcServer.GracefulStop()
}
func AsTimeP(t *timestamppb.Timestamp) *time.Time { func AsTimeP(t *timestamppb.Timestamp) *time.Time {
if t == nil { if t == nil {
return nil return nil

106
main.go
View file

@ -1,33 +1,81 @@
package main package main
func main() { import (
//cfg := lib.MustSetupConfig() "fmt"
// "git.sch9.ru/new_gate/ms-tester/internal/lib"
//var logger *zap.Logger "git.sch9.ru/new_gate/ms-tester/internal/services"
//if cfg.Env == "prod" { "git.sch9.ru/new_gate/ms-tester/internal/storage"
// logger = zap.Must(zap.NewProduction()) "git.sch9.ru/new_gate/ms-tester/internal/transport"
//} else if cfg.Env == "dev" { sessionv1 "git.sch9.ru/new_gate/ms-tester/pkg/go/gen/proto/session/v1"
// logger = zap.Must(zap.NewDevelopment()) "github.com/ilyakaznacheev/cleanenv"
//} else { _ "github.com/jackc/pgx/v5/stdlib"
// panic(fmt.Sprintf(`error reading config: env expected "prod" or "dev", got "%s"`, cfg.Env)) "github.com/jmoiron/sqlx"
//} "go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"net"
"net/http"
"os"
"os/signal"
"syscall"
)
//postgres := storage.NewUserStorage(cfg.PostgresDSN, logger) func main() {
// var cfg lib.Config
//vk := storage.NewValkeyStorage(cfg.RedisDSN, cfg, logger) err := cleanenv.ReadConfig(".env", &cfg)
// if err != nil {
//sessionService := services.NewSessionService(vk, postgres, cfg) panic(fmt.Sprintf("error reading config: %s", err.Error()))
//userService := services.NewUserService(postgres, vk, vk, cfg) }
//
//server := transport.NewAuthServer(sessionService, userService, grpc.NewServer(), logger) var logger *zap.Logger
// if cfg.Env == "prod" {
//application := app.NewApp(cfg, server) logger = zap.Must(zap.NewProduction())
// } else if cfg.Env == "dev" {
//application.Start() logger = zap.Must(zap.NewDevelopment())
// } else {
//stop := make(chan os.Signal, 1) panic(fmt.Sprintf(`error reading config: env expected "prod" or "dev", got "%s"`, cfg.Env))
//signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) }
//
//<-stop db, err := sqlx.Connect("pgx", cfg.PostgresDSN)
//application.GracefullyStop() if err != nil {
panic(err)
}
defer db.Close()
//contestStorage := storage.NewContestStorage(db, logger)
//contestService := services.NewContestService(contestStorage)
pandocClient := lib.NewPandocClient(&http.Client{}, cfg.Pandoc)
grpcSessionClient, err := grpc.NewClient(cfg.Auth, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
panic(err)
}
sessionClient := sessionv1.NewSessionServiceClient(grpcSessionClient)
problemStorage := storage.NewProblemStorage(db, logger)
problemService := services.NewProblemService(problemStorage, pandocClient)
userStorage := storage.NewUserStorage(db)
userService := services.NewUserService(userStorage)
permissionService := services.NewPermissionService()
server := transport.NewTesterServer(problemService, sessionClient, permissionService, userService, logger)
lis, err := net.Listen("tcp", cfg.Address)
if err != nil {
panic(err)
}
go func() {
if err := server.Start(lis); err != nil {
logger.Fatal("error starting server", zap.Error(err))
}
}()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT)
<-stop
} }