Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dk.via.sep3;

/**
* Spring Boot application entry point for Aarhus Logic Server.
*
* @author Group 7
*/
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import java.util.List;
import java.util.Map;

/**
* Implementation of book service that communicates with the book gRPC backend.
*
* @author Group 7
*/
@Service
public class BookServiceImpl implements BookService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import java.sql.Date;
import java.util.List;

/**
* Implementation of loan-related business logic (create, extend, fetch active loans).
*
* @author Group 7
*/
@Service public class LoanServiceImpl implements LoanService
{
private static final Logger logger = LoggerFactory.getLogger(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import dk.via.sep3.security.PasswordService;
import org.springframework.stereotype.Service;

/**
* Implementation of login/authentication logic.
*
* @author Group 7
*/
@Service public class LoginServiceImpl implements LoginService
{
private final UserGrpcService userGrpcService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import dk.via.sep3.security.PasswordService;
import org.springframework.stereotype.Service;

/**
* Implementation of user registration logic (validation, password hashing, persistence).
*
* @author Group 7
*/
@Service public class RegisterServiceImpl implements RegisterService
{
private final UserGrpcService userGrpcService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import java.util.List;
import java.time.LocalDate;

/**
* Implementation of reservation business logic (create reservations, select book to reserve).
*
* @author Group 7
*/
@Service
public class ReservationServiceImpl implements ReservationService {
private final LoanGrpcService loanGrpcService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
* Authentication controller for register/login endpoints.
*
* @author Group 7
*/
@RestController @RequestMapping("/auth") public class AuthController
{
private final UserMapper userMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import java.util.ArrayList;
import java.util.List;

/**
* Controller for book endpoints.
*
* @author Group 7
*/
@RestController @RequestMapping("/books") public class BooksController
{
private final BookService books;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import java.util.ArrayList;
import java.util.List;

/**
* Controller for loan-related endpoints.
*
* @author Group 7
*/
@RestController @RequestMapping("/loans") public class LoansController
{
private static final Logger logger = LoggerFactory.getLogger(LoansController.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Controller for reservation endpoints.
*
* @author Group 7
*/
@RestController @RequestMapping("/reservations") public class ReservationController
{
private final ReservationService reservationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import dk.via.sep3.mapper.userMapper.UserMapper;
import dk.via.sep3.application.domain.User;
import dk.via.sep3.application.services.register.RegisterService;
import dk.via.sep3.application.services.login.LoginService;
import dk.via.sep3.security.JwtUtil;
import dk.via.sep3.DTOs.auth.RegisterResponseDTO;
import dk.via.sep3.DTOs.registration.RegistrationDTO;
import dk.via.sep3.DTOs.user.UserDTO;
import dk.via.sep3.DTOs.login.LoginRequestDTO;
import dk.via.sep3.DTOs.login.LoginResponseDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -38,6 +41,9 @@ class AuthControllerTest {
@Mock
private JwtUtil jwtUtil;

@Mock
private LoginService loginService;

@InjectMocks
private AuthController authController;

Expand Down Expand Up @@ -217,5 +223,54 @@ void testRegister_CorrectMapping() {
assertEquals(registerResponseDTO.getPhoneNumber(), response.getBody().getPhoneNumber());
assertEquals(registerResponseDTO.getRole(), response.getBody().getRole());
}

@Test
@DisplayName("Should login successfully and return a token")
void testLogin_Success() {
// Arrange
LoginRequestDTO loginRequest = new LoginRequestDTO();
loginRequest.setUsername("johndoe");
loginRequest.setPassword("SecurePass123");

when(userMapper.mapLoginRequestToDomain(loginRequest)).thenReturn(validDomainUser);
when(loginService.login(validDomainUser)).thenReturn(registeredUser);
when(jwtUtil.generateToken(registeredUser.getUsername(), registeredUser.getRole())).thenReturn("mock-token");

// Act
ResponseEntity<LoginResponseDTO> response = authController.login(loginRequest);

// Assert
assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());
assertEquals("mock-token", response.getBody().getToken());
assertEquals("johndoe", response.getBody().getUsername());

// Verify interactions
verify(userMapper, times(1)).mapLoginRequestToDomain(loginRequest);
verify(loginService, times(1)).login(validDomainUser);
verify(jwtUtil, times(1)).generateToken(registeredUser.getUsername(), registeredUser.getRole());
}

@Test
@DisplayName("Should throw exception when login credentials are invalid")
void testLogin_InvalidCredentials() {
// Arrange
LoginRequestDTO loginRequest = new LoginRequestDTO();
loginRequest.setUsername("johndoe");
loginRequest.setPassword("WrongPassword");

when(userMapper.mapLoginRequestToDomain(loginRequest)).thenReturn(validDomainUser);
when(loginService.login(validDomainUser)).thenThrow(new IllegalArgumentException("Invalid username or password"));

// Act & Assert
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> authController.login(loginRequest));
assertEquals("Invalid username or password", exception.getMessage());

// Verify interactions
verify(userMapper, times(1)).mapLoginRequestToDomain(loginRequest);
verify(loginService, times(1)).login(validDomainUser);
verify(jwtUtil, never()).generateToken(any(), any());
}
}

2 changes: 1 addition & 1 deletion Client/BlazorApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.AddInteractiveServerComponents();

// Read logic server base URL from configuration or default to localhost:8080
var logicServerBase = builder.Configuration["LogicServerBaseUrl"] ?? "http://localhost:8081/";
var logicServerBase = builder.Configuration["LogicServerBaseUrl"] ?? "http://localhost:8080/";

// Unauthenticated client
builder.Services.AddScoped(_ => new HttpClient
Expand Down
30 changes: 15 additions & 15 deletions LibraryManagementSystem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PersistenceServer", "Persis
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "PersistenceServer\Server\Entities\Entities.csproj", "{234A19E6-3641-4350-90FE-4CA46BFFFDD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileRepositories", "PersistenceServer\Server\FileRepositories\FileRepositories.csproj", "{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RepositoryContracts", "PersistenceServer\Server\RepositoryContracts\RepositoryContracts.csproj", "{8229A9EA-9BE8-4F9D-B7C0-A9AF2BA27978}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{CD932AF7-82F2-EB44-7494-511AF8C7F2CE}"
Expand All @@ -25,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTOs", "Shared\DTOs\DTOs.cs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCDatabaseRepositories", "PersistenceServer\Server\EFCDatabaseRepositories\EFCDatabaseRepositories.csproj", "{9F1A647A-B7A8-4E9C-B6A7-01128AF67CDB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Tests", "PersistenceServer\Server\Server.Tests\Server.Tests.csproj", "{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -47,18 +47,6 @@ Global
{234A19E6-3641-4350-90FE-4CA46BFFFDD3}.Release|x64.Build.0 = Release|Any CPU
{234A19E6-3641-4350-90FE-4CA46BFFFDD3}.Release|x86.ActiveCfg = Release|Any CPU
{234A19E6-3641-4350-90FE-4CA46BFFFDD3}.Release|x86.Build.0 = Release|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Debug|x64.ActiveCfg = Debug|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Debug|x64.Build.0 = Debug|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Debug|x86.ActiveCfg = Debug|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Debug|x86.Build.0 = Debug|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Release|Any CPU.Build.0 = Release|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Release|x64.ActiveCfg = Release|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Release|x64.Build.0 = Release|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Release|x86.ActiveCfg = Release|Any CPU
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9}.Release|x86.Build.0 = Release|Any CPU
{8229A9EA-9BE8-4F9D-B7C0-A9AF2BA27978}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8229A9EA-9BE8-4F9D-B7C0-A9AF2BA27978}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8229A9EA-9BE8-4F9D-B7C0-A9AF2BA27978}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -119,18 +107,30 @@ Global
{9F1A647A-B7A8-4E9C-B6A7-01128AF67CDB}.Release|x64.Build.0 = Release|Any CPU
{9F1A647A-B7A8-4E9C-B6A7-01128AF67CDB}.Release|x86.ActiveCfg = Release|Any CPU
{9F1A647A-B7A8-4E9C-B6A7-01128AF67CDB}.Release|x86.Build.0 = Release|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Debug|x64.ActiveCfg = Debug|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Debug|x64.Build.0 = Debug|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Debug|x86.ActiveCfg = Debug|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Debug|x86.Build.0 = Debug|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Release|Any CPU.Build.0 = Release|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Release|x64.ActiveCfg = Release|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Release|x64.Build.0 = Release|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Release|x86.ActiveCfg = Release|Any CPU
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{234A19E6-3641-4350-90FE-4CA46BFFFDD3} = {CD932AF7-82F2-EB44-7494-511AF8C7F2CE}
{3CEA80E6-3478-4801-9F5F-CF5D6B745EE9} = {CD932AF7-82F2-EB44-7494-511AF8C7F2CE}
{8229A9EA-9BE8-4F9D-B7C0-A9AF2BA27978} = {CD932AF7-82F2-EB44-7494-511AF8C7F2CE}
{CD932AF7-82F2-EB44-7494-511AF8C7F2CE} = {98BC804B-E865-18F8-7609-8B880F601F28}
{C884B17C-6118-4747-B44B-AEDB000E8935} = {CD932AF7-82F2-EB44-7494-511AF8C7F2CE}
{4508795B-F96A-48E4-8B6E-2629BF517A7F} = {2CB42F12-E813-91B3-7D11-3220E40BEF4A}
{99187A8B-A0F8-4CD5-8782-078AE8B24A9E} = {4F52FD11-658E-A102-6CD3-7D7C16FFA15B}
{9F1A647A-B7A8-4E9C-B6A7-01128AF67CDB} = {CD932AF7-82F2-EB44-7494-511AF8C7F2CE}
{2D693FCF-9C3C-427B-8B76-F8B68EED8ADA} = {CD932AF7-82F2-EB44-7494-511AF8C7F2CE}
EndGlobalSection
EndGlobal
30 changes: 0 additions & 30 deletions PersistenceServer/Server/FileRepositories/BookFileRepository.cs

This file was deleted.

14 changes: 0 additions & 14 deletions PersistenceServer/Server/FileRepositories/FileRepositories.csproj

This file was deleted.

Loading