-
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.
Merge pull request #18 from KUSITMS-Team-A/feature/15-find-store
[Feature] 가게 찾기 API 구현
- Loading branch information
Showing
34 changed files
with
1,128 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = 'backend' | ||
rootProject.name = 'Backend' |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.backend.common.domain; | ||
|
||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Getter | ||
public abstract class BaseEntity { | ||
|
||
@CreatedDate | ||
private LocalDateTime createdTime; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime modifiedTime; | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/backend/domain/benefit/entity/Benefit.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,29 @@ | ||
package com.backend.domain.benefit.entity; | ||
|
||
import com.backend.common.domain.BaseEntity; | ||
import com.backend.domain.contract.entity.Contract; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Table(name = "benefit") | ||
public class Benefit extends BaseEntity { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long benefitId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private BenefitType type; | ||
|
||
private int amount; | ||
|
||
private String content; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "contract_id") | ||
private Contract contract; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/backend/domain/benefit/entity/BenefitType.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,7 @@ | ||
package com.backend.domain.benefit.entity; | ||
|
||
public enum BenefitType { | ||
|
||
FIX, RATE, MENU | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/backend/domain/contract/entity/Contract.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,42 @@ | ||
package com.backend.domain.contract.entity; | ||
|
||
import com.backend.domain.benefit.entity.Benefit; | ||
import com.backend.common.domain.BaseEntity; | ||
import com.backend.domain.store.entity.Store; | ||
import com.backend.domain.university.entity.University; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Table(name = "contract") | ||
public class Contract extends BaseEntity { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long contractId; | ||
|
||
private LocalDate startDate; | ||
|
||
private LocalDate endDate; | ||
|
||
private String manager; | ||
|
||
@OneToMany(mappedBy = "contract", cascade = CascadeType.PERSIST) | ||
private List<Benefit> benefits = new ArrayList<>(); | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "university_id") | ||
private University university; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "store_id") | ||
private Store store; | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/backend/domain/contract/entity/ContractStatus.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.backend.domain.contract.entity; | ||
|
||
public enum ContractStatus { | ||
AVAILABLE, EXPIRATION | ||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/com/backend/domain/store/controller/StoreController.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,87 @@ | ||
package com.backend.domain.store.controller; | ||
|
||
import com.backend.common.dto.ResponseDto; | ||
import com.backend.domain.auth.dto.Login; | ||
import com.backend.domain.auth.dto.LoginUser; | ||
import com.backend.domain.store.dto.*; | ||
import com.backend.domain.store.service.StoreService; | ||
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.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/store") | ||
@SecurityRequirement(name = "bearer-key") | ||
@Tag(name = "가게", description = "가게 관련 API") | ||
public class StoreController { | ||
|
||
private final StoreService storeService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> createStore(@RequestBody CreateStoreRequest request) { | ||
storeService.createStore(request); | ||
return ResponseDto.created(); | ||
} | ||
|
||
@GetMapping("/details/{storeId}") | ||
@Operation( | ||
summary = "가게 상세 정보 조회", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
content = @Content(schema = @Schema(implementation = ReadStoreDetailsDto.class))) | ||
}) | ||
public ResponseEntity<ReadStoreDetailsDto> readStoreDetails(@Parameter(hidden = true) @Login LoginUser loginUser, @Parameter(name = "storeId") @PathVariable Long storeId) { | ||
return ResponseDto.ok(storeService.readStoreDetails(loginUser, storeId)); | ||
} | ||
|
||
@GetMapping("/search") | ||
@Operation( | ||
summary = "가게 목록 검색 및 조회", | ||
description = | ||
"<p>{url}/store/search?isPicked=true&name=건&category=FOOD&pageSize=40&pageNumber=0</p>" + | ||
"<p>isPicked = true/false, default = false</p>" + | ||
"<p>name = String 타입의 가게 명, 입력하지 않아도 사용 가능</p>" + | ||
"<p>category = [FOOD, CAFE, BEAUTY, CULTURE, ETC, NONE] 중 하나, default = NONE(카테고리 검색X)</p>" + | ||
"<p>pageSize = int 값, default = 40</p>" + | ||
"<p>pageNumber = 0부터 int 값, default = 0</p>", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
content = @Content(schema = @Schema(implementation = ReadStoresDto.class))) | ||
}) | ||
public ResponseEntity<ReadStoresDto> readStores(@Parameter(hidden = true) @Login LoginUser loginUser, @ModelAttribute ReadStoresRequest request) { | ||
return ResponseDto.ok(storeService.readStores(loginUser, request)); | ||
} | ||
|
||
@PostMapping("/pick") | ||
@Operation( | ||
summary = "픽 등록", | ||
responses = { | ||
@ApiResponse(responseCode = "201") | ||
}) | ||
public ResponseEntity<Void> createPick(@Parameter(hidden = true) @Login LoginUser loginUser, @RequestBody PickRequest request) { | ||
storeService.createPick(loginUser, request); | ||
return ResponseDto.created(); | ||
} | ||
|
||
@DeleteMapping("/pick") | ||
@Operation( | ||
summary = "픽 취소", | ||
responses = { | ||
@ApiResponse(responseCode = "200") | ||
}) | ||
public ResponseEntity<Void> deletePick(@Parameter(hidden = true) @Login LoginUser loginUser, @RequestBody PickRequest request) { | ||
storeService.deletePick(loginUser, request); | ||
return ResponseDto.ok(); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/backend/domain/store/dto/BusinessHourDto.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,29 @@ | ||
package com.backend.domain.store.dto; | ||
|
||
import com.backend.domain.store.entity.BusinessHour; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class BusinessHourDto { | ||
|
||
private String dayOfWeek; | ||
|
||
private String openingTime; | ||
|
||
private String closingTime; | ||
|
||
public static BusinessHourDto from(BusinessHour businessHour) { | ||
return BusinessHourDto.builder() | ||
.dayOfWeek(businessHour.getDayOfWeek().getDayOfWeek()) | ||
.openingTime(businessHour.getOpeningTime()) | ||
.closingTime(businessHour.getClosingTime()) | ||
.build(); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/backend/domain/store/dto/CreateBusinessHourDto.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,26 @@ | ||
package com.backend.domain.store.dto; | ||
|
||
import com.backend.domain.store.entity.BusinessDay; | ||
import com.backend.domain.store.entity.BusinessHour; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CreateBusinessHourDto { | ||
|
||
private String dayOfWeek; | ||
|
||
private HoursInfoDto hoursInfo; | ||
|
||
public BusinessHour toEntity() { | ||
return BusinessHour.builder() | ||
.dayOfWeek(BusinessDay.convert(dayOfWeek)) | ||
.openingTime(hoursInfo.getOpeningTime()) | ||
.closingTime(hoursInfo.getClosingTime()) | ||
.build(); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/backend/domain/store/dto/CreateStoreDto.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,68 @@ | ||
package com.backend.domain.store.dto; | ||
|
||
import com.backend.domain.store.entity.Category; | ||
import com.backend.domain.store.entity.Store; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CreateStoreDto { | ||
|
||
private String storeName; | ||
private String genre; | ||
private String phoneNumber; | ||
private String address; | ||
private LocationDto location; | ||
private List<CreateBusinessHourDto> businessHours = new ArrayList<>(); | ||
private List<MenuDto> menu = new ArrayList<>(); | ||
|
||
public Store toEntity(Category category) { | ||
return Store.builder() | ||
.name(storeName) | ||
.address(address) | ||
.description(getDescription()) | ||
.latitude(getLatitude()) | ||
.longitude(getLongitude()) | ||
.category(category) | ||
.contact(phoneNumber) | ||
.phoneNumber(phoneNumber) | ||
.businessHours( | ||
businessHours.stream() | ||
.filter(Objects::nonNull) | ||
.map(CreateBusinessHourDto::toEntity) | ||
.toList() | ||
) | ||
.build(); | ||
} | ||
|
||
public String getDescription() { | ||
if (genre != null) { | ||
return genre; | ||
} | ||
if (!menu.isEmpty()) { | ||
return menu.stream() | ||
.map(MenuDto::getName) | ||
.limit(3) | ||
.collect(Collectors.joining(", ")); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
public Double getLongitude() { | ||
return location == null ? null : location.getLongitude(); | ||
} | ||
|
||
public Double getLatitude() { | ||
return location == null ? null : location.getLatitude(); | ||
} | ||
|
||
} |
Oops, something went wrong.