Skip to content
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-oauth2-client'

testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
}


Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/kidsqueue/kidsqueue/common/Api.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kidsqueue.kidsqueue.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/kidsqueue/kidsqueue/common/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@MappedSuperclass
@Data
@SuperBuilder
@NoArgsConstructor
@Data // TODO : data 어노테이션의 위험성 상 제거하는 게 좋을 듯함
@SuperBuilder(builderMethodName = "superBuilder")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Comment on lines +19 to +21
Copy link
Contributor Author

@DFDRDODM95 DFDRDODM95 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data 어노테이션의 위험성을 경계해서 우선 주석으로 남겨 놓았고
실무에서 Lombok 사용법

builder의 이름 중복 문제는 SuperBuilder의 것을 변경하도록 했습니다.

또한 기본 생성자 어노테이션의 접근 범위를 지정하여 보호 수준을 만들었습니다.

@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class) // 생성 일자, 수정 일자 자동으로 채워줌
public class BaseEntity { // 공통 속성을 묶는 엔티티
Expand All @@ -40,4 +40,8 @@ public class BaseEntity { // 공통 속성을 묶는 엔티티
public boolean isActive() { // 데이터베이스 저장용 : Integer, 실제 로직용: boolean
return isActive != null && isActive == 1;
}

public void softDelete() {
this.isActive = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.kidsqueue.kidsqueue.config.objectMapper;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ObjectMapperConfig {

@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();

objectMapper.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy());

return objectMapper;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.kidsqueue.kidsqueue.config.swagger;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.core.jackson.ModelResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {
@Bean
public ModelResolver modelResolver(ObjectMapper objectMapper) {
return new ModelResolver(objectMapper);
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
package com.kidsqueue.kidsqueue.review.controller;

import com.kidsqueue.kidsqueue.common.Api;
import com.kidsqueue.kidsqueue.review.dtos.ReviewCreateDto;
import com.kidsqueue.kidsqueue.review.dtos.ReviewDto;
import com.kidsqueue.kidsqueue.review.dtos.ReviewUpdateDto;
import com.kidsqueue.kidsqueue.review.model.*;
import com.kidsqueue.kidsqueue.review.service.ReviewService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/review")
Expand All @@ -28,15 +19,18 @@ public class ReviewController {

private final ReviewService reviewService;

public Api<List<ReviewDto>> get(
// TODO : 반환 값을 바꿔볼까 고민 중

// TODO : 동작 안 함 /api/review?sortCondition=desc로 url 입력한 결과.
// 디버깅 필요함
@GetMapping
public Api<List<ReviewReadResponse>> get(
@PageableDefault(page = 0, size = 10) Pageable pageable,
@RequestParam(required = false) String sortCondition,
@RequestParam(required = false) String name
@RequestParam(required = false) String sortCondition
) {
System.out.println("sortCondition = " + sortCondition);
System.out.println("name = " + name);

Api<List<ReviewDto>> apiResponse;
Api<List<ReviewReadResponse>> apiResponse;

if ("desc".equals(sortCondition)) {
apiResponse = reviewService.findAllDesc(pageable);
Expand All @@ -50,9 +44,9 @@ public Api<List<ReviewDto>> get(
return apiResponse;
}

@GetMapping("/{id}")
public ResponseEntity<Api<ReviewDto>> getReviewById(@PathVariable Long id) {
Api<ReviewDto> apiResponse = reviewService.findReviewById(id);
@GetMapping("/{review_id}")
public ResponseEntity<Api<ReviewReadResponse>> getReviewById(@PathVariable("review_id") Long id) {
Api<ReviewReadResponse> apiResponse = reviewService.findReviewById(id);

if (apiResponse.getData() != null) {
apiResponse.setStatus(Api.SUCCESS_STATUS);
Expand All @@ -66,8 +60,8 @@ public ResponseEntity<Api<ReviewDto>> getReviewById(@PathVariable Long id) {
}

@PostMapping
public ResponseEntity<Api<ReviewCreateDto>> createReview(@RequestBody ReviewCreateDto reviewCreateDto) {
Api<ReviewCreateDto> apiResponse = reviewService.createReview(reviewCreateDto);
public ResponseEntity<Api<ReviewCreateResponse>> createReview(@RequestBody ReviewCreateRequest reviewCreateRequest) {
Api<ReviewCreateResponse> apiResponse = reviewService.createReview(reviewCreateRequest);

if (apiResponse.getData() != null) {
apiResponse.setStatus(Api.SUCCESS_STATUS);
Expand All @@ -80,10 +74,10 @@ public ResponseEntity<Api<ReviewCreateDto>> createReview(@RequestBody ReviewCrea
}
}

@PatchMapping("/{id}")
public ResponseEntity<Api<ReviewUpdateDto>> updateReview(@PathVariable Long id,
@RequestBody ReviewUpdateDto updateDto) {
Api<ReviewUpdateDto> apiResponse = reviewService.updateReview(id, updateDto);
@PatchMapping("/{review_id}")
public ResponseEntity<Api<ReviewUpdateResponse>> updateReview(@PathVariable("review_id") Long id,
@RequestBody ReviewUpdateRequest updateDto) {
Api<ReviewUpdateResponse> apiResponse = reviewService.updateReview(id, updateDto);

if (apiResponse.getData() != null) {
apiResponse.setStatus(Api.SUCCESS_STATUS);
Expand All @@ -96,8 +90,8 @@ public ResponseEntity<Api<ReviewUpdateDto>> updateReview(@PathVariable Long id,
}
}

@DeleteMapping("/{id}")
public ResponseEntity<Api<String>> deleteReview(@PathVariable Long id) {
@DeleteMapping("/{review_id}")
public ResponseEntity<Api<String>> deleteReview(@PathVariable("review_id") Long id) {
Api<String> apiResponse = reviewService.deleteReview(id);

if (apiResponse.getData() == null) {
Expand All @@ -110,4 +104,5 @@ public ResponseEntity<Api<String>> deleteReview(@PathVariable Long id) {
return new ResponseEntity<>(apiResponse, HttpStatus.BAD_REQUEST);
}
}

}
39 changes: 39 additions & 0 deletions src/main/java/com/kidsqueue/kidsqueue/review/db/Review.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.kidsqueue.kidsqueue.review.db;

import com.kidsqueue.kidsqueue.common.BaseEntity;
import com.kidsqueue.kidsqueue.hospital.db.Hospital;
import com.kidsqueue.kidsqueue.parent.db.Parent;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "review")
public class Review extends BaseEntity {
private String title;
private Integer score;
private String description;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "hospital_id")
private Hospital hospital;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private Parent parent;

@Builder
public Review(Long id, Integer isActive, LocalDateTime createdBy, LocalDateTime updatedBy, String title, Integer score, String description, Hospital hospital, Parent parent) {
super(id, isActive, createdBy, updatedBy);
this.title = title;
this.score = score;
this.description = description;
this.hospital = hospital;
this.parent = parent;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.kidsqueue.kidsqueue.review.db;

import com.kidsqueue.kidsqueue.hospital.db.Hospital;
import com.kidsqueue.kidsqueue.review.model.Review;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface ReviewRepository extends JpaRepository<Review, Long> {
// TODO : localDateTime으로 내림차순 정렬이 안 되어서 auto increment 되는 아이디를 기준으로 정렬했음
Expand All @@ -16,6 +14,8 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {

Page<Review> findAllByIsActiveOrderByIdAsc(Integer isActive, Pageable pageable);

Optional<Review> findByIdAndIsActive(Long id, Integer isActive);


@Query("select r from Review r " +
" join fetch r.hospital")
Expand Down

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/com/kidsqueue/kidsqueue/review/dtos/ReviewDto.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.kidsqueue.kidsqueue.review.exception;

import com.kidsqueue.kidsqueue.common.error.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@AllArgsConstructor
@Getter
public enum ReviewErrorCode implements ErrorCode {
Review_Not_Found(HttpStatus.NOT_FOUND, "No Review"),
Hospital_Not_Found(HttpStatus.NOT_FOUND, "No Hospital"),
Parent_Not_Found(HttpStatus.NOT_FOUND, "No Parent"),
;
Comment on lines +8 to +14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorCode 관련 작업은 이전에 진행한 것으로 변경 가능성이 남아있는 상태입니다.


private final HttpStatus httpStatusCode;
private final String description;
}
Loading