generated from VLADIMIR/template
up
This commit is contained in:
parent
e409a69a54
commit
4b44bad1c0
@ -33,3 +33,15 @@ X-Password: pass
|
||||
{
|
||||
"place": "A-1"
|
||||
}
|
||||
|
||||
### Выдача приложения
|
||||
|
||||
POST http://localhost:8090/teams/1/applications
|
||||
|
||||
{
|
||||
"applications": [
|
||||
{
|
||||
"id": 10
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -70,3 +70,17 @@ func mapApplicationToProtoApplication(application *models.Application) *proto.Ap
|
||||
State: application.State,
|
||||
}
|
||||
}
|
||||
|
||||
func mapProtoApplicationsToApplications(items []*proto.Application) []*models.Application {
|
||||
res := make([]*models.Application, 0, len(items))
|
||||
for _, item := range items {
|
||||
res = append(res, mapProtoApplicationToApplication(item))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapProtoApplicationToApplication(items *proto.Application) *models.Application {
|
||||
return &models.Application{
|
||||
ID: items.Id,
|
||||
}
|
||||
}
|
||||
|
@ -90,9 +90,9 @@ func (r *Repository) GetActions(ctx context.Context, teamId int64) ([]*models.Ac
|
||||
return actions, nil
|
||||
}
|
||||
|
||||
func (r *Repository) AddActions(ctx context.Context, actions []*models.Action) error {
|
||||
func (r *Repository) AddActions(ctx context.Context, teamId int64, actions []*models.Action) error {
|
||||
for _, action := range actions {
|
||||
_, err := r.db.Exec("insert into actions (place, teamId) values ($1, $2)", action.Place, action.TeamID)
|
||||
_, err := r.db.Exec("insert into actions (place, teamId) values ($1, $2)", action.Place, teamId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -152,3 +152,13 @@ func (r *Repository) GetApplications(ctx context.Context, teamId int64, state st
|
||||
}
|
||||
return applications, nil
|
||||
}
|
||||
|
||||
func (r *Repository) GiveApplications(ctx context.Context, teamId int64, applications []*models.Application) error {
|
||||
for _, application := range applications {
|
||||
_, err := r.db.Exec("update applications set state = \"gave\" where teamId = $1 and id = $2", teamId, application.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -30,7 +30,11 @@ func NewServices(
|
||||
}
|
||||
|
||||
func (s *Services) GiveApplications(ctx context.Context, req *proto.GiveApplicationsReq) (*proto.GiveApplicationsRsp, error) {
|
||||
panic("unimplemented")
|
||||
applications := mapProtoApplicationsToApplications(req.Applications)
|
||||
if err := s.repository.GiveApplications(ctx, req.TeamId, applications); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
}
|
||||
return &proto.GiveApplicationsRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *Services) GameStop(ctx context.Context, req *proto.GameStopReq) (*proto.GameStopRsp, error) {
|
||||
@ -57,7 +61,7 @@ func (s *Services) AddAction(ctx context.Context, req *proto.AddActionReq) (*pro
|
||||
Applications: mapStoryApplicationsToApplications(place.Applications),
|
||||
},
|
||||
}
|
||||
if err := s.repository.AddActions(ctx, actions); err != nil {
|
||||
if err := s.repository.AddActions(ctx, team.ID, actions); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
}
|
||||
if err := s.repository.AddApplications(ctx, actions); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user