Skip to content

Commit

Permalink
feat: BRF File 반환 API 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
gitchannn committed Feb 27, 2024
1 parent 360ffd8 commit 1a10fca
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import sunflower.server.api.response.BrfFileQueryResponse;
import sunflower.server.api.response.TranslationStatusResponse;
import sunflower.server.application.TranslationService;
import sunflower.server.application.dto.TranslationStatusDto;
Expand Down Expand Up @@ -43,8 +44,10 @@ public ResponseEntity<TranslationStatusResponse> checkStatus(@PathVariable("id")
}

@GetMapping("/{id}")
public ResponseEntity<Void> downloadBrfFile(@PathVariable("id") Long id) {
return null;
public ResponseEntity<BrfFileQueryResponse> queryBrfFile(@PathVariable("id") Long id) {
final String brfContent = translationService.findBrfFileById(id);
final BrfFileQueryResponse response = BrfFileQueryResponse.from(id, brfContent);
return ResponseEntity.ok(response);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sunflower.server.api.response;

import lombok.Getter;

@Getter
public class BrfFileQueryResponse {

private final Long id;
private final String content;

public BrfFileQueryResponse(final Long id, final String content) {
this.id = id;
this.content = content;
}

public static BrfFileQueryResponse from(final Long id, final String brfContent) {
return new BrfFileQueryResponse(id, brfContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import sunflower.server.repository.TranslationsRepository;
import sunflower.server.util.FileUtil;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.UUID;

@Slf4j
Expand Down Expand Up @@ -42,4 +46,16 @@ public Long register(final MultipartFile file) {
public TranslationStatusDto status(final Long id) {
return TranslationStatusDto.from(translationsRepository.getById(id));
}

public String findBrfFileById(final Long id) {
final Translations translations = translationsRepository.getById(id);
final String brfPath = translations.getBrfPath();
final File file = Paths.get(brfPath).toFile();

try {
return new String(Files.readAllBytes(Paths.get(file.getPath())));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void registerOcr(final OcrRegisterEvent event) {

final Long id = event.getTranslations().getId();
final Translations translations = translationsRepository.getById(id);
final String pdfURI = translations.getPdfPath();
final File file = Paths.get(pdfURI).toFile();
final String pdfPath = translations.getPdfPath();
final File file = Paths.get(pdfPath).toFile();

translations.startOcr();
final String pdfId = ocrRegisterClient.requestPdfId(file);
Expand Down

0 comments on commit 1a10fca

Please sign in to comment.