Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5e64056
Add Dockerfile and spring-boot-starter-actuator dependency with actua…
NourAlPha May 9, 2025
cbafcb7
Add JitPack repository and mq-utils-lib dependency
NourAlPha May 10, 2025
54892fd
Refactor authentication to add user details in response headers
NourAlPha May 11, 2025
0308c35
Update component scanning and dependency version for podzilla-utils-lib
NourAlPha May 11, 2025
3e2e72f
Add address management and user details retrieval functionality
NourAlPha May 14, 2025
918e171
Enhance user registration and login by adding mobile number and addre…
NourAlPha May 14, 2025
9e3546f
Remove unused validation annotations from Address and User classes
NourAlPha May 14, 2025
572ef4c
Add validation error handling in GlobalExceptionHandler and include v…
NourAlPha May 14, 2025
f00e543
Remove validation annotations from UpdateRequest and adjust UserContr…
NourAlPha May 14, 2025
5c3ab6d
Merge branch 'dev' into fix-bug-in-update
NourAlPha May 14, 2025
8791fb7
Add Dockerfile and spring-boot-starter-actuator dependency with actua…
NourAlPha May 9, 2025
2866610
Add JitPack repository and mq-utils-lib dependency
NourAlPha May 10, 2025
5e708c3
Update component scanning and dependency version for podzilla-utils-lib
NourAlPha May 11, 2025
33fa149
Add address management and user details retrieval functionality
NourAlPha May 14, 2025
566e106
Enhance user registration and login by adding mobile number and addre…
NourAlPha May 14, 2025
05b2e6b
Remove unused validation annotations from Address and User classes
NourAlPha May 14, 2025
7fe5c1e
Add validation error handling in GlobalExceptionHandler and include v…
NourAlPha May 14, 2025
d6c1a55
Remove validation annotations from UpdateRequest and adjust UserContr…
NourAlPha May 14, 2025
6d47d4d
Remove user unit tests
NourAlPha May 14, 2025
2696d51
Merge branch 'fix-bug-in-update' of https://github.com/Podzilla/authe…
NourAlPha May 14, 2025
14fc45f
Fix formatting issue by adding a newline at the end of Authentication…
NourAlPha May 14, 2025
730a354
Add DatabaseSeeder to initialize default roles in the database
NourAlPha May 14, 2025
a764e4d
Add @Component annotation to DatabaseSeeder for Spring context manage…
NourAlPha May 14, 2025
fbc8ddc
Add address handling in user signup process
NourAlPha May 14, 2025
ef89fa9
Add delivery address handling to signup request in AuthenticationServ…
NourAlPha May 14, 2025
90c746c
Enhance UserDetailsRequest with Lombok annotations for improved code …
NourAlPha May 14, 2025
50c8cf5
Add AddCourierRequest DTO, implement courier registration in AdminSer…
NourAlPha May 14, 2025
e24ebd0
Remove unused CustomerRegisteredEvent import from AdminService
NourAlPha May 14, 2025
d272a67
Fix account registration to return saved user and mock event publishi…
NourAlPha May 15, 2025
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
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>com.github.Podzilla</groupId>
<artifactId>podzilla-utils-lib</artifactId>
<version>v1.1.5</version>
<version>v1.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -107,6 +112,10 @@
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/com/podzilla/auth/controller/AdminController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.podzilla.auth.controller;

import com.podzilla.auth.dto.AddCourierRequest;
import com.podzilla.auth.model.User;
import com.podzilla.auth.service.AdminService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -8,12 +9,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -71,4 +75,18 @@ public void deleteUser(
LOGGER.debug("Admin requested to delete user with userId={}", userId);
adminService.deleteUser(userId);
}

