mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-31 11:56:33 +08:00
简单基于DDD重构,并实现机器文件及脚本管理
This commit is contained in:
34
devops/apis/account.go
Normal file
34
devops/apis/account.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/devops/apis/form"
|
||||
"mayfly-go/devops/application"
|
||||
"mayfly-go/devops/domain/entity"
|
||||
"mayfly-go/devops/models"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
AccountApp application.IAccount
|
||||
}
|
||||
|
||||
// @router /accounts/login [post]
|
||||
func (a *Account) Login(rc *ctx.ReqCtx) {
|
||||
loginForm := &form.LoginForm{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, loginForm)
|
||||
rc.ReqParam = loginForm.Username
|
||||
|
||||
account := &entity.Account{Username: loginForm.Username, Password: loginForm.Password}
|
||||
biz.ErrIsNil(a.AccountApp.GetAccount(account, "Id", "Username", "Password"), "用户名或密码错误")
|
||||
rc.ResData = map[string]interface{}{
|
||||
"token": ctx.CreateToken(account.Id, account.Username),
|
||||
"username": account.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// @router /accounts [get]
|
||||
func (a *Account) Accounts(rc *ctx.ReqCtx) {
|
||||
rc.ResData = models.ListAccount(ginx.GetPageParam(rc.GinCtx))
|
||||
}
|
||||
Reference in New Issue
Block a user