From 26b16cc4111a5d33cc2a176b149d8191967bd333 Mon Sep 17 00:00:00 2001 From: Micheal Wilkinson Date: Tue, 17 Mar 2026 21:31:06 +0000 Subject: [PATCH] refactoring createdat to last update ... it will make sense --- internal/models/note.go | 6 +++--- internal/repository/notes_test.go | 36 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/models/note.go b/internal/models/note.go index 1292cd6..6edd3a6 100644 --- a/internal/models/note.go +++ b/internal/models/note.go @@ -5,7 +5,7 @@ import ( ) type Note struct { - ID int `json:"id"` - CreatedAt time.Time `json:"created_at"` - Content string `json:"content"` + ID int `json:"id"` + LastUpdate time.Time `json:"last_update"` + Content string `json:"content"` } diff --git a/internal/repository/notes_test.go b/internal/repository/notes_test.go index 01c4e79..7954a89 100644 --- a/internal/repository/notes_test.go +++ b/internal/repository/notes_test.go @@ -22,9 +22,9 @@ func TestCreateNote(t *testing.T) { name: "Good note", content: "This is a good note with valid content.", expectedNote: models.Note{ - ID: 1, - CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), //CreatedAt is set by synctest to this specific time - Content: "This is a good note with valid content.", + ID: 1, + LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), //LastUpdate is set by synctest to this specific time + Content: "This is a good note with valid content.", }, expectedError: false, }, @@ -38,9 +38,9 @@ func TestCreateNote(t *testing.T) { name: "Long content", content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", expectedNote: models.Note{ - ID: 2, - CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), - Content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", + ID: 2, + LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), + Content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", }, expectedError: false, }, @@ -65,8 +65,8 @@ func TestCreateNote(t *testing.T) { if note.ID != tc.expectedNote.ID { t.Errorf("expected ID %d but got %d", tc.expectedNote.ID, note.ID) } - if !note.CreatedAt.Equal(tc.expectedNote.CreatedAt) { - t.Errorf("expected CreatedAt %v but got %v", tc.expectedNote.CreatedAt, note.CreatedAt) + if !note.LastUpdate.Equal(tc.expectedNote.LastUpdate) { + t.Errorf("expected LastUpdate %v but got %v", tc.expectedNote.LastUpdate, note.LastUpdate) } fmt.Printf("Test case '%s' passed.\n", tc.name) }) @@ -75,11 +75,11 @@ func TestCreateNote(t *testing.T) { func TestGetNotes(t *testing.T) { notes := []models.Note{ - {ID: 1, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"}, - {ID: 2, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"}, - {ID: 3, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"}, + {ID: 1, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"}, + {ID: 2, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"}, + {ID: 3, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"}, // 4th note was clearly deleted, :sadface: - {ID: 5, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Lorem ipsum note dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}, + {ID: 5, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Lorem ipsum note dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}, } store := &mockNoteStore{Notes: notes} repo := repository.NewNoteRepository(store) @@ -155,14 +155,14 @@ func TestListNotes(t *testing.T) { { name: "Multiple notes", notes: []models.Note{ - {ID: 1, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"}, - {ID: 2, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"}, - {ID: 3, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"}, + {ID: 1, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"}, + {ID: 2, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"}, + {ID: 3, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"}, }, expectedNotes: []models.Note{ - {ID: 1, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"}, - {ID: 2, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"}, - {ID: 3, CreatedAt: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"}, + {ID: 1, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "First note"}, + {ID: 2, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Second note"}, + {ID: 3, LastUpdate: time.Date(0001, 1, 1, 0, 0, 0, 0, time.UTC), Content: "Third note"}, }, expectedError: false, },