Skip to content

Commit 191ce03

Browse files
committed
Merge branch 'dev' into builder-pattern-user
2 parents 88c30a6 + 24b838f commit 191ce03

26 files changed

Lines changed: 578 additions & 69 deletions

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use the specified base image
2+
FROM openjdk:25-ea-4-jdk-oraclelinux9
3+
4+
WORKDIR /app
5+
6+
COPY target/auth-0.0.1-SNAPSHOT.jar /app/auth-0.0.1-SNAPSHOT.jar
7+
8+
# Define the command to run your application
9+
CMD [ "java", "-jar", "/app/auth-0.0.1-SNAPSHOT.jar" ]

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,27 @@
2929
<properties>
3030
<java.version>23</java.version>
3131
</properties>
32+
<repositories>
33+
<repository>
34+
<id>jitpack.io</id>
35+
<url>https://jitpack.io</url>
36+
</repository>
37+
</repositories>
3238
<dependencies>
3339
<dependency>
3440
<groupId>org.springframework.boot</groupId>
3541
<artifactId>spring-boot-starter-data-jpa</artifactId>
3642
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-actuator</artifactId>
46+
<version>3.4.5</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.github.Podzilla</groupId>
50+
<artifactId>podzilla-utils-lib</artifactId>
51+
<version>v1.1.6</version>
52+
</dependency>
3753
<dependency>
3854
<groupId>org.springframework.boot</groupId>
3955
<artifactId>spring-boot-starter-data-redis</artifactId>
@@ -96,6 +112,10 @@
96112
<artifactId>jakarta.validation-api</artifactId>
97113
<version>3.0.2</version>
98114
</dependency>
115+
<dependency>
116+
<groupId>org.springframework.boot</groupId>
117+
<artifactId>spring-boot-starter-validation</artifactId>
118+
</dependency>
99119
<dependency>
100120
<groupId>org.mockito</groupId>
101121
<artifactId>mockito-core</artifactId>

src/main/java/com/podzilla/auth/AuthApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.cache.annotation.EnableCaching;
6+
import org.springframework.context.annotation.ComponentScan;
67

