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

feature : Store 조회 s3 경로 추가, Store 상세 조회, Store 식당 분류 조회 추가 #77

Merged
merged 23 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0719b30
feat: 식당 리뷰 신고하기 기능 개발
dldmsql Jan 6, 2024
f1c6a7f
refactor: repository 의존 관계 분리
dldmsql Jan 6, 2024
8fc4334
docs: swagger description 추가
dldmsql Jan 6, 2024
37e68ae
chore: prod 환경에서 swagger 접근 제한 설정 추가
dldmsql Jan 6, 2024
d0106a0
style: spotless
dldmsql Jan 6, 2024
8f129c7
refactor: 사용하지 않는 코드 삭제
dldmsql Jan 6, 2024
3517332
test: 오늘 먹었어요 리뷰 조회 테스트 코드 수정
dldmsql Jan 6, 2024
20e8596
test: 오늘 먹었어요 리뷰 조회 테스트 코드 수정
dldmsql Jan 6, 2024
dea0d6c
test: 오늘 먹었어요 리뷰 조회 쿼리문 수정
dldmsql Jan 6, 2024
17e06c2
feature : Store 조회 s3 경로 추가
Qbeom0925 Jan 8, 2024
30b8141
feature : log 설정 off
Qbeom0925 Jan 8, 2024
caa0aad
feature : 스토어 상세 조회 미완성
Jan 9, 2024
f59c063
feature : 식당 상세 조회 API 개발 및 테스트 완료
Qbeom0925 Jan 10, 2024
3ab3859
refactor : 한식 중식 일식 양식 세부 조회 API 리팩토링
Qbeom0925 Jan 10, 2024
ccbacca
feature : spotlessApply
Qbeom0925 Jan 10, 2024
ea4ae2c
refactor : log설정
Qbeom0925 Jan 10, 2024
8483fbc
refactor : log 미설정
Qbeom0925 Jan 10, 2024
2dec8a5
refactor : ci test yml 설정 변경
Qbeom0925 Jan 10, 2024
5458259
refactor : ci test yml 설정 변경
Qbeom0925 Jan 10, 2024
7f6fd66
refactor : ci test yml 설정 변경
Qbeom0925 Jan 10, 2024
82b9033
refactor : ci test yml 설정 변경
Qbeom0925 Jan 10, 2024
b714969
feature : 리뷰 관련 테스트 로그 설정
Jan 12, 2024
e89db55
feature : 리뷰 관련 테스트 로그 설정
Jan 12, 2024
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies {
implementation 'org.hibernate.orm:hibernate-core:6.2.5.Final'

//QueryDSL
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
// implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/everymeal/server/global/exception/ExceptionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,33 @@
@Getter
@RequiredArgsConstructor
public enum ExceptionList {
MEAL_NOT_FOUND("M0001", HttpStatus.NOT_FOUND, "Meal Not Found"),
RESTAURANT_NOT_FOUND("M0002", HttpStatus.NOT_FOUND, "등록된 식당이 아닙니다."),
UNIVERSITY_NOT_FOUND("M0003", HttpStatus.NOT_FOUND, "등록된 학교가 아닙니다."),
MEAL_NOT_FOUND("MEL0001", HttpStatus.NOT_FOUND, "Meal Not Found"),
RESTAURANT_NOT_FOUND("MEL0002", HttpStatus.NOT_FOUND, "등록된 식당이 아닙니다."),
UNIVERSITY_NOT_FOUND("MEL0003", HttpStatus.NOT_FOUND, "등록된 학교가 아닙니다."),
INVALID_MEAL_OFFEREDAT_REQUEST(
"M0004", HttpStatus.BAD_REQUEST, "동일한 데이터를 갖는 식단 데이터가 이미 존재합니다."),
INVALID_REQUEST("R0001", HttpStatus.BAD_REQUEST, "Request의 Data Type이 올바르지 않습니다."),
"MEL0004", HttpStatus.BAD_REQUEST, "동일한 데이터를 갖는 식단 데이터가 이미 존재합니다."),
INVALID_REQUEST("COM0001", HttpStatus.BAD_REQUEST, "Request의 Data Type이 올바르지 않습니다."),

USER_NOT_FOUND("U0001", HttpStatus.NOT_FOUND, "등록된 유저가 아닙니다."),
USER_AUTH_TIME_OUT("U0002", HttpStatus.FORBIDDEN, "인증 시간이 만료되었습니다."),
USER_AUTH_FAIL("U0003", HttpStatus.FORBIDDEN, "인증에 실패하였습니다."),
USER_ALREADY_EXIST("U0004", HttpStatus.CONFLICT, "이미 등록된 이메일입니다."),
NICKNAME_ALREADY_EXIST("U0005", HttpStatus.CONFLICT, "이미 등록된 닉네임입니다."),
USER_NOT_FOUND("USR0001", HttpStatus.NOT_FOUND, "등록된 유저가 아닙니다."),
USER_AUTH_TIME_OUT("USR0002", HttpStatus.FORBIDDEN, "인증 시간이 만료되었습니다."),
USER_AUTH_FAIL("USR0003", HttpStatus.FORBIDDEN, "인증에 실패하였습니다."),
USER_ALREADY_EXIST("USR0004", HttpStatus.CONFLICT, "이미 등록된 이메일입니다."),
NICKNAME_ALREADY_EXIST("USR0005", HttpStatus.CONFLICT, "이미 등록된 닉네임입니다."),

TOKEN_NOT_VALID("T0001", HttpStatus.NOT_ACCEPTABLE, "해당 토큰은 유효하지 않습니다."),
TOKEN_EXPIRATION("T0002", HttpStatus.FORBIDDEN, "토큰이 만료되었습니다."),
TOKEN_NOT_VALID("TKN0001", HttpStatus.NOT_ACCEPTABLE, "해당 토큰은 유효하지 않습니다."),
TOKEN_EXPIRATION("TKN0002", HttpStatus.FORBIDDEN, "토큰이 만료되었습니다."),

REVIEW_NOT_FOUND("RV0001", HttpStatus.NOT_FOUND, "등록된 리뷰가 아닙니다."),
REVIEW_UNAUTHORIZED("RV0002", HttpStatus.FORBIDDEN, "해당 리뷰에 대한 권한이 없습니다."),
REVIEW_ALREADY_MARKED("RV0003", HttpStatus.CONFLICT, "이미 해당 리뷰에 대한 평가를 하였습니다."),
REVIEW_MARK_NOT_FOUND("RV0004", HttpStatus.NOT_FOUND, "등록된 리뷰 평가가 아닙니다."),
STORE_NOT_FOUND("S0001", HttpStatus.NOT_FOUND, "등록된 가게가 아닙니다."),
STORE_NOT_FOUND("STR0001", HttpStatus.NOT_FOUND, "등록된 가게가 아닙니다."),

// report
REPORT_NOT_FOUND("RPT0001", HttpStatus.NOT_FOUND, "등록된 신고가 아닙니다."),
REPORT_ALREADY_EXIST("RPT0002", HttpStatus.CONFLICT, "이미 신고한 리뷰입니다."),
REPORT_REVIEW_SELF("RPT0003", HttpStatus.FORBIDDEN, "자신의 리뷰를 신고할 수 없습니다."),
REPORT_REVIEW_ALREADY("RPT0004", HttpStatus.CONFLICT, "이미 신고한 리뷰입니다."),
;

public final String CODE;
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/everymeal/server/global/util/aws/S3Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
@Component
public class S3Util {

private final AmazonS3 amazonS3;
public static AmazonS3 amazonS3;
public static String bucket;
public static String runningName;

@Value("${cloud.aws.s3.bucket}")
private String bucket;
public void setBucket(String bucket) {
this.bucket = bucket;
}

@Value("${running.name}")
private String runningName;
public void setRunningName(String runningName) {
this.runningName = runningName;
}

public S3Util(
@Value("${cloud.aws.credentials.access-key}") String accessKey,
Expand All @@ -46,7 +52,7 @@ public URL getPresignedUrl(String fileName) {
return amazonS3.generatePresignedUrl(request);
}

public String getImgUrl(String fileName) {
public static String getImgUrl(String fileName) {
URL url = amazonS3.getUrl(bucket, runningName + File.separator + fileName);
return url.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ List<Map<String, Object>> findDayList(
@Param("universityName") String universityName,
@Param("campusName") String campusName);

List<Map<String, Object>> findWeekList(
@Param("weeklyDates") List<String> weeklyDates,
@Param("universityName") String universityName,
@Param("campusName") String campusName);

List<Meal> findAllByOfferedAtOnDateAndMealType(
@Param("offeredAt") String offeredAt,
@Param("mealType") String mealType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package everymeal.server.meal.service;


import everymeal.server.meal.entity.Meal;
import everymeal.server.meal.repository.MealDao;
import everymeal.server.meal.repository.MealMapper;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class MealCommServiceImpl {

private final MealDao mealDao; // JPQL DAO
private final MealMapper mealMapper; // MyBatis DAO

public List<Meal> getMealAllByOfferedAtOnDateAndMealType(
String offeredAt, String mealType, Long restaurantIdx) {
return mealMapper.findAllByOfferedAtOnDateAndMealType(offeredAt, mealType, restaurantIdx);
}

@Transactional
public void saveAll(List<Meal> mealList) {
mealDao.saveAll(mealList);
}

public List<Map<String, Object>> getDayList(
String offeredAt, String universityName, String campusName) {
return mealMapper.findDayList(offeredAt, universityName, campusName);
}
}
59 changes: 11 additions & 48 deletions src/main/java/everymeal/server/meal/service/MealServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
import everymeal.server.meal.controller.dto.response.RestaurantListGetRes;
import everymeal.server.meal.entity.Meal;
import everymeal.server.meal.entity.Restaurant;
import everymeal.server.meal.repository.MealDao;
import everymeal.server.meal.repository.MealMapper;
import everymeal.server.meal.repository.MealRepository;
import everymeal.server.university.entity.University;
import everymeal.server.university.service.UniversityService;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -31,30 +25,9 @@
@Service
public class MealServiceImpl implements MealService {

/**
* ============================================================================================
* DI
* ============================================================================================
*/
private final MealRepository mealRepository; // 기본 JPA 제공 DAO

private final MealDao mealDao; // JPQL DAO
private final MealMapper mealMapper; // MyBatis DAO
private final MealCommServiceImpl mealCommServiceImpl;
private final RestaurantService restaurantServiceImpl;
private final UniversityService universityServiceImpl;

/**
* ============================================================================================
* 학식 식단 등록 ( 주간, 하루 모두 등록 가능 )
*
* @param request 식단 등록 요청 DTO
* @return true
* <p>식당이 없는 경우,
* @throws ApplicationException 404 존재하지 않는 식당입니다. <br>
* REQ 데이터 중 offeredAt, Restaurant, MealType 이 동일한 데이터가 존재한다면,
* @throws ApplicationException 400 등록되어 있는 식단 데이터 보다 과거의 날짜로 등록할 수 없습니다. <br>
* =========================================================================================
*/
@Override
@Transactional
public Boolean createWeekMeal(WeekMealRegisterReq request) {
Expand All @@ -66,8 +39,8 @@ public Boolean createWeekMeal(WeekMealRegisterReq request) {
List<Meal> mealList = new ArrayList<>();
for (MealRegisterReq req : request.registerReqList()) {
// 제공날짜, 학생식당, 식사분류가 동일한 데이터가 이미 존재하면, 덮어쓰기 불가능 오류
if (!mealMapper
.findAllByOfferedAtOnDateAndMealType(
if (!mealCommServiceImpl
.getMealAllByOfferedAtOnDateAndMealType(
req.offeredAt().toString(), req.mealType(), request.restaurantIdx())
.isEmpty()) {
throw new ApplicationException(ExceptionList.INVALID_MEAL_OFFEREDAT_REQUEST);
Expand All @@ -77,34 +50,23 @@ public Boolean createWeekMeal(WeekMealRegisterReq request) {
mealList.add(meal);
}
}
mealDao.saveAll(mealList);
mealCommServiceImpl.saveAll(mealList);
return true;
}
/**
* ============================================================================================
* 학생식당 리스트 조회
*
* @param universityName 학교 한글명
* @param campusName 캠퍼스 이름
* @return List<RestaurantListGetRes>
* <p>학교가 없는 경우,
* @throws ApplicationException 404 존재하지 않는 학교입니다. <br>
* =========================================================================================
*/

@Override
public List<RestaurantListGetRes> getRestaurantList(String universityName, String campusName) {
// 학교 등록 여부 판단
University university = universityServiceImpl.getUniversity(universityName, campusName);
// 학교와 식당 폐업 여부를 키로 조회
List<Restaurant> restaurants =
restaurantServiceImpl.getAllByUniversityAndIsDeletedFalse(university);
restaurantServiceImpl.getAllByUniversityAndIsDeletedFalse(
universityName, campusName);
return RestaurantListGetRes.of(restaurants);
}

@Override
public Map<String, Map<String, List<DayMealGetRes>>> getDayMealListV2(
String universityName, String campusName, String offeredAt) {
var result = mealMapper.findDayList(offeredAt, universityName, campusName);
var result = mealCommServiceImpl.getDayList(offeredAt, universityName, campusName);
return Map.of(offeredAt, DayMealGetRes.of(result));
}

Expand Down Expand Up @@ -135,9 +97,10 @@ public List<Map<String, Map<String, List<DayMealGetRes>>>> getWeekMealList(
}
List<Map<String, Map<String, List<DayMealGetRes>>>> result = new ArrayList<>();
for (LocalDate i = monday; i.isBefore(sunday); i = i.plusDays(1)) {
val row =
Map<String, List<DayMealGetRes>> row =
DayMealGetRes.of(
mealMapper.findDayList(i.toString(), universityName, campusName));
mealCommServiceImpl.getDayList(
i.toString(), universityName, campusName));
result.add(Map.of(i.toString(), row));
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package everymeal.server.meal.service;

import static everymeal.server.global.exception.ExceptionList.RESTAURANT_NOT_FOUND;

import everymeal.server.global.exception.ApplicationException;
import everymeal.server.meal.entity.Restaurant;
import everymeal.server.meal.repository.RestaurantRepository;
import everymeal.server.university.entity.University;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class RestaurantCommServiceImpl {

private final RestaurantRepository restaurantRepository;

public Optional<Restaurant> getRestaurantOptionalEntity(Long restaurantIdx) {
return restaurantRepository.findById(restaurantIdx);
}

public Restaurant getRestaurantEntity(Long restaurantIdx) {
return restaurantRepository
.findById(restaurantIdx)
.orElseThrow(() -> new ApplicationException(RESTAURANT_NOT_FOUND));
}

@Transactional
public Restaurant save(Restaurant restaurant) {
return restaurantRepository.save(restaurant);
}

public List<Restaurant> getAllByUniversityAndIsDeletedFalse(University university) {
return restaurantRepository.findAllByUniversityAndIsDeletedFalse(university);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import everymeal.server.meal.controller.dto.request.RestaurantRegisterReq;
import everymeal.server.meal.entity.Restaurant;
import everymeal.server.university.entity.University;
import java.util.List;

public interface RestaurantService {
Expand All @@ -12,5 +11,5 @@ public interface RestaurantService {

Boolean createRestaurant(RestaurantRegisterReq restaurantRegisterReq);

List<Restaurant> getAllByUniversityAndIsDeletedFalse(University university);
List<Restaurant> getAllByUniversityAndIsDeletedFalse(String universityName, String campusName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import everymeal.server.global.exception.ExceptionList;
import everymeal.server.meal.controller.dto.request.RestaurantRegisterReq;
import everymeal.server.meal.entity.Restaurant;
import everymeal.server.meal.repository.RestaurantRepository;
import everymeal.server.university.entity.University;
import everymeal.server.university.service.UniversityService;
import java.util.List;
Expand All @@ -18,13 +17,13 @@
@Service
public class RestaurantServiceImpl implements RestaurantService {

private final RestaurantRepository restaurantRepository;
private final RestaurantCommServiceImpl restaurantCommServiceImpl;
private final UniversityService universityServiceImpl;

@Override
public Restaurant getRestaurant(Long restaurantIdx) {
return restaurantRepository
.findById(restaurantIdx)
return restaurantCommServiceImpl
.getRestaurantOptionalEntity(restaurantIdx)
.orElseThrow(() -> new ApplicationException(ExceptionList.RESTAURANT_NOT_FOUND));
}

Expand All @@ -41,11 +40,15 @@ public Boolean createRestaurant(RestaurantRegisterReq restaurantRegisterReq) {
.restaurantRegisterReq(restaurantRegisterReq)
.university(university)
.build();
return restaurantRepository.save(restaurant).getIdx() != null;
return restaurantCommServiceImpl.save(restaurant).getIdx() != null;
}

@Override
public List<Restaurant> getAllByUniversityAndIsDeletedFalse(University university) {
return restaurantRepository.findAllByUniversityAndIsDeletedFalse(university);
public List<Restaurant> getAllByUniversityAndIsDeletedFalse(
String universityName, String campusName) {
// 학교 등록 여부 판단
University university = universityServiceImpl.getUniversity(universityName, campusName);

return restaurantCommServiceImpl.getAllByUniversityAndIsDeletedFalse(university);
}
}
Loading
Loading