Adding structure and testing around title support
This commit is contained in:
@@ -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(¬e); 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(¬e); 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
|
||||
|
||||
Reference in New Issue
Block a user