Skip to content

Commit

Permalink
Merge pull request #44 from Likelion12/13-be-소셜링-수정
Browse files Browse the repository at this point in the history
Feat : 소셜링 수정
  • Loading branch information
jsilver01 authored Aug 2, 2024
2 parents 0f2b5f1 + 981c31d commit c504ace
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 28 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 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

0 comments on commit c504ace

Please sign in to comment.