Skip to content

Commit

Permalink
๐Ÿ”จ Refactor: refactor job application
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhacandy authored Jul 28, 2024
2 parents 36a9521 + 862f568 commit 5d38495
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package cotato.growingpain.log.domain.controller;

import cotato.growingpain.common.Response;
import cotato.growingpain.log.domain.dto.JobPostRequestDTO;
import cotato.growingpain.log.domain.dto.JobPostRetrieveDTO;
import cotato.growingpain.log.domain.entity.JobPost;
import cotato.growingpain.log.domain.service.JobService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
Expand All @@ -24,16 +30,23 @@ public class JobPostController {

private final JobService jobService;

@PostMapping
public ResponseEntity<JobPost> createJobPost(@RequestBody @Valid JobPostRequestDTO jobPostRequestDTO) {
JobPost jobPost = jobService.createJobPost(jobPostRequestDTO);
return ResponseEntity.ok(jobPost);
@Operation(summary = "์ง€์› ํ˜„ํ™ฉ ๋“ฑ๋ก", description = "์ง€์› ํ˜„ํ™ฉ์„ ๋“ฑ๋กํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@PostMapping("")
@ResponseStatus(HttpStatus.CREATED)
public Response<JobPost> createJobPost(@RequestBody @Valid JobPostRequestDTO request,
@AuthenticationPrincipal Long memberId) {
jobService.createJobPost(request, memberId);
return Response.createSuccess("์ง€์› ํ˜„ํ™ฉ ๋“ฑ๋ก ์™„๋ฃŒ", null);
}

@GetMapping
public ResponseEntity<List<JobPostRetrieveDTO>> getJobPosts(
@RequestParam Long memberId) {
@Operation(summary = "์ง€์› ํ˜„ํ™ฉ ์กฐํšŒ", description = "์ง€์› ํ˜„ํ™ฉ์„ ์กฐํšŒํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@GetMapping("")
@ResponseStatus(HttpStatus.OK)
public Response<List<JobPostRetrieveDTO>> getJobPosts(
@AuthenticationPrincipal Long memberId) {
List<JobPostRetrieveDTO> retrievedJobPost = jobService.jobPostRetrieveList(memberId);
return ResponseEntity.ok(retrievedJobPost);
return Response.createSuccess("์ง€์› ํ˜„ํ™ฉ ์กฐํšŒ ์™„๋ฃŒ", retrievedJobPost);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@Builder
public record JobApplicationRetrieveDTO(
String applicationType,
String status
String status,
String endDate
) {
public static JobApplicationRetrieveDTO fromEntity(JobApplication jobApplication) {
String status = jobApplication.getResult().toString();
Expand All @@ -22,6 +23,7 @@ public static JobApplicationRetrieveDTO fromEntity(JobApplication jobApplication
return JobApplicationRetrieveDTO.builder()
.applicationType(String.valueOf(jobApplication.getApplicationType()))
.status(status)
.endDate(jobApplication.getApplicationCloseDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public record JobPostRequestDTO(
@NotBlank String companyName,
@NotBlank String jobPart,
Long memberId,
List<JobApplicationRequestDTO> jobApplications
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ public class JobService {

private final ApplicationDetailRepository applicationDetailRepository;

public JobPost createJobPost(JobPostRequestDTO jobPostRequestDTO) {
Long memberId = jobPostRequestDTO.memberId();
log.debug("Trying to fetch member with ID: {}", memberId);
public JobPost createJobPost(JobPostRequestDTO jobPostRequest, Long memberId) {

Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new RuntimeException("Member not found with ID: " + memberId));

log.info("Found member with ID: {}", member.getId());
log.info(jobPostRequestDTO.jobApplications().toString());
log.info(jobPostRequest.jobApplications().toString());

JobPost jobPost = jobPostRequestDTO.toEntity(member);
JobPost jobPost = jobPostRequest.toEntity(member);

log.info("Creating job post with job part: {}", jobPost.getJobPart());
log.debug("JobPost details: {}", jobPost);
Expand Down

0 comments on commit 5d38495

Please sign in to comment.