Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -61,7 +61,14 @@ public void saveHighlights(HighlightRequest request, UUID memberId) {
/*
* 2. 하이라이트 엔티티 생성
*/
List<HighlightEntity> entities=factory.createHighlightEntities(request.getHighlightUrls(),request.getHighlightIdentifier(),member,backNumber,request.getCreatedAt());
List<HighlightEntity> entities=factory.createHighlightEntities(
request.getHighlightUrls(),
request.getHighlightIdentifier(),
member,
backNumber,
request.getCreatedAt(),
request.getJobId()
);

/*
3. DB 저장
Expand Down Expand Up @@ -114,4 +121,12 @@ public HighlightCalendarResponse fetchCalendar(int year, int month,UUID memberId

return new HighlightCalendarResponse(year,month,daysResponses);
}

public List<HighlightInfoResponse> fetchLatestCreatedHighlights(UUID jobId,UUID memberId){
List<HighlightEntity> highlightList=highlightHelper.fetchLastestCreatedHighlights(jobId,memberId);

return highlightList.stream()
.map(mapper::infoResponseToEntity)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ public ResponseEntity<ApiResponse<HighlightCalendarResponse>> fetchCalendar(
UUID memberId=SecurityUtils.getCurrentMemberId();
return ResponseEntity.ok(ApiResponse.ok(manager.fetchCalendar(year,month,memberId)));
}

@GetMapping("/latest")
public ResponseEntity<ApiResponse<List<HighlightInfoResponse>>> latestCreatedHighlights(
@RequestParam(value = "jobId") UUID jobId
){
UUID memberId=SecurityUtils.getCurrentMemberId();
return ResponseEntity.ok(ApiResponse.ok(manager.fetchLatestCreatedHighlights(jobId,memberId)));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.midas.shootpointer.domain.highlight.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -27,4 +28,6 @@ public class HighlightRequest {
@NotBlank(message = "하이라이트 생성 날짜는 필수입니다.")
private LocalDateTime createdAt;

@NotNull(message = "하이라이트 JobId는 필수입니다.")
private UUID jobId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.midas.shootpointer.domain.member.entity.Member;
import com.midas.shootpointer.global.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.UuidGenerator;

Expand Down Expand Up @@ -53,6 +50,9 @@ public class HighlightEntity extends BaseEntity {
@Column(name = "video_created_at")
private LocalDateTime videoCreatedAt;

@Column(name = "job_id",columnDefinition = "uuid")
private UUID jobId;

/*
=========== [ 도메인-행위 ] ==============
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public DateTimeRange getMonthDateTimeRange(int year, int month) {
return highlightUtil.getMonthDateTimeRange(year,month);
}

@Override
public List<HighlightEntity> fetchLastestCreatedHighlights(UUID jobId, UUID memberId) {
return highlightUtil.fetchLastestCreatedHighlights(jobId,memberId);
}

@Override
public boolean filesExist(String directory) {
return highlightValidator.filesExist(directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public interface HighlightUtil {
TreeMap<LocalDate,List<HighlightInfoResponse>> groupingHighlights(List<HighlightInfoResponse> flatHighlightList);
List<HighlightInfoResponse> fetchFlatHighlightList(int year,int month,UUID memberId);
DateTimeRange getMonthDateTimeRange(int year, int month);
List<HighlightEntity> fetchLastestCreatedHighlights(UUID jobId,UUID memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,10 @@ public DateTimeRange getMonthDateTimeRange(int year, int month) {
return new DateTimeRange(start,end);
}

@Override
public List<HighlightEntity> fetchLastestCreatedHighlights(UUID jobId, UUID memberId) {
return highlightQueryRepository.fetchHighlightsByJobId(jobId,memberId);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public List<HighlightEntity> createHighlightEntities(List<HighlightInfo> highlig
UUID key,
Member member,
BackNumberEntity backNumber,
LocalDateTime createAt
LocalDateTime createAt,
UUID jobId
){
return highlightInfos.stream()
.map(info -> HighlightEntity.builder()
Expand All @@ -32,6 +33,7 @@ public List<HighlightEntity> createHighlightEntities(List<HighlightInfo> highlig
.threePointCount(info.threePointCount())
.backNumber(backNumber)
.videoCreatedAt(createAt)
.jobId(jobId)
.build())
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.midas.shootpointer.domain.highlight.repository;

import com.midas.shootpointer.domain.highlight.dto.HighlightCalendarDaysResponse;
import com.midas.shootpointer.domain.highlight.dto.HighlightInfoResponse;
import com.midas.shootpointer.domain.highlight.dto.PeriodHighlightResponse;
import com.midas.shootpointer.domain.highlight.entity.HighlightEntity;
Expand All @@ -26,9 +25,12 @@ public interface HighlightQueryRepository extends JpaRepository<HighlightEntity,
boolean isMembersHighlight(@Param("memberId") UUID memberId, @Param("highlightId") UUID highlightId);


@Query(value = "SELECT EXISTS(SELECT * FROM member AS M left join highlight AS H " +
"WHERE M.member_id=:memberId " +
"AND H.highlight_id=:highlightId ) ", nativeQuery = true)
@Query(value = """
SELECT EXISTS(
SELECT 1 FROM highlight
WHERE highlight_id = :highlightId
AND member_id = :memberId
)""", nativeQuery = true)
boolean existsByHighlightIdAndMember(@Param("highlightId") UUID highlightId, @Param("memberId") UUID memberId);

boolean existsByHighlightId(UUID highlightId);
Expand Down Expand Up @@ -102,6 +104,18 @@ public interface HighlightQueryRepository extends JpaRepository<HighlightEntity,
h.videoCreatedAt ASC
""" )
List<HighlightInfoResponse> fetchFlatHighlights(LocalDateTime startDate,LocalDateTime endDate,UUID memberId);


@Query(value = """
SELECT *
FROM
highlight AS h
INNER JOIN
member AS m ON h.member_id = :memberId
WHERE
h.job_id = :jobId
""",nativeQuery = true)
List<HighlightEntity> fetchHighlightsByJobId(UUID jobId,UUID memberId);
/**
* ===========================
* <p>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.midas.shootpointer.domain.progress.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.midas.shootpointer.domain.progress.ProgressType;
import com.mongodb.lang.Nullable;
import jakarta.validation.constraints.NotNull;

Expand All @@ -13,10 +14,18 @@ public record ProgressRedisResponse(

@NotNull boolean success,

@Nullable ProgressData data,
@NotNull long timeStamp,

@NotNull String message,
@NotNull ProgressType type,

@NotNull long timeStamp
@NotNull String jobId,

@NotNull String memberId,
/*=====================================
* 원본 전송 / 하이라이트 생성 중 활성화
=======================================*/

//진행률
@Nullable double progress
) {
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.midas.shootpointer.infrastructure.redis.helper;

import com.midas.shootpointer.domain.progress.dto.ProgressData;
import com.midas.shootpointer.domain.progress.ProgressType;
import com.midas.shootpointer.domain.progress.dto.ProgressRedisResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

Expand All @@ -10,26 +10,14 @@
@Component
@Slf4j
public class ProgressValidator {
public void validate(ProgressData data){
ProgressType type=data.type();
public void validate(ProgressRedisResponse response){
ProgressType type=response.type();

switch (type){
case UPLOADING -> {
requireNotNull(data.progress(), "progress");
requireNotNull(data.totalBytes(),"totalBytes");
requireNotNull(data.receivedBytes(),"receivedBytes");
}
case UPLOAD_COMPLETE -> {
requireNotNull(data.sizeBytes(),"sizeBytes");
requireNotNull(data.checksum(),"checkSum");
requireNotNull(data.durationSec(),"durationSec");
}
case PROCESSING -> {
requireNotNull(data.stage(),"stage");
requireNotNull(data.currentClip(),"currentClip");
requireNotNull(data.totalClips(),"totalClips");
}

case UPLOADING :
case PROCESSING:
requireNotNull(response.progress(), "progress");
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.midas.shootpointer.domain.progress.dto.ProgressRedisResponse;
import com.midas.shootpointer.domain.progress.mapper.ProgressMapper;
import com.midas.shootpointer.domain.progress.service.ProgressSseEmitter;
import com.midas.shootpointer.infrastructure.redis.helper.ProgressValidator;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,7 +23,6 @@ public class ProgressSubscriber implements MessageListener {
private final ObjectMapper objectMapper;
private final ProgressValidator validator;
private final ProgressSseEmitter emitter;
private final ProgressMapper mapper;

@Override
public void onMessage(Message message, byte[] pattern) {
Expand All @@ -42,13 +40,13 @@ public void onMessage(Message message, byte[] pattern) {
ProgressRedisResponse progress=objectMapper.readValue(body,ProgressRedisResponse.class);

//null값인 경우
if (progress==null || progress.data()==null){
if (progress==null ){
log.error("[Redis SUB] progress data is null : time = {}", LocalDateTime.now());
return;
}

//채널의 jobId와 payload의 jobId 불일치 시 무시
String jobIdFromPayload = progress.data().jobId();
String jobIdFromPayload = progress.jobId();
if (jobIdFromChannel != null && !jobIdFromChannel.equals(jobIdFromPayload)) {
log.warn("[Redis SUB] JobId mismatch detected: channel={}, payload={}", jobIdFromChannel, jobIdFromPayload);
return;
Expand All @@ -64,16 +62,16 @@ public void onMessage(Message message, byte[] pattern) {
}

//SUB로 받은 값 null 검증
validator.validate(progress.data());
validator.validate(progress);

//SSE로 client에 전달
emitter.sendToClient(
progress.data().memberId(),
progress.memberId(),
jobIdFromChannel, //redis에서 구독한 jobId로 SSE 발행
mapper.progressDataToResponse(progress.data())
progress
);

log.info("[Redis SUB] progress info : jobId = {}",progress.data().jobId());
log.info("[Redis SUB] progress info : jobId = {}",progress.jobId());

}catch (Exception e){
log.error("[Redis SUB] failed to process message : {}",e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ void createHighlightEntities(){
.backNumber(BackNumber.of(10))
.build();
LocalDateTime now=LocalDateTime.now();
UUID jobId=UUID.randomUUID();

//when
List<HighlightEntity> result=factory.createHighlightEntities(highlightInfos,highlightKey,member,backNumber,now);
List<HighlightEntity> result=factory.createHighlightEntities(highlightInfos,highlightKey,member,backNumber,now,jobId);

//then

Expand Down