File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
src/main/java/com/ase/angelos_kb_backend Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 5
5
import com .ase .angelos_kb_backend .util .JwtUtil ;
6
6
7
7
import java .util .List ;
8
+ import java .util .UUID ;
8
9
import java .util .stream .Collectors ;
9
10
10
11
import org .springframework .http .HttpStatus ;
@@ -52,6 +53,24 @@ public ResponseEntity<OrganisationDTO> addOrganisation(
52
53
return ResponseEntity .status (HttpStatus .CREATED ).body (newOrganisation );
53
54
}
54
55
56
+ /**
57
+ * Update an existing organisation. Only accessible by system admin.
58
+ */
59
+ @ PutMapping ("/{id}" )
60
+ public ResponseEntity <OrganisationDTO > updateOrganisation (
61
+ @ RequestHeader ("Authorization" ) String token ,
62
+ @ PathVariable Long id ,
63
+ @ RequestBody OrganisationDTO organisation ) {
64
+ if (!jwtUtil .extractIsSystemAdmin (token .replace ("Bearer " , "" ))) {
65
+ return ResponseEntity .status (HttpStatus .FORBIDDEN ).build ();
66
+ }
67
+ OrganisationDTO newOrganisation = organisationService .updateOrganisation (id , organisation );
68
+ if (newOrganisation == null ) {
69
+ return ResponseEntity .status (HttpStatus .NOT_FOUND ).build ();
70
+ }
71
+ return ResponseEntity .ok (newOrganisation );
72
+ }
73
+
55
74
/**
56
75
* Remove an organisation by ID. Only accessible by system admin.
57
76
*/
Original file line number Diff line number Diff line change 1
1
package com .ase .angelos_kb_backend .service ;
2
2
3
3
import java .util .List ;
4
+ import java .util .Optional ;
4
5
import java .util .stream .Collectors ;
5
6
6
7
import org .springframework .stereotype .Service ;
@@ -33,6 +34,18 @@ public OrganisationDTO addOrganisation(String name) {
33
34
Organisation savedOrganisation = organisationRepository .save (organisation );
34
35
return convertToDto (savedOrganisation );
35
36
}
37
+ public OrganisationDTO updateOrganisation (Long id , OrganisationDTO updatedOrganisation ) {
38
+ Optional <Organisation > optionalOrg = organisationRepository .findById (id );
39
+ if (optionalOrg .isEmpty ()) {
40
+ return null ;
41
+ }
42
+ Organisation existingOrg = optionalOrg .get ();
43
+ if (updatedOrganisation .getName () != null ) {
44
+ existingOrg .setName (updatedOrganisation .getName ());
45
+ }
46
+ Organisation savedOrg = organisationRepository .save (existingOrg );
47
+ return convertToDto (savedOrg );
48
+ }
36
49
37
50
public boolean removeOrganisation (Long orgId ) {
38
51
if (organisationRepository .existsById (orgId )) {
You can’t perform that action at this time.
0 commit comments