Work on getting notes API
This commit is contained in:
parent
f656757710
commit
8a4c19dd17
9 changed files with 153 additions and 11 deletions
|
@ -2,16 +2,61 @@ package server
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/google/jsonapi"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"gitlab.com/mstarongitlab/goutils/other"
|
||||
"gitlab.com/mstarongitlab/linstrom/storage"
|
||||
)
|
||||
|
||||
// Notes
|
||||
func linstromGetNote(w http.ResponseWriter, r *http.Request) {
|
||||
store := StorageFromRequest(r)
|
||||
noteId := NoteIdFromRequest(r)
|
||||
note, err := store.FindNoteById(noteId)
|
||||
_ = note
|
||||
_ = err
|
||||
log := hlog.FromRequest(r)
|
||||
sNote, err := store.FindNoteById(noteId)
|
||||
switch err {
|
||||
case nil:
|
||||
// Found, progress past switch statement
|
||||
case storage.ErrEntryNotFound:
|
||||
other.HttpErr(w, HttpErrIdNotFound, "Note not found", http.StatusNotFound)
|
||||
return
|
||||
default:
|
||||
log.Error().Err(err).Str("note-id", noteId).Msg("Failed to get note from db")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdDbFailure,
|
||||
"Failed to get note from db",
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
return
|
||||
}
|
||||
note, err := convertNoteStorageToLinstrom(sNote, store)
|
||||
if err != nil {
|
||||
log.Error().
|
||||
Err(err).
|
||||
Str("note-id", noteId).
|
||||
Msg("Failed to convert note into linstrom api form")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdConversionFailure,
|
||||
"Failed to convert note",
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
return
|
||||
}
|
||||
err = jsonapi.MarshalPayload(w, note)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("note", note).Msg("Failed to marshal and send note")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdJsonMarshalFail,
|
||||
"Failed to convert note",
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func linstromUpdateNote(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromNewNote(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromDeleteNote(w http.ResponseWriter, r *http.Request) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue