feat: 完成了连接, 断开连接

update: 慢慢过渡到 css-in-js
refactory: 新建连接改为 dialog
wip: 没找到合适和适应的状态管理方便全局状态管理
This commit is contained in:
zhaoyupeng
2024-09-30 09:20:37 +08:00
23 changed files with 603 additions and 247 deletions

View File

@ -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
}