Skip to content

Commit 151d76d

Browse files
committed
Update Org Id
1 parent 142c805 commit 151d76d

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

post-service/src/main/java/com/codecampus/post/helper/AuthenticationHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,17 @@ public static String getMyUsername() {
7373

7474
return null;
7575
}
76+
77+
public static String getMyOrgId() {
78+
Authentication a = SecurityContextHolder.getContext().getAuthentication();
79+
if (a == null || !a.isAuthenticated()) {
80+
return null;
81+
}
82+
Object p = a.getPrincipal();
83+
if (p instanceof Jwt jwt) {
84+
String orgId = jwt.getClaimAsString("org_id");
85+
return (orgId != null && !orgId.isBlank()) ? orgId : null;
86+
}
87+
return null;
88+
}
7689
}

post-service/src/main/java/com/codecampus/post/service/PostService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ public PostResponseDto getPostDetail(
103103
public void createPost(
104104
PostRequestDto postRequestDto) {
105105
String userId = AuthenticationHelper.getMyUserId();
106+
String orgId = AuthenticationHelper.getMyOrgId();
106107

107108
List<String> fileUrls =
108109
postHelper.uploadAll(postRequestDto.getFileDocument());
109110

110111
Post post = postMapper.toPostFromPostRequestDto(postRequestDto);
111112
post.setFileUrls(fileUrls);
112113
post.setUserId(userId);
114+
post.setOrgId(orgId);
113115

114116
postRepository.save(post);
115117

submission-service/src/main/java/com/codecampus/submission/helper/AuthenticationHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,17 @@ public static String getMyUsername() {
7373

7474
return null;
7575
}
76+
77+
public static String getMyOrgId() {
78+
Authentication a = SecurityContextHolder.getContext().getAuthentication();
79+
if (a == null || !a.isAuthenticated()) {
80+
return null;
81+
}
82+
Object p = a.getPrincipal();
83+
if (p instanceof Jwt jwt) {
84+
String orgId = jwt.getClaimAsString("org_id");
85+
return (orgId != null && !orgId.isBlank()) ? orgId : null;
86+
}
87+
return null;
88+
}
7689
}

submission-service/src/main/java/com/codecampus/submission/service/ExerciseService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ public Exercise createExercise(
107107
CreateExerciseRequest request,
108108
boolean returnExercise) {
109109
String userId = AuthenticationHelper.getMyUserId();
110+
String orgId = AuthenticationHelper.getMyOrgId();
110111

111-
Exercise exercise = exerciseRepository
112-
.save(exerciseMapper.toExerciseFromCreateExerciseRequest(
113-
request, userId));
112+
Exercise exercise = exerciseMapper.toExerciseFromCreateExerciseRequest(
113+
request, userId);
114+
exercise.setOrgId(orgId);
115+
exerciseRepository.save(exercise);
116+
114117
if (exercise.getExerciseType() == ExerciseType.QUIZ) {
115118
grpcQuizClient.pushExercise(exercise);
116119
} else if (exercise.getExerciseType() == ExerciseType.CODING) {

0 commit comments

Comments
 (0)