-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] 가게 도메인 API 구현 #5
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
8 commits
Select commit
Hold shift + click to select a range
110a937
feat: Market 엔티티 생성
mingdodev 592ae69
feat: 역할에 따른 회원 가입 분리 및 사장님의 가게 생성 구현
mingdodev ba810f9
feat: Security 로그인 URL 추가 허용
mingdodev cb47d40
feat: JWT Authorization을 위한 Swagger 설정 추가
mingdodev f34982b
feat: Product 엔티티 생성 및 연관관계 설정
mingdodev b19641d
feat: 고객의 가게 조회 및 검색 구현
mingdodev 2b1f02c
fix: 검색 로직 일부 서비스 계층으로 이동 및 검색어 공백 제거
mingdodev 9a1e978
feat: 회원가입 시의 중복된 이메일 입력에 대한 검증
mingdodev 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
27 changes: 27 additions & 0 deletions
27
src/main/java/danji/danjiapi/domain/market/controller/MarketController.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 danji.danjiapi.domain.market.controller; | ||
|
|
||
| import danji.danjiapi.domain.market.dto.request.MarketSearchCondition; | ||
| import danji.danjiapi.domain.market.dto.response.MarketSummary; | ||
| import danji.danjiapi.domain.market.service.MarketService; | ||
| import danji.danjiapi.global.response.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.ModelAttribute; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/markets") | ||
| @RequiredArgsConstructor | ||
| public class MarketController { | ||
| private final MarketService marketService; | ||
|
|
||
| @GetMapping("") | ||
| @Operation(summary = "가게 둘러보기", description = "회원이 모든 가게들의 목록을 조회하고, 키워드로 원하는 가게를 검색합니다.") | ||
| public ApiResponse<List<MarketSummary>> getMarkets(@ModelAttribute MarketSearchCondition searchCondition) { | ||
| return ApiResponse.success(marketService.searchMarkets(searchCondition)); | ||
| } | ||
|
|
||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/danji/danjiapi/domain/market/dto/request/MarketSearchCondition.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,6 @@ | ||
| package danji.danjiapi.domain.market.dto.request; | ||
|
|
||
| public record MarketSearchCondition( | ||
| String keyword | ||
| ) { | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/danji/danjiapi/domain/market/dto/response/MarketSummary.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 danji.danjiapi.domain.market.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.market.entity.Market; | ||
|
|
||
| public record MarketSummary( | ||
| Long id, | ||
| String name, | ||
| String address, | ||
| String imageUrl | ||
| ) { | ||
| public static MarketSummary from(Market market) { | ||
| return new MarketSummary( | ||
| market.getId(), | ||
| market.getName(), | ||
| market.getAddress(), | ||
| market.getImageUrl() | ||
| ); | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
src/main/java/danji/danjiapi/domain/market/entity/Market.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,70 @@ | ||
| package danji.danjiapi.domain.market.entity; | ||
|
|
||
| import danji.danjiapi.domain.product.entity.Product; | ||
| import danji.danjiapi.domain.user.entity.User; | ||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.OneToMany; | ||
| import jakarta.persistence.OneToOne; | ||
| import jakarta.persistence.Table; | ||
| import java.time.LocalDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.springframework.data.annotation.CreatedDate; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| @Builder | ||
| @Table(name = "markets") | ||
| public class Market { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(length = 30, nullable = false) | ||
| private String name; | ||
|
|
||
| @Column(length = 30, nullable = false) | ||
| private String address; | ||
|
|
||
| @Column(name = "image_url", nullable = false) | ||
| private String imageUrl; | ||
|
|
||
| @CreatedDate | ||
| @Column(name = "created_at", updatable = false) | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @OneToOne | ||
| @JoinColumn(name = "user_id", nullable = false, unique = true) | ||
| private User user; | ||
|
|
||
| @OneToMany(mappedBy = "market", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<Product> products = new ArrayList<>(); | ||
|
|
||
| public static Market create(String name, String address, String imageUrl, User user) { | ||
| return Market.builder() | ||
| .name(name) | ||
| .address(address) | ||
| .imageUrl(imageUrl) | ||
| .user(user) | ||
| .build(); | ||
| } | ||
|
|
||
| public void addProduct(Product product) { | ||
| products.add(product); | ||
| product.setMarket(this); | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/main/java/danji/danjiapi/domain/market/repository/MarketRepository.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,20 @@ | ||
| package danji.danjiapi.domain.market.repository; | ||
|
|
||
| import danji.danjiapi.domain.market.entity.Market; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface MarketRepository extends JpaRepository<Market, Long> { | ||
|
|
||
| @Query(""" | ||
| SELECT DISTINCT m FROM Market m | ||
| LEFT JOIN m.products p | ||
| WHERE | ||
| (m.name LIKE %:keyword% | ||
| OR m.address LIKE %:keyword% | ||
| OR p.name LIKE %:keyword%) | ||
| """) | ||
| List<Market> findByNameOrAddressOrProductsContaining(@Param("keyword") String keyword); | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/main/java/danji/danjiapi/domain/market/service/MarketService.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,29 @@ | ||
| package danji.danjiapi.domain.market.service; | ||
|
|
||
| import danji.danjiapi.domain.market.dto.request.MarketSearchCondition; | ||
| import danji.danjiapi.domain.market.dto.response.MarketSummary; | ||
| import danji.danjiapi.domain.market.entity.Market; | ||
| import danji.danjiapi.domain.market.repository.MarketRepository; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class MarketService { | ||
| private final MarketRepository marketRepository; | ||
|
|
||
| public List<MarketSummary> searchMarkets(MarketSearchCondition searchCondition) { | ||
| List<Market> markets; | ||
|
|
||
| if (searchCondition == null || searchCondition.keyword() == null || searchCondition.keyword().trim().isEmpty()) { | ||
| markets = marketRepository.findAll(); | ||
| } else { | ||
| markets = marketRepository.findByNameOrAddressOrProductsContaining(searchCondition.keyword().trim()); | ||
| } | ||
|
|
||
| return markets.stream() | ||
| .map(MarketSummary::from) | ||
| .toList(); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/danji/danjiapi/domain/product/entity/Product.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,56 @@ | ||
| package danji.danjiapi.domain.product.entity; | ||
|
|
||
| import danji.danjiapi.domain.market.entity.Market; | ||
| 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.ManyToOne; | ||
| import jakarta.persistence.Table; | ||
| import java.math.BigDecimal; | ||
| import java.time.LocalDateTime; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.springframework.data.annotation.CreatedDate; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| @Builder | ||
| @Table(name = "products") | ||
| public class Product { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(length = 20, nullable = false) | ||
| private String name; | ||
|
|
||
| @Column(nullable = false) | ||
| private BigDecimal price; | ||
|
|
||
| @Column | ||
| private Integer minQuantity; | ||
|
|
||
| @Column | ||
| private Integer maxQuantity; | ||
|
|
||
| @CreatedDate | ||
| @Column(name = "created_at", updatable = false) | ||
| private LocalDateTime createdAt; | ||
mingdodev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Setter | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "market_id", nullable = false) | ||
| private Market market; | ||
|
|
||
| } | ||
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
22 changes: 22 additions & 0 deletions
22
src/main/java/danji/danjiapi/domain/user/dto/request/UserCreateMerchantRequest.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,22 @@ | ||
| package danji.danjiapi.domain.user.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record UserCreateMerchantRequest( | ||
| @NotBlank(message = "이메일은 필수입니다.") | ||
| @Email(message = "올바른 이메일 형식이 아닙니다.") | ||
| String email, | ||
| @NotBlank(message = "비밀번호는 필수입니다") | ||
| String password, | ||
| @NotBlank(message = "이름은 필수입니다") | ||
| String name, | ||
|
|
||
| @NotBlank(message = "상호명은 필수입니다.") | ||
| String marketName, | ||
| @NotBlank(message = "주소는 필수입니다.") | ||
| String marketAddress, | ||
| String marketImageUrl | ||
| ) { | ||
|
|
||
| } |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/danji/danjiapi/domain/user/dto/response/UserCreateMerchantResponse.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,20 @@ | ||
| package danji.danjiapi.domain.user.dto.response; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record UserCreateMerchantResponse( | ||
| Long id, | ||
| String name, | ||
| String role, | ||
| Long marketId | ||
| ) { | ||
| public static UserCreateMerchantResponse from(Long id, String name, String role, Long marketId) { | ||
| return UserCreateMerchantResponse.builder() | ||
| .id(id) | ||
| .name(name) | ||
| .role(role) | ||
| .marketId(marketId) | ||
| .build(); | ||
| } | ||
| } |
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.