Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : 소셜링 수정 #44

Merged
merged 22 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5804a39
feat : 소셜링 수정 dto 작성
hd0rable Aug 1, 2024
f93dcf4
feat : CAPTAIN이 아닌 member 들어왔을때 BaseExceptionResponseStatus 작성
hd0rable Aug 1, 2024
3f4ceb8
feat : socialring 관련 BaseExceptionResponseStatus 작성
hd0rable Aug 1, 2024
7cf6b7d
feat : membersocialring 관련 BaseExceptionResponseStatus 작성
hd0rable Aug 1, 2024
eb891a7
feat : membersocialring 예외 작성
hd0rable Aug 1, 2024
b5daf27
feat : membersocialringRepository 작성
hd0rable Aug 1, 2024
440fac8
feat : Socialring Setter 추가
hd0rable Aug 1, 2024
1385a19
feat : SocialringRepository 작성
hd0rable Aug 1, 2024
a09633d
feat : MemberSocialringService의ConfirmCaptainMemberSocialring 작성
hd0rable Aug 1, 2024
508d3b3
feat : PatchSocialringModifyRequest ado 작성
hd0rable Aug 1, 2024
763b0b9
feat : SocialringController.modifySocialring 작성
hd0rable Aug 1, 2024
c2ff0fa
feat : 소셜링 수정 구현
hd0rable Aug 1, 2024
9c48265
refator : 안쓰는 import 삭제
hd0rable Aug 1, 2024
5a58207
feat : respond 추가
hd0rable Aug 1, 2024
c943065
feat : UpdateSocialringInfo 작성
hd0rable Aug 1, 2024
1ecfa79
fix : 소셜링 수정 부분 수정
hd0rable Aug 1, 2024
78e971f
Merge branch 'develop' into 13-be-소셜링-수정
jsilver01 Aug 2, 2024
21c75fd
refator : 주석 추가
hd0rable Aug 2, 2024
5de88fe
feat : 레포지토리에서 name으로 찾는 find 작성
hd0rable Aug 2, 2024
8d1e887
fix : 리다이렉트 url 수정
hd0rable Aug 2, 2024
2ce4cd6
fix : activityRegion,facility,exercise id값이아닌 name값으로 변경
hd0rable Aug 2, 2024
981c31d
Merge branch 'develop' into 13-be-소셜링-수정
jsilver01 Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 MemberSocialringException extends RuntimeException{
private final ResponseStatus exceptionStatus;

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

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

import com.example.likelion12.common.exception.MemberSocialringException;
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 MemberSocialringExceptionControllerAdvice {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MemberSocialringException.class)
public BaseErrorResponse handle_MemberSocialringException(MemberSocialringException e) {
log.error("[handle_MemberSocialringException]", e);
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,32 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{
ALREADY_EXIST_EMAIL(6001, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 이메일입니다."),

/**
* 7000 : crew 관련
* 7000: socialring 관련
*/
CANNOT_FOUND_CREW_LIST(7000, HttpStatus.BAD_REQUEST.value(), "크루 리스트를 찾을 수 없습니다."),
CANNOT_FOUND_CREW(7001, HttpStatus.BAD_REQUEST.value(), "크루를 찾을 수 없습니다."),
ALREADY_FULL_CREW(7002, HttpStatus.BAD_REQUEST.value(), "더이상 크루에 참여하실 수 없습니다."),
CANNOT_FOUND_SOCIALRING(7000, HttpStatus.BAD_REQUEST.value(), "소셜링을 찾을 수 없습니다."),


/**
* 8000 : Member crew 관련
* 8000: membersocialring 관련
*/
CANNOT_FOUND_MEMBERCREW(8000, HttpStatus.BAD_REQUEST.value(), "멤버_크루를 찾을 수 없습니다."),
CANNOT_FOUND_MEMBERCREW_LIST(8001, HttpStatus.BAD_REQUEST.value(), "멤버_크루 리스트를 찾을 수 없습니다."),
ALREADY_EXIST(8002, HttpStatus.BAD_REQUEST.value(), "이미 등록된 멤버입니다.");
CANNOT_FOUND_MEMBERSOCIALRING(8000, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링을 찾을 수 없습니다."),
CANNOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."),

/**
* 9000 : crew 관련
*/
CANNOT_FOUND_CREW_LIST(9000, HttpStatus.BAD_REQUEST.value(), "크루 리스트를 찾을 수 없습니다."),
CANNOT_FOUND_CREW(9001, HttpStatus.BAD_REQUEST.value(), "크루를 찾을 수 없습니다."),
ALREADY_FULL_CREW(9002, HttpStatus.BAD_REQUEST.value(), "더이상 크루에 참여하실 수 없습니다."),


/**
* 10000 : Member crew 관련
*/
CANNOT_FOUND_MEMBERCREW(10000, HttpStatus.BAD_REQUEST.value(), "멤버_크루를 찾을 수 없습니다."),
CANNOT_FOUND_MEMBERCREW_LIST(10001, HttpStatus.BAD_REQUEST.value(), "멤버_크루 리스트를 찾을 수 없습니다."),
ALREADY_EXIST(10002, HttpStatus.BAD_REQUEST.value(), "이미 등록된 멤버입니다.");



private final int code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.example.likelion12.controller;

import com.example.likelion12.common.response.BaseResponse;
import com.example.likelion12.dto.PostSocialringRequest;
import com.example.likelion12.dto.PostSocialringResponse;
import com.example.likelion12.common.response.status.BaseExceptionResponseStatus;
import com.example.likelion12.dto.socialring.PatchSocialringModifyRequest;
import com.example.likelion12.dto.socialring.PostSocialringRequest;
import com.example.likelion12.dto.socialring.PostSocialringResponse;
import com.example.likelion12.service.SocialringService;
import com.example.likelion12.util.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Slf4j
Expand All @@ -19,10 +22,27 @@ public class SocialringController {
private final SocialringService socialringService;
private final JwtProvider jwtProvider;

/**
* 소셜링 등록
*/
@PostMapping("")
public BaseResponse<PostSocialringResponse> createSocialring(@RequestHeader("Authorization") String authorization , @RequestBody PostSocialringRequest postSocialringRequest)
public BaseResponse<PostSocialringResponse> createSocialring(@RequestHeader("Authorization") String authorization ,
@RequestBody PostSocialringRequest postSocialringRequest)
{ //헤더에서 소셜링 등록하는 멤버아이디 찾기
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(socialringService.createSocialring(memberId,postSocialringRequest));
}

/**
* 소셜링 수정
*/
@PatchMapping("")
public BaseResponse<Void> modifySocialring(@RequestHeader("Authorization") String authorization, @RequestParam long socialringId,
@RequestBody PatchSocialringModifyRequest patchSocialringModifyRequest)
{
Long memberId = jwtProvider.extractIdFromHeader(authorization);
socialringService.modifySocialring(memberId,socialringId,patchSocialringModifyRequest);
return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null);
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/example/likelion12/domain/Socialring.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static jakarta.persistence.FetchType.LAZY;

Expand Down Expand Up @@ -95,4 +96,22 @@ public Socialring(String socialringName, String socialringImg, int totalRecruits
this.exercise = exercise;
this.status = baseStatus;
}

public void UpdateSocialringInfo(String newSocialringName, String newSocialringImg, Integer newTotalRecruits, LocalDate newSocialringDate,
Integer newSocialringCost, String newComment, String newCommentSimple, BaseGender newGender,
BaseLevel newLevel, ActivityRegion activityRegion, Facility facility,Exercise exercise) {
this.socialringName = newSocialringName;
this.socialringImg = newSocialringImg;
this.totalRecruits = newTotalRecruits;
this.socialringDate = newSocialringDate;
this.socialringCost = newSocialringCost;
this.commentSimple = newCommentSimple;
this.comment = newComment;
this.gender = newGender;
this.level = newLevel;
this.activityRegion = activityRegion;
this.facility = facility;
this.exercise = exercise;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.likelion12.dto.socialring;

import com.example.likelion12.domain.base.BaseGender;
import com.example.likelion12.domain.base.BaseLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDate;

@Getter
@AllArgsConstructor
public class PatchSocialringModifyRequest {
/**
* 소셜링 수정 request dto
*/
private String socialringName;
private String socialringImg;
private String activityRegionName;
private String facilityName;
private String exerciseName;
private Integer totalRecruits;
private LocalDate socialringDate;
private Integer socialringCost;
private String comment;
private String commentSimple;
private BaseGender gender;
private BaseLevel level;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.likelion12.dto;
package com.example.likelion12.dto.socialring;

import com.example.likelion12.domain.base.BaseGender;
import com.example.likelion12.domain.base.BaseLevel;
Expand All @@ -10,6 +10,9 @@
@Getter
@AllArgsConstructor
public class PostSocialringRequest {
/**
* 소셜링 등록 request dto
*/
private String socialringName;
private String socialringImg;
private long activityRegionId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.example.likelion12.dto;
package com.example.likelion12.dto.socialring;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class PostSocialringResponse {
/**
* 소셜링 등록 response dto
*/
private long socialringId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
public interface ActivityRegionRepository extends JpaRepository<ActivityRegion, Long> {

Optional<ActivityRegion> findByActivityRegionIdAndStatus(Long activityRegionId, BaseStatus status);
Optional<ActivityRegion> findByActivityRegionNameAndStatus(String activityRegionName, BaseStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
public interface FacilityRepository extends JpaRepository<Facility, Long> {

Optional<Facility> findByFacilityIdAndStatus(Long facilityId, BaseStatus status);
Optional<Facility> findByFacilityNameAndStatus(String facilityName, BaseStatus status);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.example.likelion12.repository;

import com.example.likelion12.domain.MemberSocialring;
import com.example.likelion12.domain.base.BaseStatus;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface MemberSocialringRepository extends JpaRepository<MemberSocialring, Long> {
//Optional<MemberSocialring> findByMemberIdAndSocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status);
Optional<MemberSocialring> findByMember_MemberIdAndSocialring_SocialringIdAndStatus(Long memberId, Long socialringId, BaseStatus status);
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.List;
import java.util.Optional;

import java.util.Optional;

public interface SocialringRepository extends JpaRepository<Socialring, Long> {

// 홈화면에 보여줄 4개를 마감기한 입박한 순으로 반환
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.likelion12.service;

import com.example.likelion12.common.exception.MemberSocialringException;
import com.example.likelion12.domain.*;
import com.example.likelion12.domain.base.BaseRole;
import com.example.likelion12.domain.base.BaseStatus;
Expand All @@ -9,6 +10,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_MEMBERSOCIALRING_CAPTAIN;

@Slf4j
@Service
@RequiredArgsConstructor
Expand All @@ -26,4 +29,16 @@ public void createMemberSocialring(Member member, Socialring socialring){
MemberSocialring memberSocialring = new MemberSocialring(BaseRole.CAPTAIN,socialring,member,BaseStatus.ACTIVE);
memberSocialringRepository.save(memberSocialring);
}

/**
* 소셜링 수정,삭제 시 접근하는 member가 CAPTAIN 인지 확인
*/
public void ConfirmCaptainMemberSocialring(MemberSocialring memberSocialring){
log.info("[MemberSocialringService.ConfirmCaptainMemberSocialring]");

if (!BaseRole.CAPTAIN.equals(memberSocialring.getRole())) {
throw new MemberSocialringException(CANNOT_MEMBERSOCIALRING_CAPTAIN);
}
}

}
Loading
Loading