From 2e044d72727fd2b429c12dfe727e8af28999cc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Efe=20Ak=C3=A7a?= Date: Sat, 14 Dec 2024 18:05:21 +0300 Subject: [PATCH 1/2] fix(backend): return follower count correctly in tags --- .../programminglanguagesforum/Services/TagService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/main/java/com/group1/programminglanguagesforum/Services/TagService.java b/backend/src/main/java/com/group1/programminglanguagesforum/Services/TagService.java index 3647c82..cfb4c18 100644 --- a/backend/src/main/java/com/group1/programminglanguagesforum/Services/TagService.java +++ b/backend/src/main/java/com/group1/programminglanguagesforum/Services/TagService.java @@ -101,6 +101,8 @@ public GetTagDetailsResponseDto getTagDetails(Long tagId) { following = false; } + Long followerCount = (long) tagEntity.getFollowers().size(); + if (tagType == TagType.PROGRAMMING_LANGUAGE) { ProgrammingLanguagesTag languageTag = (ProgrammingLanguagesTag) tagEntity; GetProgrammingLanguageTagResponseDto responseDto = modelMapper.map(languageTag, @@ -108,6 +110,7 @@ public GetTagDetailsResponseDto getTagDetails(Long tagId) { responseDto.setTagType(tagType.toString()); responseDto.setRelatedQuestions(relatedQuestions); responseDto.setQuestionCount(questionCount); + responseDto.setFollowerCount(followerCount); responseDto.setFollowing(following); return responseDto; } else if (tagType == TagType.PROGRAMMING_PARADIGM) { @@ -117,6 +120,7 @@ public GetTagDetailsResponseDto getTagDetails(Long tagId) { responseDto.setTagType(tagType.toString()); responseDto.setRelatedQuestions(relatedQuestions); responseDto.setQuestionCount(questionCount); + responseDto.setFollowerCount(followerCount); responseDto.setFollowing(following); return responseDto; } @@ -128,6 +132,7 @@ public GetTagDetailsResponseDto getTagDetails(Long tagId) { .tagType(getTagType(tagEntity).toString()) .relatedQuestions(relatedQuestions) .questionCount(questionCount) + .followerCount(followerCount) .following(following) .build(); @@ -149,6 +154,7 @@ public Page searchTags(String q, Pageable pageable) { return tags.map(tag -> GetTagDetailsResponseDto.builder() .tagId(tag.getId()) .questionCount((long) questionRepository.findQuestionsByTagId(tag.getId()).size()) + .followerCount((long) tag.getFollowers().size()) .name(tag.getTagName()) .description(tag.getTagDescription()) .tagType(getTagType(tag).toString()) From c8c217925daf1889aa6840dffb5c894bd9c8e3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Efe=20Ak=C3=A7a?= Date: Sat, 14 Dec 2024 18:13:32 +0300 Subject: [PATCH 2/2] fix backend tests --- .../programminglanguagesforum/Services/TagServiceTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/test/java/com/group1/programminglanguagesforum/Services/TagServiceTests.java b/backend/src/test/java/com/group1/programminglanguagesforum/Services/TagServiceTests.java index 4b8fbf9..7a6a6b1 100644 --- a/backend/src/test/java/com/group1/programminglanguagesforum/Services/TagServiceTests.java +++ b/backend/src/test/java/com/group1/programminglanguagesforum/Services/TagServiceTests.java @@ -12,6 +12,7 @@ import java.util.Arrays; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; @@ -111,7 +112,7 @@ void testGetTagDetails_Success() { .reputationPoints(0L) .build(); - Tag mockTag = new Tag(1L, null, "Tag1", "Description1", null); + Tag mockTag = new Tag(1L, null, "Tag1", "Description1", new HashSet<>()); Question q1 = Question.builder() .id(1L)