Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

상담신청서 에러 핸들링 수정 #55

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ public class Consulting {
private Long issuedAt;

@Column(nullable = false)
private Long classTime;
private Long time;

@Column(nullable = false)
private boolean isAccess;

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@AllArgsConstructor
public class ConsultingSubmitRequest {
@NotNull
private Long classTime;
private Long time;

@NotBlank
private String description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.gapple.weeingback.domain.consulting.exception;

public class ConsultingNotFoundException extends RuntimeException{
public ConsultingNotFoundException(String error){
super(error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.UUID;

public interface ConsultingRepository extends JpaRepository<Consulting, Long> {
boolean existsByClassTime(Long id);
boolean existsByTime(Long id);
void deleteById(UUID id);
Consulting findById(UUID id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +26,7 @@
import java.util.UUID;

@Service
@Slf4j
@RequiredArgsConstructor
public class ConsultingServiceImpl implements ConsultingService {
private final MemberRepository memberRepository;
Expand All @@ -37,10 +40,10 @@ public ResponseEntity<ConsultingSubmitResponse> 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();
}

Expand All @@ -64,7 +67,7 @@ public ResponseEntity<ConsultingShowResponse> 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"));
Expand All @@ -78,7 +81,7 @@ public ResponseEntity<ConsultingCancleResponse> 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"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,4 +64,9 @@ public ResponseEntity<HttpStatus> handleMethodMailSendingException(){
public ResponseEntity<HttpStatus> handleMethodArgumentNotValidException(){
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(ConsultingNotFoundException.class)
public ResponseEntity<HttpStatus> consultingNotFoundException(){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down