generated from VLADIMIR/template
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"evening_detective/internal/models"
|
|
"evening_detective/internal/modules/password"
|
|
"evening_detective/proto"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
type Services struct {
|
|
repository *Repository
|
|
}
|
|
|
|
func NewServices(repository *Repository) *Services {
|
|
return &Services{
|
|
repository: repository,
|
|
}
|
|
}
|
|
|
|
func (s *Services) GiveApplications(ctx context.Context, req *proto.GiveApplicationsReq) (*proto.GiveApplicationsRsp, error) {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (s *Services) GameStop(ctx context.Context, req *proto.GameStopReq) (*proto.GameStopRsp, error) {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (s *Services) GameStart(ctx context.Context, req *proto.GameStartReq) (*proto.GameStartRsp, error) {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (s *Services) AddAction(ctx context.Context, req *proto.AddActionReq) (*proto.AddActionRsp, error) {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (s *Services) DeleteTeams(ctx context.Context, req *proto.DeleteTeamsReq) (*proto.DeleteTeamsRsp, error) {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (s *Services) GetTeam(ctx context.Context, req *proto.GetTeamReq) (*proto.GetTeamRsp, error) {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (s *Services) GetTeamsCSV(ctx context.Context, req *proto.GetTeamsCSVReq) (*proto.GetTeamsCSVRsp, error) {
|
|
panic("unimplemented")
|
|
}
|
|
|
|
func (s *Services) GetTeams(ctx context.Context, _ *proto.GetTeamsReq) (*proto.GetTeamsRsp, error) {
|
|
teams, err := s.repository.GetTeams(ctx)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
|
}
|
|
res := make([]*proto.TeamAdvanced, 0, len(teams))
|
|
for _, team := range teams {
|
|
res = append(res, mapTeamsToTeamAdvanced(team))
|
|
}
|
|
return &proto.GetTeamsRsp{Teams: res}, err
|
|
}
|
|
|
|
func (s *Services) AddTeams(ctx context.Context, req *proto.AddTeamsReq) (*proto.AddTeamsRsp, error) {
|
|
inTeams := make([]*models.Team, 0, len(req.Teams))
|
|
for _, team := range req.Teams {
|
|
t := mapProtoTeamsToTeam(team)
|
|
t.Password = password.GenPass(8)
|
|
inTeams = append(inTeams, t)
|
|
}
|
|
teams, err := s.repository.AddTeams(ctx, inTeams)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, err.Error())
|
|
}
|
|
res := make([]*proto.TeamFull, 0, len(teams))
|
|
for _, team := range teams {
|
|
res = append(res, mapTeamsToTeamFull(team))
|
|
}
|
|
return &proto.AddTeamsRsp{Teams: res}, err
|
|
}
|