Files

39 lines
879 B
Go
Raw Permalink Normal View History

2026-01-07 18:04:01 +08:00
/*
SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
SPDX-License-Identifier: MIT
*/
package post
import (
"context"
"stackChan/internal/dao"
"stackChan/internal/model"
2026-01-07 18:04:01 +08:00
"stackChan/internal/model/do"
"stackChan/api/post/v1"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
2026-01-07 18:04:01 +08:00
)
func (c *ControllerV1) CreatePostComment(ctx context.Context, req *v1.CreatePostCommentReq) (res *v1.CreatePostCommentRes, err error) {
mac := g.RequestFromCtx(ctx).GetCtxVar(model.Mac).String()
if mac == "" {
return nil, gerror.NewCode(gcode.CodeInvalidParameter)
}
2026-01-07 18:04:01 +08:00
id, err := dao.DevicePostComment.Ctx(ctx).Data(do.DevicePostComment{
PostId: req.PostId,
Mac: mac,
2026-01-07 18:04:01 +08:00
Content: req.Content,
}).InsertAndGetId()
if err != nil {
return nil, err
}
res = &v1.CreatePostCommentRes{
Id: id,
}
return res, err
}