You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
836 B
35 lines
836 B
package commands |
|
|
|
import ( |
|
"context" |
|
|
|
"autostore/internal/application/interfaces" |
|
) |
|
|
|
type LoginUserCommand struct { |
|
authService interfaces.IAuthService |
|
logger interfaces.ILogger |
|
} |
|
|
|
func NewLoginUserCommand( |
|
authService interfaces.IAuthService, |
|
logger interfaces.ILogger, |
|
) *LoginUserCommand { |
|
return &LoginUserCommand{ |
|
authService: authService, |
|
logger: logger, |
|
} |
|
} |
|
|
|
func (c *LoginUserCommand) Execute(ctx context.Context, username string, password string) (string, error) { |
|
c.logger.Info(ctx, "Executing login command", "username", username) |
|
|
|
token, err := c.authService.Authenticate(ctx, username, password) |
|
if err != nil { |
|
c.logger.Warn(ctx, "Authentication failed", "username", username, "error", err) |
|
return "", err |
|
} |
|
|
|
c.logger.Info(ctx, "Login successful", "username", username) |
|
return token, nil |
|
}
|
|
|