diff --git a/src/main/java/com/gapple/weeingback/domain/consulting/controller/ConsultingController.java b/src/main/java/com/gapple/weeingback/domain/consulting/controller/ConsultingController.java index 8edbb2a..b2d2876 100644 --- a/src/main/java/com/gapple/weeingback/domain/consulting/controller/ConsultingController.java +++ b/src/main/java/com/gapple/weeingback/domain/consulting/controller/ConsultingController.java @@ -6,11 +6,13 @@ import com.gapple.weeingback.domain.consulting.entity.dto.response.ConsultingSubmitResponse; import com.gapple.weeingback.domain.consulting.service.ConsultingService; import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import com.gapple.weeingback.domain.consulting.entity.dto.request.ConsultingSubmitRequest; import lombok.RequiredArgsConstructor; +@Slf4j @RestController @RequestMapping("/api/consulting") @RequiredArgsConstructor diff --git a/src/main/java/com/gapple/weeingback/domain/consulting/entity/Consulting.java b/src/main/java/com/gapple/weeingback/domain/consulting/entity/Consulting.java index f769187..7762939 100644 --- a/src/main/java/com/gapple/weeingback/domain/consulting/entity/Consulting.java +++ b/src/main/java/com/gapple/weeingback/domain/consulting/entity/Consulting.java @@ -23,7 +23,7 @@ public class Consulting { private Long issuedAt; @Column(nullable = false) - private Long classTime; + private Long time; @Column(nullable = false) private boolean isAccess; @@ -31,13 +31,13 @@ public class Consulting { @Column(columnDefinition = "VARCHAR(3000)") private String description; - public Consulting(Long issuedAt, Long classTime, String description) { + public Consulting(Long issuedAt, Long time, String description) { this.issuedAt = issuedAt; - this.classTime = classTime; + this.time = time; this.description = description; } - public static Consulting toConsulting(Long issuedAt, Long classTime, String description){ - return new Consulting(issuedAt, classTime, description); + public static Consulting toConsulting(Long issuedAt, Long time, String description){ + return new Consulting(issuedAt, time, description); } } diff --git a/src/main/java/com/gapple/weeingback/domain/consulting/entity/dto/request/ConsultingSubmitRequest.java b/src/main/java/com/gapple/weeingback/domain/consulting/entity/dto/request/ConsultingSubmitRequest.java index d43c8ea..a73ea26 100644 --- a/src/main/java/com/gapple/weeingback/domain/consulting/entity/dto/request/ConsultingSubmitRequest.java +++ b/src/main/java/com/gapple/weeingback/domain/consulting/entity/dto/request/ConsultingSubmitRequest.java @@ -11,7 +11,7 @@ @AllArgsConstructor public class ConsultingSubmitRequest { @NotNull - private Long classTime; + private Long time; @NotBlank private String description; diff --git a/src/main/java/com/gapple/weeingback/domain/consulting/exception/ConsultingNotFoundException.java b/src/main/java/com/gapple/weeingback/domain/consulting/exception/ConsultingNotFoundException.java new file mode 100644 index 0000000..fa5ce66 --- /dev/null +++ b/src/main/java/com/gapple/weeingback/domain/consulting/exception/ConsultingNotFoundException.java @@ -0,0 +1,7 @@ +package com.gapple.weeingback.domain.consulting.exception; + +public class ConsultingNotFoundException extends RuntimeException{ + public ConsultingNotFoundException(String error){ + super(error); + } +} diff --git a/src/main/java/com/gapple/weeingback/domain/consulting/repository/ConsultingRepository.java b/src/main/java/com/gapple/weeingback/domain/consulting/repository/ConsultingRepository.java index 04948ab..502b959 100644 --- a/src/main/java/com/gapple/weeingback/domain/consulting/repository/ConsultingRepository.java +++ b/src/main/java/com/gapple/weeingback/domain/consulting/repository/ConsultingRepository.java @@ -7,7 +7,7 @@ import java.util.UUID; public interface ConsultingRepository extends JpaRepository { - boolean existsByClassTime(Long id); + boolean existsByTime(Long id); void deleteById(UUID id); Consulting findById(UUID id); } diff --git a/src/main/java/com/gapple/weeingback/domain/consulting/service/implementation/ConsultingServiceImpl.java b/src/main/java/com/gapple/weeingback/domain/consulting/service/implementation/ConsultingServiceImpl.java index 5fd1815..9ac61a7 100644 --- a/src/main/java/com/gapple/weeingback/domain/consulting/service/implementation/ConsultingServiceImpl.java +++ b/src/main/java/com/gapple/weeingback/domain/consulting/service/implementation/ConsultingServiceImpl.java @@ -7,12 +7,14 @@ import com.gapple.weeingback.domain.consulting.entity.dto.response.ConsultingShowResponse; import com.gapple.weeingback.domain.consulting.entity.dto.request.ConsultingSubmitRequest; import com.gapple.weeingback.domain.consulting.entity.dto.response.ConsultingSubmitResponse; +import com.gapple.weeingback.domain.consulting.exception.ConsultingNotFoundException; import com.gapple.weeingback.domain.consulting.repository.ConsultingRepository; import com.gapple.weeingback.domain.consulting.service.ConsultingService; import com.gapple.weeingback.domain.member.entity.Member; import com.gapple.weeingback.domain.member.repository.MemberRepository; import com.gapple.weeingback.global.exception.SameConsultingException; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; @@ -24,6 +26,7 @@ import java.util.UUID; @Service +@Slf4j @RequiredArgsConstructor public class ConsultingServiceImpl implements ConsultingService { private final MemberRepository memberRepository; @@ -37,10 +40,10 @@ public ResponseEntity submitConsulting(ConsultingSubmi Consulting consulting = Consulting.toConsulting( Instant.now().toEpochMilli(), - request.getClassTime(), + request.getTime(), request.getDescription()); - if(consultingRepository.existsByClassTime(consulting.getClassTime())){ + if(consultingRepository.existsByTime(consulting.getTime())){ throw new SameConsultingException(); } @@ -64,7 +67,7 @@ public ResponseEntity showConsulting() { consults.forEach(consulting -> consultingResponses.add(new ToConsultingResponse( consulting.getId().toString(), consulting.getIssuedAt(), - consulting.getClassTime(), + consulting.getTime(), consulting.getDescription()))); return ResponseEntity.ok().body(new ConsultingShowResponse(consultingResponses, "ok")); @@ -78,7 +81,7 @@ public ResponseEntity cancleConsulting(ConsultingCancl if(consulting != null){ consultingRepository.deleteById(UUID.fromString(request.getConsultingId())); - } else throw new IllegalArgumentException(); + } else throw new ConsultingNotFoundException("상담 신청서를 찾을 수 없습니다."); return ResponseEntity.ok().body(new ConsultingCancleResponse("ok")); } diff --git a/src/main/java/com/gapple/weeingback/global/handler/GlobalExceptionHandler.java b/src/main/java/com/gapple/weeingback/global/handler/GlobalExceptionHandler.java index fa65541..e5cb9d5 100644 --- a/src/main/java/com/gapple/weeingback/global/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/gapple/weeingback/global/handler/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package com.gapple.weeingback.global.handler; +import com.gapple.weeingback.domain.consulting.exception.ConsultingNotFoundException; import com.gapple.weeingback.global.exception.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -63,4 +64,9 @@ public ResponseEntity handleMethodMailSendingException(){ public ResponseEntity handleMethodArgumentNotValidException(){ return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } + + @ExceptionHandler(ConsultingNotFoundException.class) + public ResponseEntity consultingNotFoundException(){ + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e1af18c..2bf749a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -33,7 +33,7 @@ spring: open-in-view: false hibernate: dialect: org.hibernate.dialect.PostgreSQLDialect - ddl-auto: create + ddl-auto: create-drop properties: hibernate:format_sql: true show-sql: true