Skip to content

Commit

Permalink
Merge pull request #1620 from woowacourse/hotfix/no-issue
Browse files Browse the repository at this point in the history
fix: Map.getObject 수정
  • Loading branch information
wonyongChoi05 authored Nov 23, 2023
2 parents 1f8d48a + a7df553 commit ee36964
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import wooteco.prolog.member.application.MemberService;
import wooteco.prolog.member.application.dto.MemberResponse;
import wooteco.prolog.member.domain.Member;
import wooteco.prolog.session.application.dto.SessionGroupMemberRequest;
import wooteco.prolog.session.application.dto.SessionDepartmentMemberRequest;
import wooteco.prolog.session.domain.SessionMember;
import wooteco.prolog.session.domain.repository.SessionMemberRepository;
import wooteco.prolog.session.domain.repository.SessionRepository;
Expand All @@ -38,12 +38,12 @@ public void registerMember(Long sessionId, Long memberId) {

@Transactional
public void registerMembersByGroupId(Long sessionId,
SessionGroupMemberRequest sessionGroupMemberRequest) {
SessionDepartmentMemberRequest sessionDepartmentMemberRequest) {
List<SessionMember> alreadySessionMembers = sessionMemberRepository.findAllBySessionId(
sessionId);

List<Member> members = departmentMemberService.findDepartmentMemberByDepartmentId(
sessionGroupMemberRequest.getGroupId()).stream()
sessionDepartmentMemberRequest.getDepartmentId()).stream()
.map(it -> it.getMember())
.collect(toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class SessionGroupMemberRequest {
public class SessionDepartmentMemberRequest {

private Long departmentId;

private Long groupId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import wooteco.prolog.login.ui.LoginMember;
import wooteco.prolog.member.application.dto.MemberResponse;
import wooteco.prolog.session.application.SessionMemberService;
import wooteco.prolog.session.application.dto.SessionGroupMemberRequest;
import wooteco.prolog.session.application.dto.SessionDepartmentMemberRequest;

@RestController
@RequestMapping("/sessions/{sessionId}/members")
Expand Down Expand Up @@ -49,8 +49,8 @@ public ResponseEntity<Void> deleteRegisteredSession(
// admin only
@PostMapping
public ResponseEntity<Void> registerByGroupId(@PathVariable Long sessionId,
@RequestBody SessionGroupMemberRequest sessionGroupMemberRequest) {
sessionMemberService.registerMembersByGroupId(sessionId, sessionGroupMemberRequest);
@RequestBody SessionDepartmentMemberRequest sessionDepartmentMemberRequest) {
sessionMemberService.registerMembersByGroupId(sessionId, sessionDepartmentMemberRequest);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -43,9 +44,9 @@ public void updatePopularStudylogs(Pageable pageable) {
deleteAllLegacyPopularStudylogs();

List<DepartmentMember> departmentMembers = departmentMemberRepository.findAll();
Map<Part, List<Department>> DepartmetsBygroupType = departmentRepository.findAll()
Map<String, List<Department>> departmentsByPart = departmentRepository.findAll()
.stream()
.collect(Collectors.groupingBy(Department::getPart));
.collect(Collectors.groupingBy(part -> part.getPart().getName()));

final List<Studylog> recentStudylogs = findRecentStudylogs(LocalDateTime.now(),
pageable.getPageSize());
Expand All @@ -54,7 +55,7 @@ public void updatePopularStudylogs(Pageable pageable) {

for (Part partType : Part.values()) {
popularStudylogs.addAll(filterStudylogsByDepartmets(recentStudylogs,
new Departments(DepartmetsBygroupType.get(partType)), departmentMembers).stream()
new Departments(departmentsByPart.get(partType.getName())), departmentMembers).stream()
.sorted(Comparator.comparing(Studylog::getPopularScore).reversed())
.limit(pageable.getPageSize()).collect(toList()));
}
Expand Down Expand Up @@ -86,9 +87,8 @@ private List<Studylog> findRecentStudylogs(final LocalDateTime dateTime,
}

private List<Studylog> filterStudylogsByDepartmets(final List<Studylog> studylogs,
final Departments departments,
final List<DepartmentMember> departmentMembers) {

final Departments departments,
final List<DepartmentMember> departmentMembers) {
return studylogs.stream()
.filter(
studylog -> checkMemberAssignedInDepartmets(departments, studylog.getMember(),
Expand All @@ -97,7 +97,7 @@ private List<Studylog> filterStudylogsByDepartmets(final List<Studylog> studylog
}

private boolean checkMemberAssignedInDepartmets(Departments departments, Member member,
List<DepartmentMember> departmentMembers) {
List<DepartmentMember> departmentMembers) {
return departmentMembers.stream().anyMatch(
it -> it.getMember().equals(member) && departments.isContainsDepartments(it.getDepartment()));
}
Expand All @@ -106,22 +106,24 @@ public PopularStudylogsResponse findPopularStudylogs(Pageable pageable, Long mem
boolean isAnonymousMember) {

List<Studylog> allPopularStudylogs = getSortedPopularStudyLogs(pageable);
List<DepartmentMember> groupedMembers = departmentMemberRepository.findAll();
Map<Part, List<Department>> DepartmetsBygroupType = departmentRepository.findAll()
.stream().collect(Collectors.groupingBy(Department::getPart));
List<DepartmentMember> departmentMembers = departmentMemberRepository.findAll();
Map<Part, List<Department>> departmentsByPart = departmentRepository.findAll()
.stream()
.collect(Collectors.groupingBy(Department::getPart));

return PopularStudylogsResponse.of(
studylogsResponse(allPopularStudylogs, pageable, memberId),
studylogsResponse(
filterStudylogsByDepartmets(allPopularStudylogs, new Departments(DepartmetsBygroupType.get(Part.FRONTEND)), groupedMembers),
filterStudylogsByDepartmets(allPopularStudylogs, new Departments(departmentsByPart.get(Part.FRONTEND)), departmentMembers),
pageable,
memberId),
memberId
),
studylogsResponse(
filterStudylogsByDepartmets(allPopularStudylogs, new Departments(DepartmetsBygroupType.get(Part.BACKEND)), groupedMembers),
filterStudylogsByDepartmets(allPopularStudylogs, new Departments(departmentsByPart.get(Part.BACKEND)), departmentMembers),
pageable,
memberId),
studylogsResponse(
filterStudylogsByDepartmets(allPopularStudylogs, new Departments(DepartmetsBygroupType.get(Part.ANDROID)), groupedMembers),
filterStudylogsByDepartmets(allPopularStudylogs, new Departments(departmentsByPart.get(Part.ANDROID)), departmentMembers),
pageable,
memberId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import wooteco.prolog.member.application.MemberService;
import wooteco.prolog.member.application.dto.MemberResponse;
import wooteco.prolog.member.domain.Member;
import wooteco.prolog.session.application.dto.SessionGroupMemberRequest;
import wooteco.prolog.session.application.dto.SessionDepartmentMemberRequest;
import wooteco.prolog.session.domain.SessionMember;
import wooteco.prolog.session.domain.repository.SessionMemberRepository;
import wooteco.prolog.session.domain.repository.SessionRepository;
Expand Down Expand Up @@ -82,14 +82,14 @@ void registerMemberFail() {
@Test
void registerMembersByGroupId() {
// given
final SessionGroupMemberRequest request = new SessionGroupMemberRequest(1L);
final SessionDepartmentMemberRequest request = new SessionDepartmentMemberRequest(1L);

// when
sessionMemberService.registerMembersByGroupId(1L, request);

// then
verify(sessionMemberRepository, atMostOnce()).findAllBySessionId(1L);
verify(departmentMemberService, atMostOnce()).findDepartmentMemberByDepartmentId(request.getGroupId());
verify(departmentMemberService, atMostOnce()).findDepartmentMemberByDepartmentId(request.getDepartmentId());
verify(sessionMemberRepository, atMostOnce()).saveAll(null);

}
Expand Down

0 comments on commit ee36964

Please sign in to comment.