feat: align ids to int64

This commit is contained in:
2026-01-08 09:57:04 +08:00
parent a1de16bc01
commit d98f41f1ac
39 changed files with 298 additions and 339 deletions

View File

@@ -3,15 +3,12 @@ package services
import (
"context"
"errors"
"fmt"
"quyun/v2/app/errorx"
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/database/models"
"quyun/v2/pkg/consts"
"github.com/spf13/cast"
"go.ipao.vip/gen/types"
"gorm.io/gorm"
)
@@ -47,7 +44,7 @@ func (s *tenant) List(ctx context.Context, filter *dto.TenantListFilter) (*reque
cfg := t.Config.Data()
data = append(data, dto.TenantProfile{
ID: cast.ToString(t.ID),
ID: t.ID,
Name: t.Name,
Avatar: cfg.Avatar,
Bio: cfg.Bio,
@@ -65,9 +62,8 @@ func (s *tenant) List(ctx context.Context, filter *dto.TenantListFilter) (*reque
}, nil
}
func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string) (*dto.TenantProfile, error) {
tid := cast.ToInt64(id)
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(tid)).First()
func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id int64) (*dto.TenantProfile, error) {
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(id)).First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errorx.ErrRecordNotFound
@@ -76,9 +72,9 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
}
// Stats
followers, _ := models.TenantUserQuery.WithContext(ctx).Where(models.TenantUserQuery.TenantID.Eq(tid)).Count()
followers, _ := models.TenantUserQuery.WithContext(ctx).Where(models.TenantUserQuery.TenantID.Eq(id)).Count()
contents, _ := models.ContentQuery.WithContext(ctx).
Where(models.ContentQuery.TenantID.Eq(tid), models.ContentQuery.Status.Eq(consts.ContentStatusPublished)).
Where(models.ContentQuery.TenantID.Eq(id), models.ContentQuery.Status.Eq(consts.ContentStatusPublished)).
Count()
// Following status
@@ -86,14 +82,13 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
if userID > 0 {
uid := userID
isFollowing, _ = models.TenantUserQuery.WithContext(ctx).
Where(models.TenantUserQuery.TenantID.Eq(tid), models.TenantUserQuery.UserID.Eq(uid)).
Where(models.TenantUserQuery.TenantID.Eq(id), models.TenantUserQuery.UserID.Eq(uid)).
Exists()
}
cfg := t.Config.Data()
fmt.Printf("DEBUG: Tenant Config: %+v\n", cfg)
return &dto.TenantProfile{
ID: cast.ToString(t.ID),
ID: t.ID,
Name: t.Name,
Avatar: cfg.Avatar,
Cover: cfg.Cover,
@@ -107,21 +102,20 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
}, nil
}
func (s *tenant) Follow(ctx context.Context, userID int64, id string) error {
func (s *tenant) Follow(ctx context.Context, userID int64, id int64) error {
if userID == 0 {
return errorx.ErrUnauthorized
}
uid := userID
tid := cast.ToInt64(id)
// Check if tenant exists
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(tid)).First()
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(id)).First()
if err != nil {
return errorx.ErrRecordNotFound
}
tu := &models.TenantUser{
TenantID: tid,
TenantID: id,
UserID: uid,
Role: types.Array[consts.TenantUserRole]{consts.TenantUserRoleMember},
Status: consts.UserStatusVerified,
@@ -137,15 +131,14 @@ func (s *tenant) Follow(ctx context.Context, userID int64, id string) error {
return nil
}
func (s *tenant) Unfollow(ctx context.Context, userID int64, id string) error {
func (s *tenant) Unfollow(ctx context.Context, userID int64, id int64) error {
if userID == 0 {
return errorx.ErrUnauthorized
}
uid := userID
tid := cast.ToInt64(id)
_, err := models.TenantUserQuery.WithContext(ctx).
Where(models.TenantUserQuery.TenantID.Eq(tid), models.TenantUserQuery.UserID.Eq(uid)).
Where(models.TenantUserQuery.TenantID.Eq(id), models.TenantUserQuery.UserID.Eq(uid)).
Delete()
if err != nil {
return errorx.ErrDatabaseError.WithCause(err)
@@ -182,7 +175,7 @@ func (s *tenant) ListFollowed(ctx context.Context, userID int64) ([]dto.TenantPr
Count()
data = append(data, dto.TenantProfile{
ID: cast.ToString(t.ID),
ID: t.ID,
Name: t.Name,
Avatar: "",
Stats: dto.Stats{