Skip to content

Commit d8056fc

Browse files
authored
release 4/14 (2) (#697)
2 parents 31f506e + abb74bb commit d8056fc

File tree

5 files changed

+120
-5
lines changed

5 files changed

+120
-5
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- DropForeignKey
2+
ALTER TABLE "Enrollment" DROP CONSTRAINT "Enrollment_courseId_fkey";
3+
4+
-- DropForeignKey
5+
ALTER TABLE "Slot" DROP CONSTRAINT "Slot_courseId_fkey";
6+
7+
-- AlterTable
8+
ALTER TABLE "Message" ALTER COLUMN "isPicture" DROP DEFAULT;
9+
10+
-- AddForeignKey
11+
ALTER TABLE "Slot" ADD CONSTRAINT "Slot_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE;
12+
13+
-- AddForeignKey
14+
ALTER TABLE "Enrollment" ADD CONSTRAINT "Enrollment_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE;

server/prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ model Course {
9292
// コマ。1つの講義に対して複数存在しうる。
9393
model Slot {
9494
id Int @id @default(autoincrement())
95-
course Course @relation(fields: [courseId], references: [id])
95+
course Course @relation(fields: [courseId], references: [id], onDelete: Cascade)
9696
courseId String
9797
period Int // 1-6. 0 の場合はなし (集中など)
9898
day Day // 曜日。other の場合は集中など
@@ -104,7 +104,7 @@ model Enrollment {
104104
id Int @id @default(autoincrement())
105105
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
106106
userId Int
107-
course Course @relation(fields: [courseId], references: [id])
107+
course Course @relation(fields: [courseId], references: [id], onDelete: Cascade)
108108
courseId String
109109
110110
@@unique([userId, courseId])

server/src/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/common
22
/seeds/data.json
3+
/seeds/json
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
3+
4+
import { prisma } from "../database/client";
5+
6+
// シ楽バス形式のデータを読み込む。
7+
const FILE_PATH = path.join(__dirname, "data.json");
8+
9+
async function main() {
10+
const jsonData = JSON.parse(fs.readFileSync(FILE_PATH, "utf-8"));
11+
12+
const coursesData = jsonData.map(
13+
(course: {
14+
code: string;
15+
titleJp: string;
16+
lecturerJp: string;
17+
}) => {
18+
const { code, titleJp, lecturerJp } = course;
19+
return {
20+
id: code,
21+
name: titleJp,
22+
teacher: lecturerJp,
23+
};
24+
},
25+
);
26+
27+
await prisma.course.createMany({
28+
data: coursesData,
29+
});
30+
31+
const slotsData: {
32+
day: "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun" | "other";
33+
period: number;
34+
courseId: string;
35+
}[] = [];
36+
37+
for (const courseData of jsonData) {
38+
const { code, periods } = courseData;
39+
40+
for (const period of periods) {
41+
const [dayJp, periodStr] = period.split("");
42+
const day =
43+
dayJp === "月"
44+
? "mon"
45+
: dayJp === "火"
46+
? "tue"
47+
: dayJp === "水"
48+
? "wed"
49+
: dayJp === "木"
50+
? "thu"
51+
: dayJp === "金"
52+
? "fri"
53+
: dayJp === "土"
54+
? "sat"
55+
: dayJp === "日"
56+
? "sun"
57+
: "other";
58+
59+
slotsData.push({
60+
day,
61+
period: Number.parseInt(periodStr) || 0,
62+
courseId: code,
63+
});
64+
}
65+
}
66+
67+
await prisma.slot.createMany({
68+
data: slotsData,
69+
skipDuplicates: true,
70+
});
71+
72+
console.log("Data inserted successfully!");
73+
}
74+
75+
main()
76+
.then(async () => {
77+
await prisma.$disconnect();
78+
})
79+
.catch(async (e) => {
80+
console.error(e);
81+
await prisma.$disconnect();
82+
process.exit(1);
83+
});

web/components/course/components/SelectCourseDialog.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default function SelectCourseDialog({
2020
handleCoursesUpdate: (courses: Course[]) => void;
2121
}) {
2222
const [availableCourses, setAvailableCourses] = useState<Course[]>([]);
23+
const [searchText, setSearchText] = useState("");
2324
const [filteredAvailableCourses, setFilteredAvailableCourses] = useState<
2425
Course[]
2526
>([]);
@@ -48,7 +49,14 @@ export default function SelectCourseDialog({
4849
onClick={(e) => e.stopPropagation()}
4950
>
5051
<form className="modal-backdrop">
51-
<button type="button" onClick={onClose}>
52+
<button
53+
type="button"
54+
onClick={() => {
55+
setSearchText("");
56+
setFilteredAvailableCourses(availableCourses);
57+
onClose();
58+
}}
59+
>
5260
閉じる
5361
</button>
5462
</form>
@@ -64,7 +72,11 @@ export default function SelectCourseDialog({
6472
<button
6573
type="button"
6674
className="btn btn-ghost btn-sm absolute top-3 right-3"
67-
onClick={onClose}
75+
onClick={() => {
76+
setSearchText("");
77+
setFilteredAvailableCourses(availableCourses);
78+
onClose();
79+
}}
6880
>
6981
閉じる
7082
</button>
@@ -102,9 +114,12 @@ export default function SelectCourseDialog({
102114
type="text"
103115
placeholder="授業名で検索"
104116
className="input input-bordered mt-4 w-full"
117+
value={searchText}
105118
onChange={(e) => {
119+
const text = e.target.value.trim();
120+
setSearchText(text);
106121
const newFilteredCourses = availableCourses.filter((course) =>
107-
course.name.includes(e.target.value.trim()),
122+
course.name.includes(text),
108123
);
109124
setFilteredAvailableCourses(newFilteredCourses);
110125
}}
@@ -140,6 +155,8 @@ export default function SelectCourseDialog({
140155
onClose={() => {
141156
setConfirmDialogStatus("closed");
142157
setNewCourse(null);
158+
setSearchText("");
159+
setFilteredAvailableCourses(availableCourses);
143160
onClose();
144161
}}
145162
onCancel={() => {

0 commit comments

Comments
 (0)