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

@ -133,6 +133,47 @@ public class GroupRestAPI {
return ResponseEntity.ok(group); 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") @PostMapping("/{id}/member")
public ResponseEntity<Group> addUserToGroup(@PathVariable String id, @RequestBody String userId) { public ResponseEntity<Group> addUserToGroup(@PathVariable String id, @RequestBody String userId) {

View File

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