-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 사장님 정보 조회 #182
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
feat: 사장님 정보 조회 #182
Changes from all commits
Commits
Show all changes
17 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 b0bb124
refactor: 접근제어자 수정
songsunkook 3117d13
docs: 응답 객체 문서 주석 추가
songsunkook bf75f6a
refactor: 트랜잭션 추가
songsunkook 042b2de
refactor: 예외처리 보완
songsunkook 9789744
refactor: 양방향 연관관계 제거
songsunkook b42374c
refactor: 잘못 기입된 Setter 제거
songsunkook 77350aa
refactor: 기본생성자 접근제어 추가
songsunkook 6c503c7
refactor: 소프트딜리트된 대상은 제외
songsunkook 8e4e4a6
refactor: 기본생성자 접근제어 추가
songsunkook d67e4ad
style: 컨벤션 준수
songsunkook 020b2c3
Merge branch 'develop' into feature/116-get-owner
songsunkook edf1a7d
rename: 메서드명 변경
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
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
35 changes: 35 additions & 0 deletions
35
src/main/java/in/koreatech/koin/domain/owner/controller/OwnerApi.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,35 @@ | ||
| package in.koreatech.koin.domain.owner.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.owner.dto.OwnerResponse; | ||
| 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: 사장님", description = "사장님 정보를 관리한다.") | ||
| public interface OwnerApi { | ||
|
|
||
| @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") | ||
| ResponseEntity<OwnerResponse> getOwner( | ||
| @Auth(permit = {OWNER}) Long userId | ||
| ); | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/in/koreatech/koin/domain/owner/controller/OwnerController.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.owner.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.owner.dto.OwnerResponse; | ||
| import in.koreatech.koin.domain.owner.service.OwnerService; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Controller | ||
| @RequiredArgsConstructor | ||
| public class OwnerController implements OwnerApi { | ||
|
|
||
| private final OwnerService ownerService; | ||
|
|
||
| @Override | ||
| public ResponseEntity<OwnerResponse> getOwner( | ||
| @Auth(permit = {OWNER}) Long ownerId | ||
| ) { | ||
| OwnerResponse ownerInfo = ownerService.getOwner(ownerId); | ||
| return ResponseEntity.ok().body(ownerInfo); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/main/java/in/koreatech/koin/domain/owner/domain/Owner.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,58 @@ | ||
| package in.koreatech.koin.domain.owner.domain; | ||
|
|
||
| import in.koreatech.koin.domain.user.model.User; | ||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.MapsId; | ||
| import jakarta.persistence.OneToOne; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Entity | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(name = "owners") | ||
| public class Owner { | ||
|
|
||
| @Id | ||
| @Column(name = "user_id", nullable = false) | ||
| private Long id; | ||
|
|
||
| @MapsId | ||
| @OneToOne(cascade = CascadeType.ALL) | ||
| @JoinColumn(name = "user_id", referencedColumnName = "id") | ||
| private User user; | ||
|
|
||
| @Size(max = 12) | ||
| @NotNull | ||
| @Column(name = "company_registration_number", nullable = false, length = 12) | ||
| private String companyRegistrationNumber; | ||
|
|
||
| @Size(max = 255) | ||
| @Column(name = "company_registration_certificate_image_url") | ||
| private String companyRegistrationCertificateImageUrl; | ||
|
|
||
| @Column(name = "grant_shop") | ||
| private Boolean grantShop; | ||
|
|
||
| @Column(name = "grant_event") | ||
| private Boolean grantEvent; | ||
|
|
||
| @Builder | ||
| public Owner(User user, String companyRegistrationNumber, | ||
| String companyRegistrationCertificateImageUrl, Boolean grantShop, Boolean grantEvent) { | ||
| this.user = user; | ||
| this.companyRegistrationNumber = companyRegistrationNumber; | ||
| this.companyRegistrationCertificateImageUrl = companyRegistrationCertificateImageUrl; | ||
| this.grantShop = grantShop; | ||
| this.grantEvent = grantEvent; | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
src/main/java/in/koreatech/koin/domain/owner/domain/OwnerAttachment.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,76 @@ | ||
| package in.koreatech.koin.domain.owner.domain; | ||
|
|
||
| import org.hibernate.annotations.Where; | ||
|
|
||
| import in.koreatech.koin.domain.owner.exception.AttachmentNotFoundException; | ||
| import in.koreatech.koin.global.common.BaseEntity; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.Lob; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.PostLoad; | ||
| import jakarta.persistence.PostPersist; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.persistence.Transient; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Entity | ||
| @Where(clause = "is_deleted=0") | ||
| @Table(name = "owner_attachments") | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class OwnerAttachment extends BaseEntity { | ||
|
|
||
| private static final String NAME_SEPARATOR = "/"; | ||
| private static final int NOT_FOUND_IDX = -1; | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "id", nullable = false) | ||
| private Long id; | ||
|
|
||
| @NotNull | ||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
| @JoinColumn(name = "owner_id", nullable = false, referencedColumnName = "user_id") | ||
| private Owner owner; | ||
|
|
||
| @NotNull | ||
| @Lob | ||
| @Column(name = "url", nullable = false) | ||
| private String url; | ||
|
|
||
| @NotNull | ||
| @Column(name = "is_deleted", nullable = false) | ||
| private Boolean isDeleted = false; | ||
|
|
||
| @Transient | ||
| private String name; | ||
|
|
||
| @PostPersist | ||
| @PostLoad | ||
| public void updateName() { | ||
| int separateIndex = url.lastIndexOf(NAME_SEPARATOR); | ||
| if (separateIndex == NOT_FOUND_IDX) { | ||
| throw AttachmentNotFoundException.withDetail("코인 파일 저장 형식(static.koreatech.in)이 아닙니다. url: " + url); | ||
| } | ||
|
|
||
| name = url.substring(separateIndex + NAME_SEPARATOR.length()); | ||
| } | ||
|
|
||
| @Builder | ||
| public OwnerAttachment(Owner owner, String url, Boolean isDeleted, String name) { | ||
| this.owner = owner; | ||
| this.url = url; | ||
| this.isDeleted = isDeleted; | ||
| this.name = name; | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
src/main/java/in/koreatech/koin/domain/owner/dto/OwnerResponse.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,81 @@ | ||
| package in.koreatech.koin.domain.owner.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
|
||
| import in.koreatech.koin.domain.owner.domain.Owner; | ||
| import in.koreatech.koin.domain.owner.domain.OwnerAttachment; | ||
| import in.koreatech.koin.domain.shop.model.Shop; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record OwnerResponse( | ||
| @Schema(description = "이메일", example = "example@gmail.com") | ||
| String email, | ||
|
|
||
| @Schema(description = "이름", example = "홍길동") | ||
| String name, | ||
|
|
||
| @Schema(description = "사업자 등록 번호", example = "123-45-67890") | ||
| String company_number, | ||
|
|
||
| @Schema(description = "첨부 파일 목록") | ||
| List<InnerAttachmentResponse> attachments, | ||
|
|
||
| @Schema(description = "가게 목록") | ||
| List<InnerShopResponse> shops | ||
| ) { | ||
|
|
||
| public static OwnerResponse of(Owner owner, List<OwnerAttachment> attachments, List<Shop> shops) { | ||
| return new OwnerResponse( | ||
| owner.getUser().getEmail(), | ||
| owner.getUser().getName(), | ||
| owner.getCompanyRegistrationNumber(), | ||
| attachments.stream() | ||
| .map(InnerAttachmentResponse::from) | ||
| .toList(), | ||
| shops.stream() | ||
| .map(InnerShopResponse::from) | ||
| .toList() | ||
| ); | ||
| } | ||
|
|
||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| private record InnerAttachmentResponse( | ||
| @Schema(description = "첨부 파일 ID", example = "1") | ||
| Long id, | ||
|
|
||
| @Schema(description = "첨부 파일 URL", example = "https://static.koreatech.in/1.png") | ||
| String fileUrl, | ||
|
|
||
| @Schema(description = "첨부 파일 이름", example = "1.jpg") | ||
| String fileName | ||
| ) { | ||
|
|
||
| public static InnerAttachmentResponse from(OwnerAttachment ownerAttachment) { | ||
| return new InnerAttachmentResponse( | ||
| ownerAttachment.getId(), | ||
| ownerAttachment.getUrl(), | ||
| ownerAttachment.getName() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| private record InnerShopResponse( | ||
| @Schema(description = "가게 ID", example = "1") | ||
| Long id, | ||
|
|
||
| @Schema(description = "가게 이름", example = "가게1") | ||
| String name | ||
| ) { | ||
|
|
||
| public static InnerShopResponse from(Shop shop) { | ||
| return new InnerShopResponse( | ||
| shop.getId(), | ||
| shop.getName() | ||
| ); | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/in/koreatech/koin/domain/owner/exception/AttachmentNotFoundException.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,18 @@ | ||
| package in.koreatech.koin.domain.owner.exception; | ||
|
|
||
| import in.koreatech.koin.domain.shop.exception.MenuNotFoundException; | ||
| import in.koreatech.koin.global.exception.DataNotFoundException; | ||
|
|
||
| public class AttachmentNotFoundException extends DataNotFoundException { | ||
|
|
||
| private static final String DEFAULT_MESSAGE = "존재하지 않는 첨부파일입니다."; | ||
|
|
||
| public AttachmentNotFoundException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public static MenuNotFoundException withDetail(String detail) { | ||
| String message = String.format("%s %s", DEFAULT_MESSAGE, detail); | ||
| return new MenuNotFoundException(message); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/in/koreatech/koin/domain/owner/exception/OwnerNotFoundException.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,17 @@ | ||
| package in.koreatech.koin.domain.owner.exception; | ||
|
|
||
| import in.koreatech.koin.global.exception.DataNotFoundException; | ||
|
|
||
| public class OwnerNotFoundException extends DataNotFoundException { | ||
|
|
||
| private static final String DEFAULT_MESSAGE = "존재하지 않는 사장님입니다."; | ||
|
|
||
| public OwnerNotFoundException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public static OwnerNotFoundException withDetail(String detail) { | ||
| String message = String.format("%s %s", DEFAULT_MESSAGE, detail); | ||
| return new OwnerNotFoundException(message); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/in/koreatech/koin/domain/owner/repository/OwnerAttachmentRepository.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,16 @@ | ||
| package in.koreatech.koin.domain.owner.repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.data.repository.Repository; | ||
|
|
||
| import in.koreatech.koin.domain.owner.domain.OwnerAttachment; | ||
|
|
||
| public interface OwnerAttachmentRepository extends Repository<OwnerAttachment, Long> { | ||
|
|
||
| OwnerAttachment save(OwnerAttachment ownerAttachment); | ||
|
|
||
| OwnerAttachment findById(Long id); | ||
|
|
||
| List<OwnerAttachment> findAllByOwnerId(Long ownerId); | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/in/koreatech/koin/domain/owner/repository/OwnerRepository.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,19 @@ | ||
| package in.koreatech.koin.domain.owner.repository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.data.repository.Repository; | ||
|
|
||
| import in.koreatech.koin.domain.owner.domain.Owner; | ||
| import in.koreatech.koin.domain.owner.exception.OwnerNotFoundException; | ||
|
|
||
| public interface OwnerRepository extends Repository<Owner, Long> { | ||
|
|
||
| Optional<Owner> findById(Long ownerId); | ||
|
|
||
| default Owner getById(Long ownerId) { | ||
| return findById(ownerId).orElseThrow(() -> OwnerNotFoundException.withDetail("ownerId: " + ownerId)); | ||
| } | ||
|
|
||
| Owner save(Owner owner); | ||
| } |
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.
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
JPABuddy가 가져온친구같군..