2024-10-29 15:09:21 +00:00
|
|
|
package server
|
|
|
|
|
2024-10-30 15:05:20 +00:00
|
|
|
import (
|
|
|
|
"net/http"
|
2024-11-18 11:18:57 +00:00
|
|
|
|
|
|
|
"github.com/google/jsonapi"
|
|
|
|
"github.com/rs/zerolog/hlog"
|
|
|
|
"gitlab.com/mstarongitlab/goutils/other"
|
|
|
|
"gitlab.com/mstarongitlab/linstrom/storage"
|
2024-10-30 15:05:20 +00:00
|
|
|
)
|
2024-10-29 15:09:21 +00:00
|
|
|
|
|
|
|
// Notes
|
2024-10-30 15:05:20 +00:00
|
|
|
func linstromGetNote(w http.ResponseWriter, r *http.Request) {
|
|
|
|
store := StorageFromRequest(r)
|
|
|
|
noteId := NoteIdFromRequest(r)
|
2024-11-18 11:18:57 +00:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
}
|
2024-10-30 15:05:20 +00:00
|
|
|
}
|
2024-11-18 11:18:57 +00:00
|
|
|
|
2024-10-29 15:09:21 +00:00
|
|
|
func linstromUpdateNote(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromNewNote(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromDeleteNote(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
|
|
|
|
// Reactions
|
|
|
|
func linstromGetReactions(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromAddReaction(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromDeleteReaction(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromUpdateReaction(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
|
|
|
|
// Boosts
|
|
|
|
func linstromGetBoosts(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromAddBoost(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromRemoveBoost(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
|
|
|
|
// Quotes
|
|
|
|
func linstromGetQuotes(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromAddQuote(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
|
|
|
|
// No delete quote since quotes are their own notes with an extra attribute
|
|
|
|
|
2024-10-30 15:05:20 +00:00
|
|
|
// Pinning
|
2024-10-29 15:09:21 +00:00
|
|
|
func linstromPinNote(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromUnpinNote(w http.ResponseWriter, r *http.Request) {}
|
2024-10-30 15:05:20 +00:00
|
|
|
|
|
|
|
// Reporting
|
|
|
|
func linstromReportNote(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
func linstromRetractReportNote(w http.ResponseWriter, r *http.Request) {}
|
|
|
|
|
|
|
|
// Admin tools
|
|
|
|
// TODO: Figure out more admin tools for managing notes
|
|
|
|
// Delete can be done via normal note delete, common permission check
|
|
|
|
func linstromForceCWNote(w http.ResponseWriter, r *http.Request) {}
|