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