Skip to content

Commit

Permalink
refactor: vo,엔티티 리팩터링 (#483)
Browse files Browse the repository at this point in the history
* fix: 세션 그룹 테스트 객체 값 수정

* refactor: 사전 식물 필드 VO 래핑

* refactor: 모두의 정원 VO 래핑

* refactor: petPlant 정원 VO 래핑

* refactor: history Mapper 삭제 및 컨벤션에 맞도록 수정

* refactor: WaterDate -> WaterDetail 네이밍 변경

* refactor: 사전 식물 검색 메소드 네이밍 변경

* refactor: 불필요한 public 생성자 private으로 변경

* refactor: 불필요 줄바꿈 수정

---------

Co-authored-by: 이건회 <[email protected]>
  • Loading branch information
Kim0914 and rawfishthelgh authored Jan 2, 2024
1 parent 78ab7ae commit ec03b0b
Show file tree
Hide file tree
Showing 67 changed files with 1,659 additions and 999 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class AuthController {
@PostMapping("/login")
public ResponseEntity<Void> login(
@RequestParam(name = "code") @NotBlank String code,
HttpServletRequest request) {
HttpServletRequest request
) {
Member loginMember = authService.login(code);

HttpSession session = request.getSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ public class DictionaryPlantController {

@GetMapping("/{id}")
public ResponseEntity<DictionaryPlantResponse> read(
@PathVariable @Positive(message = "사전 식물 ID는 1이상의 값이어야 합니다.") Long id) {
@PathVariable @Positive(message = "사전 식물 ID는 1이상의 값이어야 합니다.") Long id
) {
DictionaryPlantResponse dictionaryPlantResponse = dictionaryPlantService.read(id);
return ResponseEntity.ok(dictionaryPlantResponse);
}

@GetMapping
public ResponseEntity<DataResponse<List<DictionaryPlantSearchResponse>>> searchDictionaryPlants(
@RequestParam @NotBlank(message = "검색어는 비어있을 수 없습니다.") String name) {
@RequestParam @NotBlank(message = "검색어는 비어있을 수 없습니다.") String name
) {
DataResponse<List<DictionaryPlantSearchResponse>> dataResponse = dictionaryPlantService.search(name);
return ResponseEntity.ok(dataResponse);
}

@PostMapping
public ResponseEntity<Void> create(
@AdminAuth Admin admin,
@RequestBody @Valid DictionaryPlantCreateRequest request) {
@RequestBody @Valid DictionaryPlantCreateRequest request
) {
Long dictionaryPlantId = dictionaryPlantService.create(request);
return ResponseEntity.created(URI.create("/dictionary-plants/" + dictionaryPlantId)).build();
}
Expand All @@ -61,15 +64,17 @@ public ResponseEntity<Void> create(
public ResponseEntity<Void> update(
@AdminAuth Admin admin,
@PathVariable Long id,
@RequestBody @Valid DictionaryPlantUpdateRequest request) {
@RequestBody @Valid DictionaryPlantUpdateRequest request
) {
dictionaryPlantService.update(id, request);
return ResponseEntity.ok().build();
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(
@AdminAuth Admin admin,
@PathVariable Long id) {
@PathVariable Long id
) {
dictionaryPlantService.delete(id);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ public class GardenController {
@PostMapping
public ResponseEntity<Void> create(
@RequestBody @Valid GardenCreateRequest request,
@Auth Member member) {
@Auth Member member
) {
gardenService.create(request, member);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@GetMapping
public ResponseEntity<GardenResponse> readAll(
@PageableDefault(size = 20) Pageable pageable,
@RequestParam(value = "filter", required = false) List<Long> filters) {
@RequestParam(value = "filter", required = false) List<Long> filters
) {
GardenResponse gardenResponse = gardenService.readAll(pageable, filters);
return ResponseEntity.ok(gardenResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private static final String JOINER_DELIMITER = ", ";

@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex,
HttpHeaders headers, HttpStatusCode status,
WebRequest request) {
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex,
HttpHeaders headers,
HttpStatusCode status,
WebRequest request
) {
List<ObjectError> allErrors = ex.getBindingResult().getAllErrors();
StringJoiner stringJoiner = new StringJoiner(JOINER_DELIMITER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public ResponseEntity<HistoryResponse> read(
@RequestParam @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long petPlantId,
@PageableDefault(size = 20, sort = "date", direction = DESC) Pageable pageable,
@RequestParam(value = "filter", required = false) List<String> filters,
@Auth Member member) {

@Auth Member member
) {
HistoryResponse historyResponse = historyService.read(petPlantId, pageable, member, filters);
return ResponseEntity.ok(historyResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,45 @@ 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();
}

@GetMapping
public ResponseEntity<DataResponse<List<SinglePetPlantResponse>>> readAll(
@Auth Member member) {
public ResponseEntity<DataResponse<List<SinglePetPlantResponse>>> readAll(@Auth Member member) {
DataResponse<List<SinglePetPlantResponse>> response = petPlantService.readAll(member);
return ResponseEntity.ok(response);
}

@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 @@ -33,7 +33,8 @@ public class ReminderController {
public ResponseEntity<Void> water(
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long petPlantId,
@RequestBody @Valid ReminderCreateRequest reminderCreateRequest,
@Auth Member member) {
@Auth Member member
) {
reminderService.water(reminderCreateRequest, petPlantId, member);
return ResponseEntity.noContent().build();
}
Expand All @@ -42,7 +43,8 @@ public ResponseEntity<Void> water(
public ResponseEntity<Void> updateNextWaterDate(
@PathVariable @Positive(message = "반려 식물 ID는 1이상의 값이어야 합니다.") Long petPlantId,
@RequestBody @Valid ReminderUpdateRequest reminderUpdateRequest,
@Auth Member member) {
@Auth Member member
) {
reminderService.updateNextWaterDate(reminderUpdateRequest, petPlantId, member);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.official.pium.domain;

import com.official.pium.domain.vo.CareDetail;
import com.official.pium.domain.vo.Classification;
import com.official.pium.domain.vo.Property;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand All @@ -24,87 +27,41 @@ public class DictionaryPlant extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "name")
private String name;

@Column(name = "image_url")
private String imageUrl;

@Column(name = "family_name")
private String familyName;

@Column(name = "smell")
private String smell;

@Column(name = "poison")
private String poison;

@Column(name = "manage_level")
private String manageLevel;

@Column(name = "grow_speed")
private String growSpeed;

@Column(name = "require_temp")
private String requireTemp;

@Column(name = "minimum_temp")
private String minimumTemp;

@Column(name = "require_humidity")
private String requireHumidity;

@Column(name = "posting_place")
private String postingPlace;
@Embedded
private Classification classification;

@Column(name = "special_manage_info")
private String specialManageInfo;
@Embedded
private Property property;

@Embedded
private WaterCycle waterCycle;
private CareDetail careDetail;

@Builder
private DictionaryPlant(String name, String imageUrl, String familyName, String smell, String poison,
String manageLevel, String growSpeed, String requireTemp, String minimumTemp,
String requireHumidity, String postingPlace, String specialManageInfo,
WaterCycle waterCycle) {
this.name = name;
private DictionaryPlant(
String imageUrl,
Classification classification,
Property property,
CareDetail careDetail
) {
this.imageUrl = imageUrl;
this.familyName = familyName;
this.smell = smell;
this.poison = poison;
this.manageLevel = manageLevel;
this.growSpeed = growSpeed;
this.requireTemp = requireTemp;
this.minimumTemp = minimumTemp;
this.requireHumidity = requireHumidity;
this.postingPlace = postingPlace;
this.specialManageInfo = specialManageInfo;
this.waterCycle = waterCycle;
this.classification = classification;
this.property = property;
this.careDetail = careDetail;
}

public void updateDictionaryPlant(String name, String imageUrl, String familyName, String smell, String poison,
String manageLevel, String growSpeed, String requireTemp, String minimumTemp,
String requireHumidity, String postingPlace, String specialManageInfo,
String spring, String summer, String autumn, String winter) {
this.name = name;
public void updateDictionaryPlant(
String imageUrl,
Classification classification,
Property property,
CareDetail careDetail
) {
this.imageUrl = imageUrl;
this.familyName = familyName;
this.smell = smell;
this.poison = poison;
this.manageLevel = manageLevel;
this.growSpeed = growSpeed;
this.requireTemp = requireTemp;
this.minimumTemp = minimumTemp;
this.requireHumidity = requireHumidity;
this.postingPlace = postingPlace;
this.specialManageInfo = specialManageInfo;
this.waterCycle = WaterCycle.builder()
.spring(spring)
.summer(summer)
.autumn(autumn)
.winter(winter)
.build();
this.classification = classification;
this.property = property;
this.careDetail = careDetail;
}

@Override
Expand Down
40 changes: 16 additions & 24 deletions backend/pium/src/main/java/com/official/pium/domain/Garden.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.official.pium.domain;

import com.official.pium.domain.vo.GardenPlantState;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -48,21 +50,8 @@ public class Garden extends BaseEntity {
@Column(name = "image_url", nullable = false)
private String imageUrl;

@NotBlank
@Column(name = "location", nullable = false)
private String location;

@NotBlank
@Column(name = "flowerpot", nullable = false)
private String flowerpot;

@NotBlank
@Column(name = "light", nullable = false)
private String light;

@NotBlank
@Column(name = "wind", nullable = false)
private String wind;
@Embedded
private GardenPlantState gardenPlantState;

@NotNull
@Column(name = "day_since", nullable = false)
Expand All @@ -84,19 +73,22 @@ public class Garden extends BaseEntity {
private String manageLevel;

@Builder
public Garden(final DictionaryPlant dictionaryPlant, final Member member, final String nickname,
final String imageUrl, final String location,
final String flowerpot, final String light, final String wind, final Long daySince,
final Integer waterCycle, final String content,
final String manageLevel) {
private Garden(
DictionaryPlant dictionaryPlant,
Member member,
String nickname,
String imageUrl,
GardenPlantState gardenPlantState,
Long daySince,
Integer waterCycle,
String content,
String manageLevel
) {
this.dictionaryPlant = dictionaryPlant;
this.member = member;
this.nickname = nickname;
this.imageUrl = imageUrl;
this.location = location;
this.flowerpot = flowerpot;
this.light = light;
this.wind = wind;
this.gardenPlantState = gardenPlantState;
this.daySince = daySince;
this.waterCycle = waterCycle;
this.content = content;
Expand Down
Loading

0 comments on commit ec03b0b

Please sign in to comment.