Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat/CK-242] 로드맵 관련 부분 의존성 리팩토링을 한다 #206

Merged
merged 23 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d72b469
refactor: roadmap 관련 코드 패키지 분리
Ohjintaek Dec 19, 2023
2ea6239
refactor: RoadmapCreateService에서 goalRoom 의존성 제거
Ohjintaek Dec 19, 2023
91f128b
refactor: RoadmapReadService에서 goalRoom 의존성 제거
Ohjintaek Dec 19, 2023
7085619
refactor: RoadmapScheduler에서 goalRoom 의존성 제거 및 테스트코드 패키지 분리
Ohjintaek Dec 19, 2023
3c0ba17
refactor: Roadmap에서 발생한 예외는 RoaadmapException을 던지도록 수정
Ohjintaek Dec 22, 2023
354f9b6
refactor: RoadmapSaveArgumentResolver 의존성 역전
Ohjintaek Dec 22, 2023
c8fc8f4
test: 테스트 코드 수정
Ohjintaek Dec 22, 2023
a307525
chore: build.gradle 수정 (jacoco 테스트 커버리지)
Ohjintaek Dec 22, 2023
7ce0184
refactor: roadmap과 roadmapReview에서 member 직접 참조를 삭제
Ohjintaek Jan 12, 2024
b63f1b7
chore: ScrollResponseMapper common으로 이관
Ohjintaek Jan 13, 2024
a0f588b
refactor: 로드맵 삭제 시 하위 골룸 삭제 방식 변경 (OnDelete 옵션 사용)
Ohjintaek Jan 13, 2024
3d6cd17
chore: 패키지 경로 수정
Ohjintaek Jan 13, 2024
df672b0
refactor: dto 패키지 분리
Ohjintaek Jan 13, 2024
7a1b1f3
refactor: Event 객체에서 도메인 직접 전달 제거
Ohjintaek Jan 14, 2024
3c5fc04
refactor: RoadmapNode에서 RoadmapContent 의존 제거
Ohjintaek Jan 14, 2024
9cf3c2a
refactor: Roadmap과 RoadmapContent, RoadmapReview간 의존 관계 제거
Ohjintaek Jan 14, 2024
bdccbbc
refactor: Roadmap 생성 시 태그, RoadmapContent 생성 시 노드들을 필수로 넣도록 수정
Ohjintaek Jan 21, 2024
5cf8113
test: RoadmapNodes 테스트코드 추가
Ohjintaek Jan 21, 2024
a0472bc
refactor: 불필요한 클래스 삭제
Ohjintaek Feb 15, 2024
732673f
fix: 데이터베이스 무결성 오류 수정
Ohjintaek Feb 15, 2024
fc761d5
refactor: 로드맵 삭제 시 연관된 리뷰 삭제를 이벤트로 발행
Ohjintaek Feb 16, 2024
ac71f6e
chore: merge conflict 해결
Ohjintaek Mar 27, 2024
3a7e610
refactor: 불필요한 이벤트 호출 제거
Ohjintaek Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/kirikiri/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jacocoTestReport {
fileTree(dir: it, excludes: [
"co/kirikiri/persistence/QuerydslRepositorySupporter",
"co/kirikiri/domain/**",
"co/kirikiri/**/domain/**",
"co/kirikiri/persistence/goalroom/dto/**",
"**/*Application*",
"**/*Config*",
Expand Down Expand Up @@ -115,7 +116,8 @@ jacocoTestCoverageVerification {

excludes = [
"co.kirikiri.persistence.QuerydslRepositorySupporter",
"co.kirikiri.domain.**.**",
"co.kirikiri.domain.**",
"co.kirikiri.**.domain.**",
"co.kirikiri.persistence.goalroom.dto.**",
"**.*Application*",
"**.*Config*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,98 +1,6 @@
package co.kirikiri.common.resolver;

import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest;
import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest;
import co.kirikiri.service.exception.BadRequestException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.validation.DataBinder;
import org.springframework.validation.Validator;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;

@Component
@RequiredArgsConstructor
public class RoadmapSaveArgumentResolver implements HandlerMethodArgumentResolver {

private final ObjectMapper objectMapper;
private final Validator validator;

@Override
public boolean supportsParameter(final MethodParameter parameter) {
return parameter.getParameterType().equals(RoadmapSaveRequest.class);
}

@Override
public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer,
final NativeWebRequest nativeWebRequest, final WebDataBinderFactory binderFactory)
throws MethodArgumentNotValidException {
final HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest();
checkMultipart(request);
final MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
final RoadmapSaveRequest roadmapSaveRequestNotIncludeImage = makeRoadmapSaveRequestNotIncludeImage(
multipartRequest);
validateRequest(parameter, roadmapSaveRequestNotIncludeImage);
return makeRoadmapSaveRequestIncludeImage(roadmapSaveRequestNotIncludeImage, multipartRequest);
}

private void checkMultipart(final HttpServletRequest request) {
final MultipartResolver multipartResolver = new StandardServletMultipartResolver();
if (!multipartResolver.isMultipart(request)) {
throw new BadRequestException("multipart/form-data 형식으로 들어와야합니다.");
}
}

private RoadmapSaveRequest makeRoadmapSaveRequestNotIncludeImage(
final MultipartHttpServletRequest multipartRequest) {
final String jsonData = getJsonData(multipartRequest);
return bindRoadmapSaveRequest(jsonData);
}

private void validateRequest(final MethodParameter parameter, final RoadmapSaveRequest roadmapSaveRequest)
throws MethodArgumentNotValidException {
final DataBinder binder = new DataBinder(roadmapSaveRequest);
binder.setValidator(validator);
binder.validate();

if (binder.getBindingResult().hasErrors()) {
throw new MethodArgumentNotValidException(parameter, binder.getBindingResult());
}
}

private RoadmapSaveRequest makeRoadmapSaveRequestIncludeImage(final RoadmapSaveRequest roadmapSaveRequest,
final MultipartHttpServletRequest multipartRequest) {
for (final RoadmapNodeSaveRequest roadmapNode : roadmapSaveRequest.roadmapNodes()) {
final List<MultipartFile> images = multipartRequest.getFiles(roadmapNode.getTitle());
roadmapNode.setImages(images);
}
return roadmapSaveRequest;
}

private String getJsonData(final MultipartHttpServletRequest multipartRequest) {
final String jsonData = multipartRequest.getParameter("jsonData");
if (jsonData == null) {
throw new BadRequestException("로드맵 생성 시 jsonData는 필수입니다.");
}
return multipartRequest.getParameter("jsonData");
}

private RoadmapSaveRequest bindRoadmapSaveRequest(final String jsonData) {
try {
return objectMapper.readValue(jsonData, RoadmapSaveRequest.class);
} catch (final JsonProcessingException exception) {
throw new BadRequestException("로드맵 생성 요청 형식이 틀렸습니다.");
}
}
public interface RoadmapSaveArgumentResolver extends HandlerMethodArgumentResolver {
Ohjintaek marked this conversation as resolved.
Show resolved Hide resolved
Ohjintaek marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import co.kirikiri.domain.goalroom.vo.GoalRoomName;
import co.kirikiri.domain.goalroom.vo.LimitedMemberCount;
import co.kirikiri.domain.member.Member;
import co.kirikiri.domain.roadmap.RoadmapContent;
import co.kirikiri.roadmap.domain.RoadmapContent;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import co.kirikiri.domain.BaseEntity;
import co.kirikiri.domain.goalroom.exception.GoalRoomException;
import co.kirikiri.domain.goalroom.vo.Period;
import co.kirikiri.domain.roadmap.RoadmapNode;
import co.kirikiri.roadmap.domain.RoadmapNode;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package co.kirikiri.persistence.goalroom;

import static co.kirikiri.domain.goalroom.QGoalRoom.goalRoom;
import static co.kirikiri.domain.goalroom.QGoalRoomMember.goalRoomMember;
import static co.kirikiri.domain.member.QMember.member;
import static co.kirikiri.domain.member.QMemberImage.memberImage;
import static co.kirikiri.domain.roadmap.QRoadmapContent.roadmapContent;
import static co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType.ACCOMPLISHMENT_RATE;
import static co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType.JOINED_ASC;

import co.kirikiri.domain.goalroom.GoalRoomMember;
import co.kirikiri.domain.goalroom.GoalRoomStatus;
import co.kirikiri.domain.member.vo.Identifier;
import co.kirikiri.persistence.QuerydslRepositorySupporter;
import co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;

import java.util.List;
import java.util.Optional;

import static co.kirikiri.domain.goalroom.QGoalRoom.goalRoom;
import static co.kirikiri.domain.goalroom.QGoalRoomMember.goalRoomMember;
import static co.kirikiri.domain.member.QMember.member;
import static co.kirikiri.domain.member.QMemberImage.memberImage;
import static co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType.ACCOMPLISHMENT_RATE;
import static co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType.JOINED_ASC;
import static co.kirikiri.roadmap.domain.QRoadmapContent.roadmapContent;

public class GoalRoomMemberQueryRepositoryImpl extends QuerydslRepositorySupporter implements
GoalRoomMemberQueryRepository {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import co.kirikiri.domain.goalroom.GoalRoom;
import co.kirikiri.domain.goalroom.GoalRoomStatus;
import co.kirikiri.domain.member.Member;
import co.kirikiri.domain.roadmap.Roadmap;
import co.kirikiri.roadmap.domain.Roadmap;
import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType;
import java.time.LocalDate;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package co.kirikiri.persistence.goalroom;

import static co.kirikiri.domain.goalroom.QGoalRoom.goalRoom;
import static co.kirikiri.domain.goalroom.QGoalRoomMember.goalRoomMember;
import static co.kirikiri.domain.goalroom.QGoalRoomPendingMember.goalRoomPendingMember;
import static co.kirikiri.domain.goalroom.QGoalRoomRoadmapNode.goalRoomRoadmapNode;
import static co.kirikiri.domain.goalroom.QGoalRoomToDo.goalRoomToDo;
import static co.kirikiri.domain.roadmap.QRoadmapContent.roadmapContent;

import co.kirikiri.domain.goalroom.GoalRoom;
import co.kirikiri.domain.goalroom.GoalRoomStatus;
import co.kirikiri.domain.member.Member;
import co.kirikiri.domain.roadmap.Roadmap;
import co.kirikiri.persistence.QuerydslRepositorySupporter;
import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType;
import co.kirikiri.roadmap.domain.Roadmap;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import jakarta.persistence.LockModeType;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import static co.kirikiri.domain.goalroom.QGoalRoom.goalRoom;
import static co.kirikiri.domain.goalroom.QGoalRoomMember.goalRoomMember;
import static co.kirikiri.domain.goalroom.QGoalRoomPendingMember.goalRoomPendingMember;
import static co.kirikiri.domain.goalroom.QGoalRoomRoadmapNode.goalRoomRoadmapNode;
import static co.kirikiri.domain.goalroom.QGoalRoomToDo.goalRoomToDo;
import static co.kirikiri.roadmap.domain.QRoadmapContent.roadmapContent;

public class GoalRoomQueryRepositoryImpl extends QuerydslRepositorySupporter implements GoalRoomQueryRepository {

private static final int LIMIT_OFFSET = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package co.kirikiri.persistence.goalroom;

import co.kirikiri.domain.goalroom.GoalRoom;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface GoalRoomRepository extends JpaRepository<GoalRoom, Long>, GoalRoomQueryRepository {

Optional<GoalRoom> findById(final Long goalRoomId);

List<GoalRoom> findAllByEndDate(final LocalDate endDate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package co.kirikiri.controller;
package co.kirikiri.roadmap.controller;

import co.kirikiri.common.interceptor.Authenticated;
import co.kirikiri.common.resolver.MemberIdentifier;
import co.kirikiri.roadmap.service.RoadmapCreateService;
import co.kirikiri.roadmap.service.RoadmapReadService;
import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto;
import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest;
import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest;
import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest;
import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest;
import co.kirikiri.roadmap.service.dto.request.RoadmapSearchRequest;
import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses;
import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse;
import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses;
import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses;
import co.kirikiri.roadmap.service.dto.response.RoadmapResponse;
import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse;
import co.kirikiri.service.dto.CustomScrollRequest;
import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto;
import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest;
import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest;
import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest;
import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest;
import co.kirikiri.service.dto.roadmap.request.RoadmapSearchRequest;
import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses;
import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse;
import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses;
import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses;
import co.kirikiri.service.dto.roadmap.response.RoadmapResponse;
import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse;
import co.kirikiri.service.roadmap.RoadmapCreateService;
import co.kirikiri.service.roadmap.RoadmapReadService;
import jakarta.validation.Valid;
import java.net.URI;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -34,6 +32,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/roadmaps")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.BaseCreatedTimeEntity;
import co.kirikiri.domain.member.Member;
import co.kirikiri.domain.roadmap.exception.RoadmapException;
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.BaseEntity;
import co.kirikiri.domain.roadmap.exception.RoadmapException;
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.BaseUpdatedTimeEntity;
import co.kirikiri.domain.roadmap.exception.RoadmapException;
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 클래스는 이제 없어져도 되겠네요!

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

public enum RoadmapDifficulty {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.BaseEntity;
import co.kirikiri.domain.roadmap.exception.RoadmapException;
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.BaseEntity;
import co.kirikiri.domain.ImageContentType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.roadmap.exception.RoadmapException;
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.roadmap.exception.RoadmapException;
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.BaseUpdatedTimeEntity;
import co.kirikiri.domain.member.Member;
import co.kirikiri.domain.roadmap.exception.RoadmapException;
import co.kirikiri.roadmap.domain.exception.RoadmapException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 클래스도 이제 없어져도 될것 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

둘 다 없애버렸습니다 😀

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Embeddable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

public enum RoadmapStatus {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.kirikiri.domain.roadmap;
package co.kirikiri.roadmap.domain;

import co.kirikiri.domain.BaseEntity;
import co.kirikiri.domain.roadmap.vo.RoadmapTagName;
import co.kirikiri.roadmap.domain.vo.RoadmapTagName;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import lombok.AccessLevel;
Expand Down
Loading
Loading