Skip to content

Commit 5edd8f3

Browse files
committed
feat: 음악 일기 목데이터 반환
1 parent 8127baf commit 5edd8f3

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

src/main/java/apptive/team5/Team5Application.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
6+
import org.springframework.data.web.config.EnableSpringDataWebSupport;
67
import org.springframework.scheduling.annotation.EnableScheduling;
78

9+
import static org.springframework.data.web.config.EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO;
10+
811
@EnableJpaAuditing
912
@EnableScheduling
1013
@SpringBootApplication
14+
@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)
1115
public class Team5Application {
1216

1317
public static void main(String[] args) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package apptive.team5.diary.controller;
2+
3+
import apptive.team5.diary.dto.DiaryResponse;
4+
import apptive.team5.diary.service.DiaryService;
5+
import lombok.RequiredArgsConstructor;
6+
import org.apache.catalina.connector.Response;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.PageRequest;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RequestParam;
15+
import org.springframework.web.bind.annotation.RestController;
16+
17+
@RestController
18+
@RequiredArgsConstructor
19+
@RequestMapping("/api/diaries/")
20+
public class DiaryController {
21+
22+
private final DiaryService diaryService;
23+
24+
@GetMapping("/my")
25+
public ResponseEntity<Page<DiaryResponse>> getMyMusicDiary(
26+
@AuthenticationPrincipal String identifier,
27+
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "5") int size) {
28+
29+
30+
Page<DiaryResponse> response = diaryService.getMyDiaries(identifier, PageRequest.of(page, size));
31+
32+
return ResponseEntity.status(HttpStatus.OK).body(response);
33+
}
34+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package apptive.team5.diary.dto;
2+
3+
4+
public record DiaryResponse(
5+
String content,
6+
String videoUrl
7+
) {
8+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package apptive.team5.diary.service;
2+
3+
import apptive.team5.diary.dto.DiaryResponse;
4+
import apptive.team5.user.domain.UserEntity;
5+
import apptive.team5.user.service.UserLowService;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.PageImpl;
9+
import org.springframework.data.domain.Pageable;
10+
import org.springframework.data.domain.Sort;
11+
import org.springframework.stereotype.Service;
12+
import org.springframework.transaction.annotation.Transactional;
13+
14+
import java.util.Iterator;
15+
import java.util.List;
16+
import java.util.function.Function;
17+
18+
@Transactional
19+
@Service
20+
@RequiredArgsConstructor
21+
public class DiaryService {
22+
23+
private final UserLowService userLowService;
24+
25+
public Page<DiaryResponse> getMyDiaries(String identifier, Pageable pageable) {
26+
27+
UserEntity findUser = userLowService.findByIdentifier(identifier);
28+
29+
/**
30+
* 조회된 유저를 바탕으로 음악 일기 찾기
31+
*/
32+
33+
34+
DiaryResponse data1 =
35+
new DiaryResponse("목데이터1", "https://www.youtube-nocookie.com/embed/ki08IcGubwQ");
36+
37+
DiaryResponse data2 =
38+
new DiaryResponse("목데이터2", "https://www.youtube-nocookie.com/embed/ki08IcGubwQ");
39+
40+
DiaryResponse data3 =
41+
new DiaryResponse("목데이터1", "https://www.youtube-nocookie.com/embed/ki08IcGubwQ");
42+
43+
DiaryResponse data4 =
44+
new DiaryResponse("목데이터2", "https://www.youtube-nocookie.com/embed/ki08IcGubwQ");
45+
46+
List<DiaryResponse> datas = List.of(data1, data2, data3, data4);
47+
48+
int start = (int) pageable.getOffset();
49+
int end = Math.min(start + pageable.getPageSize(), datas.size());
50+
List<DiaryResponse> subList = datas.subList(start, end);
51+
52+
return new PageImpl<>(subList, pageable, datas.size());
53+
54+
}
55+
}

0 commit comments

Comments
 (0)