Skip to content

Commit

Permalink
Merge pull request #296 from 6QuizOnTheBlock/be/feat/#292-groupCount
Browse files Browse the repository at this point in the history
feat #292: 그룹생성 시 관계테이블 그룹 횟수 카운트
  • Loading branch information
Henry-Cha authored May 12, 2024
2 parents c71ef6f + a22463c commit 92615b5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.quiz.ourclass.domain.notice.dto.SseDTO;
import com.quiz.ourclass.domain.notice.dto.SseType;
import com.quiz.ourclass.domain.notice.service.SseService;
import com.quiz.ourclass.domain.organization.entity.Relationship;
import com.quiz.ourclass.domain.organization.repository.RelationshipRepository;
import com.quiz.ourclass.global.exception.ErrorCode;
import com.quiz.ourclass.global.exception.GlobalException;
import com.quiz.ourclass.global.util.RedisUtil;
Expand All @@ -37,6 +39,7 @@ public class GroupServiceImpl implements GroupService {
private final GroupMemberRepository groupMemberRepository;
private final MemberRepository memberRepository;
private final ChallengeRepository challengeRepository;
private final RelationshipRepository relationshipRepository;
private final UserAccessUtil accessUtil;
private final RedisUtil redisUtil;
private final static String REDIS_GROUP_KEY = "CHALLENGE_LEADER:";
Expand Down Expand Up @@ -114,10 +117,28 @@ public long createGroup(String key) {
sseService.send(sseDTO);
});
groupMemberRepository.saveAll(groupMembers);
updateGroupCount(members, challenge.getOrganization().getId(), group.getGroupType());
redisUtil.delete(key);
return group.getId();
}

private void updateGroupCount(Set<String> members, long orgId, GroupType groupType) {
List<Long> memberIds = members.stream().map(Long::parseLong).sorted().toList();
for (int i = 0; i < memberIds.size() - 1; i++) {
for (int j = i + 1; j < memberIds.size(); j++) {
Relationship relationship = relationshipRepository.findByOrganizationIdAndMember1IdAndMember2Id(
orgId, memberIds.get(i), memberIds.get(j))
.orElseThrow(() -> new GlobalException(ErrorCode.RELATION_NOT_FOUND));
if (groupType.equals(GroupType.FREE)) {
relationship.updateFreeGroupCount();
} else {
relationship.updateDesignGroupCount();
}
}
}
}


@Transactional
@Override
public void deleteMatchingMember(String key, Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ public class Relationship {
Member member2;
int relationPoint;
int tagGreetingCount;
int groupCount;
int designGroupCount;
int freeGroupCount;

public int updateTagGreetingCount() {
this.tagGreetingCount += 1;
return this.tagGreetingCount;
}

public int updateDesignGroupCount() {
this.designGroupCount += 1;
return this.designGroupCount;
}

public int updateFreeGroupCount() {
this.freeGroupCount += 1;
return this.freeGroupCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public RelationResponse getMemberRelation(long id, RelationRequest relationReque
.memberId(targetMember.getId())
.memberName(targetMember.getName())
.relationPoint(relationship.getRelationPoint())
.groupCount(relationship.getGroupCount())
.groupCount(relationship.getDesignGroupCount() + relationship.getFreeGroupCount())
.tagGreetingCount(relationship.getTagGreetingCount())
.receiveCount(receiveCount)
.sendCount(sendCount).build();
Expand Down

0 comments on commit 92615b5

Please sign in to comment.