This commit is contained in:
parent
8ee314b0bb
commit
daf401a2f7
9 changed files with 73 additions and 61 deletions
|
@ -4,11 +4,12 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.mstar.dev/mstar/goutils/other"
|
||||
"git.mstar.dev/mstar/linstrom/storage"
|
||||
"git.mstar.dev/mstar/linstrom/util"
|
||||
httputil "git.mstar.dev/mstar/goutils/http"
|
||||
"github.com/google/jsonapi"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/storage"
|
||||
"git.mstar.dev/mstar/linstrom/util"
|
||||
)
|
||||
|
||||
// Notes
|
||||
|
@ -21,11 +22,11 @@ func linstromGetNote(w http.ResponseWriter, r *http.Request) {
|
|||
case nil:
|
||||
// Found, progress past switch statement
|
||||
case storage.ErrEntryNotFound:
|
||||
other.HttpErr(w, HttpErrIdNotFound, "Note not found", http.StatusNotFound)
|
||||
httputil.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(
|
||||
httputil.HttpErr(
|
||||
w,
|
||||
HttpErrIdDbFailure,
|
||||
"Failed to get note from db",
|
||||
|
@ -39,7 +40,7 @@ func linstromGetNote(w http.ResponseWriter, r *http.Request) {
|
|||
Err(err).
|
||||
Str("note-id", noteId).
|
||||
Msg("Failed to convert note into linstrom api form")
|
||||
other.HttpErr(
|
||||
httputil.HttpErr(
|
||||
w,
|
||||
HttpErrIdConversionFailure,
|
||||
"Failed to convert note",
|
||||
|
@ -50,7 +51,7 @@ func linstromGetNote(w http.ResponseWriter, r *http.Request) {
|
|||
err = jsonapi.MarshalPayload(w, note)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("note", note).Msg("Failed to marshal and send note")
|
||||
other.HttpErr(
|
||||
httputil.HttpErr(
|
||||
w,
|
||||
HttpErrIdJsonMarshalFail,
|
||||
"Failed to convert note",
|
||||
|
@ -66,7 +67,7 @@ func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
|||
log := hlog.FromRequest(r)
|
||||
|
||||
if !ok {
|
||||
other.HttpErr(
|
||||
httputil.HttpErr(
|
||||
w,
|
||||
HttpErrIdNotAuthenticated,
|
||||
"Needs a valid session to create new notes",
|
||||
|
@ -79,7 +80,7 @@ func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
|||
err := jsonapi.UnmarshalPayload(r.Body, &newNote)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to unmarshal body")
|
||||
other.HttpErr(w, HttpErrIdBadRequest, "bad body", http.StatusBadRequest)
|
||||
httputil.HttpErr(w, HttpErrIdBadRequest, "bad body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,7 @@ func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
|||
Str("actor-id", actorId).
|
||||
Str("target-id", newNote.AuthorId).
|
||||
Msg("Blocking attempt at creating a note for a different account")
|
||||
other.HttpErr(
|
||||
httputil.HttpErr(
|
||||
w,
|
||||
HttpErrIdNotAllowed,
|
||||
"creating a note for someone else is not allowed",
|
||||
|
@ -114,7 +115,7 @@ func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("note", newNote).Msg("Failed to insert new note into storage")
|
||||
other.HttpErr(
|
||||
httputil.HttpErr(
|
||||
w,
|
||||
HttpErrIdDbFailure,
|
||||
"Failed to insert new note into db",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue