Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 6 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: EAT-SSU Server 개발 & 운영 서버 배포 파이프라인
on:
push:
branches: [ "main", "develop", "hotfix/deploy-prod-fail", "hotfix/deploy-dev-fail" ]
pull_request:
branches: [ "develop" ]

permissions:
contents: read
Expand Down Expand Up @@ -30,7 +32,7 @@ jobs:
${{ runner.os }}-gradle-

- name: dev 프로필 설정
if: github.ref_name == 'develop' || github.ref_name == 'hotfix/deploy-dev-fail'
# if: github.ref_name == 'develop' || github.ref_name == 'hotfix/deploy-dev-fail'
run: |
echo "spring:
profiles:
Expand Down Expand Up @@ -64,7 +66,7 @@ jobs:
docker push ${{ secrets.DOCKER_REPO }}/eatssu-prod

- name: dev 서버 용 Docker 빌드 및 푸시
if: github.ref_name == 'develop' || github.ref_name == 'hotfix/deploy-dev-fail'
# if: github.ref_name == 'develop' || github.ref_name == 'hotfix/deploy-dev-fail'
run: |
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}/eatssu-dev .
docker push ${{ secrets.DOCKER_REPO }}/eatssu-dev
Expand Down Expand Up @@ -99,7 +101,7 @@ jobs:
- name: dev 서버에 배포
uses: appleboy/ssh-action@master
id: deploy-dev
if: github.ref_name == 'develop' || github.ref_name == 'hotfix/deploy-dev-fail'
# if: github.ref_name == 'develop' || github.ref_name == 'hotfix/deploy-dev-fail'
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
Expand All @@ -121,4 +123,4 @@ jobs:
-e EATSSU_AWS_SECRET_KEY_DEV="${{ secrets.EATSSU_AWS_SECRET_KEY_DEV }}" \
-e EATSSU_SLACK_TOKEN="${{ secrets.EATSSU_SLACK_TOKEN }}" \
${{ secrets.DOCKER_REPO }}/eatssu-dev
sudo docker image prune -f
# sudo docker image prune -f
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ out/
### env file ###
.env

/src/main/resources/application-local.yml
/src/main/resources/application-local.yml

### DS File ###
.DS_Store
*/.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

