From c0d76201b912cc8df1b2a8fdbf2f8c255c6d437e Mon Sep 17 00:00:00 2001 From: KORYEcan Date: Mon, 17 Apr 2023 15:52:41 +0900 Subject: [PATCH 1/5] =?UTF-8?q?entity=20=EC=84=A4=EA=B3=84=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/{orderproduct => order/product}/OrderProduct.java | 0 .../{orderproduct => order/product}/OrderProductRepository.java | 0 .../metamall/model/{ordersheet => order/sheet}/OrderSheet.java | 0 .../model/{ordersheet => order/sheet}/OrderSheetRepository.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/main/java/shop/mtcoding/metamall/model/{orderproduct => order/product}/OrderProduct.java (100%) rename src/main/java/shop/mtcoding/metamall/model/{orderproduct => order/product}/OrderProductRepository.java (100%) rename src/main/java/shop/mtcoding/metamall/model/{ordersheet => order/sheet}/OrderSheet.java (100%) rename src/main/java/shop/mtcoding/metamall/model/{ordersheet => order/sheet}/OrderSheetRepository.java (100%) diff --git a/src/main/java/shop/mtcoding/metamall/model/orderproduct/OrderProduct.java b/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProduct.java similarity index 100% rename from src/main/java/shop/mtcoding/metamall/model/orderproduct/OrderProduct.java rename to src/main/java/shop/mtcoding/metamall/model/order/product/OrderProduct.java diff --git a/src/main/java/shop/mtcoding/metamall/model/orderproduct/OrderProductRepository.java b/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProductRepository.java similarity index 100% rename from src/main/java/shop/mtcoding/metamall/model/orderproduct/OrderProductRepository.java rename to src/main/java/shop/mtcoding/metamall/model/order/product/OrderProductRepository.java diff --git a/src/main/java/shop/mtcoding/metamall/model/ordersheet/OrderSheet.java b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheet.java similarity index 100% rename from src/main/java/shop/mtcoding/metamall/model/ordersheet/OrderSheet.java rename to src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheet.java diff --git a/src/main/java/shop/mtcoding/metamall/model/ordersheet/OrderSheetRepository.java b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java similarity index 100% rename from src/main/java/shop/mtcoding/metamall/model/ordersheet/OrderSheetRepository.java rename to src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java From ab4ae0e055ffcf4b599d620c0d0315eab60b16a1 Mon Sep 17 00:00:00 2001 From: KORYEcan Date: Mon, 17 Apr 2023 15:57:35 +0900 Subject: [PATCH 2/5] =?UTF-8?q?repository=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ .../metamall/MetamallApplication.java | 6 ++-- .../metamall/model/log/error/ErrorLog.java | 1 + .../model/order/product/OrderProduct.java | 16 +++++++-- .../order/product/OrderProductRepository.java | 2 +- .../model/order/sheet/OrderSheet.java | 29 +++++++++++++--- .../order/sheet/OrderSheetRepository.java | 15 ++++++++- .../metamall/model/product/Product.java | 33 ++++++++++++++++++- .../mtcoding/metamall/model/user/User.java | 33 ++++++++++++++++++- src/main/resources/application.yml | 12 +++++++ 10 files changed, 136 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 4943187..88a261e 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,8 @@ repositories { } dependencies { + implementation 'org.springframework.boot:spring-boot-starter-aop' + implementation 'org.springframework.boot:spring-boot-starter-validation' implementation group: 'com.auth0', name: 'java-jwt', version: '4.3.0' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' @@ -27,6 +29,7 @@ dependencies { runtimeOnly 'com.h2database:h2' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' + } tasks.named('test') { diff --git a/src/main/java/shop/mtcoding/metamall/MetamallApplication.java b/src/main/java/shop/mtcoding/metamall/MetamallApplication.java index 487bb62..9152593 100644 --- a/src/main/java/shop/mtcoding/metamall/MetamallApplication.java +++ b/src/main/java/shop/mtcoding/metamall/MetamallApplication.java @@ -4,10 +4,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import shop.mtcoding.metamall.model.orderproduct.OrderProduct; -import shop.mtcoding.metamall.model.orderproduct.OrderProductRepository; -import shop.mtcoding.metamall.model.ordersheet.OrderSheet; -import shop.mtcoding.metamall.model.ordersheet.OrderSheetRepository; +import shop.mtcoding.metamall.model.order.product.OrderProductRepository; +import shop.mtcoding.metamall.model.order.sheet.OrderSheetRepository; import shop.mtcoding.metamall.model.product.ProductRepository; import shop.mtcoding.metamall.model.user.User; import shop.mtcoding.metamall.model.user.UserRepository; diff --git a/src/main/java/shop/mtcoding/metamall/model/log/error/ErrorLog.java b/src/main/java/shop/mtcoding/metamall/model/log/error/ErrorLog.java index fbfe7e5..41dad1d 100644 --- a/src/main/java/shop/mtcoding/metamall/model/log/error/ErrorLog.java +++ b/src/main/java/shop/mtcoding/metamall/model/log/error/ErrorLog.java @@ -17,6 +17,7 @@ public class ErrorLog { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(nullable = false, length = 100000) private String msg; private Long userId; diff --git a/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProduct.java b/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProduct.java index 165905e..a369e37 100644 --- a/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProduct.java +++ b/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProduct.java @@ -1,10 +1,10 @@ -package shop.mtcoding.metamall.model.orderproduct; +package shop.mtcoding.metamall.model.order.product; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import shop.mtcoding.metamall.model.ordersheet.OrderSheet; +import shop.mtcoding.metamall.model.order.sheet.OrderSheet; import shop.mtcoding.metamall.model.product.Product; import javax.persistence.*; @@ -19,9 +19,13 @@ public class OrderProduct { // 주문 상품 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + //chekcpoint -> 무한 참조 @ManyToOne private Product product; + @Column(nullable = false) private Integer count; // 상품 주문 개수 + @Column(nullable = false) private Integer orderPrice; // 상품 주문 금액 private LocalDateTime createdAt; private LocalDateTime updatedAt; @@ -29,6 +33,14 @@ public class OrderProduct { // 주문 상품 @ManyToOne private OrderSheet orderSheet; + + //checkpoint-> 편의 메서드 만드는 이유 + public void syncOrderSheet(OrderSheet orderSheet){ + this.orderSheet=orderSheet; + + } + + @PrePersist protected void onCreate() { this.createdAt = LocalDateTime.now(); diff --git a/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProductRepository.java b/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProductRepository.java index 6f1238c..1b686dc 100644 --- a/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProductRepository.java +++ b/src/main/java/shop/mtcoding/metamall/model/order/product/OrderProductRepository.java @@ -1,4 +1,4 @@ -package shop.mtcoding.metamall.model.orderproduct; +package shop.mtcoding.metamall.model.order.product; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheet.java b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheet.java index 7638710..febf261 100644 --- a/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheet.java +++ b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheet.java @@ -1,11 +1,10 @@ -package shop.mtcoding.metamall.model.ordersheet; +package shop.mtcoding.metamall.model.order.sheet; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import shop.mtcoding.metamall.model.orderproduct.OrderProduct; -import shop.mtcoding.metamall.model.product.Product; +import shop.mtcoding.metamall.model.order.product.OrderProduct; import shop.mtcoding.metamall.model.user.User; import javax.persistence.*; @@ -24,12 +23,26 @@ public class OrderSheet { // 주문서 private Long id; @ManyToOne private User user; // 주문자 - @OneToMany(mappedBy = "orderSheet") + + //checkpoint -> 무한참조 + @OneToMany(mappedBy = "orderSheet", cascade = CascadeType.ALL, orphanRemoval = true) private List orderProductList = new ArrayList<>(); // 총 주문 상품 리스트 + + @Column(nullable = false) private Integer totalPrice; // 총 주문 금액 (총 주문 상품 리스트의 orderPrice 합) private LocalDateTime createdAt; private LocalDateTime updatedAt; + public void addOrderProduct(OrderProduct orderProduct){ + orderProductList.add(orderProduct); + orderProduct.syncOrderSheet(this); + } + public void removeOrderProduct(OrderProduct orderProduct){ + orderProductList.remove(orderProduct); + orderProduct.syncOrderSheet(null); + } + + @PrePersist protected void onCreate() { this.createdAt = LocalDateTime.now(); @@ -42,6 +55,14 @@ protected void onUpdate() { // 연관관계 메서드 구현 필요 + + + + + + + + @Builder public OrderSheet(Long id, User user, Integer totalPrice, LocalDateTime createdAt, LocalDateTime updatedAt) { this.id = id; diff --git a/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java index 5d59249..72ecf3e 100644 --- a/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java +++ b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java @@ -1,6 +1,19 @@ -package shop.mtcoding.metamall.model.ordersheet; +package shop.mtcoding.metamall.model.order.sheet; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; public interface OrderSheetRepository extends JpaRepository { + + //내가 주문한 목록보기 + @Query("select os from OrderSheet os where os.user.id= :userId") + List findByUserId(@Param("userId") Long userId); + + + + + } diff --git a/src/main/java/shop/mtcoding/metamall/model/product/Product.java b/src/main/java/shop/mtcoding/metamall/model/product/Product.java index bc8c618..013db95 100644 --- a/src/main/java/shop/mtcoding/metamall/model/product/Product.java +++ b/src/main/java/shop/mtcoding/metamall/model/product/Product.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import shop.mtcoding.metamall.model.user.User; import javax.persistence.*; import java.time.LocalDateTime; @@ -17,12 +18,41 @@ public class Product { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @ManyToOne + private User seller; //seller_id -> DB에 표시될 이름 + + @Column(nullable = false, length = 50) private String name; // 상품 이름 + @Column(nullable = false) private Integer price; // 상품 가격 + @Column(nullable = false) private Integer qty; // 상품 재고 private LocalDateTime createdAt; private LocalDateTime updatedAt; + + //판매자 상품 변경 (판매자 입장) + public void update(String name, Integer price, Integer qty){ + this.name=name; + this.price=price; + this.qty=qty; + } + + //주문시 재고 변경 (구매자 입장) + public void updateQty(Integer orderCount){ + if (this.qty 단방향 암호화 60Byte private String password; + @Column(nullable = false,length = 50) private String email; + @Column(nullable = false,length = 10) private String role; // USER(고객), SELLER(판매자), ADMIN(관리자) + + @Column(nullable = false, length = 10) + private Boolean status; // true 활성게정 , false 비활성게정 + + + @Column(nullable = false) private LocalDateTime createdAt; private LocalDateTime updatedAt; + + //권한 변경(관리자) + public void updateRole(String role){ + if (this.role.equals(role)){ + //checkpoint 동일한 권한으로 변경할 수 없습니다. + } + this.role=role; + } + //회원 탈퇴 + public void delete(){ + this.status=false; + } + + + + + @PrePersist protected void onCreate() { this.createdAt = LocalDateTime.now(); @@ -35,12 +64,14 @@ protected void onUpdate() { } @Builder - public User(Long id, String username, String password, String email, String role, LocalDateTime createdAt) { + public User(Long id, String username, String password, String email, String role, Boolean status, LocalDateTime createdAt, LocalDateTime updatedAt) { this.id = id; this.username = username; this.password = password; this.email = email; this.role = role; + this.status = status; this.createdAt = createdAt; + this.updatedAt = updatedAt; } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1d9bd50..dccdf4c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -22,6 +22,18 @@ spring: format_sql: true default_batch_fetch_size: 100 # in query 자동 작성 + # 404 처리하는 법 + + mvc: + throw-exception-if-no-handler-found: true + web: + resources: + add-mappings: false + +# hibernateLazyInitializer 오류 해결법 +# jackson: + + logging: level: '[shop.mtcoding.metamall]': DEBUG # DEBUG 레벨부터 에러 확인할 수 있게 설정하기 From cafeb43e70a9479a2c4070cbcad4c6e99ae1df4d Mon Sep 17 00:00:00 2001 From: KORYEcan Date: Mon, 17 Apr 2023 16:01:35 +0900 Subject: [PATCH 3/5] =?UTF-8?q?dummy=C3=AC=C2=84=ED=8C=85=C3=AC=C2=98?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/mtcoding/metamall/MetamallApplication.java | 10 ++++++---- .../model/order/sheet/OrderSheetRepository.java | 4 ---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/shop/mtcoding/metamall/MetamallApplication.java b/src/main/java/shop/mtcoding/metamall/MetamallApplication.java index 9152593..a7b8444 100644 --- a/src/main/java/shop/mtcoding/metamall/MetamallApplication.java +++ b/src/main/java/shop/mtcoding/metamall/MetamallApplication.java @@ -10,16 +10,18 @@ import shop.mtcoding.metamall.model.user.User; import shop.mtcoding.metamall.model.user.UserRepository; +import java.util.Arrays; + @SpringBootApplication public class MetamallApplication { @Bean CommandLineRunner initData(UserRepository userRepository, ProductRepository productRepository, OrderProductRepository orderProductRepository, OrderSheetRepository orderSheetRepository){ return (args)->{ - // 여기에서 save 하면 됨. - // bulk Collector는 saveAll 하면 됨. - User ssar = User.builder().username("ssar").password("1234").email("ssar@nate.com").role("USER").build(); - userRepository.save(ssar); + User ssar = User.builder().username("ssar").password("1234").email("ssar@nate.com").role("USER").status(true).build(); + User seller = User.builder().username("seller").password("1234").email("ssar@nate.com").role("SELLER").status(true).build(); + User admin = User.builder().username("admin").password("1234").email("ssar@nate.com").role("ADMIN").status(true).build(); + userRepository.saveAll(Arrays.asList(ssar,seller,admin)); }; } diff --git a/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java index 72ecf3e..853dfa2 100644 --- a/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java +++ b/src/main/java/shop/mtcoding/metamall/model/order/sheet/OrderSheetRepository.java @@ -12,8 +12,4 @@ public interface OrderSheetRepository extends JpaRepository { @Query("select os from OrderSheet os where os.user.id= :userId") List findByUserId(@Param("userId") Long userId); - - - - } From 991c7efcce8b2d188805b5f3b41814f573a13907 Mon Sep 17 00:00:00 2001 From: KORYEcan Date: Mon, 17 Apr 2023 16:35:46 +0900 Subject: [PATCH 4/5] =?UTF-8?q?exception=EC=B2=98=EB=A6=AC=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metamall/core/exception/Exception404.java | 24 ------------------- .../metamall/core/exception/Exception500.java | 24 ------------------- .../metamall/{ => core}/util/MyDateUtil.java | 0 .../core/util/MyFilterResponseUtil.java | 2 ++ .../{ResponseDto.java => ResponseDTO.java} | 0 .../mtcoding/metamall/dto/user/ValidDTO.java | 2 ++ 6 files changed, 4 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/shop/mtcoding/metamall/core/exception/Exception404.java delete mode 100644 src/main/java/shop/mtcoding/metamall/core/exception/Exception500.java rename src/main/java/shop/mtcoding/metamall/{ => core}/util/MyDateUtil.java (100%) create mode 100644 src/main/java/shop/mtcoding/metamall/core/util/MyFilterResponseUtil.java rename src/main/java/shop/mtcoding/metamall/dto/{ResponseDto.java => ResponseDTO.java} (100%) create mode 100644 src/main/java/shop/mtcoding/metamall/dto/user/ValidDTO.java diff --git a/src/main/java/shop/mtcoding/metamall/core/exception/Exception404.java b/src/main/java/shop/mtcoding/metamall/core/exception/Exception404.java deleted file mode 100644 index c20b64f..0000000 --- a/src/main/java/shop/mtcoding/metamall/core/exception/Exception404.java +++ /dev/null @@ -1,24 +0,0 @@ -package shop.mtcoding.metamall.core.exception; - -import lombok.Getter; -import org.springframework.http.HttpStatus; -import shop.mtcoding.metamall.dto.ResponseDto; - - -// 리소스 없음 -@Getter -public class Exception404 extends RuntimeException { - public Exception404(String message) { - super(message); - } - - public ResponseDto body(){ - ResponseDto responseDto = new ResponseDto<>(); - responseDto.fail(HttpStatus.NOT_FOUND, "notFound", getMessage()); - return responseDto; - } - - public HttpStatus status(){ - return HttpStatus.NOT_FOUND; - } -} \ No newline at end of file diff --git a/src/main/java/shop/mtcoding/metamall/core/exception/Exception500.java b/src/main/java/shop/mtcoding/metamall/core/exception/Exception500.java deleted file mode 100644 index d3d4468..0000000 --- a/src/main/java/shop/mtcoding/metamall/core/exception/Exception500.java +++ /dev/null @@ -1,24 +0,0 @@ -package shop.mtcoding.metamall.core.exception; - -import lombok.Getter; -import org.springframework.http.HttpStatus; -import shop.mtcoding.metamall.dto.ResponseDto; - - -// 서버 에러 -@Getter -public class Exception500 extends RuntimeException { - public Exception500(String message) { - super(message); - } - - public ResponseDto body(){ - ResponseDto responseDto = new ResponseDto<>(); - responseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "serverError", getMessage()); - return responseDto; - } - - public HttpStatus status(){ - return HttpStatus.INTERNAL_SERVER_ERROR; - } -} \ No newline at end of file diff --git a/src/main/java/shop/mtcoding/metamall/util/MyDateUtil.java b/src/main/java/shop/mtcoding/metamall/core/util/MyDateUtil.java similarity index 100% rename from src/main/java/shop/mtcoding/metamall/util/MyDateUtil.java rename to src/main/java/shop/mtcoding/metamall/core/util/MyDateUtil.java diff --git a/src/main/java/shop/mtcoding/metamall/core/util/MyFilterResponseUtil.java b/src/main/java/shop/mtcoding/metamall/core/util/MyFilterResponseUtil.java new file mode 100644 index 0000000..e2c345a --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/util/MyFilterResponseUtil.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.util;public class MyFilterResponseUtil { +} diff --git a/src/main/java/shop/mtcoding/metamall/dto/ResponseDto.java b/src/main/java/shop/mtcoding/metamall/dto/ResponseDTO.java similarity index 100% rename from src/main/java/shop/mtcoding/metamall/dto/ResponseDto.java rename to src/main/java/shop/mtcoding/metamall/dto/ResponseDTO.java diff --git a/src/main/java/shop/mtcoding/metamall/dto/user/ValidDTO.java b/src/main/java/shop/mtcoding/metamall/dto/user/ValidDTO.java new file mode 100644 index 0000000..8a7713f --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/dto/user/ValidDTO.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.dto.user;public class ValidDTO { +} From 2a69a31905f5e70eb2cb2d7d3aaab702444c0040 Mon Sep 17 00:00:00 2001 From: KORYEcan Date: Mon, 17 Apr 2023 17:17:06 +0900 Subject: [PATCH 5/5] =?UTF-8?q?core=EC=84=B8=ED=8C=85=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metamall/config/MyWebMvcConfig.java | 49 +++++++++++++++++++ .../metamall/config/WebMvcConfig.java | 18 ------- .../core/advice/MyErrorLogAdvice.java | 2 + .../core/advice/MySameUserIdAdvice.java | 2 + .../metamall/core/advice/MyValidAdvice.java | 2 + .../core/annotation/MyErrorLogRecord.java | 2 + .../core/annotation/MySameUserIdCheck.java | 2 + .../core/annotation/MySessionStore.java | 2 + .../core/interceptor/MyAdminInterceptor.java | 2 + .../core/interceptor/MySellerInterceptor.java | 2 + .../resolver/MySessionArgumentResolver.java | 2 + .../{LoginUser.java => SessionUser.java} | 0 12 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 src/main/java/shop/mtcoding/metamall/config/MyWebMvcConfig.java delete mode 100644 src/main/java/shop/mtcoding/metamall/config/WebMvcConfig.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/advice/MyErrorLogAdvice.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/advice/MySameUserIdAdvice.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/advice/MyValidAdvice.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/annotation/MyErrorLogRecord.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/annotation/MySameUserIdCheck.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/annotation/MySessionStore.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/interceptor/MyAdminInterceptor.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/interceptor/MySellerInterceptor.java create mode 100644 src/main/java/shop/mtcoding/metamall/core/resolver/MySessionArgumentResolver.java rename src/main/java/shop/mtcoding/metamall/core/session/{LoginUser.java => SessionUser.java} (100%) diff --git a/src/main/java/shop/mtcoding/metamall/config/MyWebMvcConfig.java b/src/main/java/shop/mtcoding/metamall/config/MyWebMvcConfig.java new file mode 100644 index 0000000..ca60977 --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/config/MyWebMvcConfig.java @@ -0,0 +1,49 @@ +package shop.mtcoding.metamall.config; + +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import shop.mtcoding.metamall.core.interceptor.MyAdminInterceptor; +import shop.mtcoding.metamall.core.interceptor.MySellerInterceptor; +import shop.mtcoding.metamall.core.resolver.MySessionArgumentResolver; + +import java.util.List; + +@RequiredArgsConstructor +@Configuration +public class WebMvcConfig implements WebMvcConfigurer { + + private final MyAdminInterceptor adminInterceptor; + private final MySellerInterceptor sellerInterceptor; + private final MySessionArgumentResolver mySessionArgumentResolver; + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedHeaders("*") + .allowedMethods("*") // GET, POST, PUT, DELETE (Javascript 요청 허용) + .allowedOriginPatterns("*") // 모든 IP 주소 허용 (프론트 앤드 IP만 허용하게 변경해야함. * 안됨) + .allowCredentials(true) + .exposedHeaders("Authorization"); // 옛날에는 디폴트로 브라우저에 노출되어 있었는데 지금은 아님 + } + + + // AOP는 매개변수 값 확인해서 권한 비교해야할 때 사용 + // Interceptor는 세션 권한으로 체크할 때 사용 + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(adminInterceptor) + .addPathPatterns("/admin/**"); + + registry.addInterceptor(sellerInterceptor) + .addPathPatterns("/seller/**"); + } + + @Override + public void addArgumentResolvers(List resolvers) { + resolvers.add(mySessionArgumentResolver); + } +} \ No newline at end of file diff --git a/src/main/java/shop/mtcoding/metamall/config/WebMvcConfig.java b/src/main/java/shop/mtcoding/metamall/config/WebMvcConfig.java deleted file mode 100644 index 64f5d9b..0000000 --- a/src/main/java/shop/mtcoding/metamall/config/WebMvcConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package shop.mtcoding.metamall.config; - -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 WebMvcConfig implements WebMvcConfigurer { - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedHeaders("*") - .allowedMethods("*") // GET, POST, PUT, DELETE (Javascript 요청 허용) - .allowedOriginPatterns("*") // 모든 IP 주소 허용 (프론트 앤드 IP만 허용하게 변경해야함. * 안됨) - .allowCredentials(true) - .exposedHeaders("Authorization"); // 옛날에는 디폴트로 브라우저에 노출되어 있었는데 지금은 아님 - } -} diff --git a/src/main/java/shop/mtcoding/metamall/core/advice/MyErrorLogAdvice.java b/src/main/java/shop/mtcoding/metamall/core/advice/MyErrorLogAdvice.java new file mode 100644 index 0000000..8fa7b67 --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/advice/MyErrorLogAdvice.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.advice;public class MyErrorLogAdvice { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/advice/MySameUserIdAdvice.java b/src/main/java/shop/mtcoding/metamall/core/advice/MySameUserIdAdvice.java new file mode 100644 index 0000000..16c73bf --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/advice/MySameUserIdAdvice.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.advice;public class MySameUserIdAdvice { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/advice/MyValidAdvice.java b/src/main/java/shop/mtcoding/metamall/core/advice/MyValidAdvice.java new file mode 100644 index 0000000..fddc42f --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/advice/MyValidAdvice.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.advice;public class MyValidAdvice { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/annotation/MyErrorLogRecord.java b/src/main/java/shop/mtcoding/metamall/core/annotation/MyErrorLogRecord.java new file mode 100644 index 0000000..d9b19fc --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/annotation/MyErrorLogRecord.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.annotation;public class MyErrorLogRecord { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/annotation/MySameUserIdCheck.java b/src/main/java/shop/mtcoding/metamall/core/annotation/MySameUserIdCheck.java new file mode 100644 index 0000000..53785f0 --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/annotation/MySameUserIdCheck.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.annotation;public @interface MySameUserIdCheck { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/annotation/MySessionStore.java b/src/main/java/shop/mtcoding/metamall/core/annotation/MySessionStore.java new file mode 100644 index 0000000..14f0253 --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/annotation/MySessionStore.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.annotation;public @interface MySessionStore { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/interceptor/MyAdminInterceptor.java b/src/main/java/shop/mtcoding/metamall/core/interceptor/MyAdminInterceptor.java new file mode 100644 index 0000000..142bb47 --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/interceptor/MyAdminInterceptor.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.interceptor;public class MyAdminInterceptor { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/interceptor/MySellerInterceptor.java b/src/main/java/shop/mtcoding/metamall/core/interceptor/MySellerInterceptor.java new file mode 100644 index 0000000..1ebbe82 --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/interceptor/MySellerInterceptor.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.interceptor;public class MySellerInterceptor { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/resolver/MySessionArgumentResolver.java b/src/main/java/shop/mtcoding/metamall/core/resolver/MySessionArgumentResolver.java new file mode 100644 index 0000000..885e07a --- /dev/null +++ b/src/main/java/shop/mtcoding/metamall/core/resolver/MySessionArgumentResolver.java @@ -0,0 +1,2 @@ +package shop.mtcoding.metamall.core.resolver;public class MySessionArgumentResolver { +} diff --git a/src/main/java/shop/mtcoding/metamall/core/session/LoginUser.java b/src/main/java/shop/mtcoding/metamall/core/session/SessionUser.java similarity index 100% rename from src/main/java/shop/mtcoding/metamall/core/session/LoginUser.java rename to src/main/java/shop/mtcoding/metamall/core/session/SessionUser.java