-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
220 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { LockKeyhole } from 'lucide-react'; | ||
import useModal from '@/shared/hooks/useModal'; | ||
import MODAL_TYPE from '@/shared/constants/modal'; | ||
|
||
const PrivateButton = ({ isPrivate }: { isPrivate: Date | null }) => { | ||
const { onOpen } = useModal(); | ||
|
||
return ( | ||
<button | ||
onClick={() => { | ||
onOpen(MODAL_TYPE.PRIVATE_INFO); | ||
}} | ||
className="transfrom pointer-events-auto rounded-full p-2 text-white" | ||
> | ||
{isPrivate && <LockKeyhole />} | ||
</button> | ||
); | ||
}; | ||
|
||
export default PrivateButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { connectToMongoDB } from '@/shared/database/mongodb/config'; | ||
import Crystal from '@/shared/database/mongodb/models/crystalModel'; | ||
import User from '@/shared/database/mongodb/models/userModel'; | ||
import { UserType } from '@/shared/types/user'; | ||
import { CURRENT_SEASON } from '@/shared/constants/Date'; | ||
import { CURRENT_YEAR } from '@/shared/constants/Date'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const userId = req.headers.get('X-User-Id'); | ||
|
||
if (!userId) { | ||
return NextResponse.json({ error: 'User ID is required' }, { status: 400 }); | ||
} | ||
// MongoDB에 연결 | ||
await connectToMongoDB(); | ||
|
||
try { | ||
// user_id에 해당하는 유저의 crystal_id 조회 | ||
const crystal = ( | ||
(await User.findOne({ _id: userId }).select('crystal_id')) as UserType | ||
).crystal_id?.get(CURRENT_YEAR)?.[CURRENT_SEASON]; | ||
|
||
if (!crystal) { | ||
return NextResponse.json({ error: 'User not found' }, { status: 404 }); | ||
} | ||
|
||
const crystalDatas = await Promise.all( | ||
crystal.map(async (crystalId) => { | ||
return await Crystal.findOne({ _id: crystalId }); | ||
}) | ||
); | ||
|
||
return NextResponse.json({ data: crystalDatas, ok: true }); | ||
} catch (error) { | ||
console.error('Error fetching crystal:', error); | ||
return NextResponse.json( | ||
{ error: 'Failed to fetch crystal' + error }, | ||
{ status: 500 } | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { connectToMongoDB } from '@/shared/database/mongodb/config'; | ||
import Crystal from '@/shared/database/mongodb/models/crystalModel'; | ||
import { Crystal as CrystalType } from '@/shared/types/crystal'; | ||
import Message from '@/shared/database/mongodb/models/messageModel'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
const crystalId = req.headers.get('X-Crystal-Id'); | ||
|
||
if (!crystalId) { | ||
return NextResponse.json( | ||
{ error: 'Crystal ID is required' }, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
try { | ||
// MongoDB에 연결 | ||
await connectToMongoDB(); | ||
|
||
const crystal = (await Crystal.findOne({ _id: crystalId }).select( | ||
'message_id is_private' | ||
)) as CrystalType; | ||
|
||
if (!crystal) { | ||
return NextResponse.json({ error: 'Crystal not found' }, { status: 404 }); | ||
} | ||
const isPrivate = crystal.is_private; | ||
const messages = crystal.message_id; | ||
|
||
const messageDatas = await Promise.all( | ||
messages.map(async (messageId) => { | ||
const message = await Message.findOne({ _id: messageId }); | ||
if (message && isPrivate !== null) { | ||
message.content = '비공개 메시지입니다.'; | ||
message.sender = '익명'; | ||
} | ||
return message; | ||
}) | ||
); | ||
|
||
return NextResponse.json({ data: messageDatas, ok: true }); | ||
} catch (error) { | ||
console.error('Error fetching messages:', error); | ||
return NextResponse.json( | ||
{ error: 'Failed to fetch messages' + error }, | ||
{ status: 500 } | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use client'; | ||
|
||
import useModal from '@/shared/hooks/useModal'; | ||
|
||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogFooter, | ||
} from '@/components/ui/dialog'; | ||
import { Button } from '@/components/ui/button'; | ||
import MODAL_TYPE from '@/shared/constants/modal'; | ||
|
||
const PrivateInfoModal = () => { | ||
const { isOpen, onClose, type } = useModal(); | ||
|
||
if (!isOpen || type !== MODAL_TYPE.PRIVATE_INFO) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Dialog open={isOpen}> | ||
<DialogContent | ||
className="no-scrollbar rounded-lg border-none bg-primary text-white" | ||
onOpenAutoFocus={(e) => e.preventDefault()} | ||
> | ||
<DialogHeader className="flex flex-col items-center justify-center gap-2"> | ||
<DialogTitle>비공개 수정구슬</DialogTitle> | ||
<DialogDescription> | ||
현재 해당 수정구슬은 비공개로 설정되어 있습니다. | ||
<br /> | ||
비공개 수정구슬은 수정구슬 주인만 메세지를 확인할 수 있어요. | ||
</DialogDescription> | ||
</DialogHeader> | ||
|
||
<DialogFooter className="block"> | ||
<Button | ||
className="w-full" | ||
variant={'secondary'} | ||
onClick={() => onClose()} | ||
> | ||
닫기 | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default PrivateInfoModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters