From 4b8c601c31edd92c42ff56eb735430316e236e0f Mon Sep 17 00:00:00 2001 From: Anish Date: Mon, 7 Oct 2024 00:40:48 +0530 Subject: [PATCH] added a method description --- .../com/libraryman_api/book/BookService.java | 23 ++++++++++++++++ .../borrowing/BorrowingService.java | 26 +++++++++++++++++++ .../libraryman_api/member/MemberService.java | 23 ++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/src/main/java/com/libraryman_api/book/BookService.java b/src/main/java/com/libraryman_api/book/BookService.java index 1c63cef..3cb288b 100644 --- a/src/main/java/com/libraryman_api/book/BookService.java +++ b/src/main/java/com/libraryman_api/book/BookService.java @@ -112,6 +112,17 @@ public void deleteBook(int bookId) { .orElseThrow(() -> new ResourceNotFoundException("Book not found")); bookRepository.delete(book); } + /** + * Converts a Book entity to a BookDto object. + * + *

This method takes a Book entity and transforms it into a BookDto object for + * data transfer between application layers. It maps all relevant book details, + * including book ID, publisher, published year, title, author, genre, ISBN, + * and copies available, from the entity to the DTO.

+ * + * @param book the entity object containing book information + * @return a BookDto object with data populated from the entity + */ public BookDto EntityToDto(Book book){ BookDto bookDto= new BookDto(); @@ -125,6 +136,18 @@ public BookDto EntityToDto(Book book){ bookDto.setCopiesAvailable(book.getCopiesAvailable()); return bookDto; } + /** + * Converts a BookDto object to a Book entity. + * + *

This method takes a BookDto object and converts it into a Book entity for + * use in database operations. It maps all relevant book details, including + * book ID, author, genre, publisher, published year, title, ISBN, and copies + * available, from the DTO to the entity.

+ * + * @param bookDto the DTO object containing book information + * @return a Book entity with data populated from the DTO + */ + public Book DtoToEntity(BookDto bookDto){ Book book= new Book(); diff --git a/src/main/java/com/libraryman_api/borrowing/BorrowingService.java b/src/main/java/com/libraryman_api/borrowing/BorrowingService.java index ac9c22f..c16f5e0 100644 --- a/src/main/java/com/libraryman_api/borrowing/BorrowingService.java +++ b/src/main/java/com/libraryman_api/borrowing/BorrowingService.java @@ -291,6 +291,19 @@ public Page getAllBorrowingsOfMember(int memberId, Pageable pagea throw new InvalidSortFieldException("The specified 'sortBy' value is invalid."); } } + /** + * Converts a BorrowingsDto object to a Borrowings entity. + * + *

This method takes a BorrowingsDto object and transforms it into a Borrowings + * entity for use in database operations. It maps all relevant borrowing details + * from the DTO, including borrow date, member information, fine, return date, + * due date, and book details. It also retrieves and converts related entities + * such as Member and Book using respective service methods.

+ * + * @param borrowingsDto the DTO object containing borrowing information + * @return a Borrowings entity with data populated from the DTO + */ + public Borrowings DtoToEntity(BorrowingsDto borrowingsDto){ Borrowings borrowings = new Borrowings(); @@ -303,6 +316,19 @@ public Borrowings DtoToEntity(BorrowingsDto borrowingsDto){ borrowings.setBorrowingId(borrowingsDto.getBorrowingId()); return borrowings; } + /** + * Converts a Borrowings entity to a BorrowingsDto object. + * + *

This method takes a Borrowings entity and converts it into a BorrowingsDto + * object for data transfer between application layers. It maps all necessary + * borrowing details from the entity, including borrowing ID, fine, borrow date, + * return date, due date, and related Member and Book entities, converting them + * into DTOs using respective service methods.

+ * + * @param borrowings the entity object containing borrowing information + * @return a BorrowingsDto object with data populated from the entity + */ + public BorrowingsDto EntityToDto(Borrowings borrowings){ BorrowingsDto borrowingsDto = new BorrowingsDto(); diff --git a/src/main/java/com/libraryman_api/member/MemberService.java b/src/main/java/com/libraryman_api/member/MemberService.java index b4ecd2f..d45f782 100644 --- a/src/main/java/com/libraryman_api/member/MemberService.java +++ b/src/main/java/com/libraryman_api/member/MemberService.java @@ -135,6 +135,17 @@ public void deleteMember(int memberId) { notificationService.accountDeletionNotification(member); memberRepository.delete(member); } + /** + * Converts a MembersDto object to a Members entity. + * + *

This method takes a MembersDto object and transforms it into a Members entity + * to be used in database operations. It maps all relevant member details from + * the DTO, including member ID, role, name, email, password, and membership date.

+ * + * @param membersDto the DTO object containing member information + * @return a Members entity with data populated from the DTO + */ + public Members DtoEntity(MembersDto membersDto){ Members members= new Members(); @@ -146,6 +157,18 @@ public Members DtoEntity(MembersDto membersDto){ members.setMembershipDate(membersDto.getMembershipDate()); return members; } + /** + * Converts a Members entity to a MembersDto object. + * + *

This method takes a Members entity object and converts it into a MembersDto + * object to be used for data transfer between layers. It maps all necessary + * member details, including member ID, name, role, email, password, and membership + * date, from the entity to the DTO.

+ * + * @param members the entity object containing member information + * @return a MembersDto object with data populated from the entity + */ + public MembersDto EntityToDto(Members members){ MembersDto membersDto= new MembersDto();