Skip to content

Commit 663e8bd

Browse files
authored
Merge pull request #29 from SLUDI/main
Refactor organization users function
2 parents 70c330a + bd400a4 commit 663e8bd

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

.gradle/file-system.probe

0 Bytes
Binary file not shown.

build/reports/problems/problems-report.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@
650650
<script type="text/javascript">
651651
function configurationCacheProblems() { return (
652652
// begin-report-data
653-
{"diagnostics":[{"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/9.0.0/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('url = <value>') instead."}]]},{"locations":[{"path":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/VerifiableCredentialService.java"},{"taskPath":":compileJava"}],"problem":[{"text":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/VerifiableCredentialService.java uses unchecked or unsafe operations."}],"severity":"ADVICE","problemDetails":[{"text":"Note: /home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/VerifiableCredentialService.java uses unchecked or unsafe operations."}],"contextualLabel":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/VerifiableCredentialService.java uses unchecked or unsafe operations.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.filename","displayName":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/VerifiableCredentialService.java uses unchecked or unsafe operations."}]},{"locations":[{"path":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/VerifiableCredentialService.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Recompile with -Xlint:unchecked for details."}],"severity":"ADVICE","problemDetails":[{"text":"Note: Recompile with -Xlint:unchecked for details."}],"contextualLabel":"Recompile with -Xlint:unchecked for details.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.recompile","displayName":"Recompile with -Xlint:unchecked for details."}]}],"problemsReport":{"totalProblemCount":3,"buildName":"SLUDI-Backend","requestedTasks":":org.example.SLUDIBackendApplication.main()","documentationLink":"https://docs.gradle.org/9.0.0/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
653+
{"diagnostics":[{"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/9.0.0/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('url = <value>') instead."}]]},{"locations":[{"path":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/FingerprintService.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Some input files use or override a deprecated API."}],"severity":"ADVICE","problemDetails":[{"text":"Note: Some input files use or override a deprecated API."}],"contextualLabel":"Some input files use or override a deprecated API.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.deprecated.plural","displayName":"Some input files use or override a deprecated API."}]},{"locations":[{"path":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/FingerprintService.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Recompile with -Xlint:deprecation for details."}],"severity":"ADVICE","problemDetails":[{"text":"Note: Recompile with -Xlint:deprecation for details."}],"contextualLabel":"Recompile with -Xlint:deprecation for details.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.deprecated.recompile","displayName":"Recompile with -Xlint:deprecation for details."}]},{"locations":[{"path":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/HyperledgerService.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Some input files use unchecked or unsafe operations."}],"severity":"ADVICE","problemDetails":[{"text":"Note: Some input files use unchecked or unsafe operations."}],"contextualLabel":"Some input files use unchecked or unsafe operations.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.plural","displayName":"Some input files use unchecked or unsafe operations."}]},{"locations":[{"path":"/home/tishan/development/FYP/SLUDI-Backend/src/main/java/org/example/service/HyperledgerService.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Recompile with -Xlint:unchecked for details."}],"severity":"ADVICE","problemDetails":[{"text":"Note: Recompile with -Xlint:unchecked for details."}],"contextualLabel":"Recompile with -Xlint:unchecked for details.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.recompile","displayName":"Recompile with -Xlint:unchecked for details."}]}],"problemsReport":{"totalProblemCount":5,"buildName":"SLUDI-Backend","requestedTasks":":classes :testClasses","documentationLink":"https://docs.gradle.org/9.0.0/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
654654
// end-report-data
655655
);}
656656
</script>

src/main/java/org/example/controller/OrganizationUserController.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,44 @@ public ResponseEntity<ApiResponseDto<List<OrganizationUserResponseDto>>> getOrga
176176
}
177177
}
178178

