Skip to content

Commit

Permalink
Merge pull request #77 from study-hub-inu/feat/SH-219-my-study
Browse files Browse the repository at this point in the history
Feat/sh 219 my study
  • Loading branch information
wellbeing-dough authored Jan 25, 2024
2 parents a87b53e + 7618011 commit 7a69d24
Show file tree
Hide file tree
Showing 29 changed files with 160 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class QStudyEntity extends EntityPathBase<StudyEntity> {

public final NumberPath<Long> id = createNumber("id", Long.class);

public final EnumPath<kr.co.studyhubinu.studyhubserver.user.enums.MajorType> major = createEnum("major", kr.co.studyhubinu.studyhubserver.user.enums.MajorType.class);

public final NumberPath<Long> masterUserId = createNumber("masterUserId", Long.class);

//inherited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,4 +47,11 @@ public ResponseEntity<HttpStatus> 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<FindParticipateApplyResponse> getParticipateApply(UserId userId, @RequestParam int page, @RequestParam int size) {
return ResponseEntity.ok().body(applyService.getParticipateApply(userId.getId(), page, size));
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ParticipateApplyData> participateStudyData;
public FindParticipateApplyResponse(Long totalCount, Slice<ParticipateApplyData> participateStudyData) {
this.totalCount = totalCount;
this.participateStudyData = participateStudyData;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,4 +11,6 @@ public interface ApplyRepository extends JpaRepository<ApplyEntity, Long>, Apply
Optional<ApplyEntity> findByUserIdAndStudyId(Long userId, Long studyId);

List<ApplyEntity> findByUserId(Long userId);

Long countByUserIdAndInspection(Long userId, Inspection accept);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
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;

public interface ApplyRepositoryCustom {

List<ApplyUserData> findByStudy(Long studyId, Pageable pageable);

List<ParticipateApplyData> findByUserIdAndInspection(Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,11 +29,30 @@ public List<ApplyUserData> 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<ParticipateApplyData> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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();
Expand All @@ -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> participateApplyData = Converter.toSlice
(pageable, applyRepository.findByUserIdAndInspection(user.getId(), pageable));
return new FindParticipateApplyResponse(totalCount, participateApplyData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
public interface CommentRepositoryCustom {
List<CommentResponse> findSliceByPostIdWithUserId(Long postId, Long userId, Pageable pageable);

List<CommentResponse> findPreviewByPostId(Long postId, Long userId, Long commentPreviewCount);
List<CommentResponse> findPreviewByPostId(Long postId, Long userId, int commentPreviewCount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<CommentResponse> findSliceByPostIdWithUserId(Long postId, Long userI
}

@Override
public List<CommentResponse> findPreviewByPostId(Long postId, Long userId, Long commentPreviewCount) {
public List<CommentResponse> findPreviewByPostId(Long postId, Long userId, int commentPreviewCount) {
JPAQuery<CommentResponse> data = jpaQueryFactory
.select(Projections.constructor(CommentResponse.class,
commentEntity.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +17,7 @@ public class QuestionRequest {
private String content;

@Schema(description = "답변 받을 이메일", example = "[email protected]")
@InuEmail
@NormalEmail
@NotBlank(message = "이메일값은 필수 입니다")
private String toEmail;
}
Original file line number Diff line number Diff line change
@@ -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<NormalEmail, String> {

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();
}
}
Original file line number Diff line number Diff line change
@@ -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<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -33,17 +34,20 @@ 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;
this.studyStartDate = studyStartDate;
this.studyEndDate = studyEndDate;
this.chatUrl = chatUrl;
this.masterUserId = userId;
this.major = major;
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ public ResponseEntity<FindPostResponseByInquiry> findPostByAllString(@QueryStrin
return ResponseEntity.ok(findPostResponseByInquiries);
}

@Operation(summary = "스터디 게시글 마감처리", description = "postId와 헤더에 jwt토큰 보내주시면 됩니다!")
@PutMapping("/v1/study-posts/{post-id}/close")
public ResponseEntity<HttpStatus> 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<FindRecommendPostsResponse> findRecommendPosts(@RequestParam String keyword) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public StudyEntity toStudyEntity(Long userId) {
.studyStartDate(studyStartDate)
.studyEndDate(studyEndDate)
.userId(userId)
.major(major)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostDataByMajor> relatedPost;
Expand All @@ -51,6 +52,7 @@ public FindPostResponseById(PostData postData, List<PostDataByMajor> 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;
Expand Down
Loading

0 comments on commit 7a69d24

Please sign in to comment.