added strat-type endpoint and fixed profile schema

This commit is contained in:
Akito123321 2024-06-24 13:10:18 +02:00
parent 6d184ac0c6
commit 1521242653
2 changed files with 45 additions and 0 deletions

View File

@ -134,6 +134,47 @@ public class GroupRestAPI {
return ResponseEntity.ok(group);
}
@PostMapping("/{id}/strat-type")
public ResponseEntity<Group> addStratType(@PathVariable String id, @RequestBody String typeName) {
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();
}
if(group.getStratTypes().contains(typeName)) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}
group.getStratTypes().add(typeName);
groupService.saveGroup(group);
return ResponseEntity.ok(group);
}
@DeleteMapping("/{id}/strat-type/{typeName}")
public ResponseEntity<Group> removeStratType(@PathVariable String id, @PathVariable String typeName) {
StratsUser user = getUser();
Group group = groupService.getGroupById(id);
if (group == null | !group.getStratTypes().contains(typeName)) {
return ResponseEntity.notFound().build();
}
if (!group.getMembers().contains(user)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
group.getStratTypes().remove(typeName);
groupService.saveGroup(group);
return ResponseEntity.ok(group);
}
@PostMapping("/{id}/member")
public ResponseEntity<Group> addUserToGroup(@PathVariable String id, @RequestBody String userId) {
StratsUser user = getUser();

View File

@ -18,6 +18,10 @@ public class Profile {
@Column(length = Integer.MAX_VALUE)
private byte[] image;
public Profile() {
}
public Profile(String name, byte[] image) {
super();
this.name = name;