feat: 完成了连接, 断开连接
update: 慢慢过渡到 css-in-js refactory: 新建连接改为 dialog wip: 没找到合适和适应的状态管理方便全局状态管理
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
import (
|
||||
"errors"
|
||||
"github.com/loveuer/nf-disk/ndh"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Connection struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
@ -11,8 +15,22 @@ type Connection struct {
|
||||
Endpoint string `json:"endpoint" gorm:"column:endpoint"`
|
||||
Access string `json:"access" gorm:"column:access"`
|
||||
Key string `json:"key" gorm:"column:key"`
|
||||
|
||||
Active bool `json:"active" gorm:"-"`
|
||||
}
|
||||
|
||||
func (c *Connection) Create(tx *gorm.DB) error {
|
||||
return tx.Create(c).Error
|
||||
}
|
||||
|
||||
func (c *Connection) Get(tx *gorm.DB, ctx *ndh.Ctx) error {
|
||||
if err := tx.Take(c, c.Id).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return ctx.Send400(err.Error())
|
||||
}
|
||||
|
||||
return ctx.Send500(err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user