From 9a27f650706085314a23efdc8d16740a176d67e1 Mon Sep 17 00:00:00 2001 From: Youjung Heo Date: Thu, 21 Jul 2022 07:43:10 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EC=98=A4=EB=8A=98=EC=9D=98=20?= =?UTF-8?q?=EB=AE=A4=EB=A9=98=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20service=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20#47?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mument/TodayMumentResponseDto.ts | 6 ++-- src/services/MumentService.ts | 35 ++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/interfaces/mument/TodayMumentResponseDto.ts b/src/interfaces/mument/TodayMumentResponseDto.ts index ef31da1..efa73c9 100644 --- a/src/interfaces/mument/TodayMumentResponseDto.ts +++ b/src/interfaces/mument/TodayMumentResponseDto.ts @@ -1,6 +1,6 @@ -import { MumentCardViewInterface } from './MumentCardViewInterface'; +import { TodaySelectionInfo } from '../home/TodaySelectionInfo'; export interface TodayMumentResponseDto { - nowDate: Date; - todayMument: MumentCardViewInterface; + todayDate: string; + todayMument: TodaySelectionInfo; } diff --git a/src/services/MumentService.ts b/src/services/MumentService.ts index bb2d044..8fba694 100644 --- a/src/services/MumentService.ts +++ b/src/services/MumentService.ts @@ -1,4 +1,5 @@ import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; import constant from '../modules/serviceReturnConstant'; import { tagBannerTitle } from '../modules/tagTitle'; import { tagRandomTitle } from '../modules/tagTitle'; @@ -17,9 +18,10 @@ import Music from '../models/Music'; import User from '../models/User'; import Like from '../models/Like'; import HomeCandidate from '../models/HomeCandidate'; -import { HomeCandidateInfo } from '../interfaces/home/HomeCandidateInfo'; +import TodaySelection from '../models/TodaySelection'; import { RandomMumentResponseDto } from '../interfaces/mument/RandomMumentResponeDto'; import { RandomMumentInterface } from '../interfaces/home/randomMumentInterface'; +import { TodayMumentResponseDto } from '../interfaces/mument/TodayMumentResponseDto'; const createMument = async (userId: string, musicId: string, mumentCreateDto: MumentCreateDto): Promise => { try { @@ -521,6 +523,36 @@ const getRandomMument = async (): Promise => { } }; +// 오늘의 뮤멘트 조회 +const getTodayMument = async (): Promise => { + try { + dayjs.extend(utc); + + // 리퀘스트 받아온 시간 판단 후 당일 자정으로 수정 + const todayMidnight = new Date().setHours(0, 0, 0, 0); + const todayUtcDate = dayjs(todayMidnight).utc().format(); + const todayDate = dayjs(todayMidnight).format('YYYY-MM-DD'); + + const todayMument = await TodaySelection.findOne({ + displayDate: todayUtcDate, + }); + + if (!todayMument) { + return constant.NO_HOME_CONTENT; + } + + const data: TodayMumentResponseDto = { + todayDate, + todayMument, + }; + + return data; + } catch (error) { + console.log(error); + throw error; + } +}; + export default { createMument, updateMument, @@ -531,4 +563,5 @@ export default { createLike, deleteLike, getRandomMument, + getTodayMument, };