Skip to content

Commit fb7110d

Browse files
committed
refactor: null 처리 개선 및 경고 해결
### 주요 변경사항 #### null 처리 개선 - Repository 패턴: Get 메서드는 null 반환, Update/Delete는 예외 발생 - Service 레벨: Repository null 반환 시 적절한 예외 처리 - 명확한 책임 분리: Repository(데이터 접근) vs Service(비즈니스 로직) #### 경고 해결 (20개 → 0개) - null 참조 관련 경고 해결 - async 메서드 최적화 (Task.CompletedTask 사용) - 타입 불일치 해결 (Dictionary, nullable 타입) - 반환 타입 일치 (CharacterDto? → CharacterDto) #### 코드 정리 - ProjectVG.Application.csproj에서 존재하지 않는 LLM 폴더 제거 항목 삭제 - DesignTimeDbContextFactory에서 Console.WriteLine 제거 - InMemory Repository 파일들 삭제 (SqlServer Repository만 사용) #### Repository 패턴 개선 - 일관된 예외 처리: NotFoundException 사용 - Update 메서드: 무조건 반환하도록 수정 - Delete 메서드: 존재하지 않는 경우 예외 발생
1 parent cc62576 commit fb7110d

File tree

18 files changed

+54
-370
lines changed

18 files changed

+54
-370
lines changed

ProjectVG.Application/Models/User/UserDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class UserDto
88
public string Username { get; set; } = string.Empty;
99
public string Name { get; set; } = string.Empty;
1010
public string Email { get; set; } = string.Empty;
11-
public string? ProviderId { get; set; }
12-
public string? Provider { get; set; }
11+
public string ProviderId { get; set; } = string.Empty;
12+
public string Provider { get; set; } = string.Empty;
1313
public bool IsActive { get; set; }
1414
public DateTime CreatedAt { get; set; }
1515
public DateTime UpdatedAt { get; set; }

ProjectVG.Application/ProjectVG.Application.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

9-
<ItemGroup>
10-
<Compile Remove="Services\LLM\**" />
11-
<EmbeddedResource Remove="Services\LLM\**" />
12-
<None Remove="Services\LLM\**" />
13-
</ItemGroup>
14-
159
<ItemGroup>
1610
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
1711
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />

ProjectVG.Application/Services/Character/CharacterService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using ProjectVG.Infrastructure.Persistence.Repositories.Characters;
22
using Microsoft.Extensions.Logging;
33
using ProjectVG.Application.Models.Character;
4+
using ProjectVG.Common.Exceptions;
5+
using ProjectVG.Common.Constants;
46

57
namespace ProjectVG.Application.Services.Character
68
{
@@ -23,11 +25,11 @@ public async Task<IEnumerable<CharacterDto>> GetAllCharactersAsync()
2325
return characterDtos;
2426
}
2527

26-
public async Task<CharacterDto> GetCharacterByIdAsync(Guid id)
28+
public async Task<CharacterDto?> GetCharacterByIdAsync(Guid id)
2729
{
2830
var character = await _characterRepository.GetByIdAsync(id);
2931
if (character == null) {
30-
throw new NotFoundException(ErrorCode.CHARACTER_NOT_FOUND, id);
32+
return null;
3133
}
3234

3335
var characterDto = new CharacterDto(character);

ProjectVG.Application/Services/Chat/Factories/ChatLLMFormat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ [neutral] 내가 그런다고 좋아할 것 같아? [shy] 하지만 츄 해준
8989
";
9090
}
9191

