diff --git a/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java b/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java index 20a4efc..e8813e5 100644 --- a/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java +++ b/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.vam.mapper.AdminMapper; +import com.vam.model.AttachImageVO; import com.vam.model.BookVO; import com.vam.model.CateVO; import com.vam.model.Criteria; @@ -27,6 +28,18 @@ public class AdminServiceImpl implements AdminService { adminMapper.bookEnroll(book); + if(book.getImageList() == null || book.getImageList().size() <= 0) { + return; + } + + book.getImageList().forEach(attach ->{ + + attach.setBookId(book.getBookId()); + adminMapper.imageEnroll(attach); + + }); + + } /* 카테고리 리스트 */ diff --git a/VamPa/src/test/java/com/vam/service/AdminServiceTests.java b/VamPa/src/test/java/com/vam/service/AdminServiceTests.java new file mode 100644 index 0000000..c3e994b --- /dev/null +++ b/VamPa/src/test/java/com/vam/service/AdminServiceTests.java @@ -0,0 +1,68 @@ +package com.vam.service; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.vam.model.AttachImageVO; +import com.vam.model.BookVO; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml") +public class AdminServiceTests { + + @Autowired + private AdminService service; + + + /* 상품 등록 & 상품 이미지 등록 테스트 */ + @Test + public void bookEnrollTEsts() { + + BookVO book = new BookVO(); + // 상품 정보 + book.setBookName("service 테스트"); + book.setAuthorId(27); + book.setPubleYear("2021-03-18"); + book.setPublisher("출판사"); + book.setCateCode("202001"); + book.setBookPrice(20000); + book.setBookStock(300); + book.setBookDiscount(0.23); + book.setBookIntro("책 소개 "); + book.setBookContents("책 목차 "); + + // 이미지 정보 + List imageList = new ArrayList(); + + AttachImageVO image1 = new AttachImageVO(); + AttachImageVO image2 = new AttachImageVO(); + + image1.setFileName("test Image 1"); + image1.setUploadPath("test image 1"); + image1.setUuid("test1111"); + + image2.setFileName("test Image 2"); + image2.setUploadPath("test image 2"); + image2.setUuid("test2222"); + + imageList.add(image1); + imageList.add(image2); + + + book.setImageList(imageList); + + // bookEnroll() 메서드 호출 + service.bookEnroll(book); + + System.out.println("등록된 VO : " + book); + + + } + +} diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index a81d780..30ee2b8 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Mon Jun 07 20:30:56 KST 2021 +#Sun Jun 13 17:29:35 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa m2e.projectName=VamPa groupId=com.vam diff --git a/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java b/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java index 0c6c694..fe64da7 100644 --- a/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java +++ b/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java @@ -27,6 +27,18 @@ public class AdminServiceImpl implements AdminService { adminMapper.bookEnroll(book); + if(book.getImageList() == null || book.getImageList().size() <= 0) { + return; + } + + book.getImageList().forEach(attach ->{ + + attach.setBookId(book.getBookId()); + adminMapper.imageEnroll(attach); + + }); + + } /* 카테고리 리스트 */ diff --git a/VamPa_MySQL/src/test/java/com/vam/service/AdminServiceTests.java b/VamPa_MySQL/src/test/java/com/vam/service/AdminServiceTests.java new file mode 100644 index 0000000..b128665 --- /dev/null +++ b/VamPa_MySQL/src/test/java/com/vam/service/AdminServiceTests.java @@ -0,0 +1,68 @@ +package com.vam.service; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.vam.model.AttachImageVO; +import com.vam.model.BookVO; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml") +public class AdminServiceTests { + + @Autowired + private AdminService service; + + + /* 상품 등록 & 상품 이미지 등록 테스트 */ + @Test + public void bookEnrollTEsts() { + + BookVO book = new BookVO(); + // 상품 정보 + book.setBookName("mapper 테스트"); + book.setAuthorId(8); + book.setPubleYear("2021-03-18"); + book.setPublisher("출판사"); + book.setCateCode("202001"); + book.setBookPrice(20000); + book.setBookStock(300); + book.setBookDiscount(0.23); + book.setBookIntro("책 소개 "); + book.setBookContents("책 목차 "); + + // 이미지 정보 + List imageList = new ArrayList(); + + AttachImageVO image1 = new AttachImageVO(); + AttachImageVO image2 = new AttachImageVO(); + + image1.setFileName("test Image 1"); + image1.setUploadPath("test image 1"); + image1.setUuid("test1111"); + + image2.setFileName("test Image 2"); + image2.setUploadPath("test image 2"); + image2.setUuid("test2222"); + + imageList.add(image1); + imageList.add(image2); + + + book.setImageList(imageList); + + // bookEnroll() 메서드 호출 + service.bookEnroll(book); + + System.out.println("등록된 VO : " + book); + + + } + +} diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 5d84855..61003b6 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Mon Jun 07 20:30:56 KST 2021 +#Sun Jun 13 18:53:10 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL m2e.projectName=VamPa_MySQL groupId=com.vam