Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into n-kawahito
This commit is contained in:
@@ -3,7 +3,6 @@ package com.example.demo.app.domain.model;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.CourseEntity;
|
import com.example.demo.app.infra.entity.CourseEntity;
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -27,11 +26,10 @@ public class CourseModel {
|
|||||||
return courseEntityList.stream().map(CourseModel::convertFrom).toList();
|
return courseEntityList.stream().map(CourseModel::convertFrom).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CourseEntity convertTo(CourseModel courseModel, List<UserEntity> userEntityList) {
|
public static CourseEntity convertTo(CourseModel courseModel) {
|
||||||
return new CourseEntity(
|
return new CourseEntity(
|
||||||
courseModel.getCourseId(),
|
courseModel.getCourseId(),
|
||||||
courseModel.getCourseName(),
|
courseModel.getCourseName(),
|
||||||
courseModel.getDescription(),
|
courseModel.getDescription());
|
||||||
userEntityList);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,11 @@ public interface CourseService {
|
|||||||
public Long findByName(String courName);
|
public Long findByName(String courName);
|
||||||
|
|
||||||
public CourseModel save(CourseModel courseModel, Long userId);
|
public CourseModel save(CourseModel courseModel, Long userId);
|
||||||
|
|
||||||
|
public List<CourseModel> findAllByUserId(Long userId);
|
||||||
|
|
||||||
|
public List<CourseModel> findAllByNull();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,16 @@ package com.example.demo.app.domain.service.impl;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.CourseModel;
|
import com.example.demo.app.domain.model.CourseModel;
|
||||||
import com.example.demo.app.domain.service.CourseService;
|
import com.example.demo.app.domain.service.CourseService;
|
||||||
import com.example.demo.app.infra.entity.CourseEntity;
|
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.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.CourseRepository;
|
||||||
import com.example.demo.app.infra.repository.UserRepository;
|
import com.example.demo.app.infra.repository.UserRepository;
|
||||||
|
|
||||||
@@ -20,12 +24,22 @@ public class CourseServiceImpl implements CourseService {
|
|||||||
|
|
||||||
private final CourseRepository courseRepository;
|
private final CourseRepository courseRepository;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
private final CourseOwnerRepository courseOwnerRepository;
|
||||||
|
|
||||||
public List<CourseModel> findAll(){
|
public List<CourseModel> findAll(){
|
||||||
|
|
||||||
return CourseEntity.createCourseModelList(courseRepository.findAll());
|
return CourseEntity.createCourseModelList(courseRepository.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<CourseModel> findAllByUserId(Long userId) {
|
||||||
|
|
||||||
|
return CourseModel.convertFrom(courseRepository.findAllByUserId(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CourseModel> findAllByNull() {
|
||||||
|
return CourseModel.convertFrom(courseRepository.findAllByNull());
|
||||||
|
}
|
||||||
|
|
||||||
public CourseModel findById(Long courseId) {
|
public CourseModel findById(Long courseId) {
|
||||||
return CourseModel.convertFrom(courseRepository.findByCourseId(courseId));
|
return CourseModel.convertFrom(courseRepository.findByCourseId(courseId));
|
||||||
}
|
}
|
||||||
@@ -34,12 +48,27 @@ public class CourseServiceImpl implements CourseService {
|
|||||||
return courseRepository.findByCourseName(courseName).getCourseId();
|
return courseRepository.findByCourseName(courseName).getCourseId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CourseModel save(CourseModel courseModel, Long userId) {
|
public CourseModel save(CourseModel courseModel, Long userId) {
|
||||||
|
|
||||||
List<UserEntity> userEntityList = new ArrayList<>();
|
List<UserEntity> userEntityList = new ArrayList<>();
|
||||||
userEntityList.add(userRepository.findById(userId).get());
|
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)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ public class UserServiceImpl implements UserService {
|
|||||||
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
|
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
|
||||||
|
|
||||||
userEntity.setQuestionEntity(questionEntity);
|
userEntity.setQuestionEntity(questionEntity);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
userEntity.setCourseEntity(courseEntity);
|
userEntity.setCourseEntity(courseEntity);
|
||||||
|
|
||||||
userEntity.setDeleteFlag(0);
|
userEntity.setDeleteFlag(0);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import jakarta.persistence.Entity;
|
|||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.OneToMany;
|
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.CourseModel;
|
import com.example.demo.app.domain.model.CourseModel;
|
||||||
@@ -35,9 +34,6 @@ public class CourseEntity {
|
|||||||
@Column(name = "description", nullable = false)
|
@Column(name = "description", nullable = false)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "courseEntity")
|
|
||||||
private List<UserEntity> userEntity;
|
|
||||||
|
|
||||||
public static List<CourseModel> createCourseModelList(List<CourseEntity> courseEntityList) {
|
public static List<CourseModel> createCourseModelList(List<CourseEntity> courseEntityList) {
|
||||||
|
|
||||||
return courseEntityList
|
return courseEntityList
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<CourseOwnerEntity, Long>{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,17 +1,24 @@
|
|||||||
package com.example.demo.app.infra.repository;
|
package com.example.demo.app.infra.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.CourseEntity;
|
import com.example.demo.app.infra.entity.CourseEntity;
|
||||||
|
|
||||||
public interface CourseRepository extends JpaRepository<CourseEntity, Long> {
|
public interface CourseRepository extends JpaRepository<CourseEntity, Long> {
|
||||||
|
|
||||||
@Query("SELECT c FROM CourseEntity c WHERE c.courseId = :courseId ")
|
@Query("SELECT c FROM CourseEntity c WHERE c.courseId = :courseId ")
|
||||||
public CourseEntity findByCourseId(Long courseId);
|
public CourseEntity findByCourseId(Long courseId);
|
||||||
|
|
||||||
@Query("SELECT c FROM CourseEntity c WHERE c.courseName = :courseName ")
|
@Query("SELECT c FROM CourseEntity c WHERE c.courseName = :courseName ")
|
||||||
public CourseEntity findByCourseName(String 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<CourseEntity> findAllByUserId(Long userId);
|
||||||
|
|
||||||
|
@Query("select c from CourseEntity c where c.courseId between 1 and 6")
|
||||||
|
public List<CourseEntity> findAllByNull();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
|
|
||||||
import com.example.demo.aop.aspect.SessionCheck;
|
import com.example.demo.aop.aspect.SessionCheck;
|
||||||
import com.example.demo.app.domain.model.AllocationModel;
|
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.model.LoginModel;
|
||||||
import com.example.demo.app.domain.service.AllocationService;
|
import com.example.demo.app.domain.service.AllocationService;
|
||||||
import com.example.demo.app.domain.service.CourseInfoService;
|
import com.example.demo.app.domain.service.CourseInfoService;
|
||||||
@@ -47,7 +48,9 @@ public class CourseController {
|
|||||||
session.setAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
|
session.setAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
|
||||||
model.addAttribute(PageReturnAttributeKeyword.MODE, MODE);
|
model.addAttribute(PageReturnAttributeKeyword.MODE, MODE);
|
||||||
model.addAttribute(PageReturnAttributeKeyword.CURRENT_COURSE_ID, courseService.findByName(DEFAULT));
|
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,
|
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST,
|
||||||
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||||
|
|
||||||
@@ -66,9 +69,15 @@ public class CourseController {
|
|||||||
|
|
||||||
Long currentCourseId = userService.findByUserId(userId).getCourseId();
|
Long currentCourseId = userService.findByUserId(userId).getCourseId();
|
||||||
|
|
||||||
|
List<CourseModel> courseModelList = new ArrayList<>(courseService.findAllByNull());
|
||||||
|
|
||||||
|
List<CourseModel> tempList = courseService.findAllByUserId(userId);
|
||||||
|
|
||||||
|
tempList.forEach(courseModelList::add);
|
||||||
|
|
||||||
model.addAttribute(PageReturnAttributeKeyword.MODE, MODE);
|
model.addAttribute(PageReturnAttributeKeyword.MODE, MODE);
|
||||||
model.addAttribute(PageReturnAttributeKeyword.CURRENT_COURSE_ID, currentCourseId);
|
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,
|
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST,
|
||||||
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||||
|
|
||||||
@@ -117,27 +126,38 @@ public class CourseController {
|
|||||||
List<AllocationModel> allocationModelList = new ArrayList<>();
|
List<AllocationModel> allocationModelList = new ArrayList<>();
|
||||||
|
|
||||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId1(),
|
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(),
|
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(),
|
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(),
|
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(),
|
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(),
|
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(),
|
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(),
|
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(),
|
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(),
|
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(),
|
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);
|
allocationService.save(allocationModelList);
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body style="padding-top:80px; padding-bottom:80px;">
|
<body style="padding-top:80px; padding-bottom:120px;">
|
||||||
|
|
||||||
<div th:replace="~{header :: header}"></div>
|
<div th:replace="~{header :: header}"></div>
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse"
|
<div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse"
|
||||||
data-bs-parent="#accordionExample">
|
data-bs-parent="#accordionExample" style="padding-bottom: 120px;">
|
||||||
<div class="accordion-body">
|
<div class="accordion-body">
|
||||||
<span th:text="${course.description}"></span>
|
<span th:text="${course.description}"></span>
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered">
|
||||||
|
|||||||
Reference in New Issue
Block a user