You've already forked agentic-coding-workflow
feat(mcp): repository List + UpdateLastUsed + Revoke + DeleteByID
This commit is contained in:
@@ -173,16 +173,40 @@ func (r *pgRepo) GetByID(ctx context.Context, id uuid.UUID) (*MCPToken, error) {
|
|||||||
|
|
||||||
// ===== Stub methods (implemented in subsequent tasks) =====
|
// ===== Stub methods (implemented in subsequent tasks) =====
|
||||||
|
|
||||||
func (r *pgRepo) List(_ context.Context, _ *uuid.UUID, _ bool) ([]*MCPToken, error) {
|
func (r *pgRepo) List(ctx context.Context, callerUserID *uuid.UUID, activeOnly bool) ([]*MCPToken, error) {
|
||||||
panic("not implemented: List")
|
rows, err := r.q.ListMcpTokens(ctx, mcpsqlc.ListMcpTokensParams{
|
||||||
|
CallerUserID: toPgUUIDPtr(callerUserID),
|
||||||
|
ActiveOnly: activeOnly,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errs.Wrap(err, errs.CodeInternal, "list mcp_tokens")
|
||||||
|
}
|
||||||
|
out := make([]*MCPToken, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
t, err := rowToMCPToken(row)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out = append(out, t)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *pgRepo) UpdateLastUsed(_ context.Context, _ uuid.UUID) error {
|
func (r *pgRepo) UpdateLastUsed(ctx context.Context, id uuid.UUID) error {
|
||||||
panic("not implemented: UpdateLastUsed")
|
if err := r.q.UpdateMcpTokenLastUsed(ctx, toPgUUID(id)); err != nil {
|
||||||
|
return errs.Wrap(err, errs.CodeInternal, "update mcp_token last_used_at")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *pgRepo) Revoke(_ context.Context, _ uuid.UUID) (uuid.UUID, error) {
|
func (r *pgRepo) Revoke(ctx context.Context, id uuid.UUID) (uuid.UUID, error) {
|
||||||
panic("not implemented: Revoke")
|
row, err := r.q.RevokeMcpToken(ctx, toPgUUID(id))
|
||||||
|
if err != nil {
|
||||||
|
// pgx.ErrNoRows = 已撤销 / 不存在;统一返 NotFound 让上层细分
|
||||||
|
return uuid.Nil, pgxNoRowsToErrNotFound(err, errs.CodeMcpTokenNotFound,
|
||||||
|
"mcp token not found or already revoked")
|
||||||
|
}
|
||||||
|
return fromPgUUID(row), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *pgRepo) RevokeBySession(_ context.Context, _ uuid.UUID) ([]uuid.UUID, error) {
|
func (r *pgRepo) RevokeBySession(_ context.Context, _ uuid.UUID) ([]uuid.UUID, error) {
|
||||||
@@ -197,6 +221,9 @@ func (r *pgRepo) PurgeExpired(_ context.Context, _ time.Time) (int64, error) {
|
|||||||
panic("not implemented: PurgeExpired")
|
panic("not implemented: PurgeExpired")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *pgRepo) DeleteByID(_ context.Context, _ uuid.UUID) error {
|
func (r *pgRepo) DeleteByID(ctx context.Context, id uuid.UUID) error {
|
||||||
panic("not implemented: DeleteByID")
|
if err := r.q.DeleteMcpTokenByID(ctx, toPgUUID(id)); err != nil {
|
||||||
|
return errs.Wrap(err, errs.CodeInternal, "delete mcp_token")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user