Files
sundynix-pets/pets-be/internal/service/service.go
T
Blizzard 2e3345cdfc feat: 记录删除与筛选、用户侧内容删除、AI 聊天历史
修复雪花 ID 精度丢失(真 bug)
- bottom-sheet 的 postId 声明为 Number,而 ID 是 18 位雪花字符串,
  超出 JS 安全整数范围:339346584095428608 会被转成 ...600,
  评论弹层实际查的是不存在的帖子。改为 String

记录
- 后端 DELETE /records/:id 早已就绪但前端从未调用,记错了删不掉。
  时间轴支持长按删除
- 时间轴加类型筛选(体重/便便/饮食/异常/用药/疫苗/消费/照片),
  后端 ?type= 本就支持

用户侧内容删除(UGC 合规:用户应能删除自己发布的内容)
- 新增 DELETE /posts/:id 与 DELETE /comments/:id,仅限本人,
  越权返回 40300;帖子软删除,评论删除同步递减 comment_count
- 评论列表返回 is_self;社区长按自己的帖子、长按自己的评论可删

AI 聊天历史
- ai_messages 一直在写但没有查询接口,每次打开弹层都是空白。
  新增 GET /api/ai/messages,弹层打开时接在开场白后加载

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 17:42:14 +08:00

48 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package service
import (
"errors"
"gorm.io/gorm"
"github.com/sundynix/pets-be/internal/ai"
"github.com/sundynix/pets-be/internal/config"
"github.com/sundynix/pets-be/internal/model"
"github.com/sundynix/pets-be/internal/storage"
)
// ErrNotFound 资源不存在(handler 据此返回 40400
var ErrNotFound = errors.New("not found")
// ErrPayNotReady 支付未接入。会员开通必须走真实支付,未接入前一律拒绝,
// 避免「点一下白拿会员」。
var ErrPayNotReady = errors.New("支付功能即将开放,敬请期待")
// ErrForbidden 越权操作(如删除别人的内容)
var ErrForbidden = errors.New("无权操作")
// Service 业务逻辑聚合,方法按领域分散在各文件
type Service struct {
db *gorm.DB
storage *storage.Storage
cfg *config.Config
ai *ai.Engine
}
func New(db *gorm.DB, st *storage.Storage, cfg *config.Config, engine *ai.Engine) *Service {
return &Service{db: db, storage: st, cfg: cfg, ai: engine}
}
// ownedPet 校验宠物归属当前用户并返回
func (s *Service) ownedPet(userID, petID string) (*model.Pet, error) {
var pet model.Pet
err := s.db.Where("id = ? AND user_id = ?", petID, userID).First(&pet).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, ErrNotFound
}
if err != nil {
return nil, err
}
return &pet, nil
}