2026-01-04 19:27:53 +08:00
|
|
|
|
// Package dto provides data transfer objects for HTTP handlers.
|
2025-12-26 15:40:24 +08:00
|
|
|
|
package dto
|
|
|
|
|
|
|
2026-01-07 16:59:35 +08:00
|
|
|
|
import (
|
2026-02-23 12:45:37 +08:00
|
|
|
|
"strconv"
|
2026-01-07 16:59:35 +08:00
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
|
|
|
|
|
)
|
2025-12-26 15:40:24 +08:00
|
|
|
|
|
|
|
|
|
|
func UserFromServiceShallow(u *service.User) *User {
|
|
|
|
|
|
if u == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &User{
|
|
|
|
|
|
ID: u.ID,
|
|
|
|
|
|
Email: u.Email,
|
|
|
|
|
|
Username: u.Username,
|
|
|
|
|
|
Role: u.Role,
|
|
|
|
|
|
Balance: u.Balance,
|
|
|
|
|
|
Concurrency: u.Concurrency,
|
|
|
|
|
|
Status: u.Status,
|
|
|
|
|
|
AllowedGroups: u.AllowedGroups,
|
|
|
|
|
|
CreatedAt: u.CreatedAt,
|
|
|
|
|
|
UpdatedAt: u.UpdatedAt,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func UserFromService(u *service.User) *User {
|
|
|
|
|
|
if u == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
out := UserFromServiceShallow(u)
|
2026-01-04 19:27:53 +08:00
|
|
|
|
if len(u.APIKeys) > 0 {
|
|
|
|
|
|
out.APIKeys = make([]APIKey, 0, len(u.APIKeys))
|
|
|
|
|
|
for i := range u.APIKeys {
|
|
|
|
|
|
k := u.APIKeys[i]
|
|
|
|
|
|
out.APIKeys = append(out.APIKeys, *APIKeyFromService(&k))
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(u.Subscriptions) > 0 {
|
|
|
|
|
|
out.Subscriptions = make([]UserSubscription, 0, len(u.Subscriptions))
|
|
|
|
|
|
for i := range u.Subscriptions {
|
|
|
|
|
|
s := u.Subscriptions[i]
|
|
|
|
|
|
out.Subscriptions = append(out.Subscriptions, *UserSubscriptionFromService(&s))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 19:23:51 +08:00
|
|
|
|
// UserFromServiceAdmin converts a service User to DTO for admin users.
|
|
|
|
|
|
// It includes notes - user-facing endpoints must not use this.
|
|
|
|
|
|
func UserFromServiceAdmin(u *service.User) *AdminUser {
|
|
|
|
|
|
if u == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
base := UserFromService(u)
|
|
|
|
|
|
if base == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &AdminUser{
|
2026-02-28 15:01:20 +08:00
|
|
|
|
User: *base,
|
|
|
|
|
|
Notes: u.Notes,
|
|
|
|
|
|
GroupRates: u.GroupRates,
|
|
|
|
|
|
SoraStorageQuotaBytes: u.SoraStorageQuotaBytes,
|
|
|
|
|
|
SoraStorageUsedBytes: u.SoraStorageUsedBytes,
|
2026-01-19 19:23:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-04 19:27:53 +08:00
|
|
|
|
func APIKeyFromService(k *service.APIKey) *APIKey {
|
2025-12-26 15:40:24 +08:00
|
|
|
|
if k == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-03-09 10:22:24 +08:00
|
|
|
|
out := &APIKey{
|
2026-03-03 15:01:10 +08:00
|
|
|
|
ID: k.ID,
|
|
|
|
|
|
UserID: k.UserID,
|
|
|
|
|
|
Key: k.Key,
|
|
|
|
|
|
Name: k.Name,
|
|
|
|
|
|
GroupID: k.GroupID,
|
|
|
|
|
|
Status: k.Status,
|
|
|
|
|
|
IPWhitelist: k.IPWhitelist,
|
|
|
|
|
|
IPBlacklist: k.IPBlacklist,
|
|
|
|
|
|
LastUsedAt: k.LastUsedAt,
|
|
|
|
|
|
Quota: k.Quota,
|
|
|
|
|
|
QuotaUsed: k.QuotaUsed,
|
|
|
|
|
|
ExpiresAt: k.ExpiresAt,
|
|
|
|
|
|
CreatedAt: k.CreatedAt,
|
|
|
|
|
|
UpdatedAt: k.UpdatedAt,
|
|
|
|
|
|
RateLimit5h: k.RateLimit5h,
|
|
|
|
|
|
RateLimit1d: k.RateLimit1d,
|
|
|
|
|
|
RateLimit7d: k.RateLimit7d,
|
2026-03-07 09:59:40 +08:00
|
|
|
|
Usage5h: k.EffectiveUsage5h(),
|
|
|
|
|
|
Usage1d: k.EffectiveUsage1d(),
|
|
|
|
|
|
Usage7d: k.EffectiveUsage7d(),
|
2026-03-03 15:01:10 +08:00
|
|
|
|
Window5hStart: k.Window5hStart,
|
|
|
|
|
|
Window1dStart: k.Window1dStart,
|
|
|
|
|
|
Window7dStart: k.Window7dStart,
|
|
|
|
|
|
User: UserFromServiceShallow(k.User),
|
|
|
|
|
|
Group: GroupFromServiceShallow(k.Group),
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
2026-03-09 10:22:24 +08:00
|
|
|
|
if k.Window5hStart != nil && !service.IsWindowExpired(k.Window5hStart, service.RateLimitWindow5h) {
|
|
|
|
|
|
t := k.Window5hStart.Add(service.RateLimitWindow5h)
|
|
|
|
|
|
out.Reset5hAt = &t
|
|
|
|
|
|
}
|
|
|
|
|
|
if k.Window1dStart != nil && !service.IsWindowExpired(k.Window1dStart, service.RateLimitWindow1d) {
|
|
|
|
|
|
t := k.Window1dStart.Add(service.RateLimitWindow1d)
|
|
|
|
|
|
out.Reset1dAt = &t
|
|
|
|
|
|
}
|
|
|
|
|
|
if k.Window7dStart != nil && !service.IsWindowExpired(k.Window7dStart, service.RateLimitWindow7d) {
|
|
|
|
|
|
t := k.Window7dStart.Add(service.RateLimitWindow7d)
|
|
|
|
|
|
out.Reset7dAt = &t
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func GroupFromServiceShallow(g *service.Group) *Group {
|
|
|
|
|
|
if g == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-01-19 18:58:42 +08:00
|
|
|
|
out := groupFromServiceBase(g)
|
|
|
|
|
|
return &out
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func GroupFromService(g *service.Group) *Group {
|
|
|
|
|
|
if g == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-01-19 18:58:42 +08:00
|
|
|
|
return GroupFromServiceShallow(g)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GroupFromServiceAdmin converts a service Group to DTO for admin users.
|
|
|
|
|
|
// It includes internal fields like model_routing and account_count.
|
|
|
|
|
|
func GroupFromServiceAdmin(g *service.Group) *AdminGroup {
|
|
|
|
|
|
if g == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
out := &AdminGroup{
|
2026-03-18 01:41:53 +08:00
|
|
|
|
Group: groupFromServiceBase(g),
|
|
|
|
|
|
ModelRouting: g.ModelRouting,
|
|
|
|
|
|
ModelRoutingEnabled: g.ModelRoutingEnabled,
|
|
|
|
|
|
MCPXMLInject: g.MCPXMLInject,
|
|
|
|
|
|
DefaultMappedModel: g.DefaultMappedModel,
|
|
|
|
|
|
SupportedModelScopes: g.SupportedModelScopes,
|
2026-03-17 22:09:28 +08:00
|
|
|
|
AccountCount: g.AccountCount,
|
|
|
|
|
|
ActiveAccountCount: g.ActiveAccountCount,
|
|
|
|
|
|
RateLimitedAccountCount: g.RateLimitedAccountCount,
|
2026-03-18 01:41:53 +08:00
|
|
|
|
SortOrder: g.SortOrder,
|
2026-01-19 18:58:42 +08:00
|
|
|
|
}
|
2025-12-26 15:40:24 +08:00
|
|
|
|
if len(g.AccountGroups) > 0 {
|
|
|
|
|
|
out.AccountGroups = make([]AccountGroup, 0, len(g.AccountGroups))
|
|
|
|
|
|
for i := range g.AccountGroups {
|
|
|
|
|
|
ag := g.AccountGroups[i]
|
|
|
|
|
|
out.AccountGroups = append(out.AccountGroups, *AccountGroupFromService(&ag))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 18:58:42 +08:00
|
|
|
|
func groupFromServiceBase(g *service.Group) Group {
|
|
|
|
|
|
return Group{
|
2026-02-04 20:35:09 +08:00
|
|
|
|
ID: g.ID,
|
|
|
|
|
|
Name: g.Name,
|
|
|
|
|
|
Description: g.Description,
|
|
|
|
|
|
Platform: g.Platform,
|
|
|
|
|
|
RateMultiplier: g.RateMultiplier,
|
|
|
|
|
|
IsExclusive: g.IsExclusive,
|
|
|
|
|
|
Status: g.Status,
|
|
|
|
|
|
SubscriptionType: g.SubscriptionType,
|
|
|
|
|
|
DailyLimitUSD: g.DailyLimitUSD,
|
|
|
|
|
|
WeeklyLimitUSD: g.WeeklyLimitUSD,
|
|
|
|
|
|
MonthlyLimitUSD: g.MonthlyLimitUSD,
|
|
|
|
|
|
ImagePrice1K: g.ImagePrice1K,
|
|
|
|
|
|
ImagePrice2K: g.ImagePrice2K,
|
|
|
|
|
|
ImagePrice4K: g.ImagePrice4K,
|
|
|
|
|
|
SoraImagePrice360: g.SoraImagePrice360,
|
|
|
|
|
|
SoraImagePrice540: g.SoraImagePrice540,
|
|
|
|
|
|
SoraVideoPricePerRequest: g.SoraVideoPricePerRequest,
|
|
|
|
|
|
SoraVideoPricePerRequestHD: g.SoraVideoPricePerRequestHD,
|
|
|
|
|
|
ClaudeCodeOnly: g.ClaudeCodeOnly,
|
|
|
|
|
|
FallbackGroupID: g.FallbackGroupID,
|
2026-02-02 22:13:50 +08:00
|
|
|
|
FallbackGroupIDOnInvalidRequest: g.FallbackGroupIDOnInvalidRequest,
|
2026-02-28 15:01:20 +08:00
|
|
|
|
SoraStorageQuotaBytes: g.SoraStorageQuotaBytes,
|
2026-03-07 17:02:19 +08:00
|
|
|
|
AllowMessagesDispatch: g.AllowMessagesDispatch,
|
2026-02-03 16:48:52 +08:00
|
|
|
|
CreatedAt: g.CreatedAt,
|
|
|
|
|
|
UpdatedAt: g.UpdatedAt,
|
2026-01-19 18:58:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-26 15:40:24 +08:00
|
|
|
|
func AccountFromServiceShallow(a *service.Account) *Account {
|
|
|
|
|
|
if a == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-01-16 23:36:52 +08:00
|
|
|
|
out := &Account{
|
2026-01-03 06:34:00 -08:00
|
|
|
|
ID: a.ID,
|
|
|
|
|
|
Name: a.Name,
|
2026-01-05 14:07:33 +08:00
|
|
|
|
Notes: a.Notes,
|
2026-01-03 06:34:00 -08:00
|
|
|
|
Platform: a.Platform,
|
|
|
|
|
|
Type: a.Type,
|
|
|
|
|
|
Credentials: a.Credentials,
|
|
|
|
|
|
Extra: a.Extra,
|
|
|
|
|
|
ProxyID: a.ProxyID,
|
|
|
|
|
|
Concurrency: a.Concurrency,
|
2026-03-06 05:07:10 +08:00
|
|
|
|
LoadFactor: a.LoadFactor,
|
2026-01-03 06:34:00 -08:00
|
|
|
|
Priority: a.Priority,
|
2026-01-14 16:12:08 +08:00
|
|
|
|
RateMultiplier: a.BillingRateMultiplier(),
|
2026-01-03 06:34:00 -08:00
|
|
|
|
Status: a.Status,
|
|
|
|
|
|
ErrorMessage: a.ErrorMessage,
|
|
|
|
|
|
LastUsedAt: a.LastUsedAt,
|
2026-01-07 16:59:35 +08:00
|
|
|
|
ExpiresAt: timeToUnixSeconds(a.ExpiresAt),
|
|
|
|
|
|
AutoPauseOnExpired: a.AutoPauseOnExpired,
|
2026-01-03 06:34:00 -08:00
|
|
|
|
CreatedAt: a.CreatedAt,
|
|
|
|
|
|
UpdatedAt: a.UpdatedAt,
|
|
|
|
|
|
Schedulable: a.Schedulable,
|
|
|
|
|
|
RateLimitedAt: a.RateLimitedAt,
|
|
|
|
|
|
RateLimitResetAt: a.RateLimitResetAt,
|
|
|
|
|
|
OverloadUntil: a.OverloadUntil,
|
|
|
|
|
|
TempUnschedulableUntil: a.TempUnschedulableUntil,
|
|
|
|
|
|
TempUnschedulableReason: a.TempUnschedulableReason,
|
|
|
|
|
|
SessionWindowStart: a.SessionWindowStart,
|
|
|
|
|
|
SessionWindowEnd: a.SessionWindowEnd,
|
|
|
|
|
|
SessionWindowStatus: a.SessionWindowStatus,
|
|
|
|
|
|
GroupIDs: a.GroupIDs,
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
2026-01-16 23:36:52 +08:00
|
|
|
|
|
|
|
|
|
|
// 提取 5h 窗口费用控制和会话数量控制配置(仅 Anthropic OAuth/SetupToken 账号有效)
|
|
|
|
|
|
if a.IsAnthropicOAuthOrSetupToken() {
|
|
|
|
|
|
if limit := a.GetWindowCostLimit(); limit > 0 {
|
|
|
|
|
|
out.WindowCostLimit = &limit
|
|
|
|
|
|
}
|
|
|
|
|
|
if reserve := a.GetWindowCostStickyReserve(); reserve > 0 {
|
|
|
|
|
|
out.WindowCostStickyReserve = &reserve
|
|
|
|
|
|
}
|
|
|
|
|
|
if maxSessions := a.GetMaxSessions(); maxSessions > 0 {
|
|
|
|
|
|
out.MaxSessions = &maxSessions
|
|
|
|
|
|
}
|
|
|
|
|
|
if idleTimeout := a.GetSessionIdleTimeoutMinutes(); idleTimeout > 0 {
|
|
|
|
|
|
out.SessionIdleTimeoutMin = &idleTimeout
|
|
|
|
|
|
}
|
2026-02-28 01:26:45 +08:00
|
|
|
|
if rpm := a.GetBaseRPM(); rpm > 0 {
|
|
|
|
|
|
out.BaseRPM = &rpm
|
|
|
|
|
|
strategy := a.GetRPMStrategy()
|
|
|
|
|
|
out.RPMStrategy = &strategy
|
|
|
|
|
|
buffer := a.GetRPMStickyBuffer()
|
|
|
|
|
|
out.RPMStickyBuffer = &buffer
|
|
|
|
|
|
}
|
2026-03-03 01:02:39 +08:00
|
|
|
|
// 用户消息队列模式
|
|
|
|
|
|
if mode := a.GetUserMsgQueueMode(); mode != "" {
|
|
|
|
|
|
out.UserMsgQueueMode = &mode
|
|
|
|
|
|
}
|
2026-01-18 20:06:56 +08:00
|
|
|
|
// TLS指纹伪装开关
|
|
|
|
|
|
if a.IsTLSFingerprintEnabled() {
|
|
|
|
|
|
enabled := true
|
|
|
|
|
|
out.EnableTLSFingerprint = &enabled
|
|
|
|
|
|
}
|
2026-01-19 10:22:13 +08:00
|
|
|
|
// 会话ID伪装开关
|
|
|
|
|
|
if a.IsSessionIDMaskingEnabled() {
|
|
|
|
|
|
enabled := true
|
|
|
|
|
|
out.EnableSessionIDMasking = &enabled
|
|
|
|
|
|
}
|
2026-02-17 11:22:08 +03:00
|
|
|
|
// 缓存 TTL 强制替换
|
|
|
|
|
|
if a.IsCacheTTLOverrideEnabled() {
|
|
|
|
|
|
enabled := true
|
|
|
|
|
|
out.CacheTTLOverrideEnabled = &enabled
|
|
|
|
|
|
target := a.GetCacheTTLOverrideTarget()
|
|
|
|
|
|
out.CacheTTLOverrideTarget = &target
|
|
|
|
|
|
}
|
2026-01-16 23:36:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-14 17:13:30 +08:00
|
|
|
|
// 提取账号配额限制(apikey / bedrock 类型有效)
|
|
|
|
|
|
if a.IsAPIKeyOrBedrock() {
|
2026-03-05 20:54:37 +08:00
|
|
|
|
if limit := a.GetQuotaLimit(); limit > 0 {
|
|
|
|
|
|
out.QuotaLimit = &limit
|
2026-03-07 19:06:59 +08:00
|
|
|
|
used := a.GetQuotaUsed()
|
2026-03-05 20:54:37 +08:00
|
|
|
|
out.QuotaUsed = &used
|
|
|
|
|
|
}
|
2026-03-07 19:06:59 +08:00
|
|
|
|
if limit := a.GetQuotaDailyLimit(); limit > 0 {
|
|
|
|
|
|
out.QuotaDailyLimit = &limit
|
|
|
|
|
|
used := a.GetQuotaDailyUsed()
|
|
|
|
|
|
out.QuotaDailyUsed = &used
|
|
|
|
|
|
}
|
|
|
|
|
|
if limit := a.GetQuotaWeeklyLimit(); limit > 0 {
|
|
|
|
|
|
out.QuotaWeeklyLimit = &limit
|
|
|
|
|
|
used := a.GetQuotaWeeklyUsed()
|
|
|
|
|
|
out.QuotaWeeklyUsed = &used
|
|
|
|
|
|
}
|
2026-03-13 11:12:37 +08:00
|
|
|
|
// 固定时间重置配置
|
|
|
|
|
|
if mode := a.GetQuotaDailyResetMode(); mode == "fixed" {
|
|
|
|
|
|
out.QuotaDailyResetMode = &mode
|
|
|
|
|
|
hour := a.GetQuotaDailyResetHour()
|
|
|
|
|
|
out.QuotaDailyResetHour = &hour
|
|
|
|
|
|
}
|
|
|
|
|
|
if mode := a.GetQuotaWeeklyResetMode(); mode == "fixed" {
|
|
|
|
|
|
out.QuotaWeeklyResetMode = &mode
|
|
|
|
|
|
day := a.GetQuotaWeeklyResetDay()
|
|
|
|
|
|
out.QuotaWeeklyResetDay = &day
|
|
|
|
|
|
hour := a.GetQuotaWeeklyResetHour()
|
|
|
|
|
|
out.QuotaWeeklyResetHour = &hour
|
|
|
|
|
|
}
|
|
|
|
|
|
if a.GetQuotaDailyResetMode() == "fixed" || a.GetQuotaWeeklyResetMode() == "fixed" {
|
|
|
|
|
|
tz := a.GetQuotaResetTimezone()
|
|
|
|
|
|
out.QuotaResetTimezone = &tz
|
|
|
|
|
|
}
|
|
|
|
|
|
if a.Extra != nil {
|
|
|
|
|
|
if v, ok := a.Extra["quota_daily_reset_at"].(string); ok && v != "" {
|
|
|
|
|
|
out.QuotaDailyResetAt = &v
|
|
|
|
|
|
}
|
|
|
|
|
|
if v, ok := a.Extra["quota_weekly_reset_at"].(string); ok && v != "" {
|
|
|
|
|
|
out.QuotaWeeklyResetAt = &v
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-05 20:54:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-16 23:36:52 +08:00
|
|
|
|
return out
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func AccountFromService(a *service.Account) *Account {
|
|
|
|
|
|
if a == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
out := AccountFromServiceShallow(a)
|
|
|
|
|
|
out.Proxy = ProxyFromService(a.Proxy)
|
|
|
|
|
|
if len(a.AccountGroups) > 0 {
|
|
|
|
|
|
out.AccountGroups = make([]AccountGroup, 0, len(a.AccountGroups))
|
|
|
|
|
|
for i := range a.AccountGroups {
|
|
|
|
|
|
ag := a.AccountGroups[i]
|
|
|
|
|
|
out.AccountGroups = append(out.AccountGroups, *AccountGroupFromService(&ag))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(a.Groups) > 0 {
|
|
|
|
|
|
out.Groups = make([]*Group, 0, len(a.Groups))
|
|
|
|
|
|
for _, g := range a.Groups {
|
|
|
|
|
|
out.Groups = append(out.Groups, GroupFromServiceShallow(g))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-07 16:59:35 +08:00
|
|
|
|
func timeToUnixSeconds(value *time.Time) *int64 {
|
|
|
|
|
|
if value == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
ts := value.Unix()
|
|
|
|
|
|
return &ts
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-26 15:40:24 +08:00
|
|
|
|
func AccountGroupFromService(ag *service.AccountGroup) *AccountGroup {
|
|
|
|
|
|
if ag == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &AccountGroup{
|
|
|
|
|
|
AccountID: ag.AccountID,
|
|
|
|
|
|
GroupID: ag.GroupID,
|
|
|
|
|
|
Priority: ag.Priority,
|
|
|
|
|
|
CreatedAt: ag.CreatedAt,
|
|
|
|
|
|
Account: AccountFromServiceShallow(ag.Account),
|
|
|
|
|
|
Group: GroupFromServiceShallow(ag.Group),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ProxyFromService(p *service.Proxy) *Proxy {
|
|
|
|
|
|
if p == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &Proxy{
|
|
|
|
|
|
ID: p.ID,
|
|
|
|
|
|
Name: p.Name,
|
|
|
|
|
|
Protocol: p.Protocol,
|
|
|
|
|
|
Host: p.Host,
|
|
|
|
|
|
Port: p.Port,
|
|
|
|
|
|
Username: p.Username,
|
|
|
|
|
|
Status: p.Status,
|
|
|
|
|
|
CreatedAt: p.CreatedAt,
|
|
|
|
|
|
UpdatedAt: p.UpdatedAt,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ProxyWithAccountCountFromService(p *service.ProxyWithAccountCount) *ProxyWithAccountCount {
|
|
|
|
|
|
if p == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ProxyWithAccountCount{
|
2026-01-14 19:45:29 +08:00
|
|
|
|
Proxy: *ProxyFromService(&p.Proxy),
|
|
|
|
|
|
AccountCount: p.AccountCount,
|
|
|
|
|
|
LatencyMs: p.LatencyMs,
|
|
|
|
|
|
LatencyStatus: p.LatencyStatus,
|
|
|
|
|
|
LatencyMessage: p.LatencyMessage,
|
2026-01-15 15:15:20 +08:00
|
|
|
|
IPAddress: p.IPAddress,
|
|
|
|
|
|
Country: p.Country,
|
|
|
|
|
|
CountryCode: p.CountryCode,
|
|
|
|
|
|
Region: p.Region,
|
|
|
|
|
|
City: p.City,
|
2026-02-20 12:13:04 +08:00
|
|
|
|
QualityStatus: p.QualityStatus,
|
|
|
|
|
|
QualityScore: p.QualityScore,
|
|
|
|
|
|
QualityGrade: p.QualityGrade,
|
|
|
|
|
|
QualitySummary: p.QualitySummary,
|
|
|
|
|
|
QualityChecked: p.QualityChecked,
|
2026-01-14 19:45:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-01 21:06:53 +08:00
|
|
|
|
// ProxyFromServiceAdmin converts a service Proxy to AdminProxy DTO for admin users.
|
|
|
|
|
|
// It includes the password field - user-facing endpoints must not use this.
|
|
|
|
|
|
func ProxyFromServiceAdmin(p *service.Proxy) *AdminProxy {
|
|
|
|
|
|
if p == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
base := ProxyFromService(p)
|
|
|
|
|
|
if base == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &AdminProxy{
|
|
|
|
|
|
Proxy: *base,
|
|
|
|
|
|
Password: p.Password,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProxyWithAccountCountFromServiceAdmin converts a service ProxyWithAccountCount to AdminProxyWithAccountCount DTO.
|
|
|
|
|
|
// It includes the password field - user-facing endpoints must not use this.
|
|
|
|
|
|
func ProxyWithAccountCountFromServiceAdmin(p *service.ProxyWithAccountCount) *AdminProxyWithAccountCount {
|
|
|
|
|
|
if p == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
admin := ProxyFromServiceAdmin(&p.Proxy)
|
|
|
|
|
|
if admin == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &AdminProxyWithAccountCount{
|
|
|
|
|
|
AdminProxy: *admin,
|
|
|
|
|
|
AccountCount: p.AccountCount,
|
|
|
|
|
|
LatencyMs: p.LatencyMs,
|
|
|
|
|
|
LatencyStatus: p.LatencyStatus,
|
|
|
|
|
|
LatencyMessage: p.LatencyMessage,
|
|
|
|
|
|
IPAddress: p.IPAddress,
|
|
|
|
|
|
Country: p.Country,
|
|
|
|
|
|
CountryCode: p.CountryCode,
|
|
|
|
|
|
Region: p.Region,
|
|
|
|
|
|
City: p.City,
|
|
|
|
|
|
QualityStatus: p.QualityStatus,
|
|
|
|
|
|
QualityScore: p.QualityScore,
|
|
|
|
|
|
QualityGrade: p.QualityGrade,
|
|
|
|
|
|
QualitySummary: p.QualitySummary,
|
|
|
|
|
|
QualityChecked: p.QualityChecked,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-14 19:45:29 +08:00
|
|
|
|
func ProxyAccountSummaryFromService(a *service.ProxyAccountSummary) *ProxyAccountSummary {
|
|
|
|
|
|
if a == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ProxyAccountSummary{
|
|
|
|
|
|
ID: a.ID,
|
|
|
|
|
|
Name: a.Name,
|
|
|
|
|
|
Platform: a.Platform,
|
|
|
|
|
|
Type: a.Type,
|
|
|
|
|
|
Notes: a.Notes,
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func RedeemCodeFromService(rc *service.RedeemCode) *RedeemCode {
|
|
|
|
|
|
if rc == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-01-19 20:09:35 +08:00
|
|
|
|
out := redeemCodeFromServiceBase(rc)
|
|
|
|
|
|
return &out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// RedeemCodeFromServiceAdmin converts a service RedeemCode to DTO for admin users.
|
|
|
|
|
|
// It includes notes - user-facing endpoints must not use this.
|
|
|
|
|
|
func RedeemCodeFromServiceAdmin(rc *service.RedeemCode) *AdminRedeemCode {
|
|
|
|
|
|
if rc == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &AdminRedeemCode{
|
|
|
|
|
|
RedeemCode: redeemCodeFromServiceBase(rc),
|
2026-01-19 21:26:30 +08:00
|
|
|
|
Notes: rc.Notes,
|
2026-01-19 20:09:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func redeemCodeFromServiceBase(rc *service.RedeemCode) RedeemCode {
|
2026-02-02 17:44:50 +08:00
|
|
|
|
out := RedeemCode{
|
2025-12-26 15:40:24 +08:00
|
|
|
|
ID: rc.ID,
|
|
|
|
|
|
Code: rc.Code,
|
|
|
|
|
|
Type: rc.Type,
|
|
|
|
|
|
Value: rc.Value,
|
|
|
|
|
|
Status: rc.Status,
|
|
|
|
|
|
UsedBy: rc.UsedBy,
|
|
|
|
|
|
UsedAt: rc.UsedAt,
|
|
|
|
|
|
CreatedAt: rc.CreatedAt,
|
|
|
|
|
|
GroupID: rc.GroupID,
|
|
|
|
|
|
ValidityDays: rc.ValidityDays,
|
|
|
|
|
|
User: UserFromServiceShallow(rc.User),
|
|
|
|
|
|
Group: GroupFromServiceShallow(rc.Group),
|
|
|
|
|
|
}
|
2026-02-02 17:44:50 +08:00
|
|
|
|
|
|
|
|
|
|
// For admin_balance/admin_concurrency types, include notes so users can see
|
|
|
|
|
|
// why they were charged or credited by admin
|
|
|
|
|
|
if (rc.Type == "admin_balance" || rc.Type == "admin_concurrency") && rc.Notes != "" {
|
|
|
|
|
|
out.Notes = &rc.Notes
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return out
|
2025-12-26 15:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-08 17:45:31 +08:00
|
|
|
|
// AccountSummaryFromService returns a minimal AccountSummary for usage log display.
|
|
|
|
|
|
// Only includes ID and Name - no sensitive fields like Credentials, Proxy, etc.
|
|
|
|
|
|
func AccountSummaryFromService(a *service.Account) *AccountSummary {
|
|
|
|
|
|
if a == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &AccountSummary{
|
|
|
|
|
|
ID: a.ID,
|
|
|
|
|
|
Name: a.Name,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 17:05:42 +08:00
|
|
|
|
func usageLogFromServiceUser(l *service.UsageLog) UsageLog {
|
|
|
|
|
|
// 普通用户 DTO:严禁包含管理员字段(例如 account_rate_multiplier、ip_address、account)。
|
2026-02-28 15:01:20 +08:00
|
|
|
|
requestType := l.EffectiveRequestType()
|
|
|
|
|
|
stream, openAIWSMode := service.ApplyLegacyRequestFields(requestType, l.Stream, l.OpenAIWSMode)
|
2026-01-19 17:05:42 +08:00
|
|
|
|
return UsageLog{
|
2025-12-26 15:40:24 +08:00
|
|
|
|
ID: l.ID,
|
|
|
|
|
|
UserID: l.UserID,
|
2026-01-04 19:27:53 +08:00
|
|
|
|
APIKeyID: l.APIKeyID,
|
2025-12-26 15:40:24 +08:00
|
|
|
|
AccountID: l.AccountID,
|
|
|
|
|
|
RequestID: l.RequestID,
|
|
|
|
|
|
Model: l.Model,
|
2026-03-08 23:22:28 +08:00
|
|
|
|
ServiceTier: l.ServiceTier,
|
2026-02-03 14:36:29 +08:00
|
|
|
|
ReasoningEffort: l.ReasoningEffort,
|
2026-03-15 11:26:42 +08:00
|
|
|
|
InboundEndpoint: l.InboundEndpoint,
|
|
|
|
|
|
UpstreamEndpoint: l.UpstreamEndpoint,
|
2025-12-26 15:40:24 +08:00
|
|
|
|
GroupID: l.GroupID,
|
|
|
|
|
|
SubscriptionID: l.SubscriptionID,
|
|
|
|
|
|
InputTokens: l.InputTokens,
|
|
|
|
|
|
OutputTokens: l.OutputTokens,
|
|
|
|
|
|
CacheCreationTokens: l.CacheCreationTokens,
|
|
|
|
|
|
CacheReadTokens: l.CacheReadTokens,
|
|
|
|
|
|
CacheCreation5mTokens: l.CacheCreation5mTokens,
|
|
|
|
|
|
CacheCreation1hTokens: l.CacheCreation1hTokens,
|
|
|
|
|
|
InputCost: l.InputCost,
|
|
|
|
|
|
OutputCost: l.OutputCost,
|
|
|
|
|
|
CacheCreationCost: l.CacheCreationCost,
|
|
|
|
|
|
CacheReadCost: l.CacheReadCost,
|
|
|
|
|
|
TotalCost: l.TotalCost,
|
|
|
|
|
|
ActualCost: l.ActualCost,
|
|
|
|
|
|
RateMultiplier: l.RateMultiplier,
|
|
|
|
|
|
BillingType: l.BillingType,
|
2026-02-28 15:01:20 +08:00
|
|
|
|
RequestType: requestType.String(),
|
|
|
|
|
|
Stream: stream,
|
|
|
|
|
|
OpenAIWSMode: openAIWSMode,
|
2025-12-26 15:40:24 +08:00
|
|
|
|
DurationMs: l.DurationMs,
|
|
|
|
|
|
FirstTokenMs: l.FirstTokenMs,
|
2026-01-05 17:07:29 +08:00
|
|
|
|
ImageCount: l.ImageCount,
|
|
|
|
|
|
ImageSize: l.ImageSize,
|
2026-01-31 20:22:22 +08:00
|
|
|
|
MediaType: l.MediaType,
|
2026-01-08 21:02:13 +08:00
|
|
|
|
UserAgent: l.UserAgent,
|
2026-02-17 11:22:08 +03:00
|
|
|
|
CacheTTLOverridden: l.CacheTTLOverridden,
|
2025-12-26 15:40:24 +08:00
|
|
|
|
CreatedAt: l.CreatedAt,
|
|
|
|
|
|
User: UserFromServiceShallow(l.User),
|
2026-01-04 19:27:53 +08:00
|
|
|
|
APIKey: APIKeyFromService(l.APIKey),
|
2025-12-26 15:40:24 +08:00
|
|
|
|
Group: GroupFromServiceShallow(l.Group),
|
|
|
|
|
|
Subscription: UserSubscriptionFromService(l.Subscription),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-08 17:45:31 +08:00
|
|
|
|
// UsageLogFromService converts a service UsageLog to DTO for regular users.
|
2026-01-09 21:59:32 +08:00
|
|
|
|
// It excludes Account details and IP address - users should not see these.
|
2026-01-08 17:45:31 +08:00
|
|
|
|
func UsageLogFromService(l *service.UsageLog) *UsageLog {
|
2026-01-19 17:05:42 +08:00
|
|
|
|
if l == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
u := usageLogFromServiceUser(l)
|
|
|
|
|
|
return &u
|
2026-01-08 17:45:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UsageLogFromServiceAdmin converts a service UsageLog to DTO for admin users.
|
2026-01-09 21:59:32 +08:00
|
|
|
|
// It includes minimal Account info (ID, Name only) and IP address.
|
2026-01-19 17:05:42 +08:00
|
|
|
|
func UsageLogFromServiceAdmin(l *service.UsageLog) *AdminUsageLog {
|
2026-01-08 17:45:31 +08:00
|
|
|
|
if l == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-01-19 17:05:42 +08:00
|
|
|
|
return &AdminUsageLog{
|
|
|
|
|
|
UsageLog: usageLogFromServiceUser(l),
|
|
|
|
|
|
AccountRateMultiplier: l.AccountRateMultiplier,
|
|
|
|
|
|
IPAddress: l.IPAddress,
|
|
|
|
|
|
Account: AccountSummaryFromService(l.Account),
|
|
|
|
|
|
}
|
2026-01-08 17:45:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-18 10:52:18 +08:00
|
|
|
|
func UsageCleanupTaskFromService(task *service.UsageCleanupTask) *UsageCleanupTask {
|
|
|
|
|
|
if task == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &UsageCleanupTask{
|
|
|
|
|
|
ID: task.ID,
|
|
|
|
|
|
Status: task.Status,
|
|
|
|
|
|
Filters: UsageCleanupFilters{
|
|
|
|
|
|
StartTime: task.Filters.StartTime,
|
|
|
|
|
|
EndTime: task.Filters.EndTime,
|
|
|
|
|
|
UserID: task.Filters.UserID,
|
|
|
|
|
|
APIKeyID: task.Filters.APIKeyID,
|
|
|
|
|
|
AccountID: task.Filters.AccountID,
|
|
|
|
|
|
GroupID: task.Filters.GroupID,
|
|
|
|
|
|
Model: task.Filters.Model,
|
2026-02-28 15:01:20 +08:00
|
|
|
|
RequestType: requestTypeStringPtr(task.Filters.RequestType),
|
2026-01-18 10:52:18 +08:00
|
|
|
|
Stream: task.Filters.Stream,
|
|
|
|
|
|
BillingType: task.Filters.BillingType,
|
|
|
|
|
|
},
|
|
|
|
|
|
CreatedBy: task.CreatedBy,
|
|
|
|
|
|
DeletedRows: task.DeletedRows,
|
|
|
|
|
|
ErrorMessage: task.ErrorMsg,
|
|
|
|
|
|
CanceledBy: task.CanceledBy,
|
|
|
|
|
|
CanceledAt: task.CanceledAt,
|
|
|
|
|
|
StartedAt: task.StartedAt,
|
|
|
|
|
|
FinishedAt: task.FinishedAt,
|
|
|
|
|
|
CreatedAt: task.CreatedAt,
|
|
|
|
|
|
UpdatedAt: task.UpdatedAt,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-28 15:01:20 +08:00
|
|
|
|
|
|
|
|
|
|
func requestTypeStringPtr(requestType *int16) *string {
|
|
|
|
|
|
if requestType == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
value := service.RequestTypeFromInt16(*requestType).String()
|
|
|
|
|
|
return &value
|
|
|
|
|
|
}
|
2026-01-18 10:52:18 +08:00
|
|
|
|
|
2025-12-26 15:40:24 +08:00
|
|
|
|
func SettingFromService(s *service.Setting) *Setting {
|
|
|
|
|
|
if s == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &Setting{
|
|
|
|
|
|
ID: s.ID,
|
|
|
|
|
|
Key: s.Key,
|
|
|
|
|
|
Value: s.Value,
|
|
|
|
|
|
UpdatedAt: s.UpdatedAt,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func UserSubscriptionFromService(sub *service.UserSubscription) *UserSubscription {
|
|
|
|
|
|
if sub == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-01-19 19:35:13 +08:00
|
|
|
|
out := userSubscriptionFromServiceBase(sub)
|
|
|
|
|
|
return &out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UserSubscriptionFromServiceAdmin converts a service UserSubscription to DTO for admin users.
|
|
|
|
|
|
// It includes assignment metadata and notes.
|
|
|
|
|
|
func UserSubscriptionFromServiceAdmin(sub *service.UserSubscription) *AdminUserSubscription {
|
|
|
|
|
|
if sub == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &AdminUserSubscription{
|
|
|
|
|
|
UserSubscription: userSubscriptionFromServiceBase(sub),
|
|
|
|
|
|
AssignedBy: sub.AssignedBy,
|
|
|
|
|
|
AssignedAt: sub.AssignedAt,
|
|
|
|
|
|
Notes: sub.Notes,
|
|
|
|
|
|
AssignedByUser: UserFromServiceShallow(sub.AssignedByUser),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func userSubscriptionFromServiceBase(sub *service.UserSubscription) UserSubscription {
|
|
|
|
|
|
return UserSubscription{
|
2025-12-26 15:40:24 +08:00
|
|
|
|
ID: sub.ID,
|
|
|
|
|
|
UserID: sub.UserID,
|
|
|
|
|
|
GroupID: sub.GroupID,
|
|
|
|
|
|
StartsAt: sub.StartsAt,
|
|
|
|
|
|
ExpiresAt: sub.ExpiresAt,
|
|
|
|
|
|
Status: sub.Status,
|
|
|
|
|
|
DailyWindowStart: sub.DailyWindowStart,
|
|
|
|
|
|
WeeklyWindowStart: sub.WeeklyWindowStart,
|
|
|
|
|
|
MonthlyWindowStart: sub.MonthlyWindowStart,
|
|
|
|
|
|
DailyUsageUSD: sub.DailyUsageUSD,
|
|
|
|
|
|
WeeklyUsageUSD: sub.WeeklyUsageUSD,
|
|
|
|
|
|
MonthlyUsageUSD: sub.MonthlyUsageUSD,
|
|
|
|
|
|
CreatedAt: sub.CreatedAt,
|
|
|
|
|
|
UpdatedAt: sub.UpdatedAt,
|
|
|
|
|
|
User: UserFromServiceShallow(sub.User),
|
|
|
|
|
|
Group: GroupFromServiceShallow(sub.Group),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-26 21:22:48 +08:00
|
|
|
|
|
|
|
|
|
|
func BulkAssignResultFromService(r *service.BulkAssignResult) *BulkAssignResult {
|
|
|
|
|
|
if r == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2026-01-19 19:35:13 +08:00
|
|
|
|
subs := make([]AdminUserSubscription, 0, len(r.Subscriptions))
|
2025-12-26 21:22:48 +08:00
|
|
|
|
for i := range r.Subscriptions {
|
2026-01-19 19:35:13 +08:00
|
|
|
|
subs = append(subs, *UserSubscriptionFromServiceAdmin(&r.Subscriptions[i]))
|
2025-12-26 21:22:48 +08:00
|
|
|
|
}
|
2026-02-23 12:45:37 +08:00
|
|
|
|
statuses := make(map[string]string, len(r.Statuses))
|
|
|
|
|
|
for userID, status := range r.Statuses {
|
|
|
|
|
|
statuses[strconv.FormatInt(userID, 10)] = status
|
|
|
|
|
|
}
|
2025-12-26 21:22:48 +08:00
|
|
|
|
return &BulkAssignResult{
|
|
|
|
|
|
SuccessCount: r.SuccessCount,
|
2026-02-23 12:45:37 +08:00
|
|
|
|
CreatedCount: r.CreatedCount,
|
|
|
|
|
|
ReusedCount: r.ReusedCount,
|
2025-12-26 21:22:48 +08:00
|
|
|
|
FailedCount: r.FailedCount,
|
|
|
|
|
|
Subscriptions: subs,
|
|
|
|
|
|
Errors: r.Errors,
|
2026-02-23 12:45:37 +08:00
|
|
|
|
Statuses: statuses,
|
2025-12-26 21:22:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-10 13:14:35 +08:00
|
|
|
|
|
|
|
|
|
|
func PromoCodeFromService(pc *service.PromoCode) *PromoCode {
|
|
|
|
|
|
if pc == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &PromoCode{
|
|
|
|
|
|
ID: pc.ID,
|
|
|
|
|
|
Code: pc.Code,
|
|
|
|
|
|
BonusAmount: pc.BonusAmount,
|
|
|
|
|
|
MaxUses: pc.MaxUses,
|
|
|
|
|
|
UsedCount: pc.UsedCount,
|
|
|
|
|
|
Status: pc.Status,
|
|
|
|
|
|
ExpiresAt: pc.ExpiresAt,
|
|
|
|
|
|
Notes: pc.Notes,
|
|
|
|
|
|
CreatedAt: pc.CreatedAt,
|
|
|
|
|
|
UpdatedAt: pc.UpdatedAt,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func PromoCodeUsageFromService(u *service.PromoCodeUsage) *PromoCodeUsage {
|
|
|
|
|
|
if u == nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return &PromoCodeUsage{
|
|
|
|
|
|
ID: u.ID,
|
|
|
|
|
|
PromoCodeID: u.PromoCodeID,
|
|
|
|
|
|
UserID: u.UserID,
|
|
|
|
|
|
BonusAmount: u.BonusAmount,
|
|
|
|
|
|
UsedAt: u.UsedAt,
|
|
|
|
|
|
User: UserFromServiceShallow(u.User),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|