summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-07-28 21:52:49 +0300
committerPaul Buetow <paul@buetow.org>2024-07-28 21:52:49 +0300
commit9535dc386f568132f986b672528189faec8842bf (patch)
tree040010627821a2f29fcbfb96cab38041b51ffcd2 /internal
parent7fc95c18f169f0bfe0a5bc8a239ec5853619ec59 (diff)
can update/upload entry
Diffstat (limited to 'internal')
-rw-r--r--internal/client/tui/submit.go3
-rw-r--r--internal/server/repository/repository.go2
-rw-r--r--internal/types/entry.go3
3 files changed, 5 insertions, 3 deletions
diff --git a/internal/client/tui/submit.go b/internal/client/tui/submit.go
index 7e1f15c..34f668d 100644
--- a/internal/client/tui/submit.go
+++ b/internal/client/tui/submit.go
@@ -24,8 +24,7 @@ func submitEntry(ctx context.Context, conf client.ClientConfig, filePath string,
servers, err := conf.Servers()
if err == nil {
var entry types.Entry
- entry, err = types.NewEntryFromFile(filePath)
- if err == nil {
+ if entry, err = types.NewEntryFromFile(filePath); err == nil {
err = easyhttp.PostData(ctx, "submit", conf.APIKey, &entry, servers...)
}
}
diff --git a/internal/server/repository/repository.go b/internal/server/repository/repository.go
index 57be3f2..381560c 100644
--- a/internal/server/repository/repository.go
+++ b/internal/server/repository/repository.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "log"
"sync"
"time"
@@ -155,6 +156,7 @@ func (r Repository) Merge(otherEntry types.Entry) error {
entry, ok := r.entries[otherEntry.ID]
if !ok {
+ log.Println("can't find entry with ID", otherEntry.ID, "in local db, create new from copy")
var err error
if entry, err = types.NewEntryFromCopy(otherEntry); err != nil {
return err
diff --git a/internal/types/entry.go b/internal/types/entry.go
index 695c786..21a12ee 100644
--- a/internal/types/entry.go
+++ b/internal/types/entry.go
@@ -61,6 +61,7 @@ func NewEntry(bytes []byte) (Entry, error) {
func NewEntryFromCopy(other Entry) (Entry, error) {
var e Entry
e.initialize()
+ e.ID = other.ID
return e.Update(other)
}
@@ -118,7 +119,7 @@ func (e Entry) Equals(other Entry) bool {
*/
func (e Entry) Update(other Entry) (Entry, error) {
if e.ID != other.ID {
- return e, fmt.Errorf("can update entry only with other entry with same ID: %s %s", e, other)
+ return e, fmt.Errorf("can update entry only with other entry with same ID: this(%s) other(%s)", e, other)
}
e.checksumDirty = true
e.Changed = true