Skip to content

Commit

Permalink
Merge pull request #682 from bounswe/fix/backend/tag-follower-count
Browse files Browse the repository at this point in the history
[Backend] Fix follower count in Tags
  • Loading branch information
mmtftr authored Dec 15, 2024
2 parents 8951b26 + c8c2179 commit 686ef30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ 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,
GetProgrammingLanguageTagResponseDto.class);
responseDto.setTagType(tagType.toString());
responseDto.setRelatedQuestions(relatedQuestions);
responseDto.setQuestionCount(questionCount);
responseDto.setFollowerCount(followerCount);
responseDto.setFollowing(following);
return responseDto;
} else if (tagType == TagType.PROGRAMMING_PARADIGM) {
Expand All @@ -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;
}
Expand All @@ -128,6 +132,7 @@ public GetTagDetailsResponseDto getTagDetails(Long tagId) {
.tagType(getTagType(tagEntity).toString())
.relatedQuestions(relatedQuestions)
.questionCount(questionCount)
.followerCount(followerCount)
.following(following)
.build();

Expand All @@ -149,6 +154,7 @@ public Page<GetTagDetailsResponseDto> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 686ef30

Please sign in to comment.