From 17074c3132f3d0d4e7c292ccde5e2c85388deeaf Mon Sep 17 00:00:00 2001 From: s-choi Date: Mon, 28 Sep 2026 15:22:44 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[ADD]=20=E3=82=B3=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=81=AE=E4=BD=9C=E6=88=90=E8=80=85=E3=82=92=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AE=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=83=96=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/infra/entity/CourseOwnerEntity.java | 37 +++++++++++++++++++ .../repository/CourseOwnerRepository.java | 9 +++++ 2 files changed, 46 insertions(+) create mode 100644 src/main/java/com/example/demo/app/infra/entity/CourseOwnerEntity.java create mode 100644 src/main/java/com/example/demo/app/infra/repository/CourseOwnerRepository.java diff --git a/src/main/java/com/example/demo/app/infra/entity/CourseOwnerEntity.java b/src/main/java/com/example/demo/app/infra/entity/CourseOwnerEntity.java new file mode 100644 index 0000000..ad301aa --- /dev/null +++ b/src/main/java/com/example/demo/app/infra/entity/CourseOwnerEntity.java @@ -0,0 +1,37 @@ +package com.example.demo.app.infra.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "course_owner_t") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CourseOwnerEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long courseOwnerId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private UserEntity userEntity; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "course_id") + private CourseEntity courseEntity; + + +} diff --git a/src/main/java/com/example/demo/app/infra/repository/CourseOwnerRepository.java b/src/main/java/com/example/demo/app/infra/repository/CourseOwnerRepository.java new file mode 100644 index 0000000..0d387cc --- /dev/null +++ b/src/main/java/com/example/demo/app/infra/repository/CourseOwnerRepository.java @@ -0,0 +1,9 @@ +package com.example.demo.app.infra.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.demo.app.infra.entity.CourseOwnerEntity; + +public interface CourseOwnerRepository extends JpaRepository{ + +} From a45045d008b31f2e7de559125a21e9e0a7ceae0f Mon Sep 17 00:00:00 2001 From: s-choi Date: Mon, 28 Sep 2026 15:23:27 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[EDIT]=20=E4=BB=96=E4=BA=BA=E3=81=8C?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=97=E3=81=9F=E3=82=B3=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=81=AF=E8=A6=8B=E3=81=88=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/model/CourseModel.java | 6 +-- .../app/domain/service/CourseService.java | 7 +++ .../service/impl/CourseServiceImpl.java | 31 ++++++++++++- .../domain/service/impl/UserServiceImpl.java | 3 ++ .../demo/app/infra/entity/CourseEntity.java | 4 -- .../infra/repository/CourseRepository.java | 15 ++++-- .../controller/CourseController.java | 46 +++++++++++++------ 7 files changed, 86 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/model/CourseModel.java b/src/main/java/com/example/demo/app/domain/model/CourseModel.java index 43303eb..fcf67ec 100644 --- a/src/main/java/com/example/demo/app/domain/model/CourseModel.java +++ b/src/main/java/com/example/demo/app/domain/model/CourseModel.java @@ -3,7 +3,6 @@ package com.example.demo.app.domain.model; import java.util.List; import com.example.demo.app.infra.entity.CourseEntity; -import com.example.demo.app.infra.entity.UserEntity; import lombok.AllArgsConstructor; import lombok.Getter; @@ -27,11 +26,10 @@ public class CourseModel { return courseEntityList.stream().map(CourseModel::convertFrom).toList(); } - public static CourseEntity convertTo(CourseModel courseModel, List userEntityList) { + public static CourseEntity convertTo(CourseModel courseModel) { return new CourseEntity( courseModel.getCourseId(), courseModel.getCourseName(), - courseModel.getDescription(), - userEntityList); + courseModel.getDescription()); } } diff --git a/src/main/java/com/example/demo/app/domain/service/CourseService.java b/src/main/java/com/example/demo/app/domain/service/CourseService.java index 4e583ee..f49459c 100644 --- a/src/main/java/com/example/demo/app/domain/service/CourseService.java +++ b/src/main/java/com/example/demo/app/domain/service/CourseService.java @@ -13,4 +13,11 @@ public interface CourseService { public Long findByName(String courName); public CourseModel save(CourseModel courseModel, Long userId); + + public List findAllByUserId(Long userId); + + public List findAllByNull(); + } + + diff --git a/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java index 046c6dc..cdba07c 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java @@ -3,12 +3,16 @@ package com.example.demo.app.domain.service.impl; import java.util.ArrayList; import java.util.List; +import jakarta.transaction.Transactional; + import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.CourseModel; import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.infra.entity.CourseEntity; +import com.example.demo.app.infra.entity.CourseOwnerEntity; import com.example.demo.app.infra.entity.UserEntity; +import com.example.demo.app.infra.repository.CourseOwnerRepository; import com.example.demo.app.infra.repository.CourseRepository; import com.example.demo.app.infra.repository.UserRepository; @@ -20,12 +24,22 @@ public class CourseServiceImpl implements CourseService { private final CourseRepository courseRepository; private final UserRepository userRepository; + private final CourseOwnerRepository courseOwnerRepository; public List findAll(){ return CourseEntity.createCourseModelList(courseRepository.findAll()); } + public List findAllByUserId(Long userId) { + + return CourseModel.convertFrom(courseRepository.findAllByUserId(userId)); + } + + public List findAllByNull() { + return CourseModel.convertFrom(courseRepository.findAllByNull()); + } + public CourseModel findById(Long courseId) { return CourseModel.convertFrom(courseRepository.findByCourseId(courseId)); } @@ -34,12 +48,27 @@ public class CourseServiceImpl implements CourseService { return courseRepository.findByCourseName(courseName).getCourseId(); } + @Transactional public CourseModel save(CourseModel courseModel, Long userId) { List userEntityList = new ArrayList<>(); userEntityList.add(userRepository.findById(userId).get()); + CourseEntity result = courseRepository.save( CourseModel.convertTo(courseModel)); + + UserEntity user = userRepository.findById(userId).orElse(null); + + user.setCourseEntity(result); + + UserEntity userResult = userRepository.save(user); + + CourseOwnerEntity courseOwnerEntity = new CourseOwnerEntity(); + courseOwnerEntity.setUserEntity(userResult); + courseOwnerEntity.setCourseEntity(result); + + courseOwnerRepository.save(courseOwnerEntity); + + return CourseModel.convertFrom(result); - return CourseModel.convertFrom( courseRepository.save( CourseModel.convertTo(courseModel, userEntityList))); } } diff --git a/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java index ed6c47f..20b862e 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java @@ -52,6 +52,9 @@ public class UserServiceImpl implements UserService { CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null); userEntity.setQuestionEntity(questionEntity); + + + userEntity.setCourseEntity(courseEntity); userEntity.setDeleteFlag(0); diff --git a/src/main/java/com/example/demo/app/infra/entity/CourseEntity.java b/src/main/java/com/example/demo/app/infra/entity/CourseEntity.java index fc66343..56cb01e 100644 --- a/src/main/java/com/example/demo/app/infra/entity/CourseEntity.java +++ b/src/main/java/com/example/demo/app/infra/entity/CourseEntity.java @@ -7,7 +7,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import com.example.demo.app.domain.model.CourseModel; @@ -35,9 +34,6 @@ public class CourseEntity { @Column(name = "description", nullable = false) private String description; - @OneToMany(mappedBy = "courseEntity") - private List userEntity; - public static List createCourseModelList(List courseEntityList) { return courseEntityList diff --git a/src/main/java/com/example/demo/app/infra/repository/CourseRepository.java b/src/main/java/com/example/demo/app/infra/repository/CourseRepository.java index 96fb2a9..a557a77 100644 --- a/src/main/java/com/example/demo/app/infra/repository/CourseRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/CourseRepository.java @@ -1,17 +1,24 @@ package com.example.demo.app.infra.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import com.example.demo.app.infra.entity.CourseEntity; public interface CourseRepository extends JpaRepository { - + @Query("SELECT c FROM CourseEntity c WHERE c.courseId = :courseId ") public CourseEntity findByCourseId(Long courseId); - + @Query("SELECT c FROM CourseEntity c WHERE c.courseName = :courseName ") public CourseEntity findByCourseName(String courseName); - - + + @Query("select c from CourseEntity c inner join CourseOwnerEntity o on c.courseId = o.courseEntity.courseId inner join UserEntity u on o.userEntity.userId = u.userId where u.userId = :userId") + public List findAllByUserId(Long userId); + + @Query("select c from CourseEntity c where c.courseId between 1 and 6") + public List findAllByNull(); + } diff --git a/src/main/java/com/example/demo/app/presentation/controller/CourseController.java b/src/main/java/com/example/demo/app/presentation/controller/CourseController.java index cd2f770..6166a96 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/CourseController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/CourseController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import com.example.demo.aop.aspect.SessionCheck; import com.example.demo.app.domain.model.AllocationModel; +import com.example.demo.app.domain.model.CourseModel; import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.service.AllocationService; import com.example.demo.app.domain.service.CourseInfoService; @@ -47,7 +48,9 @@ public class CourseController { session.setAttribute(PageReturnAttributeKeyword.USER_FORM, userForm); model.addAttribute(PageReturnAttributeKeyword.MODE, MODE); model.addAttribute(PageReturnAttributeKeyword.CURRENT_COURSE_ID, courseService.findByName(DEFAULT)); - model.addAttribute(PageReturnAttributeKeyword.COURSE_LIST, CourseForm.convertFrom(courseService.findAll())); + + model.addAttribute(PageReturnAttributeKeyword.COURSE_LIST, + CourseForm.convertFrom(courseService.findAllByNull())); model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST, CourseInfoForm.convertFrom(courseInfoService.findAll())); @@ -66,9 +69,15 @@ public class CourseController { Long currentCourseId = userService.findByUserId(userId).getCourseId(); + List courseModelList = new ArrayList<>(courseService.findAllByNull()); + + List tempList = courseService.findAllByUserId(userId); + + tempList.forEach(courseModelList::add); + model.addAttribute(PageReturnAttributeKeyword.MODE, MODE); model.addAttribute(PageReturnAttributeKeyword.CURRENT_COURSE_ID, currentCourseId); - model.addAttribute(PageReturnAttributeKeyword.COURSE_LIST, CourseForm.convertFrom(courseService.findAll())); + model.addAttribute(PageReturnAttributeKeyword.COURSE_LIST, CourseForm.convertFrom(courseModelList)); model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST, CourseInfoForm.convertFrom(courseInfoService.findAll())); @@ -117,27 +126,38 @@ public class CourseController { List allocationModelList = new ArrayList<>(); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId1(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio1())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio1())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId2(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio2())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio2())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId3(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio3())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio3())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId4(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio4())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio4())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId5(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio5())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio5())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId6(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio6())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio6())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId7(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio7())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio7())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId8(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio8())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio8())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId9(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio9())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio9())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId10(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio10())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio10())); allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId11(), - (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio11())); + (Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), + allocationFormList.getAllocationRatio11())); allocationService.save(allocationModelList); From d7a0aac3556601f3a40de9a3463c93d9e5d57e27 Mon Sep 17 00:00:00 2001 From: s-choi Date: Mon, 28 Sep 2026 15:26:36 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[FIX]=20=E4=B8=8B=E9=83=A8=E3=81=AE?= =?UTF-8?q?=E6=96=87=E5=AD=97=E3=81=8C=E9=9A=A0=E3=82=8C=E3=82=8B=E5=95=8F?= =?UTF-8?q?=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/course_create_ratio.html | 2 +- src/main/resources/templates/select_course.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/course_create_ratio.html b/src/main/resources/templates/course_create_ratio.html index 2c3283f..0ec7ccb 100644 --- a/src/main/resources/templates/course_create_ratio.html +++ b/src/main/resources/templates/course_create_ratio.html @@ -9,7 +9,7 @@ - +
diff --git a/src/main/resources/templates/select_course.html b/src/main/resources/templates/select_course.html index 8da86e6..aa8b300 100644 --- a/src/main/resources/templates/select_course.html +++ b/src/main/resources/templates/select_course.html @@ -34,7 +34,7 @@
+ data-bs-parent="#accordionExample" style="padding-bottom: 120px;">