-
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.
* feat: 과목 정보 검색 기능 구현 * test: lecture test code * test: lecture adaptor test * refactor: remove code smells * refactor: response body key 설정 * refactor: remove code smells
- Loading branch information
Showing
35 changed files
with
564 additions
and
38 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
32 changes: 32 additions & 0 deletions
32
...ava/com/plzgraduate/myongjigraduatebe/lecture/adapter/in/web/SearchLectureController.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,32 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.adapter.in.web; | ||
|
||
import javax.validation.constraints.Size; | ||
|
||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search.SearchLectureCommand; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search.SearchLectureResponse; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search.SearchLectureUseCase; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@WebAdapter | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/lectures") | ||
@Validated | ||
class SearchLectureController { | ||
|
||
private final SearchLectureUseCase searchLectureUseCase; | ||
|
||
@GetMapping | ||
public SearchLectureResponse searchLecture( | ||
@RequestParam(defaultValue = "name") String type, | ||
@RequestParam @Size(min = 2, message = "검색어를 2자리 이상 입력해주세요.") String keyword | ||
) { | ||
return searchLectureUseCase.searchLectures(SearchLectureCommand.toCommand(type, keyword)); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...in/java/com/plzgraduate/myongjigraduatebe/lecture/adapter/out/LectureQueryRepository.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,31 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.adapter.out; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
class LectureQueryRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
private static final QLectureJpaEntity lecture = QLectureJpaEntity.lectureJpaEntity; | ||
|
||
public List<LectureJpaEntity> searchByNameOrCode(String type, String keyword) { | ||
return jpaQueryFactory.selectFrom(lecture) | ||
.where(equalsType(type, keyword)) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression equalsType(String type, String keyword) { | ||
if (type.equals("code")) { | ||
return lecture.lectureCode.contains(keyword); | ||
} | ||
return lecture.name.contains(keyword); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tion/port/in/FindLecturesByIdUseCase.java → ...port/in/find/FindLecturesByIdUseCase.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
2 changes: 1 addition & 1 deletion
2
.../in/FindLecturesByLectureCodeUseCase.java → ...ind/FindLecturesByLectureCodeUseCase.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
35 changes: 35 additions & 0 deletions
35
...com/plzgraduate/myongjigraduatebe/lecture/application/port/in/search/LectureResponse.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,35 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search; | ||
|
||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
public class LectureResponse { | ||
private final Long id; | ||
private final String lectureCode; | ||
private final String name; | ||
private final int credit; | ||
private final boolean isRevoked; | ||
|
||
@Builder | ||
private LectureResponse(Long id, String lectureCode, String name, int credit, boolean isRevoked) { | ||
this.id = id; | ||
this.lectureCode = lectureCode; | ||
this.name = name; | ||
this.credit = credit; | ||
this.isRevoked = isRevoked; | ||
} | ||
|
||
public static LectureResponse of(Lecture lecture) { | ||
return LectureResponse.builder() | ||
.id(lecture.getId()) | ||
.lectureCode(lecture.getLectureCode()) | ||
.name(lecture.getName()) | ||
.credit(lecture.getCredit()) | ||
.isRevoked(lecture.getIsRevoked() == 0) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...lzgraduate/myongjigraduatebe/lecture/application/port/in/search/SearchLectureCommand.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,24 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SearchLectureCommand { | ||
private final String type; | ||
private final String keyword; | ||
|
||
@Builder | ||
private SearchLectureCommand(String type, String keyword) { | ||
this.type = type; | ||
this.keyword = keyword; | ||
} | ||
|
||
public static SearchLectureCommand toCommand(String type, String keyword) { | ||
return SearchLectureCommand.builder() | ||
.type(type) | ||
.keyword(keyword) | ||
.build(); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...zgraduate/myongjigraduatebe/lecture/application/port/in/search/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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class SearchLectureResponse { | ||
private List<LectureResponse> lectures; | ||
|
||
@Builder | ||
private SearchLectureResponse(List<LectureResponse> lectures) { | ||
this.lectures = lectures; | ||
} | ||
|
||
public static SearchLectureResponse from(List<LectureResponse> lectures) { | ||
return SearchLectureResponse.builder() | ||
.lectures(lectures) | ||
.build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...lzgraduate/myongjigraduatebe/lecture/application/port/in/search/SearchLectureUseCase.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,5 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search; | ||
|
||
public interface SearchLectureUseCase { | ||
SearchLectureResponse searchLectures(SearchLectureCommand searchLectureCommand); | ||
} |
9 changes: 9 additions & 0 deletions
9
...ava/com/plzgraduate/myongjigraduatebe/lecture/application/port/out/SearchLecturePort.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,9 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.port.out; | ||
|
||
import java.util.List; | ||
|
||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; | ||
|
||
public interface SearchLecturePort { | ||
List<Lecture> searchLectureByNameOrCode(String type, String keyword); | ||
} |
4 changes: 2 additions & 2 deletions
4
...tion/service/FindLecturesByIdService.java → ...service/find/FindLecturesByIdService.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
4 changes: 2 additions & 2 deletions
4
...ice/FindLecturesByLectureCodeService.java → ...ind/FindLecturesByLectureCodeService.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
27 changes: 27 additions & 0 deletions
27
...lzgraduate/myongjigraduatebe/lecture/application/service/search/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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.application.service.search; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search.SearchLectureCommand; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search.LectureResponse; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search.SearchLectureResponse; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.in.search.SearchLectureUseCase; | ||
import com.plzgraduate.myongjigraduatebe.lecture.application.port.out.SearchLecturePort; | ||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class SearchLectureService implements SearchLectureUseCase { | ||
|
||
private final SearchLecturePort searchLecturePort; | ||
@Override | ||
public SearchLectureResponse searchLectures(SearchLectureCommand searchLectureCommand) { | ||
List<Lecture> lectures = searchLecturePort.searchLectureByNameOrCode( | ||
searchLectureCommand.getType(), searchLectureCommand.getKeyword()); | ||
return SearchLectureResponse.from(lectures.stream().map(LectureResponse::of).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
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
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ spring: | |
|
||
jpa: | ||
hibernate: | ||
ddl-auto: create | ||
ddl-auto: update | ||
properties: | ||
hibernate: | ||
show_sql: true | ||
|
Oops, something went wrong.