Skip to content

Commit

Permalink
Merge pull request #1605 from woowacourse/refactor/#1559
Browse files Browse the repository at this point in the history
Member, GroupMember, MemberGroup 엔티티 재설계
  • Loading branch information
wonyongChoi05 authored Oct 18, 2023
2 parents 6f1b776 + 6e559f3 commit d0ec8fc
Show file tree
Hide file tree
Showing 32 changed files with 450 additions and 434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@

import io.cucumber.java.en.Given;
import wooteco.prolog.AcceptanceSteps;
import wooteco.prolog.member.domain.GroupMember;
import wooteco.prolog.member.domain.Member;
import wooteco.prolog.member.domain.MemberGroup;
import wooteco.prolog.member.domain.repository.GroupMemberRepository;
import wooteco.prolog.member.domain.repository.MemberGroupRepository;
import wooteco.prolog.member.domain.*;
import wooteco.prolog.member.domain.repository.DepartmentMemberRepository;
import wooteco.prolog.member.domain.repository.DepartmentRepository;
import wooteco.prolog.member.domain.repository.MemberRepository;

import static wooteco.prolog.member.domain.Part.*;
import static wooteco.prolog.member.domain.Term.*;

public class GroupMemberStepDefinitions extends AcceptanceSteps {

private final MemberRepository memberRepository;
private final MemberGroupRepository memberGroupRepository;
private final GroupMemberRepository groupMemberRepository;
private final DepartmentRepository departmentRepository;
private final DepartmentMemberRepository departmentMemberRepository;

public GroupMemberStepDefinitions(MemberRepository memberRepository,
MemberGroupRepository memberGroupRepository,
GroupMemberRepository groupMemberRepository) {
DepartmentRepository departmentRepository,
DepartmentMemberRepository departmentMemberRepository) {
this.memberRepository = memberRepository;
this.memberGroupRepository = memberGroupRepository;
this.groupMemberRepository = groupMemberRepository;
this.departmentRepository = departmentRepository;
this.departmentMemberRepository = departmentMemberRepository;
}

@Given("{string}을 멤버그룹과 그룹멤버에 등록하고")
public void 그룹멤버를_생성하고(String title) {
Member member = memberRepository.findById(1L).get();
MemberGroup 프론트엔드 = memberGroupRepository.save(
new MemberGroup(null, "4기 프론트엔드", "4기 프론트엔드 설명"));
MemberGroup 백엔드 = memberGroupRepository.save(new MemberGroup(null, "4기 백엔드", "4기 백엔드 설명"));
MemberGroup 안드로이드 = memberGroupRepository.save(
new MemberGroup(null, "4기 안드로이드", "4기 안드로이드 설명"));
groupMemberRepository.save(new GroupMember(null, member, 백엔드));
groupMemberRepository.save(new GroupMember(null, member, 프론트엔드));
groupMemberRepository.save(new GroupMember(null, member, 안드로이드));
Department 프론트엔드 = departmentRepository.save(
new Department(null, FRONTEND, FOURTH));
Department 백엔드 = departmentRepository.save(new Department(null, BACKEND, FOURTH));
Department 안드로이드 = departmentRepository.save(
new Department(null, ANDROID, FOURTH));
departmentMemberRepository.save(new DepartmentMember(null, member, 백엔드));
departmentMemberRepository.save(new DepartmentMember(null, member, 프론트엔드));
departmentMemberRepository.save(new DepartmentMember(null, member, 안드로이드));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package wooteco.prolog.docu;

import static org.assertj.core.api.Assertions.assertThat;
import static wooteco.prolog.member.domain.Part.*;
import static wooteco.prolog.member.domain.Term.*;

import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
Expand All @@ -16,11 +18,9 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import wooteco.prolog.Documentation;
import wooteco.prolog.member.domain.GroupMember;
import wooteco.prolog.member.domain.Member;
import wooteco.prolog.member.domain.MemberGroup;
import wooteco.prolog.member.domain.repository.GroupMemberRepository;
import wooteco.prolog.member.domain.repository.MemberGroupRepository;
import wooteco.prolog.member.domain.*;
import wooteco.prolog.member.domain.repository.DepartmentMemberRepository;
import wooteco.prolog.member.domain.repository.DepartmentRepository;
import wooteco.prolog.member.domain.repository.MemberRepository;
import wooteco.prolog.session.application.dto.MissionRequest;
import wooteco.prolog.session.application.dto.MissionResponse;
Expand All @@ -37,9 +37,9 @@ class StudylogDocumentation extends Documentation {
@Autowired
private MemberRepository memberRepository;
@Autowired
private MemberGroupRepository memberGroupRepository;
private DepartmentRepository departmentRepository;
@Autowired
private GroupMemberRepository groupMemberRepository;
private DepartmentMemberRepository departmentMemberRepository;

@Test
void 스터디로그를_생성한다() {
Expand Down Expand Up @@ -312,14 +312,14 @@ private StudylogRequest createStudylogRequest3() {

private void 회원과_멤버그룹_그룹멤버를_등록함() {
Member member = memberRepository.findById(1L).get();
MemberGroup 프론트엔드 = memberGroupRepository.save(
new MemberGroup(null, "4기 프론트엔드", "4기 프론트엔드 설명"));
MemberGroup 백엔드 = memberGroupRepository.save(new MemberGroup(null, "4기 백엔드", "4기 백엔드 설명"));
MemberGroup 안드로이드 = memberGroupRepository.save(
new MemberGroup(null, "4기 안드로이드", "4기 안드로이드 설명"));
groupMemberRepository.save(new GroupMember(null, member, 백엔드));
groupMemberRepository.save(new GroupMember(null, member, 프론트엔드));
groupMemberRepository.save(new GroupMember(null, member, 안드로이드));
Department 프론트엔드 = departmentRepository.save(
new Department(null, FRONTEND, FOURTH));
Department 백엔드 = departmentRepository.save(new Department(null, BACKEND, FOURTH));
Department 안드로이드 = departmentRepository.save(
new Department(null, ANDROID, FOURTH));
departmentMemberRepository.save(new DepartmentMember(null, member, 백엔드));
departmentMemberRepository.save(new DepartmentMember(null, member, 프론트엔드));
departmentMemberRepository.save(new DepartmentMember(null, member, 안드로이드));
}

private Long 미션_등록함(MissionRequest request) {
Expand Down
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 @@ -94,7 +94,7 @@ public enum BadRequestCode {
ARTICLE_IMAGE_URL_OVER_LENGTH_EXCEPTION(12007, "ARTICLE_IMAGE_URL_OVER_LENGTH_EXCEPTION"),
ARTICLE_INVALID_URL_EXCEPTION(12008, "ARTICLE_INVALID_URL_EXCEPTION"),
UNVALIDATED_MEMBER_EXCEPTION(12009, "UNVALIDATED_MEMBER_EXCEPTION");

private int code;
private String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package wooteco.prolog.member.application;

import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import wooteco.prolog.member.domain.DepartmentMember;
import wooteco.prolog.member.domain.repository.DepartmentMemberRepository;

@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class DepartmentMemberService {

private DepartmentMemberRepository departmentMemberRepository;

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

}

This file was deleted.

40 changes: 40 additions & 0 deletions backend/src/main/java/wooteco/prolog/member/domain/Department.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package wooteco.prolog.member.domain;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Department {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(value = EnumType.STRING)
private Part part;

@Enumerated(value = EnumType.STRING)
private Term term;

public Department(Long id, Part part, Term term) {
this.id = id;
this.part = part;
this.term = term;
}

public Department(Long id, String part, String term) {
this.id = id;
this.part = Part.getPartByName(part);
this.term = Term.getTermByName(term);
}

public Part getPart() {
return part;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
public class GroupMember {
public class DepartmentMember {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -25,12 +25,12 @@ public class GroupMember {
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_id", nullable = false)
private MemberGroup group;
@JoinColumn(name = "department_id", nullable = false)
private Department department;

public GroupMember(Long id, Member member, MemberGroup group) {
public DepartmentMember(Long id, Member member, Department department) {
this.id = id;
this.member = member;
this.group = group;
this.department = department;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package wooteco.prolog.member.domain;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class Departments {

private List<Department> values;

public boolean isContainsDepartments(Department department) {
return values.contains(department);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d0ec8fc

Please sign in to comment.