Commit f51ad2e1 authored by Forest's avatar Forest
Browse files

refactor: 删除 ports 目录

parent f57f12c6
...@@ -9,13 +9,12 @@ import ( ...@@ -9,13 +9,12 @@ import (
"github.com/Wei-Shaw/sub2api/internal/config" "github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/model" "github.com/Wei-Shaw/sub2api/internal/model"
"github.com/Wei-Shaw/sub2api/internal/service/ports"
) )
// TokenRefreshService OAuth token自动刷新服务 // TokenRefreshService OAuth token自动刷新服务
// 定期检查并刷新即将过期的token // 定期检查并刷新即将过期的token
type TokenRefreshService struct { type TokenRefreshService struct {
accountRepo ports.AccountRepository accountRepo AccountRepository
refreshers []TokenRefresher refreshers []TokenRefresher
cfg *config.TokenRefreshConfig cfg *config.TokenRefreshConfig
...@@ -25,7 +24,7 @@ type TokenRefreshService struct { ...@@ -25,7 +24,7 @@ type TokenRefreshService struct {
// NewTokenRefreshService 创建token刷新服务 // NewTokenRefreshService 创建token刷新服务
func NewTokenRefreshService( func NewTokenRefreshService(
accountRepo ports.AccountRepository, accountRepo AccountRepository,
oauthService *OAuthService, oauthService *OAuthService,
openaiOAuthService *OpenAIOAuthService, openaiOAuthService *OpenAIOAuthService,
cfg *config.Config, cfg *config.Config,
......
...@@ -17,8 +17,6 @@ import ( ...@@ -17,8 +17,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/Wei-Shaw/sub2api/internal/service/ports"
) )
const ( const (
...@@ -34,6 +32,12 @@ const ( ...@@ -34,6 +32,12 @@ const (
maxDownloadSize = 500 * 1024 * 1024 maxDownloadSize = 500 * 1024 * 1024
) )
// UpdateCache defines cache operations for update service
type UpdateCache interface {
GetUpdateInfo(ctx context.Context) (string, error)
SetUpdateInfo(ctx context.Context, data string, ttl time.Duration) error
}
// GitHubReleaseClient 获取 GitHub release 信息的接口 // GitHubReleaseClient 获取 GitHub release 信息的接口
type GitHubReleaseClient interface { type GitHubReleaseClient interface {
FetchLatestRelease(ctx context.Context, repo string) (*GitHubRelease, error) FetchLatestRelease(ctx context.Context, repo string) (*GitHubRelease, error)
...@@ -43,14 +47,14 @@ type GitHubReleaseClient interface { ...@@ -43,14 +47,14 @@ type GitHubReleaseClient interface {
// UpdateService handles software updates // UpdateService handles software updates
type UpdateService struct { type UpdateService struct {
cache ports.UpdateCache cache UpdateCache
githubClient GitHubReleaseClient githubClient GitHubReleaseClient
currentVersion string currentVersion string
buildType string // "source" for manual builds, "release" for CI builds buildType string // "source" for manual builds, "release" for CI builds
} }
// NewUpdateService creates a new UpdateService // NewUpdateService creates a new UpdateService
func NewUpdateService(cache ports.UpdateCache, githubClient GitHubReleaseClient, version, buildType string) *UpdateService { func NewUpdateService(cache UpdateCache, githubClient GitHubReleaseClient, version, buildType string) *UpdateService {
return &UpdateService{ return &UpdateService{
cache: cache, cache: cache,
githubClient: githubClient, githubClient: githubClient,
......
...@@ -4,12 +4,11 @@ import ( ...@@ -4,12 +4,11 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"time"
"github.com/Wei-Shaw/sub2api/internal/model" "github.com/Wei-Shaw/sub2api/internal/model"
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination" "github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
"github.com/Wei-Shaw/sub2api/internal/pkg/usagestats" "github.com/Wei-Shaw/sub2api/internal/pkg/usagestats"
"github.com/Wei-Shaw/sub2api/internal/service/ports"
"time"
"gorm.io/gorm" "gorm.io/gorm"
) )
...@@ -55,12 +54,12 @@ type UsageStats struct { ...@@ -55,12 +54,12 @@ type UsageStats struct {
// UsageService 使用统计服务 // UsageService 使用统计服务
type UsageService struct { type UsageService struct {
usageRepo ports.UsageLogRepository usageRepo UsageLogRepository
userRepo ports.UserRepository userRepo UserRepository
} }
// NewUsageService 创建使用统计服务实例 // NewUsageService 创建使用统计服务实例
func NewUsageService(usageRepo ports.UsageLogRepository, userRepo ports.UserRepository) *UsageService { func NewUsageService(usageRepo UsageLogRepository, userRepo UserRepository) *UsageService {
return &UsageService{ return &UsageService{
usageRepo: usageRepo, usageRepo: usageRepo,
userRepo: userRepo, userRepo: userRepo,
......
...@@ -4,10 +4,9 @@ import ( ...@@ -4,10 +4,9 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/Wei-Shaw/sub2api/internal/model" "github.com/Wei-Shaw/sub2api/internal/model"
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination" "github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
"github.com/Wei-Shaw/sub2api/internal/service/ports"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"gorm.io/gorm" "gorm.io/gorm"
) )
...@@ -18,6 +17,24 @@ var ( ...@@ -18,6 +17,24 @@ var (
ErrInsufficientPerms = errors.New("insufficient permissions") ErrInsufficientPerms = errors.New("insufficient permissions")
) )
type UserRepository interface {
Create(ctx context.Context, user *model.User) error
GetByID(ctx context.Context, id int64) (*model.User, error)
GetByEmail(ctx context.Context, email string) (*model.User, error)
GetFirstAdmin(ctx context.Context) (*model.User, error)
Update(ctx context.Context, user *model.User) error
Delete(ctx context.Context, id int64) error
List(ctx context.Context, params pagination.PaginationParams) ([]model.User, *pagination.PaginationResult, error)
ListWithFilters(ctx context.Context, params pagination.PaginationParams, status, role, search string) ([]model.User, *pagination.PaginationResult, error)
UpdateBalance(ctx context.Context, id int64, amount float64) error
DeductBalance(ctx context.Context, id int64, amount float64) error
UpdateConcurrency(ctx context.Context, id int64, amount int) error
ExistsByEmail(ctx context.Context, email string) (bool, error)
RemoveGroupFromAllowedGroups(ctx context.Context, groupID int64) (int64, error)
}
// UpdateProfileRequest 更新用户资料请求 // UpdateProfileRequest 更新用户资料请求
type UpdateProfileRequest struct { type UpdateProfileRequest struct {
Email *string `json:"email"` Email *string `json:"email"`
...@@ -34,11 +51,11 @@ type ChangePasswordRequest struct { ...@@ -34,11 +51,11 @@ type ChangePasswordRequest struct {
// UserService 用户服务 // UserService 用户服务
type UserService struct { type UserService struct {
userRepo ports.UserRepository userRepo UserRepository
} }
// NewUserService 创建用户服务实例 // NewUserService 创建用户服务实例
func NewUserService(userRepo ports.UserRepository) *UserService { func NewUserService(userRepo UserRepository) *UserService {
return &UserService{ return &UserService{
userRepo: userRepo, userRepo: userRepo,
} }
......
...@@ -2,8 +2,6 @@ package service ...@@ -2,8 +2,6 @@ package service
import ( import (
"github.com/Wei-Shaw/sub2api/internal/config" "github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/service/ports"
"github.com/google/wire" "github.com/google/wire"
) )
...@@ -24,7 +22,7 @@ func ProvidePricingService(cfg *config.Config, remoteClient PricingRemoteClient) ...@@ -24,7 +22,7 @@ func ProvidePricingService(cfg *config.Config, remoteClient PricingRemoteClient)
} }
// ProvideUpdateService creates UpdateService with BuildInfo // ProvideUpdateService creates UpdateService with BuildInfo
func ProvideUpdateService(cache ports.UpdateCache, githubClient GitHubReleaseClient, buildInfo BuildInfo) *UpdateService { func ProvideUpdateService(cache UpdateCache, githubClient GitHubReleaseClient, buildInfo BuildInfo) *UpdateService {
return NewUpdateService(cache, githubClient, buildInfo.Version, buildInfo.BuildType) return NewUpdateService(cache, githubClient, buildInfo.Version, buildInfo.BuildType)
} }
...@@ -35,7 +33,7 @@ func ProvideEmailQueueService(emailService *EmailService) *EmailQueueService { ...@@ -35,7 +33,7 @@ func ProvideEmailQueueService(emailService *EmailService) *EmailQueueService {
// ProvideTokenRefreshService creates and starts TokenRefreshService // ProvideTokenRefreshService creates and starts TokenRefreshService
func ProvideTokenRefreshService( func ProvideTokenRefreshService(
accountRepo ports.AccountRepository, accountRepo AccountRepository,
oauthService *OAuthService, oauthService *OAuthService,
openaiOAuthService *OpenAIOAuthService, openaiOAuthService *OpenAIOAuthService,
cfg *config.Config, cfg *config.Config,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment