Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class DetailBoardResponse {
private boolean myLikeYn;

@Schema(description = "댓글 수")
private int replyCount;
private long replyCount;

@Schema(description = "최종 저장 여부")
private boolean saveYn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.example.domain.board.QBoard.board;
import static org.example.domain.board_like.QBoardLike.boardLike;
import static org.example.domain.reply.QReply.reply;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
Expand Down Expand Up @@ -47,7 +48,14 @@ public DetailBoardResponse getBoard(Long boardId) {
boardLike.member.email.eq(SecurityUtils.getCurrentMemberEmail())
).exists()
, "myLikeYn"),
board.replyList.size().as("replyCount"),
Expressions.as(
JPAExpressions
.select(reply.count())
.from(reply)
.where(
reply.board.eq(board),
reply.deleteYn.isFalse())
, "replyCount"),
board.saveYn,
board.fixYn,
board.deleteYn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.example.domain.curriculum.controller.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

@Schema(description = "커리큘럼 생성 요청 객체")
Expand All @@ -11,15 +10,12 @@ public record CreateCurriculumRequest(
@Schema(description = "커리큘럼 대상 스터디 ID")
Long studyId,

@NotBlank
@Schema(description = "커리큘럼 제목")
String title,

@NotNull
@Schema(description = "커리큘럼 주차")
Integer week,

@NotBlank
@Schema(description = "커리큘럼 내용(에디터)")
String content
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.example.domain.study.service.CoreStudyService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Service
@RequiredArgsConstructor
Expand All @@ -26,6 +27,11 @@ public class CreateCurriculumService {
* 커리큘럼 생성
*/
public void createCurriculum(CreateCurriculumRequest request) {
if (!StringUtils.hasText(request.title()) || !StringUtils.hasText(request.content()))
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "제목 또는 내용이 비어있습니다.");
if (request.week() == null)
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "주차 선택은 필수입니다.");

Study study = coreStudyService.findById(request.studyId());
if (study.getType().equals(StudyType.TEMP)) {
throw new GeneralException(ErrorStatus.BAD_REQUEST, "자율 스터디는 커리큘럼을 생성할 수 없습니다.");
Expand All @@ -45,6 +51,11 @@ public void createCurriculum(CreateCurriculumRequest request) {
* 커리큘럼 수정
*/
public void updateCurriculum(Long curriculumId, UpdateCurriculumRequest request) {
if (!StringUtils.hasText(request.title()) || !StringUtils.hasText(request.content()))
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "제목 또는 내용이 비어있습니다.");
if (request.week() == null)
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "주차 선택은 필수입니다.");

Curriculum curriculum = coreCurriculumService.findById(curriculumId);
Study study = null;
if (request.studyId() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void renewGeneration(RenewGenerationRequest request) {
memberRepository.initBlockYN();
List<Study> regularStudyList = listStudyRepository.getOldGenerationStudyList(StudyType.REGULAR);
for (Study oldStudy : regularStudyList) {
oldStudy.end();
Study newStudy = Study.builder()
.profileUrl(oldStudy.getProfileUrl())
.name(oldStudy.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DetailInquiryResponse {
private String content;

@Schema(description = "댓글 수")
private int replyCount;
private long replyCount;

@Schema(description = "공개 여부")
private boolean publicYn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@


import static org.example.domain.inquiry.QInquiry.inquiry;
import static org.example.domain.inquiry_reply.QInquiryReply.inquiryReply;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.example.domain.inquiry.controller.response.DetailInquiryResponse;
Expand All @@ -30,7 +33,14 @@ public DetailInquiryResponse getInquiry(Long inquiryId) {
inquiry.member.profileUrl,
inquiry.createdTime,
inquiry.viewCount,
inquiry.replyList.size().as("replyCount"),
Expressions.as(
JPAExpressions
.select(inquiryReply.count())
.from(inquiryReply)
.where(
inquiryReply.inquiry.eq(inquiry),
inquiryReply.deleteYn.isFalse())
, "replyCount"),
inquiry.publicYn,
inquiry.solvedYn
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.example.domain.institution.enums.InstitutionType;

@Schema(description = "기관 생성 요청 객체")
public record CreateInstitutionRequest(

@NotBlank
@Schema(description = "기관명", requiredMode = RequiredMode.REQUIRED)
String name,

@NotNull
@Schema(description = "기관 유형", requiredMode = RequiredMode.REQUIRED)
InstitutionType type,

@NotBlank
@Schema(description = "분석 내용", requiredMode = RequiredMode.REQUIRED)
String content
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.example.domain.workbook.repository.WorkbookRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Service
@RequiredArgsConstructor
Expand All @@ -25,8 +26,13 @@ public class CreateInstitutionService {
* 기관 생성
*/
public void createInstitution(CreateInstitutionRequest request) {
if (!StringUtils.hasText(request.name()) || !StringUtils.hasText(request.content()))
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "이름 또는 내용이 비어있습니다.");
if (request.type() == null)
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "주차 선택은 필수입니다.");

if (institutionRepository.findByName(request.name()).isPresent()) {
throw new GeneralException(ErrorStatus.BAD_REQUEST, "이미 존재하는 기관명입니다.");
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "이미 존재하는 기관명입니다.");
}

institutionRepository.save(
Expand All @@ -42,6 +48,11 @@ public void createInstitution(CreateInstitutionRequest request) {
* 기관 수정
*/
public void updateInstitution(Long institutionId, UpdateInstitutionRequest request) {
if (!StringUtils.hasText(request.name()) || !StringUtils.hasText(request.content()))
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "이름 또는 내용이 비어있습니다.");
if (request.type() == null)
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "주차 선택은 필수입니다.");

Institution institution = coreInstitutionService.findById(institutionId);
institution.update(
request.name(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package org.example.domain.study.controller.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

@Schema(description = "정규 스터디 생성 요청 객체")
public record CreateRegularStudyRequest(

@Schema(description = "스터디 대표 이미지 URL")
String profileUrl,

@NotBlank
@Schema(description = "스터디 이름")
String name,

@NotBlank
@Schema(description = "내용(에디터)")
String content

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class CreateStudyService {
* 정규 스터디 생성
*/
public void createRegularStudy(CreateRegularStudyRequest request) {
if (!StringUtils.hasText(request.name()) || !StringUtils.hasText(request.content()))
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "이름 또는 내용이 비어있습니다.");

if (studyRepository.findByNameAndTypeIs(request.name(), StudyType.REGULAR).isPresent()) {
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "동일한 이름의 정규 스터디가 존재합니다.");
}
Expand All @@ -56,6 +59,9 @@ public void createRegularStudy(CreateRegularStudyRequest request) {
* 스터디 수정
*/
public void updateStudy(Long studyId, UpdateStudyRequest request) {
if (!StringUtils.hasText(request.name()) || !StringUtils.hasText(request.content()))
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "이름 또는 내용이 비어있습니다.");

Study study = coreStudyService.findById(studyId);
if (study.getType().equals(StudyType.TEMP)) {
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "자율 스터디는 수정할 수 없습니다.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.domain.week.controller.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
Expand All @@ -14,6 +15,9 @@
@Schema(description = "현재 주차 정보 응답 객체")
public class DetailWeekResponse {

@JsonIgnore
private long weekId;

@Schema(description = "현재 기수")
private int generation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public class DetailWeekRepository {
/**
* 현재 주차 정보 조회
*/
public DetailWeekResponse getWeek() {
public DetailWeekResponse getCurrentWeek() {
return queryFactory
.select(Projections.fields(
DetailWeekResponse.class,
week.id.as("weekId"),
Expressions.as(
JPAExpressions
.select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DetailWeekService {
* 현재 주차 정보 조회
*/
public DetailWeekResponse getWeek() {
DetailWeekResponse week = detailWeekRepository.getWeek();
DetailWeekResponse week = detailWeekRepository.getCurrentWeek();
if (week == null) {
Integer generation = generationRepository.findTopByOrderByValueDesc().getValue();
throw new GeneralException(ErrorStatus.ATTENDANCE_ENDED, generation + "기 스터디 진행 기간이 아닙니다.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.example.domain.workbook.service;

import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.example.api_response.exception.GeneralException;
import org.example.api_response.status.ErrorStatus;
import org.example.domain.problem.Problem;
import org.example.domain.problem.service.CoreProblemService;
import org.example.domain.week.controller.response.DetailWeekResponse;
import org.example.domain.week.repository.DetailWeekRepository;
import org.example.domain.workbook.Workbook;
import org.example.domain.workbook.controller.request.UpdateWorkbookRequest;
import org.example.domain.workbook.repository.WorkbookRepository;
import org.example.domain.workbook_problem.WorkbookProblem;
import org.example.domain.workbook_problem.controller.request.CreateWorkbookProblemRequest;
import org.example.domain.workbook_problem.repository.WorkbookProblemRepository;
import org.example.util.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -24,6 +28,7 @@ public class CreateWorkbookService {

private final WorkbookRepository workbookRepository;
private final WorkbookProblemRepository workbookProblemRepository;
private final DetailWeekRepository detailWeekRepository;


/**
Expand All @@ -46,11 +51,20 @@ public void deleteWorkbook(Long workbookId) {
*/
public void createWorkbookProblem(Long workbookId, CreateWorkbookProblemRequest request) {
Workbook workbook = coreWorkbookService.findById(workbookId);
DetailWeekResponse currentWeek = detailWeekRepository.getCurrentWeek();
if (workbook.getStudy().getEndYN() || // 종료된 스터디 수정 불가
!(workbook.getWeek().getId().equals(currentWeek.getWeekId()) // 현재 주차의 문제집이면서
&& !DateUtils.isWeekend(LocalDate.now()) // 주말이 아니면서
&& !workbook.getStudy().getEndYN() // 진행 중이면 수정 가능
)
)
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "스터디원에게 공개된 문제는 수정할 수 없습니다.");

Problem problem = coreProblemService.findByNumber(request.number());
if (workbookProblemRepository.findByWorkbookAndProblem(workbook, problem).isPresent()) {
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "이미 문제집에 포함된 문제입니다.");
}
workbookProblemRepository.save(
workbook.getWorkbookProblemList().add(
WorkbookProblem.builder()
.workbook(workbook)
.problem(problem)
Expand All @@ -62,6 +76,16 @@ public void createWorkbookProblem(Long workbookId, CreateWorkbookProblemRequest
* 문제집 문제 삭제
*/
public void deleteWorkbookProblem(Long workbookId, Integer problemNumber) {
workbookProblemRepository.deleteByWorkbookIdAndProblemNumber(workbookId, problemNumber);
Workbook workbook = coreWorkbookService.findById(workbookId);
DetailWeekResponse currentWeek = detailWeekRepository.getCurrentWeek();
if (workbook.getStudy().getEndYN() || // 종료된 스터디 삭제 불가
!(workbook.getWeek().getId().equals(currentWeek.getWeekId()) // 현재 주차의 문제집이면서
&& !DateUtils.isWeekend(LocalDate.now()) // 주말이 아니면서
&& !workbook.getStudy().getEndYN() // 진행 중이면 삭제 가능
)
)
throw new GeneralException(ErrorStatus.NOTICE_BAD_REQUEST, "스터디원에게 공개된 문제는 삭제할 수 없습니다.");

workbookProblemRepository.deleteByWorkbookAndProblemNumber(workbook, problemNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface WorkbookProblemRepository extends JpaRepository<WorkbookProblem, Long> {

@Modifying
void deleteByWorkbookIdAndProblemNumber(Long workbookId, Integer number);
void deleteByWorkbookAndProblemNumber(Workbook workbook, Integer number);

Optional<WorkbookProblem> findByWorkbookAndProblem(Workbook workbook, Problem problem);
}
6 changes: 6 additions & 0 deletions module-core/src/main/java/org/example/util/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static java.time.temporal.ChronoUnit.HOURS;
import static java.time.temporal.ChronoUnit.MINUTES;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;

public class DateUtils {
Expand All @@ -24,4 +26,8 @@ public static String getUpdatedTime(LocalDateTime updatedTime) {

return dayGap + "일 전";
}

public static boolean isWeekend(LocalDate localDate) {
return (localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class DetailBoardResponse {
private boolean myLikeYn;

@Schema(description = "댓글 수")
private int replyCount;
private long replyCount;

@Schema(description = "최종 저장 여부")
private boolean saveYn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.example.domain.board.QBoard.board;
import static org.example.domain.board_like.QBoardLike.boardLike;
import static org.example.domain.reply.QReply.reply;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
Expand Down Expand Up @@ -40,7 +41,14 @@ public DetailBoardResponse getBoard(Long boardId) {
board.saveYn,
board.deleteYn,
board.fixYn,
board.replyList.size().as("replyCount"),
Expressions.as(
JPAExpressions
.select(reply.count())
.from(reply)
.where(
reply.board.eq(board),
reply.deleteYn.isFalse())
, "replyCount"),
board.boardLikeList.size().as("likeCount"),
Expressions.as(
JPAExpressions
Expand Down
Loading
Loading