Skip to content

Commit e6ea4a2

Browse files
committed
refactory: 명칭 변경 Token-> Credit
도메인 명칭 변경 Token-> Credit 사유 : JWT Token과 명칭이 겹치고 좀 더 알맞는 명칭으로 판단됨
1 parent d4048d4 commit e6ea4a2

28 files changed

+425
-429
lines changed

ProjectVG.Api/ApiServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static IServiceCollection AddDevelopmentCors(this IServiceCollection serv
7070
services.AddCors(options => {
7171
options.AddPolicy("AllowAll",
7272
policy => policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()
73-
.WithExposedHeaders("X-Access-Token", "X-Refresh-Token", "X-Expires-In", "X-UID"));
73+
.WithExposedHeaders("X-Access-Credit", "X-Refresh-Credit", "X-Expires-In", "X-UID"));
7474
});
7575

7676
return services;

ProjectVG.Api/Controllers/AuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task<IActionResult> GuestLogin([FromBody] string guestId)
6161

6262
private string GetRefreshTokenFromHeader()
6363
{
64-
return Request.Headers["X-Refresh-Token"].FirstOrDefault() ?? string.Empty;
64+
return Request.Headers["X-Refresh-Credit"].FirstOrDefault() ?? string.Empty;
6565
}
6666
}
6767
}

ProjectVG.Api/Controllers/TokenController.cs renamed to ProjectVG.Api/Controllers/CreditController.cs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
11
using Microsoft.AspNetCore.Mvc;
2-
using ProjectVG.Application.Services.Token;
2+
using ProjectVG.Application.Services.Credit;
33
using ProjectVG.Api.Filters;
44
using System.Security.Claims;
55

