Skip to content

Commit

Permalink
Merge pull request #92 from teamterning/hotfix/#91
Browse files Browse the repository at this point in the history
[🔥 !hotfix/#91]: 사용자가 해당 공고를 이미 스크랩했을 경우 예외처리 로직 추가
  • Loading branch information
JungYoonShin authored Jul 19, 2024
2 parents 7fdf253 + c26a95d commit dc381d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public enum ErrorMessage {
// 사용자 필터링 정보 생성
FAILED_SIGN_UP_FILTER(404, "회원가입 필터링 정보 생성에 실패하였습니다"),

//스크랩
EXISTS_SCRAP_ALREADY(400, "이미 스크랩했습니다."),

// 로그 아웃
FAILED_SIGN_OUT(404, "로그아웃에 실패하였습니다"),
FAILED_REFRESH_TOKEN_RESET(400, "리프레쉬 토큰 초기화에 실패하였습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.terning.terningserver.dto.calendar.response.MonthlyListResponseDto;
import org.terning.terningserver.dto.user.response.TodayScrapResponseDto;
import org.terning.terningserver.exception.CustomException;
import org.terning.terningserver.jwt.PrincipalHandler;
import org.terning.terningserver.repository.internship_announcement.InternshipRepository;
import org.terning.terningserver.repository.scrap.ScrapRepository;
import org.terning.terningserver.repository.user.UserRepository;
Expand Down Expand Up @@ -117,6 +116,12 @@ public List<DailyScrapResponseDto> getDailyScraps(Long userId, LocalDate date) {
@Override
@Transactional
public void createScrap(Long internshipAnnouncementId, CreateScrapRequestDto request, Long userId) {

//이미 스크랩 했을 경우 예외처리
if(scrapRepository.existsByInternshipAnnouncementIdAndUserId(internshipAnnouncementId, userId)) {
throw new CustomException(EXISTS_SCRAP_ALREADY);
}

InternshipAnnouncement announcement = getInternshipAnnouncement(internshipAnnouncementId);

announcement.updateScrapCount(1);
Expand Down

0 comments on commit dc381d9

Please sign in to comment.