Skip to content

Commit

Permalink
fix: jpql 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wonyongChoi05 committed Oct 13, 2023
1 parent f7ecf9e commit 1200cf7
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public List<ArticleResponse> getFilteredArticles(final LoginMember member,
final ArticleFilterType course,
final boolean onlyBookmarked) {
if (member.isMember()) {
return articleRepository.findArticlesByCourseAndMember(course.getGroupName(),
return articleRepository.findArticlesByCourseAndMember(course.getPartName(),
member.getId(), onlyBookmarked).stream()
.map(article -> ArticleResponse.of(article, member.getId()))
.collect(toList());
}

return articleRepository.findArticlesByCourse(course.getGroupName()).stream()
return articleRepository.findArticlesByCourse(course.getPartName()).stream()
.map(article -> ArticleResponse.of(article, member.getId()))
.collect(toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public enum ArticleFilterType {
BACKEND("백엔드"),
FRONTEND("프론트엔드");

private final String groupName;
private final String partName;

ArticleFilterType(String groupName) {
this.groupName = groupName;
ArticleFilterType(String partName) {
this.partName = partName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
Optional<Article> findFetchLikeById(@Param("id") final Long id);

@Query("SELECT DISTINCT a FROM Article a " +
"JOIN GroupMember gm ON a.member.id = gm.member.id " +
"JOIN gm.group mg " +
"WHERE mg.name LIKE %:course " +
"JOIN DepartmentMember dm ON dm.member.id = dm.member.id " +
"JOIN dm.department d " +
"WHERE d.part = :course " +
"ORDER by a.createdAt desc")
List<Article> findArticlesByCourse(@Param("course") String course);

@Query("SELECT DISTINCT a FROM Article a " +
"JOIN GroupMember gm ON a.member.id = gm.member.id " +
"JOIN gm.group mg " +
"JOIN DepartmentMember dm ON a.member.id = dm.member.id " +
"JOIN dm.department d " +
"LEFT JOIN a.articleBookmarks.articleBookmarks ab " +
"LEFT JOIN a.articleLikes.articleLikes al " +
"WHERE mg.name LIKE %:course AND (:onlyBookmarked = false OR (:onlyBookmarked = true and ab.memberId = :memberId))" +
"WHERE d.part = :course AND (:onlyBookmarked = false OR (:onlyBookmarked = true and ab.memberId = :memberId))" +
"ORDER by a.createdAt desc")
List<Article> findArticlesByCourseAndMember(@Param("course") String course,
@Param("memberId") Long memberId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class GroupMemberService {
public class DepartmentMemberService {

private DepartmentMemberRepository departmentMemberRepository;

public List<DepartmentMember> findGroupMemberByGroupId(Long groupId) {
return departmentMemberRepository.findByDepartmentId(groupId);
public List<DepartmentMember> findDepartmentMemberByDepartmentId(Long departmentId) {
return departmentMemberRepository.findByDepartmentId(departmentId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import wooteco.prolog.common.exception.BadRequestException;
import wooteco.prolog.member.application.GroupMemberService;
import wooteco.prolog.member.application.DepartmentMemberService;
import wooteco.prolog.member.application.MemberService;
import wooteco.prolog.member.application.dto.MemberResponse;
import wooteco.prolog.member.domain.Member;
Expand All @@ -25,7 +25,7 @@ public class SessionMemberService {
private SessionMemberRepository sessionMemberRepository;
private SessionRepository sessionRepository;
private MemberService memberService;
private GroupMemberService groupMemberService;
private DepartmentMemberService departmentMemberService;

@Transactional
public void registerMember(Long sessionId, Long memberId) {
Expand All @@ -42,7 +42,7 @@ public void registerMembersByGroupId(Long sessionId,
List<SessionMember> alreadySessionMembers = sessionMemberRepository.findAllBySessionId(
sessionId);

List<Member> members = groupMemberService.findGroupMemberByGroupId(
List<Member> members = departmentMemberService.findDepartmentMemberByDepartmentId(
sessionGroupMemberRequest.getGroupId()).stream()
.map(it -> it.getMember())
.collect(toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void updatePopularStudylogs(Pageable pageable) {

List<Studylog> popularStudylogs = new ArrayList<>();

for (Part groupType : Part.values()) {
for (Part partType : Part.values()) {
popularStudylogs.addAll(filterStudylogsByDepartmets(recentStudylogs,
new Departments(DepartmetsBygroupType.get(groupType)), departmentMembers).stream()
new Departments(DepartmetsBygroupType.get(partType)), departmentMembers).stream()
.sorted(Comparator.comparing(Studylog::getPopularScore).reversed())
.limit(pageable.getPageSize()).collect(toList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ class DepartmentMemberServiceTest {
private DepartmentMemberRepository departmentMemberRepository;

@InjectMocks
private GroupMemberService groupMemberService;
private DepartmentMemberService departmentMemberService;

@DisplayName("GroupId로 GroupMember를 찾는다.")
@Test
void findGroupMemberByGroupId() {
void findDepartmentMemberByDepartmentId() {
//given
final Long memberId = 1L;
final Long DepartmetId = 2L;
final Long DepartmentId = 2L;
final Long groupMemberId = 3L;

final Member member = new Member(memberId, "송세연", "아마란스", Role.CREW, 1523L, "image");
final Department department = new Department(DepartmetId, "백엔드", "2023 백엔드");
final Department department = new Department(DepartmentId, "백엔드", "2023 백엔드");
final DepartmentMember departmentMember = new DepartmentMember(groupMemberId, member, department);

when(departmentMemberRepository.findByDepartmentId(any())).thenReturn(ImmutableList.of(departmentMember));

//when
final List<DepartmentMember> departmentMembers = groupMemberService.findGroupMemberByGroupId(
DepartmetId);
final List<DepartmentMember> departmentMembers = departmentMemberService.findDepartmentMemberByDepartmentId(
DepartmentId);

//then
assertThat(departmentMembers).containsExactly(departmentMember);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

class DepartmentTest {

private static final Department ANDROID_GROUP = new Department(null, "안드로이드", "5기");
private static final Department BACKEND_GROUP = new Department(null, "백엔드", "5기");
private static final Department FRONTEND_GROUP = new Department(null, "프론트엔드", "4기");
private static final Department ANDROID_DEPARTMENT = new Department(null, "안드로이드", "5기");
private static final Department BACKEND_DEPARTMENT = new Department(null, "백엔드", "5기");
private static final Department FRONTEND_DEPARTMENT = new Department(null, "프론트엔드", "4기");

@Test
void getGroupType_이름이_그룹명을_포함하면_그룹을_반환한다() {
assertThat(ANDROID_GROUP.getPart()).isEqualTo(ANDROID);
assertThat(BACKEND_GROUP.getPart()).isEqualTo(BACKEND);
assertThat(FRONTEND_GROUP.getPart()).isEqualTo(FRONTEND);
void getPartType_이름이_그룹명을_포함하면_그룹을_반환한다() {
assertThat(ANDROID_DEPARTMENT.getPart()).isEqualTo(ANDROID);
assertThat(BACKEND_DEPARTMENT.getPart()).isEqualTo(BACKEND);
assertThat(FRONTEND_DEPARTMENT.getPart()).isEqualTo(FRONTEND);
}

@Test
void getGroupType_이름이_포함하는_그룹명이_없으면_예외가_발생한다() {
void getPartType_이름이_포함하는_그룹명이_없으면_예외가_발생한다() {
Department department = new Department(null, "테스트", "test");

assertThatThrownBy(department::getPart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import wooteco.prolog.common.exception.BadRequestException;
import wooteco.prolog.member.application.GroupMemberService;
import wooteco.prolog.member.application.DepartmentMemberService;
import wooteco.prolog.member.application.MemberService;
import wooteco.prolog.member.application.dto.MemberResponse;
import wooteco.prolog.member.domain.Member;
Expand All @@ -45,7 +45,7 @@ class SessionMemberServiceTest {
private MemberService memberService;

@Mock
private GroupMemberService groupMemberService;
private DepartmentMemberService departmentMemberService;

@DisplayName("Member가 회원가입을 할 수 있어야 한다.")
@Test
Expand Down Expand Up @@ -89,7 +89,7 @@ void registerMembersByGroupId() {

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

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void findPopularStudylogs_IsAnonymousMemberFalse() {

@DisplayName("인기학습 로그를 분야별로 나누어서 반한한다.")
@Test
void findPopularStudylogs_filterGroupType() {
void findPopularStudylogs_filterDepartmentType() {
{
//given
final Department frontend = setUpDepartment("프론트엔드", "5기");
Expand Down

0 comments on commit 1200cf7

Please sign in to comment.