Skip to content

Commit

Permalink
Merge pull request #146 from TEAM-YOAJUNG/fix/application-status-fix1
Browse files Browse the repository at this point in the history
[FIX] Application Domain 지원 API Status 관련 Logic 수정
  • Loading branch information
EeeasyCode authored Nov 20, 2024
2 parents 4abcfa5 + dced689 commit 0afeaf2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package club.gach_dong.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.Map;
import lombok.Builder;
import lombok.Getter;

public class ClubResponseDTO {
@Getter
@Builder
@Schema(description = "내부 Service Mesh용 DTO (FrontEnd와는 관계가 없습니다.)")
public static class RecruitmentResponseDto {
private Long clubId;
private Long recruitmentId;
private Integer viewCount;
private String title;
private String content;
private Integer recruitmentCount;
private Long applicationFormId;
private String recruitmentStatus;
private LocalDateTime startDate;
private LocalDateTime endDate;
@JsonProperty("processData")
private Map<String, String> processData;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ public ClubAdminCommunicateFailedException() {
super(ErrorCode.CLUB_UNABLE_TO_REQUEST);
}
}

public static class ClubCommunicateFailedException extends DomainException {
public ClubCommunicateFailedException() {
super(ErrorCode.CLUB_UNABLE_TO_REQUEST);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>
@Query("UPDATE application a SET a.applicationStatus = :status WHERE a = :application")
void updateApplicationStatus(@Param("status") String status, @Param("application") Application application);

List<Application> findAllByRecruitmentIdAndApplicationStatus(Long recruitmentId, String status);
@Query("SELECT a FROM application a WHERE a.recruitmentId = :recruitmentId AND a.applicationStatus NOT IN ('TEMPORARY_SAVED')")
List<Application> findAllByRecruitmentIdAndApplicationStatus(@Param("recruitmentId") Long recruitmentId);

Optional<Application> findByRecruitmentIdAndApplicationStatusAndUserId(Long recruitmentId, String status,
String userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public enum ErrorCode {
CLUB_UNAUTHORIZED("CLUBADMIN401", "인증이 필요합니다."),
CLUB_UNABLE_TO_REQUEST("CLUBADMIN402", "클럽 서비스의 인증 요청이 실패했습니다."),

CLUB_UNABLE_TO_GET_PROCESS("CLUB401", "클럽 서비스의 신청 절차(Process)를 불러오는데 실패했습니다."),

USER_NOT_FOUND("USER401", "사용자 ID를 찾을 수 없습니다."),

APPLICATION_FORM_NOT_FOUND("APPLICATIONFORM401", "ApplicationForm이 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,19 @@ public ApplicationResponseDTO.ToCreateApplicationDTO createApplication(Long recr
}
}

String applicationStatus = null;
if (!Objects.equals(toApplyClub.getStatus(), "TEMPORARY_SAVED")) {
applicationStatus = serviceMeshService.getFirstStatus(toApplyClub.getClubId(), recruitmentId);
} else {
applicationStatus = toApplyClub.getStatus();
}

Application application = Application.builder()
.userId(userId)
.recruitmentId(recruitmentId)
.applicationFormId(toApplyClub.getApplicationFormId())
.applicationBody(toApplyClub.getFormBody())
.applicationStatus(toApplyClub.getStatus())
.applicationStatus(applicationStatus)
.clubId(toApplyClub.getClubId())
.submitDate(LocalDateTime.now())
.build();
Expand Down Expand Up @@ -213,7 +220,7 @@ public void deleteApplication(Long recruitmentId, String userId) {
}

//If application couldn't be deleted.
if (Objects.equals(application.getApplicationStatus(), "SAVED")) {
if (!Objects.equals(application.getApplicationStatus(), "TEMPORARY_SAVED")) {
throw new ApplicationNotChangeableException();
}

Expand Down Expand Up @@ -280,8 +287,7 @@ public ApplicationResponseDTO.ToGetApplicationListAdminDTO getApplicationListAdm
authorizationService.getAuthByUserIdAndApplyId(userId, recruitmentId);

List<Application> applicationList = applicationRepository.findAllByRecruitmentIdAndApplicationStatus(
recruitmentId,
"SAVED");
recruitmentId);

if (applicationList.isEmpty()) {
return ApplicationResponseDTO.ToGetApplicationListAdminDTO.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package club.gach_dong.service;

import club.gach_dong.dto.response.AuthResponseDTO;
import club.gach_dong.dto.response.ClubResponseDTO;
import club.gach_dong.exception.ClubException;
import club.gach_dong.exception.UserException;
import java.util.HashMap;
import java.util.List;
Expand All @@ -9,6 +11,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
Expand All @@ -20,6 +23,9 @@ public class ServiceMeshService {
@Value("${msa.url.userDetail}")
private String userDetailUrl;

@Value("${msa.url.clubPublic}")
private String clubPublicUrl;

public final RestClient restClient;

public List<AuthResponseDTO.getUserProfile> getUserProfiles(List<String> userIds) {
Expand Down Expand Up @@ -48,4 +54,35 @@ public List<AuthResponseDTO.getUserProfile> getUserProfiles(List<String> userIds
throw new UserException.UserNotFound();
}
}

public String getFirstStatus(Long clubId, Long recruitmentId) {

String uri = UriComponentsBuilder.fromHttpUrl(clubPublicUrl)
.path("/inner-service/{clubId}/recruitments/{recruitmentId}")
.buildAndExpand(clubId, recruitmentId)
.toUriString();
try {
ResponseEntity<ClubResponseDTO.RecruitmentResponseDto> responseEntity = restClient.get()
.uri(uri)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.toEntity(ClubResponseDTO.RecruitmentResponseDto.class);

ClubResponseDTO.RecruitmentResponseDto responseBody = responseEntity.getBody();
if (responseBody != null && responseBody.getProcessData() != null) {
return responseBody.getProcessData().get("process1");
}

throw new ClubException.ClubCommunicateFailedException();

} catch (RestClientException e) {
System.err.println("REST 클라이언트 오류 발생: " + e.getMessage());
throw new ClubException.ClubAdminCommunicateFailedException();
// return false;
} catch (Exception e) {
System.err.println("예상치 못한 오류 발생: " + e.getMessage());
throw new ClubException.ClubAdminCommunicateFailedException();
// return false;
}
}
}
1 change: 1 addition & 0 deletions application-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ spring:
msa:
url:
club: ${CLUB_URL}
clubPublic: ${CLUB_PUBLIC_URL}
userDetail: ${USER_DETAIL_URL}

0 comments on commit 0afeaf2

Please sign in to comment.