Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOT FIX : 클라이언트 요구사항 반영 #22

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading