Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 12f9f74

Browse files
authored
Merge pull request #109 from Zenfulcode/patch-bug-fixes
Patch bug fixes
2 parents 8fe5ab3 + 1baf7bb commit 12f9f74

28 files changed

Lines changed: 219 additions & 57 deletions

deploy/.env.example

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
DATASOURCE_URL=jdbc:mysql://mysql:3306/commercifydb?createDatabaseIfNotExist=true
33
DATASOURCE_USERNAME=commercifyapp
44
DATASOURCE_PASSWORD=password123!
5-
STRIPE_SECRET_TEST_KEY=
6-
STRIPE_WEBHOOK_SECRET=
7-
STRIPE_WEBHOOK_ENDPOINT=https://<insert_host>/api/v2/payments/webhooks/stripe/callback
85
JWT_SECRET_KEY=
96
ADMIN_EMAIL=admin@commercify.app
107
ADMIN_PASSWORD=admin
@@ -18,4 +15,5 @@ MOBILEPAY_WEBHOOK_CALLBACK=https://<insert_host>/api/v2/payments/webhooks/mobile
1815
MAIL_USERNAME=
1916
MAIL_PASSWORD=
2017
MAIL_HOST=smtp.ethereal.email
21-
MAIL_PORT=587
18+
MAIL_PORT=587
19+
FRONTEND_HOST=http://localhost:3000

deploy/docker-compose.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- MYSQL_PASSWORD=password123!
99
- MYSQL_ROOT_PASSWORD=rootpassword
1010
ports:
11-
- "3307:3306"
11+
- "3306:3306"
1212
healthcheck:
1313
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
1414
timeout: 5s
@@ -26,11 +26,9 @@ services:
2626
- "6091:6091"
2727
environment:
2828
- SPRING_PROFILES_ACTIVE=docker
29-
- SPRING_DATASOURCE_URL=${DATASOURCE_URL}
30-
- SPRING_DATASOURCE_USERNAME=${DATASOURCE_USERNAME}
31-
- SPRING_DATASOURCE_PASSWORD=${DATASOURCE_PASSWORD}
32-
- STRIPE_SECRET_TEST_KEY=${STRIPE_SECRET_TEST_KEY}
33-
- STRIPE_WEBHOOK_SECRET=${STRIPE_WEBHOOK_SECRET}
29+
- SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/commercifydb?createDatabaseIfNotExist=true
30+
- SPRING_DATASOURCE_USERNAME=root
31+
- SPRING_DATASOURCE_PASSWORD=rootpassword
3432
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
3533
- ADMIN_EMAIL=${ADMIN_EMAIL}
3634
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
@@ -45,6 +43,7 @@ services:
4543
- MAIL_PORT=${MAIL_PORT}
4644
- MAIL_USERNAME=${MAIL_USERNAME}
4745
- MAIL_PASSWORD=${MAIL_PASSWORD}
46+
- FRONTEND_URL=${FRONTEND_URL}
4847
depends_on:
4948
mysql:
5049
condition: service_healthy

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@
194194
<jsonLibrary>jackson2</jsonLibrary>
195195
<outputKind>module</outputKind>
196196
<classPatterns>
197-
<pattern>com.zenfulcode.commercify.api.**.dto.**</pattern>
197+
<!-- <pattern>cfiom.zenfulcode.commercify.api.*.dto.**</pattern>-->
198+
<pattern>com.zenfulcode.commercify.**.dto.**</pattern>
198199
</classPatterns>
199200
</configuration>
200201
</plugin>

