Skip to content

usecase ​

go
import "github.com/prescriptoo/prescriptoo-api/services/identity/internal/usecase"

Package usecase defines the identity application's contracts and use cases.

Index ​

Variables ​

ErrUnavailable indicates missing dependencies, such as a documentation-only module.

go
var ErrUnavailable = errors.New("authentication dependencies are unavailable")

type Auth ​

Auth holds shared dependencies for identity operations.

go
type Auth struct {
    // contains filtered or unexported fields
}

func NewAuth ​

go
func NewAuth(d Dependencies) (*Auth, error)

NewAuth wires authentication dependencies and prepares timing protection.

type AuthenticatedDTO ​

AuthenticatedDTO carries the bearer authorization header.

go
type AuthenticatedDTO struct{ Authorization string }

type ChangePasswordDTO ​

ChangePasswordDTO carries credentials for a password change.

go
type ChangePasswordDTO struct{ Authorization, CurrentPassword, NewPassword string }

type ChangePasswordUseCase ​

ChangePasswordUseCase changes a password and revokes sessions.

go
type ChangePasswordUseCase struct {
    // contains filtered or unexported fields
}

func NewChangePasswordUseCase ​

go
func NewChangePasswordUseCase(auth *Auth) *ChangePasswordUseCase

NewChangePasswordUseCase wires the operation to its dependencies.

func (*ChangePasswordUseCase) Execute ​

go
func (uc *ChangePasswordUseCase) Execute(ctx context.Context, input ChangePasswordDTO) error

Execute changes a password and revokes sessions.

type ConfirmEmailVerificationUseCase ​

ConfirmEmailVerificationUseCase consumes an email verification token.

go
type ConfirmEmailVerificationUseCase struct {
    // contains filtered or unexported fields
}

func NewConfirmEmailVerificationUseCase ​

go
func NewConfirmEmailVerificationUseCase(auth *Auth) *ConfirmEmailVerificationUseCase

NewConfirmEmailVerificationUseCase wires the operation to its dependencies.

func (*ConfirmEmailVerificationUseCase) Execute ​

go
func (uc *ConfirmEmailVerificationUseCase) Execute(ctx context.Context, input TokenDTO) error

Execute consumes an email verification token.

type Dependencies ​

Dependencies supplies persistence, cryptography, and the shared email sender.

go
type Dependencies struct {
    Users                 ports.UserRepository
    Sessions              ports.SessionRepository
    Accounts              ports.AccountRepository
    Passwords             ports.PasswordHasher
    Tokens                ports.AccessTokens
    Email                 email.Sender
    AccessTTL, RefreshTTL time.Duration
}

type EmailDTO ​

EmailDTO identifies an email recipient.

go
type EmailDTO struct{ Email string }

type ForgotPasswordUseCase ​

ForgotPasswordUseCase requests a password-reset token.

go
type ForgotPasswordUseCase struct {
    // contains filtered or unexported fields
}

func NewForgotPasswordUseCase ​

go
func NewForgotPasswordUseCase(auth *Auth) *ForgotPasswordUseCase

NewForgotPasswordUseCase wires the operation to its dependencies.

func (*ForgotPasswordUseCase) Execute ​

go
func (uc *ForgotPasswordUseCase) Execute(ctx context.Context, input EmailDTO) (*Message, error)

Execute requests a password-reset token.

type GetAccountUseCase ​

GetAccountUseCase reads an identity account for an internal service call.

go
type GetAccountUseCase struct {
    // contains filtered or unexported fields
}

func NewGetAccountUseCase ​

go
func NewGetAccountUseCase(auth *Auth) *GetAccountUseCase

NewGetAccountUseCase wires account lookup to the authentication dependencies.

func (*GetAccountUseCase) Execute ​

go
func (uc *GetAccountUseCase) Execute(ctx context.Context, userID string) (*User, error)

Execute retrieves a user by ID without exposing private identity fields.

type GetMeUseCase ​

GetMeUseCase returns the authenticated user profile.

go
type GetMeUseCase struct {
    // contains filtered or unexported fields
}

func NewGetMeUseCase ​

