|
|
|
@ -17,13 +17,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import me.akito123321.valoStrats.rest.requests.GroupRequest;
|
|
|
|
|
import me.akito123321.valoStrats.rest.requests.MapRequest;
|
|
|
|
|
import me.akito123321.valoStrats.rest.requests.StratRequest;
|
|
|
|
|
import me.akito123321.valoStrats.rest.requests.StratStateRequest;
|
|
|
|
|
import me.akito123321.valoStrats.rest.services.GroupService;
|
|
|
|
|
import me.akito123321.valoStrats.rest.services.MapService;
|
|
|
|
|
import me.akito123321.valoStrats.rest.services.ProfileService;
|
|
|
|
|
import me.akito123321.valoStrats.rest.services.StratService;
|
|
|
|
|
import me.akito123321.valoStrats.rest.services.StratStateService;
|
|
|
|
|
import me.akito123321.valoStrats.rest.util.JDBCUserDetailsService;
|
|
|
|
|
import me.akito123321.valoStrats.schemas.Group;
|
|
|
|
|
import me.akito123321.valoStrats.schemas.Map;
|
|
|
|
|
import me.akito123321.valoStrats.schemas.Profile;
|
|
|
|
|
import me.akito123321.valoStrats.schemas.Strat;
|
|
|
|
|
import me.akito123321.valoStrats.schemas.StratState;
|
|
|
|
|
import me.akito123321.valoStrats.schemas.StratsUser;
|
|
|
|
@ -32,6 +37,12 @@ import me.akito123321.valoStrats.schemas.StratsUser;
|
|
|
|
|
@RequestMapping("/api/group")
|
|
|
|
|
public class GroupRestAPI {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ProfileService profileService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MapService mapService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StratStateService stratStateService;
|
|
|
|
|
|
|
|
|
@ -183,16 +194,15 @@ public class GroupRestAPI {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
if (group == null) {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
if (strat == null) {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
if (!group.getStrats().contains(strat)) {
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stratService.removeStrat(strat);
|
|
|
|
@ -209,17 +219,14 @@ public class GroupRestAPI {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
if (group == null) {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Strat strat = stratService.getStratById(stratId);
|
|
|
|
|
if (strat == null){
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}if (!group.getStrats().contains(strat)) {
|
|
|
|
|
if (!group.getStrats().contains(strat)) {
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -241,6 +248,152 @@ public class GroupRestAPI {
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/map")
|
|
|
|
|
public ResponseEntity<Group> addMap(@PathVariable String id, @RequestBody MapRequest mapRequest) {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
if (group == null) {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map map = new Map(mapRequest.name(), mapRequest.image());
|
|
|
|
|
|
|
|
|
|
mapService.saveMap(map);
|
|
|
|
|
|
|
|
|
|
group.getMaps().add(map);
|
|
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{id}/map/{mapId}")
|
|
|
|
|
public ResponseEntity<Group> removeMap(@PathVariable String id, @PathVariable String mapId) {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
Map map = mapService.getMapById(mapId);
|
|
|
|
|
if (group == null | map == null) {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMaps().contains(map)) {
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapService.removeMap(map);
|
|
|
|
|
|
|
|
|
|
group.getMaps().remove(map);
|
|
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/{id}/map/{mapId}")
|
|
|
|
|
public ResponseEntity<Group> editMap(@PathVariable String id, @PathVariable String mapId, @RequestBody MapRequest newMap) {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
Map map = mapService.getMapById(mapId);
|
|
|
|
|
if (group == null | map == null) {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMaps().contains(map)) {
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
map.setName(newMap.name());
|
|
|
|
|
map.setImage(newMap.image());
|
|
|
|
|
|
|
|
|
|
mapService.saveMap(map);
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/profile")
|
|
|
|
|
public ResponseEntity<Group> addProfile(@PathVariable String id, @RequestBody ProfileRequest profileRequest) {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
if (group == null) {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Profile profile = new Profile(profileRequest.name(), profileRequest.image());
|
|
|
|
|
|
|
|
|
|
profileService.saveProfile(profile);
|
|
|
|
|
|
|
|
|
|
group.getProfiles().add(profile);
|
|
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{id}/profile/{profileId}")
|
|
|
|
|
public ResponseEntity<Group> removeProfile(@PathVariable String id, @PathVariable String profileId) {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
Profile profile = profileService.getProfileById(profileId);
|
|
|
|
|
if (group == null | profile == null) {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getProfiles().contains(profile)) {
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
profileService.removeProfile(profile);
|
|
|
|
|
|
|
|
|
|
group.getProfiles().remove(profile);
|
|
|
|
|
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/{id}/profile/{profileId}")
|
|
|
|
|
public ResponseEntity<Group> editProfile(@PathVariable String id, @PathVariable String profileId, @RequestBody MapRequest newMap) {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|
|
|
|
|
|
Group group = groupService.getGroupById(id);
|
|
|
|
|
Profile profile = profileService.getProfileById(profileId);
|
|
|
|
|
if (group == null | profile == null) {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getMembers().contains(user)) {
|
|
|
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
|
|
}
|
|
|
|
|
if (!group.getProfiles().contains(profile)) {
|
|
|
|
|
return ResponseEntity.badRequest().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
profile.setName(newMap.name());
|
|
|
|
|
profile.setImage(newMap.image());
|
|
|
|
|
|
|
|
|
|
profileService.saveProfile(profile);
|
|
|
|
|
groupService.saveGroup(group);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/strat/{stratId}/strat-state")
|
|
|
|
|
public ResponseEntity<Group> addStratState(@PathVariable String id, @PathVariable String stratId , @RequestBody StratStateRequest stratStateRequest) {
|
|
|
|
|
StratsUser user = getUser();
|
|
|
|
|