Skip to content

Commit

Permalink
Merge pull request #74 from MemorAIzee/feature/#67-voice
Browse files Browse the repository at this point in the history
✨ FEAT. 메인 페이지 슬라이드 쇼 조회 API
  • Loading branch information
junhaa authored May 30, 2024
2 parents f704b1b + 4d41715 commit 3642105
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ public Photo savePhotoImages(MultipartFile image) {

photo.setPlace(place);
photo.setImageUrl(imageUrl);
for (PhotoHashTag hashTag : hashTagList) {
photo.addHashTag(hashTag);
}
} catch (Exception e) {
log.error("사진 저장 중 에러가 발생했습니다. {}", e.getMessage());
throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package memoraize.domain.slideshow.service;

import java.util.List;

import memoraize.domain.slideshow.web.dto.SlideShowResponseDTO;

public interface SlideShowQueryService {
String getMemoriesUrl(Long albumId);

List<SlideShowResponseDTO.SlideShowPreviewResponseDto> getSlideShowPreview();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package memoraize.domain.slideshow.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -9,6 +12,7 @@
import memoraize.domain.album.repository.AlbumPostRepository;
import memoraize.domain.slideshow.entity.Memories;
import memoraize.domain.slideshow.repository.MemoriesRepository;
import memoraize.domain.slideshow.web.dto.SlideShowResponseDTO;
import memoraize.global.cloudinary.CloudinaryService;

@Service
Expand All @@ -32,4 +36,24 @@ public String getMemoriesUrl(Long albumId) {
}
return memories.getUrl();
}

@Override
public List<SlideShowResponseDTO.SlideShowPreviewResponseDto> getSlideShowPreview() {
List<SlideShowResponseDTO.SlideShowPreviewResponseDto> result = new ArrayList<>();
for (Memories memories : memoriesRepository.findAll()) {
if (memories.getUrl() != null) {
SlideShowResponseDTO.SlideShowPreviewResponseDto dto = SlideShowResponseDTO.SlideShowPreviewResponseDto.builder()
.slideShowUrl(memories.getUrl())
.albumName(memories.getAlbum().getAlbumName())
.mainImageUrl(memories.getAlbum().getPhotoImages().get(0).getImageUrl())
.userName(memories.getAlbum().getUser().getUserName())
.build();

result.add(dto);
if (result.size() == 2)
break;
}
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package memoraize.domain.slideshow.web.controller;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.ResponseEntity;
Expand All @@ -13,6 +15,7 @@
import lombok.RequiredArgsConstructor;
import memoraize.domain.slideshow.service.SlideShowQueryService;
import memoraize.domain.slideshow.web.dto.SlideShowRequestDTO;
import memoraize.domain.slideshow.web.dto.SlideShowResponseDTO;
import memoraize.global.response.ApiResponse;

@RestController
Expand All @@ -33,4 +36,9 @@ public ApiResponse<String> getMemoriesUrl(@PathVariable(name = "albumId") Long a
String memoriesUrl = slideShowQueryService.getMemoriesUrl(albumId);
return ApiResponse.onSuccess(memoriesUrl);
}

@GetMapping()
public ApiResponse<List<SlideShowResponseDTO.SlideShowPreviewResponseDto>> getSlideShowPreview() {
return ApiResponse.onSuccess(slideShowQueryService.getSlideShowPreview());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package memoraize.domain.slideshow.web.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

public class SlideShowResponseDTO {
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class SlideShowPreviewResponseDto {
private String userName;
private String albumName;
private String slideShowUrl;
private String mainImageUrl;

}

}
151 changes: 133 additions & 18 deletions src/main/java/memoraize/global/cloudinary/CloudinaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public String createVideo(Long photoId) {
.addTextBody("resource_type", "video")
.addTextBody("upload_preset", uploadPreset)
.addTextBody("manifest_json", generateManifestJson(photo.getImageUrl(), colorCode, photo.getTitle(),
getHashTagString(hashTagList)))
hashTagList))
.build();

httpPost.setEntity(entity);
Expand All @@ -151,7 +151,8 @@ public String createVideo(Long photoId) {

int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
log.error("슬라이드 쇼 제작 API 요청에서 에러가 발생했습니다. errorcode = {}", statusCode);
log.error("슬라이드 쇼 제작 API 요청에서 에러가 발생했습니다. errorcode = {}",
response.getEntity().getContent().toString());
throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR);
}

Expand All @@ -166,13 +167,28 @@ public String getHashTagString(List<PhotoHashTag> hashTagList) {
String hashTagString = "";
for (PhotoHashTag hashTag : hashTagList) {
if (hashTag.getTagCategorie() == TagCategory.LABEL) {
hashTagString += "#" + hashTag.getTagName() + " ";
hashTagString += "#" + hashTag.getTagName() + "";
}
}
return hashTagString;
}

private String generateManifestJson(String imageUrl, String colorCode, String photoTitle, String hashTagString) {
private String generateManifestJson(String imageUrl, String colorCode, String photoTitle,
List<PhotoHashTag> hashTagList) {
ArrayList<String> hashTagString = new ArrayList<>();
for (PhotoHashTag hashTag : hashTagList) {
if (hashTag.getTagCategorie() != TagCategory.COLOR) {
hashTagString.add(hashTag.getTagName());
}
}

if (hashTagList.size() != 6) {
log.error("해쉬태그의 크기가 맞지 않습니다. size = {}", hashTagList.size());
throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR);
}

int fontSize = 26;

String manifest = "{\n"
+ " \"type\": \"video\",\n"
+ " \"width\": 1280,\n"
Expand All @@ -182,9 +198,12 @@ private String generateManifestJson(String imageUrl, String colorCode, String ph
+ " \"vars\": {\n"
+ " \"bgColor\": \"" + colorCode + "\",\n"
+ " \"imageUrl\": \"" + imageUrl + "\",\n"
+ " \"sponsoredText\": \"" + photoTitle + "\",\n"
+ " \"titleText\": \"" + hashTagString + "\",\n"
+ " \"ctaText\": \"Read more\"\n"
+ " \"sponsoredText\": \"" + colorCode + "\",\n"
+ " \"titleText1\": \"" + "# " + hashTagString.get(0) + "\",\n"
+ " \"titleText2\": \"" + "# " + hashTagString.get(1) + "\",\n"
+ " \"titleText3\": \"" + "# " + hashTagString.get(2) + "\",\n"
+ " \"titleText4\": \"" + "# " + hashTagString.get(3) + "\",\n"
+ " \"titleText5\": \"" + "# " + hashTagString.get(4) + "\"\n"
+ " },\n"
+ " \"tracks\": [\n"
+ " {\n"
Expand Down Expand Up @@ -226,23 +245,24 @@ private String generateManifestJson(String imageUrl, String colorCode, String ph
+ " ]\n"
+ " }, // track 2\n"
+ " {\n"
+ " \"x\": 950,\n"
+ " \"x\": 1150,\n"
+ " \"keyframes\": {\n"
+ " \"0\": {\n"
+ " \"y\": 290,\n"
+ " \"y\": 630,\n"
+ " \"opacity\": 0\n"
+ " },\n"
+ " \"1000\": {\n"
+ " \"y\": 290,\n"
+ " \"y\": 640,\n"
+ " \"opacity\": 0\n"
+ " },\n"
+ " \"2000\": {\n"
+ " \"y\": 280,\n"
+ " \"y\": 640,\n"
+ " \"opacity\": 1\n"
+ " }\n"
+ " },\n"
+ " \"clipDefaults\": {\n"
+ " \"fontSize\": 24,\n"
+ " \"fontType\": \"Noto Sans\",\n"
+ " \"fontSize\": 18,\n"
+ " \"fontColor\": \"white\"\n"
+ " },\n"
+ " \"clips\": [\n"
Expand All @@ -255,28 +275,123 @@ private String generateManifestJson(String imageUrl, String colorCode, String ph
+ " {\n"
+ " \"x\": 950,\n"
+ " \"width\": 300,\n"
+ " \"height\": 300,\n"
+ " \"height\": 50,\n"
+ " \"keyframes\": {\n"
+ " \"0\": {\n"
+ " \"y\":80\n"
+ " },\n"
+ " \"1000\": {\n"
+ " \"y\": 100\n"
+ " }\n"
+ " },\n"
+ " \"clipDefaults\": {\n"
+ " \"textAlign\": \"left\",\n"
+ " \"fontSize\": " + fontSize + ",\n"
+ " \"fontColor\": \"white\"\n"
+ " },\n"
+ " \"clips\": [\n"
+ " {\n"
+ " \"text\": \"{{titleText1}}\",\n"
+ " \"type\": \"textArea\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"x\": 950,\n"
+ " \"width\": 300,\n"
+ " \"height\": 30,\n"
+ " \"keyframes\": {\n"
+ " \"0\": {\n"
+ " \"y\": 150\n"
+ " },\n"
+ " \"1000\": {\n"
+ " \"y\": 170\n"
+ " }\n"
+ " },\n"
+ " \"clipDefaults\": {\n"
+ " \"textAlign\": \"left\",\n"
+ " \"fontSize\": " + fontSize + ",\n"
+ " \"fontColor\": \"white\"\n"
+ " },\n"
+ " \"clips\": [\n"
+ " {\n"
+ " \"text\": \"{{titleText2}}\",\n"
+ " \"type\": \"textArea\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"x\": 950,\n"
+ " \"width\": 300,\n"
+ " \"height\": 30,\n"
+ " \"keyframes\": {\n"
+ " \"0\": {\n"
+ " \"y\": 220\n"
+ " },\n"
+ " \"1000\": {\n"
+ " \"y\": 240\n"
+ " }\n"
+ " },\n"
+ " \"clipDefaults\": {\n"
+ " \"textAlign\": \"left\",\n"
+ " \"fontSize\": " + fontSize + ",\n"
+ " \"fontColor\": \"white\"\n"
+ " },\n"
+ " \"clips\": [\n"
+ " {\n"
+ " \"text\": \"{{titleText3}}\",\n"
+ " \"type\": \"textArea\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"x\": 950,\n"
+ " \"width\": 300,\n"
+ " \"height\": 30,\n"
+ " \"keyframes\": {\n"
+ " \"0\": {\n"
+ " \"y\": 290\n"
+ " },\n"
+ " \"1000\": {\n"
+ " \"y\": 300\n"
+ " \"y\": 310\n"
+ " }\n"
+ " },\n"
+ " \"clipDefaults\": {\n"
+ " \"textAlign\": \"left\",\n"
+ " \"fontSize\": 32,\n"
+ " \"fontType\": \"Noto Sans\",\n"
+ " \"fontSize\": " + fontSize + ",\n"
+ " \"fontColor\": \"white\"\n"
+ " },\n"
+ " \"clips\": [\n"
+ " {\n"
+ " \"text\": \"{{titleText4}}\",\n"
+ " \"type\": \"textArea\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"x\": 950,\n"
+ " \"width\": 300,\n"
+ " \"height\": 30,\n"
+ " \"keyframes\": {\n"
+ " \"0\": {\n"
+ " \"y\": 360\n"
+ " },\n"
+ " \"1000\": {\n"
+ " \"y\": 380\n"
+ " }\n"
+ " },\n"
+ " \"clipDefaults\": {\n"
+ " \"textAlign\": \"left\",\n"
+ " \"fontSize\": " + fontSize + ",\n"
+ " \"fontColor\": \"white\"\n"
+ " },\n"
+ " \"clips\": [\n"
+ " {\n"
+ " \"text\": \"{{titleText}}\",\n"
+ " \"text\": \"{{titleText5}}\",\n"
+ " \"type\": \"textArea\"\n"
+ " }\n"
+ " ]\n"
+ " } // track 4\n"
+ " }\n"
+ " ]\n"
+ "}";

Expand Down

0 comments on commit 3642105

Please sign in to comment.