-
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 #6 from LikeLion-Hackathon-T1/feat/market-info
Feat/market info
- Loading branch information
Showing
31 changed files
with
697 additions
and
17 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
57 changes: 57 additions & 0 deletions
57
api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.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,57 @@ | ||
package com.likelion.apimodule.market.application; | ||
|
||
import com.likelion.apimodule.market.dto.MarketInfo; | ||
import com.likelion.apimodule.market.dto.VisitListInfo; | ||
import com.likelion.coremodule.VisitList.domain.VisitList; | ||
import com.likelion.coremodule.VisitList.service.VisitListQueryService; | ||
import com.likelion.coremodule.market.domain.Market; | ||
import com.likelion.coremodule.market.service.MarketQueryService; | ||
import com.likelion.coremodule.store.domain.Store; | ||
import com.likelion.coremodule.store.service.StoreQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MarketInfoUseCase { | ||
|
||
private final MarketQueryService marketQueryService; | ||
private final VisitListQueryService visitListQueryService; | ||
private final StoreQueryService storeQueryService; | ||
|
||
public MarketInfo findMarketInfo() { | ||
|
||
Market market = marketQueryService.findMarket(1L); | ||
|
||
return new MarketInfo(market.getName(), | ||
market.getDescription(), | ||
market.getStartHour(), | ||
market.getCloseHour(), | ||
market.getContact()); | ||
} | ||
|
||
public void saveVisitList(Long storeId) { | ||
|
||
marketQueryService.saveVisitList(storeId); | ||
} | ||
|
||
public List<VisitListInfo> findVisitList() { | ||
|
||
List<VisitListInfo> visitListInfos = new ArrayList<>(); | ||
List<VisitList> visitLists = visitListQueryService.findAllVisitList(); | ||
|
||
for (VisitList i : visitLists) { | ||
Long id = i.getId(); | ||
Store store = storeQueryService.findStoreById(id); | ||
|
||
VisitListInfo visitListInfo = new VisitListInfo(store.getName(), i.getVisit_status()); | ||
visitListInfos.add(visitListInfo); | ||
} | ||
|
||
return visitListInfos; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
api-module/src/main/java/com/likelion/apimodule/market/dto/MarketInfo.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,8 @@ | ||
package com.likelion.apimodule.market.dto; | ||
|
||
public record MarketInfo(String name, | ||
String description, | ||
String startHour, | ||
String closeHour, | ||
String contact) { | ||
} |
7 changes: 7 additions & 0 deletions
7
api-module/src/main/java/com/likelion/apimodule/market/dto/VisitListInfo.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.likelion.apimodule.market.dto; | ||
|
||
import com.likelion.coremodule.VisitList.domain.VisitStatus; | ||
|
||
public record VisitListInfo(String store, | ||
VisitStatus status) { | ||
} |
99 changes: 99 additions & 0 deletions
99
api-module/src/main/java/com/likelion/apimodule/market/presentation/MarketController.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,99 @@ | ||
package com.likelion.apimodule.market.presentation; | ||
|
||
import com.likelion.apimodule.market.application.MarketInfoUseCase; | ||
import com.likelion.apimodule.market.dto.MarketInfo; | ||
import com.likelion.apimodule.market.dto.VisitListInfo; | ||
import com.likelion.apimodule.store.application.StoreInfoUseCase; | ||
import com.likelion.commonmodule.exception.common.ApplicationResponse; | ||
import com.likelion.coremodule.store.domain.Store; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
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 lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/v1/market") | ||
@Validated | ||
@Tag(name = "Market", description = "Market 관련 API") | ||
public class MarketController { | ||
|
||
private final MarketInfoUseCase marketInfoUseCase; | ||
private final StoreInfoUseCase storeInfoUseCase; | ||
|
||
@GetMapping("/info") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "시장 정보 확인 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "시장 정보 확인 API", description = "시장 정보 확인 API입니다.") | ||
public ApplicationResponse<MarketInfo> getMarketInfo() { | ||
|
||
MarketInfo infos = marketInfoUseCase.findMarketInfo(); | ||
return ApplicationResponse.ok(infos); | ||
} | ||
|
||
// 가게 검색 | ||
@GetMapping("/store") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "가게 검색 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "가게 검색 API", description = "가게 검색 API입니다.") | ||
public ApplicationResponse<List<Store>> findStoreByFilter(@RequestParam String search, @RequestParam String category) { | ||
|
||
final List<Store> storeByFilter = storeInfoUseCase.findStoreByFilter(search, category); | ||
return ApplicationResponse.ok(storeByFilter); | ||
} | ||
|
||
// 방문 리스트 추가 | ||
@PostMapping("/{storeId}/visitlist") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "방문 리스트 추가 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "방문 리스트 추가 API", description = "방문 리스트 추가 API입니다.") | ||
public ApplicationResponse<String> saveVisitList(@PathVariable Long storeId) { | ||
|
||
marketInfoUseCase.saveVisitList(storeId); | ||
return ApplicationResponse.ok("방문 리스트 추가 완료"); | ||
} | ||
|
||
// 전체 방문 리스트 조회 | ||
@GetMapping("/visitlist") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "방문 리스트 조회 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "방문 리스트 조회 API", description = "방문 리스트 조회 API입니다.") | ||
public ApplicationResponse<List<VisitListInfo>> findVisitList() { | ||
|
||
final List<VisitListInfo> visitList = marketInfoUseCase.findVisitList(); | ||
return ApplicationResponse.ok(visitList); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
api-module/src/main/java/com/likelion/apimodule/store/application/StoreInfoUseCase.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,44 @@ | ||
package com.likelion.apimodule.store.application; | ||
|
||
import com.likelion.coremodule.store.domain.Store; | ||
import com.likelion.coremodule.store.domain.StoreCategory; | ||
import com.likelion.coremodule.store.exception.StoreErrorCode; | ||
import com.likelion.coremodule.store.exception.StoreException; | ||
import com.likelion.coremodule.store.service.StoreQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StoreInfoUseCase { | ||
|
||
private final StoreQueryService storeQueryService; | ||
|
||
public List<Store> findStoreByFilter(String search, String category) { | ||
|
||
List<Store> storeList = storeQueryService.findAllStore(); | ||
|
||
if ((search == null || search.isEmpty()) && (category == null || category.isEmpty())) { | ||
return storeList; | ||
} | ||
|
||
StoreCategory storeCategory = null; | ||
if (category != null && !category.isEmpty()) { | ||
try { | ||
storeCategory = StoreCategory.valueOf(category.toUpperCase()); | ||
} catch (IllegalArgumentException e) { | ||
throw new StoreException(StoreErrorCode.NO_STORE_CATEGORY); | ||
} | ||
} | ||
|
||
final StoreCategory finalStoreCategory = storeCategory; | ||
|
||
return storeList.stream() | ||
.filter(store -> (search == null || search.isEmpty() || store.getName().contains(search))) | ||
.filter(store -> (finalStoreCategory == null || store.getCategory() == finalStoreCategory)) | ||
.toList(); | ||
} | ||
|
||
} |
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
108 changes: 108 additions & 0 deletions
108
...-module/src/main/java/com/likelion/commonmodule/exception/common/ApplicationResponse.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,108 @@ | ||
package com.likelion.commonmodule.exception.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Jacksonized | ||
public class ApplicationResponse<T> { | ||
private ApplicationResult result; | ||
private T payload; | ||
|
||
public static <T> ApplicationResponse<T> ok(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.OK.value()) | ||
.message("API 호출 성공") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> ok(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.OK.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> badRequest(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.BAD_REQUEST.value()) | ||
.message("잘못된 요청입니다.") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> badRequest(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.BAD_REQUEST.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> notAuthenticated(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.UNAUTHORIZED.value()) | ||
.message("잘못된 접근입니다.") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> notAuthenticated(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.UNAUTHORIZED.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> server(T payload) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.INTERNAL_SERVER_ERROR.value()) | ||
.message("API 호출 실패") | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> server(T payload, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(HttpStatus.INTERNAL_SERVER_ERROR.value()) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
|
||
public static <T> ApplicationResponse<T> custom(T payload, Integer code, String message) { | ||
return ApplicationResponse.<T>builder() | ||
.result(ApplicationResult.builder() | ||
.code(code) | ||
.message(message) | ||
.build()) | ||
.payload(payload) | ||
.build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...on-module/src/main/java/com/likelion/commonmodule/exception/common/ApplicationResult.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,17 @@ | ||
package com.likelion.commonmodule.exception.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Jacksonized | ||
public class ApplicationResult { | ||
private Integer code; | ||
private String message; | ||
} |
14 changes: 14 additions & 0 deletions
14
common-module/src/main/java/com/likelion/commonmodule/security/util/SecurityUtils.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,14 @@ | ||
package com.likelion.commonmodule.security.util; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class SecurityUtils { | ||
|
||
public static String getAuthenticationPrincipal() { | ||
final String email = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
return email; | ||
} | ||
} |
Oops, something went wrong.