Skip to content

Commit

Permalink
課題 Task の作成 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-kbot authored Aug 27, 2023
1 parent e4e7b53 commit 3d042c2
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "tasks" (
"id" VARCHAR(255) NOT NULL,
"name" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

CONSTRAINT "tasks_pkey" PRIMARY KEY ("id")
);
9 changes: 9 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ model Participant {
@@map("participants")
}

model Task {
id String @id @db.VarChar(255)
name String @db.VarChar(255)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("tasks")
}
13 changes: 12 additions & 1 deletion backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ async function main() {
update: {},
create: u,
});
console.log(`Created user with id: ${team.id}`);
console.log(`Created team with id: ${team.id}`);
}
for (let i = 1; i <= 80; i++) {
const task = await prisma.task.upsert({
where: { id: `${i}` },
update: {},
create: {
id: `${i}`,
name: `課題${i}`,
},
});
console.log(`Created task with id: ${task.id}`);
}
console.log(`Seeding finished.`);
}
Expand Down
19 changes: 19 additions & 0 deletions backend/src/domain/task/task-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { v4 as uuidv4 } from 'uuid';

export class TaskId {
private constructor(private readonly id: string) {
this.id = id;
}

static build(): TaskId {
return new TaskId(uuidv4());
}

static rebuild(value: string): TaskId {
return new TaskId(value);
}

get value(): string {
return this.id;
}
}
15 changes: 15 additions & 0 deletions backend/src/domain/task/task-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export class TaskName {
private constructor(private name: string) {}

static build(name: string): TaskName {
return new TaskName(name);
}

static rebuild(name: string): TaskName {
return new TaskName(name);
}

get value(): string {
return this.name;
}
}
36 changes: 36 additions & 0 deletions backend/src/domain/task/task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { TaskId } from './task-id';
import { TaskName } from './task-name';

interface TeamProps {
id: TaskId;
name: TaskName;
createdAt: Date;
updatedAt: Date;
}

type TaskBuildProps = Omit<TeamProps, 'createdAt' | 'updatedAt'>;

export class Task {
private constructor(private props: TeamProps) {}

static build(props: TaskBuildProps): Task {
return new Task({
...props,
createdAt: new Date(),
updatedAt: new Date(),
});
}

static rebuild(props: TeamProps): Task {
return new Task({
...props,
});
}

getAllProperties() {
return {
id: this.props.id.value,
name: this.props.name.value,
};
}
}

0 comments on commit 3d042c2

Please sign in to comment.