diff --git a/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/bookmark/domain/QBookMarkEntity.java b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/bookmark/domain/QBookMarkEntity.java index fda02eac..789c8e0d 100644 --- a/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/bookmark/domain/QBookMarkEntity.java +++ b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/bookmark/domain/QBookMarkEntity.java @@ -19,8 +19,16 @@ public class QBookMarkEntity extends EntityPathBase { public static final QBookMarkEntity bookMarkEntity = new QBookMarkEntity("bookMarkEntity"); + public final kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity _super = new kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity(this); + + //inherited + public final DateTimePath createdDate = _super.createdDate; + public final NumberPath id = createNumber("id", Long.class); + //inherited + public final DateTimePath modifiedDate = _super.modifiedDate; + public final NumberPath postId = createNumber("postId", Long.class); public final NumberPath userId = createNumber("userId", Long.class); diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/domain/BookMarkEntity.java b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/domain/BookMarkEntity.java index f70a6d3d..c3616a14 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/domain/BookMarkEntity.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/domain/BookMarkEntity.java @@ -1,5 +1,6 @@ package kr.co.studyhubinu.studyhubserver.bookmark.domain; +import kr.co.studyhubinu.studyhubserver.common.domain.BaseTimeEntity; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -10,7 +11,7 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class BookMarkEntity { +public class BookMarkEntity extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/controller/StudyPostController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/controller/StudyPostController.java index cd04acba..fc33e845 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/controller/StudyPostController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/controller/StudyPostController.java @@ -3,9 +3,12 @@ import io.swagger.v3.oas.annotations.Operation; import kr.co.studyhubinu.studyhubserver.study.dto.request.CreatePostRequest; import kr.co.studyhubinu.studyhubserver.study.dto.request.UpdatePostRequest; +import kr.co.studyhubinu.studyhubserver.study.dto.response.GetBookmarkedPostsResponse; +import kr.co.studyhubinu.studyhubserver.study.dto.response.GetMyPostResponse; import kr.co.studyhubinu.studyhubserver.study.service.StudyPostService; import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Slice; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -42,4 +45,16 @@ public ResponseEntity deletePost(@PathVariable("postId") Long postId studyPostService.deletePost(postId, userId.getId()); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } + + @Operation(summary = "내가 쓴 스터디 조회") + @GetMapping("/mypost") + public ResponseEntity> getMyPosts(@RequestParam int page, @RequestParam int size, UserId userId) { + return ResponseEntity.ok(studyPostService.getMyPosts(page, size, userId.getId())); + } + + @Operation(summary = "내가 북마크한 스터디 조회") + @GetMapping("/bookmarked") + public ResponseEntity> getBookmarkedPosts(@RequestParam int page, @RequestParam int size, UserId userId) { + return ResponseEntity.ok().body(studyPostService.getBookmarkedPosts(page, size, userId.getId())); + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyPostEntity.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyPostEntity.java index baac588c..7fe9bf51 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyPostEntity.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/domain/StudyPostEntity.java @@ -31,14 +31,17 @@ public class StudyPostEntity extends BaseTimeEntity { @Column(name = "chat_url") private String chatUrl; + @Enumerated(EnumType.STRING) private MajorType major; @Column(name = "study_person") private int studyPerson; + @Enumerated(EnumType.STRING) @Column(name = "filtered_gender") private GenderType filteredGender; + @Enumerated(EnumType.STRING) @Column(name = "study_way") private StudyWayType studyWay; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/request/CreatePostRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/request/CreatePostRequest.java index d69695ed..ccb70b02 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/request/CreatePostRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/request/CreatePostRequest.java @@ -26,7 +26,7 @@ public class CreatePostRequest { @NotBlank private String chatUrl; - @Schema(description = "관련 학과", example = "COMPUTER") + @Schema(description = "관련 학과", example = "COMPUTER_SCIENCE_ENGINEERING") private MajorType major; @Schema(description = "스터디 정원", example = "10") diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/response/GetBookmarkedPostsResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/response/GetBookmarkedPostsResponse.java new file mode 100644 index 00000000..2035c0f3 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/response/GetBookmarkedPostsResponse.java @@ -0,0 +1,19 @@ +package kr.co.studyhubinu.studyhubserver.study.dto.response; + +import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; +import lombok.*; + +@Getter +@Setter // QueryDsl 때문에 필요함 +@NoArgsConstructor +@AllArgsConstructor +public class GetBookmarkedPostsResponse { + + private Long postId; + private MajorType major; + private String title; + private String content; + private int remainingSeat; + private boolean close; + +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/response/GetMyPostResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/response/GetMyPostResponse.java new file mode 100644 index 00000000..a3c42799 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/dto/response/GetMyPostResponse.java @@ -0,0 +1,23 @@ +package kr.co.studyhubinu.studyhubserver.study.dto.response; + +import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; +import lombok.Getter; + +@Getter +public class GetMyPostResponse { + private Long postId; + private MajorType major; + private String title; + private String content; + private int remainingSeat; + private boolean close; + + public GetMyPostResponse(Long postId, MajorType major, String title, String content, int remainingSeat, boolean close) { + this.postId = postId; + this.major = major; + this.title = title; + this.content = content; + this.remainingSeat = remainingSeat; + this.close = close; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepository.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepository.java index c5163da9..82287658 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepository.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepository.java @@ -1,7 +1,16 @@ package kr.co.studyhubinu.studyhubserver.study.repository; import kr.co.studyhubinu.studyhubserver.study.domain.StudyPostEntity; +import kr.co.studyhubinu.studyhubserver.study.dto.response.GetMyPostResponse; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface StudyPostRepository extends JpaRepository, StudyPostRepositoryCustom { + + @Query("SELECT new kr.co.studyhubinu.studyhubserver.study.dto.response.GetMyPostResponse(sp.id, sp.major, sp.title, sp.content, sp.remainingSeat, sp.close) " + + "FROM StudyPostEntity sp " + + "WHERE sp.postedUserId = :userId") + Slice findByPostedUserId(Long userId, Pageable pageable); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryCustom.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryCustom.java index 50759bd3..3746d41e 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryCustom.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryCustom.java @@ -1,6 +1,5 @@ package kr.co.studyhubinu.studyhubserver.study.repository; -import kr.co.studyhubinu.studyhubserver.study.domain.StudyPostEntity; import kr.co.studyhubinu.studyhubserver.study.dto.response.*; import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; import org.springframework.data.domain.Pageable; @@ -17,5 +16,7 @@ public interface StudyPostRepositoryCustom { Slice findByContent(String content, Pageable pageable); + Slice findPostsByBookmarked(Long userId, Pageable pageable); + //Slice findByBookMark(Pageable pageable); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryImpl.java index 8d189c72..aa79c40e 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/repository/StudyPostRepositoryImpl.java @@ -14,6 +14,7 @@ import java.util.Collections; import java.util.List; +import static kr.co.studyhubinu.studyhubserver.bookmark.domain.QBookMarkEntity.bookMarkEntity; import static kr.co.studyhubinu.studyhubserver.study.domain.QStudyPostEntity.*; @Repository @@ -81,6 +82,29 @@ public Slice findByContent(String content, Pageable p return findByQuery(studyPostDto, pageable); } + @Override + public Slice findPostsByBookmarked(Long userId, Pageable pageable) { + List lists = jpaQueryFactory.select( + Projections.bean(GetBookmarkedPostsResponse.class, + studyPostEntity.id.as("postId"), + studyPostEntity.major, + studyPostEntity.title, + studyPostEntity.content, + studyPostEntity.remainingSeat, + studyPostEntity.close + ) + ) + .from(studyPostEntity) + .innerJoin(bookMarkEntity) + .on(bookMarkEntity.postId.eq(studyPostEntity.id)) + .where(bookMarkEntity.userId.eq(userId)) + .orderBy(studyPostEntity.createdDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + return toSlice(pageable, lists); + } + public Slice findByQuery(JPAQuery query, Pageable pageable) { Slice sliceDto = toSlice(pageable, query.fetch()); diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/study/service/StudyPostService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/study/service/StudyPostService.java index 037f657c..dc4e0bca 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/study/service/StudyPostService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/study/service/StudyPostService.java @@ -13,8 +13,10 @@ import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -68,6 +70,18 @@ public Slice findPostResponseByContent(String content return studyPostRepository.findByContent(content, pageable); } + public Slice getMyPosts(int page, int size, Long userId) { + UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdDate")); + return studyPostRepository.findByPostedUserId(user.getId(), pageable); + } + + public Slice getBookmarkedPosts(int page, int size, Long userId) { + UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdDate")); + return studyPostRepository.findPostsByBookmarked(userId, pageable); + } + // public Slice findPostResponseByBookMark(Pageable pageable) { // return studyPostRepository.findByBookMark(pageable); // } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserEntity.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserEntity.java index bdf3d118..d7f25676 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserEntity.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/domain/UserEntity.java @@ -11,10 +11,7 @@ import lombok.NoArgsConstructor; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import javax.persistence.*; @Entity @Getter @@ -33,8 +30,10 @@ public class UserEntity extends BaseTimeEntity { private String imaUrl; + @Enumerated(EnumType.STRING) private MajorType major; + @Enumerated(EnumType.STRING) private GenderType gender; private String imageUrl; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/SignUpRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/SignUpRequest.java index 0c1b794b..34d5da98 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/SignUpRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/SignUpRequest.java @@ -18,7 +18,7 @@ public class SignUpRequest { @NotBlank private String email; - @Schema(description = "유저 비밀번호", example = "asd123") + @Schema(description = "유저 비밀번호", example = "asdasdasd!!") @Pattern( regexp = "^(?=.*[!@#$%^&*?~_]).{10,}$", message = "비밀번호는 10자 이상이어야 하며, 하나 이상의 특수문자를 포함해야 합니다." diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java index 2c55689d..67621baf 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java @@ -56,7 +56,9 @@ public void updateNickname(UpdateNicknameInfo info) { } public void nicknameDuplicationValid(String nickname) { - userRepository.findByNickname(nickname).orElseThrow(UserNicknameDuplicateException::new); + if (userRepository.findByNickname(nickname).isPresent()) { + throw new UserNicknameDuplicateException(); + } } @Transactional