diff --git a/pom.xml b/pom.xml
index 95e4f3f..2d9aa31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,10 @@
mysql-connector-j
runtime
-
+
+ org.apache.tomcat.embed
+ tomcat-embed-jasper
+
org.springframework.boot
diff --git a/src/main/java/com/libraryman_api/LibrarymanApiApplication.java b/src/main/java/com/libraryman_api/LibrarymanApiApplication.java
index df9a8cf..e95b811 100644
--- a/src/main/java/com/libraryman_api/LibrarymanApiApplication.java
+++ b/src/main/java/com/libraryman_api/LibrarymanApiApplication.java
@@ -2,9 +2,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
+@ComponentScan(basePackages = {"com.libraryman_api"})
@EnableAsync
public class LibrarymanApiApplication {
diff --git a/src/main/java/com/libraryman_api/borrowing/BorrowingService.java b/src/main/java/com/libraryman_api/borrowing/BorrowingService.java
index 668d0cc..c5e427c 100644
--- a/src/main/java/com/libraryman_api/borrowing/BorrowingService.java
+++ b/src/main/java/com/libraryman_api/borrowing/BorrowingService.java
@@ -5,6 +5,8 @@
import com.libraryman_api.fine.Fines;
import com.libraryman_api.exception.ResourceNotFoundException;
import com.libraryman_api.fine.FineRepository;
+import com.libraryman_api.member.MemberService;
+import com.libraryman_api.member.Members;
import com.libraryman_api.notification.NotificationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -39,6 +41,7 @@ public class BorrowingService {
private final FineRepository fineRepository;
private final NotificationService notificationService;
private final BookService bookService;
+ private final MemberService memberService;
/**
* Constructs a new {@code BorrowingService} with the specified repositories and services.
@@ -48,11 +51,12 @@ public class BorrowingService {
* @param notificationService the service for sending notifications
* @param bookService the service for managing book records
*/
- public BorrowingService(BorrowingRepository borrowingRepository, FineRepository fineRepository, NotificationService notificationService, BookService bookService) {
+ public BorrowingService(BorrowingRepository borrowingRepository, FineRepository fineRepository, NotificationService notificationService, BookService bookService, MemberService memberService) {
this.borrowingRepository = borrowingRepository;
this.fineRepository = fineRepository;
this.notificationService = notificationService;
this.bookService = bookService;
+ this.memberService=memberService;
}
/**
@@ -89,13 +93,16 @@ public Optional getBorrowingById(int borrowingId) {
@Transactional
public synchronized Borrowings borrowBook(Borrowings borrowing) {
Optional book = bookService.getBookById(borrowing.getBook().getBookId());
-
- if (book.isPresent()) {
+ Optional member = memberService.getMemberById(borrowing.getMember().getMemberId());
+ if (book.isPresent() && member.isPresent()) {
Book bookEntity = book.get();
+ Members memberEntity = member.get();
if (bookEntity.getCopiesAvailable() > 0) {
updateBookCopies(borrowing.getBook().getBookId(), "REMOVE", 1);
borrowing.setBorrowDate(new Date());
+ borrowing.setBook(bookEntity);
+ borrowing.setMember(memberEntity);
borrowing.setDueDate(calculateDueDate());
Borrowings savedBorrowing = borrowingRepository.save(borrowing);
@@ -107,7 +114,10 @@ public synchronized Borrowings borrowBook(Borrowings borrowing) {
throw new ResourceNotFoundException("Not enough copies available");
}
} else {
- throw new ResourceNotFoundException("Book not found");
+ if (book.isEmpty()) {
+ throw new ResourceNotFoundException("Book not found");
+ }
+ throw new ResourceNotFoundException("Member not found");
}
}
diff --git a/src/main/resources/application-development.properties b/src/main/resources/application-development.properties
index e16234d..76a3f8f 100644
--- a/src/main/resources/application-development.properties
+++ b/src/main/resources/application-development.properties
@@ -1,23 +1,36 @@
## Database Setup First
-## Create a Database and add database name where "Add_Your_Database_Name" is below
-## Make this file as it was earlier before commiting code
-
-# Change this connection string to this format: jdbc:mysql://{ip_address}:{port}/{database_name}
-spring.datasource.url=jdbc:mysql://localhost:3306/Add_Your_Database_Name
+# MySQL Database Connection
+spring.datasource.url=jdbc:mysql://localhost:3306/library
+spring.datasource.username=
+spring.datasource.password=
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-## Add your Database Username and Password
-spring.datasource.username= Add_Your_UserName
-spring.datasource.password= Add_Your_Password
+# Hibernate Dialect for MySQL 8
+spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
-spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+# Prevent early database interaction
+spring.jpa.properties.hibernate.boot.allow_jdbc_metadata_access=false
spring.jpa.hibernate.ddl-auto=update
+spring.sql.init.mode=never
+
+# Format SQL
spring.jpa.properties.hibernate.format_sql=true
+# Logging for Spring Security
+logging.level.org.springframework.security=TRACE
+# Error Handling
server.error.include-binding-errors=always
server.error.include-message=always
server.error.include-stacktrace=never
server.error.include-exception=true
-logging.level.org.springframework.security = TRACE
\ No newline at end of file
+spring.mail.host=smtp.gmail.com
+spring.mail.port=587
+spring.mail.username=
+spring.mail.password=
+spring.mail.properties.mail.smtp.auth=true
+spring.mail.properties.mail.smtp.starttls.enable=true
+spring.mail.properties.domain_name=gmail.com
+
diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties
index 6b8edc4..4d50b9f 100644
--- a/src/main/resources/application-production.properties
+++ b/src/main/resources/application-production.properties
@@ -14,4 +14,4 @@ spring.mail.username=${MAIL_SERVICE_USERNAME}
spring.mail.password=${MAIL_SERVICE_PASSWORD}
spring.mail.properties.mail.smtp.auth=${MAIL_SERVICE_SMTP}
spring.mail.properties.mail.starttls.enable=${MAIL_SERVICE_STARTTLS}
-spring.mail.properties.domain_name=${MAIL_SERVICE_DOMAIN_NAME}
\ No newline at end of file
+spring.mail.properties.domain_name=${MAIL_SERVICE_DOMAIN_NAME}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index eeefb5c..53718a7 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,2 +1,2 @@
spring.application.name=libraryman-api
-spring.profiles.active=${ENV:dev}
\ No newline at end of file
+spring.profiles.active=${ENV:development}
\ No newline at end of file