account and meta add id

This commit is contained in:
微凉
2021-11-13 16:49:03 +08:00
parent 959ef620fb
commit 5f34b8ab80
5 changed files with 67 additions and 7 deletions

View File

@ -17,6 +17,31 @@ func GetAccounts(c *gin.Context) {
SuccessResp(c, accounts)
}
func CreateAccount(c *gin.Context) {
var req model.Account
if err := c.ShouldBind(&req); err != nil {
ErrorResp(c, err, 400)
return
}
driver, ok := drivers.GetDriver(req.Type)
if !ok {
ErrorResp(c, fmt.Errorf("no [%s] driver", req.Type), 400)
return
}
now := time.Now()
req.UpdatedAt = &now
if err := model.CreateAccount(req); err != nil {
ErrorResp(c, err, 500)
} else {
err = driver.Save(&req, nil)
if err != nil {
ErrorResp(c, err, 500)
return
}
SuccessResp(c)
}
}
func SaveAccount(c *gin.Context) {
var req model.Account
if err := c.ShouldBind(&req); err != nil {