Skip to content

Commit

Permalink
Merge pull request #154 from HGU-WALAB/HISTUDY-153
Browse files Browse the repository at this point in the history
뒤늦게 신청한 상대의 친구 선택 상태가 변경되지 않는 버그 수정
  • Loading branch information
zionhann authored Mar 17, 2024
2 parents f551a14 + e88a494 commit e801a8e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static StudyApplicant of(
return applicant;
}

public void changeStatusIfPartnerRequested(
public void changeStatusIfReceivedBy(
User user, Function<StudyPartnerRequest, RequestStatus> changeStatus) {
this.partnerRequests.stream()
.filter(request -> request.isReceivedBy(user))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ public boolean isInSameGroup(StudyApplicant applicant) {
}

protected void assignCommonCourses(StudyApplicant... applicants) {
if (isSameMemberExact(applicants)) return;
if (this.members.isEmpty()) {
this.courses.clear();
this.tag = -1;
if (isSameMemberExact(applicants)) {
return;
}
findCommonCourses(applicants).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public interface StudyGroupRepository extends JpaRepository<StudyGroup, Long> {
Optional<StudyGroup> findByTagAndAcademicTerm(int tag, AcademicTerm academicTerm);

@Modifying
@Query("delete from StudyGroup s where s.tag = -1")
void deleteEmptyGroup();
@Query("delete from StudyGroup s where s.members is empty and s.academicTerm = :academicTerm")
void deleteEmptyGroup(@Param("academicTerm") AcademicTerm academicTerm);

@Query("select max(s.tag) from StudyGroup s where s.academicTerm = :academicTerm")
Optional<Integer> countMaxTag(@Param("academicTerm") AcademicTerm academicTerm);
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/edu/handong/csee/histudy/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public ApplyFormDto apply(ApplyForm form, String email) {
studyApplicantRepository
.findByUserAndTerm(partner, currentTerm)
.ifPresent(
partnerApplication ->
partnerApplication.changeStatusIfPartnerRequested(
user, StudyPartnerRequest::accept)));
partnerApplication -> {
partnerApplication.changeStatusIfReceivedBy(
user, StudyPartnerRequest::accept);

applicant.changeStatusIfReceivedBy(partner, StudyPartnerRequest::accept);
}));
studyApplicantRepository.save(applicant);
return new ApplyFormDto(applicant);
}
Expand Down Expand Up @@ -88,9 +91,12 @@ public StudyApplicant apply(List<Long> friendsIds, List<Long> courseIds, String
studyApplicantRepository
.findByUserAndTerm(partner, currentTerm)
.ifPresent(
partnerApplication ->
partnerApplication.changeStatusIfPartnerRequested(
user, StudyPartnerRequest::accept)));
partnerApplication -> {
partnerApplication.changeStatusIfReceivedBy(
user, StudyPartnerRequest::accept);

applicant.changeStatusIfReceivedBy(partner, StudyPartnerRequest::accept);
}));
return studyApplicantRepository.save(applicant);
}

Expand All @@ -109,7 +115,7 @@ private void removeFormHistoryIfExists(User user, AcademicTerm currentTerm) {
.findByUserAndTerm(receiver, currentTerm)
.ifPresent(
partnerApplication ->
partnerApplication.changeStatusIfPartnerRequested(
partnerApplication.changeStatusIfReceivedBy(
user, StudyPartnerRequest::unfriend));
}
studyApplicantRepository.delete(applicant);
Expand Down Expand Up @@ -222,7 +228,7 @@ public void editUser(UserDto.UserEdit form) {
applicantOr.ifPresent(
applicant -> {
applicant.leaveGroup();
studyGroupRepository.deleteEmptyGroup();
studyGroupRepository.deleteEmptyGroup(currentTerm);
}));
}

Expand Down

0 comments on commit e801a8e

Please sign in to comment.