go
func NewGetMeUseCase(auth *Auth) *GetMeUseCase

NewGetMeUseCase wires the operation to authentication dependencies.

func (*GetMeUseCase) Execute ​

go
func (uc *GetMeUseCase) Execute(ctx context.Context, input AuthenticatedDTO) (*User, error)

Execute returns the authenticated user profile.

type ListSessionsUseCase ​

ListSessionsUseCase lists the authenticated user’s active sessions.

go
type ListSessionsUseCase struct {
    // contains filtered or unexported fields
}

func NewListSessionsUseCase ​

go
func NewListSessionsUseCase(auth *Auth) *ListSessionsUseCase

NewListSessionsUseCase wires the operation to its dependencies.

func (*ListSessionsUseCase) Execute ​

go
func (uc *ListSessionsUseCase) Execute(ctx context.Context, input AuthenticatedDTO) (*Sessions, error)

Execute lists the authenticated user’s active sessions.

type LoginDTO ​

LoginDTO carries login credentials.

go
type LoginDTO struct{ Email, Password, IPAddress, UserAgent string }

type LoginUseCase ​

LoginUseCase authenticates credentials and creates a session.

go
type LoginUseCase struct {
    // contains filtered or unexported fields
}

func NewLoginUseCase ​

go
func NewLoginUseCase(auth *Auth) *LoginUseCase

NewLoginUseCase wires the operation to authentication dependencies.

func (*LoginUseCase) Execute ​

go
func (uc *LoginUseCase) Execute(ctx context.Context, input LoginDTO) (result *TokenPair, err error)

Execute authenticates credentials and creates a session.

func (*LoginUseCase) ExecuteWithAuthorization ​

go
func (uc *LoginUseCase) ExecuteWithAuthorization(ctx context.Context, input LoginDTO, authorize func(context.Context, string) error) (result *TokenPair, err error)

ExecuteWithAuthorization checks caller-owned eligibility after authenticating an active account and before issuing credentials or persisting a session.

type LogoutAllUseCase ​

LogoutAllUseCase revokes all sessions belonging to the authenticated user.

go
type LogoutAllUseCase struct {
    // contains filtered or unexported fields
}

func NewLogoutAllUseCase ​

go
func NewLogoutAllUseCase(auth *Auth) *LogoutAllUseCase

NewLogoutAllUseCase wires the operation to its dependencies.

func (*LogoutAllUseCase) Execute ​

go
func (uc *LogoutAllUseCase) Execute(ctx context.Context, input AuthenticatedDTO) error

Execute revokes all sessions belonging to the authenticated user.

type LogoutUseCase ​

LogoutUseCase revokes the session identified by a refresh token.

go
type LogoutUseCase struct {
    // contains filtered or unexported fields
}

func NewLogoutUseCase ​

go
func NewLogoutUseCase(auth *Auth) *LogoutUseCase

NewLogoutUseCase wires the operation to authentication dependencies.

func (*LogoutUseCase) Execute ​

go
func (uc *LogoutUseCase) Execute(ctx context.Context, input RefreshDTO) error

Execute revokes the session identified by a refresh token.

type Message ​

Message is the public result of an identity operation.

go
type Message struct {
    Message string `json:"message" example:"If the account is eligible, email delivery has been requested." doc:"Generic acknowledgement independent of account existence."`
}

type Principal ​

Principal is the result of validating an Authorization header.

go
type Principal struct {
    UserID    string
    SessionID string
}

type Provisioner ​

Provisioner atomically saves an account and its initiating admin's audit event.

go
type Provisioner interface {
    Create(context.Context, audit.OperationContext, *domain.User) error
}

type RefreshDTO ​

RefreshDTO carries a refresh token.

go
type RefreshDTO struct{ RefreshToken string }

type RefreshUseCase ​

RefreshUseCase rotates credentials for an existing session.

go
type RefreshUseCase struct {
    // contains filtered or unexported fields
}

func NewRefreshUseCase ​

go
func NewRefreshUseCase(auth *Auth) *RefreshUseCase

NewRefreshUseCase wires the operation to authentication dependencies.

