-
Notifications
You must be signed in to change notification settings - Fork 0
feature/add-caseofficer #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4ce8f4b
Add case officer controller, modify security config and custom authen…
gvaguirres a7f5f52
Implemented case assignment and assigned cases view for case officers
gvaguirres 276e282
Add one more officer for testing
gvaguirres 3e9ae01
Change passwords in officers for testing
gvaguirres 3d4bf6d
Fix with code rabbit admin controller
gvaguirres a441b2a
Remove logging @Slf4j
gvaguirres bddbc26
Updated case-officer UI fragments and refined case closing logic
gvaguirres d4ea903
Change password for officers testing
gvaguirres 644146c
Remove System.out.println of authorities and add endpoint to close a …
gvaguirres d3a446a
Add explicit query in repository for method findByAssignedId
gvaguirres d41a1ee
Refactored file access logic to include assigned officer checks and u…
gvaguirres 4b31d5f
Merge branch 'main' into feature/add-caseofficer
gvaguirres 7434800
Merge remote-tracking branch 'origin/feature/add-caseofficer' into fe…
gvaguirres 557a563
Merge branch 'main' into feature/add-caseofficer
gvaguirres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/backendlab/team4you/controller/CaseOfficerController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package backendlab.team4you.controller; | ||
|
|
||
| import backendlab.team4you.caserecord.CaseRecord; | ||
| import backendlab.team4you.caserecord.CaseRecordRepository; | ||
| import backendlab.team4you.caserecord.CaseRecordService; | ||
| import backendlab.team4you.caserecord.CaseStatus; | ||
| import backendlab.team4you.exceptions.CaseRecordNotFoundException; | ||
| import backendlab.team4you.exceptions.UserNotFoundException; | ||
| import backendlab.team4you.user.UserEntity; | ||
| import backendlab.team4you.user.UserRepository; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.ResponseBody; | ||
| import org.springframework.web.server.ResponseStatusException; | ||
|
|
||
| @Controller | ||
| @PreAuthorize("hasRole('CASE_OFFICER')") | ||
| public class CaseOfficerController { | ||
|
|
||
| private final CaseRecordRepository caseRecordRepository; | ||
| private final UserRepository userRepository; | ||
|
|
||
| public CaseOfficerController(CaseRecordRepository caseRecordRepository, UserRepository userRepository) { | ||
| this.caseRecordRepository = caseRecordRepository; | ||
| this.userRepository = userRepository; | ||
| } | ||
|
|
||
| @GetMapping("/case-officer") | ||
| public String caseOfficerHome() { | ||
| return "case-officer"; | ||
| } | ||
|
|
||
| @GetMapping("/case-officer/cases") | ||
| public String listCases( | ||
| @RequestParam(defaultValue = "0") int page, | ||
| Authentication auth, | ||
| Model model | ||
| ) { | ||
| UserEntity officer = userRepository.findByName(auth.getName()) | ||
| .orElseThrow(() -> new UserNotFoundException("Case Officer not found")); | ||
|
|
||
| Page<CaseRecord> cases = | ||
| caseRecordRepository.findByAssignedUserId(officer.getIdAsString(), PageRequest.of(page, 5)); | ||
|
|
||
| model.addAttribute("cases", cases.getContent()); | ||
| model.addAttribute("currentPage", page); | ||
| model.addAttribute("totalPages", cases.getTotalPages()); | ||
|
|
||
| return "fragments/case-officer-cases :: content"; | ||
| } | ||
|
|
||
| @PostMapping("/case-officer/cases/close") | ||
| @ResponseBody | ||
| public String closeCase(@RequestParam String id, Authentication auth) { | ||
| UserEntity officer = userRepository.findByName(auth.getName()) | ||
| .orElseThrow(() -> new UserNotFoundException("Case Officer not found")); | ||
|
|
||
| CaseRecord caseRecord = caseRecordRepository.findById(Long.valueOf(id)) | ||
| .orElseThrow(() -> new CaseRecordNotFoundException(id)); | ||
|
|
||
| if (!caseRecord.getAssignedUser().getId().equals(officer.getId())) { | ||
| throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Not assigned to this officer"); | ||
| } | ||
|
|
||
| caseRecord.setStatus(CaseStatus.CLOSED); | ||
| caseRecordRepository.save(caseRecord); | ||
|
|
||
| return ""; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.