mirror of
https://github.com/navidrome/navidrome.git
synced 2026-03-04 06:35:52 +00:00
35 lines
752 B
Go
35 lines
752 B
Go
package persistence
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
. "github.com/Masterminds/squirrel"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/pocketbase/dbx"
|
|
)
|
|
|
|
type scrobbleRepository struct {
|
|
sqlRepository
|
|
}
|
|
|
|
func NewScrobbleRepository(ctx context.Context, db dbx.Builder) model.ScrobbleRepository {
|
|
r := &scrobbleRepository{}
|
|
r.ctx = ctx
|
|
r.db = db
|
|
r.tableName = "scrobbles"
|
|
return r
|
|
}
|
|
|
|
func (r *scrobbleRepository) RecordScrobble(mediaFileID string, submissionTime time.Time) error {
|
|
userID := loggedUser(r.ctx).ID
|
|
values := map[string]any{
|
|
"media_file_id": mediaFileID,
|
|
"user_id": userID,
|
|
"submission_time": submissionTime.Unix(),
|
|
}
|
|
insert := Insert(r.tableName).SetMap(values)
|
|
_, err := r.executeSQL(insert)
|
|
return err
|
|
}
|