generated from jphacks/JP_sample
-
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.
Merge pull request #44 from jphacks/feat/hikahana/add-exp-schema
EXPスキーマを作成&ユーザサインアップ、サインイン時にテーブル作成。
- Loading branch information
Showing
5 changed files
with
128 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { experiencePoint } from "@/types"; | ||
import { prisma } from "@lib/prisma"; | ||
import type { NextRequest } from "next/server"; | ||
import { NextResponse } from "next/server"; | ||
|
||
// experiencePointの新規作成 | ||
export async function POST(req: NextRequest) { | ||
const reader = req.body?.getReader(); | ||
if (!reader) { | ||
return NextResponse.json( | ||
{ error: "No request body found" }, | ||
{ status: 400 }, | ||
); | ||
} | ||
const { value } = await reader.read(); | ||
const userId = new TextDecoder().decode(value); | ||
|
||
const id = JSON.parse(userId); | ||
const createExp: experiencePoint = await prisma.experiencePoint.create({ | ||
data: { | ||
speedPoint: 0, | ||
similarityPoint: 0, | ||
totalPoint: 0, | ||
continuationDay: 0, | ||
userId: id, | ||
}, | ||
}); | ||
|
||
return new Response(JSON.stringify({ createExp }), { | ||
status: 200, | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,49 +1,57 @@ | ||
import type { NextRequest } from "next/server"; | ||
import { prisma } from "@lib/prisma"; | ||
import type { DBUser as User } from "@/types"; | ||
import { prisma } from "@lib/prisma"; | ||
import type { NextRequest } from "next/server"; | ||
import { NextResponse } from "next/server"; | ||
|
||
type ResponseData = { | ||
message: string; | ||
message: string; | ||
}; | ||
|
||
// GETメソッドのハンドラ関数 | ||
export function GET() { | ||
// 疎通確認 | ||
return new Response(JSON.stringify({ message: "Hello from Next.js!" }), { | ||
status: 200, | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
// 疎通確認 | ||
return new Response(JSON.stringify({ message: "Hello from Next.js!" }), { | ||
status: 200, | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} | ||
|
||
// POSTメソッドをサポートしたい場合(例) | ||
export async function POST(req: NextRequest) { | ||
const reader = req.body?.getReader(); | ||
if (!reader) { | ||
return NextResponse.json( | ||
{ error: "No request body found" }, | ||
{ status: 400 } | ||
); | ||
} | ||
const { value } = await reader.read(); | ||
const userData = new TextDecoder().decode(value); | ||
const reader = req.body?.getReader(); | ||
if (!reader) { | ||
return NextResponse.json( | ||
{ error: "No request body found" }, | ||
{ status: 400 }, | ||
); | ||
} | ||
const { value } = await reader.read(); | ||
const userData = new TextDecoder().decode(value); | ||
|
||
// 任意の処理をここで行います(例: データのパース) const userData = new TextDecoder().decode(value); | ||
// TODO ここバリデーション欲しい | ||
const user = JSON.parse(userData); | ||
// プリズマでユーザを登録 | ||
const registerUser: User = await prisma.user.create({ | ||
data: { | ||
uid: user.uid, | ||
name: user.displayName, | ||
email: user.email, | ||
photoUrl: user.photoURL, | ||
}, | ||
}); | ||
// 任意の処理をここで行います(例: データのパース) const userData = new TextDecoder().decode(value); | ||
// TODO ここバリデーション欲しい | ||
const user = JSON.parse(userData); | ||
// プリズマでユーザ,経験値を登録 | ||
const registerUser: User = await prisma.user.create({ | ||
data: { | ||
uid: user.uid, | ||
name: user.displayName, | ||
email: user.email, | ||
photoUrl: user.photoURL, | ||
experiencePoint: { | ||
create: { | ||
speedPoint: 0, | ||
similarityPoint: 0, | ||
totalPoint: 0, | ||
continuationDay: 0, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// 疎通確認 | ||
return new Response(JSON.stringify({ registerUser }), { | ||
status: 200, | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
// 疎通確認 | ||
return new Response(JSON.stringify({ registerUser }), { | ||
status: 200, | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} |
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