Skip to content

Commit

Permalink
Merge pull request #342 from Leejungmin0426/master
Browse files Browse the repository at this point in the history
AcaClassRepository 쿼리문 필요없는 코드 제외, 거기에 맞춰서 강좌 등록 서비스 수정, 중복된 Product …
  • Loading branch information
Leejungmin0426 authored Feb 27, 2025
2 parents ecda9b3 + 0ef0ac2 commit eb2d6e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
24 changes: 14 additions & 10 deletions src/main/java/com/green/acamatch/acaClass/AcaClassService.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public int postAcaClass(AcaClassPostReq p) {
// teacherUserId 값 보정
Long teacherUserId = Optional.ofNullable(p.getTeacherUserId()).orElse(0L);

// 동일한 강좌가 존재하는지 체크 (EmbeddedId 사용)
Long duplicateCount = classRepository.countByAcaIdAndClassNameAndStartDateAndEndDateAndStartTimeAndEndTimeAndTeacherUserId(
p.getAcaId(), p.getClassName(), p.getStartDate(), p.getEndDate(), p.getStartTime(), p.getEndTime(), teacherUserId);
// 중복 강좌 검사 (운영 시간(start_time, end_time) 제외)
Long duplicateCount = classRepository.countByAcaIdAndClassNameAndStartDateAndEndDateAndTeacherUserId(
p.getAcaId(), p.getClassName(), p.getStartDate(), p.getEndDate(), teacherUserId);

if (duplicateCount > 0) {
throw new CustomException(ManagerErrorCode.CLASS_ALREADY_EXISTS);
Expand All @@ -113,15 +113,19 @@ public int postAcaClass(AcaClassPostReq p) {
acaClass.setPrice(p.getPrice());
acaClass.setTeacher(teacher); // Teacher 설정

classRepository.save(acaClass);
// 강좌 저장
AcaClass savedClass = classRepository.save(acaClass);

// Product 객체 생성 시 AcaClass 설정
Product product = new Product();
product.setClassId(acaClass);
product.setProductName(p.getClassName()); // 강좌 이름을 상품명으로 설정
product.setProductPrice(p.getPrice());
// 중복된 Product 생성 방지
boolean productExists = productRepository.existsByClassId(savedClass);

productRepository.save(product);
if (!productExists) {
Product product = new Product();
product.setClassId(savedClass);
product.setProductName(p.getClassName()); // 강좌 이름을 상품명으로 설정
product.setProductPrice(p.getPrice());
productRepository.save(product);
}

return 1;
} catch (CustomException e) {
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/green/acamatch/acaClass/ClassRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@ public interface ClassRepository extends JpaRepository<AcaClass, Long> {
"AND a.className = :className " +
"AND a.startDate = :startDate " +
"AND a.endDate = :endDate " +
"AND a.startTime = :startTime " +
"AND a.endTime = :endTime " +
"AND a.teacher.user.userId = :teacherUserId")
Long countByAcaIdAndClassNameAndStartDateAndEndDateAndStartTimeAndEndTimeAndTeacherUserId(
"AND (:teacherUserId = 0 OR a.teacher.user.userId = :teacherUserId)")
Long countByAcaIdAndClassNameAndStartDateAndEndDateAndTeacherUserId(
@Param("acaId") Long acaId,
@Param("className") String className,
@Param("startDate") LocalDate startDate,
@Param("endDate") LocalDate endDate,
@Param("startTime") LocalTime startTime,
@Param("endTime") LocalTime endTime,
@Param("teacherUserId") Long teacherUserId);


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.green.acamatch.academyCost;

import com.green.acamatch.entity.acaClass.AcaClass;
import com.green.acamatch.entity.academyCost.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
boolean existsByClassId(AcaClass classId);
}

0 comments on commit eb2d6e6

Please sign in to comment.