feat: 重构内容列表接口,使用过滤器结构体简化参数传递;更新相关服务和测试用例

This commit is contained in:
2025-12-29 15:04:55 +08:00
parent 8c4bc55f45
commit fba77afec1
14 changed files with 65 additions and 60 deletions

View File

@@ -20,11 +20,11 @@ type tenant struct{}
func (s *tenant) GetPublicProfile(ctx context.Context, id string) (*tenant_dto.TenantProfile, error) {
// id could be Code or ID. Try Code first, then ID.
tbl, q := models.TenantQuery.QueryContext(ctx)
// Try to find by code or ID
var t *models.Tenant
var err error
// Assume id is ID for simplicity if numeric, or try both.
if cast.ToInt64(id) > 0 {
t, err = q.Where(tbl.ID.Eq(cast.ToInt64(id))).First()
@@ -48,7 +48,7 @@ func (s *tenant) GetPublicProfile(ctx context.Context, id string) (*tenant_dto.T
var likes int64
// Sum content likes
// Mock likes for now or fetch
// IsFollowing
isFollowing := false
userID := ctx.Value(consts.CtxKeyUser)
@@ -60,14 +60,14 @@ func (s *tenant) GetPublicProfile(ctx context.Context, id string) (*tenant_dto.T
// Config parsing (Unused for now as we don't map to bio yet)
// config := t.Config.Data()
return &tenant_dto.TenantProfile{
ID: cast.ToString(t.ID),
Name: t.Name,
Avatar: "", // From config
Cover: "", // From config
Bio: "", // From config
Description: "", // From config
Avatar: "", // From config
Cover: "", // From config
Bio: "", // From config
Description: "", // From config
CertType: "personal", // Mock
Stats: tenant_dto.Stats{
Followers: int(followers),
@@ -99,7 +99,7 @@ func (s *tenant) Follow(ctx context.Context, id string) error {
Role: types.Array[consts.TenantUserRole]{consts.TenantUserRoleMember},
Status: consts.UserStatusVerified,
}
count, _ := models.TenantUserQuery.WithContext(ctx).Where(models.TenantUserQuery.TenantID.Eq(tid), models.TenantUserQuery.UserID.Eq(uid)).Count()
if count > 0 {
return nil // Already following
@@ -124,4 +124,4 @@ func (s *tenant) Unfollow(ctx context.Context, id string) error {
return errorx.ErrDatabaseError.WithCause(err)
}
return nil
}
}