-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 사장님 자신의 모든 상점 조회 #183
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
497bff1
feat: 도메인 엔티티 생성
songsunkook 169e87f
feat: 응답 객체 초안 작성
songsunkook defb275
feat: 도메인 클래스 작성
songsunkook 26f478e
feat: API 작성
songsunkook 1701234
test: 테스트 작성
songsunkook 40d685b
feat: API 작성
songsunkook 54e25cb
test: 테스트 작성
songsunkook 84c995c
refactor: 트랜잭션 적용
songsunkook 2a9403a
docs: 응답 객체 문서 주석 추가
songsunkook da163f9
merge: develop 브랜치 변경사항 반영
songsunkook f0d7bd8
fix: 버그 수정
songsunkook 46d0759
refactor: 읽기 전용 트랜잭션으로 수정
songsunkook 6cabbdc
refactor: 개행 컨벤션 준수
songsunkook 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
36 changes: 36 additions & 0 deletions
36
src/main/java/in/koreatech/koin/domain/ownershop/controller/OwnerShopApi.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,36 @@ | ||
| package in.koreatech.koin.domain.ownershop.controller; | ||
|
|
||
| import static in.koreatech.koin.domain.user.model.UserType.OWNER; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
||
| import in.koreatech.koin.domain.ownershop.dto.OwnerShopsResponse; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| 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.security.SecurityRequirement; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
|
||
| @Tag(name = "(Normal) Owner Shop: 상점 (점주 전용)", description = "사장님이 상점 정보를 관리한다.") | ||
| public interface OwnerShopApi { | ||
|
|
||
| @ApiResponses( | ||
| value = { | ||
| @ApiResponse(responseCode = "200"), | ||
| @ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))), | ||
| } | ||
| ) | ||
| @Operation(summary = "자신의 모든 상점 조회") | ||
| @SecurityRequirement(name = "Jwt Authentication") | ||
| @GetMapping("/owner/shops") | ||
| ResponseEntity<OwnerShopsResponse> getOwnerShops( | ||
| @Auth(permit = {OWNER}) Long userId | ||
| ); | ||
|
|
||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/in/koreatech/koin/domain/ownershop/controller/OwnerShopContoller.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,26 @@ | ||
| package in.koreatech.koin.domain.ownershop.controller; | ||
|
|
||
| import static in.koreatech.koin.domain.user.model.UserType.OWNER; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.stereotype.Controller; | ||
|
|
||
| import in.koreatech.koin.domain.ownershop.dto.OwnerShopsResponse; | ||
| import in.koreatech.koin.domain.ownershop.service.OwnerShopService; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Controller | ||
| @RequiredArgsConstructor | ||
| public class OwnerShopContoller implements OwnerShopApi { | ||
|
|
||
| private final OwnerShopService ownerShopService; | ||
|
|
||
| @Override | ||
| public ResponseEntity<OwnerShopsResponse> getOwnerShops( | ||
| @Auth(permit = {OWNER}) Long ownerId | ||
| ) { | ||
| OwnerShopsResponse ownerShopsResponses = ownerShopService.getOwnerShops(ownerId); | ||
| return ResponseEntity.ok().body(ownerShopsResponses); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/main/java/in/koreatech/koin/domain/ownershop/dto/OwnerShopsResponse.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,30 @@ | ||
| package in.koreatech.koin.domain.ownershop.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import in.koreatech.koin.domain.shop.model.Shop; | ||
|
|
||
| public record OwnerShopsResponse( | ||
| Long count, | ||
| List<InnerShopResponse> shops | ||
| ) { | ||
|
|
||
| public static OwnerShopsResponse from(List<Shop> shops) { | ||
| return new OwnerShopsResponse( | ||
| (long)shops.size(), | ||
| shops.stream() | ||
| .map(InnerShopResponse::from) | ||
| .toList() | ||
| ); | ||
| } | ||
|
|
||
| private record InnerShopResponse( | ||
| Long id, | ||
| String name | ||
| ) { | ||
|
|
||
| public static InnerShopResponse from(Shop shop) { | ||
| return new InnerShopResponse(shop.getId(), shop.getName()); | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/in/koreatech/koin/domain/ownershop/service/OwnerShopService.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,24 @@ | ||
| package in.koreatech.koin.domain.ownershop.service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import in.koreatech.koin.domain.ownershop.dto.OwnerShopsResponse; | ||
| import in.koreatech.koin.domain.shop.model.Shop; | ||
| import in.koreatech.koin.domain.shop.repository.ShopRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class OwnerShopService { | ||
|
|
||
| private final ShopRepository shopRepository; | ||
|
|
||
| public OwnerShopsResponse getOwnerShops(Long ownerId) { | ||
| List<Shop> shops = shopRepository.findAllByOwnerId(ownerId); | ||
| return OwnerShopsResponse.from(shops); | ||
| } | ||
| } |
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
130 changes: 130 additions & 0 deletions
130
src/test/java/in/koreatech/koin/acceptance/OwnerShopApiTest.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,130 @@ | ||
| package in.koreatech.koin.acceptance; | ||
|
|
||
| import static in.koreatech.koin.domain.user.model.UserType.OWNER; | ||
| import static org.assertj.core.api.SoftAssertions.assertSoftly; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import in.koreatech.koin.AcceptanceTest; | ||
| import in.koreatech.koin.domain.owner.domain.Owner; | ||
| import in.koreatech.koin.domain.owner.repository.OwnerRepository; | ||
| import in.koreatech.koin.domain.shop.model.Shop; | ||
| import in.koreatech.koin.domain.shop.repository.ShopRepository; | ||
| import in.koreatech.koin.domain.user.model.User; | ||
| import in.koreatech.koin.domain.user.model.UserGender; | ||
| import in.koreatech.koin.global.auth.JwtProvider; | ||
| import io.restassured.RestAssured; | ||
| import io.restassured.response.ExtractableResponse; | ||
| import io.restassured.response.Response; | ||
|
|
||
| class OwnerShopApiTest extends AcceptanceTest { | ||
|
|
||
| @Autowired | ||
| private OwnerRepository ownerRepository; | ||
|
|
||
| @Autowired | ||
| private ShopRepository shopRepository; | ||
|
|
||
| @Autowired | ||
| private JwtProvider jwtProvider; | ||
|
|
||
| private Owner owner; | ||
| private Shop shop; | ||
| private String token; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| Owner ownerRequest = Owner.builder() | ||
| .companyRegistrationNumber("123-45-67890") | ||
| .companyRegistrationCertificateImageUrl("https://test.com/test.jpg") | ||
| .grantShop(true) | ||
| .grantEvent(true) | ||
| .user( | ||
| User.builder() | ||
| .password("1234") | ||
| .nickname("주노") | ||
| .name("최준호") | ||
| .phoneNumber("010-1234-5678") | ||
| .userType(OWNER) | ||
| .gender(UserGender.MAN) | ||
| .email("test@koreatech.ac.kr") | ||
| .isAuthed(true) | ||
| .isDeleted(false) | ||
| .build() | ||
| ) | ||
| .build(); | ||
| owner = ownerRepository.save(ownerRequest); | ||
| token = jwtProvider.createToken(owner.getUser()); | ||
|
|
||
| Shop shopRequest = Shop.builder() | ||
| .owner(owner) | ||
| .name("테스트 상점") | ||
| .internalName("테스트") | ||
| .chosung("테스트") | ||
| .phone("010-1234-5678") | ||
| .address("대전광역시 유성구 대학로 291") | ||
| .description("테스트 상점입니다.") | ||
| .delivery(true) | ||
| .deliveryPrice(3000L) | ||
| .payCard(true) | ||
| .payBank(true) | ||
| .isDeleted(false) | ||
| .isEvent(false) | ||
| .remarks("비고") | ||
| .hit(0L) | ||
| .build(); | ||
| shop = shopRepository.save(shopRequest); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("사장님의 가게 목록을 조회한다.") | ||
| void getOwnerShops() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A테스트 굿 |
||
| // given | ||
| final int SHOP_COUNT = 2; | ||
|
|
||
| Shop shopRequest = Shop.builder() | ||
| .owner(owner) | ||
| .name("테스트 상점2") | ||
| .internalName("테스트") | ||
| .chosung("테스트") | ||
| .phone("010-1234-5678") | ||
| .address("대전광역시 유성구 대학로 291") | ||
| .description("테스트 상점2입니다.") | ||
| .delivery(true) | ||
| .deliveryPrice(4000L) | ||
| .payCard(true) | ||
| .payBank(true) | ||
| .isDeleted(false) | ||
| .isEvent(false) | ||
| .remarks("비고2") | ||
| .hit(10L) | ||
| .build(); | ||
| Shop shop2 = shopRepository.save(shopRequest); | ||
|
|
||
| // when then | ||
| ExtractableResponse<Response> response = RestAssured | ||
| .given() | ||
| .header("Authorization", "Bearer " + token) | ||
| .when() | ||
| .get("/owner/shops") | ||
| .then() | ||
| .log().all() | ||
| .statusCode(HttpStatus.OK.value()) | ||
| .extract(); | ||
|
|
||
| assertSoftly( | ||
| softly -> { | ||
| softly.assertThat(response.body().jsonPath().getLong("count")).isEqualTo(SHOP_COUNT); | ||
| softly.assertThat(response.body().jsonPath().getList("shops").size()).isEqualTo(SHOP_COUNT); | ||
| softly.assertThat(response.body().jsonPath().getLong("shops[0].id")).isEqualTo(shop.getId()); | ||
| softly.assertThat(response.body().jsonPath().getString("shops[0].name")).isEqualTo(shop.getName()); | ||
| softly.assertThat(response.body().jsonPath().getLong("shops[1].id")).isEqualTo(shop2.getId()); | ||
| softly.assertThat(response.body().jsonPath().getString("shops[1].name")).isEqualTo(shop2.getName()); | ||
| } | ||
| ); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
이전 PR 반영사항 잘 확인해주셨네요 👍