Skip to content

Commit

Permalink
feat: 修改模型
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Jun 14, 2024
1 parent 7a4a71f commit cc6a45b
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 129 deletions.
4 changes: 2 additions & 2 deletions app/http/requests/cert/cert_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type CertStore struct {
Domains []string `form:"domains" json:"domains"`
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id"`
DNSID *uint `form:"dns_id" json:"dns_id"`
WebsiteID *uint `form:"website_id" json:"website_id"`
DNSID uint `form:"dns_id" json:"dns_id"`
WebsiteID uint `form:"website_id" json:"website_id"`
}

func (r *CertStore) Authorize(ctx http.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions app/http/requests/cert/cert_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type CertUpdate struct {
Domains []string `form:"domains" json:"domains"`
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id"`
DNSID *uint `form:"dns_id" json:"dns_id"`
WebsiteID *uint `form:"website_id" json:"website_id"`
DNSID uint `form:"dns_id" json:"dns_id"`
WebsiteID uint `form:"website_id" json:"website_id"`
}

func (r *CertUpdate) Authorize(ctx http.Context) error {
Expand Down
24 changes: 11 additions & 13 deletions app/models/cert.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package models

import (
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/database/orm"
)

type Cert struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"default:null" json:"user_id"` // 关联的 ACME 用户 ID
WebsiteID *uint `gorm:"default:null" json:"website_id"` // 关联的网站 ID
DNSID *uint `gorm:"column:dns_id;default:null" json:"dns_id"` // 关联的 DNS ID
Type string `gorm:"not null" json:"type"` // 证书类型 (P256, P384, 2048, 4096)
Domains []string `gorm:"type:json;serializer:json" json:"domains"`
AutoRenew bool `gorm:"default:true" json:"auto_renew"` // 自动续签
CertURL *string `gorm:"default:null" json:"cert_url"` // 证书 URL (续签时使用)
Cert string `gorm:"default:null" json:"cert"` // 证书内容
Key string `gorm:"default:null" json:"key"` // 私钥内容
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
UserID uint `gorm:"not null" json:"user_id"` // 关联的 ACME 用户 ID
WebsiteID uint `gorm:"not null" json:"website_id"` // 关联的网站 ID
DNSID uint `gorm:"not null" json:"dns_id"` // 关联的 DNS ID
Type string `gorm:"not null" json:"type"` // 证书类型 (P256, P384, 2048, 4096)
Domains []string `gorm:"not null;serializer:json" json:"domains"`
AutoRenew bool `gorm:"not null" json:"auto_renew"` // 自动续签
CertURL string `gorm:"not null" json:"cert_url"` // 证书 URL (续签时使用)
Cert string `gorm:"not null" json:"cert"` // 证书内容
Key string `gorm:"not null" json:"key"` // 私钥内容

Website *Website `gorm:"foreignKey:WebsiteID" json:"website"`
User *CertUser `gorm:"foreignKey:UserID" json:"user"`
Expand Down
16 changes: 5 additions & 11 deletions app/models/cert_dns.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package models

import (
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/database/orm"

"github.com/TheTNB/panel/pkg/acme"
)

type CertDNS struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"` // 备注名称
Type string `gorm:"not null" json:"type"` // DNS 提供商 (dnspod, aliyun, cloudflare)
Data acme.DNSParam `gorm:"type:json;serializer:json" json:"dns_param"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null" json:"name"` // 备注名称
Type string `gorm:"not null" json:"type"` // DNS 提供商 (dnspod, aliyun, cloudflare)
Data acme.DNSParam `gorm:"not null;serializer:json" json:"dns_param"`

Certs []*Cert `gorm:"foreignKey:DNSID" json:"-"`
}

func (CertDNS) TableName() string {
return "cert_dns"
}
20 changes: 8 additions & 12 deletions app/models/cert_user.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package models

import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"

type CertUser struct {
ID uint `gorm:"primaryKey" json:"id"`
Email string `gorm:"not null" json:"email"`
CA string `gorm:"not null" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass)
Kid *string `gorm:"default:null" json:"kid"`
HmacEncoded *string `gorm:"default:null" json:"hmac_encoded"`
PrivateKey string `gorm:"not null" json:"private_key"`
KeyType string `gorm:"not null" json:"key_type"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Email string `gorm:"not null" json:"email"`
CA string `gorm:"not null" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass)
Kid string `gorm:"not null" json:"kid"`
HmacEncoded string `gorm:"not null" json:"hmac_encoded"`
PrivateKey string `gorm:"not null" json:"private_key"`
KeyType string `gorm:"not null" json:"key_type"`

Certs []*Cert `gorm:"foreignKey:UserID" json:"-"`
}
20 changes: 8 additions & 12 deletions app/models/cron.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package models

import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"

type Cron struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null;unique" json:"name"`
Status bool `gorm:"not null;default:false" json:"status"`
Type string `gorm:"not null" json:"type"`
Time string `gorm:"not null" json:"time"`
Shell string `gorm:"default:''" json:"shell"`
Log string `gorm:"default:''" json:"log"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;unique" json:"name"`
Status bool `gorm:"not null" json:"status"`
Type string `gorm:"not null" json:"type"`
Time string `gorm:"not null" json:"time"`
Shell string `gorm:"not null" json:"shell"`
Log string `gorm:"not null" json:"log"`
}
20 changes: 9 additions & 11 deletions app/models/database.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package models

import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"

type Database struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"unique;not null" json:"name"`
Type string `gorm:"not null;index" json:"type"`
Host string `gorm:"not null" json:"host"`
Port int `gorm:"not null" json:"port"`
Username string `gorm:"not null" json:"username"`
Password string `gorm:"default:''" json:"password"`
Remark string `gorm:"default:''" json:"remark"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;unique" json:"name"`
Type string `gorm:"not null" json:"type"`
Host string `gorm:"not null" json:"host"`
Port int `gorm:"not null" json:"port"`
Username string `gorm:"not null" json:"username"`
Password string `gorm:"not null" json:"password"`
Remark string `gorm:"not null" json:"remark"`
}
8 changes: 3 additions & 5 deletions app/models/monitor.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package models

