11using Microsoft . AspNetCore . Mvc ;
2- using ProjectVG . Application . Services . Token ;
2+ using ProjectVG . Application . Services . Credit ;
33using ProjectVG . Api . Filters ;
44using System . Security . Claims ;
55
66namespace 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
0 commit comments