Adding structure and testing around title support

This commit is contained in:
2026-03-18 22:22:04 +00:00
parent 0935788b69
commit 8749ff3c03
4 changed files with 147 additions and 29 deletions

View File

@@ -85,12 +85,13 @@ func (s *Server) getNotes(w http.ResponseWriter, r *http.Request) {
func (s *Server) createNote(w http.ResponseWriter, r *http.Request) {
note := struct {
Content string `json:"content"`
Title string `json:"title"`
}{}
if err := json.NewDecoder(r.Body).Decode(&note); err != nil {
http.Error(w, "invalid request body", http.StatusBadRequest)
return
}
createdNote, err := s.noteRepo.CreateNote(r.Context(), note.Content)
createdNote, err := s.noteRepo.CreateNote(r.Context(), note.Content, note.Title)
if err != nil {
s.getErrorResponse(w, err)
return
@@ -122,12 +123,13 @@ func (s *Server) updateNoteByID(w http.ResponseWriter, r *http.Request) {
}
note := struct {
Content string `json:"content"`
Title string `json:"title"`
}{}
if err := json.NewDecoder(r.Body).Decode(&note); err != nil {
http.Error(w, "invalid request body", http.StatusBadRequest)
return
}
updatedNote, err := s.noteRepo.UpdateNote(r.Context(), id, note.Content)
updatedNote, err := s.noteRepo.UpdateNote(r.Context(), id, repository.NoteUpdate{Content: note.Content, Title: note.Title})
if err != nil {
s.getErrorResponse(w, err)
return