usecase

package
v0.0.0-...-1f1dc5f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package usecase coordinates operation and login audit workflows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListFilter

type ListFilter struct {
	Offset   int
	Limit    int
	Page     int
	PageSize int
}

ListFilter is the validated store-facing pagination window.

type ListInput

type ListInput struct {
	Page     int
	PageSize int
}

ListInput carries pagination for audit lists.

type LoginInput

type LoginInput struct {
	AdminID   int64
	Username  string
	IP        string
	UserAgent string
	Success   bool
	Reason    string
}

LoginInput carries a sign-in attempt audit request.

type LoginListOutput

type LoginListOutput struct {
	Items    []LoginLog
	Page     int
	PageSize int
	Total    int
}

LoginListOutput is a paginated login log result.

type LoginLog

type LoginLog struct {
	ID        int64     `json:"id"`
	AdminID   int64     `json:"admin_id"`
	Username  string    `json:"username"`
	IP        string    `json:"ip"`
	UserAgent string    `json:"user_agent"`
	Success   bool      `json:"success"`
	Reason    string    `json:"reason"`
	CreatedAt time.Time `json:"created_at"`
}

LoginLog is the adapter-facing login log DTO.

type OperationInput

type OperationInput struct {
	ActorID    int64
	Action     string
	Resource   string
	ResourceID string
	Method     string
	Path       string
	IP         string
	UserAgent  string
	Success    bool
	Message    string
}

OperationInput carries an operation log request from adapters.

type OperationListOutput

type OperationListOutput struct {
	Items    []OperationLog
	Page     int
	PageSize int
	Total    int
}

OperationListOutput is a paginated operation log result.

type OperationLog

type OperationLog struct {
	ID         int64     `json:"id"`
	ActorID    int64     `json:"actor_id"`
	Action     string    `json:"action"`
	Resource   string    `json:"resource"`
	ResourceID string    `json:"resource_id"`
	Method     string    `json:"method"`
	Path       string    `json:"path"`
	IP         string    `json:"ip"`
	UserAgent  string    `json:"user_agent"`
	Success    bool      `json:"success"`
	Message    string    `json:"message"`
	CreatedAt  time.Time `json:"created_at"`
}

OperationLog is the adapter-facing operation log DTO.

type ResolveSystemErrorInput

type ResolveSystemErrorInput struct {
	ID         int64
	ResolverID int64
	Note       string
}

ResolveSystemErrorInput carries a resolution decision for one error log.

type Store

type Store interface {
	RecordOperation(context.Context, domain.OperationLog) (domain.OperationLog, error)
	FindOperationLog(context.Context, int64) (domain.OperationLog, error)
	ListOperationLogs(context.Context, ListFilter) ([]domain.OperationLog, int, error)
	DeleteOperationLogs(context.Context, []int64) error
	RecordLogin(context.Context, domain.LoginLog) (domain.LoginLog, error)
	FindLoginLog(context.Context, int64) (domain.LoginLog, error)
	ListLoginLogs(context.Context, ListFilter) ([]domain.LoginLog, int, error)
	DeleteLoginLogs(context.Context, []int64) error
	RecordSystemError(context.Context, domain.SystemErrorLog) (domain.SystemErrorLog, error)
	FindSystemErrorLog(context.Context, int64) (domain.SystemErrorLog, error)
	ListSystemErrorLogs(context.Context, ListFilter) ([]domain.SystemErrorLog, int, error)
	UpdateSystemErrorLog(context.Context, domain.SystemErrorLog) (domain.SystemErrorLog, error)
	DeleteSystemErrorLogs(context.Context, []int64) error
}

Store persists operation and login logs.

type SystemErrorInput

type SystemErrorInput struct {
	Code      int
	Message   string
	Detail    string
	Method    string
	Path      string
	IP        string
	UserAgent string
	RequestID string
	UserID    string
}

SystemErrorInput carries an internal API failure record from the server boundary.

type SystemErrorListOutput

