Commit d247cbd

Eric Bower  ·  2025-12-17 19:31:56 -0500 EST
parent bd8d606
feat: find access logs by pubkey
3 files changed,  +31, -0
+1, -0
......@@ -466,6 +466,7 @@ type DB interface {
466466 InsertAccessLog(log *AccessLog) error
467467 FindAccessLogs(userID string, fromDate *time.Time) ([]*AccessLog, error)
468468 FindPubkeysInAccessLogs(userID string) ([]string, error)
469+ FindAccessLogsByPubkey(pubkey string, fromDate *time.Time) ([]*AccessLog, error)
469470
470471 Close() error
471472 }
+26, -0
......@@ -1967,6 +1967,32 @@ func (me *PsqlDB) FindAccessLogs(userID string, fromDate *time.Time) ([]*db.Acce
19671967 return logs, nil
19681968 }
19691969
1970+func (me *PsqlDB) FindAccessLogsByPubkey(pubkey string, fromDate *time.Time) ([]*db.AccessLog, error) {
1971+ logs := []*db.AccessLog{}
1972+ rs, err := me.Db.Query(
1973+ `SELECT id, user_id, service, pubkey, identity, created_at FROM access_logs WHERE pubkey=$1 AND created_at >= $2 ORDER BY created_at DESC`, pubkey, fromDate)
1974+ if err != nil {
1975+ return nil, err
1976+ }
1977+
1978+ for rs.Next() {
1979+ log := db.AccessLog{}
1980+ err := rs.Scan(
1981+ &log.ID, &log.UserID, &log.Service, &log.Pubkey, &log.Identity, &log.CreatedAt,
1982+ )
1983+ if err != nil {
1984+ return nil, err
1985+ }
1986+ logs = append(logs, &log)
1987+ }
1988+
1989+ if rs.Err() != nil {
1990+ return nil, rs.Err()
1991+ }
1992+
1993+ return logs, nil
1994+}
1995+
19701996 func (me *PsqlDB) FindPubkeysInAccessLogs(userID string) ([]string, error) {
19711997 pubkeys := []string{}
19721998 rs, err := me.Db.Query(
+4, -0
......@@ -293,6 +293,10 @@ func (me *StubDB) FindAccessLogs(userID string, fromDate *time.Time) ([]*db.Acce
293293 return nil, errNotImpl
294294 }
295295
296+func (me *StubDB) FindAccessLogsByPubkey(pubkey string, fromDate *time.Time) ([]*db.AccessLog, error) {
297+ return nil, errNotImpl
298+}
299+
296300 func (me *StubDB) FindPubkeysInAccessLogs(userID string) ([]string, error) {
297301 return []string{}, errNotImpl
298302 }