@PostMapping("/courier")
@Operation(summary = "Add a new courier",
description = "Allows an admin to add a new courier to the system.")
@ApiResponse(responseCode = "200",
description = "Courier added successfully")
public void addCourier(
@Parameter(description = "Courier details")
@RequestBody final AddCourierRequest addCourierRequest) {

LOGGER.debug("Admin requested to add a new courier with details={}",
addCourierRequest);
adminService.addCourier(addCourierRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -43,7 +44,7 @@ public AuthenticationController(
description = "User logged in successfully"
)
public ResponseEntity<?> login(
@RequestBody final LoginRequest loginRequest,
@Valid @RequestBody final LoginRequest loginRequest,
final HttpServletResponse response) {
String email = authenticationService.login(loginRequest, response);
LOGGER.info("User {} logged in", email);
Expand All @@ -62,7 +63,7 @@ public ResponseEntity<?> login(
description = "User registered successfully"
)
public ResponseEntity<?> registerUser(
@RequestBody final SignupRequest signupRequest) {
@Valid @RequestBody final SignupRequest signupRequest) {
authenticationService.registerAccount(signupRequest);
LOGGER.info("User {} registered", signupRequest.getEmail());
return new ResponseEntity<>("Account registered.",
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/podzilla/auth/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.podzilla.auth.controller;

import com.podzilla.auth.dto.UpdateRequest;
import com.podzilla.auth.dto.UserDetailsRequest;
import com.podzilla.auth.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.UUID;

@RestController
@RequestMapping("/user")
public class UserController {
Expand All @@ -27,14 +26,24 @@ public UserController(final UserService userService) {
this.userService = userService;
}

@PutMapping("/update/{userId}")
@PutMapping("/update")
@Operation(summary = "Update user name",
description = "Allows user to update their name.")
@ApiResponse(responseCode = "200",
description = "User profile updated successfully")
public void updateProfile(@PathVariable final UUID userId,
@Valid @RequestBody final String name) {
LOGGER.debug("Received updateProfile request for userId={}", userId);
userService.updateUserProfile(userId, name);
public void updateProfile(@RequestBody final UpdateRequest
updateRequest) {
LOGGER.debug("Received updateProfile request");
userService.updateUserProfile(updateRequest);
}

@GetMapping("/details")
@Operation(summary = "Get user details",
description = "Fetches the details of the current user.")
@ApiResponse(responseCode = "200",
description = "User details fetched successfully")
public UserDetailsRequest getUserDetails() {
LOGGER.debug("Received getUserDetails request");
return userService.getUserDetails();
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/podzilla/auth/dto/AddCourierRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.podzilla.auth.dto;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

@Data
public class AddCourierRequest {
@NotBlank(message = "Name is required")
private String name;

@Email
@NotBlank(message = "Email is required")
private String email;

@NotBlank(message = "Password is required")
private String password;

@NotBlank(message = "Mobile number is required")
private String mobileNumber;
}
3 changes: 3 additions & 0 deletions src/main/java/com/podzilla/auth/dto/CustomUserDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Set;
import java.util.UUID;

@JsonIgnoreProperties(ignoreUnknown = true)
@Builder
Expand All @@ -21,6 +22,8 @@ public class CustomUserDetails implements UserDetails {

private String username;

private UUID id;

@JsonIgnore
private String password;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/podzilla/auth/dto/LoginRequest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.podzilla.auth.dto;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

@Data
public class LoginRequest {

@Email
@NotBlank(message = "Email is required")
private String email;

@NotBlank(message = "Password is required")
private String password;
}
16 changes: 16 additions & 0 deletions src/main/java/com/podzilla/auth/dto/SignupRequest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
package com.podzilla.auth.dto;

import com.podzilla.mq.events.DeliveryAddress;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

@Data
public class SignupRequest {
@NotBlank(message = "Name is required")
private String name;

@Email
@NotBlank(message = "Email is required")
private String email;

@NotBlank(message = "Password is required")
private String password;

@NotBlank(message = "Mobile number is required")
private String mobileNumber;

@Valid
private DeliveryAddress address;
}
11 changes: 11 additions & 0 deletions src/main/java/com/podzilla/auth/dto/UpdateRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.podzilla.auth.dto;

import com.podzilla.mq.events.DeliveryAddress;
import lombok.Data;

@Data
public class UpdateRequest {
private String name;
private DeliveryAddress address;
private String mobileNumber;
}
18 changes: 18 additions & 0 deletions src/main/java/com/podzilla/auth/dto/UserDetailsRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.podzilla.auth.dto;

import com.podzilla.mq.events.DeliveryAddress;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class UserDetailsRequest {
private String email;
private String name;
private String mobileNumber;
private DeliveryAddress address;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
package com.podzilla.auth.exception;

import io.micrometer.common.lang.NonNull;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

@Override // Good practice to use @Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
final MethodArgumentNotValidException ex,
@NonNull final HttpHeaders headers,
@NonNull final HttpStatusCode status,
@NonNull final WebRequest request) {

StringBuilder errorMessage = new StringBuilder("Validation failed: ");
for (FieldError error : ex.getBindingResult().getFieldErrors()) {
errorMessage.append(error.getField()).append(": ")
.append(error.getDefaultMessage()).append("; ");
}

ErrorResponse errorResponse = new ErrorResponse(
errorMessage.toString(), (HttpStatus) status);

return new ResponseEntity<>(errorResponse, status);

}

@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<ErrorResponse> handleAccessDeniedException(
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/podzilla/auth/model/Address.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.podzilla.auth.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.UUID;

@Entity
@Table(name = "addresses")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class Address {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

@OneToOne(optional = false)
@JoinColumn(name = "user_id", nullable = false)
@JsonIgnore
private User user;

private String street;

private String city;

private String state;

private String country;

private String postalCode;
}
3 changes: 2 additions & 1 deletion src/main/java/com/podzilla/auth/model/ERole.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum ERole {
ROLE_USER,
ROLE_ADMIN
ROLE_ADMIN,
ROLE_COURIER
}
Loading