Skip to content

Commit

Permalink
[SPR-128] 쇼츠 프로필 초록불 관련 작업
Browse files Browse the repository at this point in the history
* [SPR-128] feat: 숏츠 초록불 업데이트 스케줄링 함수 구현

* [SPR-128] feat: 스케줄링 함수 반복 시간 수정

* [SPR-128] feat: Follower->following으로 변경

* [SPR-128] fix: 테스트용 출력문 제거

* [SPR-126] Feat: updateUploadStatus 함수 추가
  • Loading branch information
yerim216 authored Feb 14, 2024
1 parent d3affca commit a62d78a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableJpaAuditing
@EnableScheduling
public class ClimeetBackendApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.transaction.Transactional;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -40,7 +41,13 @@ public static FollowRelationship toEntity(User follower, User following){
return FollowRelationship.builder()
.follower(follower)
.following(following)
.isUploadShortsRecent(false)
.build();
}

@Transactional
public void updateUploadStatus(boolean status){
this.isUploadShortsRecent = status;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.climeet.climeet_backend.domain.shorts;

import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
Expand Down Expand Up @@ -49,4 +50,6 @@ public interface ShortsRepository extends JpaRepository<Shorts, Long> {
Slice<Shorts> findAllByShortsVisibilityInAndRouteIdOrderByCreatedAtDesc(List<ShortsVisibility> shortsVisibilities, Long routeId, Pageable pageable);


List<Shorts> findByCreatedAtBefore(LocalDateTime dateTime);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.climeet.climeet_backend.domain.shorts;

import static java.util.stream.Collectors.toList;

import com.climeet.climeet_backend.domain.climbinggym.ClimbingGym;
import com.climeet.climeet_backend.domain.climbinggym.ClimbingGymRepository;
import com.climeet.climeet_backend.domain.difficultymapping.DifficultyMapping;
Expand All @@ -24,16 +26,22 @@
import com.climeet.climeet_backend.global.response.exception.GeneralException;
import com.climeet.climeet_backend.global.s3.S3Service;
import jakarta.transaction.Transactional;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@RequiredArgsConstructor
@Service
@Slf4j
public class ShortsService {

private final ShortsRepository shortsRepository;
Expand Down Expand Up @@ -74,6 +82,13 @@ public void uploadShorts(User user, MultipartFile video,
createShortsRequest);

shortsRepository.save(shorts);

//팔로워 관계 isUploadShortsRecent update
List<FollowRelationship> followRelationshipList = followRelationshipRepository.findByFollowingId(shorts.getUser()
.getId());
for(FollowRelationship f : followRelationshipList){
f.updateUploadStatus(true);
}
}

public PageResponseDto<List<ShortsSimpleInfo>> findShortsLatest(User user, Long gymId,
Expand Down Expand Up @@ -235,4 +250,24 @@ public List<ShortsProfileSimpleInfo> getShortsProfileList(User user) {

return shortsProfileSimpleInfos;
}


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

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

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

}


}
}

0 comments on commit a62d78a

Please sign in to comment.