From 490bcd6380a5072768c3e666383c996f955c1ffc Mon Sep 17 00:00:00 2001 From: CagatayColak Date: Tue, 10 Dec 2024 16:19:19 +0300 Subject: [PATCH 1/3] Add return questions, answers and followed tags to GET users/{userId} --- .../Controllers/UserController.java | 19 ++++++++++--------- .../Responses/UserProfileResponseDto.java | 5 ++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java index 0abad964..1318129d 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java @@ -42,16 +42,14 @@ public ResponseEntity> getUser() { List questions = questionService.findByAuthorId(user.getId()); List answers = answerService.findByAnsweredBy(user.getId()); selfProfileResponseDto.setFollowedTags( - tagService.getFollowedTags(user.getId()) - ); + tagService.getFollowedTags(user.getId())); selfProfileResponseDto.setReputationPoints(userService.calculateReputation(user)); selfProfileResponseDto.setQuestionCount((long) questions.size()); selfProfileResponseDto.setQuestions( - questions); + questions); selfProfileResponseDto.setAnswerCount((long) answers.size()); selfProfileResponseDto.setAnswers( - answers); - + answers); GenericApiResponse response = ApiResponseBuilder.buildSuccessResponse( selfProfileResponseDto.getClass(), @@ -84,10 +82,13 @@ public ResponseEntity> getUserById( UserProfileResponseDto.class); userProfileResponseDto.setReputationPoints(userService.calculateReputation(user.get())); userProfileResponseDto.setSelfFollowing(userService.selfFollowing(user.get())); - userProfileResponseDto.setFollowedTags( - tagService.getFollowedTags(user.get().getId()) - ); - + List questions = questionService.findByAuthorId(id); + userProfileResponseDto.setQuestions(questions); + userProfileResponseDto.setQuestionCount((long) questions.size()); + List answers = answerService.findByAnsweredBy(id); + userProfileResponseDto.setAnswers(answers); + userProfileResponseDto.setAnswerCount((long) answers.size()); + userProfileResponseDto.setFollowedTags(tagService.getFollowedTags(id)); GenericApiResponse response = ApiResponseBuilder.buildSuccessResponse( userProfileResponseDto.getClass(), diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java b/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java index 15d12b1a..06fb45b7 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java @@ -1,4 +1,5 @@ package com.group1.programminglanguagesforum.DTOs.Responses; + import com.group1.programminglanguagesforum.Entities.ExperienceLevel; import lombok.*; @@ -25,5 +26,7 @@ public class UserProfileResponseDto { private ExperienceLevel experienceLevel; @Builder.Default private List followedTags = new ArrayList<>(); - + private Long questionCount; + private List questions; + private List answers; } From 6d146ac1b4c87094079392f70b70ce617c560976 Mon Sep 17 00:00:00 2001 From: CagatayColak Date: Tue, 10 Dec 2024 16:20:02 +0300 Subject: [PATCH 2/3] Revert "Add return questions, answers and followed tags to GET users/{userId}" This reverts commit 490bcd6380a5072768c3e666383c996f955c1ffc. --- .../Controllers/UserController.java | 19 +++++++++---------- .../Responses/UserProfileResponseDto.java | 5 +---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java index 1318129d..0abad964 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java @@ -42,14 +42,16 @@ public ResponseEntity> getUser() { List questions = questionService.findByAuthorId(user.getId()); List answers = answerService.findByAnsweredBy(user.getId()); selfProfileResponseDto.setFollowedTags( - tagService.getFollowedTags(user.getId())); + tagService.getFollowedTags(user.getId()) + ); selfProfileResponseDto.setReputationPoints(userService.calculateReputation(user)); selfProfileResponseDto.setQuestionCount((long) questions.size()); selfProfileResponseDto.setQuestions( - questions); + questions); selfProfileResponseDto.setAnswerCount((long) answers.size()); selfProfileResponseDto.setAnswers( - answers); + answers); + GenericApiResponse response = ApiResponseBuilder.buildSuccessResponse( selfProfileResponseDto.getClass(), @@ -82,13 +84,10 @@ public ResponseEntity> getUserById( UserProfileResponseDto.class); userProfileResponseDto.setReputationPoints(userService.calculateReputation(user.get())); userProfileResponseDto.setSelfFollowing(userService.selfFollowing(user.get())); - List questions = questionService.findByAuthorId(id); - userProfileResponseDto.setQuestions(questions); - userProfileResponseDto.setQuestionCount((long) questions.size()); - List answers = answerService.findByAnsweredBy(id); - userProfileResponseDto.setAnswers(answers); - userProfileResponseDto.setAnswerCount((long) answers.size()); - userProfileResponseDto.setFollowedTags(tagService.getFollowedTags(id)); + userProfileResponseDto.setFollowedTags( + tagService.getFollowedTags(user.get().getId()) + ); + GenericApiResponse response = ApiResponseBuilder.buildSuccessResponse( userProfileResponseDto.getClass(), diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java b/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java index 06fb45b7..15d12b1a 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java @@ -1,5 +1,4 @@ package com.group1.programminglanguagesforum.DTOs.Responses; - import com.group1.programminglanguagesforum.Entities.ExperienceLevel; import lombok.*; @@ -26,7 +25,5 @@ public class UserProfileResponseDto { private ExperienceLevel experienceLevel; @Builder.Default private List followedTags = new ArrayList<>(); - private Long questionCount; - private List questions; - private List answers; + } From be1a66e5065cc54394b0372a66d6a7424a3c15eb Mon Sep 17 00:00:00 2001 From: CagatayColak Date: Tue, 10 Dec 2024 16:21:37 +0300 Subject: [PATCH 3/3] Reapply "Add return questions, answers and followed tags to GET users/{userId}" This reverts commit 6d146ac1b4c87094079392f70b70ce617c560976. --- .../Controllers/UserController.java | 19 ++++++++++--------- .../Responses/UserProfileResponseDto.java | 5 ++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java index 0abad964..1318129d 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Controllers/UserController.java @@ -42,16 +42,14 @@ public ResponseEntity> getUser() { List questions = questionService.findByAuthorId(user.getId()); List answers = answerService.findByAnsweredBy(user.getId()); selfProfileResponseDto.setFollowedTags( - tagService.getFollowedTags(user.getId()) - ); + tagService.getFollowedTags(user.getId())); selfProfileResponseDto.setReputationPoints(userService.calculateReputation(user)); selfProfileResponseDto.setQuestionCount((long) questions.size()); selfProfileResponseDto.setQuestions( - questions); + questions); selfProfileResponseDto.setAnswerCount((long) answers.size()); selfProfileResponseDto.setAnswers( - answers); - + answers); GenericApiResponse response = ApiResponseBuilder.buildSuccessResponse( selfProfileResponseDto.getClass(), @@ -84,10 +82,13 @@ public ResponseEntity> getUserById( UserProfileResponseDto.class); userProfileResponseDto.setReputationPoints(userService.calculateReputation(user.get())); userProfileResponseDto.setSelfFollowing(userService.selfFollowing(user.get())); - userProfileResponseDto.setFollowedTags( - tagService.getFollowedTags(user.get().getId()) - ); - + List questions = questionService.findByAuthorId(id); + userProfileResponseDto.setQuestions(questions); + userProfileResponseDto.setQuestionCount((long) questions.size()); + List answers = answerService.findByAnsweredBy(id); + userProfileResponseDto.setAnswers(answers); + userProfileResponseDto.setAnswerCount((long) answers.size()); + userProfileResponseDto.setFollowedTags(tagService.getFollowedTags(id)); GenericApiResponse response = ApiResponseBuilder.buildSuccessResponse( userProfileResponseDto.getClass(), diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java b/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java index 15d12b1a..06fb45b7 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/DTOs/Responses/UserProfileResponseDto.java @@ -1,4 +1,5 @@ package com.group1.programminglanguagesforum.DTOs.Responses; + import com.group1.programminglanguagesforum.Entities.ExperienceLevel; import lombok.*; @@ -25,5 +26,7 @@ public class UserProfileResponseDto { private ExperienceLevel experienceLevel; @Builder.Default private List followedTags = new ArrayList<>(); - + private Long questionCount; + private List questions; + private List answers; }