progress
This commit is contained in:
parent
6d0445417c
commit
bae5135bd8
@ -137,6 +137,7 @@ public class GroupRestAPI {
|
|||||||
@PostMapping("/{id}/strat-type")
|
@PostMapping("/{id}/strat-type")
|
||||||
public ResponseEntity<Group> addStratType(@PathVariable String id, @RequestBody String typeName) {
|
public ResponseEntity<Group> addStratType(@PathVariable String id, @RequestBody String typeName) {
|
||||||
StratsUser user = getUser();
|
StratsUser user = getUser();
|
||||||
|
typeName = typeName.replace("\"", "");
|
||||||
|
|
||||||
Group group = groupService.getGroupById(id);
|
Group group = groupService.getGroupById(id);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@ -218,6 +219,8 @@ public class GroupRestAPI {
|
|||||||
StratsUser user = getUser();
|
StratsUser user = getUser();
|
||||||
|
|
||||||
Group group = groupService.getGroupById(id);
|
Group group = groupService.getGroupById(id);
|
||||||
|
Map map = mapService.getMapById(stratRequest.mapId());
|
||||||
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.notFound().build();
|
||||||
}
|
}
|
||||||
@ -225,7 +228,7 @@ public class GroupRestAPI {
|
|||||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
Strat strat = new Strat(stratRequest.title(), stratRequest.description(), group, stratRequest.stratType());
|
Strat strat = new Strat(stratRequest.title(), stratRequest.description(), group, stratRequest.stratType(), map);
|
||||||
|
|
||||||
if(stratRequest.attempts() != null) {
|
if(stratRequest.attempts() != null) {
|
||||||
strat.setAttempts(stratRequest.attempts());
|
strat.setAttempts(stratRequest.attempts());
|
||||||
@ -233,7 +236,7 @@ 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())) {
|
if(stratRequest.stratType() != null && stratRequest.stratType().length() > 0 && !group.getStratTypes().contains(stratRequest.stratType())) {
|
||||||
group.getStratTypes().add(stratRequest.stratType());
|
group.getStratTypes().add(stratRequest.stratType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,6 +280,8 @@ public class GroupRestAPI {
|
|||||||
|
|
||||||
Group group = groupService.getGroupById(id);
|
Group group = groupService.getGroupById(id);
|
||||||
Strat strat = stratService.getStratById(stratId);
|
Strat strat = stratService.getStratById(stratId);
|
||||||
|
Map map = mapService.getMapById(newStrat.mapId());
|
||||||
|
|
||||||
if (group == null | strat == null) {
|
if (group == null | strat == null) {
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.notFound().build();
|
||||||
}
|
}
|
||||||
@ -291,6 +296,7 @@ public class GroupRestAPI {
|
|||||||
strat.setTitle(newStrat.title());
|
strat.setTitle(newStrat.title());
|
||||||
strat.setStratStates(newStrat.stratStates());
|
strat.setStratStates(newStrat.stratStates());
|
||||||
strat.setStratType(newStrat.stratType());
|
strat.setStratType(newStrat.stratType());
|
||||||
|
|
||||||
if(newStrat.attempts() != null) {
|
if(newStrat.attempts() != null) {
|
||||||
strat.setAttempts(newStrat.attempts());
|
strat.setAttempts(newStrat.attempts());
|
||||||
}
|
}
|
||||||
@ -300,6 +306,9 @@ public class GroupRestAPI {
|
|||||||
if(!group.getStratTypes().contains(newStrat.stratType())) {
|
if(!group.getStratTypes().contains(newStrat.stratType())) {
|
||||||
group.getStratTypes().add(newStrat.stratType());
|
group.getStratTypes().add(newStrat.stratType());
|
||||||
}
|
}
|
||||||
|
if(map != null) {
|
||||||
|
strat.setMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
stratService.saveStrat(strat);
|
stratService.saveStrat(strat);
|
||||||
|
|
||||||
|
@ -5,12 +5,14 @@ import java.util.List;
|
|||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
import me.akito123321.valoStrats.schemas.Map;
|
||||||
import me.akito123321.valoStrats.schemas.StratState;
|
import me.akito123321.valoStrats.schemas.StratState;
|
||||||
|
|
||||||
public record StratRequest(
|
public record StratRequest(
|
||||||
@Size(max = 50, message = "{title can not be longer than 50 chars}") @NotBlank String title,
|
@Size(max = 50, message = "{title can not be longer than 50 chars}") @NotBlank String title,
|
||||||
@Size(max = 512, message = "{description can not be longer than 50 chars}") @NotBlank String description,
|
@Size(max = 512, message = "{description can not be longer than 50 chars}") @NotBlank String description,
|
||||||
@Size(max = 50, message = "{title stratType can not be than 50 chars}") @NotBlank String stratType,
|
@Size(max = 50, message = "{title stratType can not be than 50 chars}") String stratType,
|
||||||
|
@NotNull String mapId,
|
||||||
@NotNull List<StratState> stratStates,
|
@NotNull List<StratState> stratStates,
|
||||||
Integer attempts,
|
Integer attempts,
|
||||||
Integer success) {
|
Integer success) {
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package me.akito123321.valoStrats.rest.util;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class GlobalErrorHandler extends ResponseEntityExceptionHandler {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -31,14 +31,15 @@ public class Strat {
|
|||||||
@OneToMany(fetch = FetchType.EAGER)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
private List<PlayerType> playerTypes = new ArrayList<PlayerType>();
|
private List<PlayerType> playerTypes = new ArrayList<PlayerType>();
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
private Map map;
|
private Map map;
|
||||||
|
|
||||||
public Strat(String title, String description, Group group, String stratType) {
|
public Strat(String title, String description, Group group, String stratType, Map map) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.stratType = stratType;
|
this.stratType = stratType;
|
||||||
|
this.map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Strat() {
|
public Strat() {
|
||||||
@ -97,6 +98,14 @@ public class Strat {
|
|||||||
this.success = success;
|
this.success = success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map getMap() {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMap(Map map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
public List<PlayerType> getPlayerTypes() {
|
public List<PlayerType> getPlayerTypes() {
|
||||||
return playerTypes;
|
return playerTypes;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user