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

Function GetNote

pkg/server/operations/notes.go:27–47  ·  view source on GitHub ↗

GetNote retrieves a note for the given user

(db *gorm.DB, uuid string, user *database.User)

Source from the content-addressed store, hash-verified

25
26// GetNote retrieves a note for the given user
27func GetNote(db *gorm.DB, uuid string, user *database.User) (database.Note, bool, error) {
28 zeroNote := database.Note{}
29 if !helpers.ValidateUUID(uuid) {
30 return zeroNote, false, nil
31 }
32
33 var note database.Note
34 err := database.PreloadNote(db.Where("notes.uuid = ? AND deleted = ?", uuid, false)).Find(&note).Error
35
36 if errors.Is(err, gorm.ErrRecordNotFound) {
37 return zeroNote, false, nil
38 } else if err != nil {
39 return zeroNote, false, errors.Wrap(err, "finding note")
40 }
41
42 if ok := permissions.ViewNote(user, note); !ok {
43 return zeroNote, false, nil
44 }
45
46 return note, true, nil
47}

Callers 3

getNoteMethod · 0.92
TestGetNoteFunction · 0.85
TestGetNote_nonexistentFunction · 0.85

Calls 3

ValidateUUIDFunction · 0.92
PreloadNoteFunction · 0.92
ViewNoteFunction · 0.92

Tested by 2

TestGetNoteFunction · 0.68
TestGetNote_nonexistentFunction · 0.68