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

[10] 상품 등록 #17

Merged
merged 10 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.0'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
165 changes: 165 additions & 0 deletions docs/DDL.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
-- ecommerce_site.users definition
CREATE TABLE `users` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`email` varchar(30) NOT NULL,
`status` varchar(30) NOT NULL DEFAULT 'ACTIVE',
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='회원';

-- ecommerce_site.partners definition
CREATE TABLE `partners` (
`id` bigint NOT NULL AUTO_INCREMENT,
`business_number` varchar(50) NOT NULL,
`name` varchar(20) NOT NULL,
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`email` varchar(30) NOT NULL,
`status` varchar(30) NOT NULL DEFAULT 'ACTIVE',
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='파트너';

-- ecommerce_site.categories definition
CREATE TABLE `categories` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(100) DEFAULT NULL,
`parent_category_id` bigint DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='카테고리';

-- ecommerce_site.addresses definition

CREATE TABLE `addresses` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`phone_number` varchar(11) NOT NULL,
`zip_code` varchar(5) NOT NULL,
`address` varchar(50) NOT NULL,
`address_detail` varchar(50) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_user_TO_address` (`user_id`),
CONSTRAINT `FK_user_TO_address` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='배송지';

-- ecommerce_site.products definition

CREATE TABLE `products` (
`id` bigint NOT NULL AUTO_INCREMENT,
`partner_id` bigint NOT NULL,
`category_id` bigint NOT NULL,
`name` varchar(100) NOT NULL,
`description` json NOT NULL,
`price` bigint NOT NULL,
`stock_quantity` bigint NOT NULL DEFAULT '1',
`is_enable` tinyint(1) NOT NULL DEFAULT '1',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_partner_TO_product` (`partner_id`),
KEY `FK_category_TO_product` (`category_id`),
CONSTRAINT `FK_category_TO_product` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`),
CONSTRAINT `FK_partner_TO_product` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='상품';

-- ecommerce_site.carts definition

CREATE TABLE `carts` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`product_id` bigint NOT NULL,
`quantity` bigint NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_user_TO_cart` (`user_id`),
KEY `FK_product_TO_cart` (`product_id`),
CONSTRAINT `FK_product_TO_cart` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
CONSTRAINT `FK_user_TO_cart` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='장바구니';

-- ecommerce_site.orders definition

CREATE TABLE `orders` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`total_amount` bigint NOT NULL,
`status` varchar(30) NOT NULL DEFAULT 'PENDING',
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_user_TO_order` (`user_id`),
CONSTRAINT `FK_user_TO_order` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='주문';

-- ecommerce_site.order_details definition

CREATE TABLE `order_details` (
`id` bigint NOT NULL AUTO_INCREMENT,
`order_id` bigint NOT NULL,
`product_id` bigint NOT NULL,
`quantity` bigint NOT NULL,
`unit_price` bigint NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_order_TO_order_detail` (`order_id`),
KEY `FK_product_TO_order_detail` (`product_id`),
CONSTRAINT `FK_order_TO_order_detail` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`),
CONSTRAINT `FK_product_TO_order_detail` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='주문 상세';

-- ecommerce_site.payments definition

CREATE TABLE `payments` (
`id` bigint NOT NULL AUTO_INCREMENT,
`order_id` bigint NOT NULL,
`payment_method` varchar(30) NOT NULL DEFAULT 'CREDIT_CARD',
`status` varchar(30) NOT NULL DEFAULT 'PENDING',
`amount` bigint NOT NULL,
`payment_date` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_order_TO_payment` (`order_id`),
CONSTRAINT `FK_order_TO_payment` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='결제';

-- ecommerce_site.reviews definition

CREATE TABLE `reviews` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` bigint NOT NULL,
`product_id` bigint NOT NULL,
`rating` int NOT NULL,
`comment` longtext NOT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_user_TO_review` (`user_id`),
KEY `FK_product_TO_review` (`product_id`),
CONSTRAINT `FK_product_TO_review` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
CONSTRAINT `FK_user_TO_review` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='리뷰';

-- ecommerce_site.shipments definition

CREATE TABLE `shipments` (
`id` bigint NOT NULL AUTO_INCREMENT,
`order_id` bigint NOT NULL,
`order_detail_id` bigint NOT NULL,
`tracking_number` varchar(30) NOT NULL,
`status` varchar(30) NOT NULL DEFAULT 'SHIPPED',
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_order_TO_shipment` (`order_id`),
KEY `FK_order_detail_TO_shipment` (`order_detail_id`),
CONSTRAINT `FK_order_detail_TO_shipment` FOREIGN KEY (`order_detail_id`) REFERENCES `order_details` (`id`),
CONSTRAINT `FK_order_TO_shipment` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='배송';
62 changes: 62 additions & 0 deletions docs/naver-intellij-formatter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<code_scheme name="Naver-coding-convention-v1.2">
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<emptyLine />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="com.nhncorp" withSubpackages="true" static="false" />
<emptyLine />
<package name="com.navercorp" withSubpackages="true" static="false" />
<emptyLine />
<package name="com.naver" withSubpackages="true" static="false" />
<emptyLine />
</value>
</option>
<option name="RIGHT_MARGIN" value="120" />
<option name="ENABLE_JAVADOC_FORMATTING" value="false" />
<option name="JD_KEEP_EMPTY_LINES" value="false" />
<option name="FORMATTER_TAGS_ENABLED" value="true" />
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="JAVA">
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
<option name="LINE_COMMENT_ADD_SPACE" value="true" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="SPACE_AFTER_TYPE_CAST" value="false" />
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="1" />
<option name="METHOD_PARAMETERS_WRAP" value="1" />
<option name="EXTENDS_LIST_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="THROWS_LIST_WRAP" value="5" />
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
<option name="BINARY_OPERATION_WRAP" value="1" />
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
<option name="TERNARY_OPERATION_WRAP" value="1" />
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@EnableJpaAuditing
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
public class CommerceSiteApplication {
public static void main(String[] args) {
SpringApplication.run(CommerceSiteApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(CommerceSiteApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example.commerce_site.application.category;

import org.example.commerce_site.common.exception.CustomException;
import org.example.commerce_site.common.exception.ErrorCode;
import org.example.commerce_site.domain.Category;
import org.example.commerce_site.infrastructure.CategoryRepository;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@RequiredArgsConstructor
public class CategoryService {
private final CategoryRepository categoryRepository;

public Category getCategoryById(Long id) {
return categoryRepository.findById(id).orElseThrow(
() -> new CustomException(ErrorCode.CATEGORY_NOT_FOUND)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package org.example.commerce_site.application.partner;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.commerce_site.application.partner.dto.PartnerRequestDto;
import org.example.commerce_site.application.partner.dto.PartnerResponseDto;
import org.example.commerce_site.infrastructure.PartnerRepository;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@RequiredArgsConstructor
public class PartnerService {
private final PartnerRepository partnerRepository;
private final PartnerRepository partnerRepository;

public PartnerResponseDto.Create create(PartnerRequestDto.Create dto) {
return PartnerResponseDto.Create.of(partnerRepository.save(PartnerRequestDto.Create.toEntity(dto)));
}
public PartnerResponseDto.Create create(PartnerRequestDto.Create dto) {
// TODO : email 중복 체크
return PartnerResponseDto.Create.of(partnerRepository.save(PartnerRequestDto.Create.toEntity(dto)));
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package org.example.commerce_site.application.partner.dto;

import org.example.commerce_site.attribute.PartnerStatus;
import org.example.commerce_site.domain.Partner;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.example.commerce_site.attribute.PartnerStatus;
import org.example.commerce_site.domain.Partner;

public class PartnerRequestDto {
@Getter
@Builder
@ToString
public static class Create {
private String name;
private String email;
private String password;
private String businessNumber;
@Getter
@Builder
@ToString
public static class Create {
private String name;
private String email;
private String password;
private String businessNumber;

public static Partner toEntity(PartnerRequestDto.Create dto) {
return Partner.builder()
.name(dto.getName())
.email(dto.getEmail())
.password(dto.getPassword())
.status(PartnerStatus.ACTIVE)
.businessNumber(dto.getBusinessNumber())
.build();
}
}
public static Partner toEntity(PartnerRequestDto.Create dto) {
return Partner.builder()
.name(dto.getName())
.email(dto.getEmail())
.password(dto.getPassword())
.status(PartnerStatus.ACTIVE)
.businessNumber(dto.getBusinessNumber())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package org.example.commerce_site.application.partner.dto;

import org.example.commerce_site.domain.Partner;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.example.commerce_site.domain.Partner;

public class PartnerResponseDto {
@Builder
@Getter
@ToString
public static class Create {
private String name;
private String email;
private String businessNumber;
@Builder
@Getter
@ToString
public static class Create {
private String name;
private String email;
private String businessNumber;

public static PartnerResponseDto.Create of(Partner partner) {
return Create.builder()
.name(partner.getName())
.email(partner.getEmail())
.businessNumber(partner.getBusinessNumber())
.build();
}
}
public static PartnerResponseDto.Create of(Partner partner) {
return Create.builder()
.name(partner.getName())
.email(partner.getEmail())
.businessNumber(partner.getBusinessNumber())
.build();
}
}
}
Loading
Loading