-
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
Changes from all commits
913016f
8fb107b
9ad7692
6f398d4
398c728
8079515
21a2fcb
36be2a5
a189482
9ac5972
e92a0a9
f6a6cb8
8c9ac91
aec0ada
bfc1bbb
32c11e1
2e654f4
9212001
0be1625
9d8a363
a3e6132
3385770
7ccaeff
5bad14b
7633d28
40039a5
5fefb1b
c2367ef
f2cea5e
1258380
b6aff67
5431692
5c93236
6720c2b
180aabd
979a3e0
23a10fb
2bf7346
5d890ea
85dea3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ Thumbs.db | |
Thumbs.db:encryptable | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
/app/out/ |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.codesoom.assignment; | ||
|
||
public class ResourceNotFoundException extends RuntimeException { | ||
public ResourceNotFoundException(Long id) { | ||
super("식별자에 해당하는 자원이 존재하지 않습니다. : " + id); | ||
} | ||
} |
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; | ||
Comment on lines
+29
to
+31
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. 만약 삭제가 실패했다면 실패했다는 사실을 호출자에게 어떤 식으로 알릴 수 있을까요? 지금은 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. Controller에서 @DeleteMapping("{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@PathVariable Long id){
command.delete(query.findUser(id));
} 어떤 상황이 더 있을까요?? 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. 예외를 던진다면 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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(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 UserQueryService(UserRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public List<User> findAll(){ | ||
return repository.findAll(); | ||
} | ||
|
||
public User findUser(Long id) { | ||
return repository.findById(id) | ||
.orElseThrow(() -> new ResourceNotFoundException(id)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
package com.codesoom.assignment.controllers; | ||
|
||
import com.codesoom.assignment.ResourceNotFoundException; | ||
import com.codesoom.assignment.application.ProductService; | ||
import com.codesoom.assignment.domain.Product; | ||
import com.codesoom.assignment.dto.ProductData; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
import java.util.List; | ||
|
||
/** | ||
* 상품을 조회, 생성, 삭제한다. | ||
*/ | ||
@RestController | ||
@RequestMapping("/products") | ||
public class ProductController { | ||
|
@@ -18,22 +23,48 @@ public ProductController(ProductService productService) { | |
this.productService = productService; | ||
} | ||
|
||
/** | ||
* 모든 상품들을 반환한다. | ||
*/ | ||
@GetMapping | ||
public List<Product> list() { | ||
return productService.getProducts(); | ||
} | ||
|
||
/** | ||
* 식별자에 해당하는 상품을 조회한다. | ||
* | ||
* @param id 찾으려는 상품의 식별자 | ||
* @return 식별자에 해당하는 상품 | ||
* @throws ResourceNotFoundException 식별자에 해당하는 상품이 없는 경우 | ||
*/ | ||
@GetMapping("{id}") | ||
public Product detail(@PathVariable Long id) { | ||
return productService.getProduct(id); | ||
} | ||
|
||
/** | ||
* 상품 정보를 저장한다. | ||
* | ||
* @param productData 저장할 정보 | ||
* @return 생성된 상품 | ||
* @throws MethodArgumentNotValidException 필수 정보가 비어있는 경우 | ||
*/ | ||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public Product create(@RequestBody @Valid ProductData productData) { | ||
return productService.createProduct(productData); | ||
} | ||
|
||
/** | ||
* 식별자에 해당하는 상품을 전달받은 상품으로 수정한다. | ||
* | ||
* @param id 수정할 상품의 식별자 | ||
* @param productData 수정할 정보 | ||
* @return 수정된 상품 | ||
* @throws MethodArgumentNotValidException 필수 정보가 비어있는 경우 | ||
* @throws ResourceNotFoundException 식별자에 해당하는 상품이 없는 경우 | ||
Comment on lines
+65
to
+66
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. 좋습니다. |
||
*/ | ||
@PatchMapping("{id}") | ||
public Product update( | ||
@PathVariable Long id, | ||
|
@@ -42,6 +73,12 @@ public Product update( | |
return productService.updateProduct(id, productData); | ||
} | ||
|
||
/** | ||
* 식별자에 해당하는 상품을 삭제한다. | ||
* | ||
* @param id 삭제할 상품의 식별자 | ||
* @throws ResourceNotFoundException 식별자에 해당하는 상품이 없는 경우 | ||
*/ | ||
@DeleteMapping("{id}") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public void destroy(@PathVariable Long id) { | ||
|
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.
dozermapper github repository에 방문해 보세요. 어떤 문제가 있다는 것을 알 수 있을 텐데, 어떤 문제인지 확인해서 글로 작성해 보세요. dozermapper 를 제거해야 할 지에 대해서도 생각해 보시고, 제거한다면 어떤 대안이 있는지도 글에 함께 적어 보세요.