This commit is contained in:
@@ -45,6 +45,33 @@ func (s *JournalStore) InsertImage(ctx context.Context, img domain.JournalImage)
|
||||
return img, err
|
||||
}
|
||||
|
||||
// GetEntry returns a single entry by ID, verifying ownership.
|
||||
func (s *JournalStore) GetEntry(ctx context.Context, entryID, userID string) (domain.JournalEntry, error) {
|
||||
var e domain.JournalEntry
|
||||
err := s.pool.QueryRow(ctx,
|
||||
`SELECT entry_id, user_id, entry_date::text, entry_time::text, title, description, lat, lon, visibility, hashtags, created_at
|
||||
FROM journal_entries WHERE entry_id = $1 AND user_id = $2`,
|
||||
entryID, userID,
|
||||
).Scan(&e.EntryID, &e.UserID, &e.EntryDate, &e.EntryTime,
|
||||
&e.Title, &e.Description, &e.Lat, &e.Lon, &e.Visibility, &e.Hashtags, &e.CreatedAt)
|
||||
return e, err
|
||||
}
|
||||
|
||||
// UpdateEntry updates mutable fields of an existing entry.
|
||||
func (s *JournalStore) UpdateEntry(ctx context.Context, e domain.JournalEntry) error {
|
||||
if e.Hashtags == nil {
|
||||
e.Hashtags = []string{}
|
||||
}
|
||||
_, err := s.pool.Exec(ctx,
|
||||
`UPDATE journal_entries
|
||||
SET entry_time = $1, title = $2, description = $3, lat = $4, lon = $5, visibility = $6, hashtags = $7
|
||||
WHERE entry_id = $8 AND user_id = $9`,
|
||||
e.EntryTime, e.Title, e.Description, e.Lat, e.Lon, e.Visibility, e.Hashtags,
|
||||
e.EntryID, e.UserID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
// ListByDate returns all journal entries for a given date (YYYY-MM-DD), including their images.
|
||||
func (s *JournalStore) ListByDate(ctx context.Context, userID, date string) ([]domain.JournalEntry, error) {
|
||||
rows, err := s.pool.Query(ctx,
|
||||
|
||||
Reference in New Issue
Block a user