feat: import services and standardize Go 1.26.5
This commit is contained in:
42
apps/base/feedback/internal/logic/method/get.go
Normal file
42
apps/base/feedback/internal/logic/method/get.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Package method 业务逻辑方法包,实现反馈相关的业务操作
|
||||
package method
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.apinb.com/bsm-apps/feedback/internal/impl"
|
||||
"git.apinb.com/bsm-apps/feedback/internal/models"
|
||||
pb "git.apinb.com/bsm-apps/feedback/pb"
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Get 根据ID获取反馈记录详情
|
||||
// ctx: 上下文
|
||||
// in: 查询请求参数,包含记录ID
|
||||
// 返回: 反馈记录详情
|
||||
func Get(ctx context.Context, in *pb.GetRequest) (reply *pb.GetReply, err error) {
|
||||
// 验证请求参数
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, exception.ErrInvalidArgument
|
||||
}
|
||||
|
||||
out := new(pb.GetReply)
|
||||
record := new(models.FeedbackItem)
|
||||
|
||||
// 查询记录,预加载关联的图片信息
|
||||
err = impl.DBService.Preload("Images").Where("identity = ?", in.GetIdentity()).First(record).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, exception.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 转换为响应格式
|
||||
item := convert(*record)
|
||||
out.Record = item
|
||||
out.Exists = true
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user