import (
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/database/orm"

"github.com/TheTNB/panel/pkg/tools"
)

type Monitor struct {
ID uint `gorm:"primaryKey" json:"id"`
Info tools.MonitoringInfo `gorm:"type:json;serializer:json" json:"info"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Info tools.MonitoringInfo `gorm:"not null;serializer:json" json:"info"`
}
14 changes: 6 additions & 8 deletions app/models/plugin.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package models

import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"

type Plugin struct {
ID uint `gorm:"primaryKey" json:"id"`
Slug string `gorm:"unique;not null" json:"slug"`
Version string `gorm:"not null" json:"version"`
Show bool `gorm:"default:false;not null" json:"show"`
ShowOrder int `gorm:"default:0;not null" json:"show_order"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Slug string `gorm:"not null;unique" json:"slug"`
Version string `gorm:"not null" json:"version"`
Show bool `gorm:"not null" json:"show"`
ShowOrder int `gorm:"not null" json:"show_order"`
}
10 changes: 4 additions & 6 deletions app/models/setting.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package models

import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"

const (
SettingKeyName = "name"
Expand All @@ -17,9 +17,7 @@ const (
)

type Setting struct {
ID uint `gorm:"primaryKey" json:"id"`
Key string `gorm:"unique;not null" json:"key"`
Value string `gorm:"default:''" json:"value"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Key string `gorm:"not null;unique" json:"key"`
Value string `gorm:"not null" json:"value"`
}
16 changes: 6 additions & 10 deletions app/models/task.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package models

import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"

const (
TaskStatusWaiting = "waiting"
Expand All @@ -12,11 +10,9 @@ const (
)

type Task struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"`
Status string `gorm:"not null;default:'waiting'" json:"status"`
Shell string `gorm:"default:''" json:"shell"`
Log string `gorm:"default:''" json:"log"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;index" json:"name"`
Status string `gorm:"not null;default:'waiting'" json:"status"`
Shell string `gorm:"not null" json:"shell"`
Log string `gorm:"not null" json:"log"`
}
12 changes: 5 additions & 7 deletions app/models/user.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package models

import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"

type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"unique;not null" json:"username"`
Password string `gorm:"not null" json:"password"`
Email string `gorm:"default:''" json:"email"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Username string `gorm:"not null;unique" json:"username"`
Password string `gorm:"not null" json:"password"`
Email string `gorm:"not null" json:"email"`
}
20 changes: 8 additions & 12 deletions app/models/website.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package models

import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"

type Website struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
Status bool `gorm:"default:true" json:"status"`
Path string `json:"path"`
Php int `gorm:"default:0;not null;index" json:"php"`
Ssl bool `gorm:"default:false;not null;index" json:"ssl"`
Remark string `gorm:"default:''" json:"remark"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;unique" json:"name"`
Status bool `gorm:"not null;default:true" json:"status"`
Path string `gorm:"not null" json:"path"`
Php int `gorm:"not null" json:"php"`
Ssl bool `gorm:"not null" json:"ssl"`
Remark string `gorm:"not null" json:"remark"`

Cert *Cert `gorm:"foreignKey:WebsiteID" json:"cert"`
}
Loading

0 comments on commit cc6a45b

Please sign in to comment.