src/main/java/com/zenfulcode/commercify/api/auth/AuthController.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import com.zenfulcode.commercify.auth.domain.exception.InvalidAuthenticationException;
1111
import com.zenfulcode.commercify.auth.domain.model.AuthenticatedUser;
1212
import com.zenfulcode.commercify.shared.interfaces.ApiResponse;
13+
import com.zenfulcode.commercify.user.application.dto.response.UserProfileResponse;
1314
import com.zenfulcode.commercify.user.application.service.UserApplicationService;
15+
import com.zenfulcode.commercify.user.domain.model.User;
1416
import lombok.RequiredArgsConstructor;
1517
import lombok.extern.slf4j.Slf4j;
1618
import org.springframework.http.HttpStatus;
@@ -24,6 +26,7 @@
2426
public class AuthController {
2527
private final AuthenticationApplicationService authService;
2628
private final UserApplicationService userService;
29+
private final UserApplicationService userApplicationService;
2730

2831
@PostMapping("/nextauth")
2932
public ResponseEntity<ApiResponse<NextAuthResponse>> nextAuthSignIn(@RequestBody LoginRequest request) {
@@ -52,10 +55,26 @@ public ResponseEntity<ApiResponse<NextAuthResponse>> validateSession(@RequestHea
5255
}
5356
}
5457

58+
@GetMapping("/me")
59+
public ResponseEntity<ApiResponse<UserProfileResponse>> getCurrentUser(@RequestHeader("Authorization") String authHeader) {
60+
// Extract token using a domain service method
61+
String token = authService.extractTokenFromHeader(authHeader).orElseThrow(() -> new InvalidAuthenticationException("Invalid authorization header"));
62+
63+
// Validate token through the application service
64+
AuthenticatedUser authenticatedUser = authService.validateAccessToken(token);
65+
66+
// Fetch full user entity from the database
67+
User user = userApplicationService.getUser(authenticatedUser.getUserId());
68+
69+
// Map to response DTO
70+
UserProfileResponse response = UserProfileResponse.fromUser(user);
71+
72+
return ResponseEntity.ok(ApiResponse.success(response));
73+
}
74+
5575
@PostMapping("/signin")
5676
public ResponseEntity<ApiResponse<AuthResponse>> login(@RequestBody LoginRequest request) {
5777
AuthenticationResult result = authService.authenticate(request.toCommand());
58-
5978
AuthResponse response = AuthResponse.from(result);
6079
return ResponseEntity.ok(ApiResponse.success(response));
6180
}
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
package com.zenfulcode.commercify.api.auth.dto.response;
22

33
import com.zenfulcode.commercify.auth.application.service.AuthenticationResult;
4-
import com.zenfulcode.commercify.auth.domain.model.UserRole;
5-
6-
import java.util.Set;
7-
import java.util.stream.Collectors;
4+
import com.zenfulcode.commercify.user.application.dto.response.UserProfileResponse;
85

96
public record AuthResponse(
107
String accessToken,
118
String refreshToken,
12-
String tokenType,
13-
String userId,
14-
String username,
15-
String email,
16-
Set<String> roles
9+
UserProfileResponse user
1710
) {
1811
public static AuthResponse from(AuthenticationResult result) {
19-
Set<String> roles = result.user().getRoles().stream()
20-
.map(UserRole::name)
21-
.collect(Collectors.toSet());
22-
2312
return new AuthResponse(
2413
result.accessToken(),
2514
result.refreshToken(),
26-
"Bearer",
27-
result.user().getUserId().toString(),
28-
result.user().getUsername(),
29-
result.user().getEmail(),
30-
roles
15+
UserProfileResponse.fromUser(result.userInfo())
3116
);
3217
}
3318
}

src/main/java/com/zenfulcode/commercify/api/auth/dto/response/NextAuthResponse.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package com.zenfulcode.commercify.api.auth.dto.response;
22

3+
import com.zenfulcode.commercify.user.application.dto.response.UserProfileResponse;
34
import com.zenfulcode.commercify.auth.application.service.AuthenticationResult;
45
import com.zenfulcode.commercify.auth.domain.model.AuthenticatedUser;
56
import com.zenfulcode.commercify.auth.domain.model.UserRole;
67

78
import java.util.Set;
89

910
public record NextAuthResponse(
10-
String id,
11-
String name,
12-
String email,
11+
UserProfileResponse user,
1312
String accessToken,
1413
String refreshToken,
1514
Set<UserRole> roles
1615
) {
1716
public static NextAuthResponse from(AuthenticationResult result) {
1817
AuthenticatedUser user = result.user();
1918
return new NextAuthResponse(
20-
user.getUserId().toString(),
21-
user.getUsername(),
22-
user.getEmail(),
19+
UserProfileResponse.fromUser(result.userInfo()),
2320
result.accessToken(),
2421
result.refreshToken(),
2522
user.getRoles()
@@ -28,9 +25,7 @@ public static NextAuthResponse from(AuthenticationResult result) {
2825

2926
public static NextAuthResponse fromUser(AuthenticatedUser user) {
3027
return new NextAuthResponse(
31-
user.getUserId().toString(),
32-
user.getUsername(),
33-
user.getEmail(),
28+
UserProfileResponse.fromAuthenticatedUser(user),
3429
null,
3530
null,
3631
user.getRoles()

src/main/java/com/zenfulcode/commercify/api/order/OrderController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public ResponseEntity<ApiResponse<CreateOrderResponse>> createOrder(
5858
return ResponseEntity.ok(ApiResponse.success(response));
5959
}
6060

61+
// TODO: SUPER NOT SECURE AND NOT GOOD
6162
@GetMapping("/{orderId}")
6263
public ResponseEntity<ApiResponse<OrderDetailsResponse>> getOrder(
6364
@PathVariable String orderId,

src/main/java/com/zenfulcode/commercify/api/order/dto/response/OrderDetailsResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public record OrderDetailsResponse(
1414
CustomerDetailsResponse customerDetails,
1515
AddressResponse shippingAddress,
1616
AddressResponse billingAddress,
17-
Instant createdAt
17+
Instant createdAt,
18+
Instant updatedAt
1819
) {
1920
}

src/main/java/com/zenfulcode/commercify/api/order/mapper/OrderDtoMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public OrderDetailsResponse toResponse(OrderDetailsDTO dto) {
8686
toAddressResponse(dto.shippingAddress()),
8787
dto.billingAddress() != null ?
8888
toAddressResponse(dto.billingAddress()) : null,
89-
dto.createdAt()
89+
dto.createdAt(),
90+
dto.updatedAt()
9091
);
9192
}
9293

src/main/java/com/zenfulcode/commercify/api/product/dto/request/UpdateProductRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
public record UpdateProductRequest(
66
String name,
77
String description,
8+
String imageUrl,
89
Integer stock,
910
Money price,
1011
Boolean active

0 commit comments

Comments
 (0)