-
Notifications
You must be signed in to change notification settings - Fork 112
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
강원대 BE_박지희 4주차 과제 (1단계) #228
Open
peacefullyquietly
wants to merge
20
commits into
kakao-tech-campus-2nd-step2:peacefullyquietly
Choose a base branch
from
peacefullyquietly:step1
base: peacefullyquietly
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
20 commits
Select commit
Hold shift + click to select a range
9d2da5f
init : step0 - 3주차 jpa 코드 리뷰 반영
peacefullyquietly 380f7ad
docs : README.md 수정
peacefullyquietly 5cd354d
feat : CategoryDTO 클래스 작성
peacefullyquietly 25a214e
feat : CategoryController.class 작성
peacefullyquietly 22a925d
feat : CategoryEntity 클래스 작성
peacefullyquietly cf40b40
feat : CategoryService 클래스 작성
peacefullyquietly 9f4dea6
feat : CategoryRepository 클래스 작성
peacefullyquietly 1041e7a
refactor : 단일 책임 원칙에 따른 메서드 분리
peacefullyquietly c94e4cb
refactor : 단일 책임 원칙에 따른 메서드 분리
peacefullyquietly 840491d
refactor : 컨트롤러 레이어 개선
peacefullyquietly e259339
Merge branch 'tmp_step1' into step1
peacefullyquietly de23358
refactor : 테스트코드 내 @Transaction 추가 및 오류 해결
peacefullyquietly 5ca217c
test : WishListRepositoryTest 클래스 작성
peacefullyquietly a7157eb
refactor : 요구사항에 맞게 유효성 검사 부분 수정
peacefullyquietly dfeb282
refactor : validation 추가
peacefullyquietly 5e4a0a7
refactor : 예외처리 방법 수정
peacefullyquietly 67dfd4a
refactor : 잘못된 서비스 로직 수정
peacefullyquietly d9de226
refactor : 서비스 로직에따른 변경 사항
peacefullyquietly d7ff863
refactor : 예외처리 방법 변경에 따른 수정사항
peacefullyquietly 0e1c777
refactor : 에러 메시지 수정
peacefullyquietly 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 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 |
---|---|---|
@@ -1 +1,34 @@ | ||
# spring-gift-enhancement | ||
# spring-gift-enhancement | ||
|
||
## Step1 | ||
- 기능 요구사항 | ||
- 상품 정보에 카테고리를 추가한다. 상품과 카테고리 모델 간의 관계를 고려하여 설계하고 구현한다. | ||
- 상품에는 항상 하나의 카테고리가 있어야 한다. | ||
- 상품 카테고리는 수정할 수 있다. | ||
- 관리자 화면에서 상품을 추가할 때 카테고리를 지정할 수 있다. | ||
- 카테고리는 1차 카테고리만 있으며 2차 카테고리는 고려하지 않는다. | ||
- 카테고리의 예시는 아래와 같다. | ||
- 교환권, 상품권, 뷰티, 패션, 식품, 리빙/도서, 레저/스포츠, 아티스트/캐릭터, 유아동/반려, 디지털/가전, 카카오프렌즈, 트렌드 선물, 백화점, ... | ||
- 아래 예시와 같이 HTTP 메시지를 주고받도록 구현한다. | ||
|
||
- Request | ||
<pre> | ||
GET /api/categories HTTP/1.1 | ||
</pre> | ||
|
||
- Response | ||
<pre> | ||
<code> | ||
HTTP/1.1 200 | ||
Content-Type: application/json | ||
[ | ||
{ | ||
"id": 91, | ||
"name": "교환권", | ||
"color": "#6c95d1", | ||
"imageUrl": "https://gift-s.kakaocdn.net/dn/gift/images/m640/dimm_theme.png", | ||
"description": "" | ||
} | ||
] | ||
</code> | ||
</pre> |
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
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
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,60 @@ | ||
package gift.controller; | ||
|
||
import gift.domain.CategoryDTO; | ||
import gift.service.CategoryService; | ||
import jakarta.validation.Valid; | ||
import java.util.List; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/category") | ||
public class CategoryController { | ||
private final CategoryService categoryService; | ||
|
||
@Autowired | ||
public CategoryController(CategoryService categoryService){ | ||
this.categoryService = categoryService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<CategoryDTO>> getCategory() { | ||
List<CategoryDTO> response = categoryService.getCategories(); | ||
return new ResponseEntity<>(response, HttpStatus.OK); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<CategoryDTO> getCategoryById(@PathVariable Long id) throws Exception { | ||
CategoryDTO response = categoryService.getCategory(id); | ||
return new ResponseEntity<>(response, HttpStatus.OK); | ||
} | ||
|
||
@PutMapping | ||
public ResponseEntity<CategoryDTO> addCategory(@Valid @RequestBody CategoryDTO category) { | ||
CategoryDTO createdCategory = categoryService.createCategory(category); | ||
return new ResponseEntity<>(createdCategory, HttpStatus.CREATED); | ||
} | ||
|
||
@PostMapping("/{id}") | ||
public ResponseEntity<CategoryDTO> updateCategory(@PathVariable Long id, @Valid @RequestBody CategoryDTO category) { | ||
CategoryDTO updatedCategory = categoryService.updateCategory(id, category); | ||
return new ResponseEntity<>(updatedCategory, HttpStatus.OK); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteCategory(@PathVariable Long id) { | ||
categoryService.deleteCategory(id); | ||
return new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
} | ||
|
||
|
||
} |
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
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
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,49 @@ | ||
package gift.domain; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public class CategoryDTO { | ||
private Long id; | ||
|
||
@NotBlank(message = "카테고리 이름은 필수 입력 항목입니다.") | ||
private String name; | ||
|
||
@Pattern(regexp = "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", message = "올바른 HEX 색상 코드로 입력해 주세요") | ||
private String color; | ||
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. 저장될때는 nullable하지 않게 되어있는데 앞에서도 검증이 필요할것같습니다. |
||
|
||
@Pattern(regexp = "^https?://.*$", message = "올바른 이미지 URL 형식으로 입력해 주세요") | ||
private String imageUrl; | ||
|
||
@Size(max = 255, message = "설명은 최대 255글자 이하로 입력해 주세요") | ||
private String description; | ||
|
||
public CategoryDTO(Long id, String name, String color, String imageUrl, String description) { | ||
this.id = id; | ||
this.name = name; | ||
this.color = color; | ||
this.imageUrl = imageUrl; | ||
this.description = description; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getColor() { | ||
return color; | ||
} | ||
|
||
public String getImageUrl() { | ||
return imageUrl; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
} |
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
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.
상품추가할때 바로 카테고리를 지정해야하는 요구사항이 있는것으로 알고있는데요, 상품쪽 controller에 수정이 필요할것같습니다.
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.
넵 수정해보겠습니다!