mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
parent
3c650187c5
commit
e6b5aea147
5 changed files with 7 additions and 3 deletions
|
|
@ -27,7 +27,7 @@ import (
|
|||
|
||||
// CreateNote creates a note with the next usn and updates the user's max_usn.
|
||||
// It returns the created note.
|
||||
func (a *App) CreateNote(user database.User, bookUUID, content string, addedOn *int64, editedOn *int64, public bool) (database.Note, error) {
|
||||
func (a *App) CreateNote(user database.User, bookUUID, content string, addedOn *int64, editedOn *int64, public bool, origin string) (database.Note, error) {
|
||||
tx := a.DB.Begin()
|
||||
|
||||
nextUSN, err := incrementUserUSN(tx, user.ID)
|
||||
|
|
@ -65,6 +65,7 @@ func (a *App) CreateNote(user database.User, bookUUID, content string, addedOn *
|
|||
Body: content,
|
||||
Public: public,
|
||||
Encrypted: false,
|
||||
Client: origin,
|
||||
}
|
||||
if err := tx.Create(¬e).Error; err != nil {
|
||||
tx.Rollback()
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ func TestCreateNote(t *testing.T) {
|
|||
})
|
||||
|
||||
tx := testutils.DB.Begin()
|
||||
if _, err := a.CreateNote(user, b1.UUID, "note content", tc.addedOn, tc.editedOn, false); err != nil {
|
||||
if _, err := a.CreateNote(user, b1.UUID, "note content", tc.addedOn, tc.editedOn, false, ""); err != nil {
|
||||
tx.Rollback()
|
||||
t.Fatal(errors.Wrap(err, "deleting note"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ type Note struct {
|
|||
Deleted bool `json:"-" gorm:"default:false"`
|
||||
Encrypted bool `json:"-" gorm:"default:false"`
|
||||
NoteReview NoteReview `json:"-"`
|
||||
Client string `gorm:"index"`
|
||||
}
|
||||
|
||||
// User is a model for a user
|
||||
|
|
|
|||
|
|
@ -281,6 +281,7 @@ func logging(inner http.Handler) http.HandlerFunc {
|
|||
inner.ServeHTTP(&lw, r)
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"origin": r.Header.Get("Origin"),
|
||||
"remoteAddr": lookupIP(r),
|
||||
"uri": r.RequestURI,
|
||||
"statusCode": lw.statusCode,
|
||||
|
|
|
|||
|
|
@ -195,7 +195,8 @@ func (a *API) CreateNote(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
note, err := a.App.CreateNote(user, params.BookUUID, params.Content, params.AddedOn, params.EditedOn, false)
|
||||
origin := r.Header.Get("Origin")
|
||||
note, err := a.App.CreateNote(user, params.BookUUID, params.Content, params.AddedOn, params.EditedOn, false, origin)
|
||||
if err != nil {
|
||||
HandleError(w, "creating note", err, http.StatusInternalServerError)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue