Work on new note endpoint
This commit is contained in:
parent
5f94a71415
commit
e76490f637
3 changed files with 41 additions and 1 deletions
|
@ -58,7 +58,45 @@ func linstromGetNote(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func linstromUpdateNote(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromNewNote(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromNewNote(w http.ResponseWriter, r *http.Request) {
|
||||
store := StorageFromRequest(r)
|
||||
actorId, ok := ActorIdFromRequest(r)
|
||||
log := hlog.FromRequest(r)
|
||||
|
||||
if !ok {
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdNotAuthenticated,
|
||||
"Needs a valid session to create new notes",
|
||||
http.StatusUnauthorized,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
newNote := linstromNote{}
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
if newNote.AuthorId != actorId {
|
||||
log.Debug().
|
||||
Str("actor-id", actorId).
|
||||
Str("target-id", newNote.AuthorId).
|
||||
Msg("Blocking attempt at creating a note for a different account")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdNotAllowed,
|
||||
"creating a note for someone else is not allowed",
|
||||
http.StatusForbidden,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = store.CreateNote()
|
||||
}
|
||||
func linstromDeleteNote(w http.ResponseWriter, r *http.Request) {}
|
||||
|
||||
// Reactions
|
||||
|
|
|
@ -19,4 +19,5 @@ const (
|
|||
HttpErrIdAlreadyExists
|
||||
HttpErrIdNotFound
|
||||
HttpErrIdConversionFailure
|
||||
HttpErrIdNotAllowed
|
||||
)
|
||||
|
|
|
@ -122,6 +122,7 @@ func (s *Storage) UpdateNote(note *Note) error {
|
|||
}
|
||||
|
||||
func (s *Storage) CreateNote() (*Note, error) {
|
||||
defer util.Untrace(util.Trace(&log.Logger))
|
||||
// TODO: Think of good arguments and implement me
|
||||
panic("not implemented")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue