Skip to content

Commit 5b79c70

Browse files
committed
Update Profile
1 parent b9c4894 commit 5b79c70

File tree

15 files changed

+224
-52
lines changed

15 files changed

+224
-52
lines changed

coding-service/src/main/java/com/codecampus/coding/service/grpc/PlaygroundServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class PlaygroundServiceImpl
4848

4949
private static Path createWorkDir() throws IOException {
5050
Files.createDirectories(RUNNER_ROOT);
51-
return Files.createTempDirectory(RUNNER_ROOT,
51+
return Files.createTempDirectory(
5252
"pg_"); // <— nằm trong volume host
5353
}
5454

@@ -104,7 +104,7 @@ public void run(
104104
}
105105

106106
// 2) Compile (python bỏ qua)
107-
final String image = SANDBOX_IMAGE;
107+
final String image = "capstoneprojectpythondocker";
108108
String binName = "bin_" + UUID.randomUUID();
109109

110110
if (!"python".equals(lang)) {

identity-service/src/main/java/com/codecampus/identity/configuration/config/init/ApplicationInitializationService.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ void createAdminUser(String username, String password, String email) {
5050
.roles(roles)
5151
.build());
5252

53-
profileClient.createUserProfile(UserProfileCreationRequest.builder()
54-
.userId(user.getId())
55-
.firstName("Admin")
56-
.lastName("Sys")
57-
.dob(ConvertUtils.parseDdMmYyyyToInstant("28/03/2004"))
58-
.bio("Too lazy to write anything :v")
59-
.gender(true)
60-
.displayName("ADMIN SYS")
61-
.education(11)
62-
.links(new String[] {"https://github.com/yunomix2834",
63-
"https://github.com/CapstoneProjectCMC/backend"})
64-
.city("Vietnam")
65-
.build()
53+
profileClient.internalCreateUserProfile(
54+
UserProfileCreationRequest.builder()
55+
.userId(user.getId())
56+
.firstName("Admin")
57+
.lastName("Sys")
58+
.dob(ConvertUtils.parseDdMmYyyyToInstant("28/03/2004"))
59+
.bio("Too lazy to write anything :v")
60+
.gender(true)
61+
.displayName("ADMIN SYS")
62+
.education(11)
63+
.links(new String[] {"https://github.com/yunomix2834",
64+
"https://github.com/CapstoneProjectCMC/backend"})
65+
.city("Vietnam")
66+
.build()
6667
);
6768
}
6869

@@ -81,19 +82,20 @@ void createUser(String username, String password, String email) {
8182
.roles(roles)
8283
.build());
8384

84-
profileClient.createUserProfile(UserProfileCreationRequest.builder()
85-
.userId(user.getId())
86-
.firstName("Code")
87-
.lastName("Campus")
88-
.dob(ConvertUtils.parseDdMmYyyyToInstant("28/03/2004"))
89-
.bio("Too lazy to write anything :v")
90-
.gender(true)
91-
.displayName("ADMIN SYS")
92-
.education(11)
93-
.links(new String[] {"https://github.com/yunomix2834",
94-
"https://github.com/CapstoneProjectCMC/backend"})
95-
.city("Vietnam")
96-
.build()
85+
profileClient.internalCreateUserProfile(
86+
UserProfileCreationRequest.builder()
87+
.userId(user.getId())
88+
.firstName("Code")
89+
.lastName("Campus")
90+
.dob(ConvertUtils.parseDdMmYyyyToInstant("28/03/2004"))
91+
.bio("Too lazy to write anything :v")
92+
.gender(true)
93+
.displayName("ADMIN SYS")
94+
.education(11)
95+
.links(new String[] {"https://github.com/yunomix2834",
96+
"https://github.com/CapstoneProjectCMC/backend"})
97+
.city("Vietnam")
98+
.build()
9799
);
98100
}
99101

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codecampus.identity.dto.request.profile;
2+
3+
import lombok.AccessLevel;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
import lombok.experimental.FieldDefaults;
7+
8+
@Data
9+
@NoArgsConstructor
10+
@FieldDefaults(level = AccessLevel.PRIVATE)
11+
public class UserProfileUpdateRequest {
12+
String firstName;
13+
String lastName;
14+
String dob;
15+
String bio;
16+
Boolean gender;
17+
String displayName;
18+
Integer education;
19+
String[] links;
20+
String city;
21+
}

identity-service/src/main/java/com/codecampus/identity/helper/ProfileSyncHelper.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codecampus.identity.dto.request.authentication.UserCreationRequest;
44
import com.codecampus.identity.dto.request.profile.UserProfileCreationRequest;
5+
import com.codecampus.identity.dto.request.profile.UserProfileUpdateRequest;
56
import com.codecampus.identity.entity.account.User;
67
import com.codecampus.identity.mapper.client.UserProfileMapper;
78
import com.codecampus.identity.repository.httpclient.profile.ProfileClient;
@@ -23,13 +24,44 @@ public class ProfileSyncHelper {
2324
*/
2425
public void createProfile(
2526
User user,
26-
UserCreationRequest src) {
27-
UserProfileCreationRequest req =
28-
userProfileMapper.toUserProfileCreationRequest(src);
29-
req.setUserId(user.getId());
27+
UserCreationRequest userCreationRequest) {
28+
UserProfileCreationRequest userProfileCreationRequest =
29+
userProfileMapper
30+
.toUserProfileCreationRequestFromUserCreationRequest(
31+
userCreationRequest);
32+
userProfileCreationRequest.setUserId(user.getId());
3033

3134
try {
32-
profileClient.createUserProfile(req);
35+
profileClient.internalCreateUserProfile(userProfileCreationRequest);
36+
} catch (FeignException.Conflict ignored) {
37+
// profile đã tồn tại ⇒ idempotent
38+
}
39+
}
40+
41+
public void updateProfile(
42+
String userId,
43+
UserProfileUpdateRequest userProfileUpdateRequest) {
44+
try {
45+
profileClient.internalUpdateProfileByUserId(userId,
46+
userProfileUpdateRequest);
47+
} catch (FeignException.Conflict ignored) {
48+
// profile đã tồn tại ⇒ idempotent
49+
}
50+
}
51+
52+
public void softDeleteProfile(
53+
String userId,
54+
String deletedBy) {
55+
try {
56+
profileClient.internalSoftDeleteByUserId(userId, deletedBy);
57+
} catch (FeignException.Conflict ignored) {
58+
// profile đã tồn tại ⇒ idempotent
59+
}
60+
}
61+
62+
public void restoreProfile(String userId) {
63+
try {
64+
profileClient.internalRestoreProfile(userId);
3365
} catch (FeignException.Conflict ignored) {
3466
// profile đã tồn tại ⇒ idempotent
3567
}

identity-service/src/main/java/com/codecampus/identity/mapper/client/UserProfileMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface UserProfileMapper {
1414
"email",
1515
"password"
1616
})
17-
UserProfileCreationRequest toUserProfileCreationRequest(
17+
UserProfileCreationRequest toUserProfileCreationRequestFromUserCreationRequest(
1818
UserCreationRequest userCreationRequest);
1919
}
2020

identity-service/src/main/java/com/codecampus/identity/repository/httpclient/profile/ProfileClient.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,52 @@
33
import com.codecampus.identity.configuration.config.AuthenticationRequestInterceptor;
44
import com.codecampus.identity.dto.common.ApiResponse;
55
import com.codecampus.identity.dto.request.profile.UserProfileCreationRequest;
6+
import com.codecampus.identity.dto.request.profile.UserProfileUpdateRequest;
67
import com.codecampus.identity.dto.response.profile.UserProfileResponse;
78
import org.springframework.cloud.openfeign.FeignClient;
89
import org.springframework.http.MediaType;
10+
import org.springframework.web.bind.annotation.DeleteMapping;
11+
import org.springframework.web.bind.annotation.PatchMapping;
12+
import org.springframework.web.bind.annotation.PathVariable;
913
import org.springframework.web.bind.annotation.PostMapping;
1014
import org.springframework.web.bind.annotation.RequestBody;
15+
import org.springframework.web.bind.annotation.RequestParam;
1116

1217
@FeignClient(
1318
name = "profile-service",
1419
url = "${app.services.profile}",
15-
configuration = {AuthenticationRequestInterceptor.class}
20+
configuration = {AuthenticationRequestInterceptor.class},
21+
path = "/internal"
1622
)
1723
public interface ProfileClient {
1824
@PostMapping(
19-
value = "/internal/user",
25+
value = "/user",
2026
produces = MediaType.APPLICATION_JSON_VALUE
2127
)
22-
ApiResponse<UserProfileResponse> createUserProfile(
28+
ApiResponse<UserProfileResponse> internalCreateUserProfile(
2329
@RequestBody UserProfileCreationRequest request);
30+
31+
@PatchMapping(
32+
value = "/user/{userId}",
33+
produces = MediaType.APPLICATION_JSON_VALUE
34+
)
35+
ApiResponse<Void> internalUpdateProfileByUserId(
36+
@PathVariable("userId") String userId,
37+
@RequestBody UserProfileUpdateRequest request);
38+
39+
@DeleteMapping(
40+
value = "/user/{userId}",
41+
produces = MediaType.APPLICATION_JSON_VALUE
42+
)
43+
ApiResponse<Void> internalSoftDeleteByUserId(
44+
@PathVariable("userId") String userId,
45+
@RequestParam(value = "deletedBy", required = false)
46+
String deletedBy);
47+
48+
@PatchMapping(
49+
value = "/user/{userId}/restore",
50+
produces = MediaType.APPLICATION_JSON_VALUE
51+
)
52+
ApiResponse<Void> internalRestoreProfile(
53+
@PathVariable("userId") String userId);
2454
}

identity-service/src/main/java/com/codecampus/identity/service/account/UserService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ public void deleteUser(String userId) {
195195
User user = findUser(userId);
196196
user.markDeleted(AuthenticationHelper.getMyEmail());
197197
userRepository.save(user);
198+
199+
profileSyncHelper.softDeleteProfile(userId,
200+
AuthenticationHelper.getMyUsername());
198201
}
199202

200203
/**

identity-service/src/main/java/com/codecampus/identity/service/authentication/AuthenticationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private JWTClaimsSet buildJwtClaimsSet(
385385
.distinct()
386386
.toList()
387387
)
388-
.claim("active", true)
388+
.claim("active", user.isEnabled())
389389
.claim("token_type", type)
390390
.build();
391391
}

identity-service/src/main/java/com/codecampus/identity/utils/ConvertUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class ConvertUtils {
2424
// Định dạng dd/MM/yyyy
2525
private static final DateTimeFormatter DMY_FORMATTER =
2626
DateTimeFormatter.ofPattern("dd/MM/yyyy");
27+
private static final DateTimeFormatter DMY_FORMATTER_SHORT =
28+
DateTimeFormatter.ofPattern("dd/MM/yy");
2729

2830
/**
2931
* Chuyển chuỗi ngày có định dạng dd/MM/yyyy sang Instant (đầu ngày).

profile-service/src/main/java/com/codecampus/profile/controller/InternalUserProfileController.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
import com.codecampus.profile.dto.common.ApiResponse;
44
import com.codecampus.profile.dto.request.UserProfileCreationRequest;
5+
import com.codecampus.profile.dto.request.UserProfileUpdateRequest;
56
import com.codecampus.profile.dto.response.UserProfileResponse;
67
import com.codecampus.profile.service.UserProfileService;
78
import lombok.AccessLevel;
89
import lombok.Builder;
910
import lombok.RequiredArgsConstructor;
1011
import lombok.experimental.FieldDefaults;
1112
import lombok.extern.slf4j.Slf4j;
13+
import org.springframework.web.bind.annotation.DeleteMapping;
1214
import org.springframework.web.bind.annotation.GetMapping;
15+
import org.springframework.web.bind.annotation.PatchMapping;
1316
import org.springframework.web.bind.annotation.PathVariable;
1417
import org.springframework.web.bind.annotation.PostMapping;
1518
import org.springframework.web.bind.annotation.RequestBody;
19+
import org.springframework.web.bind.annotation.RequestParam;
1620
import org.springframework.web.bind.annotation.RestController;
1721

1822
@RestController
@@ -24,18 +28,45 @@ public class InternalUserProfileController {
2428
UserProfileService userProfileService;
2529

2630
@PostMapping("/internal/user")
27-
ApiResponse<UserProfileResponse> createUserProfile(
31+
ApiResponse<UserProfileResponse> internalCreateUserProfile(
2832
@RequestBody UserProfileCreationRequest request) {
2933
return ApiResponse.<UserProfileResponse>builder()
3034
.result(userProfileService.createUserProfile(request))
3135
.build();
3236
}
3337

3438
@GetMapping("/internal/user/{userId}")
35-
ApiResponse<UserProfileResponse> getUserProfileByUserId(
39+
ApiResponse<UserProfileResponse> internalGetUserProfileByUserId(
3640
@PathVariable("userId") String userId) {
3741
return ApiResponse.<UserProfileResponse>builder()
3842
.result(userProfileService.getUserProfileByUserId(userId))
3943
.build();
4044
}
45+
46+
@PatchMapping("/internal/user/{userId}")
47+
ApiResponse<Void> internalUpdateProfileByUserId(
48+
@PathVariable String userId,
49+
@RequestBody UserProfileUpdateRequest request) {
50+
userProfileService.updateUserProfileById(userId, request);
51+
return ApiResponse.<Void>builder()
52+
.build();
53+
}
54+
55+
@DeleteMapping("/internal/user/{userId}")
56+
ApiResponse<Void> internalSoftDeleteByUserId(
57+
@PathVariable String userId,
58+
@RequestParam(required = false) String deletedBy) {
59+
userProfileService.softDeleteUserProfileByUserId(
60+
userId, deletedBy);
61+
return ApiResponse.<Void>builder()
62+
.build();
63+
}
64+
65+
@PatchMapping("/internal/user/{userId}/restore")
66+
ApiResponse<Void> restoreByUserId(
67+
@PathVariable String userId) {
68+
userProfileService.restoreByUserId(userId);
69+
return ApiResponse.<Void>builder()
70+
.build();
71+
}
4172
}

0 commit comments

Comments
 (0)