|
|
@ -17,17 +17,23 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.rest.requests.GroupRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.requests.GroupRequest;
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.rest.requests.LineupRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.requests.MapRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.requests.MapRequest;
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.rest.requests.PlayerTypeRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.requests.StratRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.requests.StratRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.requests.StratStateRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.requests.StratStateRequest;
|
|
|
|
import me.akito123321.valoStrats.rest.services.GroupService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.GroupService;
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.rest.services.LineupService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.MapService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.MapService;
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.rest.services.PlayerTypeService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.ProfileService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.ProfileService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.StratService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.StratService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.StratStateService;
|
|
|
|
import me.akito123321.valoStrats.rest.services.StratStateService;
|
|
|
|
import me.akito123321.valoStrats.rest.util.JDBCUserDetailsService;
|
|
|
|
import me.akito123321.valoStrats.rest.util.JDBCUserDetailsService;
|
|
|
|
import me.akito123321.valoStrats.schemas.Group;
|
|
|
|
import me.akito123321.valoStrats.schemas.Group;
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.schemas.Lineup;
|
|
|
|
import me.akito123321.valoStrats.schemas.Map;
|
|
|
|
import me.akito123321.valoStrats.schemas.Map;
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.schemas.PlayerType;
|
|
|
|
import me.akito123321.valoStrats.schemas.Profile;
|
|
|
|
import me.akito123321.valoStrats.schemas.Profile;
|
|
|
|
import me.akito123321.valoStrats.schemas.Strat;
|
|
|
|
import me.akito123321.valoStrats.schemas.Strat;
|
|
|
|
import me.akito123321.valoStrats.schemas.StratState;
|
|
|
|
import me.akito123321.valoStrats.schemas.StratState;
|
|
|
@ -37,6 +43,12 @@ import me.akito123321.valoStrats.schemas.StratsUser;
|
|
|
|
@RequestMapping("/api/group")
|
|
|
|
@RequestMapping("/api/group")
|
|
|
|
public class GroupRestAPI {
|
|
|
|
public class GroupRestAPI {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private PlayerTypeService playerTypeService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private LineupService lineupService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ProfileService profileService;
|
|
|
|
private ProfileService profileService;
|
|
|
|
|
|
|
|
|
|
|
@ -179,6 +191,9 @@ public class GroupRestAPI {
|
|
|
|
if(stratRequest.success() != null) {
|
|
|
|
if(stratRequest.success() != null) {
|
|
|
|
strat.setSuccess(stratRequest.success());
|
|
|
|
strat.setSuccess(stratRequest.success());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStratTypes().contains(stratRequest.stratType())) {
|
|
|
|
|
|
|
|
group.getStratTypes().add(stratRequest.stratType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
|
|
|
@ -240,6 +255,9 @@ public class GroupRestAPI {
|
|
|
|
if(newStrat.success() != null) {
|
|
|
|
if(newStrat.success() != null) {
|
|
|
|
strat.setSuccess(newStrat.success());
|
|
|
|
strat.setSuccess(newStrat.success());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStratTypes().contains(newStrat.stratType())) {
|
|
|
|
|
|
|
|
group.getStratTypes().add(newStrat.stratType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
|
|
|
@ -394,6 +412,187 @@ public class GroupRestAPI {
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/strat/{stratId}/player-type")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> addPlayerType(@PathVariable String id, @PathVariable String stratId , @RequestBody PlayerTypeRequest playerTypeRequest) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PlayerType playerType = new PlayerType(playerTypeRequest.name(), playerTypeRequest.task());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerTypeService.savePlayerType(playerType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strat.getPlayerTypes().add(playerType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{id}/strat/{stratId}/player-type/{playerTypeId}")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> removePlayerType(@PathVariable String id, @PathVariable String stratId, @PathVariable String playerTypeId) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
PlayerType playerType = playerTypeService.getPlayerTypeById(playerTypeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null | playerType == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) | !strat.getPlayerTypes().contains(playerType)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerTypeService.removePlayerType(playerType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strat.getPlayerTypes().remove(playerType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping("/{id}/strat/{stratId}/player-type/{playerTypeId}")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> editPlayerType(@PathVariable String id, @PathVariable String stratId, @PathVariable String playerTypeId, @RequestBody PlayerTypeRequest newPlayerType) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
PlayerType playerType = playerTypeService.getPlayerTypeById(playerTypeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null | playerType == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) | !strat.getPlayerTypes().contains(playerType)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerType.setName(newPlayerType.name());
|
|
|
|
|
|
|
|
playerType.setTask(newPlayerType.task());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerTypeService.savePlayerType(playerType);
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/strat/{stratId}/player-type/{playerTypeId}/profile")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> addProfile(@PathVariable String id, @PathVariable String stratId, @PathVariable String playerTypeId , @RequestBody ProfileRequest profileRequest) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
PlayerType playerType = playerTypeService.getPlayerTypeById(playerTypeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null| playerTypeId == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) && !strat.getPlayerTypes().contains(playerType)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Profile profile = new Profile(profileRequest.name(), profileRequest.image());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profileService.saveProfile(profile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerType.getProfiles().add(profile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerTypeService.savePlayerType(playerType);
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!group.getProfiles().contains(profile)) {
|
|
|
|
|
|
|
|
group.getProfiles().add(profile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{id}/strat/{stratId}/player-type/{playerTypeId}/profile/{profileId}")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> removeProfile(@PathVariable String id, @PathVariable String stratId, @PathVariable String playerTypeId, @PathVariable String profileId) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
PlayerType playerType = playerTypeService.getPlayerTypeById(playerTypeId);
|
|
|
|
|
|
|
|
Profile profile = profileService.getProfileById(profileId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null | playerType == null | profile == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) | !strat.getPlayerTypes().contains(playerType) | !playerType.getProfiles().contains(profile)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profileService.removeProfile(profile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerType.getProfiles().remove(profile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerTypeService.savePlayerType(playerType);
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping("/{id}/strat/{stratId}/player-type/{playerTypeId}profile/{profileId}") //TODO remove privius from playerType and create new and add to group if not existend in group
|
|
|
|
|
|
|
|
public ResponseEntity<Group> editProfile(@PathVariable String id, @PathVariable String stratId, @PathVariable String playerTypeId, @PathVariable String profileId, @RequestBody ProfileRequest newProfile) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
PlayerType playerType = playerTypeService.getPlayerTypeById(playerTypeId);
|
|
|
|
|
|
|
|
Profile profile = profileService.getProfileById(profileId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null | playerType == null | profile == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) | !strat.getPlayerTypes().contains(playerType) | !playerType.getProfiles().contains(profile)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profile.setName(newProfile.name());
|
|
|
|
|
|
|
|
profile.setImage(newProfile.image());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profileService.saveProfile(profile);
|
|
|
|
|
|
|
|
playerTypeService.savePlayerType(playerType);
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/strat/{stratId}/strat-state")
|
|
|
|
@PostMapping("/{id}/strat/{stratId}/strat-state")
|
|
|
|
public ResponseEntity<Group> addStratState(@PathVariable String id, @PathVariable String stratId , @RequestBody StratStateRequest stratStateRequest) {
|
|
|
|
public ResponseEntity<Group> addStratState(@PathVariable String id, @PathVariable String stratId , @RequestBody StratStateRequest stratStateRequest) {
|
|
|
|
StratsUser user = getUser();
|
|
|
|
StratsUser user = getUser();
|
|
|
@ -479,6 +678,97 @@ public class GroupRestAPI {
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/strat/{stratId}/strat-state/{stratStateId}/lineup")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> addLineup(@PathVariable String id, @PathVariable String stratId, @PathVariable String stratStateId, @RequestBody LineupRequest lineupRequest) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
StratState stratState = stratStateService.getStratStateById(stratStateId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null | stratState == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) && !strat.getStratStates().contains(stratState)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Lineup lineup = new Lineup(lineupRequest.description(), lineupRequest.image());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lineupService.saveLineup(lineup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stratState.getLineups().add(lineup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stratStateService.saveStratState(stratState);
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{id}/strat/{stratId}/strat-state/{stratStateId}/lineup/{lineupId}")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> removeLineup(@PathVariable String id, @PathVariable String stratId, @PathVariable String stratStateId, @PathVariable String linupId) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
StratState stratState = stratStateService.getStratStateById(stratStateId);
|
|
|
|
|
|
|
|
Lineup lineup = lineupService.getLineupById(linupId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null | stratState == null | lineup == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) | !strat.getStratStates().contains(stratState) | !stratState.getLineups().contains(lineup)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lineupService.removeLineup(lineup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stratState.getLineups().remove(lineup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping("/{id}/strat/{stratId}/strat-state/{stratStateId}/lineup/{lineupId}")
|
|
|
|
|
|
|
|
public ResponseEntity<Group> editLineup(@PathVariable String id, @PathVariable String stratId, @PathVariable String stratStateId, @PathVariable String lineupId, @RequestBody LineupRequest newLineup) {
|
|
|
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
|
|
|
StratState stratState = stratStateService.getStratStateById(stratStateId);
|
|
|
|
|
|
|
|
Lineup lineup = lineupService.getLineupById(lineupId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (group == null | strat == null | stratState == null | lineup == null) {
|
|
|
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!group.getStrats().contains(strat) | !strat.getStratStates().contains(stratState) | !stratState.getLineups().contains(lineup)) {
|
|
|
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lineup.setDescription(newLineup.description());
|
|
|
|
|
|
|
|
lineup.setLineupImage(newLineup.image());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lineupService.saveLineup(lineup);
|
|
|
|
|
|
|
|
stratStateService.saveStratState(stratState);
|
|
|
|
|
|
|
|
stratService.saveStrat(strat);
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private StratsUser getUser() {
|
|
|
|
private StratsUser getUser() {
|
|
|
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|