Skip to content

Commit

Permalink
refactor: 사전 식물 검색 메소드 네이밍 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
rawfishthelgh committed Jan 2, 2024
1 parent f5410f0 commit 60dbbf9
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public class PetPlantController {

@GetMapping("/{id}")
public ResponseEntity<PetPlantResponse> read(
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long id,
@Auth Member member
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long id,
@Auth Member member
) {
PetPlantResponse petPlantResponse = petPlantService.read(id, member);
return ResponseEntity.ok(petPlantResponse);
}

@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Void> create(
@RequestPart(name = "request") @Valid PetPlantCreateRequest request,
@RequestPart(name = "image", required = false) MultipartFile multipartFile,
@Auth Member member
@RequestPart(name = "request") @Valid PetPlantCreateRequest request,
@RequestPart(name = "image", required = false) MultipartFile multipartFile,
@Auth Member member
) {
PetPlantResponse petPlantResponse = petPlantService.create(request, multipartFile, member);
return ResponseEntity.created(URI.create("/pet-plants/" + petPlantResponse.getId())).build();
Expand All @@ -61,19 +61,19 @@ public ResponseEntity<DataResponse<List<SinglePetPlantResponse>>> readAll(@Auth

@PatchMapping(path = "/{id}", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Void> update(
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long id,
@RequestPart(name = "request") @Valid PetPlantUpdateRequest petPlantUpdateRequest,
@RequestPart(name = "image", required = false) MultipartFile multipartFile,
@Auth Member member
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long id,
@RequestPart(name = "request") @Valid PetPlantUpdateRequest petPlantUpdateRequest,
@RequestPart(name = "image", required = false) MultipartFile multipartFile,
@Auth Member member
) {
petPlantService.update(id, petPlantUpdateRequest, multipartFile, member);
return ResponseEntity.ok().build();
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long id,
@Auth Member member
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long id,
@Auth Member member
) {
petPlantService.delete(id, member);
return ResponseEntity.noContent().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.official.pium.domain.DictionaryPlant;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface DictionaryPlantRepository extends JpaRepository<DictionaryPlant, Long> {

List<DictionaryPlant> findDictionaryPlantsByClassification_NameContains(String name);
@Query("SELECT dp FROM DictionaryPlant dp WHERE dp.classification.name LIKE %:name%")
List<DictionaryPlant> searchDictionaryPlantByName(@Param("name") String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<PetPlant> findAllByWaterNotification(LocalDate date) {
.from(petPlant)
.join(petPlant.member, member)
.fetchJoin()
.where(petPlant.waterDate.nextWaterDate.eq(date), member.deviceToken.isNotNull())
.where(petPlant.waterDetail.nextWaterDate.eq(date), member.deviceToken.isNotNull())
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public DictionaryPlantResponse read(Long id) {
}

public DataResponse<List<DictionaryPlantSearchResponse>> search(String name) {
List<DictionaryPlant> dictionaryPlants = dictionaryPlantRepository.findDictionaryPlantsByClassification_NameContains(
List<DictionaryPlant> dictionaryPlants = dictionaryPlantRepository.searchDictionaryPlantByName(
name);

List<DictionaryPlantSearchResponse> dictionaryPlantSearchResponses = dictionaryPlants.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private PetPlant createPetPlant(
.petPlantState(request.toPetPlantState())
.birthDate(request.getBirthDate())
.waterCycle(request.getWaterCycle())
.waterDate(request.toWaterDate())
.waterDetail(request.toWaterDate())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@RequiredArgsConstructor
public class ReminderService {

public static final String SORT_CONDITION = "waterDetail_nextWaterDate";

private final PetPlantRepository petPlantRepository;
private final ApplicationEventPublisher publisher;

Expand Down Expand Up @@ -63,7 +65,7 @@ private void checkOwner(PetPlant petPlant, Member member) {

public DataResponse<List<ReminderResponse>> readAll(Member member) {
List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(member.getId(),
Sort.by(Direction.ASC, "waterDate_nextWaterDate"));
Sort.by(Direction.ASC, SORT_CONDITION));

List<ReminderResponse> reminderResponses = petPlants.stream()
.map(petPlant -> ReminderResponse.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private History generateHistory(LocalDate lastWaterDate) {
)
.waterCycle(5)
.birthDate(LocalDate.of(2021, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(lastWaterDate)
.nextWaterDate(lastWaterDate.plusDays(5))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PetPlantTest {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2022, 7, 1))
.nextWaterDate(LocalDate.of(2022, 7, 8))
Expand Down Expand Up @@ -120,7 +120,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2022, 7, 1))
.nextWaterDate(LocalDate.now().minusDays(3))
Expand Down Expand Up @@ -358,7 +358,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2022, 7, 1))
.nextWaterDate(baseDate.minusDays(days))
Expand Down Expand Up @@ -389,7 +389,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2022, 7, 1))
.nextWaterDate(LocalDate.now())
Expand Down Expand Up @@ -419,7 +419,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(WaterDetail.builder()
.waterDetail(WaterDetail.builder()
.lastWaterDate(LocalDate.of(2022, 7, 1))
.nextWaterDate(LocalDate.now().plusDays(days))
.build())
Expand Down Expand Up @@ -460,7 +460,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2022, 7, 1))
.nextWaterDate(now.plusDays(days))
Expand Down Expand Up @@ -537,7 +537,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2023, 7, 1))
.nextWaterDate(LocalDate.of(2023, 7, 17))
Expand All @@ -564,7 +564,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2023, 7, 1))
.nextWaterDate(LocalDate.of(2023, 7, 17))
Expand Down Expand Up @@ -592,7 +592,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(lastWaterDate)
.nextWaterDate(LocalDate.of(2022, 7, 17))
Expand Down Expand Up @@ -620,7 +620,7 @@ class 반려_식물_정보_수정 {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(lastWaterDate)
.nextWaterDate(LocalDate.of(2022, 7, 17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PetPlantFixture {
)
.waterCycle(7)
.birthDate(LocalDate.of(2022, 7, 1))
.waterDate(
.waterDetail(
WaterDetail.builder()
.lastWaterDate(LocalDate.of(2022, 7, 1))
.nextWaterDate(LocalDate.of(2022, 7, 8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private PetPlant createPetPlant() {
.build()
)
.birthDate(LocalDate.of(2020, 1, 3))
.waterDate(
.waterDetail(
WaterDetail.builder()
.nextWaterDate(LocalDate.of(2020, 1, 3))
.lastWaterDate(LocalDate.of(2020, 1, 3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private PetPlant savePetPlant(Member member, DictionaryPlant dictionaryPlant) {
.build()
)
.birthDate(LocalDate.of(2021, 6, 4))
.waterDate(
.waterDetail(
WaterDetail.builder()
.nextWaterDate(LocalDate.of(2021, 6, 4))
.lastWaterDate(LocalDate.of(2021, 6, 4))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private PetPlant createPetPlant() {
.build()
)
.birthDate(LocalDate.of(2020, 1, 3))
.waterDate(
.waterDetail(
WaterDetail.builder()
.nextWaterDate(LocalDate.of(2020, 1, 3))
.lastWaterDate(LocalDate.of(2020, 1, 3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private PetPlant savePetPlantWithNextWaterDate(LocalDate nextWaterDate) {
.wind("testWind")
.build())
.birthDate(LocalDate.of(2000, 7, 1))
.waterDate(WaterDetail.builder()
.waterDetail(WaterDetail.builder()
.nextWaterDate(nextWaterDate)
.lastWaterDate(LocalDate.of(2022, 7, 1))
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public PetPlant build() {
.build()
)
.birthDate(LocalDate.of(2000, 6, 14))
.waterDate(
.waterDetail(
WaterDetail.builder()
.nextWaterDate(LocalDate.of(2020, 2, 3))
.lastWaterDate(LocalDate.of(2022, 3, 4))
Expand Down

0 comments on commit 60dbbf9

Please sign in to comment.