chore(linting): changes to make clean-transactional-propsal_lint pass… (#10072)

This commit is contained in:
Iraq
2025-06-13 17:05:37 +02:00
committed by GitHub
parent d857c12b0f
commit d75a45ebed
22 changed files with 1024 additions and 1015 deletions

View File

@@ -1,175 +1,175 @@
package domain
import (
"context"
"time"
)
// import (
// "context"
// "time"
// )
// EmailVerifiedCommand verifies an email address for a user.
type EmailVerifiedCommand struct {
UserID string `json:"userId"`
Email *Email `json:"email"`
}
// // EmailVerifiedCommand verifies an email address for a user.
// type EmailVerifiedCommand struct {
// UserID string `json:"userId"`
// Email *Email `json:"email"`
// }
func NewEmailVerifiedCommand(userID string, isVerified bool) *EmailVerifiedCommand {
return &EmailVerifiedCommand{
UserID: userID,
Email: &Email{
VerifiedAt: time.Time{},
},
}
}
// func NewEmailVerifiedCommand(userID string, isVerified bool) *EmailVerifiedCommand {
// return &EmailVerifiedCommand{
// UserID: userID,
// Email: &Email{
// VerifiedAt: time.Time{},
// },
// }
// }
// String implements [Commander].
func (cmd *EmailVerifiedCommand) String() string {
return "EmailVerifiedCommand"
}
// // String implements [Commander].
// func (cmd *EmailVerifiedCommand) String() string {
// return "EmailVerifiedCommand"
// }
var (
_ Commander = (*EmailVerifiedCommand)(nil)
_ SetEmailOpt = (*EmailVerifiedCommand)(nil)
)
// var (
// _ Commander = (*EmailVerifiedCommand)(nil)
// _ SetEmailOpt = (*EmailVerifiedCommand)(nil)
// )
// Execute implements [Commander]
func (cmd *EmailVerifiedCommand) Execute(ctx context.Context, opts *CommandOpts) error {
repo := userRepo(opts.DB).Human()
return repo.Update(ctx, repo.IDCondition(cmd.UserID), repo.SetEmailVerifiedAt(time.Time{}))
}
// // Execute implements [Commander]
// func (cmd *EmailVerifiedCommand) Execute(ctx context.Context, opts *CommandOpts) error {
// repo := userRepo(opts.DB).Human()
// return repo.Update(ctx, repo.IDCondition(cmd.UserID), repo.SetEmailVerifiedAt(time.Time{}))
// }
// applyOnSetEmail implements [SetEmailOpt]
func (cmd *EmailVerifiedCommand) applyOnSetEmail(setEmailCmd *SetEmailCommand) {
cmd.UserID = setEmailCmd.UserID
cmd.Email.Address = setEmailCmd.Email
setEmailCmd.verification = cmd
}
// // applyOnSetEmail implements [SetEmailOpt]
// func (cmd *EmailVerifiedCommand) applyOnSetEmail(setEmailCmd *SetEmailCommand) {
// cmd.UserID = setEmailCmd.UserID
// cmd.Email.Address = setEmailCmd.Email
// setEmailCmd.verification = cmd
// }
// SendCodeCommand sends a verification code to the user's email address.
// If the URLTemplate is not set it will use the default of the organization / instance.
type SendCodeCommand struct {
UserID string `json:"userId"`
Email string `json:"email"`
URLTemplate *string `json:"urlTemplate"`
generator *generateCodeCommand
}
// // SendCodeCommand sends a verification code to the user's email address.
// // If the URLTemplate is not set it will use the default of the organization / instance.
// type SendCodeCommand struct {
// UserID string `json:"userId"`
// Email string `json:"email"`
// URLTemplate *string `json:"urlTemplate"`
// generator *generateCodeCommand
// }
var (
_ Commander = (*SendCodeCommand)(nil)
_ SetEmailOpt = (*SendCodeCommand)(nil)
)
// var (
// _ Commander = (*SendCodeCommand)(nil)
// _ SetEmailOpt = (*SendCodeCommand)(nil)
// )
func NewSendCodeCommand(userID string, urlTemplate *string) *SendCodeCommand {
return &SendCodeCommand{
UserID: userID,
generator: &generateCodeCommand{},
URLTemplate: urlTemplate,
}
}
// func NewSendCodeCommand(userID string, urlTemplate *string) *SendCodeCommand {
// return &SendCodeCommand{
// UserID: userID,
// generator: &generateCodeCommand{},
// URLTemplate: urlTemplate,
// }
// }
// String implements [Commander].
func (cmd *SendCodeCommand) String() string {
return "SendCodeCommand"
}
// // String implements [Commander].
// func (cmd *SendCodeCommand) String() string {
// return "SendCodeCommand"
// }
// Execute implements [Commander]
func (cmd *SendCodeCommand) Execute(ctx context.Context, opts *CommandOpts) error {
if err := cmd.ensureEmail(ctx, opts); err != nil {
return err
}
if err := cmd.ensureURL(ctx, opts); err != nil {
return err
}
// // Execute implements [Commander]
// func (cmd *SendCodeCommand) Execute(ctx context.Context, opts *CommandOpts) error {
// if err := cmd.ensureEmail(ctx, opts); err != nil {
// return err
// }
// if err := cmd.ensureURL(ctx, opts); err != nil {
// return err
// }
if err := opts.Invoker.Invoke(ctx, cmd.generator, opts); err != nil {
return err
}
// TODO: queue notification
// if err := opts.Invoker.Invoke(ctx, cmd.generator, opts); err != nil {
// return err
// }
// // TODO: queue notification
return nil
}
// return nil
// }
func (cmd *SendCodeCommand) ensureEmail(ctx context.Context, opts *CommandOpts) error {
if cmd.Email != "" {
return nil
}
repo := userRepo(opts.DB).Human()
email, err := repo.GetEmail(ctx, repo.IDCondition(cmd.UserID))
if err != nil || !email.VerifiedAt.IsZero() {
return err
}
cmd.Email = email.Address
return nil
}
// func (cmd *SendCodeCommand) ensureEmail(ctx context.Context, opts *CommandOpts) error {
// if cmd.Email != "" {
// return nil
// }
// repo := userRepo(opts.DB).Human()
// email, err := repo.GetEmail(ctx, repo.IDCondition(cmd.UserID))
// if err != nil || !email.VerifiedAt.IsZero() {
// return err
// }
// cmd.Email = email.Address
// return nil
// }
func (cmd *SendCodeCommand) ensureURL(ctx context.Context, opts *CommandOpts) error {
if cmd.URLTemplate != nil && *cmd.URLTemplate != "" {
return nil
}
_, _ = ctx, opts
// TODO: load default template
return nil
}
// func (cmd *SendCodeCommand) ensureURL(ctx context.Context, opts *CommandOpts) error {
// if cmd.URLTemplate != nil && *cmd.URLTemplate != "" {
// return nil
// }
// _, _ = ctx, opts
// // TODO: load default template
// return nil
// }
// applyOnSetEmail implements [SetEmailOpt]
func (cmd *SendCodeCommand) applyOnSetEmail(setEmailCmd *SetEmailCommand) {
cmd.UserID = setEmailCmd.UserID
cmd.Email = setEmailCmd.Email
setEmailCmd.verification = cmd
}
// // applyOnSetEmail implements [SetEmailOpt]
// func (cmd *SendCodeCommand) applyOnSetEmail(setEmailCmd *SetEmailCommand) {
// cmd.UserID = setEmailCmd.UserID
// cmd.Email = setEmailCmd.Email
// setEmailCmd.verification = cmd
// }
// ReturnCodeCommand creates the code and returns it to the caller.
// The caller gets the code by calling the Code field after the command got executed.
type ReturnCodeCommand struct {
UserID string `json:"userId"`
Email string `json:"email"`
Code string `json:"code"`
generator *generateCodeCommand
}
// // ReturnCodeCommand creates the code and returns it to the caller.
// // The caller gets the code by calling the Code field after the command got executed.
// type ReturnCodeCommand struct {
// UserID string `json:"userId"`
// Email string `json:"email"`
// Code string `json:"code"`
// generator *generateCodeCommand
// }
var (
_ Commander = (*ReturnCodeCommand)(nil)
_ SetEmailOpt = (*ReturnCodeCommand)(nil)
)
// var (
// _ Commander = (*ReturnCodeCommand)(nil)
// _ SetEmailOpt = (*ReturnCodeCommand)(nil)
// )
func NewReturnCodeCommand(userID string) *ReturnCodeCommand {
return &ReturnCodeCommand{
UserID: userID,
generator: &generateCodeCommand{},
}
}
// func NewReturnCodeCommand(userID string) *ReturnCodeCommand {
// return &ReturnCodeCommand{
// UserID: userID,
// generator: &generateCodeCommand{},
// }
// }
// String implements [Commander].
func (cmd *ReturnCodeCommand) String() string {
return "ReturnCodeCommand"
}
// // String implements [Commander].
// func (cmd *ReturnCodeCommand) String() string {
// return "ReturnCodeCommand"
// }
// Execute implements [Commander]
func (cmd *ReturnCodeCommand) Execute(ctx context.Context, opts *CommandOpts) error {
if err := cmd.ensureEmail(ctx, opts); err != nil {
return err
}
if err := opts.Invoker.Invoke(ctx, cmd.generator, opts); err != nil {
return err
}
cmd.Code = cmd.generator.code
return nil
}
// // Execute implements [Commander]
// func (cmd *ReturnCodeCommand) Execute(ctx context.Context, opts *CommandOpts) error {
// if err := cmd.ensureEmail(ctx, opts); err != nil {
// return err
// }
// if err := opts.Invoker.Invoke(ctx, cmd.generator, opts); err != nil {
// return err
// }
// cmd.Code = cmd.generator.code
// return nil
// }
func (cmd *ReturnCodeCommand) ensureEmail(ctx context.Context, opts *CommandOpts) error {
if cmd.Email != "" {
return nil
}
repo := userRepo(opts.DB).Human()
email, err := repo.GetEmail(ctx, repo.IDCondition(cmd.UserID))
if err != nil || !email.VerifiedAt.IsZero() {
return err
}
cmd.Email = email.Address
return nil
}
// func (cmd *ReturnCodeCommand) ensureEmail(ctx context.Context, opts *CommandOpts) error {
// if cmd.Email != "" {
// return nil
// }
// repo := userRepo(opts.DB).Human()
// email, err := repo.GetEmail(ctx, repo.IDCondition(cmd.UserID))
// if err != nil || !email.VerifiedAt.IsZero() {
// return err
// }
// cmd.Email = email.Address
// return nil
// }
// applyOnSetEmail implements [SetEmailOpt]
func (cmd *ReturnCodeCommand) applyOnSetEmail(setEmailCmd *SetEmailCommand) {
cmd.UserID = setEmailCmd.UserID
cmd.Email = setEmailCmd.Email
setEmailCmd.verification = cmd
}
// // applyOnSetEmail implements [SetEmailOpt]
// func (cmd *ReturnCodeCommand) applyOnSetEmail(setEmailCmd *SetEmailCommand) {
// cmd.UserID = setEmailCmd.UserID
// cmd.Email = setEmailCmd.Email
// setEmailCmd.verification = cmd
// }