forked from kakao-tech-campus-2nd-step3/Team29_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d75d7b
commit c4e726d
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
src/main/java/notai/sttTask/application/SttTaskQueryService.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,53 @@ | ||
package notai.sttTask.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import notai.document.domain.Document; | ||
import notai.document.domain.DocumentRepository; | ||
import notai.llm.domain.TaskStatus; | ||
import static notai.llm.domain.TaskStatus.*; | ||
import notai.member.domain.Member; | ||
import notai.member.domain.MemberRepository; | ||
import notai.stt.domain.Stt; | ||
import notai.stt.domain.SttRepository; | ||
import notai.sttTask.application.result.SttTaskOverallStatusResult; | ||
import notai.sttTask.domain.SttTask; | ||
import notai.sttTask.domain.SttTaskRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Service | ||
public class SttTaskQueryService { | ||
|
||
private final DocumentRepository documentRepository; | ||
private final MemberRepository memberRepository; | ||
private final SttTaskRepository sttTaskRepository; | ||
private final SttRepository sttRepository; | ||
|
||
public SttTaskOverallStatusResult fetchOverallStatus(Long memberId, Long documentId) { | ||
Document foundDocument = documentRepository.getById(documentId); | ||
Member member = memberRepository.getById(memberId); | ||
foundDocument.validateOwner(member); | ||
|
||
List<Stt> sttResults = sttRepository.findAllByDocumentId(documentId); | ||
|
||
if (sttResults.isEmpty()) { | ||
return SttTaskOverallStatusResult.of(documentId, NOT_REQUESTED, 0, 0); | ||
} | ||
List<TaskStatus> taskStatuses = | ||
sttTaskRepository.findAllBySttIn(sttResults).stream().map(SttTask::getStatus).toList(); | ||
|
||
|
||
int totalPages = taskStatuses.size(); | ||
int completedPages = Collections.frequency(taskStatuses, COMPLETED); | ||
|
||
if (totalPages == completedPages) { | ||
return SttTaskOverallStatusResult.of(documentId, COMPLETED, totalPages, completedPages); | ||
} | ||
return SttTaskOverallStatusResult.of(documentId, IN_PROGRESS, totalPages, completedPages); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/notai/sttTask/application/result/SttTaskOverallStatusResult.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 notai.sttTask.application.result; | ||
|
||
import notai.llm.domain.TaskStatus; | ||
|
||
public record SttTaskOverallStatusResult( | ||
Long documentId, | ||
TaskStatus overallStatus, | ||
int totalPages, | ||
int completedPages | ||
) { | ||
public static SttTaskOverallStatusResult of( | ||
Long documentId, | ||
TaskStatus taskStatus, | ||
int totalPages, | ||
int completedPages | ||
) { | ||
return new SttTaskOverallStatusResult(documentId, taskStatus, totalPages, completedPages); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/notai/sttTask/presentation/SttTaskController.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,26 @@ | ||
package notai.sttTask.presentation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import notai.auth.Auth; | ||
import notai.sttTask.application.SttTaskQueryService; | ||
import notai.sttTask.application.result.SttTaskOverallStatusResult; | ||
import notai.sttTask.presentation.response.SttTaskOverallStatusResponse; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class SttTaskController { | ||
|
||
private final SttTaskQueryService sttTaskQueryService; | ||
|
||
@GetMapping("/status/{documentId}") | ||
public ResponseEntity<SttTaskOverallStatusResponse> fetchOverallStatus( | ||
@Auth Long memberId, @PathVariable("documentId") Long documentId | ||
) { | ||
SttTaskOverallStatusResult result = sttTaskQueryService.fetchOverallStatus(memberId, documentId); | ||
return ResponseEntity.ok(SttTaskOverallStatusResponse.from(result)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/notai/sttTask/presentation/response/SttTaskOverallStatusResponse.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,20 @@ | ||
package notai.sttTask.presentation.response; | ||
|
||
import notai.llm.domain.TaskStatus; | ||
import notai.sttTask.application.result.SttTaskOverallStatusResult; | ||
|
||
public record SttTaskOverallStatusResponse( | ||
Long documentId, | ||
TaskStatus overallStatus, | ||
Integer totalPages, | ||
Integer completedPages | ||
) { | ||
public static SttTaskOverallStatusResponse from(SttTaskOverallStatusResult result) { | ||
return new SttTaskOverallStatusResponse( | ||
result.documentId(), | ||
result.overallStatus(), | ||
result.totalPages(), | ||
result.completedPages() | ||
); | ||
} | ||
} |