Skip to content

Commit

Permalink
Merge branch 'main' into feat/hikahana/add-point-dailog
Browse files Browse the repository at this point in the history
  • Loading branch information
hikahana authored Nov 14, 2024
2 parents 3ca97dd + 7a810fb commit 4ac23f3
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 236 deletions.
15 changes: 15 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-slot": "^1.1.0",
"browser-image-compression": "^2.0.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
Expand Down
38 changes: 38 additions & 0 deletions app/src/app/api/experiencePoint/continuation/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { prisma } from "@lib/prisma";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

// continuationDayの更新
export async function PUT(req: NextRequest) {
const { pathname } = new URL(req.url || "");
const id = Number(pathname.split("/").pop());

if (!id) {
return NextResponse.json(
{ error: "Invalid or missing ID" },
{ status: 400 },
);
}

try {
const { continuationDay } = await req.json();
if (typeof continuationDay !== "number") {
return NextResponse.json(
{ error: "Invalid speed value" },
{ status: 400 },
);
}

const putContinuationDay = await prisma.experiencePoint.update({
where: { id },
data: { continuationDay: continuationDay },
});

return NextResponse.json({ putContinuationDay }, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to update continuationDay", details: error },
{ status: 500 },
);
}
}
26 changes: 26 additions & 0 deletions app/src/app/api/experiencePoint/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { prisma } from "@lib/prisma";
import type { NextRequest } from "next/server";

// GETメソッドのハンドラ関数
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url || "");
const id = searchParams.get("id") || "";
const numId = Number(id)

// prismaでユーザを取得
const exp = await prisma.experiencePoint.findFirst({
where: { userId: numId },
});

if (!exp) {
return new Response(JSON.stringify({ message: "Not Found" }), {
status: 404,
headers: { "Content-Type": "application/json" },
});
}

return new Response(JSON.stringify(exp), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
38 changes: 38 additions & 0 deletions app/src/app/api/experiencePoint/similarity/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { prisma } from "@lib/prisma";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

// similarityPointの更新
export async function PUT(req: NextRequest) {
const { pathname } = new URL(req.url || "");
const id = Number(pathname.split("/").pop());

if (!id) {
return NextResponse.json(
{ error: "Invalid or missing ID" },
{ status: 400 },
);
}

try {
const { similarity } = await req.json();
if (typeof similarity !== "number") {
return NextResponse.json(
{ error: "Invalid speed value" },
{ status: 400 },
);
}

const putSimilarity = await prisma.experiencePoint.update({
where: { id },
data: { similarityPoint: similarity },
});

return NextResponse.json({ putSimilarity }, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to update similarityPoint", details: error },
{ status: 500 },
);
}
}
38 changes: 38 additions & 0 deletions app/src/app/api/experiencePoint/speed/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { prisma } from "@lib/prisma";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

// speedPointの更新
export async function PUT(req: NextRequest) {
const { pathname } = new URL(req.url || "");
const id = Number(pathname.split("/").pop());

if (!id) {
return NextResponse.json(
{ error: "Invalid or missing ID" },
{ status: 400 },
);
}

try {
const { speed } = await req.json();
if (typeof speed !== "number") {
return NextResponse.json(
{ error: "Invalid speed value" },
{ status: 400 },
);
}

const putSpeed = await prisma.experiencePoint.update({
where: { id },
data: { speedPoint: speed },
});

return NextResponse.json({ putSpeed }, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to update speedPoint", details: error },
{ status: 500 },
);
}
}
38 changes: 38 additions & 0 deletions app/src/app/api/experiencePoint/total/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { prisma } from "@lib/prisma";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

// totalPointの更新
export async function PUT(req: NextRequest) {
const { pathname } = new URL(req.url || "");
const id = Number(pathname.split("/").pop());

if (!id) {
return NextResponse.json(
{ error: "Invalid or missing ID" },
{ status: 400 },
);
}

try {
const { total } = await req.json();
if (typeof total !== "number") {
return NextResponse.json(
{ error: "Invalid speed value" },
{ status: 400 },
);
}

const putTotal = await prisma.experiencePoint.update({
where: { id },
data: { totalPoint: total },
});

return NextResponse.json({ putTotal }, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to update totalPoint", details: error },
{ status: 500 },
);
}
}
106 changes: 53 additions & 53 deletions app/src/app/api/image/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,74 @@ import type { NextRequest } from "next/server";
import { OpenAI } from "openai";

type ResponseData = {
message: string;
message: string;
};

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
apiKey: process.env.OPENAI_API_KEY,
});

const BUCKET_NAME = "kz2404";

export async function GET(
req: NextRequest,
res: NextApiResponse<ResponseData>
req: NextRequest,
res: NextApiResponse<ResponseData>,
) {
// クエリパラメータを取得
// クエリパラメータを取得
const { searchParams } = new URL(req.url || "");
const imageName = searchParams.get("imageName") || "default-image-name";
const imageURL = `${process.env.NEXT_PUBLIC_MINIO_ENDPOINT}${BUCKET_NAME}/${imageName}`;
const imageURL = `${process.env.NEXT_PUBLIC_MINIO_ENDPOINT}${BUCKET_NAME}/${imageName}`;

return await generateCaption(imageURL)
.then((caption) => {
console.log(caption);
return new Response(JSON.stringify({ caption }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
})
.catch((error) => {
console.error("Error generating caption:", error);
return new Response(JSON.stringify({ message: "エラーが発生しました" }), {
status: 500,
headers: { "Content-Type": "application/json" },
});
});
return await generateCaption(imageURL)
.then((caption) => {
console.log(caption);
return new Response(JSON.stringify({ caption }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
})
.catch((error) => {
console.error("Error generating caption:", error);
return new Response(JSON.stringify({ message: "エラーが発生しました" }), {
status: 500,
headers: { "Content-Type": "application/json" },
});
});
}

// 画像URLからキャプションを生成する関数
const generateCaption = async (imageUrl: string) => {
try {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "system",
content: [
{
type: "text",
text: "A robot that can generate very short captions for images.",
},
],
},
{
role: "user",
content: [
{
type: "image_url",
image_url: {
url: imageUrl,
detail: "low",
},
},
],
},
],
});
try {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "system",
content: [
{
type: "text",
text: "A robot that can generate very short captions for images.",
},
],
},
{
role: "user",
content: [
{
type: "image_url",
image_url: {
url: imageUrl,
detail: "low",
},
},
],
},
],
});

const caption = await completion.choices[0].message.content;
return caption;
} catch (error) {
console.error("Error generating caption:", error);
}
const caption = await completion.choices[0].message.content;
return caption;
} catch (error) {
console.error("Error generating caption:", error);
}
};
Loading

0 comments on commit 4ac23f3

Please sign in to comment.