Skip to content

Commit

Permalink
Merge pull request #33 from Orange-Co/feature/home
Browse files Browse the repository at this point in the history
Feat: reflect modification
  • Loading branch information
Kang1221 authored Jul 16, 2024
2 parents 5b267ee + 017a847 commit d453b38
Show file tree
Hide file tree
Showing 26 changed files with 328 additions and 97 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// mysql
implementation 'mysql:mysql-connector-java:8.0.32'
//redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

//lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'


testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/co/orange/ddanzi/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import co.orange.ddanzi.service.HomeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequiredArgsConstructor
Expand All @@ -21,8 +18,10 @@ public ApiResponse<?> home() {
return homeService.getProductList();
}

@GetMapping("/product/{id}")
public ApiResponse<?> homeDetail(@PathVariable String id) {
@GetMapping( "/product/{id}")
public ApiResponse<?> homeDetail(@RequestHeader("devicetoken") String devicetoken,
@PathVariable String id) {
log.info("devicetoken: {}", devicetoken);
return homeService.getProductDetail(id);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package co.orange.ddanzi.domain.order.pk;

import co.orange.ddanzi.domain.product.Item;
import co.orange.ddanzi.domain.order.Order;
import co.orange.ddanzi.domain.term.TermOrder;
import jakarta.persistence.*;
import lombok.Data;
Expand All @@ -11,8 +11,8 @@
@Data
public class OrderAgreementId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "item_id")
private Item item;
@JoinColumn(name = "order_id")
private Order order;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "term_order_id")
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/co/orange/ddanzi/domain/product/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class Category extends BaseTimeEntity {
private Boolean isForbidden; //금지 여부

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "discount_id", nullable = true)
private Discount discount; //할인율
@JoinColumn(name = "default_discount_id", nullable = true)
private DefaultDiscount defaultDiscount; //할인율

@OneToMany(fetch = FetchType.LAZY, mappedBy = "parentCategory", cascade = CascadeType.ALL)
private List<Category> childrenCategory = new ArrayList<>(); //자식 카테고리
Expand All @@ -40,12 +40,12 @@ public class Category extends BaseTimeEntity {
private Category parentCategory; //부모 카테고리

@Builder
public Category(Long id, String content, Boolean isForbidden, Category parentCategory, Discount discount) {
public Category(Long id, String content, Boolean isForbidden, Category parentCategory, DefaultDiscount defaultDiscount) {
this.id = id;
this.content = content;
this.isForbidden = isForbidden;
this.parentCategory = parentCategory;
this.discount = discount;
this.defaultDiscount = defaultDiscount;
}

public String getFullPath(){
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/co/orange/ddanzi/domain/product/DefaultDiscount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package co.orange.ddanzi.domain.product;

import co.orange.ddanzi.global.common.domain.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

@Getter
@NoArgsConstructor
@Table(name = "defalut_discounts")
@Entity
public class DefaultDiscount extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "defalut_discount_id")
private Long id; //할인율 고유 ID

@ColumnDefault("0.3")
@Column(name = "rate", nullable = false)
private Float rate; //할인율, 디폴트 30%

// @OneToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "root_category_id", nullable = true)
// private Category rootCategory; //카테고리 = root category

@Builder
public DefaultDiscount(Long id, Float rate) {
this.id = id;
this.rate = rate;
}
}
28 changes: 15 additions & 13 deletions src/main/java/co/orange/ddanzi/domain/product/Discount.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

@Getter
@NoArgsConstructor
@Table(name = "discounts")
@Entity
public class Discount extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "discount_id")
private Long id; //할인율 고유 ID
@Column(name = "product_id")
private String id; //상품 고유 ID (PK/FK)

@ColumnDefault("0.3")
@Column(name = "rate", nullable = false)
private Float rate; //할인율, 디폴트 30%
@MapsId
@OneToOne
@JoinColumn(name = "product_id")
private Product product;

// @OneToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "root_category_id", nullable = true)
// private Category rootCategory; //카테고리 = root category
@Column(name = "discount_rate", nullable = false)
private Float discountRate;

@Column(name = "discount_price", nullable = false)
private Integer discountPrice;

@Builder
public Discount(Long id, Float rate) {
this.id = id;
this.rate = rate;
public Discount(Product product, Float discountRate, Integer discountPrice) {
this.product = product;
this.discountRate = discountRate;
this.discountPrice = discountPrice;
}
}
1 change: 0 additions & 1 deletion src/main/java/co/orange/ddanzi/domain/product/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.hibernate.annotations.ColumnDefault;

import java.time.LocalDate;
import java.util.UUID;

@Getter
@NoArgsConstructor
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/co/orange/ddanzi/domain/product/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

