-
Notifications
You must be signed in to change notification settings - Fork 3
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
c5956bc
commit ead04a2
Showing
15 changed files
with
215 additions
and
10 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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/SollutionChallenge/HighLight/File/FileRepository.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,6 @@ | ||
package com.SollutionChallenge.HighLight.File; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FileRepository extends JpaRepository<File, Long> { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/SollutionChallenge/HighLight/File/FullTextInfoDto.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,15 @@ | ||
package com.SollutionChallenge.HighLight.File; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class FullTextInfoDto { | ||
private String full_text; | ||
private String audio_url; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/SollutionChallenge/HighLight/File/GetPageResDto.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,16 @@ | ||
package com.SollutionChallenge.HighLight.File; | ||
|
||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class GetPageResDto { | ||
private Long page_id; | ||
private FullTextInfoDto full_text; | ||
private List<TextInfoDto> text; | ||
private List<ImageInfoDto> image; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/SollutionChallenge/HighLight/File/ImageInfoDto.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,14 @@ | ||
package com.SollutionChallenge.HighLight.File; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ImageInfoDto { | ||
private Long img_idx; | ||
private String img_url; | ||
private String audio_url; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/SollutionChallenge/HighLight/File/SendPageResDto.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,22 @@ | ||
package com.SollutionChallenge.HighLight.File; | ||
|
||
import lombok.*; | ||
|
||
import java.util.List; | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class SendPageResDto { | ||
private Long page_id; | ||
private String full_audio_url; | ||
private List<SendTextInfoDto> text; | ||
private List<ImageInfoDto> image; | ||
|
||
@Builder | ||
public SendPageResDto(Long page_id, String full_audio_url, List<SendTextInfoDto> text, List<ImageInfoDto> image) { | ||
this.page_id = page_id; | ||
this.full_audio_url = full_audio_url; | ||
this.text = text; | ||
this.image = image; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/SollutionChallenge/HighLight/File/SendTextInfoDto.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,14 @@ | ||
package com.SollutionChallenge.HighLight.File; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class SendTextInfoDto { | ||
private String audio_url; | ||
private int font_size; | ||
private String text_content; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/SollutionChallenge/HighLight/File/TextInfoDto.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,14 @@ | ||
package com.SollutionChallenge.HighLight.File; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class TextInfoDto { | ||
private String audio_url; | ||
private int font_size; | ||
private String text; // text_content | ||
} |
2 changes: 0 additions & 2 deletions
2
src/main/java/com/SollutionChallenge/HighLight/HighLightApplication.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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/SollutionChallenge/HighLight/Page/PageController.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 |
---|---|---|
@@ -1,4 +1,29 @@ | ||
package com.SollutionChallenge.HighLight.Page; | ||
|
||
import com.SollutionChallenge.HighLight.File.SendPageResDto; | ||
import com.SollutionChallenge.HighLight.auth.JwtTokenUtil; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import lombok.RequiredArgsConstructor; | ||
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.RequestHeader; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
import java.util.HashMap; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class PageController { | ||
private final PageService pageService; | ||
private final JwtTokenUtil jwtTokenUtil; | ||
@GetMapping("/files/{file_id}/page/{page_id}") | ||
public ResponseEntity<HashMap<String, SendPageResDto>> getPageContents(@RequestHeader("token") String jwtToken, @PathVariable Long file_id, @PathVariable Long page_id) throws JsonProcessingException { | ||
System.out.println("jwtToken: " + jwtToken); | ||
Long user_id = Long.valueOf(jwtTokenUtil.getUserIdFromToken(jwtToken)); | ||
HashMap<String, SendPageResDto> map = new HashMap<>(); | ||
map.put("data", pageService.getPageContents(user_id, file_id, page_id)); | ||
return ResponseEntity.ok(map); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/SollutionChallenge/HighLight/Page/PageService.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,77 @@ | ||
package com.SollutionChallenge.HighLight.Page; | ||
|
||
import com.SollutionChallenge.HighLight.File.*; | ||
import com.SollutionChallenge.HighLight.User.Entity.User; | ||
import com.SollutionChallenge.HighLight.User.UserRepository; | ||
import com.SollutionChallenge.HighLight.auth.JwtTokenUtil; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.cloud.storage.Blob; | ||
import com.google.cloud.storage.BlobId; | ||
import com.google.cloud.storage.Storage; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class PageService { | ||
private final FileRepository fileRepository; | ||
private final UserRepository userRepository; | ||
@Autowired | ||
private Storage storage; | ||
@Transactional | ||
public SendPageResDto getPageContents(Long userId, Long fileId, Long pageId) throws JsonProcessingException { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
// User user = userRepository.findById(1L).get(); // api 테스트용 파일생성 코드 - 유저 정보 임의로 가져옴 | ||
User user = userRepository.findById(userId).get(); | ||
System.out.println("userid: "+userId); | ||
// File testfile = File.createFile(1L, user, "StallingsOS8e-Chap04", "파일링크"); // api 테스트용 파일 생성 코드 | ||
// fileRepository.save(testfile); // api테스트용 파일 생성 코드 | ||
|
||
// 파일 repository에서 파일 찾기 | ||
Optional<File> wantedFile = fileRepository.findById(fileId); | ||
|
||
// GCS에서 해당하는 페이지 json 받아오기 | ||
if (wantedFile.isPresent()) { | ||
File target = wantedFile.get(); | ||
String fileName = target.getFileName(); | ||
// String downloadFileName = "userid/"+fileName+"_json_folder/"+pageId+"/"+fileName+"_"+pageId+".json"; // api 테스트용 파일 생성 코드 | ||
String downloadFileName = userId+"/"+fileName+"_json_folder/"+pageId+"/"+fileName+"_"+pageId+".json"; // 실제 코드 | ||
|
||
System.out.println("다운로드 경로: " + downloadFileName); | ||
BlobId blobId = BlobId.of("cloud_storage_leturn", downloadFileName); | ||
Blob blob = storage.get(blobId); | ||
byte[] content = blob.getContent(); | ||
String targetJson = new String(content, StandardCharsets.UTF_8); | ||
|
||
// 보내줄 형식 맞추어 다시 dto로 매핑하기 | ||
GetPageResDto pageResDto = objectMapper.readValue(targetJson, GetPageResDto.class); | ||
List<TextInfoDto> textInfoDto = pageResDto.getText(); | ||
List<SendTextInfoDto> sendTextInfoDto = new ArrayList<SendTextInfoDto>(); | ||
for (TextInfoDto textDto: textInfoDto) { | ||
SendTextInfoDto sendDto = new SendTextInfoDto(); | ||
sendDto.setText_content(textDto.getText()); | ||
sendDto.setFont_size(textDto.getFont_size()); | ||
sendDto.setAudio_url(textDto.getAudio_url()); | ||
sendTextInfoDto.add(sendDto); | ||
} | ||
return SendPageResDto.builder() | ||
.page_id(pageResDto.getPage_id()) | ||
.full_audio_url(pageResDto.getFull_text().getAudio_url()) | ||
.text(sendTextInfoDto) | ||
.image(pageResDto.getImage()) | ||
.build(); | ||
} | ||
else { | ||
return new SendPageResDto(); | ||
} | ||
} | ||
} |
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
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