func (*RefreshUseCase) Execute ​

go
func (uc *RefreshUseCase) Execute(ctx context.Context, input RefreshDTO) (*TokenPair, error)

Execute rotates credentials for an existing session.

type RegisterDTO ​

RegisterDTO carries account registration fields.

go
type RegisterDTO struct{ Email, Password, Name string }

type RegisterUseCase ​

RegisterUseCase creates an active account.

go
type RegisterUseCase struct {
    // contains filtered or unexported fields
}

func NewRegisterUseCase ​

go
func NewRegisterUseCase(auth *Auth) *RegisterUseCase

NewRegisterUseCase wires the operation to authentication dependencies.

func (*RegisterUseCase) Execute ​

go
func (uc *RegisterUseCase) Execute(ctx context.Context, input RegisterDTO) (result *User, err error)

Execute creates an active account.

type RequestEmailVerificationUseCase ​

RequestEmailVerificationUseCase requests an email verification token.

go
type RequestEmailVerificationUseCase struct {
    // contains filtered or unexported fields
}

func NewRequestEmailVerificationUseCase ​

go
func NewRequestEmailVerificationUseCase(auth *Auth) *RequestEmailVerificationUseCase

NewRequestEmailVerificationUseCase wires the operation to its dependencies.

func (*RequestEmailVerificationUseCase) Execute ​

go
func (uc *RequestEmailVerificationUseCase) Execute(ctx context.Context, input EmailDTO) (*Message, error)

Execute requests an email verification token.

type ResetPasswordDTO ​

ResetPasswordDTO carries a reset token and replacement password.

go
type ResetPasswordDTO struct{ Token, NewPassword string }

type ResetPasswordUseCase ​

ResetPasswordUseCase resets a password and revokes sessions.

go
type ResetPasswordUseCase struct {
    // contains filtered or unexported fields
}

func NewResetPasswordUseCase ​

go
func NewResetPasswordUseCase(auth *Auth) *ResetPasswordUseCase

NewResetPasswordUseCase wires the operation to its dependencies.

func (*ResetPasswordUseCase) Execute ​

go
func (uc *ResetPasswordUseCase) Execute(ctx context.Context, input ResetPasswordDTO) error

Execute resets a password and revokes sessions.

type RevokeSessionDTO ​

RevokeSessionDTO identifies a session to revoke.

go
type RevokeSessionDTO struct{ Authorization, SessionID string }

type RevokeSessionUseCase ​

RevokeSessionUseCase revokes a session owned by the authenticated user.

go
type RevokeSessionUseCase struct {
    // contains filtered or unexported fields
}

func NewRevokeSessionUseCase ​

go
func NewRevokeSessionUseCase(auth *Auth) *RevokeSessionUseCase

NewRevokeSessionUseCase wires the operation to its dependencies.

func (*RevokeSessionUseCase) Execute ​

go
func (uc *RevokeSessionUseCase) Execute(ctx context.Context, input RevokeSessionDTO) error

Execute revokes a session owned by the authenticated user.

type Session ​

Session is the public result of an identity operation.

go
type Session struct {
    ID           string    `json:"id" format:"uuid" example:"cd20a97b-5107-44db-bf05-66c86c54aa91" doc:"Session identifier for revocation."`
    DeviceName   string    `json:"device_name" example:"Chrome on Linux" doc:"Device label, if available."`
    DeviceType   string    `json:"device_type" example:"web" doc:"Device category, if available."`
    IPAddress    string    `json:"ip_address" example:"192.0.2.1" doc:"IP address associated with the session."`
    UserAgent    string    `json:"user_agent" example:"Mozilla/5.0" doc:"Client user agent, if available."`
    Current      bool      `json:"current" example:"true" doc:"Whether this is the session used for the request."`
    CreatedAt    time.Time `json:"created_at" doc:"Session creation timestamp."`
    LastActiveAt time.Time `json:"last_active_at" doc:"Most recent session activity timestamp."`
    ExpiresAt    time.Time `json:"expires_at" doc:"Session expiration timestamp."`
}

type Sessions ​

