Skip to content

Commit

Permalink
[DEV-28] 커스텀 수강과목 수정 api 분리 생성 삭제 (#249)
Browse files Browse the repository at this point in the history
* refactor: UpdateTakenLectureController update -> generate, delete로 분리

* feat: 수강과목 삭제 UseCase

* feat: 수강과목 삭제 Service

* refactor: 수강과목 삭제 Port id 단건 삭제로 변경

* refactor: 수강과목 삭제 Adapter id 단건 삭제로 변경

* feat: application 레벨 수강 과목 생성 로직 추가

* feat: 수강과목 저장 로직 추가

* feat: 과목 id에 의한 과목 단건 조회

* refactor: UpdateTakenLectureController update -> generate, delete로 분리

* refactor: UpdateTakenLectureController update -> generate, delete로 분리로 인한 파일 삭제

* feat: 수강과목 삭제 로직 추가

* test: spring test container 통합을 위한  test 설정

* test: UpdateTakenLectureController update -> generate, delete로 분리로 test

* refactor: Semester 타입 String으로 설정

* refactor: Controller 메서드명 변경

* refactor: Controller 메서드명 변경

* refactor: path variable 변수명 camel case로 변경

* refactor: parsing으로 인한 수강과목 생성과 구분되도록 customize 명시

* refactor: DeleteTakenLecture UseCase Service 통합
  • Loading branch information
나경호 authored Apr 12, 2024
1 parent 1ebe900 commit 834c517
Show file tree
Hide file tree
Showing 32 changed files with 367 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface FindLecturePort {
List<Lecture> findLecturesByLectureCodes(List<String> lectureCodes);

List<Lecture> findLecturesByIds(List<Long> lectureIds);

Lecture findLectureById(Long lectureId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
import java.util.stream.Collectors;

import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter;
import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort;
import com.plzgraduate.myongjigraduatebe.lecture.application.port.SearchLecturePort;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture;
import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.entity.LectureJpaEntity;
import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.mapper.LectureMapper;
import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureQueryRepository;
import com.plzgraduate.myongjigraduatebe.lecture.infrastructure.adapter.persistence.repository.LectureRepository;
import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort;
import com.plzgraduate.myongjigraduatebe.lecture.application.port.SearchLecturePort;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture;

import lombok.RequiredArgsConstructor;

@PersistenceAdapter
@RequiredArgsConstructor
public class LecturePersistenceAdapter implements FindLecturePort, SearchLecturePort {

private final static String NOT_FOUND_LECTURE_ERROR_MESSAGE = "해당 과목을 찾을 수 없습니다.";
private final LectureQueryRepository lectureQueryRepository;
private final LectureRepository lectureRepository;
private final LectureMapper lectureMapper;
Expand All @@ -38,6 +39,13 @@ public List<Lecture> findLecturesByIds(List<Long> lectureIds) {
.collect(Collectors.toList());
}

@Override
public Lecture findLectureById(final Long lectureId) {
LectureJpaEntity lectureJpaEntity = lectureRepository.findById(lectureId)
.orElseThrow(() -> new IllegalArgumentException(NOT_FOUND_LECTURE_ERROR_MESSAGE));
return lectureMapper.mapToLectureModel(lectureJpaEntity);
}

@Override
public List<Lecture> searchLectureByNameOrCode(String type, String keyword) {
List<LectureJpaEntity> lectureJpaEntities = lectureQueryRepository.searchByNameOrCode(type, keyword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.plzgraduate.myongjigraduatebe.parsing.application.usecase.ParsingTextUseCase;
import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingInformation;
import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingTakenLectureDto;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureByUserUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.save.SaveTakenLectureFromParsingTextUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInformation;
import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase;
Expand All @@ -35,7 +35,7 @@ class ParsingTextService implements ParsingTextUseCase {
private final FindUserUseCase findUserUseCase;
private final UpdateStudentInformationUseCase updateStudentInformationUseCase;
private final SaveTakenLectureFromParsingTextUseCase saveTakenLectureFromParsingTextUseCase;
private final DeleteTakenLectureByUserUseCase deleteTakenLectureByUserUseCase;
private final DeleteTakenLectureUseCase deleteTakenLectureByUserUseCase;

private final GenerateOrModifyCompletedCreditUseCase generateOrModifyCompletedCreditUseCase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import javax.validation.Valid;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser;
import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request.UpdateTakenLectureRequest;
import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request.GenerateCustomizedTakenLectureRequest;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -14,5 +15,11 @@
public interface UpdateTakenLectureApiPresentation {

@Parameter(name = "userId", description = "로그인한 유저의 PK값")
void updateTakenLectures(@LoginUser Long userId, @Valid @RequestBody UpdateTakenLectureRequest updateTakenLectureRequest);
void generateCustomizedTakenLecture(@LoginUser Long userId,
@Valid @RequestBody GenerateCustomizedTakenLectureRequest generateCustomizedTakenLectureRequest);

@Parameter(name = "userId", description = "로그인한 유저의 PK값")
@Parameter(name = "takenLectureId", description = "삭제할 수강 과목 ID")
void deleteCustomizedTakenLecture(@LoginUser Long userId,
@Valid @PathVariable Long takenLectureId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@

import javax.validation.Valid;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser;
import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter;
import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request.UpdateTakenLectureRequest;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.update.UpdateTakenLectureUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request.GenerateCustomizedTakenLectureRequest;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.save.GenerateCustomizedTakenLectureUseCase;

import lombok.RequiredArgsConstructor;

@WebAdapter
@RequestMapping("/api/v1/taken-lectures")
@RequiredArgsConstructor
public class UpdateTakenLectureController implements UpdateTakenLectureApiPresentation {
private final UpdateTakenLectureUseCase updateTakenLectureUseCase;

@PostMapping("/update")
public void updateTakenLectures(@LoginUser Long userId,
@Valid @RequestBody UpdateTakenLectureRequest updateTakenLectureRequest) {
updateTakenLectureUseCase.modifyTakenLecture(userId, updateTakenLectureRequest.getDeletedTakenLectures(),
updateTakenLectureRequest.getAddedTakenLectures());
private final GenerateCustomizedTakenLectureUseCase generateCustomizedTakenLectureUseCase;
private final DeleteTakenLectureUseCase deleteTakenLectureUseCase;

@PostMapping()
public void generateCustomizedTakenLecture(@LoginUser Long userId,
@Valid @RequestBody GenerateCustomizedTakenLectureRequest generateCustomizedTakenLectureRequest) {
generateCustomizedTakenLectureUseCase.generateCustomizedTakenLecture(userId,
generateCustomizedTakenLectureRequest.getLectureId());
}

@DeleteMapping("{takenLectureId}")
public void deleteCustomizedTakenLecture(@LoginUser Long userId,
@Valid @PathVariable Long takenLectureId) {
deleteTakenLectureUseCase.deleteTakenLecture(userId, takenLectureId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.plzgraduate.myongjigraduatebe.takenlecture.api.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class GenerateCustomizedTakenLectureRequest {

@Schema(name = "lectureId", example = "103")
private Long lectureId;

@Builder
private GenerateCustomizedTakenLectureRequest(Long lectureId) {
this.lectureId = lectureId;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
public interface DeleteTakenLecturePort {
void deleteAllTakenLecturesByUser(User user);

void deleteTakenLecturesByIds(List<Long> deleteIds);
void deleteTakenLectureById(Long deleteId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
public interface SaveTakenLecturePort {

void saveTakenLectures(List<TakenLecture> takenLectures);

void saveTakenLecture(TakenLecture takenLecture);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.delete;

import org.springframework.transaction.annotation.Transactional;

import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase;
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.DeleteTakenLecturePort;
import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import lombok.RequiredArgsConstructor;

@UseCase
@Transactional
@RequiredArgsConstructor
class DeleteTakenLectureService implements DeleteTakenLectureUseCase {

private final FindUserUseCase findUserUseCase;
private final DeleteTakenLecturePort deleteTakenLecturePort;
private final GenerateOrModifyCompletedCreditUseCase generateOrModifyCompletedCreditUseCase;

@Override
public void deleteAllTakenLecturesByUser(User user) {
deleteTakenLecturePort.deleteAllTakenLecturesByUser(user);
}

@Override
public void deleteTakenLecture(Long userId, Long deletedTakenLectureId) {
User user = findUserUseCase.findUserById(userId);
deleteTakenLecturePort.deleteTakenLectureById(deletedTakenLectureId);
generateOrModifyCompletedCreditUseCase.generateOrModifyCompletedCredit(user);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.plzgraduate.myongjigraduatebe.takenlecture.application.service.save;

import org.springframework.transaction.annotation.Transactional;

import com.plzgraduate.myongjigraduatebe.completedcredit.application.usecase.GenerateOrModifyCompletedCreditUseCase;
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase;
import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindLecturePort;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.port.SaveTakenLecturePort;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.save.GenerateCustomizedTakenLectureUseCase;
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture;
import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import lombok.RequiredArgsConstructor;

@UseCase
@Transactional
@RequiredArgsConstructor
public class GenerateCustomizedTakenLectureService implements GenerateCustomizedTakenLectureUseCase {

private final FindUserUseCase findUserUseCase;
private final FindLecturePort findLecturePort;
private final SaveTakenLecturePort saveTakenLecturePort;
private final GenerateOrModifyCompletedCreditUseCase generateOrModifyCompletedCreditUseCase;

@Override
public void generateCustomizedTakenLecture(final Long userId, final Long addedTakenLectureId) {
User user = findUserUseCase.findUserById(userId);
Lecture lecture = findLecturePort.findLectureById(addedTakenLectureId);
addCustomTakenLecture(user, lecture);
generateOrModifyCompletedCreditUseCase.generateOrModifyCompletedCredit(user);
}

private void addCustomTakenLecture(User user, Lecture addedLecture) {
TakenLecture addedTakenLecture = TakenLecture.custom(user, addedLecture);
saveTakenLecturePort.saveTakenLecture(addedTakenLecture);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

public interface DeleteTakenLectureByUserUseCase {
public interface DeleteTakenLectureUseCase {
void deleteAllTakenLecturesByUser(User user);

void deleteTakenLecture(Long userId, Long deletedTakenLectureId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.save;


public interface GenerateCustomizedTakenLectureUseCase {
void generateCustomizedTakenLecture(Long userId, Long addedTakenLectureId);
}

This file was deleted.

Loading

0 comments on commit 834c517

Please sign in to comment.