-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: SearchLectureUseCase - return 값 수정(추가 여부 필드를 포함한 Dto) * refactor: SearchLectureController - response spec 수정 * refactor: response 수정
- Loading branch information
Showing
8 changed files
with
121 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 29 additions & 11 deletions
40
...ava/com/plzgraduate/myongjigraduatebe/lecture/api/dto/response/SearchLectureResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.api.dto.response; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class SearchLectureResponse { | ||
|
||
private List<LectureResponse> lectures; | ||
@Schema(name = "id", example = "18") | ||
private final Long id; | ||
@Schema(name = "lectureCode", example = "KMA02137") | ||
private final String lectureCode; | ||
@Schema(name = "name", example = "4차산업혁명시대의진로선택") | ||
private final String name; | ||
@Schema(name = "credit", example = "2") | ||
private final int credit; | ||
@Schema(name = "isRevoked", example = "false") | ||
private final boolean revoked; | ||
@Schema(name = "isAddable", example = "true") | ||
private final boolean taken; | ||
|
||
@Builder | ||
private SearchLectureResponse(List<LectureResponse> lectures) { | ||
this.lectures = lectures; | ||
private SearchLectureResponse(Long id, String lectureCode, String name, int credit, boolean revoked, | ||
boolean taken) { | ||
this.id = id; | ||
this.lectureCode = lectureCode; | ||
this.name = name; | ||
this.credit = credit; | ||
this.revoked = revoked; | ||
this.taken = taken; | ||
} | ||
|
||
public static SearchLectureResponse from(List<Lecture> lectures) { | ||
public static SearchLectureResponse from(SearchedLectureDto searchedLectureDto) { | ||
return SearchLectureResponse.builder() | ||
.lectures(lectures.stream().map(LectureResponse::of).collect(Collectors.toList())) | ||
.id(searchedLectureDto.getLecture().getId()) | ||
.lectureCode(searchedLectureDto.getLecture().getLectureCode()) | ||
.name(searchedLectureDto.getLecture().getName()) | ||
.credit(searchedLectureDto.getLecture().getCredit()) | ||
.revoked(searchedLectureDto.getLecture().getIsRevoked() != 0) | ||
.taken(searchedLectureDto.isAddable()) | ||
.build(); | ||
} | ||
} |
23 changes: 21 additions & 2 deletions
23
...a/com/plzgraduate/myongjigraduatebe/lecture/application/service/SearchLectureService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.SearchLecturePort; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.SearchLectureUseCase; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto.SearchedLectureDto; | ||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; | ||
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; | ||
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; | ||
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@UseCase | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class SearchLectureService implements SearchLectureUseCase { | ||
|
||
private final SearchLecturePort searchLecturePort; | ||
private final FindTakenLectureUseCase findTakenLectureUseCase; | ||
|
||
@Override | ||
public List<Lecture> searchLectures(String type, String keyword) { | ||
return searchLecturePort.searchLectureByNameOrCode(type, keyword); | ||
public List<SearchedLectureDto> searchLectures(Long userId, String type, String keyword) { | ||
List<Lecture> searchedLectures = searchLecturePort.searchLectureByNameOrCode(type, keyword); | ||
TakenLectureInventory takenLectureInventory = findTakenLectureUseCase.findTakenLectures(userId); | ||
|
||
List<Lecture> takenLectures = takenLectureInventory.getTakenLectures().stream() | ||
.map(TakenLecture::getLecture) | ||
.collect(Collectors.toList()); | ||
|
||
return searchedLectures.stream() | ||
.map(searchedLecture -> SearchedLectureDto.of(takenLectures.contains(searchedLecture), | ||
searchedLecture)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...com/plzgraduate/myongjigraduatebe/lecture/application/usecase/dto/SearchedLectureDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.usecase.dto; | ||
|
||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SearchedLectureDto { | ||
|
||
private final boolean addable; | ||
private final Lecture lecture; | ||
|
||
@Builder | ||
private SearchedLectureDto(boolean addable, Lecture lecture) { | ||
this.addable = addable; | ||
this.lecture = lecture; | ||
} | ||
|
||
public static SearchedLectureDto of(boolean addable, Lecture lecture) { | ||
return SearchedLectureDto.builder() | ||
.addable(addable) | ||
.lecture(lecture).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters