Skip to content

Commit

Permalink
refactor: remove task domain
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Jul 15, 2024
1 parent 76d4a26 commit 7fb613f
Show file tree
Hide file tree
Showing 18 changed files with 12 additions and 388 deletions.
20 changes: 0 additions & 20 deletions client/pages/console/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,3 @@
border-radius: 8px;
box-shadow: 2px 2px 12px #0004;
}

.controls {
display: flex;
gap: 8px;
align-items: center;
padding: 12px 16px;
}

.textInput {
width: 200px;
padding: 4px 8px;
border-radius: 4px;
}

.btn {
padding: 4px 8px;
margin-left: auto;
cursor: pointer;
border-radius: 4px;
}
70 changes: 2 additions & 68 deletions client/pages/console/index.page.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,12 @@
import type { TaskEntity } from 'common/types/task';
import type { UserEntity } from 'common/types/user';
import { Loading } from 'components/Loading/Loading';
import { Layout } from 'layouts/Layout';
import type { FormEvent } from 'react';
import { useEffect, useState } from 'react';
import { apiClient } from 'utils/apiClient';
import { returnNull } from 'utils/returnNull';
import styles from './index.module.css';

const Main = (props: { user: UserEntity }) => {
const [tasks, setTasks] = useState<TaskEntity[]>();
const [label, setLabel] = useState('');
const fetchTasks = async () => {
const tasks = await apiClient.public.tasks.$get().catch(returnNull);

if (tasks !== null) setTasks(tasks);
};
const createTask = async (e: FormEvent) => {
e.preventDefault();

await apiClient.public.tasks.post({ body: { label } }).catch(returnNull);
setLabel('');
await fetchTasks();
};
const toggleDone = async (task: TaskEntity) => {
await apiClient.public.tasks
._taskId(task.id)
.patch({ body: { done: !task.done } })
.catch(returnNull);
await fetchTasks();
};
const deleteTask = async (task: TaskEntity) => {
await apiClient.public.tasks._taskId(task.id).delete().catch(returnNull);
await fetchTasks();
};

useEffect(() => {
fetchTasks();
}, []);

if (!tasks) return <Loading visible />;

const Main = (_: { user: UserEntity }) => {
return (
<div className={styles.container}>
<div>Todo list of {props.user.name}</div>
<div className={styles.main}>
<div className={styles.card}>
<form onSubmit={createTask}>
<div className={styles.controls}>
<input
value={label}
className={styles.textInput}
type="text"
placeholder="Todo task"
onChange={(e) => setLabel(e.target.value)}
/>
<input className={styles.btn} disabled={label === ''} type="submit" value="ADD" />
</div>
</form>
</div>
{tasks.map((task) => (
<div key={task.id} className={styles.card}>
<div className={styles.controls}>
<input type="checkbox" checked={task.done} onChange={() => toggleDone(task)} />
<span>{task.label}</span>
<input
type="button"
value="DELETE"
className={styles.btn}
onClick={() => deleteTask(task)}
/>
</div>
</div>
))}
<div className={styles.card}></div>
</div>
</div>
);
Expand Down
23 changes: 0 additions & 23 deletions server/api/public/tasks/_taskId@string/controller.ts

This file was deleted.

18 changes: 0 additions & 18 deletions server/api/public/tasks/_taskId@string/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions server/api/public/tasks/_taskId@string/validators.ts

This file was deleted.

37 changes: 0 additions & 37 deletions server/api/public/tasks/controller.ts

This file was deleted.

31 changes: 0 additions & 31 deletions server/api/public/tasks/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion server/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export const BRANDED_ID_NAMES = [
'deletableUser',
'userPool',
'userPoolClient',
'task',
] as const;
12 changes: 0 additions & 12 deletions server/common/types/task.ts

This file was deleted.

3 changes: 0 additions & 3 deletions server/domain/task/model/taskEntity.ts

This file was deleted.

24 changes: 0 additions & 24 deletions server/domain/task/model/taskMethod.ts

This file was deleted.

24 changes: 0 additions & 24 deletions server/domain/task/repository/taskCommand.ts

This file was deleted.

24 changes: 0 additions & 24 deletions server/domain/task/repository/taskQuery.ts

This file was deleted.

12 changes: 0 additions & 12 deletions server/domain/task/service/taskValidator.ts

This file was deleted.

35 changes: 0 additions & 35 deletions server/domain/task/useCase/taskUseCase.ts

This file was deleted.

10 changes: 10 additions & 0 deletions server/prisma/migrations/20240715163953_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:
- You are about to drop the `Task` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
PRAGMA foreign_keys=off;
DROP TABLE "Task";
PRAGMA foreign_keys=on;
7 changes: 0 additions & 7 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,3 @@ model UserPoolClient {
UserPool UserPool @relation(fields: [userPoolId], references: [id])
userPoolId String
}

model Task {
id String @id
label String
done Boolean
createdAt DateTime
}
Loading

0 comments on commit 7fb613f

Please sign in to comment.