Sessions is the public result of an identity operation.

go
type Sessions struct {
    Sessions []Session `json:"sessions" nullable:"false" doc:"Active sessions, ordered by most recent activity; empty when none exist."`
}

type TokenDTO ​

TokenDTO carries a single-use token.

go
type TokenDTO struct{ Token string }

type TokenPair ​

TokenPair is the public result of an identity operation.

go
type TokenPair = identitypublic.TokenPair

type UpdateMeDTO ​

UpdateMeDTO carries replacement profile fields.

go
type UpdateMeDTO struct{ Authorization, Name, Phone, AvatarURL string }

type UpdateMeUseCase ​

UpdateMeUseCase updates editable profile fields.

go
type UpdateMeUseCase struct {
    // contains filtered or unexported fields
}

func NewUpdateMeUseCase ​

go
func NewUpdateMeUseCase(auth *Auth) *UpdateMeUseCase

NewUpdateMeUseCase wires the operation to its dependencies.

func (*UpdateMeUseCase) Execute ​

go
func (uc *UpdateMeUseCase) Execute(ctx context.Context, input UpdateMeDTO) (*User, error)

Execute updates editable profile fields.

type User ​

User is the public result of an identity operation.

go
type User struct {
    ID            string    `json:"id" format:"uuid" example:"b3f1c812-479a-4f37-a67b-0e089cc827f4" doc:"Unique user identifier."`
    Email         string    `json:"email" format:"email" example:"user@example.com" doc:"Account email address."`
    Name          string    `json:"name" example:"Jane Doe" doc:"Display name."`
    Phone         string    `json:"phone" example:"+8801700000000" doc:"Contact phone number, or an empty string when unset."`
    AvatarURL     string    `json:"avatar_url" example:"https://example.com/avatar.png" doc:"Avatar URL, or an empty string when unset."`
    Status        string    `json:"status" example:"active" doc:"Account lifecycle status."`
    EmailVerified bool      `json:"email_verified" example:"false" doc:"Whether the account email has been verified."`
    CreatedAt     time.Time `json:"created_at" doc:"Account creation timestamp in RFC 3339 format."`
    UpdatedAt     time.Time `json:"updated_at" doc:"Last profile update timestamp in RFC 3339 format."`
}

func ProvisionAccount ​

go
func ProvisionAccount(ctx context.Context, auth *Auth, writer Provisioner, op audit.OperationContext, input RegisterDTO) (*User, error)

ProvisionAccount validates and hashes credentials before atomically saving the account and its audit entry.

func RegisterWithRepository ​

go
func RegisterWithRepository(ctx context.Context, auth *Auth, users ports.UserRepository, input RegisterDTO) (*User, error)

RegisterWithRepository keeps validation and password hashing owned by Identity while allowing onboarding to use transaction-bound persistence.

type ValidateAuthorizationUseCase ​

ValidateAuthorizationUseCase validates an access token and persistent session without exposing identity domain entities.

go
type ValidateAuthorizationUseCase struct {
    // contains filtered or unexported fields
}

func NewValidateAuthorizationUseCase ​

go
func NewValidateAuthorizationUseCase(auth *Auth) *ValidateAuthorizationUseCase

NewValidateAuthorizationUseCase wires access token and session validation.

func (*ValidateAuthorizationUseCase) Execute ​

go
func (uc *ValidateAuthorizationUseCase) Execute(ctx context.Context, authorization string) (*Principal, error)

Execute validates an Authorization header and returns its user and active session IDs.

type ValidateTokenUseCase ​

ValidateTokenUseCase validates an access token against its persistent session.

go
type ValidateTokenUseCase struct {
    // contains filtered or unexported fields
}

func NewValidateTokenUseCase ​

go
func NewValidateTokenUseCase(auth *Auth) *ValidateTokenUseCase

NewValidateTokenUseCase wires the operation to authentication dependencies.

func (*ValidateTokenUseCase) Execute ​

go
func (uc *ValidateTokenUseCase) Execute(ctx context.Context, token string) (*domain.User, error)

Execute validates an access token against its persistent session.

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.