179+
/**
180+
* Get all users of an organization
181+
* GET /api/organization-users/get-all
182+
*/
183+
@GetMapping("/organization/{organizationId}")
184+
@Operation(
185+
security = {@SecurityRequirement(name = "bearerAuth")}
186+
)
187+
public ResponseEntity<ApiResponseDto<List<OrganizationUserResponseDto>>> getAllOrganizationsUsers() {
188+
189+
log.info("Fetching all organizations users");
190+
191+
try {
192+
List<OrganizationUserResponseDto> users = userService.getAllOrgUsers();
193+
194+
ApiResponseDto<List<OrganizationUserResponseDto>> apiResponse = ApiResponseDto.<List<OrganizationUserResponseDto>>builder()
195+
.success(true)
196+
.message("Users fetched successfully")
197+
.data(users)
198+
.timestamp(Instant.now())
199+
.build();
200+
201+
return ResponseEntity.ok(apiResponse);
202+
203+
} catch (Exception ex) {
204+
log.error("Error fetching users: {}", ex.getMessage(), ex);
205+
206+
ApiResponseDto<List<OrganizationUserResponseDto>> apiResponse = ApiResponseDto.<List<OrganizationUserResponseDto>>builder()
207+
.success(false)
208+
.message("Failed to fetch users")
209+
.errorCode("FETCH_ERROR")
210+
.timestamp(Instant.now())
211+
.build();
212+
213+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(apiResponse);
214+
}
215+
}
216+
179217
/**
180218
* Get user details by ID
181219
* GET /api/organization-users/{userId}
@@ -385,6 +423,9 @@ public ResponseEntity<ApiResponseDto<OrganizationUserResponseDto>> reactivateUse
385423
* GET /api/organization-users/verify-permission
386424
*/
387425
@GetMapping("/verify-permission")
426+
@Operation(
427+
security = {@SecurityRequirement(name = "bearerAuth")}
428+
)
388429
public ResponseEntity<ApiResponseDto<Boolean>> verifyUserPermission(
389430
@RequestParam String username,
390431
@RequestParam String permission) {
@@ -422,6 +463,9 @@ public ResponseEntity<ApiResponseDto<Boolean>> verifyUserPermission(
422463
* POST /api/organization-users/organization/{organizationId}/roles/initialize
423464
*/
424465
@PostMapping("/organization/{organizationId}/roles/initialize")
466+
@Operation(
467+
security = {@SecurityRequirement(name = "bearerAuth")}
468+
)
425469
public ResponseEntity<ApiResponseDto<List<OrganizationRole>>> initializeOrganizationRoles(
426470
@PathVariable Long organizationId) {
427471

@@ -641,6 +685,9 @@ public ResponseEntity<ApiResponseDto<Void>> resetPassword(
641685
* DELETE /api/organization-users/{userId}
642686
*/
643687
@DeleteMapping("/{userId}")
688+
@Operation(
689+
security = {@SecurityRequirement(name = "bearerAuth")}
690+
)
644691
public ResponseEntity<ApiResponseDto<Void>> deleteUser(
645692
@PathVariable Long userId,
646693
@RequestParam Long deletedBy) {

src/main/java/org/example/service/OrganizationService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public OrganizationResponse createOrganization (CreateOrganizationRequest reques
9393
// Save to database
9494
organization = organizationRepository.save(organization);
9595

96-
// Log audit trail
96+
// Initialize roles
97+
userService.initializeOrganizationRoles(organization.getId());
9798

9899
log.info("Organization created successfully with ID: {} and code: {}",
99100
organization.getId(), organization.getOrgCode());

src/main/java/org/example/service/OrganizationUserService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,14 @@ public void changePassword(String username, ChangePasswordRequestDto request) {
967967
log.info("Password changed successfully for user: {}", username);
968968
}
969969

970+
public List<OrganizationUserResponseDto> getAllOrgUsers() {
971+
List<OrganizationUser> organizationUserList = userRepository.findAll();
972+
973+
return organizationUserList.stream()
974+
.map(this::mapToUserResponse)
975+
.collect(Collectors.toList());
976+
}
977+
970978
// Helper Methods
971979
/**
972980
* Generate unique Fabric user ID
@@ -996,6 +1004,7 @@ private OrganizationUserResponseDto mapToUserResponse(OrganizationUser user) {
9961004
.lastName(user.getLastName())
9971005
.phone(user.getPhone())
9981006
.organizationId(user.getOrganization().getId())
1007+
.organizationCode(user.getOrganization().getOrgCode())
9991008
.organizationName(user.getOrganization().getName())
10001009
.roleId(user.getAssignedRole().getId())
10011010
.roleCode(user.getAssignedRole().getRoleCode())

0 commit comments

Comments
 (0)