tsk-34: Update last login of user (#37)
Closes #34 Reviewed-on: phoenix/textsender-auth#37 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -3,6 +3,7 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/user"
|
||||
"github.com/google/uuid"
|
||||
@@ -10,11 +11,13 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// TODO: Rename this to ServiceUserStore
|
||||
type ServiceStore interface {
|
||||
CheckWithUsername(ctx context.Context, username string) (bool, error)
|
||||
GetWithUsername(ctx context.Context, username string) (*user.ServiceUser, error)
|
||||
GetWithId(ctx context.Context, id uuid.UUID) (*user.ServiceUser, error)
|
||||
Create(ctx context.Context, serviceUser *user.ServiceUser) error
|
||||
UpdateLastLogin(ctx context.Context, id uuid.UUID, lastLogin time.Time) (int64, error)
|
||||
}
|
||||
|
||||
type PGServiceStore struct {
|
||||
@@ -81,3 +84,12 @@ func (s *PGServiceStore) Create(ctx context.Context, serviceUser *user.ServiceUs
|
||||
&serviceUser.Id, &serviceUser.Created,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *PGServiceStore) UpdateLastLogin(ctx context.Context, id uuid.UUID, lastLogin time.Time) (int64, error) {
|
||||
query := `UPDATE service_users SET last_login = $1 WHERE id = $2`
|
||||
if affected, err := s.db.Exec(ctx, query, lastLogin, id); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
return affected.RowsAffected(), nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user