Skip to content

Commit

Permalink
Merge pull request #86 from Team-B1ND/FIX/#85
Browse files Browse the repository at this point in the history
Fix/#85
  • Loading branch information
dongchandev authored Jun 19, 2024
2 parents d7433bc + 984425f commit 6266ed1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Response updateMemberInfo(UpdateMemberInfoReq req) {
Member member = service.getMemberFromSession();
member.updateInfo(req.name(), req.email(), req.phone(), req.profileImage());

service.save(member);
// service.save(member);
return Response.noContent("내 정보 수정 성공");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@RestController
@RequestMapping("/upload")
@RequiredArgsConstructor
public class UploadController {
public class UploadController {

private final UploadService uploadService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ public ResponseData<List<WakeupSongRes>> getMyWakeupSong(){
@Transactional(rollbackFor = Exception.class)
public CompletableFuture<Response> createWakeupSong(String videoUrl) {
Member member = verifyAlreadyAppliedFromSession();
return CompletableFuture.supplyAsync(() -> {
String videoId = YoutubeApiUtil.getVideoId(videoUrl);
YoutubeApiRes.Snippet snippet = videoClient.getVideo(videoId).getItems().get(0).getSnippet();
checkValidVideoType(snippet.getTitle());
buildAndSaveWakeupSong(snippet, videoId,videoUrl,member);
return Response.created("기상송 신청 성공");
}).exceptionally(this::handleExceptionOnCreateWakeupSong);
String videoId = YoutubeApiUtil.getVideoId(videoUrl);

return videoClient.getVideo(videoId)
.thenApply(videoResponse -> {
YoutubeApiRes.Snippet snippet = videoResponse.getItems().get(0).getSnippet();
checkValidVideoType(snippet.getTitle());
buildAndSaveWakeupSong(snippet, videoId, videoUrl, member);
return Response.created("기상송 신청 성공");
}).exceptionally(this::handleExceptionOnCreateWakeupSong);
}


@Transactional(rollbackFor = Exception.class)
public CompletableFuture<Response> createWakeupSongByYoutubeSearch(ApplyWakeupSongBySearchReq req){
Member member = verifyAlreadyAppliedFromSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ List<NightStudy> findValidStudyByStudentAndDate(@Param("student") Student studen
List<NightStudy> findByStatus(NightStudyStatus status);

@EntityGraph(attributePaths = {"student.member"})
@Query("select n from NightStudy n where n.endAt >= :now and n.startAt <= :now and n.status = :status")
@Query("select n from NightStudy n join n.student s join s.member m " +
"where n.endAt >= :now and n.startAt <= :now and n.status = :status " +
"order by n.student.grade, n.student.room, n.student.number")
List<NightStudy> findAllowedStudyByDate(@Param("now") LocalDate now, @Param("status") NightStudyStatus status);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ default OutSleeping getById(Long id) {
}

@EntityGraph(attributePaths = {"student.member"})
@Query("select o from OutSleeping o where :date between o.startAt and o.endAt")
@Query("select o from OutSleeping o where :date between o.startAt and o.endAt " +
"order by o.student.grade, o.student.room, o.student.number")
List<OutSleeping> findByDate(@Param("date") LocalDate date);

@EntityGraph(attributePaths = {"student.member"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import b1nd.dodamcore.wakeupsong.application.dto.res.YoutubeApiRes;

import java.util.concurrent.CompletableFuture;

public interface VideoClient {

YoutubeApiRes.Video getVideo(String videoId);
CompletableFuture<YoutubeApiRes.Video> getVideo(String videoId);

YoutubeApiRes.Search searchVideoByKeyword(String keyword, int size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.concurrent.CompletableFuture;

@Component
@RequiredArgsConstructor
public class YoutubeClient implements VideoClient {
Expand All @@ -15,12 +17,12 @@ public class YoutubeClient implements VideoClient {
private final WebClientSupport webClientSupport;

@Override
public YoutubeApiRes.Video getVideo(String videoId) {
public CompletableFuture<YoutubeApiRes.Video> getVideo(String videoId) {
return webClientSupport.get(
UriComponentsBuilder.fromUriString(youtubeProperties.url().getVideo())
.build(youtubeProperties.getApiKey(), videoId).toString(),
YoutubeApiRes.Video.class
).block();
).toFuture();
}

@Override
Expand Down

0 comments on commit 6266ed1

Please sign in to comment.