File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed
post-service/src/main/java/com/codecampus/post
submission-service/src/main/java/com/codecampus/submission Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments