Skip to content

Commit

Permalink
[SPR-174] 숏츠 단일 조회
Browse files Browse the repository at this point in the history
* [SPR-174] feat: 숏츠 단일조회

* [SPR-174] import문 정리
  • Loading branch information
gourderased authored Feb 20, 2024
1 parent 584efb2 commit e6059ba
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ src/test/resources/application.yml

### keystore.p12 ###
src/main/resources/keystore.p12
src/test/resources/keystore.p12
src/main/resources/keystore-dev.p12
src/main/resources/keystore-prod.p12

src/test/resources/keystore.p12

### firebase ###
src/main/resources/firebase/
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public ResponseEntity<PageResponseDto<List<ShortsSimpleInfo>>> findPopularShorts
@CurrentUser User user, @RequestParam int page, @RequestParam int size,
@RequestParam(required = false) Long gymId, @RequestParam(required = false) Long sectorId,
@RequestParam(required = false) Long routeId) {
return ResponseEntity.ok(shortsService.findShortsPopular(user, gymId, sectorId, routeId, page, size));
return ResponseEntity.ok(
shortsService.findShortsPopular(user, gymId, sectorId, routeId, page, size));
}

@PatchMapping("/shorts/{shortsId}/viewCount")
Expand All @@ -81,8 +82,17 @@ public ResponseEntity<List<ShortsProfileSimpleInfo>> getShortsProfileList(
@PatchMapping("/shorts/isRead")
@Operation(summary = "숏츠 프로필바 초록불 OFF 처리")
@SwaggerApiError({ErrorStatus._EMPTY_FOLLOW_RELATIONSHIP})
public ResponseEntity<String> updateShortsIsRead(@CurrentUser User user, @RequestParam Long followingUserId){
public ResponseEntity<String> updateShortsIsRead(@CurrentUser User user,
@RequestParam Long followingUserId) {
shortsService.updateShortsIsRead(user, followingUserId);
return ResponseEntity.ok("초록불 OFF 완료");
}

@GetMapping("/shorts/{shortsId}")
@Operation(summary = "숏츠 단일 조회")
@SwaggerApiError({ErrorStatus._EMPTY_SHORTS, ErrorStatus._SHORTS_ACCESS_DENIED})
public ResponseEntity<ShortsSimpleInfo> findShorts(@CurrentUser User user,
@PathVariable Long shortsId) {
return ResponseEntity.ok(shortsService.findDetailShorts(user, shortsId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ public void uploadShorts(User user, MultipartFile video,
shortsRepository.save(shorts);

//팔로워 관계 isUploadShortsRecent update
List<FollowRelationship> followRelationshipList = followRelationshipRepository.findByFollowingId(shorts.getUser()
.getId());
for(FollowRelationship f : followRelationshipList){
List<FollowRelationship> followRelationshipList = followRelationshipRepository.findByFollowingId(
shorts.getUser()
.getId());
for (FollowRelationship f : followRelationshipList) {
f.updateUploadStatus(true);
}
}
Expand Down Expand Up @@ -242,7 +243,7 @@ public List<ShortsProfileSimpleInfo> getShortsProfileList(User user) {

Long gymId = null;
Boolean isGym = followRelationship.getFollowing() instanceof Manager;
if(isGym) {
if (isGym) {
gymId = ((Manager) followRelationship.getFollowing()).getClimbingGym().getId();
}

Expand All @@ -256,15 +257,15 @@ public List<ShortsProfileSimpleInfo> getShortsProfileList(User user) {

@Transactional
@Scheduled(fixedRate = 1000 * 60 * 60 * 24) //하루마다 시행
public void updateVideoStatus(){
public void updateVideoStatus() {

LocalDateTime threeDaysAgo = LocalDateTime.now().minusDays(3);
List<Shorts> shortsList = shortsRepository.findByCreatedAtBefore(threeDaysAgo);
for(Shorts shorts : shortsList) {
for (Shorts shorts : shortsList) {
List<FollowRelationship> followRelationship = followRelationshipRepository.findByFollowingId(
shorts.getUser().getId());

for(FollowRelationship relationship : followRelationship){
for (FollowRelationship relationship : followRelationship) {
relationship.updateUploadStatus(false);
}

Expand All @@ -274,9 +275,51 @@ public void updateVideoStatus(){
}

@Transactional
public void updateShortsIsRead(User currentUser, Long userId){
FollowRelationship followRelationship = followRelationshipRepository.findByFollowerIdAndFollowingId(currentUser.getId(), userId)
.orElseThrow(()-> new GeneralException(ErrorStatus._EMPTY_FOLLOW_RELATIONSHIP));
public void updateShortsIsRead(User currentUser, Long userId) {
FollowRelationship followRelationship = followRelationshipRepository.findByFollowerIdAndFollowingId(
currentUser.getId(), userId)
.orElseThrow(() -> new GeneralException(ErrorStatus._EMPTY_FOLLOW_RELATIONSHIP));
followRelationship.updateUploadStatus(false);
}

public ShortsSimpleInfo findDetailShorts(User user, Long shortsId) {

Shorts shorts = shortsRepository.findById(shortsId)
.orElseThrow(() -> new GeneralException(ErrorStatus._EMPTY_SHORTS));

// 현재 유저가 볼 수 있는지 확인
if (shorts.getShortsVisibility() == ShortsVisibility.FOLLOWERS_ONLY) {
if (followRelationshipRepository.existsByFollowerIdAndFollowingId(
user.getId(), shorts.getUser().getId())) {
throw new GeneralException(ErrorStatus._SHORTS_ACCESS_DENIED);
}
}

if (shorts.getShortsVisibility() == ShortsVisibility.PRIVATE) {
throw new GeneralException(ErrorStatus._SHORTS_ACCESS_DENIED);
}
DifficultyMapping difficultyMapping = null;
String gymDifficultyName = null;
String gymDifficultyColor = null;
String climeetDifficultyName = null;

if (shorts.getRoute() != null) {
difficultyMapping = difficultyMappingRepository.findByClimbingGymAndDifficulty(
shorts.getClimbingGym(),
shorts.getRoute().getDifficultyMapping().getDifficulty());

gymDifficultyName = difficultyMapping.getGymDifficultyName();
gymDifficultyColor = difficultyMapping.getGymDifficultyColor();
climeetDifficultyName = difficultyMapping.getClimeetDifficultyName();
}

// 쇼츠 상세 정보 생성 및 반환
return ShortsSimpleInfo.toDTO(
shorts.getId(),
shorts.getThumbnailImageUrl(),
shorts.getClimbingGym(),
findShorts(user, shorts.getId(), difficultyMapping), gymDifficultyName,
gymDifficultyColor, climeetDifficultyName, shorts.getUser() instanceof Manager);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public enum ErrorStatus implements BaseErrorCode {

//숏츠 관련
_EMPTY_SHORTS(HttpStatus.CONFLICT, "SHORTS_001", "존재하지 않는 쇼츠입니다."),
_SHORTS_ACCESS_DENIED(HttpStatus.UNAUTHORIZED, "SHORTS_002", "비공개 영상입니다."),

//암장 리뷰 관련
_RATING_OUT_OF_RANGE(HttpStatus.CONFLICT, "REVIEW_001", "rating의 범위가 올바르지 않습니다."),
Expand All @@ -92,9 +93,10 @@ public enum ErrorStatus implements BaseErrorCode {
//팔로우 관련
_EMPTY_FOLLOW_RELATIONSHIP(HttpStatus.NOT_FOUND, "FOLLOW_RELATION_001", "존재하지 않는 팔로우 관계입니다."),
_EXIST_FOLLOW_RELATIONSHIP(HttpStatus.CONFLICT, "FOLLOW_RELATION_002", "이미 존재하는 팔로우 관계입니다."),



//암장 회원가입 관련
_EMPTY_GYM_REGISTRATION(HttpStatus.CONFLICT, "GYM_REGISTRATION_001", "존재하지 안는 암장입니다."),
_EMPTY_GYM_REGISTRATION(HttpStatus.CONFLICT, "GYM_REGISTRATION_001", "존재하지 않는 암장입니다."),

//공지사항 관련
_BOARD_NOT_FOUND(HttpStatus.NOT_FOUND, "BOARD_001", "존재하지 않는 공지사항입니다.");
Expand Down

0 comments on commit e6059ba

Please sign in to comment.