Skip to content
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

Feat/store info #10

Merged
merged 8 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 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/market-info ]
branches: [ feat/store-info ]

jobs:
deploy:
Expand All @@ -17,6 +17,13 @@ jobs:
- name: μ €μž₯μ†Œ Checkout
uses: actions/checkout@v3

- name: make application-s3 yml file
run: |
cd ./common-module/src/main/resources
touch ./application-s3.yml
echo "${{ secrets.APPLICATION_S3 }}" > ./application-s3.yml
shell: bash

- name: Gradlew κΆŒν•œ λΆ€μ—¬
run: chmod +x ./gradlew

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

common-module/src/main/resources/application-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ public MarketInfo findMarketInfo() {

Market market = marketQueryService.findMarket(1L);

return new MarketInfo(market.getName(),
return new MarketInfo(
market.getId(),
market.getName(),
market.getDescription(),
market.getStartHour(),
market.getCloseHour(),
market.getContact());
market.getContact(),
market.getImageUrl());
}

public void saveVisitList(Long storeId, String accessToken) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.likelion.apimodule.market.dto;

public record MarketInfo(String name,
public record MarketInfo(Long marketId,
String name,
String description,
String startHour,
String closeHour,
String contact) {
String contact,
String image) {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.likelion.apimodule.store.application;

import com.likelion.apimodule.security.util.JwtUtil;
import com.likelion.apimodule.store.dto.MenuDetailDTO;
import com.likelion.apimodule.store.dto.StoreInfo;
import com.likelion.apimodule.store.dto.StoreResponse;
import com.likelion.coremodule.cart.domain.Cart;
import com.likelion.coremodule.cart.service.CartQueryService;
import com.likelion.coremodule.menu.domain.Menu;
import com.likelion.coremodule.menu.service.MenuQueryService;
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 com.likelion.coremodule.user.application.UserQueryService;
import com.likelion.coremodule.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -17,6 +26,43 @@
public class StoreInfoUseCase {

private final StoreQueryService storeQueryService;
private final MenuQueryService menuQueryService;
private final UserQueryService userQueryService;
private final CartQueryService cartQueryService;
private final JwtUtil jwtUtil;

public List<StoreInfo> findStoreInfo() {

List<Store> storeList = storeQueryService.findAllStore();
List<StoreInfo> storeInfoList = new ArrayList<>();

for (Store store : storeList) {

List<Menu> menus = menuQueryService.findMenusByStoreId(store.getId());
List<MenuDetailDTO> menuDetails = menus.stream()
.map(menu -> new MenuDetailDTO(menu.getId(),
menu.getName(),
menu.getPrice(),
menu.getContent(),
menu.getImageUrl()))
.toList();

StoreInfo storeInfo = new StoreInfo(
store.getId(),
store.getName(),
store.getReviewCount(),
store.getLocation(),
store.getOpenHours(),
store.getCloseHours(),
store.getContact(),
store.getImageUrl(),
menuDetails
);
storeInfoList.add(storeInfo);
}

return storeInfoList;
}

public List<StoreResponse> findStoreByFilter(String search, String category) {

Expand Down Expand Up @@ -44,12 +90,21 @@ public List<StoreResponse> findStoreByFilter(String search, String category) {
.toList();

for (Store store : list) {
StoreResponse ex = new StoreResponse(store.getName(), finalStoreCategory, store.getLocation(), store.getOpenHours());
StoreResponse ex = new StoreResponse(store.getName(), finalStoreCategory, store.getLocation(), store.getOpenHours(), store.getImageUrl());
response.add(ex);
}

return response;
}

public void addToCart(Long menuId, String accessToken) {

Menu menu = menuQueryService.findMenuById(menuId);

String email = jwtUtil.getEmail(accessToken);
User user = userQueryService.findByEmail(email);

final Cart cart = Cart.builder().user(user).menu(menu).build();
cartQueryService.saveCart(cart);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.likelion.apimodule.store.dto;

public record MenuDetailDTO(Long marketId,
String name,
Integer price,
String content,
String menuImage) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.likelion.apimodule.store.dto;

import java.util.List;

public record StoreInfo(Long storeId,
String name,
Integer reviewCount,
String location,
String openHours,
String closeHours,
String contact,
String storeImage,
List<MenuDetailDTO> menuDetails) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
public record StoreResponse(String name,
StoreCategory category,
String location,
String openHours) {
String openHours,
String image) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.likelion.apimodule.store.presentation;

import com.likelion.apimodule.store.application.StoreInfoUseCase;
import com.likelion.apimodule.store.dto.StoreInfo;
import com.likelion.commonmodule.exception.common.ApplicationResponse;
import com.likelion.commonmodule.security.util.AuthConsts;
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/store")
@Validated
@Tag(name = "Store", description = "Store κ΄€λ ¨ API")
public class StoreController {

private final StoreInfoUseCase storeInfoUseCase;

// κ°€κ²Œ 정보
@GetMapping("/info")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "κ°€κ²Œ 정보 확인 성곡",
useReturnTypeSchema = true
)
}
)
@Operation(summary = "κ°€κ²Œ 정보 확인 API", description = "κ°€κ²Œ 정보 확인 API μž…λ‹ˆλ‹€.")
public ApplicationResponse<List<StoreInfo>> getStoreInfo() {

List<StoreInfo> infos = storeInfoUseCase.findStoreInfo();
return ApplicationResponse.ok(infos);
}

// μž₯λ°”κ΅¬λ‹ˆ μΆ”κ°€
@PostMapping("/{menuId}/addcart")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "μž₯λ°”κ΅¬λ‹ˆ μΆ”κ°€ 성곡",
useReturnTypeSchema = true
)
}
)
@Operation(summary = "μž₯λ°”κ΅¬λ‹ˆ μΆ”κ°€ API", description = "μž₯λ°”κ΅¬λ‹ˆ μΆ”κ°€ API μž…λ‹ˆλ‹€.")
public ApplicationResponse<String> addToCart(@PathVariable Long menuId,
@RequestHeader(AuthConsts.ACCESS_TOKEN_HEADER) String accessToken) {

storeInfoUseCase.addToCart(menuId, accessToken);
return ApplicationResponse.ok("μž₯λ°”κ΅¬λ‹ˆ μΆ”κ°€ μ™„λ£Œ");
}

