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

전남대 BE_박진화 6주차 과제(Step2) #280

Open
wants to merge 112 commits into
base: jinhwa-park
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
316e185
Initial commit
wotjd243 Jun 23, 2024
8569d45
Initial commit
wotjd243 Jun 23, 2024
d5003d1
feat: set up the project
wotjd243 Jul 15, 2024
ba7709c
feat: migrate prev project codes
Jinhwa-Park Jul 16, 2024
6c1df36
feat: migrate prev project codes (#131)
Jinhwa-Park Jul 16, 2024
c9708c4
docs: delete unnecessary lines
Jinhwa-Park Jul 16, 2024
3efb237
docs: add README
Jinhwa-Park Jul 17, 2024
0d0c2a9
docs: modify typo
Jinhwa-Park Jul 17, 2024
f596fbf
rename: move prev codes to oldTestCodes directory
Jinhwa-Park Jul 17, 2024
319d6a2
feat: add codes about Category
Jinhwa-Park Jul 17, 2024
d50a1b7
feat: changed feature about set to update
Jinhwa-Park Jul 17, 2024
41a56e1
refactor: modify ProductController as modified Product entity
Jinhwa-Park Jul 17, 2024
8efe562
feat: add getEmailFromRequest method to JwtUtil
Jinhwa-Park Jul 17, 2024
2378e85
refactor: update controllers with clear return types and improve read…
Jinhwa-Park Jul 17, 2024
3c5036e
feat: add new fields(color, imageUrl, description) and update Catego…
Jinhwa-Park Jul 17, 2024
30200d0
feat: add path variable support for category deletion
Jinhwa-Park Jul 18, 2024
3d12d7b
feat: integrate category handling in ProductController
Jinhwa-Park Jul 18, 2024
e0e7fbe
feat: update Product entity to include category handling
Jinhwa-Park Jul 18, 2024
b6eca3e
feat: update ProductRequest, ProductResponse, ProductService to inclu…
Jinhwa-Park Jul 18, 2024
3f68385
feat: Add code to WishController to verify ProductId
Jinhwa-Park Jul 18, 2024
b5c7cbd
"remove: delete unnecessary product.html"
Jinhwa-Park Jul 18, 2024
b82b476
Merge branch 'jinhwa-park' into step1
Jinhwa-Park Jul 18, 2024
b9d1b08
docs: update README
Jinhwa-Park Jul 18, 2024
e6f9d4c
feat: make addOption page for admin
Jinhwa-Park Jul 18, 2024
4a990a1
refactor: change dependency injection from field to constructor
Jinhwa-Park Jul 18, 2024
f735135
feat: implement option features
Jinhwa-Park Jul 18, 2024
9db3978
feat: add option handle feature
Jinhwa-Park Jul 18, 2024
d781978
refactor: change dependency injection from field to constructor (JwtA…
Jinhwa-Park Jul 19, 2024
f55e846
feat: add option schema
Jinhwa-Park Jul 19, 2024
b74f7ad
feat: add redundancy option check feature
Jinhwa-Park Jul 19, 2024
37177da
feat: add properties
Jinhwa-Park Jul 19, 2024
78f78fa
refactor: change annotation from korean to english
Jinhwa-Park Jul 19, 2024
cd2982f
Revert "feat: add redundancy option check feature"
Jinhwa-Park Jul 19, 2024
4494483
Revert "Revert "feat: add redundancy option check feature""
Jinhwa-Park Jul 19, 2024
35c1d34
feat: add enforcing product have at least one option
Jinhwa-Park Jul 19, 2024
a72acdb
feat: add feat ProductController, OptionDTO, ProductRequest
Jinhwa-Park Jul 19, 2024
d10b7a0
docs: update README
Jinhwa-Park Jul 19, 2024
2c3afa5
docs: edit README indent
Jinhwa-Park Jul 19, 2024
ec2b9d5
feat: add getter and setter for quantity
Jinhwa-Park Jul 19, 2024
6e576f5
feat: add method for decrease quantity value
Jinhwa-Park Jul 19, 2024
1978094
docs: update README as include selectable options
Jinhwa-Park Jul 20, 2024
1eb1dd1
fix: make GlobalExceptionHandler handles proper error
Jinhwa-Park Jul 20, 2024
ae56b70
refactor: changes id variable to indicate clearly
Jinhwa-Park Jul 20, 2024
1737485
feat: Apply review feedback and add test code
Jinhwa-Park Jul 21, 2024
29c5d18
Merge branch 'step1' into step2
Jinhwa-Park Jul 21, 2024
8477326
feat: add builder, delete unnecessary import and annotations
Jinhwa-Park Jul 21, 2024
4e0459c
fix: modify as it works on test codes, change order, add option on data
Jinhwa-Park Jul 21, 2024
c8b4d09
feat: add CustomException, delete unnecessary annotations
Jinhwa-Park Jul 21, 2024
8d4dfbb
rename: modify OptionDTO to OptionRequest
Jinhwa-Park Jul 21, 2024
d47d8b0
refactor: Improve validation, error handling, entity retrieval
Jinhwa-Park Jul 21, 2024
0c75891
refactor: change to use CustomException
Jinhwa-Park Jul 21, 2024
a9d6536
refactor: change to use CustomException
Jinhwa-Park Jul 21, 2024
8e1b1a0
refactor: using SpringBootTest to WebMvcTest
Jinhwa-Park Jul 21, 2024
152c8ad
refactor: apply renamed OptionRequest
Jinhwa-Park Jul 21, 2024
44ae309
refactor: enhance validation
Jinhwa-Park Jul 21, 2024
3d9b0ed
feat: set up the project
wotjd243 Jul 22, 2024
aae0660
전남대_BE 박진화 4주차 과제 (1단계) (#219)
Jinhwa-Park Jul 22, 2024
5af08fe
fix: resolve conflicts
Jinhwa-Park Jul 22, 2024
289a9bd
전남대 BE_박진화 4주차 과제 (2단계) (#312)
Jinhwa-Park Jul 23, 2024
50f4da0
fix: resolve conflicts and update codes using builder
Jinhwa-Park Jul 23, 2024
965cd9a
feat: add InvalidQuantityException
Jinhwa-Park Jul 23, 2024
a9218d9
Merge branch 'jinhwa-park' into step3
Jinhwa-Park Jul 23, 2024
3d4dc9a
feat: update step0 as step3 in previous project spring-gift-enhancement
Jinhwa-Park Jul 23, 2024
d437145
전남대 BE_박진화 5주차 과제 (0단계 (#120)
Jinhwa-Park Jul 23, 2024
6575763
feat: make file structure
Jinhwa-Park Jul 24, 2024
cfb623e
feat: modify file names, add API-KEY
Jinhwa-Park Jul 24, 2024
8fa967d
feat: add @ConfigurationPropertiesScan
Jinhwa-Park Jul 25, 2024
c297314
feat: add Lombok
Jinhwa-Park Jul 25, 2024
e49417e
refactor: change code order
Jinhwa-Park Jul 25, 2024
75513b9
feat: add code about kakao
Jinhwa-Park Jul 25, 2024
7ce7418
feat: add regexp 가-힣
Jinhwa-Park Jul 25, 2024
63a6112
feat: implement kakao OAuth features
Jinhwa-Park Jul 25, 2024
52f6302
Merge branch 'jinhwa-park' of https://github.com/kakao-tech-campus-2n…
Jinhwa-Park Jul 25, 2024
804182a
feat: update as fit on step2
Jinhwa-Park Jul 25, 2024
afe1211
feat: add logger and complement AccessDeniedException
Jinhwa-Park Jul 26, 2024
6e5122e
feat: implement feature about Message
Jinhwa-Park Jul 26, 2024
6c4e300
feat: add method that return error's reason
Jinhwa-Park Jul 26, 2024
b9ba916
fix: fix wrong data type
Jinhwa-Park Jul 26, 2024
f47ba7b
feat: implement features about order
Jinhwa-Park Jul 26, 2024
c4b89d2
fix: initialization with constructor
Jinhwa-Park Jul 26, 2024
9880e6f
feat: implement feature that delete related wish list items when orde…
Jinhwa-Park Jul 26, 2024
0aa3867
refactor: remove unnecessary indent
Jinhwa-Park Jul 26, 2024
2e79d2c
feat: add method that help update id
Jinhwa-Park Jul 26, 2024
b8f4158
feat: modify parameter that fits on OrderRequest
Jinhwa-Park Jul 26, 2024
2501774
fix: fix JWT token validation and order placement logic
Jinhwa-Park Jul 27, 2024
dd9e329
docs: remove unnecessary indent or annotations
Jinhwa-Park Jul 27, 2024
6f74476
fix: fix everything I can do
Jinhwa-Park Jul 27, 2024
dd9cb6a
Merge branch 'step1' into step2
Jinhwa-Park Jul 27, 2024
32dea8a
fix: fix everything I can do, and merge with Hotfix branch
Jinhwa-Park Jul 27, 2024
f14fcd0
docs: Write API document
Jinhwa-Park Jul 28, 2024
f28b45d
전남대_BE 박진화 5주차 과제(Step1) (#215)
Jinhwa-Park Jul 28, 2024
5fd98b1
fix: conflict fix
Jinhwa-Park Jul 28, 2024
4bc5f59
feat: Merge previous project's codes
Jinhwa-Park Jul 29, 2024
7c187d2
feat: add swagger for API documentation
Jinhwa-Park Jul 30, 2024
4686e3b
전남대 BE_ 박진화 5주차 과제(Step2) (#323)
Jinhwa-Park Jul 30, 2024
c02d690
docs: add DS_Store as ignore type
Jinhwa-Park Jul 30, 2024
3705f2e
feat: add swagger
Jinhwa-Park Jul 30, 2024
0a45662
Merge branch 'jinhwa-park' into step3
Jinhwa-Park Jul 30, 2024
50d5533
refactor: change url usage
Jinhwa-Park Jul 31, 2024
d8663a2
fix: fix conflict and type.
Jinhwa-Park Jul 31, 2024
dc602f1
feat: update codes as previous project's step3
Jinhwa-Park Jul 31, 2024
1cb5c30
feat: update differences
Jinhwa-Park Jul 31, 2024
d6ac0e9
refactor: set codes like teamMates
Jinhwa-Park Aug 1, 2024
34e9860
refactor: set codes like teamMates
Jinhwa-Park Aug 1, 2024
647f5c4
feat: update codes that fits on teammate's API
Jinhwa-Park Aug 1, 2024
20b375e
fix: fix different implements
Jinhwa-Park Aug 2, 2024
3d15b3e
feat: modify codes
Jinhwa-Park Aug 2, 2024
f2e57f9
fix: OrderServiceTest fixed
Jinhwa-Park Aug 6, 2024
390beb4
feat: add or modify DTO files
Jinhwa-Park Aug 6, 2024
870f8f0
Merge branch 'jinhwa-park' of https://github.com/kakao-tech-campus-2n…
Jinhwa-Park Aug 6, 2024
2f6243f
Merge branch 'above' into step2
Jinhwa-Park Aug 6, 2024
cda28a8
fix: fix conflicts
Jinhwa-Park Aug 7, 2024
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
18 changes: 13 additions & 5 deletions src/main/java/gift/controller/OptionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import gift.dto.option.OptionResponse;
import gift.dto.option.OptionUpdateResponse;
import gift.entity.Option;
import gift.exception.CustomException;
import gift.service.OptionService;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -47,8 +49,7 @@ public ResponseEntity<OptionResponse> addOptionToProduct(
UriComponentsBuilder uriBuilder) {
Option option = optionService.addOptionToProduct(productId, optionRequest);
OptionResponse response = new OptionResponse(option.getId(), option.getName(), option.getQuantity());
URI location = uriBuilder.path("/api/products/{productId}/options/{optionId}")
.buildAndExpand(productId, option.getId()).toUri();
URI location = uriBuilder.path("/api/products/{productId}/options/{optionId}").buildAndExpand(productId, option.getId()).toUri();
return ResponseEntity.created(location).body(response);
}

Expand All @@ -72,8 +73,15 @@ public ResponseEntity<String> deleteOption(
@PathVariable Long optionId,
@Parameter(description = "ID of the product", required = true)
@RequestBody DeleteOptionRequest deleteOptionRequest) {
optionService.deleteOption(optionId, deleteOptionRequest.getEmail(), deleteOptionRequest.getPassword());
return ResponseEntity.ok("Option successfully deleted.");
try {
optionService.deleteOption(optionId, DeleteOptionRequest.getEmail(), DeleteOptionRequest.getPassword());
return ResponseEntity.ok("Option successfully deleted.");
} catch (CustomException.EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
} catch (CustomException.InvalidPasswordException e) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage());
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred: " + e.getMessage());
}
}
}

1 change: 1 addition & 0 deletions src/main/java/gift/controller/ProductController.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public ResponseEntity<ProductResponse> updateProduct(
public ResponseEntity<String> deleteProduct(
@Parameter(description = "ID of the product to be deleted", required = true)
@PathVariable Long id) {
productService.deleteById(id);
try {
productService.deleteById(id);
return ResponseEntity.ok("성공적으로 삭제되었습니다.");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gift/controller/WishController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gift/entity/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public String getEmail() {
return email;
}

public LocalDateTime getOrderTime() {
return orderDateTime;
}

public static class Builder {
private Long id;
private Long optionId;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/gift/entity/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public class Product {
@OneToMany(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Option> options = new ArrayList<>();

@OneToMany(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Wish> wishes = new ArrayList<>();

private Product(Builder builder) {
this.id = builder.id;
this.name = builder.name;
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/gift/exception/CustomException.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ public static class InvalidQuantityException extends RuntimeException {
public InvalidQuantityException(String message) {super(message);}
}

<<<<<<< HEAD
public static class InvalidPasswordException extends RuntimeException {
public InvalidPasswordException(String message) {super(message);}
}

=======
>>>>>>> e3b9ef38d18104514aa1d0951ff1a098ff9a093f
public static class GenericException extends RuntimeException {
public GenericException(String message) {
super(message);
Expand All @@ -42,13 +39,10 @@ public GenericException(String message, Throwable cause) {
super(message, cause);
}
}
<<<<<<< HEAD

public static class EntityAlreadyExistException extends RuntimeException {
public EntityAlreadyExistException(String message) {
super(message);
public static class EntityAlreadyExistException extends Throwable {
public EntityAlreadyExistException(String s) {
super(s);
}
}
=======
>>>>>>> e3b9ef38d18104514aa1d0951ff1a098ff9a093f
}
4 changes: 2 additions & 2 deletions src/main/java/gift/service/OptionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public Option addOptionToProduct(Long productId, OptionRequest optionRequest) {
Option option = new Option.Builder()
.name(optionRequest.getName())
.quantity(optionRequest.getQuantity())
.product(product).build();
.product(product)
.build();
optionRepository.save(option);

product.getOptions().add(option);
return optionRepository.save(option);
}

public void deleteOption(Long optionId, String email, String password) {
System.out.println("email: " + email);
Option deletedOption = optionRepository.findById(optionId).orElseThrow(()-> new CustomException.EntityNotFoundException("Option not found"));
Member member = memberService.findByEmail(email).orElseThrow(()-> new CustomException.EntityNotFoundException("Member not found"));
memberService.verifyPassword(member, password);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gift/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public OrderResponse placeOrder(OrderRequest orderRequest) {
order.getId(),
order.getOptionId(),
order.getQuantity(),
order.getOrderDateTime(),
order.getOrderTime(),
order.getMessage()
);
}
Expand All @@ -54,7 +54,7 @@ public Page<OrderResponse> getOrdersByEmail(String email, Pageable pageable) {
order.getId(),
order.getOptionId(),
order.getQuantity(),
order.getOrderDateTime(),
order.getOrderTime(),
order.getMessage()
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gift/service/WishService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Wish updateWish(Long wishId) {
return wishRepository.save(wish);
}

public Wish createWish(Member member,Product product, int quantity) {
public Wish createWish(Member member,Product product, int quantity) throws CustomException.EntityAlreadyExistException {
Optional<Wish> existingWish = wishRepository.findByMemberAndProduct(member, product);
if(existingWish.isPresent()) {
throw new CustomException.EntityAlreadyExistException("Wish already exist for this product");
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/gift/util/ProductValidator.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package gift.util;

<<<<<<< HEAD
import gift.dto.option.OptionRequest;
import gift.dto.product.ProductRequest;
=======
import gift.dto.OptionRequest;
import gift.dto.ProductRequest;
>>>>>>> e3b9ef38d18104514aa1d0951ff1a098ff9a093f

public class ProductValidator {
public static void validateProductRequest(ProductRequest productRequest) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ INSERT INTO options (name, quantity, product_id) VALUES ('Option1', 100, 1);
INSERT INTO options (name, quantity, product_id) VALUES ('Option2', 200, 1);

-- wish
INSERT INTO wish (member_id, product_id, quantity, created_date) VALUES (1, 1, 1, NOW());
INSERT INTO wish (member_id, product_id) VALUES (1, 1);
2 changes: 1 addition & 1 deletion src/test/java/gift/service/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void setUp() {

@Test
public void PlaceOrderSuccess() {
OrderRequest orderRequest = new OrderRequest(1L, 1L, 1, "Test message", LocalDateTime.now(), "[email protected]");
OrderRequest orderRequest = new OrderRequest(1L, 1L, 1,"Test message", LocalDateTime.now(), "[email protected]");

Order order = new Order.Builder()
.id(1L)
Expand Down