Skip to content

Commit

Permalink
Merge branch 'main' into yama/fix-ranking-design
Browse files Browse the repository at this point in the history
  • Loading branch information
TkymHrt authored Nov 12, 2024
2 parents 8265a14 + 5f366e6 commit 6aa100e
Show file tree
Hide file tree
Showing 23 changed files with 693 additions and 167 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/auto_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and Test

on:
push


jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Set environment variables from .env file1
run: |
echo "${{ secrets.DB_ENV_FILE }}" > .env
- name: Set environment variables from .env file2
working-directory: app
run: |
echo "${{ secrets.ENV_FILE }}" > .env
- name: Build Docker compose up
run: docker compose -f compose.dev.yml up --build -d

- name: npm install
run: docker compose exec app npm install

- name: npm run build
run: docker compose exec app npm run build

- name: Build Docker compose down
run: docker compose down
71 changes: 71 additions & 0 deletions app/package-lock.json

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

4 changes: 4 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
Expand All @@ -27,12 +28,14 @@
"lucide-react": "^0.453.0",
"minio": "^8.0.2",
"next": "14.2.16",
"next-themes": "^0.4.3",
"nodemailer": "^6.9.15",
"openai": "^4.68.4",
"react": "^18",
"react-camera-pro": "^1.4.0",
"react-dom": "^18",
"react-icons": "^5.3.0",
"sonner": "^1.7.0",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7"
},
Expand All @@ -41,6 +44,7 @@
"@svgr/webpack": "^8.1.0",
"@types/formidable": "^3.4.5",
"@types/node": "^20.17.1",
"@types/nodemailer": "^6.4.16",
"@types/react": "^18",
"@types/react-dom": "^18",
"postcss": "^8",
Expand Down
29 changes: 29 additions & 0 deletions app/src/app/api/assignment/latest/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { latestAssignment } from "@/types";
import { prisma } from "@lib/prisma";

// 最新の課題を取得
export async function GET() {
const assignment = await prisma.assignment.findFirst({
include: { word: true },
orderBy: {
date: "desc",
},
});

if (!assignment) {
return new Response(JSON.stringify({ message: "No assignment found for today." }), {
status: 404,
headers: { "Content-Type": "application/json" },
});
}

const latestAssignment: latestAssignment = {
assignmentId: assignment.id,
english: assignment.word.english,
};

return new Response(JSON.stringify(latestAssignment), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
20 changes: 8 additions & 12 deletions app/src/app/api/assignment/today/route.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
;import { prisma } from "@lib/prisma";
import type { Assignment, todayAssignment } from "@/types";
import { prisma } from "@lib/prisma";

// 課題新規作成(ランダム)
export async function GET() {
const startOfToday = new Date();
startOfToday.setHours(0, 0, 0, 0); // 今日の開始時間を設定 (00:00:00)

const endOfToday = new Date();
endOfToday.setHours(23, 59, 59, 999); // 今日の終了時間を設定 (23:59:59)

const assignments = await prisma.assignment.findMany({
where: {
date: {
gte: startOfToday, // 今日の開始時間以上
lte: endOfToday, // 今日の終了時間以下
gte: startOfToday, // 今日の開始時間以上
lte: endOfToday, // 今日の終了時間以下
},
},
include: { word: true },
},
include: { word: true },
});
console.log(assignments);

const todayAssignments: todayAssignment[] = assignments.map((assignment) => {
const todayAssignment: todayAssignment = {
assignmentId: assignment.id,
english: assignment.word.english,
assignTime: assignment.date,
};
return todayAssignment;
})
});

return new Response(JSON.stringify(todayAssignments), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}





21 changes: 11 additions & 10 deletions app/src/app/api/image/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { NextApiResponse } from "next";
import type { NextRequest } from "next/server";

import { OpenAI } from "openai";
import fs from "fs";
import path from "path";

type ResponseData = {
message: string;
Expand All @@ -13,14 +11,21 @@ const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

const BUCKET_NAME = "kz2404";

export async function GET(
req: NextRequest,
res: NextApiResponse<ResponseData>
) {
return await generateCaption()
// クエリパラメータを取得
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}`;

return await generateCaption(imageURL)
.then((caption) => {
console.log(caption);
return new Response(JSON.stringify({ message: caption }), {
return new Response(JSON.stringify({ caption }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
Expand All @@ -35,12 +40,8 @@ export async function GET(
}

// 画像URLからキャプションを生成する関数
const generateCaption = async () => {
export const generateCaption = async (imageUrl: string) => {
try {
// 猿人の画像URL
const imageUrl =
"https://www.cnn.co.jp/storage/2020/01/31/f85a2dac057ec8b6d8e08e9fec7a49e5/t/768/432/d/180226123522-neanderthal-man-super-169.jpg";

const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
Expand Down Expand Up @@ -68,7 +69,7 @@ const generateCaption = async () => {
],
});

const caption = completion.choices[0].message.content;
const caption = await completion.choices[0].message.content;
return caption;
} catch (error) {
console.error("Error generating caption:", error);
Expand Down
4 changes: 2 additions & 2 deletions app/src/app/api/minio/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function POST(req: NextRequest) {
};

try {
const response = await minioClient.putObject(
await minioClient.putObject(
BUCKET_NAME,
image.originalFilename,
fs.createReadStream(image.filepath),
Expand All @@ -69,7 +69,7 @@ export async function POST(req: NextRequest) {
}
});

return new Response(JSON.stringify({ message: '成功' }), {
return new Response(JSON.stringify({ message: "成功" }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
Expand Down
21 changes: 21 additions & 0 deletions app/src/app/api/score/assignment/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,32 @@ export async function GET(req: NextRequest) {
include: { user: true, assignment: true },
});

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

const word: Word | null = await prisma.word.findFirst({
where: { id: scores[0].assignment.wordId },
});



const scoreDetails: ScoreDetail[] = scores.map((score) => {
if(!score.assignment){
return {
id: 0,
assignment: "",
answerIntervalTime: 0,
userName: "",
imageUrl: "",
point: 0,
similarity: 0,
};
}

const answerIntervalTimeMilliseconds =
score.answerTime.getTime() - score.assignment.date.getTime();
const answerIntervalTimeSeconds = answerIntervalTimeMilliseconds / 1000;
Expand Down
Loading

0 comments on commit 6aa100e

Please sign in to comment.