-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from Likelion12/11-be-소셜링-등록
Feat : 소셜링 등록
- Loading branch information
Showing
11 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/likelion12/common/exception/SocialringException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SocialringException extends RuntimeException{ | ||
private final ResponseStatus exceptionStatus; | ||
|
||
public SocialringException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
|
||
public SocialringException(ResponseStatus exceptionStatus, String message) { | ||
super(message); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../com/example/likelion12/common/exception_handler/SocialringExceptionControllerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.SocialringException; | ||
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 SocialringExceptionControllerAdvice { | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(SocialringException.class) | ||
public BaseErrorResponse handle_SocialringException(SocialringException e) { | ||
log.error("[handle_SocialringException]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/likelion12/controller/SocialringController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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.service.SocialringService; | ||
import com.example.likelion12.util.JwtProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/socialring") | ||
|
||
public class SocialringController { | ||
|
||
private final SocialringService socialringService; | ||
private final JwtProvider jwtProvider; | ||
|
||
@PostMapping("") | ||
public BaseResponse<PostSocialringResponse> createSocialring(@RequestHeader("Authorization") String authorization , @RequestBody PostSocialringRequest postSocialringRequest) | ||
{ //헤더에서 소셜링 등록하는 멤버아이디 찾기 | ||
Long memberId = jwtProvider.extractIdFromHeader(authorization); | ||
return new BaseResponse<>(socialringService.createSocialring(memberId,postSocialringRequest)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/likelion12/dto/PostSocialringRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.likelion12.dto; | ||
|
||
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 PostSocialringRequest { | ||
private String socialringName; | ||
private String socialringImg; | ||
private long activityRegionId; | ||
private long facilityId; | ||
private long exerciseId; | ||
private int totalRecruits; | ||
private LocalDate socialringDate; | ||
private int socialringCost; | ||
private String comment; | ||
private String commentSimple; | ||
private BaseGender gender; | ||
private BaseLevel level; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/likelion12/dto/PostSocialringResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.likelion12.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PostSocialringResponse { | ||
private long socialringId; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/likelion12/repository/MemberSocialringRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.likelion12.repository; | ||
|
||
import com.example.likelion12.domain.MemberSocialring; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberSocialringRepository extends JpaRepository<MemberSocialring, Long> { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/likelion12/repository/SocialringRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.likelion12.repository; | ||
|
||
|
||
import com.example.likelion12.domain.Socialring; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SocialringRepository extends JpaRepository<Socialring, Long> { | ||
//Optional<Socialring> findBySocialringIdAndStatus(Long socialringId, BaseStatus status); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/likelion12/service/MemberSocialringService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.likelion12.service; | ||
|
||
import com.example.likelion12.domain.*; | ||
import com.example.likelion12.domain.base.BaseRole; | ||
import com.example.likelion12.domain.base.BaseStatus; | ||
import com.example.likelion12.repository.MemberSocialringRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MemberSocialringService { | ||
|
||
private final MemberSocialringRepository memberSocialringRepository; | ||
|
||
/** | ||
* 소셜링 등록 시 소셜링 만든 사람이 CAPTAIN 이 되도록 | ||
*/ | ||
@Transactional | ||
public void createMemberSocialring(Member member, Socialring socialring){ | ||
log.info("[MemberSocialringService.createMemberSocialring]"); | ||
MemberSocialring memberSocialring = new MemberSocialring(BaseRole.CAPTAIN,socialring,member,BaseStatus.ACTIVE); | ||
memberSocialringRepository.save(memberSocialring); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/example/likelion12/service/SocialringService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.example.likelion12.service; | ||
|
||
import com.example.likelion12.common.exception.ActivityRegionException; | ||
import com.example.likelion12.common.exception.ExerciseException; | ||
import com.example.likelion12.common.exception.FacilityException; | ||
import com.example.likelion12.common.exception.MemberException; | ||
import com.example.likelion12.domain.*; | ||
import com.example.likelion12.domain.base.BaseGender; | ||
import com.example.likelion12.domain.base.BaseLevel; | ||
import com.example.likelion12.domain.base.BaseStatus; | ||
import com.example.likelion12.dto.PostSocialringRequest; | ||
import com.example.likelion12.dto.PostSocialringResponse; | ||
import com.example.likelion12.repository.*; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.*; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SocialringService { | ||
private final SocialringRepository socialringRepository; | ||
private final MemberRepository memberRepository; | ||
private final FacilityRepository facilityRepository; | ||
private final ExerciseRepository exerciseRepository; | ||
private final MemberSocialringService memberSocialringService; | ||
private final ActivityRegionRepository activityRegionRepository; | ||
|
||
//소셜링등록 | ||
@Transactional | ||
public PostSocialringResponse createSocialring(Long memberId, PostSocialringRequest postSocialringRequest) { | ||
log.info("[SocialringService.createSocialring]"); | ||
Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) | ||
.orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER)); | ||
|
||
String socialringName = postSocialringRequest.getSocialringName(); | ||
String socialringImg = postSocialringRequest.getSocialringImg(); | ||
long activityRegionId = postSocialringRequest.getActivityRegionId(); | ||
long facilityId = postSocialringRequest.getFacilityId(); | ||
long exerciseId = postSocialringRequest.getExerciseId(); | ||
int totalRecruits = postSocialringRequest.getTotalRecruits(); | ||
LocalDate socialringDate = postSocialringRequest.getSocialringDate(); | ||
int socialringCost = postSocialringRequest.getSocialringCost(); | ||
String comment = postSocialringRequest.getComment(); | ||
String commentSimple = postSocialringRequest.getCommentSimple(); | ||
BaseGender gender = postSocialringRequest.getGender(); | ||
BaseLevel level = postSocialringRequest.getLevel(); | ||
|
||
ActivityRegion activityRegion = activityRegionRepository.findByActivityRegionIdAndStatus(activityRegionId, BaseStatus.ACTIVE) | ||
.orElseThrow(()-> new ActivityRegionException(CANNOT_FOUND_ACTIVITYREGION)); | ||
Facility facility = facilityRepository.findByFacilityIdAndStatus(facilityId, BaseStatus.ACTIVE) | ||
.orElseThrow(()-> new FacilityException(CANOOT_FOUND_FACILITY)); | ||
Exercise exercise = exerciseRepository.findByExerciseIdAndStatus(exerciseId,BaseStatus.ACTIVE) | ||
.orElseThrow(()-> new ExerciseException(CANNOT_FOUND_EXERCISE)); | ||
|
||
Socialring socialring = new Socialring(socialringName,socialringImg,totalRecruits,socialringDate,socialringCost,comment,commentSimple, | ||
gender,level,activityRegion,facility, exercise, BaseStatus.ACTIVE); | ||
socialringRepository.save(socialring); | ||
|
||
//소셜링을 만든 사람이 CAPTAIN 이 되도록 | ||
memberSocialringService.createMemberSocialring(member,socialring); | ||
return new PostSocialringResponse(socialring.getSocialringId()); | ||
} | ||
} |