Skip to content

Commit

Permalink
Merge branch 'develop' into 61-be-크루-검색결과-필터링
Browse files Browse the repository at this point in the history
  • Loading branch information
hd0rable authored Aug 4, 2024
2 parents 4e9f9a3 + 5adf55c commit b11c161
Show file tree
Hide file tree
Showing 24 changed files with 457 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.likelion12.common.exception;

import com.example.likelion12.common.response.status.ResponseStatus;
import lombok.Getter;

@Getter
public class ReviewException extends RuntimeException{
private final ResponseStatus exceptionStatus;

public ReviewException(ResponseStatus exceptionStatus) {
super(exceptionStatus.getMessage());
this.exceptionStatus = exceptionStatus;
}

public ReviewException(ResponseStatus exceptionStatus, String message) {
super(message);
this.exceptionStatus = exceptionStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.likelion12.common.exception_handler;

import com.example.likelion12.common.exception.MemberCrewException;
import com.example.likelion12.common.exception.ReviewException;
import com.example.likelion12.common.response.BaseErrorResponse;
import jakarta.annotation.Priority;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Priority(0)
@RestControllerAdvice
public class ReviewExceptionControllerAdvice {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ReviewException.class)
public BaseErrorResponse handle_ReviewException(ReviewException e) {
log.error("[handle_ReviewException]", e);
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{
* 8000: member socialring 관련
*/
CANNOT_FOUND_MEMBERSOCIALRING(8000, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링을 찾을 수 없습니다."),
CANNOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."),
NOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."),
CANNOT_FOUND_MEMBERSOCIALRING_LIST(8002, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링 리스트를 찾을 수 없습니다."),
ALREADY_EXIST_IN_SOCIALRING(8003, HttpStatus.BAD_REQUEST.value(), "해당 소셜링에 이미 등록된 멤버입니다."),

Expand All @@ -61,8 +61,16 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{
*/
CANNOT_FOUND_MEMBERCREW(10000, HttpStatus.BAD_REQUEST.value(), "멤버_크루를 찾을 수 없습니다."),
CANNOT_FOUND_MEMBERCREW_LIST(10001, HttpStatus.BAD_REQUEST.value(), "멤버_크루 리스트를 찾을 수 없습니다."),
ALREADY_EXIST_IN_CREW(10002, HttpStatus.BAD_REQUEST.value(), "해당 크루에 이미 등록된 멤버입니다.");
ALREADY_EXIST_IN_CREW(10002, HttpStatus.BAD_REQUEST.value(), "해당 크루에 이미 등록된 멤버입니다."),
NOT_MEMBERCREW_CAPTAIN(10003, HttpStatus.BAD_REQUEST.value(), "크루 수정,삭제에 접근할수없는 권한입니다."),
NOT_CREW_MEMBERCREW(10004, HttpStatus.BAD_REQUEST.value(), "해당 크루에 참여 상태가 아닙니다."),

/**
* 11000 : Review 관련
*/
CANNOT_FOUND_REVIEW(11000, HttpStatus.BAD_REQUEST.value(), "리뷰를 찾을 수 없습니다."),
ALREADY_EXIST_REVIEW(11001, HttpStatus.BAD_REQUEST.value(), "이미 등록한 리뷰가 있습니다. 수정으로 작성해주세요."),
CANNOT_SET_SCORE(11002, HttpStatus.BAD_REQUEST.value(), "점수가 너무 높거나 낮습니다. 1~5점으로 평가해주세요"); // 추가된 상수


private final int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,28 @@ public BaseResponse<List<GetCrewSearchFilterResponse>> searchFilterCrew(@Request
return new BaseResponse<>(crewService.searchFilterCrew(memberId, getCrewSearchFilterRequest));
}

/**
* 크루 삭제하기
*/
@PatchMapping("/delete")
public BaseResponse<Void> deleteCrew(@RequestHeader("Authorization") String authorization,
@RequestParam Long crewId){
log.info("[CrewController.deleteCrew]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
crewService.deleteCrew(memberId,crewId);
return new BaseResponse<>(null);
}

/**
* 크루 탈퇴하기
*/
@PatchMapping("/cancel")
public BaseResponse<Void> cancelCrew(@RequestHeader("Authorization") String authorization,
@RequestParam Long crewId){
log.info("[CrewController.deleteCrew]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
crewService.cancelCrew(memberId,crewId);
return new BaseResponse<>(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import com.example.likelion12.dto.member.PostSignupRequest;
import com.example.likelion12.dto.member.PostSignupResponse;
import com.example.likelion12.service.MemberService;
import com.example.likelion12.util.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
Expand All @@ -18,10 +16,33 @@
public class MemberController {

private final MemberService memberService;
private final JwtProvider jwtProvider;

/**
* 회원가입
*/
@PostMapping("/signup")
public BaseResponse<PostSignupResponse> signUp(@RequestBody PostSignupRequest postSignupRequest){
log.info("[MemberController.signUp]");
return new BaseResponse<>(memberService.signUp(postSignupRequest));
}

@PatchMapping("/signout")
public BaseResponse<String> signOut(@RequestHeader("Authorization") String authorization){
Long memberId = jwtProvider.extractIdFromHeader(authorization);
memberService.signOut(memberId);
return new BaseResponse<>("회원탈퇴 되었습니다");
}

/**
* 로그아웃
*/
@PostMapping("/logout")
public BaseResponse<Void> logout(@RequestHeader("Authorization") String authorization){
log.info("[MemberController.logout]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
memberService.logout(memberId);
return new BaseResponse<>(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,38 @@ public BaseResponse<PostReviewResponse> createReview(@RequestHeader("Authorizati
memberId);
PostReviewResponse response = new PostReviewResponse(reviewId);
return new BaseResponse<>(response);

}

@PatchMapping("/delete")
public BaseResponse<String> deleteReview(@RequestHeader("Authorization") String authorization,
@RequestParam("review-id") Long reviewId) {
Long memberId = jwtProvider.extractIdFromHeader(authorization);


boolean isDeleted = reviewService.deleteReview(reviewId, memberId);
if (isDeleted) {
// 삭제 성공 시 응답 생성
return new BaseResponse<>("리뷰를 성공적으로 삭제했습니다");
}
else {
// 삭제 실패 시 응답 생성
return new BaseResponse<>("리뷰가 삭제되지 않았습니다");
}
}

@PatchMapping
public BaseResponse<String> updateReview(@RequestHeader("Authorization") String authorization,
@RequestParam("review-id") Long reviewId,
@RequestBody PostReviewRequest postReviewRequest) {
Long memberId = jwtProvider.extractIdFromHeader(authorization);

reviewService.updateReview(reviewId,
postReviewRequest.getFacilityId(),
postReviewRequest.getRanking(),
postReviewRequest.getComment(),
memberId);

return new BaseResponse<>("리뷰가 성공적으로 업데이트되었습니다");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ public BaseResponse<List<GetSocialringSearchFilterResponse>> searchFilterSocialr
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(socialringService.searchFilterSocialring(memberId, getSocialringSearchFilterRequest));
}

/**
* 소셜링 삭제하기
*/
@PatchMapping("/delete")
public BaseResponse<Void> deleteSocialring(@RequestHeader("Authorization") String authorization,
@RequestParam("socialringId") Long socialringId) {
log.info("[SocialringController.deleteSocialring]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
socialringService.deleteSocialring(memberId, socialringId);
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/example/likelion12/domain/Crew.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ public Crew(String crewName, String crewImg, int totalRecruits, int crewCost,
this.exercise = exercise;
this.status = status;
}

public void DeleteCrewInfo(BaseStatus status) {
this.status= status;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/likelion12/domain/Facility.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Facility extends BaseTime {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "facility_id", nullable = false)
private long facilityId;
private Long facilityId;

@Column(nullable = false)
private String facilityName;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/example/likelion12/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ public Member(String memberName, String email, String memberImg, BaseGender gend
this.status = status;
this.exercise = exercise;
}

public void setStatus(BaseStatus status) {
this.status = status;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/example/likelion12/domain/MemberCrew.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public MemberCrew (BaseRole role, Crew crew, Member member, BaseStatus status){
this.member = member;
this.status = status;
}

public void DeleteMemberCrewInfo(BaseStatus status) {
this.status= status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public MemberSocialring(BaseRole baseRole, Socialring socialring, Member member,
this.member = member;
this.status = baseStatus;
}

public void setStatus(BaseStatus status) {
this.status = status;
}
}
41 changes: 40 additions & 1 deletion src/main/java/com/example/likelion12/domain/Review.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.likelion12.domain;

import com.example.likelion12.common.exception.ReviewException;
import com.example.likelion12.domain.base.BaseStatus;
import com.example.likelion12.domain.base.BaseTime;
import jakarta.persistence.*;
Expand All @@ -8,6 +9,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_SET_SCORE;
import static jakarta.persistence.FetchType.LAZY;

@Entity
Expand All @@ -19,7 +21,7 @@ public class Review extends BaseTime {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "review_id", nullable = false)
private long reviewId;
private Long reviewId;

@Column(nullable = false)
private String comment;
Expand All @@ -43,9 +45,46 @@ public class Review extends BaseTime {

public void setReview(Facility facility , int ranking, String comment , Member member)
{
// 리뷰 점수 1~5 로 한정하기위해 검증하는 함수
if (ranking < 1 || ranking > 5) {
throw new ReviewException(CANNOT_SET_SCORE);
}

this.facility = facility;
this.ranking = ranking;
this.comment = comment;
this.member = member;
}

public void updateReview(Facility facility , int ranking, String comment )
{
this.facility = facility;
this.ranking = ranking;
this.comment = comment;
}

public void setStatus(BaseStatus status) {
this.status = status;
}

public void setRanking(Integer ranking) {
if (ranking != null) {
// 랭킹이 1~5 범위에 있어야 함
if (ranking < 1 || ranking > 5) {
throw new ReviewException(CANNOT_SET_SCORE);
}
this.ranking = ranking;
}
// ranking이 null인 경우, 기존 값을 그대로 유지합니다.
}

// 코멘트 설정 메서드
public void setComment(String comment) {
this.comment = comment != null ? comment : this.comment; // 기존 값 유지
}

// 시설 설정 메서드
public void setFacility(Facility facility) {
this.facility = facility != null ? facility : this.facility; // 기존 값 유지
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/example/likelion12/domain/Socialring.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.likelion12.domain.base.BaseStatus;
import com.example.likelion12.domain.base.BaseTime;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ser.Serializers;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down Expand Up @@ -114,4 +115,8 @@ public void UpdateSocialringInfo(String newSocialringName, String newSocialringI
this.exercise = exercise;

}

public void setStatus(BaseStatus status) {
this.status = status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.example.likelion12.domain.Member;
import com.example.likelion12.domain.base.BaseStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;
Expand All @@ -13,4 +15,9 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByEmailAndStatus(String email, BaseStatus status);
Optional<Member> findByMemberIdAndStatus(Long memberId, BaseStatus status);
boolean existsByEmailAndStatus(String email, BaseStatus status);

@Modifying
@Query("Delete From Member m Where m.memberId = :memberId")
void deleteByMemberId(Long memberId);

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.example.likelion12.repository;

import com.example.likelion12.domain.Facility;
import com.example.likelion12.domain.Member;
import com.example.likelion12.domain.Review;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -17,4 +22,15 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {

// 리뷰 삭제
void deleteById(Long reviewId);

// 리뷰 수정 -> 기본적인 CRUD외에는 내가 직접 구현해야함 -> 쿼리로 수정하는 방식 선택
@Modifying
@Query("UPDATE Review r SET r.ranking = :ranking, r.comment = :comment, r.facility = :facility WHERE r.id = :reviewId")
void updateReview(@Param("reviewId") Long reviewId,
@Param("ranking") int ranking,
@Param("comment") String comment,
@Param("facility") Facility facility);

// 중복 검사
boolean existsByMemberAndFacility(Member member, Facility facility);
}
Loading

0 comments on commit b11c161

Please sign in to comment.