Skip to content

Commit

Permalink
Merge pull request #248 from techeer-sv/BE/#247
Browse files Browse the repository at this point in the history
BE/#247 프로젝트 참가 중복 신청 방지 로직 추가
  • Loading branch information
youKeon committed Oct 2, 2023
2 parents be13bc8 + 56eafd6 commit 126c359
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

public interface ApplicationRepository extends JpaRepository<Application, Long>, ApplicationCustomRepository {
Page<Application> findAllByRecruitmentId(Long id, Pageable pageable);

Boolean existsByMemberIdAndRecruitmentId(Long memberId, Long recruitmentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.graphy.backend.domain.recruitment.repository.ApplicationRepository;
import com.graphy.backend.global.error.ErrorCode;
import com.graphy.backend.global.error.exception.EmptyResultException;
import com.graphy.backend.global.error.exception.InvalidMemberException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -34,6 +35,9 @@ public class ApplicationService {
public void addApplication(CreateApplicationRequest request, Member loginUser) {
Recruitment recruitment = recruitmentService.getRecruitmentById(request.getRecruitmentId());

if (applicationRepository.existsByMemberIdAndRecruitmentId(loginUser.getId(), recruitment.getId()))
throw new InvalidMemberException(ErrorCode.APPLICATION_ALREADY_EXIST);

Application application = request.toEntity(recruitment, loginUser);

if (request.getTechLevels() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum ErrorCode {

// Application
APPLICATION_NOT_EXIST(HttpStatus.NOT_FOUND, "AP001", "존재하지 않는 프로젝트 참가 신청서"),
APPLICATION_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "AP002", "이미 존재하는 프로젝트 참가 신청서"),

// ChatGPT,
REQUEST_TOO_MUCH_TOKENS(HttpStatus.BAD_REQUEST, "AI001", "GPT에 보내야 할 요청 길이 제한 초과"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import lombok.Getter;

@Getter
public class InvalidMemberException extends RuntimeException{
public class InvalidMemberException extends BusinessException {
private final ErrorCode errorCode;

public InvalidMemberException(ErrorCode errorCode) {
super(errorCode.getMessage());
super(errorCode);
this.errorCode = errorCode;
}
}

0 comments on commit 126c359

Please sign in to comment.