-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aecfe7
commit 7e217bf
Showing
13 changed files
with
566 additions
and
89 deletions.
There are no files selected for viewing
This file contains 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 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 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
49 changes: 42 additions & 7 deletions
49
src/main/java/com/libraryman_api/controller/MemberController.java
This file contains 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 |
---|---|---|
@@ -1,53 +1,88 @@ | ||
package com.libraryman_api.controller; | ||
|
||
import com.libraryman_api.entity.Borrowings; | ||
import com.libraryman_api.entity.Members; | ||
import com.libraryman_api.exception.ResourceNotFoundException; | ||
import com.libraryman_api.service.BorrowingService; | ||
import com.libraryman_api.service.MemberService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* REST controller for managing library members. | ||
* This controller provides endpoints for performing CRUD operations on members. | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/members") | ||
public class MemberController { | ||
|
||
private final MemberService memberService; | ||
|
||
/** | ||
* Constructs a new {@code MemberController} with the specified {@link MemberService}. | ||
* | ||
* @param memberService the service to handle member-related operations | ||
*/ | ||
public MemberController(MemberService memberService) { | ||
this.memberService = memberService; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Retrieves a list of all library members. | ||
* | ||
* @return a list of {@link Members} representing all members in the library | ||
*/ | ||
@GetMapping | ||
public List<Members> getAllMembers() { | ||
return memberService.getAllMembers(); | ||
} | ||
|
||
/** | ||
* Retrieves a library member by their ID. | ||
* If the member is not found, a {@link ResourceNotFoundException} is thrown. | ||
* | ||
* @param id the ID of the member to retrieve | ||
* @return a {@link ResponseEntity} containing the found {@link Members} object | ||
*/ | ||
@GetMapping("/{id}") | ||
public ResponseEntity<Members> getMemberById(@PathVariable int id) { | ||
return memberService.getMemberById(id) | ||
.map(ResponseEntity::ok) | ||
.orElseThrow(() -> new ResourceNotFoundException("Member not found")); | ||
} | ||
|
||
/** | ||
* Adds a new library member. | ||
* | ||
* @param member the {@link Members} object representing the new member | ||
* @return the added {@link Members} object | ||
*/ | ||
@PostMapping | ||
public Members addMember(@RequestBody Members member) { | ||
return memberService.addMember(member); | ||
} | ||
|
||
/** | ||
* Updates an existing library member. | ||
* If the member is not found, a {@link ResourceNotFoundException} is thrown. | ||
* | ||
* @param id the ID of the member to update | ||
* @param memberDetails the {@link Members} object containing the updated details | ||
* @return the updated {@link Members} object | ||
*/ | ||
@PutMapping("/{id}") | ||
public Members updateMember(@PathVariable int id, @RequestBody Members memberDetails) { | ||
return memberService.updateMember(id, memberDetails); | ||
} | ||
|
||
/** | ||
* Deletes a library member by their ID. | ||
* If the member is not found, a {@link ResourceNotFoundException} is thrown. | ||
* | ||
* @param id the ID of the member to delete | ||
*/ | ||
@DeleteMapping("/{id}") | ||
public void deleteMember(@PathVariable int id) { | ||
memberService.deleteMember(id); | ||
} | ||
} | ||
|
This file contains 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 |
---|---|---|
@@ -1,6 +1,22 @@ | ||
package com.libraryman_api.email; | ||
|
||
import com.libraryman_api.entity.Notifications; | ||
|
||
/** | ||
* Interface representing an email sending service for the Library Management System. | ||
* Classes implementing this interface are responsible for sending emails | ||
* and updating the status of notifications in the system. | ||
*/ | ||
public interface EmailSender { | ||
void send (String to, String body, String subject, Notifications notification); | ||
|
||
/** | ||
* Sends an email to the specified recipient with the given body, subject, and notification details. | ||
* | ||
* @param to the email address of the recipient | ||
* @param body the body of the email, typically in HTML or plain text format | ||
* @param subject the subject of the email | ||
* @param notification the notification entity associated with the email being sent, | ||
* used to track the status of the notification | ||
*/ | ||
void send(String to, String body, String subject, Notifications notification); | ||
} |
This file contains 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
Oops, something went wrong.