// 리뷰 쑰회

// 리뷰 μž‘μ„±
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public LoginAddResponse kakaoLogin(final KakaoLoginRequest kakaoLoginRequest) {
final User user = userRepository.findBySubId(oidcDecodePayload.sub())
.orElseGet(() -> createNewKakaoUser(oidcDecodePayload));

return new LoginAddResponse(user.getName(), jwtUtil.createJwtAccessToken(oidcDecodePayload.email(), oidcDecodePayload.sub()),
return new LoginAddResponse(user.getName(), user.getPicture(),
jwtUtil.createJwtAccessToken(oidcDecodePayload.email(), oidcDecodePayload.sub()),
jwtUtil.createJwtRefreshToken(oidcDecodePayload.email(), oidcDecodePayload.sub()));
}

Expand Down
4 changes: 2 additions & 2 deletions api-module/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ spring:
config:
activate:
on-profile: local
import: application-local.yml, application-redis.yml, application-oauth.yml
import: application-local.yml, application-redis.yml, application-oauth.yml, application-s3.yml

---
spring:
config:
activate:
on-profile: prod
import: application-prod.yml, application-redis.yml, application-oauth.yml
import: application-prod.yml, application-redis.yml, application-oauth.yml, application-s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.likelion.commonmodule.image.config;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class AwsS3Config {

@Value("${cloud.aws.credentials.access-key}")
private String accessKey;

@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;

@Value("${cloud.aws.region.static}")
private String region;

@Bean
public AmazonS3 generateS3client() {
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
return AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.likelion.commonmodule.image.exception;

import com.likelion.commonmodule.exception.common.BaseErrorCode;

public class FileDeleteException extends ImageException {
public FileDeleteException(BaseErrorCode errorCode) {
super(errorCode);
}

public FileDeleteException(BaseErrorCode errorCode, Throwable cause) {
super(errorCode, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.likelion.commonmodule.image.exception;

import com.likelion.commonmodule.exception.common.BaseErrorCode;

public class FileExtensionException extends ImageException {
public FileExtensionException(BaseErrorCode errorCode) {
super(errorCode);
}

public FileExtensionException(BaseErrorCode errorCode, Throwable cause) {
super(errorCode, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.likelion.commonmodule.image.exception;

import com.likelion.commonmodule.exception.common.BaseErrorCode;

public class FileUploadException extends ImageException {
public FileUploadException(BaseErrorCode errorCode) {
super(errorCode);
}

public FileUploadException(BaseErrorCode errorCode, Throwable cause) {
super(errorCode, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.likelion.commonmodule.image.exception;

import com.likelion.commonmodule.exception.common.ApiResponse;
import com.likelion.commonmodule.exception.common.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ImageErrorCode implements BaseErrorCode {

FILE_UPLOAD_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "3000", "파일 μ—…λ‘œλ“œμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."),
FILE_DELETE_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "3000", "파일 μ‚­μ œμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."),
WRONG_FILE_FORMAT(HttpStatus.INTERNAL_SERVER_ERROR, "3000", "파일 νƒ€μž…μ΄ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
;

private final HttpStatus httpStatus;
private final String code;
private final String message;


@Override
public ApiResponse<Void> getErrorResponse() {
return null;
}
}
Loading
Loading