secont commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.homme.demo.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.homme.demo.dto.DocumentRawCleanDto;
|
||||
import com.homme.demo.entity.Document;
|
||||
import com.homme.demo.input.DocumentInput;
|
||||
import com.homme.demo.repository.DocumentRepository;
|
||||
|
||||
@Service
|
||||
public class DocumentService {
|
||||
|
||||
@Autowired
|
||||
private DocumentRepository documentRepository;
|
||||
|
||||
|
||||
public Document saveDocument(DocumentInput documentInput) {
|
||||
|
||||
String fileName = documentInput.getFileName();
|
||||
String sourceUrl = documentInput.getSourceUrl();
|
||||
String rawText = documentInput.getRawText();
|
||||
String cleanText = documentInput.getCleanText();
|
||||
LocalDate createdAt = documentInput.getCreatedAt();
|
||||
Document document = Document.builder()
|
||||
.fileName(fileName)
|
||||
.sourceUrl(sourceUrl)
|
||||
.rawText(rawText)
|
||||
.cleanText(cleanText)
|
||||
.createdAt(createdAt)
|
||||
.build();
|
||||
return documentRepository.save(document);
|
||||
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getDocumentRawClean(int id){
|
||||
|
||||
Optional<Document> documentOpt = documentRepository.findById(id);
|
||||
if(documentOpt.isEmpty()) {
|
||||
|
||||
return new ResponseEntity<>("Das Document wurde in die Datenbank nicht gefunden", HttpStatus.NOT_FOUND);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Document documentObj = documentOpt.get();
|
||||
String rawText = documentObj.getRawText();
|
||||
String cleanText = documentObj.getCleanText();
|
||||
System.out.println("rawText = "+rawText);
|
||||
System.out.println("documentObj = "+documentObj.getSourceUrl());
|
||||
|
||||
|
||||
DocumentRawCleanDto documentRawCleanDto = DocumentRawCleanDto.builder()
|
||||
.rawText(rawText)
|
||||
.cleanText(cleanText)
|
||||
.build();
|
||||
return new ResponseEntity<>(documentRawCleanDto, HttpStatus.OK);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user