From 31e61c6762fde405323ee98273c9f241051174c1 Mon Sep 17 00:00:00 2001 From: Akito123321 Date: Sat, 15 Jun 2024 19:21:08 +0200 Subject: [PATCH] even more data --- .../rest/controller/GroupRestAPI.java | 17 +++++++++-- .../rest/requests/StratRequest.java | 5 +++- .../akito123321/valoStrats/schemas/Group.java | 9 ++++++ .../akito123321/valoStrats/schemas/Strat.java | 30 ++++++++++++++++++- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/akito123321/valoStrats/rest/controller/GroupRestAPI.java b/src/main/java/me/akito123321/valoStrats/rest/controller/GroupRestAPI.java index e6c24cc..1e9c1d8 100644 --- a/src/main/java/me/akito123321/valoStrats/rest/controller/GroupRestAPI.java +++ b/src/main/java/me/akito123321/valoStrats/rest/controller/GroupRestAPI.java @@ -9,7 +9,6 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -161,7 +160,14 @@ public class GroupRestAPI { return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); } - Strat strat = new Strat(stratRequest.title(), stratRequest.description(), group); + Strat strat = new Strat(stratRequest.title(), stratRequest.description(), group, stratRequest.stratType()); + + if(stratRequest.attempts() != null) { + strat.setAttempts(stratRequest.attempts()); + } + if(stratRequest.success() != null) { + strat.setSuccess(stratRequest.success()); + } stratService.saveStrat(strat); @@ -220,6 +226,13 @@ public class GroupRestAPI { strat.setDescription(newStrat.description()); strat.setTitle(newStrat.title()); strat.setStratStates(newStrat.stratStates()); + strat.setStratType(newStrat.stratType()); + if(newStrat.attempts() != null) { + strat.setAttempts(newStrat.attempts()); + } + if(newStrat.success() != null) { + strat.setSuccess(newStrat.success()); + } stratService.saveStrat(strat); diff --git a/src/main/java/me/akito123321/valoStrats/rest/requests/StratRequest.java b/src/main/java/me/akito123321/valoStrats/rest/requests/StratRequest.java index 15e4496..7307b9f 100644 --- a/src/main/java/me/akito123321/valoStrats/rest/requests/StratRequest.java +++ b/src/main/java/me/akito123321/valoStrats/rest/requests/StratRequest.java @@ -10,5 +10,8 @@ import me.akito123321.valoStrats.schemas.StratState; public record StratRequest( @Size(max = 50, message = "{title longer than 50 chars}") @NotBlank String title, @Size(max = 512, message = "{title longer than 50 chars}") @NotBlank String description, - @NotNull List stratStates) { + @Size(max = 50, message = "{title longer than 50 chars}") @NotBlank String stratType, + @NotNull List stratStates, + Integer attempts, + Integer success) { } diff --git a/src/main/java/me/akito123321/valoStrats/schemas/Group.java b/src/main/java/me/akito123321/valoStrats/schemas/Group.java index 0c299af..8af92d1 100644 --- a/src/main/java/me/akito123321/valoStrats/schemas/Group.java +++ b/src/main/java/me/akito123321/valoStrats/schemas/Group.java @@ -3,6 +3,7 @@ package me.akito123321.valoStrats.schemas; import java.util.ArrayList; import java.util.List; +import jakarta.persistence.ElementCollection; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; @@ -30,6 +31,9 @@ public class Group { @ManyToMany(fetch = FetchType.EAGER) private List profiles; + + @ElementCollection(fetch = FetchType.EAGER) + private List stratTypes; public Group(String name, StratsUser owner) { this.name = name; @@ -38,6 +42,7 @@ public class Group { this.strats = new ArrayList(); this.maps = new ArrayList(); this.profiles = new ArrayList(); + this.stratTypes = new ArrayList(); } public Group() { @@ -68,4 +73,8 @@ public class Group { this.name = name; } + public List getStratTypes() { + return stratTypes; + } + } diff --git a/src/main/java/me/akito123321/valoStrats/schemas/Strat.java b/src/main/java/me/akito123321/valoStrats/schemas/Strat.java index 739dc16..3110139 100644 --- a/src/main/java/me/akito123321/valoStrats/schemas/Strat.java +++ b/src/main/java/me/akito123321/valoStrats/schemas/Strat.java @@ -19,6 +19,9 @@ public class Strat { private String id; private String title; private String description; + private String stratType; + private int attempts = 0, success = 0; + @ManyToOne private Group group; @@ -31,10 +34,11 @@ public class Strat { @ManyToOne private Map map; - public Strat(String title, String description, Group group) { + public Strat(String title, String description, Group group, String stratType) { this.title = title; this.description = description; this.group = group; + this.stratType = stratType; this.stratStates = new ArrayList(); this.stratStates = new ArrayList(); this.playerTypes = new ArrayList(); @@ -72,4 +76,28 @@ public class Strat { this.stratStates = stratStates; } + public String getStratType() { + return stratType; + } + + public void setStratType(String stratType) { + this.stratType = stratType; + } + + public int getAttempts() { + return attempts; + } + + public void setAttempts(int attempts) { + this.attempts = attempts; + } + + public int getSuccess() { + return success; + } + + public void setSuccess(int success) { + this.success = success; + } + }