Skip to content

Commit

Permalink
HOT FIX : 클라이언트 요구사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
yummygyudon committed Nov 25, 2023
1 parent 4dce402 commit c530876
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.sopt.sopkerton.program.domain.exception.ProgramSuccess;
import org.sopt.sopkerton.common.response.ApiResponse;
import org.sopt.sopkerton.program.dto.response.ProgramDetailResponse;
import org.sopt.sopkerton.program.dto.response.ProgramListResponse;
import org.sopt.sopkerton.program.service.ProgramService;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -39,10 +40,10 @@ public ResponseEntity<ApiResponse<List<ProgramListResponse>>> programListViewByS
}

@GetMapping("/detail")
public ResponseEntity<ApiResponse> orderProgramDetail(
public ResponseEntity<ApiResponse<ProgramDetailResponse>> orderProgramDetail(
@RequestParam("programId") Long programId
) {
Object programDetail = programService.getProgramDetail(1L, programId);
ProgramDetailResponse programDetail = programService.getProgramDetail(1L, programId);
return ResponseEntity
.status(ProgramSuccess.PROGRAM_DETAIL_VIEW_SUCCESS.getHttpStatus())
.body(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,23 @@

import com.fasterxml.jackson.annotation.JsonProperty;

public abstract class ProgramDetailResponse {
public record ProgramDetailResponse (
@JsonProperty("imageUrl")
String imageUrl,
@JsonProperty("content")
String content,
@JsonProperty("organizationName")
String organizationName,
@JsonProperty("registerAt")
String registerAt,
@JsonProperty("hour")
int hour,
@JsonProperty("salary")
int salary,
@JsonProperty("isApply")
boolean isApply,
@JsonProperty("programType")
String type
){

public record VolunteerDetail(
@JsonProperty("imageUrl")
String imageUrl,
@JsonProperty("content")
String content,
@JsonProperty("organizationName")
String organizationName,
@JsonProperty("registerAt")
String registerAt,
@JsonProperty("hour")
int hour,
@JsonProperty("isApply")
boolean isApply,
@JsonProperty("programType")
String type
) {
}

public record EmploymentDetail(
@JsonProperty("imageUrl")
String imageUrl,
@JsonProperty("content")
String content,
@JsonProperty("organizationName")
String organizationName,
@JsonProperty("registerAt")
String registerAt,
@JsonProperty("salary")
int salary,
@JsonProperty("isApply")
boolean isApply,
@JsonProperty("programType")
String type
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
@Service
@RequiredArgsConstructor
public class ProgramService {
private static final String VOLUNTEER_TYPE = "VOLUNTEERING";
private static final String EMPLOYMENT_TYPE = "EMPLOYMENT";

private final ProgramRepository programRepository;
private final ApplyRepository applyRepository;
Expand Down Expand Up @@ -60,35 +58,22 @@ public List<ProgramListResponse> getStatusDoneProgramList() {
.collect(Collectors.toList());
}

public Object getProgramDetail(Long userId, Long programId) {
public ProgramDetailResponse getProgramDetail(Long userId, Long programId) {
Program program = programRepository.findById(programId)
.orElseThrow(() -> new ProgramException(ProgramError.PROGRAM_NOT_FOUND));
Apply apply = applyRepository.findByUserIdAndProgramId(userId, programId)
.orElseThrow(() -> new ApplyException(ApplyError.APPLY_NOT_FOUND));
boolean isApply = convertToIsApply(apply.getIsApply());
if (program.getType().equals(VOLUNTEER_TYPE)) {
return new ProgramDetailResponse.VolunteerDetail(
program.getImageUrl(),
program.getContent(),
program.getOrganizationName(),
formatToLocalDate(program.getRegisterAt()),
program.getVolunteerHours(),
isApply,
program.getType()
);
}
if (program.getType().equals(EMPLOYMENT_TYPE)){
return new ProgramDetailResponse.EmploymentDetail(
program.getImageUrl(),
program.getContent(),
program.getOrganizationName(),
formatToLocalDate(program.getRegisterAt()),
program.getSalary(),
isApply,
program.getType()
);
}
return null;
return new ProgramDetailResponse(
program.getImageUrl(),
program.getContent(),
program.getOrganizationName(),
formatToLocalDate(program.getRegisterAt()),
program.getVolunteerHours(),
program.getSalary(),
isApply,
program.getType()
);
}

private String formatToLocalDate(LocalDateTime localDateTime) {
Expand Down

0 comments on commit c530876

Please sign in to comment.