This commit is contained in:
Vyacheslav1557 2024-10-13 19:01:36 +05:00
parent 4cdd751b16
commit be25404852
51 changed files with 606 additions and 1194 deletions

View file

@ -1,4 +0,0 @@
package languages
type languageHandlers interface {
}

View file

@ -1 +0,0 @@
package grpc

View file

@ -1,10 +0,0 @@
package languages
import (
"context"
"git.sch9.ru/new_gate/models"
)
type LanguageRepository interface {
ReadLanguageById(ctx context.Context, id int32) (*models.Language, error)
}

View file

@ -1,28 +0,0 @@
package repository
import (
"context"
"git.sch9.ru/new_gate/models"
"git.sch9.ru/new_gate/ms-tester/pkg/utils"
"github.com/jmoiron/sqlx"
"go.uber.org/zap"
)
type LanguageRepository struct {
db *sqlx.DB
logger *zap.Logger
}
func NewLanguageRepository(db *sqlx.DB, logger *zap.Logger) *LanguageRepository {
return &LanguageRepository{
db: db,
logger: logger,
}
}
func (r *LanguageRepository) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
if id <= int32(len(models.Languages)) {
return nil, utils.StorageError(nil, utils.ErrNotFound, "languages not found")
}
return &models.Languages[id], nil
}

View file

@ -1,10 +0,0 @@
package languages
import (
"context"
"git.sch9.ru/new_gate/models"
)
type LanguageUseCase interface {
ReadLanguageById(ctx context.Context, id int32) (*models.Language, error)
}

View file

@ -1,44 +0,0 @@
package problem.rbac
import rego.v1
spectator := 0
participant := 1
moderator := 2
admin := 3
permissions := {
"read": is_spectator,
"participate": is_participant,
"update": is_moderator,
"create": is_moderator,
"delete": is_moderator,
}
default allow := false
allow if is_admin
allow if {
permissions[input.action]
}
default is_admin := false
is_admin if {
input.user.role == admin
}
default is_moderator := false
is_moderator if {
input.user.role >= moderator
}
default is_participant := false
is_participant if {
input.user.role >= participant
}
default is_spectator := true
is_spectator if {
input.user.role >= spectator
}

View file

@ -1,25 +0,0 @@
package usecase
import (
"context"
"git.sch9.ru/new_gate/models"
"git.sch9.ru/new_gate/ms-tester/internal/languages"
)
type LanguageUseCase struct {
languageRepo languages.LanguageRepository
}
func NewLanguageUseCase(
languageRepo languages.LanguageRepository,
) *LanguageUseCase {
return &LanguageUseCase{
languageRepo: languageRepo,
}
}
func (uc *LanguageUseCase) ReadLanguageById(ctx context.Context, id int32) (*models.Language, error) {
//userId := ctx.Value("user_id").(int32)
panic("access control is not implemented yet")
return uc.languageRepo.ReadLanguageById(ctx, id)
}