Skip to content

Commit

Permalink
Merge pull request #6 from LikeLion-Hackathon-T1/feat/market-info
Browse files Browse the repository at this point in the history
Feat/market info
  • Loading branch information
Jeongh00 authored Jul 19, 2024
2 parents d1c9f27 + bbe3738 commit 0d00983
Show file tree
Hide file tree
Showing 31 changed files with 697 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Backend CD # actions 이름

on:
push:
branches: [ feat/infra-settings ]
branches: [ feat/market-info ]

jobs:
deploy:
Expand Down
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;
}

}
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) {
}
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) {
}
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);
}
}
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();
}

}
15 changes: 7 additions & 8 deletions api-module/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ spring:

datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://syluv-database.cb2sy0ccsa47.ap-northeast-2.rds.amazonaws.com:3306/syluv_database
username: admin
url: jdbc:mysql://syluv-db.cb2sy0ccsa47.ap-northeast-2.rds.amazonaws.com:3306/syluv_db
username: syluvdatabase
password: syluvdatabase

jpa:
hibernate:
ddl-auto: update
show-sql: true
format_sql: true
properties:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
hibernate:
format_sql: true
hbm2ddl:
auto: update
show_sql: true
hibernate.dialect: org.hibernate.dialect.MySQLDialect

security:
jwt:
Expand Down
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();
}
}
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;
}
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;
}
}
Loading

0 comments on commit 0d00983

Please sign in to comment.