forked from codesquad-members-2022/sidedish
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request codesquad-members-2022#135 from Louie-03/dev-BE
[Team-03][BE][루이&쿠킴] - 로그인 제외한 모든 API 기능 구현, 배포
- Loading branch information
Showing
40 changed files
with
1,182 additions
and
207 deletions.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sidedish.com.config; | ||
|
||
import java.util.Map; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
Map<String, String> envs = System.getenv(); | ||
String awsIp = "http://" + envs.get("AWS_IP"); | ||
String localIp = "http://" + envs.get("LOCAL_IP"); | ||
String dnsName = envs.get("DNS_NAME"); | ||
|
||
registry.addMapping("/**") | ||
.allowedOrigins(localIp, awsIp, dnsName); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
BE/src/main/java/sidedish/com/controller/DomainDtoMapper.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,55 @@ | ||
package sidedish.com.controller; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.springframework.stereotype.Component; | ||
import sidedish.com.controller.model.OrderSaveResponse; | ||
import sidedish.com.controller.model.ProductDetailTypeResponse; | ||
import sidedish.com.controller.model.ProductBasicTypeResponse; | ||
import sidedish.com.domain.Product; | ||
import sidedish.com.repository.entity.OrderEntity; | ||
|
||
@Component | ||
public class DomainDtoMapper { | ||
|
||
public List<ProductBasicTypeResponse> toProductsBasicTypeResponseFromProducts( | ||
List<Product> products) { | ||
return products.stream() | ||
.map(this::toProductMealTypeResponseFromProduct) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private ProductBasicTypeResponse toProductMealTypeResponseFromProduct( | ||
Product product) { | ||
return new ProductBasicTypeResponse( | ||
product.getId(), | ||
product.getImages().get(0).getImageUrl(), | ||
product.getProductName(), | ||
product.getDescription(), | ||
product.getFixedPrice(), | ||
product.getOriginalPrice(), | ||
product.getDiscountPolicy().getPolicyName()); | ||
} | ||
|
||
public ProductDetailTypeResponse toProductDetailTypeFromProduct( | ||
Product product) { | ||
return new ProductDetailTypeResponse( | ||
product.getId(), | ||
product.getImages(), | ||
product.getProductName(), | ||
product.getDescription(), | ||
product.getFixedPrice(), | ||
product.getOriginalPrice(), | ||
product.getDiscountPolicy().getPolicyName(), | ||
product.getMileage(), | ||
product.getDeliveryPolicy().getDeliveryInfo(), | ||
product.getDeliveryPolicy().getDeliveryCharge(), | ||
product.getDeliveryPolicy().getFreeDeliveryOverAmount() | ||
); | ||
} | ||
|
||
public OrderSaveResponse toOrderSaveResponseFromOrder(OrderEntity orderEntity) { | ||
return new OrderSaveResponse(orderEntity.getId()); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
BE/src/main/java/sidedish/com/controller/OrderController.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,28 @@ | ||
package sidedish.com.controller; | ||
|
||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import sidedish.com.controller.model.OrderSaveRequest; | ||
import sidedish.com.controller.model.OrderSaveResponse; | ||
import sidedish.com.service.OrderService; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class OrderController { | ||
|
||
private final OrderService orderService; | ||
|
||
@PostMapping("/api/products/{id}/order") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public OrderSaveResponse order(@PathVariable Long id, | ||
@RequestBody @Valid OrderSaveRequest orderSaveRequest) { | ||
return orderService.save(id, orderSaveRequest.getCount()); | ||
} | ||
|
||
} |
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
31 changes: 0 additions & 31 deletions
31
BE/src/main/java/sidedish/com/controller/ProductsDtoMapper.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
BE/src/main/java/sidedish/com/controller/model/OrderSaveRequest.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,11 @@ | ||
package sidedish.com.controller.model; | ||
|
||
import javax.validation.constraints.Positive; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class OrderSaveRequest { | ||
|
||
@Positive | ||
private Long count; | ||
} |
11 changes: 11 additions & 0 deletions
11
BE/src/main/java/sidedish/com/controller/model/OrderSaveResponse.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,11 @@ | ||
package sidedish.com.controller.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class OrderSaveResponse { | ||
private Long id; | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
BE/src/main/java/sidedish/com/controller/model/ProductDetailTypeResponse.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,25 @@ | ||
package sidedish.com.controller.model; | ||
|
||
|
||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import sidedish.com.domain.Image; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ProductDetailTypeResponse { | ||
|
||
private Long id; | ||
private List<Image> images; | ||
private String productName; | ||
private String description; | ||
private long fixedPrice; | ||
private long originalPrice; | ||
private String event; | ||
private long mileage; | ||
private String deliveryInfo; | ||
private long deliveryCharge; | ||
private long freeDeliveryOverAmount; | ||
|
||
} |
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,14 @@ | ||
package sidedish.com.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class DeliveryPolicy { | ||
|
||
private String deliveryInfo; | ||
private Long deliveryCharge; | ||
private Long freeDeliveryOverAmount; | ||
|
||
} |
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,29 @@ | ||
package sidedish.com.domain; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class Order { | ||
private final Product product; | ||
private final long count; | ||
private final long totalPrice; | ||
private final long deliveryPrice; | ||
|
||
public Order(Product product, long count) { | ||
this.product = product; | ||
this.count = count; | ||
this.totalPrice = calculateTotalPrice(); | ||
this.deliveryPrice = calculateDeliveryPrice(); | ||
} | ||
|
||
private long calculateTotalPrice() { | ||
return count * product.getFixedPrice(); | ||
} | ||
|
||
private long calculateDeliveryPrice() { | ||
if (totalPrice >= product.getDeliveryPolicy().getFreeDeliveryOverAmount()) { | ||
return 0; | ||
} | ||
return product.getDeliveryPolicy().getDeliveryCharge(); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
BE/src/main/java/sidedish/com/exception/GlobalExceptionHandler.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,24 @@ | ||
package sidedish.com.exception; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(NotEnoughStockQuantityException.class) | ||
public Map<String, Long> exceptionHandler(NotEnoughStockQuantityException e) { | ||
long stockQuantity = e.getStockQuantity(); | ||
return Collections.singletonMap("currentStockQuantity", stockQuantity); | ||
} | ||
|
||
@ResponseStatus(value = HttpStatus.NOT_FOUND) | ||
@ExceptionHandler(NoSuchProductsException.class) | ||
public void exceptionHandler(NoSuchProductsException e) { | ||
} | ||
} |
Oops, something went wrong.