public interface PartnershipRestaurantRepository extends JpaRepository<PartnershipRestaurant, Long> {
@Query("""
SELECT DISTINCT pr FROM PartnershipRestaurant pr
LEFT JOIN FETCH pr.partnerships p
LEFT JOIN FETCH p.partnershipCollege
LEFT JOIN FETCH p.partnershipDepartment
WHERE p.endDate is null or p.endDate >= CURRENT_DATE""")
SELECT DISTINCT pr FROM PartnershipRestaurant pr
JOIN FETCH pr.partnerships p
LEFT JOIN FETCH p.partnershipCollege
LEFT JOIN FETCH p.partnershipDepartment
WHERE p.endDate IS NULL OR p.endDate >= CURRENT_DATE
""")
List<PartnershipRestaurant> findAllWithDetails();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public record ReportCreateRequest(
@Schema(description = "신고할 리뷰 id", example = "4")
Long reviewId,

@Schema(description = "신고 타입", example = "BAD_WORD")
@Schema(description = "신고 타입", example = "NO_ASSOCIATE_CONTENT")
ReportType reportType,

@Schema(description = "신고 내용", example = "음란성, 욕설 등 부적절한 내용")
@Schema(description = "신고 내용", example = "리뷰 작성 취지에 맞지 않는 내용")
String content) {

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
package ssu.eatssu.domain.report.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ssu.eatssu.domain.review.entity.Report;

import java.time.LocalDateTime;

public interface ReportRepository extends JpaRepository<Report, Long> {

@Query("""
SELECT CASE WHEN COUNT(r) > 0 THEN true ELSE false END
FROM Report r
WHERE r.user.id = :userId
AND r.review.id = :reviewId
AND r.createdDate >= CURRENT_TIMESTAMP - 1
""")
boolean existsRecentReport(@Param("userId") Long userId,
@Param("reviewId") Long reviewId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

JPQL 쿼리에 두 가지 개선점을 제안합니다.

  1. SELECT CASE WHEN COUNT(r) > 0 THEN true ELSE false END 구문은 SELECT COUNT(r) > 0으로 단순화할 수 있습니다. Spring Data JPA가 이 결과를 boolean으로 올바르게 처리합니다.
  2. 더 중요한 점은, r.createdDate >= CURRENT_TIMESTAMP - 1과 같은 날짜/시간 연산은 JPQL 표준이 아니며, 사용하는 데이터베이스(H2, MySQL, PostgreSQL 등)에 따라 다르게 동작할 수 있어 이식성을 해칠 수 있습니다. 서비스 레이어에서 시간 임계값(예: 24시간 전)을 계산하여 파라미터로 전달하는 것이 더 안정적이고 명확한 방법입니다.

아래와 같이 메서드 시그니처와 쿼리를 수정하는 것을 권장합니다. 이 변경은 ReportService에서의 호출 방식 수정도 필요합니다.

    @Query("""
    SELECT count(r) > 0
    FROM Report r
    WHERE r.user.id = :userId
      AND r.review.id = :reviewId
      AND r.createdDate >= :threshold
""")
    boolean existsRecentReport(@Param("userId") Long userId,
                               @Param("reviewId") Long reviewId,
                               @Param("threshold") LocalDateTime threshold);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import ssu.eatssu.global.handler.response.BaseException;
import ssu.eatssu.global.log.event.LogEvent;

import static ssu.eatssu.global.handler.response.BaseResponseStatus.NOT_FOUND_REVIEW;
import static ssu.eatssu.global.handler.response.BaseResponseStatus.NOT_FOUND_USER;
import static ssu.eatssu.global.handler.response.BaseResponseStatus.*;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

스타일 가이드 3번 규칙에 따라 와일드카드(*) import는 사용하지 않는 것이 좋습니다.1 코드의 가독성을 높이고 불필요한 클래스가 네임스페이스에 포함되는 것을 방지하기 위해, 필요한 static 멤버만 명시적으로 import하는 것을 권장합니다.

Suggested change
import static ssu.eatssu.global.handler.response.BaseResponseStatus.*;
import static ssu.eatssu.global.handler.response.BaseResponseStatus.NOT_FOUND_REVIEW;
import static ssu.eatssu.global.handler.response.BaseResponseStatus.NOT_FOUND_USER;
import static ssu.eatssu.global.handler.response.BaseResponseStatus.RECENT_REPORT_ON_REVIEW;

Style Guide References

Footnotes

  1. Do not use wildcard when importing libraries


@RequiredArgsConstructor
@Service
Expand All @@ -37,6 +36,10 @@ public Report reportReview(CustomUserDetails userDetails, ReportCreateRequest re
Review review = reviewRepository.findById(request.reviewId())
.orElseThrow(() -> new BaseException(NOT_FOUND_REVIEW));

if(reportRepository.existsRecentReport(user.getId(),review.getId())){
throw new BaseException(RECENT_REPORT_ON_REVIEW);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

ReportRepository에 제안된 변경사항과 일관성을 맞추기 위해, existsRecentReport 메서드를 호출할 때 24시간 전의 시간 임계값을 파라미터로 전달하도록 수정해야 합니다. 이렇게 하면 시간 계산 로직이 서비스 레이어로 이동하여, 데이터베이스에 독립적이고 명확한 코드가 됩니다. 이 변경을 적용하려면 java.time.LocalDateTime을 import해야 할 수 있습니다.

Suggested change
if(reportRepository.existsRecentReport(user.getId(),review.getId())){
throw new BaseException(RECENT_REPORT_ON_REVIEW);
}
if(reportRepository.existsRecentReport(user.getId(), review.getId(), java.time.LocalDateTime.now().minusHours(24))){
throw new BaseException(RECENT_REPORT_ON_REVIEW);
}


Report report = Report.create(user, review, request, ReportStatus.PENDING);
reportRepository.save(report);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public enum BaseResponseStatus {
EXISTED_MEAL(false, HttpStatus.BAD_REQUEST, 40011, "이미 존재하는 식단입니다."),
INVALID_TARGET_TYPE(false, HttpStatus.BAD_REQUEST, 40012, "잘못된 targetType 입니다."),
MISSING_USER_DEPARTMENT(false, HttpStatus.BAD_REQUEST, 40013, "사용자의 학과 정보가 없습니다."),
RECENT_REPORT_ON_REVIEW(false, HttpStatus.BAD_REQUEST, 40014, "24시간 이내에 동일 댓글을 신고했습니다."),

/**
* 401 UNAUTHORIZED 권한없음(인증 실패)
Expand Down
Loading