66
namespace ProjectVG.Api.Controllers
77
{
88
/// <summary>
9-
/// 토큰 관리 API 컨트롤러
10-
/// 사용자의 토큰 잔액 조회, 거래 내역 조회 등을 제공
9+
/// 크래딧 관리 API 컨트롤러
10+
/// 사용자의 크래딧 잔액 조회, 거래 내역 조회 등을 제공
1111
/// </summary>
1212
[ApiController]
13-
[Route("api/v1/tokens")]
13+
[Route("api/v1/credits")]
1414
[JwtAuthentication]
15-
public class TokenController : ControllerBase
15+
public class CreditController : ControllerBase
1616
{
17-
private readonly ITokenManagementService _tokenManagementService;
18-
private readonly ILogger<TokenController> _logger;
17+
private readonly ICreditManagementService _creditManagementService;
18+
private readonly ILogger<CreditController> _logger;
1919

20-
public TokenController(ITokenManagementService tokenManagementService, ILogger<TokenController> logger)
20+
public CreditController(ICreditManagementService creditManagementService, ILogger<CreditController> logger)
2121
{
22-
_tokenManagementService = tokenManagementService;
22+
_creditManagementService = creditManagementService;
2323
_logger = logger;
2424
}
2525

2626
/// <summary>
27-
/// 현재 사용자의 토큰 잔액 조회
27+
/// 현재 사용자의 크래딧 잔액 조회
2828
/// </summary>
29-
/// <returns>토큰 잔액 정보</returns>
29+
/// <returns>크래딧 잔액 정보</returns>
3030
[HttpGet("balance")]
3131
public async Task<IActionResult> GetBalance()
3232
{
3333
var userId = GetCurrentUserId();
3434

3535
try
3636
{
37-
var balance = await _tokenManagementService.GetTokenBalanceAsync(userId);
37+
var balance = await _creditManagementService.GetCreditBalanceAsync(userId);
3838
return Ok(new
3939
{
4040
userId = balance.UserId,
4141
currentBalance = balance.CurrentBalance,
4242
totalEarned = balance.TotalEarned,
4343
totalSpent = balance.TotalSpent,
4444
lastUpdated = balance.LastUpdated,
45-
initialTokensGranted = balance.InitialTokensGranted
45+
initialTokensGranted = balance.InitialCreditsGranted
4646
});
4747
}
4848
catch (Exception ex)
4949
{
50-
_logger.LogError(ex, "Failed to get token balance for user {UserId}", userId);
51-
return StatusCode(500, new { error = "Failed to retrieve token balance" });
50+
_logger.LogError(ex, "Failed to get credit balance for user {UserId}", userId);
51+
return StatusCode(500, new { error = "Failed to retrieve credit balance" });
5252
}
5353
}
5454

5555
/// <summary>
56-
/// 토큰 거래 내역 조회 (페이지네이션)
56+
/// 크래딧 거래 내역 조회 (페이지네이션)
5757
/// </summary>
5858
/// <param name="page">페이지 번호 (1부터 시작)</param>
5959
/// <param name="pageSize">페이지 크기 (최대 100)</param>
6060
/// <param name="type">거래 유형 필터 (Earn=1, Spend=2)</param>
61-
/// <returns>토큰 거래 내역</returns>
61+
/// <returns>크래딧 거래 내역</returns>
6262
[HttpGet("history")]
6363
public async Task<IActionResult> GetHistory(
6464
[FromQuery] int page = 1,
@@ -71,15 +71,15 @@ public async Task<IActionResult> GetHistory(
7171
if (page < 1) page = 1;
7272
if (pageSize < 1 || pageSize > 100) pageSize = 20;
7373

74-
Domain.Entities.Tokens.TokenTransactionType? transactionType = null;
75-
if (type.HasValue && Enum.IsDefined(typeof(Domain.Entities.Tokens.TokenTransactionType), type.Value))
74+
Domain.Entities.Credits.CreditTransactionType? transactionType = null;
75+
if (type.HasValue && Enum.IsDefined(typeof(Domain.Entities.Credits.CreditTransactionType), type.Value))
7676
{
77-
transactionType = (Domain.Entities.Tokens.TokenTransactionType)type.Value;
77+
transactionType = (Domain.Entities.Credits.CreditTransactionType)type.Value;
7878
}
7979

8080
try
8181
{
82-
var history = await _tokenManagementService.GetTokenHistoryAsync(userId, page, pageSize, transactionType);
82+
var history = await _creditManagementService.GetCreditHistoryAsync(userId, page, pageSize, transactionType);
8383

8484
return Ok(new
8585
{
@@ -110,18 +110,18 @@ public async Task<IActionResult> GetHistory(
110110
}
111111
catch (Exception ex)
112112
{
113-
_logger.LogError(ex, "Failed to get token history for user {UserId}", userId);
114-
return StatusCode(500, new { error = "Failed to retrieve token history" });
113+
_logger.LogError(ex, "Failed to get credit history for user {UserId}", userId);
114+
return StatusCode(500, new { error = "Failed to retrieve credit history" });
115115
}
116116
}
117117

118118
/// <summary>
119-
/// 토큰 충분 여부 확인
119+
/// 크래딧 충분 여부 확인
120120
/// </summary>
121-
/// <param name="amount">확인할 토큰 수량</param>
122-
/// <returns>토큰 충분 여부</returns>
121+
/// <param name="amount">확인할 크래딧 수량</param>
122+
/// <returns>크래딧 충분 여부</returns>
123123
[HttpGet("check/{amount}")]
124-
public async Task<IActionResult> CheckSufficientTokens(decimal amount)
124+
public async Task<IActionResult> CheckSufficientCredits(decimal amount)
125125
{
126126
if (amount <= 0)
127127
{
@@ -132,33 +132,33 @@ public async Task<IActionResult> CheckSufficientTokens(decimal amount)
132132

133133
try
134134
{
135-
var hasSufficient = await _tokenManagementService.HasSufficientTokensAsync(userId, amount);
136-
var balance = await _tokenManagementService.GetTokenBalanceAsync(userId);
135+
var hasSufficient = await _creditManagementService.HasSufficientCreditsAsync(userId, amount);
136+
var balance = await _creditManagementService.GetCreditBalanceAsync(userId);
137137

138138
return Ok(new
139139
{
140140
userId = userId,
141141
requiredAmount = amount,
142142
currentBalance = balance.CurrentBalance,
143-
hasSufficientTokens = hasSufficient,
143+
hasSufficientCredits = hasSufficient,
144144
shortage = hasSufficient ? 0 : amount - balance.CurrentBalance
145145
});
146146
}
147147
catch (Exception ex)
148148
{
149-
_logger.LogError(ex, "Failed to check token sufficiency for user {UserId}, amount {Amount}", userId, amount);
150-
return StatusCode(500, new { error = "Failed to check token sufficiency" });
149+
_logger.LogError(ex, "Failed to check credit sufficiency for user {UserId}, amount {Amount}", userId, amount);
150+
return StatusCode(500, new { error = "Failed to check credit sufficiency" });
151151
}
152152
}
153153

154154
/// <summary>
155-
/// 토큰 추가 (관리자 전용 또는 결제 시스템 연동용)
155+
/// 크래딧 추가 (관리자 전용 또는 결제 시스템 연동용)
156156
/// 실제 운영 환경에서는 결제 검증 로직이 필요
157157
/// </summary>
158-
/// <param name="request">토큰 추가 요청</param>
159-
/// <returns>토큰 추가 결과</returns>
158+
/// <param name="request">크래딧 추가 요청</param>
159+
/// <returns>크래딧 추가 결과</returns>
160160
[HttpPost("add")]
161-
public async Task<IActionResult> AddTokens([FromBody] AddTokenRequest request)
161+
public async Task<IActionResult> AddCredits([FromBody] AddCreditRequest request)
162162
{
163163
if (!ModelState.IsValid)
164164
{
@@ -170,11 +170,11 @@ public async Task<IActionResult> AddTokens([FromBody] AddTokenRequest request)
170170
try
171171
{
172172
// 실제 운영에서는 결제 검증, 권한 확인 등이 필요
173-
var result = await _tokenManagementService.AddTokensAsync(
173+
var result = await _creditManagementService.AddCreditsAsync(
174174
userId,
175175
request.Amount,
176176
request.Source ?? "MANUAL_ADD",
177-
request.Description ?? "토큰 수동 추가",
177+
request.Description ?? "크래딧 수동 추가",
178178
request.RelatedEntityId,
179179
request.RelatedEntityType
180180
);
@@ -197,8 +197,8 @@ public async Task<IActionResult> AddTokens([FromBody] AddTokenRequest request)
197197
}
198198
catch (Exception ex)
199199
{
200-
_logger.LogError(ex, "Failed to add tokens for user {UserId}", userId);
201-
return StatusCode(500, new { error = "Failed to add tokens" });
200+
_logger.LogError(ex, "Failed to add credits for user {UserId}", userId);
201+
return StatusCode(500, new { error = "Failed to add credits" });
202202
}
203203
}
204204

@@ -210,24 +210,24 @@ private Guid GetCurrentUserId()
210210
var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
211211
if (string.IsNullOrEmpty(userIdClaim) || !Guid.TryParse(userIdClaim, out var userId))
212212
{
213-
throw new UnauthorizedAccessException("Invalid user ID in token");
213+
throw new UnauthorizedAccessException("Invalid user ID in credit");
214214
}
215215
return userId;
216216
}
217217
}
218218

219219
/// <summary>
220-
/// 토큰 추가 요청 모델
220+
/// 크래딧 추가 요청 모델
221221
/// </summary>
222-
public class AddTokenRequest
222+
public class AddCreditRequest
223223
{
224224
/// <summary>
225-
/// 추가할 토큰 수량 (필수)
225+
/// 추가할 크래딧 수량 (필수)
226226
/// </summary>
227227
public decimal Amount { get; set; }
228228

229229
/// <summary>
230-
/// 토큰 소스 (선택, 기본값: MANUAL_ADD)
230+
/// 크래딧 소스 (선택, 기본값: MANUAL_ADD)
231231
/// </summary>
232232
public string? Source { get; set; }
233233

ProjectVG.Api/Controllers/OAuthController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public async Task<IActionResult> GetOAuth2Token([FromQuery] string state)
101101

102102
await _oauth2Service.DeleteTokenDataAsync(state);
103103

104-
Response.Headers.Append("X-Access-Token", tokenData.AccessToken);
105-
Response.Headers.Append("X-Refresh-Token", tokenData.RefreshToken);
104+
Response.Headers.Append("X-Access-Credit", tokenData.AccessToken);
105+
Response.Headers.Append("X-Refresh-Credit", tokenData.RefreshToken);
106106
Response.Headers.Append("X-Expires-In", tokenData.ExpiresIn.ToString());
107107
Response.Headers.Append("X-UID", tokenData.UID);
108108

ProjectVG.Application/ApplicationServiceCollectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using ProjectVG.Application.Services.Chat.Handlers;
1010
using ProjectVG.Application.Services.Conversation;
1111
using ProjectVG.Application.Services.Session;
12-
using ProjectVG.Application.Services.Token;
12+
using ProjectVG.Application.Services.Credit;
1313
using ProjectVG.Application.Services.Users;
1414
using ProjectVG.Application.Services.WebSocket;
1515

@@ -30,8 +30,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
3030
// Character Services
3131
services.AddScoped<ICharacterService, CharacterService>();
3232

33-
// Token Management Services
34-
services.AddScoped<ITokenManagementService, TokenManagementService>();
33+
// Credit Management Services
34+
services.AddScoped<ICreditManagementService, CreditManagementService>();
3535

3636
// Chat Services - Core
3737
services.AddScoped<IChatService, ChatService>();

ProjectVG.Application/Models/Chat/ChatProcessResultMessage.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public record ChatProcessResultMessage
3434
[JsonPropertyName("order")]
3535
public int Order { get; init; }
3636

37-
[JsonPropertyName("tokens_used")]
38-
public decimal? TokensUsed { get; init; }
37+
[JsonPropertyName("credits_used")]
38+
public decimal? CreditsUsed { get; init; }
3939

40-
[JsonPropertyName("tokens_remaining")]
41-
public decimal? TokensRemaining { get; init; }
40+
[JsonPropertyName("credits_remaining")]
41+
public decimal? CreditsRemaining { get; init; }
4242

4343
public static ChatProcessResultMessage FromSegment(ChatSegment segment, string? requestId = null)
4444
{
@@ -72,9 +72,9 @@ public ChatProcessResultMessage WithAudioData(byte[]? audioBytes)
7272
}
7373
}
7474

75-
public ChatProcessResultMessage WithTokenInfo(decimal? tokensUsed, decimal? tokensRemaining)
75+
public ChatProcessResultMessage WithCreditInfo(decimal? creditsUsed, decimal? creditsRemaining)
7676
{
77-
return this with { TokensUsed = tokensUsed, TokensRemaining = tokensRemaining };
77+
return this with { CreditsUsed = creditsUsed, CreditsRemaining = creditsRemaining };
7878
}
7979
}
8080
}

ProjectVG.Application/Services/Auth/AuthService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Microsoft.Extensions.Logging;
22
using ProjectVG.Application.Models.User;
33
using ProjectVG.Application.Services.Users;
4-
using ProjectVG.Application.Services.Token;
4+
using ProjectVG.Application.Services.Credit;
55
using ProjectVG.Infrastructure.Auth;
66
using ProjectVG.Common.Exceptions;
77
using ProjectVG.Common.Constants;
@@ -13,13 +13,13 @@ public class AuthService : IAuthService
1313
{
1414
private readonly IUserService _userService;
1515
private readonly ITokenService _tokenService;
16-
private readonly ITokenManagementService _tokenManagementService;
16+
private readonly ICreditManagementService _tokenManagementService;
1717
private readonly ILogger<AuthService> _logger;
1818

1919
public AuthService(
2020
IUserService userService,
2121
ITokenService tokenService,
22-
ITokenManagementService tokenManagementService,
22+
ICreditManagementService tokenManagementService,
2323
ILogger<AuthService> logger)
2424
{
2525
_userService = userService;
@@ -97,7 +97,7 @@ public async Task<AuthResult> LoginWithOAuthAsync(string provider, string provid
9797
}
9898

9999
// 첫 로그인 토큰 지급 시도
100-
var tokenGranted = await _tokenManagementService.GrantInitialTokensAsync(user.Id);
100+
var tokenGranted = await _tokenManagementService.GrantInitialCreditsAsync(user.Id);
101101
if (tokenGranted)
102102
{
103103
_logger.LogInformation("Initial tokens (5000) granted successfully to user {UserId}", user.Id);

0 commit comments

Comments
 (0)