Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
November-12 committed Oct 17, 2023
1 parent 9eda6e9 commit a8b32b8
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
24 changes: 20 additions & 4 deletions controllers/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package controllers

import (
gvalid "ThingsPanel-Go/initialize/validate"
"ThingsPanel-Go/services"
"ThingsPanel-Go/utils"
response "ThingsPanel-Go/utils"
valid "ThingsPanel-Go/validate"
"encoding/json"
Expand All @@ -18,23 +20,37 @@ type ConsoleController struct {
}

func (c *ConsoleController) Add() {
vaild := valid.AddConsole{}
err := json.Unmarshal(c.Ctx.Input.RequestBody, &vaild)
input := valid.AddConsole{}
err := json.Unmarshal(c.Ctx.Input.RequestBody, &input)
if err != nil {
fmt.Println("参数解析失败", err.Error())
}
v := validation.Validation{}
status, _ := v.Valid(vaild)
status, _ := v.Valid(input)
if !status {
for _, err := range v.Errors {
// 获取字段别称
alias := gvalid.GetAlias(vaild, err.Field)
alias := gvalid.GetAlias(input, err.Field)
message := strings.Replace(err.Message, err.Field, alias, 1)
response.SuccessWithMessage(1000, message, (*context2.Context)(c.Ctx))
break
}
return
}

tenantId, ok := c.Ctx.Input.GetData("tenant_id").(string)
if !ok {
response.SuccessWithMessage(400, "代码逻辑错误", (*context2.Context)(c.Ctx))
return
}

var ConsoleService services.ConsoleService
err = ConsoleService.AddConsole(input.Name, input.CreatedBy, input.Data, input.Config, input.Template, input.Code, tenantId)
if err != nil {
utils.SuccessWithMessage(1000, err.Error(), (*context2.Context)(c.Ctx))
return
}
utils.Success(200, c.Ctx)
}

func (c *ConsoleController) Edit() {
Expand Down
18 changes: 18 additions & 0 deletions models/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package models

type Console struct {
ID string `json:"id" gorm:"primaryKey,size:36"`
Name string `json:"name"`
CreatedAt int64 `json:"created_at"`
CreatedBy string `json:"created_by"`
UpdateAt int64 `json:"update_at"`
Data string `json:"data"`
Config string `json:"config"`
Template string `json:"template"`
Code string `json:"code"`
TenantId string `json:"tenant_id"`
}

func (Console) TableName() string {
return "tp_console"
}
8 changes: 8 additions & 0 deletions services/console_service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package services

type ConsoleService struct {
}

func (*ConsoleService) AddConsole(name string, offset int, pageSize int) int {

}
45 changes: 45 additions & 0 deletions services/console_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package services

import (
"ThingsPanel-Go/initialize/psql"
"ThingsPanel-Go/models"
uuid "ThingsPanel-Go/utils"
"time"
)

type ConsoleService struct {
}

func (*ConsoleService) AddConsole(name, createdBy, data, config, template, code, tenantId string) error {
id := uuid.GetUuid()
save := models.Console{
ID: id,
Name: name,
CreatedAt: time.Now().Unix(),
CreatedBy: createdBy,
UpdateAt: time.Now().Unix(),
Data: data,
Config: config,
Template: template,
Code: code,
TenantId: tenantId,
}
result := psql.Mydb.Create(&save)
return result.Error
}

func (*ConsoleService) EditConsole() int {
return 0
}

func (*ConsoleService) DeleteConsoleById() int {
return 0
}

func (*ConsoleService) GetConsoleList() int {
return 0
}

func (*ConsoleService) GetConsoleDetail() int {
return 0
}

0 comments on commit a8b32b8

Please sign in to comment.