type SystemErrorListOutput struct {
	Items    []SystemErrorLog
	Page     int
	PageSize int
	Total    int
}

SystemErrorListOutput is a paginated system error log result.

type SystemErrorLog

type SystemErrorLog struct {
	ID          int64      `json:"id"`
	Code        int        `json:"code"`
	Message     string     `json:"message"`
	Detail      string     `json:"detail"`
	Method      string     `json:"method"`
	Path        string     `json:"path"`
	IP          string     `json:"ip"`
	UserAgent   string     `json:"user_agent"`
	RequestID   string     `json:"request_id"`
	UserID      string     `json:"user_id"`
	Resolved    bool       `json:"resolved"`
	ResolveNote string     `json:"resolve_note"`
	ResolvedBy  int64      `json:"resolved_by"`
	ResolvedAt  *time.Time `json:"resolved_at,omitempty"`
	CreatedAt   time.Time  `json:"created_at"`
}

SystemErrorLog is the adapter-facing system error log DTO.

type Usecase

type Usecase struct {
	// contains filtered or unexported fields
}

Usecase coordinates audit log rules.

func New

func New(store Store) *Usecase

New creates an audit usecase.

func (*Usecase) DeleteLoginLogs

func (u *Usecase) DeleteLoginLogs(ctx context.Context, ids []int64) error

DeleteLoginLogs removes login logs by id.

func (*Usecase) DeleteOperationLogs

func (u *Usecase) DeleteOperationLogs(ctx context.Context, ids []int64) error

DeleteOperationLogs removes operation logs by id.

func (*Usecase) DeleteSystemErrorLogs

func (u *Usecase) DeleteSystemErrorLogs(ctx context.Context, ids []int64) error

DeleteSystemErrorLogs removes system error logs by id.

func (*Usecase) FindLoginLog

func (u *Usecase) FindLoginLog(ctx context.Context, id int64) (LoginLog, error)

FindLoginLog returns one login log by id.

func (*Usecase) FindOperationLog

func (u *Usecase) FindOperationLog(ctx context.Context, id int64) (OperationLog, error)

FindOperationLog returns one operation log by id.

func (*Usecase) FindSystemErrorLog

func (u *Usecase) FindSystemErrorLog(ctx context.Context, id int64) (SystemErrorLog, error)

FindSystemErrorLog returns one system error log by id.

func (*Usecase) ListLoginLogs

func (u *Usecase) ListLoginLogs(ctx context.Context, input ListInput) (LoginListOutput, error)

ListLoginLogs returns paginated login logs.

func (*Usecase) ListOperationLogs

func (u *Usecase) ListOperationLogs(ctx context.Context, input ListInput) (OperationListOutput, error)

ListOperationLogs returns paginated operation logs.

func (*Usecase) ListSystemErrorLogs

func (u *Usecase) ListSystemErrorLogs(ctx context.Context, input ListInput) (SystemErrorListOutput, error)

ListSystemErrorLogs returns paginated internal API failure logs.

func (*Usecase) RecordLogin

func (u *Usecase) RecordLogin(ctx context.Context, input LoginInput) (LoginLog, error)

RecordLogin stores one login attempt log.

func (*Usecase) RecordOperation

func (u *Usecase) RecordOperation(ctx context.Context, input OperationInput) (OperationLog, error)

RecordOperation stores one operation log.

func (*Usecase) RecordSystemError

func (u *Usecase) RecordSystemError(ctx context.Context, input SystemErrorInput) (SystemErrorLog, error)

RecordSystemError stores one internal API failure log.

func (*Usecase) ReopenSystemErrorLog

func (u *Usecase) ReopenSystemErrorLog(ctx context.Context, id int64) (SystemErrorLog, error)

ReopenSystemErrorLog clears a wrong resolution from one system error.

func (*Usecase) ResolveSystemErrorLog

func (u *Usecase) ResolveSystemErrorLog(ctx context.Context, input ResolveSystemErrorInput) (SystemErrorLog, error)

ResolveSystemErrorLog records that an administrator handled one system error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL