diff --git a/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/study/domain/QStudyEntity.java b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/study/domain/QStudyEntity.java index 55e8492a..a3ecb51a 100644 --- a/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/study/domain/QStudyEntity.java +++ b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/study/domain/QStudyEntity.java @@ -30,6 +30,8 @@ public class QStudyEntity extends EntityPathBase { public final NumberPath id = createNumber("id", Long.class); + public final EnumPath major = createEnum("major", kr.co.studyhubinu.studyhubserver.user.enums.MajorType.class); + public final NumberPath masterUserId = createNumber("masterUserId", Long.class); //inherited diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java index 053075ac..b927e3d8 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyController.java @@ -9,6 +9,7 @@ import kr.co.studyhubinu.studyhubserver.apply.dto.request.UpdateApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.service.ApplyService; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindParticipateApplyResponse; import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import lombok.RequiredArgsConstructor; import org.apache.http.HttpStatus; @@ -46,4 +47,11 @@ public ResponseEntity updateStudyInspection(UpdateApplyRequest reque public FindApplyResponse findStudyEnroll(FindApplyRequest request, @RequestParam int page, @RequestParam int size) { return applyService.findApply(request, page, size); } + + @Operation(summary = "내가 참여한 스터디 목록", description = "헤더에 JWT토큰 보내주시면 됩니다") + @GetMapping("/v1/participated-study") + public ResponseEntity getParticipateApply(UserId userId, @RequestParam int page, @RequestParam int size) { + return ResponseEntity.ok().body(applyService.getParticipateApply(userId.getId(), page, size)); + } + } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/ParticipateApplyData.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/ParticipateApplyData.java new file mode 100644 index 00000000..a589a45d --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/ParticipateApplyData.java @@ -0,0 +1,25 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.data; + +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; +import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; +import lombok.Getter; + +@Getter +public class ParticipateApplyData { + + private String major; + private String title; + private String content; + private String chatUrl; + private String inspection; + private Long postId; + + public ParticipateApplyData(MajorType major, String title, String content, String chatUrl, Inspection inspection, Long postId) { + this.major = major.getValue(); + this.title = title; + this.content = content; + this.chatUrl = chatUrl; + this.inspection = inspection.getValue(); + this.postId = postId; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindParticipateApplyResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindParticipateApplyResponse.java new file mode 100644 index 00000000..10498708 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindParticipateApplyResponse.java @@ -0,0 +1,15 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.response; + +import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; +import lombok.Getter; +import org.springframework.data.domain.Slice; + +@Getter +public class FindParticipateApplyResponse { + private Long totalCount; + Slice participateStudyData; + public FindParticipateApplyResponse(Long totalCount, Slice participateStudyData) { + this.totalCount = totalCount; + this.participateStudyData = participateStudyData; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepository.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepository.java index 93fd817b..547ad697 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepository.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepository.java @@ -1,8 +1,7 @@ package kr.co.studyhubinu.studyhubserver.apply.repository; import kr.co.studyhubinu.studyhubserver.apply.domain.ApplyEntity; -import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; -import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; @@ -12,4 +11,6 @@ public interface ApplyRepository extends JpaRepository, Apply Optional findByUserIdAndStudyId(Long userId, Long studyId); List findByUserId(Long userId); + + Long countByUserIdAndInspection(Long userId, Inspection accept); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java index e6275630..ad55c00d 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java @@ -1,6 +1,7 @@ package kr.co.studyhubinu.studyhubserver.apply.repository; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ApplyUserData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; import org.springframework.data.domain.Pageable; import java.util.List; @@ -8,4 +9,6 @@ public interface ApplyRepositoryCustom { List findByStudy(Long studyId, Pageable pageable); + + List findByUserIdAndInspection(Long userId, Pageable pageable); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java index eb10e29a..733a1bc0 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryImpl.java @@ -3,12 +3,16 @@ import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ApplyUserData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.util.List; +import static kr.co.studyhubinu.studyhubserver.study.domain.QStudyEntity.studyEntity; +import static kr.co.studyhubinu.studyhubserver.studypost.domain.QStudyPostEntity.studyPostEntity; import static kr.co.studyhubinu.studyhubserver.user.domain.QUserEntity.userEntity; import static kr.co.studyhubinu.studyhubserver.apply.domain.QApplyEntity.applyEntity; @@ -25,11 +29,30 @@ public List findByStudy(Long studyId, final Pageable pageable) { userEntity.id, userEntity.nickname, userEntity.major, userEntity.imageUrl, applyEntity.introduce, applyEntity.createdDate)) .from(applyEntity) - .leftJoin(userEntity).on(applyEntity.userId.eq(userEntity.id)) + .innerJoin(userEntity).on(applyEntity.userId.eq(userEntity.id)) .where(applyEntity.studyId.eq(studyId)) - .orderBy(applyEntity.createdDate.asc()) + .orderBy(applyEntity.createdDate.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize() + 1) .fetch(); } + + @Override + public List findByUserIdAndInspection(Long userId, Pageable pageable) { + return jpaQueryFactory + .select(Projections.constructor(ParticipateApplyData.class, + studyEntity.major, studyEntity.title, studyEntity.content, studyEntity.chatUrl, + applyEntity.inspection, studyPostEntity.id.as("postId"))) + .from(applyEntity) + .innerJoin(studyEntity).on(applyEntity.studyId.eq(studyEntity.id)) + .innerJoin(studyPostEntity).on(studyEntity.id.eq(studyPostEntity.studyId)) + .where( + applyEntity.userId.eq(userId) + .and(applyEntity.inspection.eq(Inspection.ACCEPT)) + ) + .orderBy(applyEntity.createdDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize() + 1) + .fetch(); + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java index 154f3636..8eac78bd 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyService.java @@ -1,34 +1,40 @@ package kr.co.studyhubinu.studyhubserver.apply.service; +import kr.co.studyhubinu.studyhubserver.apply.domain.ApplyEntity; import kr.co.studyhubinu.studyhubserver.apply.dto.data.ApplyUserData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; import kr.co.studyhubinu.studyhubserver.apply.dto.request.EnrollApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.dto.request.FindApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.dto.request.UpdateApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindParticipateApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import kr.co.studyhubinu.studyhubserver.apply.repository.ApplyRepository; import kr.co.studyhubinu.studyhubserver.common.dto.Converter; import kr.co.studyhubinu.studyhubserver.exception.apply.ApplyNotFoundException; import kr.co.studyhubinu.studyhubserver.exception.apply.SameUserRequestException; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; -import kr.co.studyhubinu.studyhubserver.study.StudyRepository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; -import kr.co.studyhubinu.studyhubserver.apply.domain.ApplyEntity; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service +@Transactional(readOnly = true) public class ApplyService { private final UserRepository userRepository; private final StudyRepository studyRepository; private final ApplyRepository applyRepository; + @Transactional public void enroll(Long userId, EnrollApplyRequest request) { UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); StudyEntity study = studyRepository.findById(request.getStudyId()).orElseThrow(); @@ -37,6 +43,7 @@ public void enroll(Long userId, EnrollApplyRequest request) { applyRepository.save(ApplyEntity.of(user.getId(), study.getId(), request.getIntroduce())); } + @Transactional public void update(UpdateApplyRequest request) { UserEntity user = userRepository.findById(request.getUserId()).orElseThrow(UserNotFoundException::new); StudyEntity study = studyRepository.findById(request.getStudyId()).orElseThrow(); @@ -56,4 +63,13 @@ private void validateSameRequest(UserEntity user, StudyEntity study) { throw new SameUserRequestException(); } } + + public FindParticipateApplyResponse getParticipateApply(final Long userId, final int page, final int size) { + UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + final Pageable pageable = PageRequest.of(page, size); + Long totalCount = applyRepository.countByUserIdAndInspection(user.getId(), Inspection.ACCEPT); + Slice participateApplyData = Converter.toSlice + (pageable, applyRepository.findByUserIdAndInspection(user.getId(), pageable)); + return new FindParticipateApplyResponse(totalCount, participateApplyData); + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryCustom.java b/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryCustom.java index 317b959f..73551acd 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryCustom.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryCustom.java @@ -8,5 +8,5 @@ public interface CommentRepositoryCustom { List findSliceByPostIdWithUserId(Long postId, Long userId, Pageable pageable); - List findPreviewByPostId(Long postId, Long userId, Long commentPreviewCount); + List findPreviewByPostId(Long postId, Long userId, int commentPreviewCount); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryImpl.java index 63853542..ec10c606 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/comment/repository/CommentRepositoryImpl.java @@ -51,7 +51,7 @@ public List findSliceByPostIdWithUserId(Long postId, Long userI } @Override - public List findPreviewByPostId(Long postId, Long userId, Long commentPreviewCount) { + public List findPreviewByPostId(Long postId, Long userId, int commentPreviewCount) { JPAQuery data = jpaQueryFactory .select(Projections.constructor(CommentResponse.class, commentEntity.id, diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/comment/service/CommentService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/comment/service/CommentService.java index bfa1804f..ecc6dd33 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/comment/service/CommentService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/comment/service/CommentService.java @@ -29,7 +29,7 @@ @Transactional(readOnly = true) public class CommentService { - private static final Long COMMENT_PREVIEW_COUNT = 5L; + private static final int COMMENT_PREVIEW_COUNT = 8; private final CommentRepository commentRepository; private final CommentValidator commentValidator; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/email/dto/request/QuestionRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/email/dto/request/QuestionRequest.java index a17c6a18..93daddf6 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/email/dto/request/QuestionRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/email/dto/request/QuestionRequest.java @@ -1,7 +1,7 @@ package kr.co.studyhubinu.studyhubserver.email.dto.request; import io.swagger.v3.oas.annotations.media.Schema; -import kr.co.studyhubinu.studyhubserver.email.validate.InuEmail; +import kr.co.studyhubinu.studyhubserver.email.validate.NormalEmail; import lombok.Getter; import javax.validation.constraints.NotBlank; @@ -17,7 +17,7 @@ public class QuestionRequest { private String content; @Schema(description = "답변 받을 이메일", example = "kdw990202@inu.ac.kr") - @InuEmail + @NormalEmail @NotBlank(message = "이메일값은 필수 입니다") private String toEmail; } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/email/validate/EmailValidator.java b/src/main/java/kr/co/studyhubinu/studyhubserver/email/validate/EmailValidator.java new file mode 100644 index 00000000..14686218 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/email/validate/EmailValidator.java @@ -0,0 +1,15 @@ +package kr.co.studyhubinu.studyhubserver.email.validate; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.regex.Pattern; + +public class EmailValidator implements ConstraintValidator { + + private static final Pattern EMAIL_PATTERN = Pattern.compile("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)*(\\.[a-zA-Z]{2,})$"); + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + return value != null && EMAIL_PATTERN.matcher(value).matches(); + } +} \ No newline at end of file diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/email/validate/NormalEmail.java b/src/main/java/kr/co/studyhubinu/studyhubserver/email/validate/NormalEmail.java new file mode 100644 index 00000000..670a3718 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/email/validate/NormalEmail.java @@ -0,0 +1,18 @@ +package kr.co.studyhubinu.studyhubserver.email.validate; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Documented +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = EmailValidator.class) +public @interface NormalEmail { + + String message() default "이메일 형식에 맞지 않습니다."; + + Class[] groups() default {}; + + Class[] payload() default {}; +} \ No newline at end of file diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java index 5ffbcbd1..8e368d32 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyEntity.java @@ -1,6 +1,7 @@ package kr.co.studyhubinu.studyhubserver.study.domain; import kr.co.studyhubinu.studyhubserver.common.domain.BaseTimeEntity; +import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; import lombok.*; import javax.persistence.*; @@ -33,10 +34,12 @@ public class StudyEntity extends BaseTimeEntity { @Column(name = "master_user_id") private Long masterUserId; + @Enumerated(EnumType.STRING) + private MajorType major; @Builder - public StudyEntity(Long id, String title, String content, LocalDate studyStartDate, LocalDate studyEndDate, String chatUrl, Long userId) { + public StudyEntity(Long id, String title, String content, LocalDate studyStartDate, LocalDate studyEndDate, String chatUrl, Long userId, MajorType major) { this.id = id; this.title = title; this.content = content; @@ -44,6 +47,7 @@ public StudyEntity(Long id, String title, String content, LocalDate studyStartDa this.studyEndDate = studyEndDate; this.chatUrl = chatUrl; this.masterUserId = userId; + this.major = major; } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/StudyRepository.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyRepository.java similarity index 77% rename from src/main/java/kr/co/studyhubinu/studyhubserver/study/StudyRepository.java rename to src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyRepository.java index 63cdb398..3e0026f4 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/StudyRepository.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyRepository.java @@ -1,4 +1,4 @@ -package kr.co.studyhubinu.studyhubserver.study; +package kr.co.studyhubinu.studyhubserver.study.repository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java index 54650320..4bec68a2 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java @@ -99,13 +99,14 @@ public ResponseEntity findPostByAllString(@QueryStrin return ResponseEntity.ok(findPostResponseByInquiries); } + @Operation(summary = "스터디 게시글 마감처리", description = "postId와 헤더에 jwt토큰 보내주시면 됩니다!") @PutMapping("/v1/study-posts/{post-id}/close") public ResponseEntity closePost(@PathVariable("post-id") Long postId, UserId userId) { studyPostService.closePost(postId, userId.getId()); return ResponseEntity.ok().build(); } - @Operation(summary = "검색어 추천 기능 개발", description = "parameter에 검색어를 입력해주세요 기획상 추천수는 5개입니다") + @Operation(summary = "검색어 추천 기능 개발", description = "parameter에 검색어를 입력해주세요 기획상 추천수는 10개입니다") @ApiImplicitParam(name = "keyword", value = "검색어 키워드", required = true) @GetMapping("/v1/study-post/recommend") public ResponseEntity findRecommendPosts(@RequestParam String keyword) { diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/data/PostDataByBookmark.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/data/PostDataByBookmark.java index f971517b..6ded7cef 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/data/PostDataByBookmark.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/data/PostDataByBookmark.java @@ -12,14 +12,16 @@ public class PostDataByBookmark { private String content; private int remainingSeat; private boolean close; + private Long studyId; @Builder - public PostDataByBookmark(Long postId, MajorType major, String title, String content, int remainingSeat, boolean close) { + public PostDataByBookmark(Long postId, MajorType major, String title, String content, int remainingSeat, boolean close, Long studyId) { this.postId = postId; this.major = major; this.title = title; this.content = content; this.remainingSeat = remainingSeat; this.close = close; + this.studyId = studyId; } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/request/CreatePostRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/request/CreatePostRequest.java index 935861e3..00b119a0 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/request/CreatePostRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/request/CreatePostRequest.java @@ -97,6 +97,7 @@ public StudyEntity toStudyEntity(Long userId) { .studyStartDate(studyStartDate) .studyEndDate(studyEndDate) .userId(userId) + .major(major) .build(); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/response/FindPostResponseById.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/response/FindPostResponseById.java index f911a653..990b2232 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/response/FindPostResponseById.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/dto/response/FindPostResponseById.java @@ -30,6 +30,7 @@ public class FindPostResponseById { private final String chatUrl; private final boolean isUsersPost; private final boolean isBookmarked; + private final Long studyId; private final boolean isApply; private final UserData postedUser; private final List relatedPost; @@ -51,6 +52,7 @@ public FindPostResponseById(PostData postData, List relatedPost this.chatUrl = postData.getCharUrl(); this.isUsersPost = postData.isUsersPost(); this.isBookmarked = postData.isBookmarked(); + this.studyId = postData.getStudyId(); this.postedUser = postData.getPostedUser(); this.relatedPost = relatedPosts; this.isApply = isApply; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java index a4b9d9c1..47ad617a 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java @@ -68,10 +68,9 @@ public List findPostsByBookmarked(Long userId, Pageable page JPAQuery studyPostDto = jpaQueryFactory.select( Projections.constructor(PostDataByBookmark.class, - post.id.as("postId"), post.major, post.title, post.content, post.remainingSeat, post.close)) + post.id.as("postId"), post.major, post.title, post.content, post.remainingSeat, post.close, post.studyId)) .from(post) - .innerJoin(bookmark) - .on(bookmark.postId.eq(post.id)) + .innerJoin(bookmark).on(bookmark.postId.eq(post.id)) .where(bookmark.userId.eq(userId)) .orderBy(post.createdDate.desc()) .offset(pageable.getOffset()) diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostFindService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostFindService.java index 78c0af01..c35753ef 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostFindService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostFindService.java @@ -43,7 +43,6 @@ public class StudyPostFindService { public FindPostResponseByInquiry findPostResponseByInquiry(final InquiryRequest inquiryRequest, final int page, final int size, Long userId) { final Pageable pageable = PageRequest.of(page, size); final Slice posts = Converter.toSlice(pageable, studyPostRepository.findByInquiry(inquiryRequest, pageable, userId)); - return new FindPostResponseByInquiry((long) posts.getContent().size(), posts); } @@ -51,9 +50,7 @@ public FindPostResponseByBookmark getBookmarkedPosts(int page, int size, Long us validateUser(userId); final Pageable pageable = PageRequest.of(page, size); final Long totalCount = getBookmarkCountByUserId(userId); - final Slice posts = Converter.toSlice(pageable, studyPostRepository.findPostsByBookmarked(userId, pageable)); - return new FindPostResponseByBookmark(totalCount, posts); } @@ -65,9 +62,7 @@ public FindPostResponseByUserId getMyPosts(int page, int size, Long userId) { final UserEntity user = findUser(userId); final Pageable pageable = PageRequest.of(page, size); final Long totalCount = getPostCountByUserId(userId); - final Slice posts = Converter.toSlice(pageable, studyPostRepository.findByPostedUserId(user.getId(), pageable)); - return new FindPostResponseByUserId(totalCount, posts); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostService.java index d6840008..73153c4c 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostService.java @@ -5,7 +5,7 @@ import kr.co.studyhubinu.studyhubserver.exception.study.PostStartDateConflictException; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotAccessRightException; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; -import kr.co.studyhubinu.studyhubserver.study.StudyRepository; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import kr.co.studyhubinu.studyhubserver.studypost.domain.StudyPostEntity; import kr.co.studyhubinu.studyhubserver.studypost.dto.data.UpdateStudyPostInfo; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserActivityFinder.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserActivityFinder.java index caf6f85b..38ae539d 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserActivityFinder.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserActivityFinder.java @@ -1,7 +1,7 @@ package kr.co.studyhubinu.studyhubserver.user.domain; import kr.co.studyhubinu.studyhubserver.bookmark.repository.BookmarkRepository; -import kr.co.studyhubinu.studyhubserver.study.StudyRepository; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; import kr.co.studyhubinu.studyhubserver.user.dto.data.UserActivityCountData; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserDeleter.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserDeleter.java index 44e58d74..5e43f285 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserDeleter.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserDeleter.java @@ -5,7 +5,7 @@ import kr.co.studyhubinu.studyhubserver.bookmark.domain.BookmarkEntity; import kr.co.studyhubinu.studyhubserver.bookmark.repository.BookmarkRepository; -import kr.co.studyhubinu.studyhubserver.study.StudyRepository; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; import kr.co.studyhubinu.studyhubserver.studypost.domain.StudyPostEntity; import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index c8e8bf5d..08c5a91b 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -54,6 +54,7 @@ CREATE TABLE study study_end_date DATE DEFAULT NULL, chat_url VARCHAR(100) DEFAULT NULL, master_user_id BIGINT NOT NULL, + major VARCHAR(50) DEFAULT NULL, created_date TIMESTAMP(3) DEFAULT NULL, modified_date TIMESTAMP(3) DEFAULT NULL, PRIMARY KEY (study_id) diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryTest.java index a96ed843..7c6199d1 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryTest.java @@ -5,7 +5,7 @@ import kr.co.studyhubinu.studyhubserver.apply.dto.request.UpdateApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import kr.co.studyhubinu.studyhubserver.exception.apply.ApplyNotFoundException; -import kr.co.studyhubinu.studyhubserver.study.StudyRepository; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import kr.co.studyhubinu.studyhubserver.support.fixture.StudyEntityFixture; import kr.co.studyhubinu.studyhubserver.support.fixture.UserEntityFixture; diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java index 82a0a570..d94d09d8 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceTest.java @@ -9,22 +9,16 @@ import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import kr.co.studyhubinu.studyhubserver.apply.repository.ApplyRepository; -import kr.co.studyhubinu.studyhubserver.exception.apply.SameUserRequestException; -import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; -import kr.co.studyhubinu.studyhubserver.study.StudyRepository; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import java.util.ArrayList; import java.util.List; import java.util.Optional; diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostServiceTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostServiceTest.java index 232b768f..53eb5dee 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostServiceTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/service/StudyPostServiceTest.java @@ -5,7 +5,7 @@ import kr.co.studyhubinu.studyhubserver.exception.study.PostStartDateConflictException; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotAccessRightException; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; -import kr.co.studyhubinu.studyhubserver.study.StudyRepository; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import kr.co.studyhubinu.studyhubserver.studypost.domain.StudyPostEntity; import kr.co.studyhubinu.studyhubserver.studypost.dto.data.UpdateStudyPostInfo;