MCPcopy Index your code
hub / github.com/dnote/dnote / V3Show

Method V3Show

pkg/server/controllers/books.go:82–110  ·  view source on GitHub ↗

V3Show gets a book

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

80
81// V3Show gets a book
82func (b *Books) V3Show(w http.ResponseWriter, r *http.Request) {
83 user := context.User(r.Context())
84 if user == nil {
85 handleJSONError(w, app.ErrLoginRequired, "login required")
86 return
87 }
88
89 vars := mux.Vars(r)
90 bookUUID := vars["bookUUID"]
91
92 if !helpers.ValidateUUID(bookUUID) {
93 handleJSONError(w, app.ErrInvalidUUID, "login required")
94 return
95 }
96
97 var book database.Book
98 err := b.app.DB.Where("uuid = ? AND user_id = ?", bookUUID, user.ID).First(&book).Error
99
100 if errors.Is(err, gorm.ErrRecordNotFound) {
101 w.WriteHeader(http.StatusNotFound)
102 return
103 }
104 if err != nil {
105 handleJSONError(w, err, "finding the book")
106 return
107 }
108
109 respondJSON(w, http.StatusOK, presenters.PresentBook(book))
110}
111
112type createBookPayload struct {
113 Name string `schema:"name" json:"name"`

Callers

nothing calls this directly

Calls 6

UserFunction · 0.92
ValidateUUIDFunction · 0.92
PresentBookFunction · 0.92
handleJSONErrorFunction · 0.85
respondJSONFunction · 0.85
WriteHeaderMethod · 0.80

Tested by

no test coverage detected