92-
private ChatOutputFormatResult ParseChatResponse(string llmText, string voiceName = null)
92+
private ChatOutputFormatResult ParseChatResponse(string llmText, string? voiceName = null)
9393
{
9494
if (string.IsNullOrWhiteSpace(llmText))
9595
return new ChatOutputFormatResult();
@@ -102,7 +102,7 @@ private ChatOutputFormatResult ParseChatResponse(string llmText, string voiceNam
102102
var matches = Regex.Matches(response, @"\[(.*?)\]\s*([^\[]+)");
103103

104104
// 보이스별 감정 매핑
105-
Dictionary<string, string> emotionMap = null;
105+
Dictionary<string, string>? emotionMap = null;
106106
if (!string.IsNullOrWhiteSpace(voiceName))
107107
{
108108
var profile = VoiceCatalog.GetProfile(voiceName);

ProjectVG.Application/Services/Chat/Factories/UserInputAnalysisLLMFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private UserInputAnalysis ParseChatAction(Dictionary<string, string> response)
155155
{
156156
var conversationContext = response.GetValueOrDefault("CONTEXT", "일반적인 대화");
157157
var userIntent = response.GetValueOrDefault("INTENT", "대화");
158-
var enhancedQuery = response.GetValueOrDefault("ENHANCED_QUERY", null);
158+
var enhancedQuery = response.GetValueOrDefault("ENHANCED_QUERY", "");
159159

160160
// 키워드 파싱
161161
var keywords = ParseKeywords(response.GetValueOrDefault("KEYWORDS", ""));

ProjectVG.Application/Services/User/UserService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using ProjectVG.Infrastructure.Persistence.Repositories.Users;
22
using ProjectVG.Application.Models.User;
3+
using ProjectVG.Common.Exceptions;
4+
using ProjectVG.Common.Constants;
35

46
namespace ProjectVG.Application.Services.User
57
{

ProjectVG.Application/Services/WebSocket/WebSocketManager.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task SendAsync(string sessionId, WebSocketMessage message)
4949

5050
public async Task SendTextAsync(string sessionId, string text)
5151
{
52-
if (_connectionRegistry.TryGet(sessionId, out var connection)) {
52+
if (_connectionRegistry.TryGet(sessionId, out var connection) && connection != null) {
5353
await connection.SendTextAsync(text);
5454
_logger.LogDebug("WebSocket 텍스트 전송: {SessionId}", sessionId);
5555
}
@@ -60,7 +60,7 @@ public async Task SendTextAsync(string sessionId, string text)
6060

6161
public async Task SendBinaryAsync(string sessionId, byte[] data)
6262
{
63-
if (_connectionRegistry.TryGet(sessionId, out var connection)) {
63+
if (_connectionRegistry.TryGet(sessionId, out var connection) && connection != null) {
6464
await connection.SendBinaryAsync(data);
6565
_logger.LogDebug("WebSocket 바이너리 전송: {SessionId}, {Length} bytes", sessionId, data?.Length ?? 0);
6666
}
@@ -69,10 +69,11 @@ public async Task SendBinaryAsync(string sessionId, byte[] data)
6969
}
7070
}
7171

72-
public async Task DisconnectAsync(string sessionId)
72+
public Task DisconnectAsync(string sessionId)
7373
{
7474
_connectionRegistry.Unregister(sessionId);
7575
_logger.LogInformation("WebSocket 세션 해제: {SessionId}", sessionId);
76+
return Task.CompletedTask;
7677
}
7778

7879
public bool IsSessionActive(string sessionId)
@@ -101,12 +102,13 @@ public async Task HandleMessageAsync(string sessionId, string message)
101102
}
102103
}
103104

104-
public async Task HandleBinaryMessageAsync(string sessionId, byte[] data)
105+
public Task HandleBinaryMessageAsync(string sessionId, byte[] data)
105106
{
106107
_logger.LogDebug("WebSocket 바이너리 메시지 처리: {SessionId}, {Length} bytes", sessionId, data?.Length ?? 0);
107108

108109
// 바이너리 메시지 처리 로직 구현
109110
// 예: 오디오 데이터, 파일 업로드 등
111+
return Task.CompletedTask;
110112
}
111113

112114
private async Task ProcessMessageAsync(string sessionId, WebSocketMessage message)
@@ -130,11 +132,12 @@ private async Task HandlePingAsync(string sessionId)
130132
await SendAsync(sessionId, pongMessage);
131133
}
132134

133-
private async Task HandleChatMessageAsync(string sessionId, WebSocketMessage message)
135+
private Task HandleChatMessageAsync(string sessionId, WebSocketMessage message)
134136
{
135137
// 채팅 메시지 처리 로직
136138
// ChatService와 연동하여 처리
137139
_logger.LogInformation("채팅 메시지 수신: {SessionId}", sessionId);
140+
return Task.CompletedTask;
138141
}
139142

140143
private string GenerateSessionId()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
global using Microsoft.Extensions.Logging;
2+
3+
global using ProjectVG.Common.Constants;
4+
global using ProjectVG.Common.Exceptions;

ProjectVG.Infrastructure/Integrations/MemoryClient/VectorMemoryClient.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ public async Task<List<MemorySearchResult>> SearchAsync(string collection, strin
6868
PropertyNameCaseInsensitive = true
6969
});
7070

71-
_logger.LogInformation("[MemoryStore] Search 결과 {Count}개:", results.Count);
72-
foreach (var result in results) {
73-
_logger.LogInformation(" - Text: {Text}, Score: {Score:F4}", result.Text, result.Score);
71+
_logger.LogInformation("[MemoryStore] Search 결과 {Count}개:", results?.Count ?? 0);
72+
if (results != null)
73+
{
74+
foreach (var result in results) {
75+
_logger.LogInformation(" - Text: {Text}, Score: {Score:F4}", result.Text, result.Score);
76+
}
7477
}
7578

7679
return results ?? new List<MemorySearchResult>();

ProjectVG.Infrastructure/Integrations/TextToSpeechClient/Models/TextToSpeechRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ProjectVG.Infrastructure.Integrations.TextToSpeechClient.Models
55
public class TextToSpeechRequest
66
{
77
[JsonIgnore]
8-
public string VoiceId { get; set; }
8+
public string VoiceId { get; set; } = string.Empty;
99

1010
/// <summary>
1111
/// 텍스트를 음성으로 변환할 내용 (최대 300자)

0 commit comments

Comments
 (0)