Skip to content

Commit

Permalink
Updated at (#24)
Browse files Browse the repository at this point in the history
* [backend/frontend] chore: Refactor api
  • Loading branch information
helloitsdave authored Feb 8, 2024
1 parent 5903134 commit 829d5ed
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
4 changes: 2 additions & 2 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ model Note {
id Int @id @default(autoincrement())
title String
content String
created_at DateTime @default(now())
updated_at DateTime @default(now())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
}
36 changes: 18 additions & 18 deletions backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,56 @@ export const seed = [
{
"title": "Meeting Notes",
"content": "Discussed project timelines and goals.",
"created_at": "2024-02-05T23:33:42.252Z",
"updated_at": "2024-02-05T23:33:42.252Z",
"createdAt": "2024-02-05T23:33:42.252Z",
"updatedAt": "2024-02-05T23:33:42.252Z",
},
{
"title": "Shopping List",
"content": "Milk, eggs, bread, and fruits.",
"created_at": "2024-02-05T23:33:42.253Z",
"updated_at": "2024-02-05T23:33:42.253Z",
"createdAt": "2024-02-05T23:33:42.253Z",
"updatedAt": "2024-02-05T23:33:42.253Z",
},
{
"title": "Recipe",
"content": "Ingredients: Chicken, tomatoes, onions, garlic.",
"created_at": "2024-02-05T23:33:42.254Z",
"updated_at": "2024-02-05T23:33:42.254Z",
"createdAt": "2024-02-05T23:33:42.254Z",
"updatedAt": "2024-02-05T23:33:42.254Z",
},
{
"title": "Ideas",
"content": "Brainstorming ideas for the next feature release. 🚀",
"created_at": "2024-02-05T23:33:42.255Z",
"updated_at": "2024-02-05T23:33:42.255Z",
"createdAt": "2024-02-05T23:33:42.255Z",
"updatedAt": "2024-02-05T23:33:42.255Z",
},
{
"title": "Personal Goals",
"content": "Exercise for 30 minutes daily. Read a book every week.",
"created_at": "2024-02-05T23:33:42.256Z",
"updated_at": "2024-02-05T23:33:42.256Z",
"createdAt": "2024-02-05T23:33:42.256Z",
"updatedAt": "2024-02-05T23:33:42.256Z",
},
{
"title": "Fête d'anniversaire",
"content": "Préparer une surprise pour la fête d'anniversaire.",
"created_at": "2024-02-05T23:33:42.257Z",
"updated_at": "2024-02-05T23:33:42.257Z",
"createdAt": "2024-02-05T23:33:42.257Z",
"updatedAt": "2024-02-05T23:33:42.257Z",
},
{
"title": "日本旅行",
"content": "計画: 東京、京都、大阪を訪れる。",
"created_at": "2024-02-05T23:33:42.258Z",
"updated_at": "2024-02-05T23:33:42.258Z",
"createdAt": "2024-02-05T23:33:42.258Z",
"updatedAt": "2024-02-05T23:33:42.258Z",
},
{
"title": "Семейный ужин",
"content": "Приготовить вкусный ужин для всей семьи.",
"created_at": "2024-02-05T23:33:42.259Z",
"updated_at": "2024-02-05T23:33:42.259Z",
"createdAt": "2024-02-05T23:33:42.259Z",
"updatedAt": "2024-02-05T23:33:42.259Z",
},
{
"title": "Coding Project",
"content": "Implement new features using React and Express.",
"created_at": "2024-02-05T23:33:42.260Z",
"updated_at": "2024-02-05T23:33:42.260Z",
"createdAt": "2024-02-05T23:33:42.260Z",
"updatedAt": "2024-02-05T23:33:42.260Z",
}
];

Expand Down
4 changes: 2 additions & 2 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ app.use(cors())

app.get("/api/notes", async (req, res) => {
try {
const notes = await prisma.note.findMany({ orderBy: { updated_at: "desc" }});
const notes = await prisma.note.findMany({ orderBy: { updatedAt: "desc" }});
res.json(notes);
}
catch (error) {
Expand Down Expand Up @@ -50,7 +50,7 @@ app.put("/api/notes/:id", async (req, res) => {
try {
const updatedNote = await prisma.note.update({
where: { id },
data: { title, content, updated_at: new Date()},
data: { title, content, updatedAt: new Date()},
});
res.json(updatedNote);
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/service/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ test("Get the list of Notes", async () => {

expect(getNoteResponse.body[getNoteResponse.body.length - 1]).toStrictEqual({
content: "Discussed project timelines and goals.",
created_at: "2024-02-05T23:33:42.252Z",
createdAt: "2024-02-05T23:33:42.252Z",
id: 1,
title: "Meeting Notes",
updated_at: "2024-02-05T23:33:42.252Z",
updatedAt: "2024-02-05T23:33:42.252Z",
});
});

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function App() {
{connectionIssue && (
<h3 className="connection-warning">Warning: API Connection Issue</h3>
)}
<div className="app-content">
<NoteForm
onCancel={handleCancel}
selectedNote={selectedNote}
Expand All @@ -97,6 +98,7 @@ function App() {
handleEdit={handleEdit}
/>
)}
</div>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Note: React.FC<NoteProps> = ({ note, handleEdit, deleteNote }) => {
<div data-testid="note" className="note-item" onClick={handleEdit}>
<h3 data-testid="note-title">{note.title}</h3>
<p className="note-content" data-testid="note-content">{note.content}</p>
<p className="note-updated" data-testid="note-updated">Updated {new Date(note.updatedAt ?? "").toLocaleDateString()}</p>
<div className="notes-header">
<button data-testid='note-delete-button' onClick={handleDeleteMouseDown}>X</button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ type Note = {
id?: number;
title: string;
content: string;
createdAt?: string;
updatedAt?: string;
};

export default Note;

2 comments on commit 829d5ed

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   index.ts100%100%100%
   prisma.ts100%100%100%
src/__mocks__
   prisma.ts100%100%100%

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   App.tsx100%100%100%
src/api
   apiService.ts100%100%100%
src/components
   Note.tsx100%100%100%
   NoteForm.tsx100%100%100%
   NoteGrid.tsx100%100%100%
   Spinner.tsx100%100%100%

Please sign in to comment.