Skip to content

Commit

Permalink
✨ [FEAT] lottie 반환 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
dong2ast committed Aug 1, 2024
1 parent 1e38924 commit 53ea972
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,39 @@
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.sopt.lequuServer.domain.common.dto.response.PopularBookResponseDto;
import org.sopt.lequuServer.domain.common.dto.response.SplashDto;
import org.sopt.lequuServer.global.common.dto.ApiResponse;
import org.springframework.http.ResponseEntity;

import java.util.List;

@Tag(name = "Common", description = "홈 & 스플래시 API")
public interface CommonApi {

@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "스플래시 조회에 성공했습니다.",
content = @Content(schema = @Schema(implementation = SplashDto.class))
responseCode = "200",
description = "스플래시 조회에 성공했습니다.",
content = @Content(schema = @Schema(implementation = SplashDto.class))
)
@Operation(summary = "스플래시 조회")
public ResponseEntity<ApiResponse<SplashDto>> getSplash();
ResponseEntity<ApiResponse<SplashDto>> getSplash();

@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "홈 화면 조회에 성공했습니다.",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PopularBookResponseDto.class)))
responseCode = "200",
description = "홈 화면 조회에 성공했습니다.",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PopularBookResponseDto.class)))
)
@Operation(summary = "홈 조회")
public ResponseEntity<ApiResponse<List<PopularBookResponseDto>>> getHome();
ResponseEntity<ApiResponse<List<PopularBookResponseDto>>> getHome();

@Hidden
public ResponseEntity<ApiResponse<?>> test();
ResponseEntity<ApiResponse<?>> test();

@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "로띠 조회에 성공했습니다.",
content = @Content(schema = @Schema(implementation = String.class))
)
@Operation(summary = "로띠 json 조회")
ResponseEntity<ApiResponse<String>> getLottie();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.lequuServer.domain.common.controller;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.sopt.lequuServer.domain.common.dto.response.PopularBookResponseDto;
import org.sopt.lequuServer.domain.common.dto.response.SplashDto;
Expand All @@ -11,8 +12,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common")
Expand All @@ -34,4 +33,9 @@ public ResponseEntity<ApiResponse<List<PopularBookResponseDto>>> getHome() {
public ResponseEntity<ApiResponse<?>> test() {
throw new RuntimeException("테스트용 에러 발생");
}

@GetMapping("/lottie")
public ResponseEntity<ApiResponse<String>> getLottie(){
return ResponseEntity.ok(ApiResponse.success(SuccessType.GET_LOTTIE_SUCCESS, commonFacade.getLottie()));
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package org.sopt.lequuServer.domain.common.facade;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.sopt.lequuServer.domain.book.repository.BookRepository;
import lombok.extern.slf4j.Slf4j;
import org.sopt.lequuServer.domain.book.service.BookService;
import org.sopt.lequuServer.domain.common.dto.response.PopularBookResponseDto;
import org.sopt.lequuServer.domain.common.dto.response.SplashDto;
import org.sopt.lequuServer.domain.note.repository.NoteRepository;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
@Transactional(readOnly = true)
public class CommonFacade {
private final BookRepository bookRepository;
private final NoteRepository noteRepository;
private final BookService bookService;

Expand All @@ -30,4 +33,18 @@ public List<PopularBookResponseDto> getHome() {
.toList();
}
// 레큐북 정렬된 것을 가져오기

public String getLottie(){
try {
// src/main/resources 디렉토리의 data.json 파일 경로 읽기
ClassPathResource resource = new ClassPathResource("lottie.json");
Path path = resource.getFile().toPath();
String json = Files.readString(path);

return json;
} catch (IOException e) {
log.error("IOE Error: {e}", e);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum SuccessType {
GET_FAVORITE_SUCCESS(HttpStatus.OK, "즐겨찾는 레큐북 조회에 성공했습니다."),
GET_MYPAGE_FAVORITE_SUCCESS(HttpStatus.OK, "마이페이지의 내 즐겨찾기 조회에 성공했습니다."),
GET_MYPAGE_SUCCESS(HttpStatus.OK, "마이페이지 조회에 성공했습니다."),
GET_LOTTIE_SUCCESS(HttpStatus.OK, "로띠 json 조회에 성공했습니다."),

/**
* 201 CREATED
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lottie.json

Large diffs are not rendered by default.

0 comments on commit 53ea972

Please sign in to comment.