Skip to content

Commit

Permalink
refactor: dto, service, controller 메서드에 byShelter 를 붙인다.
Browse files Browse the repository at this point in the history
  • Loading branch information
pushedrumex committed Nov 1, 2023
1 parent 8f71818 commit 0d7a807
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.domain.recruitment.controller;

import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentResponse;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentByShelterResponse;
import com.clova.anifriends.domain.recruitment.service.RecruitmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -17,8 +17,8 @@ public class RecruitmentController {
private final RecruitmentService recruitmentService;

@GetMapping("/shelters/recruitments/{recruitmentId}")
public ResponseEntity<FindRecruitmentResponse> findRecruitmentById(
public ResponseEntity<FindRecruitmentByShelterResponse> findRecruitmentByIdByShelter(
@PathVariable Long recruitmentId) {
return ResponseEntity.ok(recruitmentService.findRecruitmentById(recruitmentId));
return ResponseEntity.ok(recruitmentService.findRecruitmentByIdByShelter(recruitmentId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.LocalDateTime;
import java.util.List;

public record FindRecruitmentResponse(
public record FindRecruitmentByShelterResponse(
String title,
int capacity,
int applicantCount,
Expand All @@ -18,8 +18,8 @@ public record FindRecruitmentResponse(
List<String> imageUrls
) {

public static FindRecruitmentResponse from(Recruitment recruitment) {
return new FindRecruitmentResponse(
public static FindRecruitmentByShelterResponse from(Recruitment recruitment) {
return new FindRecruitmentByShelterResponse(
recruitment.getTitle(),
recruitment.getCapacity(),
recruitment.getApplicantCount(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.clova.anifriends.domain.recruitment.service;

import com.clova.anifriends.domain.recruitment.Recruitment;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentResponse;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentByShelterResponse;
import com.clova.anifriends.domain.recruitment.exception.RecruitmentNotFoundException;
import com.clova.anifriends.domain.recruitment.repository.RecruitmentRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -13,9 +13,9 @@ public class RecruitmentService {

private final RecruitmentRepository recruitmentRepository;

public FindRecruitmentResponse findRecruitmentById(long id) {
public FindRecruitmentByShelterResponse findRecruitmentByIdByShelter(long id) {
Recruitment recruitment = getRecruitmentById(id);
return FindRecruitmentResponse.from(recruitment);
return FindRecruitmentByShelterResponse.from(recruitment);
}

private Recruitment getRecruitmentById(long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.clova.anifriends.base.BaseControllerTest;
import com.clova.anifriends.domain.recruitment.Recruitment;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentResponse;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentByShelterResponse;
import com.clova.anifriends.domain.shelter.Shelter;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -33,9 +33,9 @@ void FindRecruitmentTest() throws Exception {
// given
Shelter shelter = shelter();
Recruitment recruitment = recruitment(shelter);
FindRecruitmentResponse response = findRecruitmentResponse(recruitment);
FindRecruitmentByShelterResponse response = findRecruitmentResponse(recruitment);

when(recruitmentService.findRecruitmentById(anyLong()))
when(recruitmentService.findRecruitmentByIdByShelter(anyLong()))
.thenReturn(response);

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static org.mockito.Mockito.when;

import com.clova.anifriends.domain.recruitment.Recruitment;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentResponse;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentByShelterResponse;
import com.clova.anifriends.domain.recruitment.exception.RecruitmentNotFoundException;
import com.clova.anifriends.domain.recruitment.repository.RecruitmentRepository;
import com.clova.anifriends.domain.shelter.Shelter;
Expand Down Expand Up @@ -41,13 +41,13 @@ void findRecruitmentById() {
// given
Shelter shelter = shelter();
Recruitment recruitment = recruitment(shelter);
FindRecruitmentResponse expected = findRecruitmentResponse(recruitment);
FindRecruitmentByShelterResponse expected = findRecruitmentResponse(recruitment);

when(recruitmentRepository.findById(anyLong())).thenReturn(Optional.of(recruitment));

// when
FindRecruitmentResponse result = recruitmentService
.findRecruitmentById(anyLong());
FindRecruitmentByShelterResponse result = recruitmentService
.findRecruitmentByIdByShelter(anyLong());

// then
assertThat(result).usingRecursiveComparison().isEqualTo(expected);
Expand All @@ -62,7 +62,7 @@ void exceptionWhenRecruitmentIsNotExist() {

// when
Exception exception = catchException(
() -> recruitmentService.findRecruitmentById(anyLong()));
() -> recruitmentService.findRecruitmentByIdByShelter(anyLong()));

// then
assertThat(exception).isInstanceOf(RecruitmentNotFoundException.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.clova.anifriends.domain.recruitment.support.fixture;

import com.clova.anifriends.domain.recruitment.Recruitment;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentResponse;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentByShelterResponse;

public class RecruitmentDtoFixture {

public static FindRecruitmentResponse findRecruitmentResponse(Recruitment recruitment) {
return FindRecruitmentResponse.from(recruitment);
public static FindRecruitmentByShelterResponse findRecruitmentResponse(
Recruitment recruitment) {
return FindRecruitmentByShelterResponse.from(recruitment);
}

}

0 comments on commit 0d7a807

Please sign in to comment.