generated from VLADIMIR/template
add db
This commit is contained in:
@@ -2,13 +2,22 @@ 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{}
|
||||
type Services struct {
|
||||
repository *Repository
|
||||
}
|
||||
|
||||
func NewServices() *Services {
|
||||
return &Services{}
|
||||
func NewServices(repository *Repository) *Services {
|
||||
return &Services{
|
||||
repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Services) GiveApplications(ctx context.Context, req *proto.GiveApplicationsReq) (*proto.GiveApplicationsRsp, error) {
|
||||
@@ -39,10 +48,32 @@ func (s *Services) GetTeamsCSV(ctx context.Context, req *proto.GetTeamsCSVReq) (
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (s *Services) GetTeams(ctx context.Context, req *proto.GetTeamsReq) (*proto.GetTeamsRsp, 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) {
|
||||
panic("unimplemented")
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user