mirror of
https://github.com/m5stack/StackChan.git
synced 2026-04-27 19:12:40 +00:00
server code 4/27
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
||||
SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package pano
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
||||
SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package pano
|
||||
|
||||
import (
|
||||
"stackChan/api/pano"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() pano.IPanoV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
||||
SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
package pano
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stackChan/internal/dao"
|
||||
"stackChan/internal/model"
|
||||
"stackChan/internal/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
"stackChan/api/pano/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AddPano(ctx context.Context, req *v1.AddPanoReq) (res *v1.AddPanoRes, err error) {
|
||||
mac := g.RequestFromCtx(ctx).GetCtxVar(model.Mac).String()
|
||||
if mac == "" {
|
||||
return nil, gerror.NewCode(gcode.CodeInvalidParameter)
|
||||
}
|
||||
|
||||
if req.Url == "" {
|
||||
return nil, gerror.NewCode(gcode.CodeInvalidParameter)
|
||||
}
|
||||
|
||||
Id, err := dao.DevicePano.Ctx(ctx).Data(entity.DevicePano{
|
||||
Mac: mac,
|
||||
PanoUrl: req.Url,
|
||||
}).InsertAndGetId()
|
||||
|
||||
if err != nil {
|
||||
return nil, gerror.NewCode(gcode.CodeInvalidParameter)
|
||||
}
|
||||
|
||||
res = &v1.AddPanoRes{
|
||||
Id: Id,
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
||||
SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
package pano
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stackChan/internal/dao"
|
||||
"stackChan/internal/model"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
"stackChan/api/pano/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) GetPanoList(ctx context.Context, req *v1.GetPanoListReq) (res *v1.GetPanoListRes, err error) {
|
||||
mac := g.RequestFromCtx(ctx).GetCtxVar(model.Mac).String()
|
||||
if mac == "" {
|
||||
return nil, gerror.NewCode(gcode.CodeInvalidParameter)
|
||||
}
|
||||
|
||||
var list []model.Pano
|
||||
|
||||
err = dao.DevicePano.Ctx(ctx).Where("mac = ?", mac).Scan(&list)
|
||||
|
||||
if err != nil {
|
||||
return nil, gerror.NewCode(gcode.CodeInvalidParameter)
|
||||
}
|
||||
|
||||
if list == nil {
|
||||
list = make([]model.Pano, 0)
|
||||
}
|
||||
|
||||
response := v1.GetPanoListRes(list)
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
Reference in New Issue
Block a user