diff --git a/Services/DatabaseService.cs b/Services/DatabaseService.cs index dc02faf..f38982a 100644 --- a/Services/DatabaseService.cs +++ b/Services/DatabaseService.cs @@ -122,7 +122,7 @@ namespace VNCServerList.Services connection.Open(); string sql = @" INSERT INTO VNC_ServerList ([User], [IP], [Category], [Title],[Description], [Password], [Argument]) - VALUES (@User, @IP, @Category, @Description, @Password, @Argument)"; + VALUES (@User, @IP, @Category, @Title,@Description, @Password, @Argument)"; using (var command = new SqlCommand(sql, connection)) { @@ -165,6 +165,33 @@ namespace VNCServerList.Services } } + public bool UpdateServerByUserAndIP(string originalUser, string originalIp, VNCServer newServerData) + { + using (var connection = new SqlConnection(_connectionString)) + { + connection.Open(); + string sql = @" + UPDATE VNC_ServerList + SET [IP] = @NewIP, [Category] = @Category, [Title] = @Title, [Description] = @Description, + [Password] = @Password, [Argument] = @Argument + WHERE [User] = @User AND [IP] = @OriginalIP"; + + using (var command = new SqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@User", originalUser); + command.Parameters.AddWithValue("@OriginalIP", originalIp); + command.Parameters.AddWithValue("@NewIP", newServerData.IP); + command.Parameters.AddWithValue("@Category", (object)newServerData.Category ?? DBNull.Value); + command.Parameters.AddWithValue("@Title", (object)newServerData.Title ?? DBNull.Value); + command.Parameters.AddWithValue("@Description", (object)newServerData.Description ?? DBNull.Value); + command.Parameters.AddWithValue("@Password", (object)newServerData.Password ?? DBNull.Value); + command.Parameters.AddWithValue("@Argument", (object)newServerData.Argument ?? DBNull.Value); + + return command.ExecuteNonQuery() > 0; + } + } + } + public bool DeleteServer(string user, string ip) { using (var connection = new SqlConnection(_connectionString)) diff --git a/Web/Controllers/VNCServerController.cs b/Web/Controllers/VNCServerController.cs index 26afc55..28c1fbf 100644 --- a/Web/Controllers/VNCServerController.cs +++ b/Web/Controllers/VNCServerController.cs @@ -28,13 +28,13 @@ namespace VNCServerList.Web.Controllers try { var servers = _databaseService.GetAllServers(); - + // 사용자 이름이 있으면 필터링 if (!string.IsNullOrEmpty(userName)) { servers = servers.Where(s => s.User.Equals(userName, StringComparison.OrdinalIgnoreCase)).ToList(); } - + // 사용자명으로 오름차순 정렬 var sortedServers = servers.OrderBy(s => s.User).ThenBy(s => s.IP).ToList(); return Ok(sortedServers); @@ -92,8 +92,8 @@ namespace VNCServerList.Web.Controllers } [HttpPut] - [Route("update")] - public IHttpActionResult UpdateServer([FromBody] VNCServer server) + [Route("update/{originalUser}/{originalIp}")] + public IHttpActionResult UpdateServer(string originalUser, string originalIp, [FromBody] VNCServer server) { try { @@ -102,7 +102,8 @@ namespace VNCServerList.Web.Controllers return BadRequest("서버 정보가 없습니다."); } - bool success = _databaseService.UpdateServer(server); + // 원본 사용자명과 IP로 서버를 찾아서 업데이트 + bool success = _databaseService.UpdateServerByUserAndIP(originalUser, originalIp, server); if (success) { return Ok(new { Message = "서버가 성공적으로 업데이트되었습니다." }); @@ -170,10 +171,11 @@ namespace VNCServerList.Web.Controllers { bool isInstalled = _vncService.IsVNCViewerInstalled(); string path = _vncService.GetVNCViewerPath(); - - return Ok(new { - IsInstalled = isInstalled, - Path = path + + return Ok(new + { + IsInstalled = isInstalled, + Path = path }); } catch (Exception ex) @@ -210,13 +212,13 @@ namespace VNCServerList.Web.Controllers try { System.Diagnostics.Debug.WriteLine("=== 설정 조회 시작 ==="); - + var settings = _settingsService.GetSettings(); - + // 디버깅용 로그 System.Diagnostics.Debug.WriteLine($"조회된 설정: VNCViewerPath='{settings.VNCViewerPath}', WebServerPort={settings.WebServerPort}"); System.Diagnostics.Debug.WriteLine("=== 설정 조회 완료 ==="); - + return Ok(settings); } catch (Exception ex) @@ -234,7 +236,7 @@ namespace VNCServerList.Web.Controllers try { System.Diagnostics.Debug.WriteLine("=== 설정 저장 요청 시작 ==="); - + if (settings == null) { System.Diagnostics.Debug.WriteLine("설정 객체가 null입니다."); @@ -247,12 +249,12 @@ namespace VNCServerList.Web.Controllers System.Diagnostics.Debug.WriteLine($"WebServerPort 타입: {settings.WebServerPort.GetType()}"); _settingsService.SaveSettings(settings); - + // 저장된 설정 확인 var savedSettings = _settingsService.GetSettings(); System.Diagnostics.Debug.WriteLine($"저장된 설정: VNCViewerPath='{savedSettings.VNCViewerPath}', WebServerPort={savedSettings.WebServerPort}"); System.Diagnostics.Debug.WriteLine("=== 설정 저장 완료 ==="); - + return Ok(new { Message = "설정이 저장되었습니다." }); } catch (Exception ex) @@ -263,4 +265,4 @@ namespace VNCServerList.Web.Controllers } } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Web/wwwroot/index.html b/Web/wwwroot/index.html index ed168c6..57627ad 100644 --- a/Web/wwwroot/index.html +++ b/Web/wwwroot/index.html @@ -63,34 +63,37 @@