package logic import ( "context" "healthapi/internal/model" "healthapi/internal/svc" "healthapi/internal/types" "healthapi/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type GetConversationsLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetConversationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetConversationsLogic { return &GetConversationsLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *GetConversationsLogic) GetConversations() (resp *types.ConversationListResp, err error) { userID, err := GetUserIDFromCtx(l.ctx) if err != nil { return nil, errorx.ErrUnauthorized } var conversations []model.Conversation l.svcCtx.DB.Where("user_id = ?", userID).Order("updated_at DESC").Find(&conversations) resp = &types.ConversationListResp{ Conversations: make([]types.ConversationItem, 0, len(conversations)), } for _, c := range conversations { resp.Conversations = append(resp.Conversations, types.ConversationItem{ ID: uint(c.ID), Title: c.Title, CreatedAt: c.CreatedAt.Format("2006-01-02 15:04:05"), UpdatedAt: c.UpdatedAt.Format("2006-01-02 15:04:05"), }) } return resp, nil }