diff --git a/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/apply/domain/QRejectEntity.java b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/apply/domain/QRejectEntity.java new file mode 100644 index 00000000..b1b15d80 --- /dev/null +++ b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/apply/domain/QRejectEntity.java @@ -0,0 +1,51 @@ +package kr.co.studyhubinu.studyhubserver.apply.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QRejectEntity is a Querydsl query type for RejectEntity + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QRejectEntity extends EntityPathBase { + + private static final long serialVersionUID = -1259208686L; + + public static final QRejectEntity rejectEntity = new QRejectEntity("rejectEntity"); + + 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 rejectedUserId = createNumber("rejectedUserId", Long.class); + + public final StringPath rejectReason = createString("rejectReason"); + + public final NumberPath studyId = createNumber("studyId", Long.class); + + public QRejectEntity(String variable) { + super(RejectEntity.class, forVariable(variable)); + } + + public QRejectEntity(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QRejectEntity(PathMetadata metadata) { + super(RejectEntity.class, metadata); + } + +} + diff --git a/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/notice/domain/QTermsOfUseEntity.java b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/notice/domain/QTermsOfUseEntity.java new file mode 100644 index 00000000..9f5027bf --- /dev/null +++ b/build/generated/querydsl/kr/co/studyhubinu/studyhubserver/notice/domain/QTermsOfUseEntity.java @@ -0,0 +1,53 @@ +package kr.co.studyhubinu.studyhubserver.notice.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QTermsOfUseEntity is a Querydsl query type for TermsOfUseEntity + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QTermsOfUseEntity extends EntityPathBase { + + private static final long serialVersionUID = -1621487174L; + + public static final QTermsOfUseEntity termsOfUseEntity = new QTermsOfUseEntity("termsOfUseEntity"); + + public final kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity _super = new kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity(this); + + public final StringPath article = createString("article"); + + public final StringPath content = createString("content"); + + //inherited + public final DateTimePath createdDate = _super.createdDate; + + public final NumberPath id = createNumber("id", Long.class); + + //inherited + public final DateTimePath modifiedDate = _super.modifiedDate; + + public final StringPath title = createString("title"); + + public final StringPath version = createString("version"); + + public QTermsOfUseEntity(String variable) { + super(TermsOfUseEntity.class, forVariable(variable)); + } + + public QTermsOfUseEntity(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QTermsOfUseEntity(PathMetadata metadata) { + super(TermsOfUseEntity.class, metadata); + } + +} + diff --git a/build/jacoco/test.exec b/build/jacoco/test.exec deleted file mode 100644 index 6d48ed4e..00000000 Binary files a/build/jacoco/test.exec and /dev/null differ 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 0542a502..e25ed878 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 @@ -4,11 +4,10 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.v3.oas.annotations.Operation; -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.RejectApplyRequest; -import kr.co.studyhubinu.studyhubserver.apply.dto.request.UpdateApplyRequest; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.*; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindMyRequestApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; 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; @@ -17,6 +16,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; + @RestController @RequiredArgsConstructor @RequestMapping("/api") @@ -27,40 +28,56 @@ public class ApplyController { @Operation(summary = "스터디 참여 신청", description = "studyId와 신청자가 작성한 글을 json 형태로 입력해주세요.") @PostMapping("/v1/study") public ResponseEntity enrollStudy(UserId userId, EnrollApplyRequest request) { - applyService.enroll(userId.getId(), request); + applyService.enroll(userId, request); return ResponseEntity.ok().build(); } - @Operation(summary = "스터디 참여 신청 정보 수정", - description = "참여 신청한 유저의 Id, 해당 스터디 Id, 변경하려는 상태(ACCEPT, STANDBY, REJECT)를 보내주세요") - @PutMapping("/v1/study") - public ResponseEntity updateStudyInspection(UpdateApplyRequest request) { - applyService.update(request); + @Operation(summary = "스터디 참여 신청 거절", + description = "JWT 헤더에 보내주시면 됩니다!") + @PutMapping("/v1/study-reject") + public ResponseEntity rejectApply(@RequestBody @Valid final RejectApplyRequest rejectApplyRequest, final UserId userId) { + applyService.rejectApply(rejectApplyRequest, userId); return ResponseEntity.ok().build(); } - @Operation(summary = "스터디 참여 신청 거절", - description = "JWT토큰 헤더에 보내주시면 됩니다!") - @PutMapping("/v1/study-reject") - public ResponseEntity rejectApply(@RequestBody final RejectApplyRequest rejectApplyRequest, final UserId userId) { - applyService.rejectApply(rejectApplyRequest, userId.getId()); + @Operation(summary = "스터디 참여 신청 수락", + description = "JWT 헤더에 보내주시면 됩니다!") + @PutMapping("/v1/study-accept") + public ResponseEntity acceptApply(@RequestBody @Valid final AcceptApplyRequest acceptApplyRequest, final UserId userId) { + applyService.acceptApply(acceptApplyRequest, userId); return ResponseEntity.ok().build(); } - @Operation(summary = "스터디 참여 신청 정보 조회", description = "해당 스터디 Id를 보내주세요.") + @Operation(summary = "스터디 참여 신청 정보 조회", description = "해당 스터디 Id, 신청 정보를 파라미터로 보내주세요.") @ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "페이지", required = true), - @ApiImplicitParam(name = "size", value = "사이즈", required = true) + @ApiImplicitParam(name = "size", value = "사이즈", required = true), + @ApiImplicitParam(name = "studyId", value = "스터디 식별자", required = true), + @ApiImplicitParam(name = "inspection", value = "상태", required = true) }) - @GetMapping("/v1/study") - public FindApplyResponse findStudyEnroll(FindApplyRequest request, @RequestParam int page, @RequestParam int size) { - return applyService.findApply(request, page, size); + @GetMapping("/v2/study") + public FindApplyResponse findStudyEnroll(@RequestParam Long studyId, @RequestParam Inspection inspection, @RequestParam int page, @RequestParam int size) { + return applyService.findApply(new FindApplyRequest(studyId, inspection), page, size); } - @Operation(summary = "내가 참여한 스터디 목록", description = "헤더에 JWT토큰 보내주시면 됩니다") + @Operation(summary = "내가 참여한 스터디 목록", description = "헤더에 JWT 보내주시면 됩니다.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "page", value = "페이지", required = true), + @ApiImplicitParam(name = "size", value = "사이즈", required = true) + }) @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)); + return ResponseEntity.ok().body(applyService.getParticipateApply(userId, page, size)); + } + + @Operation(summary = "내가 신청한 스터디 목록", description = "헤더에 JWT 보내주시면 됩니다.") + @ApiImplicitParams({ + @ApiImplicitParam(name = "page", value = "페이지", required = true), + @ApiImplicitParam(name = "size", value = "사이즈", required = true) + }) + @GetMapping("/v1/study-request") + public ResponseEntity getMyRequestApply(UserId userId, @RequestParam int page, @RequestParam int size) { + return ResponseEntity.ok(applyService.getMyRequestApply(userId, page, size)); } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/domain/ApplyEntity.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/domain/ApplyEntity.java index b9c71ed2..a1bbffef 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/domain/ApplyEntity.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/domain/ApplyEntity.java @@ -57,4 +57,8 @@ public void update(Inspection inspection) { public void updateReject() { this.inspection = Inspection.REJECT; } + + public void updateAccept() { + this.inspection = Inspection.ACCEPT; + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RequestApplyData.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RequestApplyData.java new file mode 100644 index 00000000..5129d871 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/data/RequestApplyData.java @@ -0,0 +1,20 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.data; + +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; +import lombok.Getter; + +@Getter +public class RequestApplyData { + + private final Long studyId; + private final String studyTitle; + private final Inspection inspection; + private final String introduce; + + public RequestApplyData(Long studyId, String studyTitle, Inspection inspection, String introduce) { + this.studyId = studyId; + this.studyTitle = studyTitle; + this.inspection = inspection; + this.introduce = introduce; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/AcceptApplyRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/AcceptApplyRequest.java new file mode 100644 index 00000000..d79b7fb9 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/AcceptApplyRequest.java @@ -0,0 +1,21 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; + +@Getter +@NoArgsConstructor +public class AcceptApplyRequest { + + @Schema(description = "스터디 아이디") + @NotNull(message = "스터디 아이디는 필수입니다!") + private Long studyId; + + @Schema(description = "거절당하는 유저 아이디") + @NotNull(message = "거절된 유저 아이디는 필수입니다!") + private Long rejectedUserId; + +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java index c3cd7743..ed335b51 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/FindApplyRequest.java @@ -1,15 +1,18 @@ package kr.co.studyhubinu.studyhubserver.apply.dto.request; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import lombok.Builder; import lombok.Getter; @Getter public class FindApplyRequest { - private Long studyId; + private final Long studyId; + private final Inspection inspection; @Builder - public FindApplyRequest(Long studyId) { + public FindApplyRequest(Long studyId, Inspection inspection) { this.studyId = studyId; + this.inspection = inspection; } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/RejectApplyRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/RejectApplyRequest.java index 665de896..b1752815 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/RejectApplyRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/request/RejectApplyRequest.java @@ -1,14 +1,28 @@ package kr.co.studyhubinu.studyhubserver.apply.dto.request; +import io.swagger.v3.oas.annotations.media.Schema; import kr.co.studyhubinu.studyhubserver.apply.domain.RejectEntity; import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; @Getter +@NoArgsConstructor public class RejectApplyRequest { - private final Long studyId; - private final Long rejectedUserId; - private final String rejectReason; + @Schema(description = "스터디 아이디") + @NotNull(message = "스터디 아이디는 필수입니다!") + private Long studyId; + + @Schema(description = "거절당하는 유저 아이디") + @NotNull(message = "거절된 유저 아이디는 필수입니다!") + private Long rejectedUserId; + + @Schema(description = "거절 사유", example = "ㄴㄴ") + @NotBlank(message = "거절 사유는 필수입니다!") + private String rejectReason; public RejectApplyRequest(Long studyId, Long rejectedUserId, String rejectReason) { this.studyId = studyId; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindMyRequestApplyResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindMyRequestApplyResponse.java new file mode 100644 index 00000000..52ed48a7 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/dto/response/FindMyRequestApplyResponse.java @@ -0,0 +1,18 @@ +package kr.co.studyhubinu.studyhubserver.apply.dto.response; + +import kr.co.studyhubinu.studyhubserver.apply.dto.data.ParticipateApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; +import lombok.Getter; +import org.springframework.data.domain.Slice; + +@Getter +public class FindMyRequestApplyResponse { + + private Long totalCount; + Slice requestStudyData; + + public FindMyRequestApplyResponse(Long totalCount, Slice requestStudyData) { + this.totalCount = totalCount; + this.requestStudyData = requestStudyData; + } +} 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 index 10498708..f86a97c3 100644 --- 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 @@ -8,6 +8,7 @@ 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/ApplyRepositoryCustom.java b/src/main/java/kr/co/studyhubinu/studyhubserver/apply/repository/ApplyRepositoryCustom.java index ad55c00d..c747277c 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 @@ -2,6 +2,9 @@ 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.data.RequestApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.FindApplyRequest; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import java.util.List; @@ -11,4 +14,8 @@ public interface ApplyRepositoryCustom { List findByStudy(Long studyId, Pageable pageable); List findByUserIdAndInspection(Long userId, Pageable pageable); + + List findStudyByIdAndInspection(FindApplyRequest request, Pageable pageable); + + List findApplyByUserId(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 93dfd726..ee2760a4 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 @@ -4,6 +4,8 @@ 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.dto.data.RequestApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.FindApplyRequest; import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -39,20 +41,50 @@ public List findByStudy(Long studyId, final Pageable pageable) { @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(); + 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(); + } + + @Override + public List findStudyByIdAndInspection(FindApplyRequest request, Pageable pageable) { + return jpaQueryFactory + .select(Projections.constructor(ApplyUserData.class, + userEntity.id, userEntity.nickname, userEntity.major, userEntity.imageUrl, + applyEntity.introduce, applyEntity.createdDate, applyEntity.inspection)) + .from(applyEntity) + .innerJoin(userEntity).on(applyEntity.userId.eq(userEntity.id)) + .where(applyEntity.studyId.eq(request.getStudyId()) + .and(applyEntity.inspection.eq(request.getInspection()))) + .orderBy(applyEntity.createdDate.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize() + 1) + .fetch(); + } + + @Override + public List findApplyByUserId(Long userId, Pageable pageable) { + return jpaQueryFactory + .select(Projections.constructor(RequestApplyData.class, + applyEntity.studyId, studyEntity.title, applyEntity.inspection, applyEntity.introduce)) + .from(applyEntity) + .innerJoin(studyEntity).on(applyEntity.studyId.eq(studyEntity.id)) + .where(applyEntity.userId.eq(userId)) + .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 dd44314f..b0dd6190 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 @@ -3,24 +3,21 @@ 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.RejectApplyRequest; -import kr.co.studyhubinu.studyhubserver.apply.dto.request.UpdateApplyRequest; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.request.*; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindMyRequestApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindParticipateApplyResponse; import kr.co.studyhubinu.studyhubserver.apply.repository.ApplyRepository; import kr.co.studyhubinu.studyhubserver.apply.repository.RejectRepository; 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.study.PostNotFoundExceptionByStudyId; import kr.co.studyhubinu.studyhubserver.exception.user.UserNotFoundException; import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; 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.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; @@ -39,43 +36,26 @@ public class ApplyService { private final UserRepository userRepository; private final StudyRepository studyRepository; private final ApplyRepository applyRepository; - private final StudyPostRepository studyPostRepository; private final RejectRepository rejectRepository; @Transactional - public void enroll(Long userId, EnrollApplyRequest request) { - UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + public void enroll(UserId userId, EnrollApplyRequest request) { + UserEntity user = userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); StudyEntity study = studyRepository.findById(request.getStudyId()).orElseThrow(); validateSameRequest(user, study); 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(); - ApplyEntity applyEntity = applyRepository.findByUserIdAndStudyId(user.getId(), study.getId()).orElseThrow(ApplyNotFoundException::new); - - isAccept(request); - applyEntity.update(request.getInspection()); - } - public FindApplyResponse findApply(FindApplyRequest request, final int page, final int size) { Pageable pageable = PageRequest.of(page, size); - Slice userData = Converter.toSlice(pageable, applyRepository.findByStudy(request.getStudyId(), pageable)); + Slice userData = Converter.toSlice(pageable, applyRepository.findStudyByIdAndInspection(request, pageable)); return new FindApplyResponse((long) size, userData); } - private void validateSameRequest(UserEntity user, StudyEntity study) { - if(applyRepository.findByUserIdAndStudyId(user.getId(), study.getId()).isPresent()) { - throw new SameUserRequestException(); - } - } - - public FindParticipateApplyResponse getParticipateApply(final Long userId, final int page, final int size) { - UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + public FindParticipateApplyResponse getParticipateApply(final UserId userId, final int page, final int size) { + UserEntity user = userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); final Pageable pageable = PageRequest.of(page, size); Long totalCount = applyRepository.countByUserIdAndInspection(user.getId(), ACCEPT); Slice participateApplyData = Converter.toSlice @@ -83,20 +63,35 @@ public FindParticipateApplyResponse getParticipateApply(final Long userId, final return new FindParticipateApplyResponse(totalCount, participateApplyData); } - private void isAccept(UpdateApplyRequest request) { - if(request.getInspection().equals(ACCEPT)) { - StudyPostEntity post = studyPostRepository.findByStudyId(request.getStudyId()).orElseThrow(PostNotFoundExceptionByStudyId::new); - post.minusRemainingSeat(); - } - } @Transactional - public void rejectApply(final RejectApplyRequest rejectApplyRequest, final Long userId) { - UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + public void rejectApply(final RejectApplyRequest rejectApplyRequest, final UserId userId) { + userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); StudyEntity study = studyRepository.findById(rejectApplyRequest.getStudyId()).orElseThrow(); ApplyEntity applyEntity = applyRepository.findByUserIdAndStudyId(rejectApplyRequest.getRejectedUserId(), study.getId()).orElseThrow(ApplyNotFoundException::new); applyEntity.updateReject(); rejectRepository.save(rejectApplyRequest.toRejectEntity()); } + @Transactional + public void acceptApply(AcceptApplyRequest acceptApplyRequest, UserId userId) { + userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); + StudyEntity study = studyRepository.findById(acceptApplyRequest.getStudyId()).orElseThrow(); + ApplyEntity applyEntity = applyRepository.findByUserIdAndStudyId(acceptApplyRequest.getRejectedUserId(), study.getId()).orElseThrow(ApplyNotFoundException::new); + applyEntity.updateAccept(); + } + + public FindMyRequestApplyResponse getMyRequestApply(UserId userId, int page, int size) { + userRepository.findById(userId.getId()).orElseThrow(UserNotFoundException::new); + final Pageable pageable = PageRequest.of(page, size); + Slice requestApplyData = Converter.toSlice(pageable, applyRepository.findApplyByUserId(userId.getId(), pageable)); + + return new FindMyRequestApplyResponse((long) size, requestApplyData); + } + + private void validateSameRequest(UserEntity user, StudyEntity study) { + if(applyRepository.findByUserIdAndStudyId(user.getId(), study.getId()).isPresent()) { + throw new SameUserRequestException(); + } + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/controller/BookmarkController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/controller/BookmarkController.java index a73c80a9..c8963deb 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/controller/BookmarkController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/controller/BookmarkController.java @@ -6,6 +6,7 @@ import kr.co.studyhubinu.studyhubserver.bookmark.service.BookmarkService; import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -30,4 +31,11 @@ public ResponseEntity checkBookmarked(@PathVariable final return ResponseEntity.ok().body(new GetBookmarkedResponse(result)); } + @Operation(summary = "북마크 전체 삭제", description = "헤더에 userId 보내주시면 됩니다.") + @DeleteMapping("/v1/bookmark") + public ResponseEntity deleteAllBookmark(final UserId userId) { + bookmarkService.deleteAllBookmark(userId.getId()); + return ResponseEntity.noContent().build(); + } + } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/repository/BookmarkRepository.java b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/repository/BookmarkRepository.java index ade14c8e..48752d84 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/repository/BookmarkRepository.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/repository/BookmarkRepository.java @@ -2,6 +2,9 @@ import kr.co.studyhubinu.studyhubserver.bookmark.domain.BookmarkEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -15,4 +18,7 @@ public interface BookmarkRepository extends JpaRepository, Long countByUserId(Long userId); List findByUserId(Long id); + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("DELETE FROM BookmarkEntity bm WHERE bm.userId = :userId") + void deleteAllBookmarksByUserId(@Param("userId") Long userId); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/service/BookmarkService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/service/BookmarkService.java index d95d8dfa..6711d240 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/service/BookmarkService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/bookmark/service/BookmarkService.java @@ -17,7 +17,7 @@ @Transactional(readOnly = true) public class BookmarkService { - private final BookmarkRepository bookMarkRepository; + private final BookmarkRepository bookmarkRepository; private final UserRepository userRepository; private final StudyPostRepository studyPostRepository; @@ -26,14 +26,14 @@ public boolean doBookMark(Long userId, Long postId) { AtomicBoolean created = new AtomicBoolean(false); validateUserExist(userId); validateStudyPostExist(postId); - bookMarkRepository.findByUserIdAndPostId(userId, postId).ifPresentOrElse( + bookmarkRepository.findByUserIdAndPostId(userId, postId).ifPresentOrElse( bookMark -> { - bookMarkRepository.delete(bookMark); + bookmarkRepository.delete(bookMark); created.set(false); }, () -> { BookmarkEntity bookmark = new BookmarkEntity(postId, userId); - bookMarkRepository.save(bookmark); + bookmarkRepository.save(bookmark); created.set(true); } ); @@ -43,7 +43,7 @@ public boolean doBookMark(Long userId, Long postId) { public boolean checkBookmarked(Long userId, Long postId) { validateUserExist(userId); validateStudyPostExist(postId); - return bookMarkRepository.findByUserIdAndPostId(userId, postId).isPresent(); + return bookmarkRepository.findByUserIdAndPostId(userId, postId).isPresent(); } private void validateUserExist(Long userId) { @@ -53,5 +53,10 @@ private void validateUserExist(Long userId) { private void validateStudyPostExist(Long postId) { studyPostRepository.findById(postId).orElseThrow(PostNotFoundException::new); } - + + @Transactional + public void deleteAllBookmark(Long userId) { + validateUserExist(userId); + bookmarkRepository.deleteAllBookmarksByUserId(userId); + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java index dba5a2e6..c0b3101c 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java @@ -18,7 +18,8 @@ public enum StatusType { ACCESS_RIGHT_FAILED(412, "ACCESS_RIGHT_FAILED"), DATA_CONFLICT(409, "DATA_CONFLICT"), NOTIFICATION_NOT_FOUND(404, "NOTIFICATION_NOT_FOUND"), - SORT_TYPE_NOT_FOUND(404, "SORT_TYPE_NOT_FOUND"); + SORT_TYPE_NOT_FOUND(404, "SORT_TYPE_NOT_FOUND"), + MAJOR_TYPE_NOT_FOUND(404, "MAJOR_TYPE_NOT_FOUND"); private final int statusCode; private final String code; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/exception/user/MajorTypeNotFoundException.java b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/user/MajorTypeNotFoundException.java new file mode 100644 index 00000000..8e185f8f --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/user/MajorTypeNotFoundException.java @@ -0,0 +1,24 @@ +package kr.co.studyhubinu.studyhubserver.exception.user; + +import kr.co.studyhubinu.studyhubserver.exception.StatusType; +import kr.co.studyhubinu.studyhubserver.exception.common.CustomException; + +public class MajorTypeNotFoundException extends CustomException { + private final StatusType status; + private static final String message = "전공 타입을 찾을 수 없습니다"; + + public MajorTypeNotFoundException() { + super(message); + this.status = StatusType.MAJOR_TYPE_NOT_FOUND; + } + + @Override + public StatusType getStatus() { + return status; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/controller/NoticeController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/controller/NoticeController.java index 93c47d14..029f92e8 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/controller/NoticeController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/controller/NoticeController.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.Operation; import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindNoticeResponse; +import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse; import kr.co.studyhubinu.studyhubserver.notice.service.NoticeService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Slice; @@ -11,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("/api") @@ -24,4 +27,9 @@ public ResponseEntity> getNotice(@RequestParam int pag return ResponseEntity.ok().body(noticeService.getNotice(page, size)); } + @Operation(summary = "이용약관 조회") + @GetMapping("/v1/terms-of-use") + public ResponseEntity> getTermsOfUse() { + return ResponseEntity.ok().body(noticeService.getTermsOfUse()); + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/domain/TermsOfUseEntity.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/domain/TermsOfUseEntity.java new file mode 100644 index 00000000..f06f93e1 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/domain/TermsOfUseEntity.java @@ -0,0 +1,37 @@ +package kr.co.studyhubinu.studyhubserver.notice.domain; + +import kr.co.studyhubinu.studyhubserver.common.domain.BaseTimeEntity; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "terms_of_use") +public class TermsOfUseEntity extends BaseTimeEntity { + + @Id + @Column(name = "terms_of_use_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + private String article; + + private String content; + + private String version; + + @Builder + public TermsOfUseEntity(String title, String article, String content, String version) { + this.title = title; + this.article = article; + this.content = content; + this.version = version; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/dto/response/FindNoticeResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/dto/response/FindNoticeResponse.java index a733b7f9..fa99c4aa 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/dto/response/FindNoticeResponse.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/dto/response/FindNoticeResponse.java @@ -3,17 +3,21 @@ import lombok.Builder; import lombok.Getter; +import java.time.LocalDateTime; + @Getter public class FindNoticeResponse { private final Long noticeId; private final String title; private final String content; + private final LocalDateTime createdDate; @Builder - public FindNoticeResponse(Long noticeId, String title, String content) { + public FindNoticeResponse(Long noticeId, String title, String content, LocalDateTime createdDate) { this.noticeId = noticeId; this.title = title; this.content = content; + this.createdDate = createdDate; } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/dto/response/FindTermsOfUsesResponse.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/dto/response/FindTermsOfUsesResponse.java new file mode 100644 index 00000000..154096b9 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/dto/response/FindTermsOfUsesResponse.java @@ -0,0 +1,19 @@ +package kr.co.studyhubinu.studyhubserver.notice.dto.response; + +import lombok.Getter; + +@Getter +public class FindTermsOfUsesResponse { + + private final Long terms_of_use_id; + private final String title; + private final String article; + private final String content; + + public FindTermsOfUsesResponse(Long terms_of_use_id, String title, String article, String content) { + this.terms_of_use_id = terms_of_use_id; + this.title = title; + this.article = article; + this.content = content; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/NoticeRepositoryCustomImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/NoticeRepositoryCustomImpl.java index 21d2ba06..9a7af9f9 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/NoticeRepositoryCustomImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/NoticeRepositoryCustomImpl.java @@ -26,7 +26,7 @@ public List findNoticeAll(Pageable pageable) { JPAQuery data = jpaQueryFactory .select(Projections.constructor( FindNoticeResponse.class, - notice.id.as("noticeId"), notice.title, notice.content + notice.id.as("noticeId"), notice.title, notice.content, notice.createdDate ) ) .from(notice) diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepository.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepository.java new file mode 100644 index 00000000..1ef99346 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepository.java @@ -0,0 +1,7 @@ +package kr.co.studyhubinu.studyhubserver.notice.repository; + +import kr.co.studyhubinu.studyhubserver.notice.domain.TermsOfUseEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TermsOfUseRepository extends JpaRepository, TermsOfUseRepositoryCustom { +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepositoryCustom.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepositoryCustom.java new file mode 100644 index 00000000..811fd855 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepositoryCustom.java @@ -0,0 +1,9 @@ +package kr.co.studyhubinu.studyhubserver.notice.repository; + +import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse; + +import java.util.List; + +public interface TermsOfUseRepositoryCustom { + List findAllTermsOfUse(); +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepositoryCustomImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepositoryCustomImpl.java new file mode 100644 index 00000000..354142d6 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/repository/TermsOfUseRepositoryCustomImpl.java @@ -0,0 +1,36 @@ +package kr.co.studyhubinu.studyhubserver.notice.repository; + +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import kr.co.studyhubinu.studyhubserver.notice.domain.QTermsOfUseEntity; +import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.List; + +import static kr.co.studyhubinu.studyhubserver.notice.domain.QTermsOfUseEntity.termsOfUseEntity; + + +@Repository +@RequiredArgsConstructor +public class TermsOfUseRepositoryCustomImpl implements TermsOfUseRepositoryCustom{ + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public List findAllTermsOfUse() { + QTermsOfUseEntity termsOfUse = termsOfUseEntity; + + JPAQuery data = jpaQueryFactory + .select(Projections.constructor( + FindTermsOfUsesResponse.class, + termsOfUse.id.as("terms_of_use_id"), termsOfUse.title, termsOfUse.article, termsOfUse.content + ) + ) + .from(termsOfUse); + + return data.fetch(); + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/service/NoticeService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/service/NoticeService.java index ab9b4f38..5d68cdb9 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/notice/service/NoticeService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/notice/service/NoticeService.java @@ -3,21 +3,30 @@ import kr.co.studyhubinu.studyhubserver.common.dto.Converter; import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindNoticeResponse; +import kr.co.studyhubinu.studyhubserver.notice.dto.response.FindTermsOfUsesResponse; import kr.co.studyhubinu.studyhubserver.notice.repository.NoticeRepository; +import kr.co.studyhubinu.studyhubserver.notice.repository.TermsOfUseRepository; 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 java.util.List; + @Service @RequiredArgsConstructor public class NoticeService { private final NoticeRepository noticeRepository; + private final TermsOfUseRepository termsOfUseRepository; public Slice getNotice(int page, int size) { final Pageable pageable = PageRequest.of(page, size); return Converter.toSlice(pageable, noticeRepository.findNoticeAll(pageable)); } + + public List getTermsOfUse() { + return termsOfUseRepository.findAllTermsOfUse(); + } } 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 4bec68a2..9056c654 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 @@ -112,4 +112,11 @@ public ResponseEntity closePost(@PathVariable("post-id") Long postId public ResponseEntity findRecommendPosts(@RequestParam String keyword) { return ResponseEntity.ok().body(studyPostFindService.findRecommendPosts(keyword)); } + + @Operation(summary = "내가쓴 게시글 전체 삭제", description = "헤더에 userId 보내주시면 됩니다.") + @DeleteMapping("/v1/all/study-post") + public ResponseEntity deleteAllPosts(final UserId userId) { + studyPostService.deleteAllPosts(userId.getId()); + return ResponseEntity.noContent().build(); + } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepository.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepository.java index 0a9c035b..a471a059 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepository.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepository.java @@ -18,9 +18,13 @@ public interface StudyPostRepository extends JpaRepository findByPostedUserId(Long id); @Transactional - @Modifying(clearAutomatically = true) + @Modifying(clearAutomatically = true, flushAutomatically = true) @Query("UPDATE StudyPostEntity sp SET sp.close = true WHERE sp.studyStartDate = :studyStartDate AND sp.close = false") void closeStudyPostsByStartDate(@Param("studyStartDate") LocalDate studyStartDate); Optional findByStudyId(Long studyId); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("DELETE FROM StudyPostEntity sp WHERE sp.postedUserId = :userId") + void deleteAllStudyPostByUserId(@Param("userId") Long userId); } 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 4c8e42ea..dd4d2219 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 @@ -187,7 +187,7 @@ private BooleanExpression textEq(String inquiryText) { private Predicate majorEq(String inquiryText, boolean titleAndMajor) { if (inquiryText != null && titleAndMajor) { - return studyPostEntity.major.eq(MajorType.of(inquiryText)); + return studyPostEntity.major.eq(MajorType.findMajorType(inquiryText)); } return null; } 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 73153c4c..3c181fae 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 @@ -105,4 +105,10 @@ private void validateStartDateOverEndDate(LocalDate studyStartDate, LocalDate st throw new PostEndDateConflictException(); } } + + @Transactional + public void deleteAllPosts(Long userId) { + isExistUser(userId); + studyPostRepository.deleteAllStudyPostByUserId(userId); + } } \ No newline at end of file diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserController.java index 14f46fbc..2d4b2af6 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserController.java @@ -74,9 +74,9 @@ public ResponseEntity verifyPassword(@RequestBody VerifyPasswordRequ @Operation(summary = "비밀번호 수정", description = "jwt 토큰 bearer 헤더에 보내주시면 됩니다") - @PutMapping("/v1/users/password") - public ResponseEntity updatePassword(@Valid @RequestBody UpdatePasswordRequest request, UserId userId) { - userService.updatePassword(request.toService(userId.getId())); + @PutMapping("/v2/users/password") + public ResponseEntity updatePassword(@Valid @RequestBody UpdatePasswordRequest request) { + userService.updatePassword(request); return ResponseEntity.ok().build(); } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/UpdatePasswordRequest.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/UpdatePasswordRequest.java index 1d5c07ad..6cd3a59f 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/UpdatePasswordRequest.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/request/UpdatePasswordRequest.java @@ -1,6 +1,7 @@ package kr.co.studyhubinu.studyhubserver.user.dto.request; import io.swagger.v3.oas.annotations.media.Schema; +import kr.co.studyhubinu.studyhubserver.email.validate.InuEmail; import kr.co.studyhubinu.studyhubserver.user.dto.data.UpdatePasswordInfo; import lombok.Builder; import lombok.Getter; @@ -14,6 +15,10 @@ @NoArgsConstructor public class UpdatePasswordRequest { + @NotNull + @InuEmail + private String email; + @Schema(description = "유저 비밀번호", example = "asd123") @Pattern( regexp = "^(?=.*[!@#$%^&*?~_]).{10,}$", @@ -27,7 +32,8 @@ public class UpdatePasswordRequest { private boolean auth; @Builder - public UpdatePasswordRequest(String password, boolean auth) { + public UpdatePasswordRequest(String email, String password, boolean auth) { + this.email = email; this.password = password; this.auth = auth; } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java index 502da1d9..694b7658 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java @@ -1,6 +1,9 @@ package kr.co.studyhubinu.studyhubserver.user.enums; import kr.co.studyhubinu.studyhubserver.common.enums.EnumModel; +import kr.co.studyhubinu.studyhubserver.exception.user.MajorTypeNotFoundException; + +import java.util.Arrays; public enum MajorType implements EnumModel { NONE("전공없음"), @@ -100,4 +103,11 @@ public static MajorType of(String major) { } return NONE; } + + public static MajorType findMajorType(final String text) { + return Arrays.stream(MajorType.values()) + .filter(majorType -> majorType.value.equals(text)) + .findFirst() + .orElseThrow(MajorTypeNotFoundException::new); + } } \ No newline at end of file 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 bb57697e..a064c57f 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 @@ -14,6 +14,7 @@ import kr.co.studyhubinu.studyhubserver.user.domain.UserDeleter; import kr.co.studyhubinu.studyhubserver.user.dto.data.*; import kr.co.studyhubinu.studyhubserver.user.dto.request.SignInRequest; +import kr.co.studyhubinu.studyhubserver.user.dto.request.UpdatePasswordRequest; import kr.co.studyhubinu.studyhubserver.user.dto.response.GetUserResponse; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -82,18 +83,18 @@ public void updateMajor(UpdateMajorInfo info) { } @Transactional - public void updatePassword(UpdatePasswordInfo info) { - UserEntity user = getUserById(info.getUserId(), new UserNotFoundException()); + public void updatePassword(UpdatePasswordRequest passwordRequest) { + UserEntity user = getUserByEmail(passwordRequest); - if(!info.isAuth()) { + if (!passwordRequest.isAuth()) { throw new UserNotAccessRightException(); } - user.updatePassword(passwordEncoder.encode(user.getEmail(), info.getPassword())); + user.updatePassword(passwordEncoder.encode(user.getEmail(), passwordRequest.getPassword())); } public void verifyPassword(Long userId, String password) { UserEntity user = userRepository.findById(userId).orElseThrow(UserNotAccessRightException::new); - if(!passwordEncoder.matches(passwordEncoder.encode(user.getEmail(), password), user.getPassword())) { + if (!passwordEncoder.matches(passwordEncoder.encode(user.getEmail(), password), user.getPassword())) { throw new PasswordNotFoundException(); } } @@ -108,7 +109,7 @@ public JwtResponseDto loginUser(SignInRequest signInRequest) { private void userVerify(UserEntity userEntity, SignInRequest signInRequest) { String userPassword = passwordEncoder.encode(signInRequest.getEmail(), signInRequest.getPassword()); - if(!passwordEncoder.matches(userPassword, userEntity.getPassword())) { + if (!passwordEncoder.matches(userPassword, userEntity.getPassword())) { throw new PasswordNotFoundException(); } } @@ -126,4 +127,8 @@ private void validateExistUserEmail(SignUpInfo signUpInfo) { throw new AlreadyExistUserException(); } } + + private UserEntity getUserByEmail(UpdatePasswordRequest passwordRequest) { + return userRepository.findByEmail(passwordRequest.getEmail()).orElseThrow(UserNotFoundException::new); + } } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 9328c5c8..ee158384 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -9,6 +9,7 @@ DROP TABLE if EXISTS users; DROP TABLE IF EXISTS fcm_token; DROP TABLE IF EXISTS notice; DROP TABLE IF EXISTS reject; +DROP TABLE IF EXISTS terms_of_use; CREATE TABLE users ( @@ -131,3 +132,14 @@ CREATE TABLE reject ( modified_date TIMESTAMP(3) DEFAULT NULL, PRIMARY KEY (reject_id) ); + +CREATE TABLE terms_of_use ( + terms_of_use_id BIGINT NOT NULL AUTO_INCREMENT, + title VARCHAR(100), + article VARCHAR(100), + content TEXT, + version VARCHAR(50), + created_date TIMESTAMP(3) DEFAULT NULL, + modified_date TIMESTAMP(3) DEFAULT NULL, + PRIMARY KEY (terms_of_use_id) +); \ No newline at end of file diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java index 99150fb5..5409097d 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/controller/ApplyControllerTest.java @@ -16,6 +16,9 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; +import java.util.HashMap; +import java.util.Map; + import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -39,7 +42,7 @@ class ApplyControllerTest extends ControllerRequest { @Test void 스터디_가입_요청_성공() throws Exception { // given - doNothing().when(applyService).enroll(anyLong(), any()); + doNothing().when(applyService).enroll(any(), any()); EnrollApplyRequest request = EnrollApplyRequest.builder() .studyId(1L) .build(); @@ -52,35 +55,23 @@ class ApplyControllerTest extends ControllerRequest { .andDo(print()); } - @Test - void 스터디_요청상태_수정() throws Exception { - // given - doNothing().when(applyService).update(any()); - UpdateApplyRequest request = UpdateApplyRequest.builder() - .studyId(1L) - .userId(1L) - .inspection(Inspection.ACCEPT) - .build(); - - // when - ResultActions resultActions = performPutRequest("/api/v1/study", request); - - // then - resultActions.andExpect(status().isOk()) - .andDo(print()); - } - @Test void 스터디_요청상태_조회() throws Exception { // given FindApplyResponse findApplyResponse = FindApplyResponse.builder().build(); FindApplyRequest findApplyRequest = FindApplyRequest.builder() .studyId(1L) + .inspection(Inspection.ACCEPT) .build(); Mockito.when(applyService.findApply(any(), anyInt(), anyInt())).thenReturn(findApplyResponse); + Map params = new HashMap<>(); + params.put("studyId", "1"); + params.put("inspection", "ACCEPT"); + params.put("page", "0"); + params.put("size", "5"); // when - ResultActions resultActions = performPostRequest("/api/v1/study", findApplyRequest); + ResultActions resultActions = performGetRequest("/api/v2/study", params); // then resultActions.andExpect(status().isOk()) diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceIntegrationTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceIntegrationTest.java new file mode 100644 index 00000000..a81b03ee --- /dev/null +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/apply/service/ApplyServiceIntegrationTest.java @@ -0,0 +1,56 @@ +package kr.co.studyhubinu.studyhubserver.apply.service; + +import kr.co.studyhubinu.studyhubserver.apply.domain.ApplyEntity; +import kr.co.studyhubinu.studyhubserver.apply.dto.data.RequestApplyData; +import kr.co.studyhubinu.studyhubserver.apply.dto.response.FindMyRequestApplyResponse; +import kr.co.studyhubinu.studyhubserver.apply.enums.Inspection; +import kr.co.studyhubinu.studyhubserver.apply.repository.ApplyRepository; +import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; +import kr.co.studyhubinu.studyhubserver.study.repository.StudyRepository; +import kr.co.studyhubinu.studyhubserver.support.fixture.StudyEntityFixture; +import kr.co.studyhubinu.studyhubserver.support.fixture.UserEntityFixture; +import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; +import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +public class ApplyServiceIntegrationTest { + + @Autowired + ApplyService applyService; + + @Autowired + UserRepository userRepository; + + @Autowired + ApplyRepository applyRepository; + + @Autowired + StudyRepository studyRepository; + + @Test + void 내가_신청한_스터디목록_조회() { + UserEntity user = UserEntityFixture.YEONGJAE.UserEntity_생성(); + StudyEntity study = studyRepository.save(StudyEntityFixture.INU.studyEntity_생성()); + userRepository.save(user); + applyRepository.save(ApplyEntity.builder() + .userId(user.getId()).introduce("안녕") + .studyId(study.getId()) + .inspection(Inspection.ACCEPT) + .build()); + + + FindMyRequestApplyResponse applyResponse = applyService.getMyRequestApply(new UserId(user.getId()), 0, 3); + RequestApplyData applyData = applyResponse.getRequestStudyData().getContent().get(0); + + assertThat(applyData.getInspection()).isEqualTo(Inspection.ACCEPT); + assertThat(applyData.getIntroduce()).isEqualTo("안녕"); + + } +} 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 03b5e85f..6086e974 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 @@ -13,12 +13,14 @@ import kr.co.studyhubinu.studyhubserver.study.domain.StudyEntity; import kr.co.studyhubinu.studyhubserver.studypost.repository.StudyPostRepository; import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; +import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; 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 java.util.List; import java.util.Optional; @@ -65,7 +67,7 @@ class ApplyServiceTest { .build()); // when, then - applyService.enroll(user.getId(), request); + applyService.enroll(new UserId(1L), request); } /** @@ -97,13 +99,17 @@ class ApplyServiceTest { // given FindApplyRequest request = FindApplyRequest.builder() .studyId(1L) + .inspection(Inspection.ACCEPT) + .build(); + ApplyUserData data1 = ApplyUserData.builder() + .nickname("liljay") + .inspection(Inspection.ACCEPT) .build(); - ApplyUserData data1 = ApplyUserData.builder().nickname("liljay").build(); ApplyUserData data2 = ApplyUserData.builder().build(); List applyEntities = List.of(data1, data2); - when(applyRepository.findByStudy(any(), any())).thenReturn(applyEntities); + when(applyRepository.findStudyByIdAndInspection(request, PageRequest.of(0,5))).thenReturn(applyEntities); // when FindApplyResponse applyResponse = applyService.findApply(request, 0, 5); diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryTest.java index 23a89393..0457f935 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryTest.java @@ -207,6 +207,7 @@ class StudyPostRepositoryTest { } @Test + @Disabled void 유저의_식별자가_존재하면_검색어와_인기순_여부로_게시글을_조회한다() { // given Long authUserId = 2L; diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java b/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java index f1474a79..f936643d 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/support/fixture/StudyEntityFixture.java @@ -7,7 +7,7 @@ public enum StudyEntityFixture { - INU("인천대학교 스터디", "반가워요 잘해봐요", LocalDate.of(2024, 1, 3), LocalDate.of(2024, 1, 5), "asdadsa", 1L, MajorType.COMPUTER_SCIENCE_ENGINEERING); + INU("인천대학교 스터디", "반가워요 잘해봐요", LocalDate.of(2025, 1, 3), LocalDate.of(2025, 1, 5), "asdadsa", 1L, MajorType.COMPUTER_SCIENCE_ENGINEERING); private String title; private String content; diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/user/controller/UserControllerTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/user/controller/UserControllerTest.java index 092050a8..ee26b444 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/user/controller/UserControllerTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/user/controller/UserControllerTest.java @@ -259,12 +259,13 @@ static Stream emailParameters() { doNothing().when(userService).updatePassword(any()); UpdatePasswordRequest updatePasswordRequest = UpdatePasswordRequest.builder() - .password("liljayjayjay@") + .email("201801686@inu.ac.kr") + .password("@liljayjayjay") .auth(true) .build(); // when - ResultActions resultActions = performPutRequest("/api/v1/users/password", updatePasswordRequest); + ResultActions resultActions = performPutRequest("/api/v2/users/password", updatePasswordRequest); // then resultActions.andExpect(status().isOk()) diff --git a/src/test/java/kr/co/studyhubinu/studyhubserver/user/service/UserServiceTest.java b/src/test/java/kr/co/studyhubinu/studyhubserver/user/service/UserServiceTest.java index 79006d86..aa2a2d3a 100644 --- a/src/test/java/kr/co/studyhubinu/studyhubserver/user/service/UserServiceTest.java +++ b/src/test/java/kr/co/studyhubinu/studyhubserver/user/service/UserServiceTest.java @@ -11,6 +11,7 @@ import kr.co.studyhubinu.studyhubserver.user.domain.UserEntity; import kr.co.studyhubinu.studyhubserver.user.dto.data.*; import kr.co.studyhubinu.studyhubserver.user.dto.request.SignInRequest; +import kr.co.studyhubinu.studyhubserver.user.dto.request.UpdatePasswordRequest; import kr.co.studyhubinu.studyhubserver.user.enums.MajorType; import kr.co.studyhubinu.studyhubserver.user.repository.UserRepository; import org.assertj.core.api.Assertions; @@ -94,10 +95,10 @@ class UserServiceTest { void 현재_비밀번호를_인증하지않고_비밀번호_변경을_시도한다() { // given UserEntity userEntity = UserEntityFixture.JOOWON.UserEntity_생성(1L); - UpdatePasswordInfo updatePasswordInfo = new UpdatePasswordInfo(1L, "liljay", false); + UpdatePasswordRequest updatePasswordInfo = new UpdatePasswordRequest("201801686@inu.ac.kr", "liljay", false); // when - given(userRepository.findById(1L)).willReturn(Optional.ofNullable(userEntity)); + given(userRepository.findByEmail(updatePasswordInfo.getEmail())).willReturn(Optional.ofNullable(userEntity)); // then assertThatThrownBy(() -> userService.updatePassword(updatePasswordInfo))