:card_box: Add detailed release model
This commit is contained in:
parent
c13c1f57a4
commit
79e03e74f3
@ -15,10 +15,11 @@ const (
|
|||||||
type ProductRelease struct {
|
type ProductRelease struct {
|
||||||
cruda.BaseModel
|
cruda.BaseModel
|
||||||
|
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Type ProductReleaseType `json:"type"`
|
Type ProductReleaseType `json:"type"`
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
Assets datatypes.JSONType[map[string]any] `json:"assets"`
|
Assets datatypes.JSONType[map[string]ReleaseAsset] `json:"assets"`
|
||||||
|
Installers datatypes.JSONType[map[string]ReleaseInstaller] `json:"installers"`
|
||||||
|
|
||||||
ProductID uint `json:"product_id"`
|
ProductID uint `json:"product_id"`
|
||||||
Meta ProductReleaseMeta `json:"meta" gorm:"foreignKey:ReleaseID"`
|
Meta ProductReleaseMeta `json:"meta" gorm:"foreignKey:ReleaseID"`
|
||||||
@ -33,3 +34,19 @@ type ProductReleaseMeta struct {
|
|||||||
Attachments datatypes.JSONSlice[string] `json:"attachments"`
|
Attachments datatypes.JSONSlice[string] `json:"attachments"`
|
||||||
ReleaseID uint `json:"release_id"`
|
ReleaseID uint `json:"release_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ReleaseAsset struct {
|
||||||
|
URI string `json:"uri" validate:"required"`
|
||||||
|
ContentType string `json:"content_type" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReleaseInstaller struct {
|
||||||
|
Workdir string `json:"workdir"`
|
||||||
|
Script string `json:"script"`
|
||||||
|
Patches []ReleaseInstallerPatch `json:"patches"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReleaseInstallerPatch struct {
|
||||||
|
Action string `json:"action" validate:"required"`
|
||||||
|
Glob string `json:"glob" validate:"required"`
|
||||||
|
}
|
||||||
|
@ -50,14 +50,15 @@ func createRelease(c *fiber.Ctx) error {
|
|||||||
productId, _ := c.ParamsInt("productId", 0)
|
productId, _ := c.ParamsInt("productId", 0)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Version string `json:"version" validate:"required"`
|
Version string `json:"version" validate:"required"`
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
Channel string `json:"channel" validate:"required"`
|
Channel string `json:"channel" validate:"required"`
|
||||||
Title string `json:"title" validate:"required,max=1024"`
|
Title string `json:"title" validate:"required,max=1024"`
|
||||||
Description string `json:"description" validate:"required,max=4096"`
|
Description string `json:"description" validate:"required,max=4096"`
|
||||||
Content string `json:"content" validate:"required"`
|
Content string `json:"content" validate:"required"`
|
||||||
Assets map[string]any `json:"assets" validate:"required"`
|
Assets map[string]models.ReleaseAsset `json:"assets" validate:"required"`
|
||||||
Attachments []string `json:"attachments"`
|
Installers map[string]models.ReleaseInstaller `json:"installers" validate:"required"`
|
||||||
|
Attachments []string `json:"attachments"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
@ -70,11 +71,12 @@ func createRelease(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
release := models.ProductRelease{
|
release := models.ProductRelease{
|
||||||
Version: data.Version,
|
Version: data.Version,
|
||||||
Type: models.ProductReleaseType(data.Type),
|
Type: models.ProductReleaseType(data.Type),
|
||||||
Channel: data.Channel,
|
Channel: data.Channel,
|
||||||
Assets: datatypes.NewJSONType(data.Assets),
|
Assets: datatypes.NewJSONType(data.Assets),
|
||||||
ProductID: product.ID,
|
Installers: datatypes.NewJSONType(data.Installers),
|
||||||
|
ProductID: product.ID,
|
||||||
Meta: models.ProductReleaseMeta{
|
Meta: models.ProductReleaseMeta{
|
||||||
Title: data.Title,
|
Title: data.Title,
|
||||||
Description: data.Description,
|
Description: data.Description,
|
||||||
@ -100,14 +102,15 @@ func updateRelease(c *fiber.Ctx) error {
|
|||||||
id, _ := c.ParamsInt("releaseId", 0)
|
id, _ := c.ParamsInt("releaseId", 0)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Version string `json:"version" validate:"required"`
|
Version string `json:"version" validate:"required"`
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
Channel string `json:"channel" validate:"required"`
|
Channel string `json:"channel" validate:"required"`
|
||||||
Title string `json:"title" validate:"required,max=1024"`
|
Title string `json:"title" validate:"required,max=1024"`
|
||||||
Description string `json:"description" validate:"required,max=4096"`
|
Description string `json:"description" validate:"required,max=4096"`
|
||||||
Content string `json:"content" validate:"required"`
|
Content string `json:"content" validate:"required"`
|
||||||
Assets map[string]any `json:"assets" validate:"required"`
|
Assets map[string]models.ReleaseAsset `json:"assets" validate:"required"`
|
||||||
Attachments []string `json:"attachments"`
|
Installers map[string]models.ReleaseInstaller `json:"installers" validate:"required"`
|
||||||
|
Attachments []string `json:"attachments"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
@ -128,6 +131,7 @@ func updateRelease(c *fiber.Ctx) error {
|
|||||||
release.Type = models.ProductReleaseType(data.Type)
|
release.Type = models.ProductReleaseType(data.Type)
|
||||||
release.Channel = data.Channel
|
release.Channel = data.Channel
|
||||||
release.Assets = datatypes.NewJSONType(data.Assets)
|
release.Assets = datatypes.NewJSONType(data.Assets)
|
||||||
|
release.Installers = datatypes.NewJSONType(data.Installers)
|
||||||
release.Meta.Title = data.Title
|
release.Meta.Title = data.Title
|
||||||
release.Meta.Description = data.Description
|
release.Meta.Description = data.Description
|
||||||
release.Meta.Content = data.Content
|
release.Meta.Content = data.Content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user