generated from MurakawaTakuya/react-nextjs-environment-setting-template
-
Notifications
You must be signed in to change notification settings - Fork 0
お気に入り機能を追加 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
お気に入り機能を追加 #16
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
79cbee6
論文のお気に入り保存テーブルを作成
MurakawaTakuya 8d6cc81
お気に入り登録のUIを作成
MurakawaTakuya 07df4a0
お気に入り表示ページを作成
MurakawaTakuya 4f04ba2
サイドバーにお気に入りフォルダ一覧を作成
MurakawaTakuya 256d2ae
テキストを日本語に変更
MurakawaTakuya 95ac27a
レイアウト調整
MurakawaTakuya 3ed09d4
複数フォルダにお気に入り登録できるように変更
MurakawaTakuya 6f7a618
スマホ表示のstepperの表示を改善
MurakawaTakuya e9bf529
スマホ表示のお気に入り論文のabstractの表示を改善
MurakawaTakuya c0caae8
お気に入りフォルダの名前変更機能を実装
MurakawaTakuya 7784a7d
お気に入りのloadingを表示
MurakawaTakuya f945d87
お気に入りへの追加・削除をoptimistic updateに変更
MurakawaTakuya 35fe4f9
npx heroui-cli@latest add toast
MurakawaTakuya 63e057f
Revert "npx heroui-cli@latest add toast"
MurakawaTakuya aa9982c
お気に入り編集時の通知を追加
MurakawaTakuya 24b4166
フォルダ編集時にも通知を表示
MurakawaTakuya 0a213a3
フォルダの削除機能を追加
MurakawaTakuya 8ebfe1e
フォルダ削除時に確認モーダルを表示
MurakawaTakuya a132392
fixup! フォルダ削除時に確認モーダルを表示
MurakawaTakuya 803403c
レイアウト調整
MurakawaTakuya b53c219
ビルドエラーを解消
MurakawaTakuya 182459e
AIレビュー修正
MurakawaTakuya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,59 @@ | ||
| import { getUserIdFromRequest } from "@/lib/auth-server"; | ||
| import { db, schema } from "@/lib/db"; | ||
| import { and, eq } from "drizzle-orm"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| export async function DELETE( | ||
| request: NextRequest, | ||
| { params }: { params: Promise<{ id: string }> } | ||
| ) { | ||
| const userId = await getUserIdFromRequest(request); | ||
| if (!userId) { | ||
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
| } | ||
|
|
||
| if (!db) { | ||
| return NextResponse.json( | ||
| { error: "Database not configured" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const { id } = await params; | ||
MurakawaTakuya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const favoriteId = parseInt(id); | ||
|
|
||
| if (isNaN(favoriteId)) { | ||
| return NextResponse.json( | ||
| { error: "Invalid favorite ID" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| // 削除実行 (自分のものだけ削除可能) | ||
| const deleted = await db | ||
| .delete(schema.favorites) | ||
| .where( | ||
| and( | ||
| eq(schema.favorites.id, favoriteId), | ||
| eq(schema.favorites.userId, userId) | ||
| ) | ||
| ) | ||
| .returning(); | ||
|
|
||
| if (deleted.length === 0) { | ||
| return NextResponse.json( | ||
| { error: "Favorite not found or not authorized" }, | ||
| { status: 404 } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json({ success: true, deleted: deleted[0] }); | ||
| } catch (error) { | ||
| console.error("Error deleting favorite:", error); | ||
| return NextResponse.json( | ||
| { error: "Internal server error" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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,136 @@ | ||
| import { getUserIdFromRequest } from "@/lib/auth-server"; | ||
| import { db, schema } from "@/lib/db"; | ||
| import { and, desc, eq, isNull } from "drizzle-orm"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| // GET /api/favorites - お気に入り一覧を取得 (フォルダ情報、論文情報込み) | ||
| export async function GET(request: NextRequest) { | ||
| const userId = await getUserIdFromRequest(request); | ||
| if (!userId) { | ||
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
| } | ||
|
|
||
| if (!db) { | ||
| return NextResponse.json( | ||
| { error: "Database not configured" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| // フォルダIDでフィルタリングする場合 | ||
| const { searchParams } = new URL(request.url); | ||
| const folderId = searchParams.get("folderId"); | ||
|
|
||
| const conditions = [eq(schema.favorites.userId, userId)]; | ||
|
|
||
| if (folderId) { | ||
| if (folderId === "null") { | ||
| // 未分類 | ||
| conditions.push(isNull(schema.favorites.folderId)); | ||
| } else { | ||
| const fid = parseInt(folderId); | ||
| if (!isNaN(fid)) { | ||
| conditions.push(eq(schema.favorites.folderId, fid)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const results = await db | ||
| .select({ | ||
| favorite: schema.favorites, | ||
| paper: schema.papers, | ||
| folder: schema.folders, | ||
| }) | ||
| .from(schema.favorites) | ||
| .innerJoin(schema.papers, eq(schema.favorites.paperId, schema.papers.id)) | ||
| .leftJoin( | ||
| schema.folders, | ||
| eq(schema.favorites.folderId, schema.folders.id) | ||
| ) | ||
| .where(and(...conditions)) | ||
| .orderBy(desc(schema.favorites.createdAt)); | ||
|
|
||
| // 整形して返す | ||
| const favorites = results.map((r) => ({ | ||
| ...r.favorite, | ||
| paper: r.paper, | ||
| folder: r.folder, | ||
| })); | ||
|
|
||
| return NextResponse.json(favorites); | ||
| } catch (error) { | ||
| console.error("Error fetching favorites:", error); | ||
| return NextResponse.json( | ||
| { error: "Internal server error" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // POST /api/favorites - お気に入り追加 | ||
| export async function POST(request: NextRequest) { | ||
| const userId = await getUserIdFromRequest(request); | ||
| if (!userId) { | ||
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
| } | ||
|
|
||
| if (!db) { | ||
| return NextResponse.json( | ||
| { error: "Database not configured" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const body = await request.json(); | ||
| const { paperId, folderId } = body; | ||
|
|
||
| if (!paperId) { | ||
| return NextResponse.json( | ||
| { error: "Paper ID is required" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
MurakawaTakuya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // 既に全く同じ組み合わせ(paperId, folderId)が存在するかチェック | ||
| const existing = await db | ||
| .select() | ||
| .from(schema.favorites) | ||
| .where( | ||
| and( | ||
| eq(schema.favorites.userId, userId), | ||
| eq(schema.favorites.paperId, paperId), | ||
| folderId | ||
| ? eq(schema.favorites.folderId, folderId) | ||
| : isNull(schema.favorites.folderId) | ||
| ) | ||
| ); | ||
|
|
||
| if (existing.length > 0) { | ||
| // 既に存在する場合は何もしない(冪等性) | ||
| return NextResponse.json(existing[0]); | ||
| } | ||
|
|
||
| // 新規登録 | ||
| // "Default" (null) folder acts as a regular folder now, so we don't delete it | ||
| // when adding to other folders. | ||
|
|
||
| const newFavorite = await db | ||
| .insert(schema.favorites) | ||
| .values({ | ||
| userId, | ||
| paperId, | ||
| folderId: folderId || null, | ||
| }) | ||
| .returning(); | ||
MurakawaTakuya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return NextResponse.json(newFavorite[0], { status: 201 }); | ||
| } catch (error) { | ||
| console.error("Error adding favorite:", error); | ||
| return NextResponse.json( | ||
| { error: "Internal server error" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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,64 @@ | ||
| import { getUserIdFromRequest } from "@/lib/auth-server"; | ||
| import { db, schema } from "@/lib/db"; | ||
| import { and, eq } from "drizzle-orm"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| // PATCH /api/folders/[id] - フォルダ名を変更 | ||
| export async function PATCH( | ||
| request: NextRequest, | ||
| { params }: { params: Promise<{ id: string }> } | ||
| ) { | ||
MurakawaTakuya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const userId = await getUserIdFromRequest(request); | ||
| if (!userId) { | ||
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
| } | ||
|
|
||
| if (!db) { | ||
| return NextResponse.json( | ||
| { error: "Database not configured" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const { id } = await params; | ||
| const folderId = parseInt(id); | ||
| if (isNaN(folderId)) { | ||
| return NextResponse.json({ error: "Invalid folder ID" }, { status: 400 }); | ||
| } | ||
|
|
||
| const body = await request.json(); | ||
| const { name } = body; | ||
|
|
||
| if (!name || typeof name !== "string" || !name.trim()) { | ||
| return NextResponse.json( | ||
| { error: "Valid folder name is required" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| // 自分のフォルダかつIDが一致するものを更新 | ||
| const updatedFolder = await db | ||
| .update(schema.folders) | ||
| .set({ name: name.trim() }) | ||
MurakawaTakuya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .where( | ||
| and(eq(schema.folders.id, folderId), eq(schema.folders.userId, userId)) | ||
| ) | ||
| .returning(); | ||
|
|
||
| if (updatedFolder.length === 0) { | ||
| return NextResponse.json( | ||
| { error: "Folder not found or unauthorized" }, | ||
| { status: 404 } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json(updatedFolder[0]); | ||
| } catch (error) { | ||
| console.error("Error updating folder:", error); | ||
| return NextResponse.json( | ||
| { error: "Internal server error" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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,78 @@ | ||
| import { getUserIdFromRequest } from "@/lib/auth-server"; | ||
| import { db, schema } from "@/lib/db"; | ||
| import { desc, eq } from "drizzle-orm"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| // GET /api/folders - フォルダ一覧を取得 | ||
| export async function GET(request: NextRequest) { | ||
| const userId = await getUserIdFromRequest(request); | ||
| if (!userId) { | ||
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
| } | ||
|
|
||
| if (!db) { | ||
| return NextResponse.json( | ||
| { error: "Database not configured" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const userFolders = await db | ||
| .select() | ||
| .from(schema.folders) | ||
| .where(eq(schema.folders.userId, userId)) | ||
| .orderBy(desc(schema.folders.createdAt)); | ||
|
|
||
| return NextResponse.json(userFolders); | ||
| } catch (error) { | ||
| console.error("Error fetching folders:", error); | ||
| return NextResponse.json( | ||
| { error: "Internal server error" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // POST /api/folders - フォルダを作成 | ||
| export async function POST(request: NextRequest) { | ||
| const userId = await getUserIdFromRequest(request); | ||
| if (!userId) { | ||
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
| } | ||
|
|
||
| if (!db) { | ||
| return NextResponse.json( | ||
| { error: "Database not configured" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const body = await request.json(); | ||
| const { name } = body; | ||
|
|
||
| if (!name || typeof name !== "string") { | ||
| return NextResponse.json( | ||
| { error: "Folder name is required" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
MurakawaTakuya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const newFolder = await db | ||
| .insert(schema.folders) | ||
| .values({ | ||
| userId, | ||
| name, | ||
MurakawaTakuya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
MurakawaTakuya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
| .returning(); | ||
|
|
||
| return NextResponse.json(newFolder[0], { status: 201 }); | ||
| } catch (error) { | ||
| console.error("Error creating folder:", error); | ||
| return NextResponse.json( | ||
| { error: "Internal server error" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.