-
Notifications
You must be signed in to change notification settings - Fork 2
♻️ [refactor] - 상세 주소를 위해 Region 엔티티를 리팩토링한다 #64
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
48f6ccc
[refactor] #61 region Entity refactoring
oOccasio ef1d71d
[feat] #61 add sql file and flyway
oOccasio 2d384e9
[refactor] #61 region queryService and Auth logic refactoring
oOccasio beb4c88
[fix] #61 annoatation fix and parameter binding
oOccasio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
92 changes: 92 additions & 0 deletions
92
src/main/java/com/example/dgu/returnwork/domain/region/controller/RegionApi.java
This file contains hidden or 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,92 @@ | ||
| package com.example.dgu.returnwork.domain.region.controller; | ||
|
|
||
| import com.example.dgu.returnwork.domain.region.dto.response.SearchRegionDto; | ||
| import com.example.dgu.returnwork.global.dto.PageResponseDto; | ||
| import com.example.dgu.returnwork.global.exception.CustomErrorResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| @Tag(name = "Region", description = "지역 검색 API") | ||
| public interface RegionApi { | ||
|
|
||
| @Operation( | ||
| summary = "지역 검색", | ||
| description = """ | ||
| 키워드로 지역을 검색하는 API입니다. | ||
| - 시/도, 시/군/구, 동/리 등 모든 주소 레벨에서 검색 가능 | ||
| - 대소문자 구분 없이 검색 | ||
| - 부분 검색 지원 (예: "서울", "종로", "청운동" 모두 검색 가능) | ||
| """ | ||
| ) | ||
| @ApiResponses({ | ||
| @ApiResponse( | ||
| responseCode = "200", | ||
| description = "지역 검색 성공", | ||
| content = @Content( | ||
| mediaType = "application/json", | ||
| schema = @Schema(implementation = com.example.dgu.returnwork.global.response.ApiResponse.class), | ||
| examples = @ExampleObject( | ||
| name = "성공 응답", | ||
| value = """ | ||
| { | ||
| "errorCode": null, | ||
| "message": "OK", | ||
| "result": { | ||
| "content": [ | ||
| { | ||
| "id": 1, | ||
| "fullAddress": "서울특별시 종로구 청운동" | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "fullAddress": "서울특별시 종로구 신교동" | ||
| } | ||
| ], | ||
| "currentPage": 0, | ||
| "totalPage": 5, | ||
| "totalElements": 45, | ||
| "hasNext": true | ||
| } | ||
| } | ||
| """ | ||
| ) | ||
| ) | ||
| ), | ||
| @ApiResponse( | ||
| responseCode = "400", | ||
| description = "잘못된 요청", | ||
| content = @Content( | ||
| mediaType = "application/json", | ||
| schema = @Schema(implementation = CustomErrorResponse.class), | ||
| examples = @ExampleObject( | ||
| name = "검증 실패", | ||
| summary = "검색 키워드가 비어있는 경우", | ||
| value = """ | ||
| { | ||
| "status": 400, | ||
| "errorCode": "COMMON_002", | ||
| "message": "입력값 검증에 실패했습니다" | ||
| } | ||
| """ | ||
| ) | ||
| ) | ||
| ) | ||
| }) | ||
| PageResponseDto<SearchRegionDto> searchRegion( | ||
| @Parameter( | ||
| description = "검색할 지역 키워드 (시/도, 시/군/구, 동/리 등)", | ||
| example = "서울" | ||
| ) | ||
| @RequestParam String searchKeyword, | ||
|
|
||
| @RequestParam(defaultValue = "0") Integer page | ||
| ); | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/dgu/returnwork/domain/region/controller/RegionController.java
This file contains hidden or 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,23 @@ | ||
| package com.example.dgu.returnwork.domain.region.controller; | ||
|
|
||
| import com.example.dgu.returnwork.domain.region.dto.response.SearchRegionDto; | ||
| import com.example.dgu.returnwork.domain.region.service.RegionQueryService; | ||
| import com.example.dgu.returnwork.global.dto.PageResponseDto; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/regions") | ||
| public class RegionController implements RegionApi { | ||
|
|
||
| private final RegionQueryService regionQueryService; | ||
|
|
||
| @Override | ||
| @GetMapping | ||
| public PageResponseDto<SearchRegionDto> searchRegion (@RequestParam String searchKeyword, | ||
| @RequestParam(defaultValue = "0") Integer page) { | ||
| return regionQueryService.searchRegion(searchKeyword, page); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/dgu/returnwork/domain/region/dto/response/SearchRegionDto.java
This file contains hidden or 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,13 @@ | ||
| package com.example.dgu.returnwork.domain.region.dto.response; | ||
|
|
||
| import com.example.dgu.returnwork.domain.region.Region; | ||
|
|
||
| public record SearchRegionDto( | ||
| Long id, | ||
|
|
||
| String fullAddress | ||
| ) { | ||
| public static SearchRegionDto from(Region region) { | ||
| return new SearchRegionDto(region.getId(), region.getFullAddress()); | ||
| } | ||
| } |
7 changes: 6 additions & 1 deletion
7
src/main/java/com/example/dgu/returnwork/domain/region/repository/RegionRepository.java
This file contains hidden or 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,10 +1,15 @@ | ||
| package com.example.dgu.returnwork.domain.region.repository; | ||
|
|
||
| import com.example.dgu.returnwork.domain.region.Region; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface RegionRepository extends JpaRepository<Region, Long> { | ||
| Optional<Region> findByName(String name); | ||
| @Query("SELECT r FROM Region r WHERE LOWER(r.searchKeywords) LIKE LOWER(CONCAT('%', :keyword, '%'))") | ||
| Page<Region> searchByKeywordIgnoreCase(@Param("keyword") String keyword, Pageable pageable); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
src/main/java/com/example/dgu/returnwork/global/dto/PageResponseDto.java
This file contains hidden or 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.example.dgu.returnwork.global.dto; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record PageResponseDto<T>( | ||
| List<T> content, | ||
|
|
||
| int currentPage, | ||
|
|
||
| int totalPage, | ||
|
|
||
| long totalElements, | ||
|
|
||
| boolean hasNext | ||
| ) { | ||
| public static <T> PageResponseDto<T> from(Page<T> page) { | ||
| return new PageResponseDto<>( | ||
| page.getContent(), | ||
| page.getNumber(), | ||
| page.getTotalPages(), | ||
| page.getTotalElements(), | ||
| page.hasNext() | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.