78
@SpringBootApplication
89
@EnableCaching
10+
@ComponentScan(basePackages = { "com.podzilla" })
911
public class AuthApplication {
1012

1113
public static void main(final String[] args) {

src/main/java/com/podzilla/auth/controller/AdminController.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.podzilla.auth.controller;
22

3+
import com.podzilla.auth.dto.AddCourierRequest;
34
import com.podzilla.auth.model.User;
45
import com.podzilla.auth.service.AdminService;
56
import io.swagger.v3.oas.annotations.Operation;
@@ -8,12 +9,15 @@
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
1011
import org.springframework.web.bind.annotation.RestController;
11-
import org.springframework.web.bind.annotation.RequestMapping;
12-
import org.springframework.web.bind.annotation.GetMapping;
1312
import org.springframework.web.bind.annotation.DeleteMapping;
13+
import org.springframework.web.bind.annotation.GetMapping;
1414
import org.springframework.web.bind.annotation.PatchMapping;
1515
import org.springframework.web.bind.annotation.PathVariable;
16+
import org.springframework.web.bind.annotation.RequestBody;
17+
import org.springframework.web.bind.annotation.RequestMapping;
1618
import org.springframework.web.bind.annotation.RequestParam;
19+
import org.springframework.web.bind.annotation.PostMapping;
20+
1721
import java.util.List;
1822
import java.util.UUID;
1923

@@ -71,4 +75,18 @@ public void deleteUser(
7175
LOGGER.debug("Admin requested to delete user with userId={}", userId);
7276
adminService.deleteUser(userId);
7377
}
78+
79+
@PostMapping("/courier")
80+
@Operation(summary = "Add a new courier",
81+
description = "Allows an admin to add a new courier to the system.")
82+
@ApiResponse(responseCode = "200",
83+
description = "Courier added successfully")
84+
public void addCourier(
85+
@Parameter(description = "Courier details")
86+
@RequestBody final AddCourierRequest addCourierRequest) {
87+
88+
LOGGER.debug("Admin requested to add a new courier with details={}",
89+
addCourierRequest);
90+
adminService.addCourier(addCourierRequest);
91+
}
7492
}

src/main/java/com/podzilla/auth/controller/AuthenticationController.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import io.swagger.v3.oas.annotations.responses.ApiResponse;
88
import jakarta.servlet.http.HttpServletRequest;
99
import jakarta.servlet.http.HttpServletResponse;
10+
import jakarta.validation.Valid;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
1213
import org.springframework.beans.factory.annotation.Autowired;
1314
import org.springframework.http.HttpStatus;
1415
import org.springframework.http.ResponseEntity;
15-
import org.springframework.security.core.userdetails.UserDetails;
1616
import org.springframework.web.bind.annotation.PostMapping;
1717
import org.springframework.web.bind.annotation.RequestBody;
1818
import org.springframework.web.bind.annotation.RequestMapping;
@@ -44,7 +44,7 @@ public AuthenticationController(
4444
description = "User logged in successfully"
4545
)
4646
public ResponseEntity<?> login(
47-
@RequestBody final LoginRequest loginRequest,
47+
@Valid @RequestBody final LoginRequest loginRequest,
4848
final HttpServletResponse response) {
4949
String email = authenticationService.login(loginRequest, response);
5050
LOGGER.info("User {} logged in", email);
@@ -63,7 +63,7 @@ public ResponseEntity<?> login(
6363
description = "User registered successfully"
6464
)
6565
public ResponseEntity<?> registerUser(
66-
@RequestBody final SignupRequest signupRequest) {
66+
@Valid @RequestBody final SignupRequest signupRequest) {
6767
authenticationService.registerAccount(signupRequest);
6868
LOGGER.info("User {} registered", signupRequest.getEmail());
6969
return new ResponseEntity<>("Account registered.",
@@ -113,9 +113,8 @@ public ResponseEntity<?> refreshToken(
113113
responseCode = "200",
114114
description = "User details fetched successfully"
115115
)
116-
public UserDetails getCurrentUser() {
117-
UserDetails userDetails = authenticationService.getCurrentUserDetails();
118-
LOGGER.info("Fetched details for user {}", userDetails.getUsername());
119-
return userDetails;
116+
public void addUserDetailsInHeader(final HttpServletResponse response) {
117+
authenticationService.addUserDetailsInHeader(response);
118+
LOGGER.info("Fetching current user details and adding to header");
120119
}
121120
}
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package com.podzilla.auth.controller;
22

3+
import com.podzilla.auth.dto.UpdateRequest;
4+
import com.podzilla.auth.dto.UserDetailsRequest;
35
import com.podzilla.auth.service.UserService;
46
import io.swagger.v3.oas.annotations.Operation;
57
import io.swagger.v3.oas.annotations.responses.ApiResponse;
6-
import jakarta.validation.Valid;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
9-
import org.springframework.web.bind.annotation.RestController;
1010
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
1112
import org.springframework.web.bind.annotation.PutMapping;
12-
import org.springframework.web.bind.annotation.PathVariable;
13+
import org.springframework.web.bind.annotation.GetMapping;
1314
import org.springframework.web.bind.annotation.RequestBody;
1415

15-
import java.util.UUID;
16-
1716
@RestController
1817
@RequestMapping("/user")
1918
public class UserController {
@@ -27,14 +26,24 @@ public UserController(final UserService userService) {
2726
this.userService = userService;
2827
}
2928

30-
@PutMapping("/update/{userId}")
29+
@PutMapping("/update")
3130
@Operation(summary = "Update user name",
3231
description = "Allows user to update their name.")
3332
@ApiResponse(responseCode = "200",
3433
description = "User profile updated successfully")
35-
public void updateProfile(@PathVariable final UUID userId,
36-
@Valid @RequestBody final String name) {
37-
LOGGER.debug("Received updateProfile request for userId={}", userId);
38-
userService.updateUserProfile(userId, name);
34+
public void updateProfile(@RequestBody final UpdateRequest
35+
updateRequest) {
36+
LOGGER.debug("Received updateProfile request");
37+
userService.updateUserProfile(updateRequest);
38+
}
39+
40+
@GetMapping("/details")
41+
@Operation(summary = "Get user details",
42+
description = "Fetches the details of the current user.")
43+
@ApiResponse(responseCode = "200",
44+
description = "User details fetched successfully")
45+
public UserDetailsRequest getUserDetails() {
46+
LOGGER.debug("Received getUserDetails request");
47+
return userService.getUserDetails();
3948
}
4049
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.podzilla.auth.dto;
2+
3+
import jakarta.validation.constraints.Email;
4+
import jakarta.validation.constraints.NotBlank;
5+
import lombok.Data;
6+
7+
@Data
8+
public class AddCourierRequest {
9+
@NotBlank(message = "Name is required")
10+
private String name;
11+
12+
@Email
13+
@NotBlank(message = "Email is required")
14+
private String email;
15+
16+
@NotBlank(message = "Password is required")
17+
private String password;
18+
19+
@NotBlank(message = "Mobile number is required")
20+
private String mobileNumber;
21+
}

src/main/java/com/podzilla/auth/dto/CustomUserDetails.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.security.core.userdetails.UserDetails;
1212

1313
import java.util.Set;
14+
import java.util.UUID;
1415

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

2223
private String username;
2324

25+
private UUID id;
26+
2427
@JsonIgnore
2528
private String password;
2629

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package com.podzilla.auth.dto;
22

3+
import jakarta.validation.constraints.Email;
4+
import jakarta.validation.constraints.NotBlank;
35
import lombok.Data;
46

57
@Data
68
public class LoginRequest {
9+
10+
@Email
11+
@NotBlank(message = "Email is required")
712
private String email;
13+
14+
@NotBlank(message = "Password is required")
815
private String password;
916
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
package com.podzilla.auth.dto;
22

3+
import com.podzilla.mq.events.DeliveryAddress;
4+
import jakarta.validation.Valid;
5+
import jakarta.validation.constraints.Email;
6+
import jakarta.validation.constraints.NotBlank;
37
import lombok.Data;
48

59
@Data
610
public class SignupRequest {
11+
@NotBlank(message = "Name is required")
712
private String name;
13+
14+
@Email
15+
@NotBlank(message = "Email is required")
816
private String email;
17+
18+
@NotBlank(message = "Password is required")
919
private String password;
20+
21+
@NotBlank(message = "Mobile number is required")
22+
private String mobileNumber;
23+
24+
@Valid
25+
private DeliveryAddress address;
1026
}

0 commit comments

Comments
 (0)