@Getter
@NoArgsConstructor
Expand All @@ -16,17 +17,21 @@ public class Option {
@Column(name = "option_id")
private Long id; //옵션 고유 ID

@Enumerated(EnumType.STRING)
@Column(name = "type")
private OptionType type; //옵션 종류
// @Enumerated(EnumType.STRING)
// @Column(name = "type")
// private OptionType type; //옵션 종류

@ColumnDefault("'옵션'")
@Column(name = "content", nullable = false)
private String content; //옵션 내용

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_id")
private Product product; //참조하는 상품

@Builder
public Option(final OptionType type, final Product product) {
this.type = type;
public Option(String content, Product product) {
this.content = content;
this.product = product;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ public class OptionDetail {
@Column(name = "content")
private String content; //세부 옵션 내용

@ColumnDefault("true")
@Column(name = "is_available")
private Boolean isAvailable; //옵션 선택 가능 여부

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "option_id")
private Option option; //참조하는 옵션

@Builder
public OptionDetail(String content, Option option) {
public OptionDetail(String content, Boolean isAvailable, Option option) {
this.content = content;
this.isAvailable = isAvailable;
this.option = option;
}
}
29 changes: 17 additions & 12 deletions src/main/java/co/orange/ddanzi/domain/product/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,46 @@
public class Product {
@Id
@Column(name = "product_id")
private String id; //상품 고유 ID
private String id; //상품 고유 ID

@Column(name = "kakao_product_id", nullable = false, unique = true)
private Long kakaoProductId; //카카오톡 선물하기 상품 ID
private Long kakaoProductId; //카카오톡 선물하기 상품 ID

@Column(name = "name", nullable = false)
private String name; //상품명
private String name; //상품명

@Column(name = "origin_name", nullable = false, unique = true)
private String originName; //변경 전 상품명

@Column(name = "origin_price", nullable = false)
private Integer originPrice; //정가=선물하기 가격
private Integer originPrice; //정가=선물하기 가격

@Column(name = "discount_price", nullable = false)
private Integer discountPrice; //할인 금액
// @OneToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "discount_id")
// private Discount discount; //할인 정보

@ColumnDefault("0")
@Column(name = "stock", nullable = false)
private Integer stock; //재고 수
private Integer stock; //재고 수

@Column(name = "img_url")
private String imgUrl; //상품 이미지
private String imgUrl; //상품 이미지

@Column(name = "info_url")
private String infoUrl; //상품 상세 정보 url
private String infoUrl; //상품 상세 정보 url

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "leaf_category_id")
private Category leafCategory;
private Category leafCategory; //리프 카테고리

@Builder
public Product (String id, Long kakaoProductId, String name, Integer originPrice, Integer discountPrice, String imgUrl, String infoUrl, Integer stock, Category leafCategory) {
public Product (String id, Long kakaoProductId, String name, String originName, Integer originPrice, String imgUrl, String infoUrl, Integer stock, Category leafCategory) {
this.id = id;
// this.discount = discount;
this.kakaoProductId = kakaoProductId;
this.name = name;
this.originName = originName;
this.originPrice = originPrice;
this.discountPrice = discountPrice;
this.imgUrl = imgUrl;
this.infoUrl = infoUrl;
this.stock = stock;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/co/orange/ddanzi/domain/user/Device.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package co.orange.ddanzi.domain.user;

import co.orange.ddanzi.domain.user.enums.DeviceType;
import jakarta.persistence.*;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Table(name = "device")
@Entity
public class Device {
@Id
@Column(name = "device_token")
private String deviceToken;

@Column(name = "type")
private DeviceType type;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
}
15 changes: 15 additions & 0 deletions src/main/java/co/orange/ddanzi/domain/user/enums/DeviceType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.orange.ddanzi.domain.user.enums;

import lombok.Getter;

@Getter
public enum DeviceType {
ANDROID("ANDROID"),
IOS("IOS")
;

private final String deviceToken;
DeviceType(String deviceToken) {
this.deviceToken = deviceToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
public class HomeDetailResponseDto {
private String name;
private String category;
// private Boolean isOptionExist;
private Boolean isOptionExist;
private Boolean isImminent;
private Integer discountRate;
private Integer stockCount;
private String infoUrl;
private Integer interestCount;
// private List<OptionInfo> optionList;
private List<OptionInfo> optionList;
}
2 changes: 1 addition & 1 deletion src/main/java/co/orange/ddanzi/dto/home/OptionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@Builder
public class OptionInfo {
private Long optionId;
private OptionType type;
private String type;
private List<OptionDetailInfo> optionDetailList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public Product toProduct(String id, Integer discountPrice, Category leafCategory
.kakaoProductId(kakaoProductId)
.name(productName)
.originPrice(originPrice)
.discountPrice(discountPrice)
.imgUrl(imgUrl)
.infoUrl(infoUrl)
.leafCategory(leafCategory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public enum Success {
SUCCESS(HttpStatus.OK, "Request successfully processed."),

// 200 OK SUCCESS
GET_REDIS_KEY_SUCCESS(HttpStatus.CREATED, "Successfully retrieved the redis key"),

GET_HOME_INFO_SUCCESS(HttpStatus.OK, "Successfully retrieved home information."),
GET_PRODUCT_DETAIL_SUCCESS(HttpStatus.OK, "Successfully retrieved product details."),

Expand Down Expand Up @@ -46,13 +48,16 @@ public enum Success {


// 201 CREATED
CREATE_PRODUCT_SUCCESS(HttpStatus.OK, "Successfully confirmed the product."),
CREATE_ORDER_SUCCESS(HttpStatus.OK, "Successfully completed the order"),
CREATE_ITEM_SUCCESS(HttpStatus.OK, "Successfully listed the item for sale."),
SET_REDIS_KEY_SUCCESS(HttpStatus.CREATED, "Successfully set the redis key"),

CREATE_PRODUCT_SUCCESS(HttpStatus.CREATED, "Successfully confirmed the product."),
CREATE_ORDER_SUCCESS(HttpStatus.CREATED, "Successfully completed the order"),
CREATE_ITEM_SUCCESS(HttpStatus.CREATED, "Successfully listed the item for sale."),
CREATE_INTEREST_SUCCESS(HttpStatus.CREATED, "Successfully added the product to interest List."),
CREATE_ADDRESS_SUCCESS(HttpStatus.CREATED, "Successfully added the delivery address."),
CREATE_ACCOUNT_SUCCESS(HttpStatus.CREATED, "Successfully added the account."),


;

private final HttpStatus httpStatus;
Expand Down
Loading

0 comments on commit d453b38

Please sign in to comment.