- 
                Notifications
    You must be signed in to change notification settings 
- Fork 164
[Spring MVC] 홍석주 미션 제출합니다. #415
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
          
     Open
      
      
            somefood
  wants to merge
  9
  commits into
  next-step:somefood
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
somefood:week3
  
      
      
   
  
    
  
  
  
 
  
      
    base: somefood
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            9 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3e10081
              
                8단계 - 시간 관리 기능 작성
              
              
                somefood 58bbf3e
              
                9단계 - 기존 코드 수정
              
              
                somefood 4583056
              
                10단계 - 계층화 리팩터링
              
              
                somefood 6088940
              
                테스트 변경 사항 수정
              
              
                somefood 3d4516f
              
                ROWMAPPER 공통화
              
              
                somefood dc9ccee
              
                쿼리 String 멀티라인으로 수정
              
              
                somefood 0d5a4b6
              
                시간 관리 페이지 연결
              
              
                somefood d5630c0
              
                시간 등록 시 중복인 경우 예외 처리
              
              
                somefood ed1aec8
              
                시간 등록 시 중복인 경우 예외 처리
              
              
                somefood File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package roomescape.time; | ||
|  | ||
| import java.time.LocalTime; | ||
|  | ||
| public class Time { | ||
|  | ||
| private Long id; | ||
|  | ||
| private LocalTime time; | ||
|  | ||
| private Time(Long id, LocalTime time) { | ||
| this.id = id; | ||
| this.time = time; | ||
| } | ||
|  | ||
| public static Time ofNew(LocalTime time) { | ||
| return new Time(null, time); | ||
| } | ||
|  | ||
| public static Time ofExist(Long id, LocalTime time) { | ||
| return new Time(id, time); | ||
| } | ||
|  | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
|  | ||
| public LocalTime getTime() { | ||
| return time; | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package roomescape.time; | ||
|  | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|  | ||
| public interface TimeDao { | ||
|  | ||
| Optional<Time> findById(Long id); | ||
|  | ||
| Optional<Time> findByTime(Time time); | ||
|  | ||
| List<Time> findAll(); | ||
|  | ||
| Time save(Time time); | ||
|  | ||
| void delete(Long id); | ||
| } | 
        
          
          
            64 changes: 64 additions & 0 deletions
          
          64 
        
  src/main/java/roomescape/time/controller/TimeCommandController.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package roomescape.time.controller; | ||
|  | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import roomescape.time.Time; | ||
| import roomescape.time.TimeDao; | ||
| import roomescape.time.dto.TimeCreateRequest; | ||
| import roomescape.time.dto.TimeCreateResponse; | ||
| import roomescape.time.exception.TimeAlreadyExistException; | ||
| import roomescape.time.exception.TimeNotFoundException; | ||
|  | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|  | ||
| @RestController | ||
| public class TimeCommandController { | ||
|  | ||
| private final TimeDao timeDao; | ||
|  | ||
| public TimeCommandController(TimeDao timeDao) { | ||
| this.timeDao = timeDao; | ||
| } | ||
|  | ||
| @GetMapping("/times/{id}") | ||
| public Time getTime(@PathVariable("id") long id) { | ||
| return timeDao.findById(id) | ||
| .orElseThrow(TimeNotFoundException::new); | ||
| } | ||
|  | ||
| @GetMapping("/times") | ||
| public List<Time> getTimes() { | ||
| return timeDao.findAll(); | ||
| } | ||
|  | ||
| @PostMapping("/times") | ||
| public ResponseEntity<TimeCreateResponse> createTime(@RequestBody TimeCreateRequest request) throws URISyntaxException { | ||
|  | ||
| Time newTime = Time.ofNew(request.getTime()); | ||
|  | ||
| Optional<Time> optionalTime = timeDao.findByTime(newTime); | ||
| if (optionalTime.isPresent()) { | ||
| throw new TimeAlreadyExistException(); | ||
| } | ||
|  | ||
| Time time = timeDao.save(newTime); | ||
|  | ||
| URI uri = new URI("/times/" + time.getId()); | ||
| return ResponseEntity | ||
| .created(uri) | ||
| .body(new TimeCreateResponse( | ||
| time.getId(), | ||
| time.getTime() | ||
| )); | ||
| } | ||
|  | ||
| @DeleteMapping("/times/{id}") | ||
| public ResponseEntity<Void> deleteTime(@PathVariable("id") long id) { | ||
| timeDao.delete(id); | ||
|  | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } | ||
        
          
          
            13 changes: 13 additions & 0 deletions
          
          13 
        
  src/main/java/roomescape/time/controller/TimeController.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package roomescape.time.controller; | ||
|  | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|  | ||
| @Controller | ||
| public class TimeController { | ||
|  | ||
| @GetMapping("/time") | ||
| public String getTimePage() { | ||
| return "time"; | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package roomescape.time.dto; | ||
|  | ||
| import java.time.LocalTime; | ||
|  | ||
| public class TimeCreateRequest { | ||
|  | ||
| private LocalTime time; | ||
|  | ||
| public LocalTime getTime() { | ||
| return time; | ||
| } | ||
| } | ||
|  | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package roomescape.time.dto; | ||
|  | ||
| import java.time.LocalTime; | ||
|  | ||
| public class TimeCreateResponse { | ||
|  | ||
| private Long id; | ||
|  | ||
| private LocalTime time; | ||
|  | ||
| public TimeCreateResponse(Long id, LocalTime time) { | ||
| this.id = id; | ||
| this.time = time; | ||
| } | ||
|  | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
|  | ||
| public LocalTime getTime() { | ||
| return time; | ||
| } | ||
| } | 
        
          
          
            4 changes: 4 additions & 0 deletions
          
          4 
        
  src/main/java/roomescape/time/exception/TimeAlreadyExistException.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package roomescape.time.exception; | ||
|  | ||
| public class TimeAlreadyExistException extends RuntimeException { | ||
| } | 
        
          
          
            14 changes: 14 additions & 0 deletions
          
          14 
        
  src/main/java/roomescape/time/exception/TimeExceptionHandler.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package roomescape.time.exception; | ||
|  | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ControllerAdvice; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|  | ||
| @ControllerAdvice | ||
| public class TimeExceptionHandler { | ||
|  | ||
| @ExceptionHandler(TimeAlreadyExistException.class) | ||
| public ResponseEntity<Void> handleException(TimeAlreadyExistException e) { | ||
| return ResponseEntity.badRequest().build(); | ||
| } | ||
| } | 
        
          
          
            4 changes: 4 additions & 0 deletions
          
          4 
        
  src/main/java/roomescape/time/exception/TimeNotFoundException.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package roomescape.time.exception; | ||
|  | ||
| public class TimeNotFoundException extends RuntimeException { | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RequestMapping을 활용해서 url의 공통적인 부분을 추출해보는 것도 좋을 것 같아요저는
@RequestMapping을 활용하면 개인적으로 한 눈에 요청 주체를 파악하기 쉬어서@RequestMapping을 이용하는 것을 선호합니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
더불어 현재 시간 관리 페이지로 응답해주는 처리 담당이 없는 것 같습니다. 이 부분 추가해 주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 회사의 코드 영향 때문일 수도 있는데, 회사에서 석환님 방식대로 컨트롤러 상단 @RequestMapping에 공통적인 부분을 두어져 있는게 더러 있습니다.
근데 이것이 개인적으로 IDE에서 검색하기 힘들어져서 저는 각 Mapping에 full url 두는 방법을 좀 더 선호하게 되었습니다 ㅎㅎ
물론 /api 등의 공통된 접두사가 붙게되거나 하면 공통적인 부분을 추출하는것도 좋다 생각하지만, 현재 제 생각은 그렇습니다~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 요건 페이지 제공 안된줄 알고 넘겼는데, 있었군요..! 바로 추가하겠습니다 ㅎㅎ