-
Notifications
You must be signed in to change notification settings - Fork 78
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
5주차 과제- 고양이 장난감가게 만들기 (심화) #75
Merged
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
913016f
gradle DozerMapper 추가
jdalma 8fb107b
DozerMapper 적용
jdalma 9ad7692
ddl-auto: create로 수정
jdalma 6f398d4
out폴더 무시
jdalma 398c728
UserController 유닛 테스트 작성
jdalma 8079515
ProductService 주석 추가
jdalma 21a2fcb
메서드 파라미터 타입 수정
jdalma 36be2a5
변수 네이밍 수정
jdalma a189482
User 테스트 데이터 클래스 추가
jdalma 9ac5972
User 도메인 password필드 직렬화 방지
jdalma e92a0a9
UserController @RequestBody 추가
jdalma f6a6cb8
UserControllerTest 반복되는 코드 제거
jdalma 8c9ac91
UserSerivce 테스트 코드 작성 중
jdalma aec0ada
Update app/src/main/java/com/codesoom/assignment/application/ProductS…
jdalma bfc1bbb
Update app/src/main/java/com/codesoom/assignment/application/ProductS…
jdalma 32c11e1
Update app/src/main/java/com/codesoom/assignment/application/UserServ…
jdalma 2e654f4
ProductService 주석 수정
jdalma 9212001
ProductNotFound -> ResourceNotFound 커스텀 예외 변경
jdalma 0be1625
AllArgsConstructor 제거
jdalma 9d8a363
Product 엔티티 AllArgsConstructor 제거
jdalma a3e6132
User 엔티티 update 메서드 추가
jdalma 3385770
예외 메세지 수정
jdalma 7ccaeff
User 테스트 코드 작성
jdalma 5bad14b
테스트를 작성하지 않은 부분은 fail()
jdalma 7633d28
findProduct 메서드 주석 추가
jdalma 40039a5
Builder어노테이션 생성자로 이동
jdalma 5fefb1b
ProductController 주석 추가
jdalma c2367ef
updateProduct 메서드 주석 수정
jdalma f2cea5e
UserService 클래스 분리
jdalma 1258380
UserService 분리로 인한 수정
jdalma b6aff67
불필요한 주석 제거
jdalma 5431692
User 도메인 필드 검증 어노테이션 추가
jdalma 5c93236
UserController 주석 및 테스트 코드 작성
jdalma 6720c2b
Update app/src/main/java/com/codesoom/assignment/controllers/ProductC…
jdalma 180aabd
Update app/src/test/java/com/codesoom/assignment/controllers/UserCont…
jdalma 979a3e0
user spec으로 인해/user를 /users로 변경
jdalma 23a10fb
User 엔티티 필수 입력 값 테스트 코드 추가
jdalma 2bf7346
user spec에 의한 DTO 추가
jdalma 5d890ea
User update 메서드 수정
jdalma 85dea3b
UserController DTO 추가로 JavaDoc 수정
jdalma File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/codesoom/assignment/application/UserCommandService.java
This file contains 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,33 @@ | ||
package com.codesoom.assignment.application; | ||
|
||
import com.codesoom.assignment.ResourceNotFoundException; | ||
import com.codesoom.assignment.domain.User; | ||
import com.codesoom.assignment.domain.UserRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@Transactional | ||
public class UserCommandService { | ||
|
||
private UserRepository repository; | ||
|
||
public UserCommandService(UserRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public User save(User user){ | ||
return repository.save(user); | ||
} | ||
|
||
public User update(User beforeUser , User user){ | ||
return beforeUser.update(user); | ||
} | ||
|
||
public User delete(User user){ | ||
repository.delete(user); | ||
return user; | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -9,38 +9,20 @@ | |
import java.util.List; | ||
|
||
@Service | ||
public class UserService { | ||
@Transactional(readOnly = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QueryService 에 잘 어울리는 애노테이션입니다. |
||
public class UserQueryService { | ||
|
||
private UserRepository repository; | ||
|
||
public UserService(UserRepository repository) { | ||
public UserQueryService(UserRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<User> findAll(){ | ||
return repository.findAll(); | ||
} | ||
|
||
@Transactional | ||
public User save(User user){ | ||
return repository.save(user); | ||
} | ||
|
||
@Transactional | ||
public User update(Long id , User user){ | ||
User beforeUser = findUser(id); | ||
return beforeUser.update(user); | ||
} | ||
|
||
@Transactional | ||
public User delete(Long id){ | ||
User user = findUser(id); | ||
repository.delete(user); | ||
return user; | ||
} | ||
|
||
private User findUser(Long id) { | ||
public User findUser(Long id) { | ||
return repository.findById(id) | ||
.orElseThrow(() -> new ResourceNotFoundException(id)); | ||
} | ||
|
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.
만약 삭제가 실패했다면 실패했다는 사실을 호출자에게 어떤 식으로 알릴 수 있을까요? 지금은
User
를 그대로 리턴하고만 있기 때문에 알 수 없을 것입니다.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.
Controller에서
query.findUser
가 식별자에 해당하는 정보가 없으면 예외를 던지게 되어 있습니다어떤 상황이 더 있을까요??
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.
예외를 던진다면
delete
메소드 위에 JavaDoc으로@throws
를 작성해 주도록 합시다. 한 번에 알아볼 수 있도록 해주는 것이 필요해요. 한편findUser
가 예외를 던지도록 하는 것이 과연 바람직한 것인지에 대해서도 생각할 수 있겠죠. 만약 검색엔진에서 어떤 것을 검색했는데 "검색 결과가 0 입니다" 라고 결과가 나오는 것과 예외가 던져지는 것을 두고 상상해볼 수도 있을 겁니다. 지금은 예외를 Goto 처럼 쓰고 있는 셈인데 (이것이 꼭 나쁘다는 것은 아닙니다) 어떻게 해야 코드를 읽는 사람에게 빨리 파악할 수 있도록 도와줄 수 있는지도 고민해야 해요