diff --git a/APIHandler.cs b/APIHandler.cs index 0078427..a762744 100644 --- a/APIHandler.cs +++ b/APIHandler.cs @@ -113,7 +113,7 @@ public static partial class APIHandler agent.Run(async runner => { if (!await runner.RequestValidated(1, "POST", true)) return; - if (await runner.TryGetBodyJsonAsync(["agentid", "name", "jabatan", "deplid", "skangkat", "tmt", "skper", "tgper", "vision", "mission", "photo", "createuser", "uname", "pass", "level"], CTS.Token) is Dictionary InElement) + if (await runner.TryGetBodyJsonAsync(["agentid", "name", "jabatan", "deplid", "skangkat", "tmt", "skper", "tgper", "vision", "mission", "photo", "seleksi", "nilaipilih", "eviden", "dokumentasi", "createuser", "uname", "pass", "level"], CTS.Token) is Dictionary InElement) { string AgentID = InElement["agentid"].GetString() ?? string.Empty; string Name = InElement["name"].GetString() ?? string.Empty; @@ -127,6 +127,10 @@ public static partial class APIHandler string Mission = InElement["mission"].GetString() ?? "-"; string Photo = InElement["photo"].GetString() ?? string.Empty; string PhotoURL = string.Empty; + string? Seleksi = InElement["seleksi"].GetString(); + DateOnly? NilaiPilih = InElement["nilaipilih"].ValueKind == JsonValueKind.Null ? null : DateOnly.FromDateTime(InElement["nilaipilih"].GetDateTime()); + string? Eviden = InElement["eviden"].GetString(); + string? Dokumentasi = InElement["dokumentasi"].GetString(); bool CreateUser = InElement["createuser"].GetBoolean(); string UName = InElement["uname"].GetString() ?? string.Empty; string PlainPass = InElement["pass"].GetString() ?? string.Empty; @@ -159,7 +163,7 @@ public static partial class APIHandler if (!File.Exists(PhotoPath)) await File.WriteAllBytesAsync(PhotoPath, ImageBytes, CTS.Token); PhotoURL = Path.Combine("/assets/images/uploads", PhotoFileName); } - Agent NewAgent = new(AgentID, Name, Jabatan, DeploymentID, SKAngkat, TMT, SKPer.Length == 0 ? null : SKPer, SKPer.Length == 0 ? null : TGPer, Vision, Mission, Photo.Length == 0 ? null : PhotoURL); + Agent NewAgent = new(AgentID, Name, Jabatan, DeploymentID, SKAngkat, TMT, SKPer.Length == 0 ? null : SKPer, SKPer.Length == 0 ? null : TGPer, Vision, Mission, Photo.Length == 0 ? null : PhotoURL, Seleksi, NilaiPilih, Eviden, Dokumentasi); await RunTransactionAsync(CS, async (Conn, Trans) => { using (SqlCommand CreateAgent = Conn.CreateCommand()) @@ -239,7 +243,11 @@ public static partial class APIHandler a["tgperubahan"] == DBNull.Value ? null : DateOnly.FromDateTime((DateTime)a["tgperubahan"]), a["vision"] == DBNull.Value ? null : (string)a["vision"], a["mission"] == DBNull.Value ? null : (string)a["mission"], - a["photourl"] == DBNull.Value ? null : (string)a["photourl"] + a["photourl"] == DBNull.Value ? null : (string)a["photourl"], + a["seleksi"] == DBNull.Value ? null : (string)a["seleksi"], + a["nilaipilih"] == DBNull.Value ? null : DateOnly.FromDateTime((DateTime)a["nilaipilih"]), + a["eviden"] == DBNull.Value ? null : (string)a["eviden"], + a["dokumentasi"] == DBNull.Value ? null : (string)a["dokumentasi"] ), CTS.Token))[0]; int AgentIdx = Agents.FindIndex(a => a.AgentID == UpAgent.AgentID); Agents[AgentIdx] = Agents[AgentIdx] with @@ -253,12 +261,29 @@ public static partial class APIHandler TMUbah = UpAgent.TMUbah, Vision = UpAgent.Vision, Mission = UpAgent.Mission, - PhotoURL = UpAgent.PhotoURL + PhotoURL = UpAgent.PhotoURL, + Seleksi = UpAgent.Seleksi, + NilaiPilih = UpAgent.NilaiPilih, + Eviden = UpAgent.Eviden, + Dokumentasi = UpAgent.Dokumentasi }; await runner.WriteJsonResponse(StatusCodes.Status202Accepted, "Data updated.", UpAgent); } }); }) + .Map("/getusers", users => + { + users.Run(async runner => + { + if (!await runner.RequestValidated(2)) return; + List SafeAccounts = []; + foreach (User UnsafeUser in UserAccounts.Values.ToList()) + { + SafeAccounts.Add(SafeUser.FromUser(UnsafeUser)); + } + await runner.WriteJsonResponse(StatusCodes.Status200OK, "Success", SafeAccounts); + }); + }) .Map("/passwd", passwd => { passwd.Run(async runner => diff --git a/Commons.cs b/Commons.cs index f800d10..86c1903 100644 --- a/Commons.cs +++ b/Commons.cs @@ -174,7 +174,11 @@ internal static class Commons r["tgperubahan"] == DBNull.Value ? null : DateOnly.FromDateTime((DateTime)r["tgperubahan"]), r["vision"] == DBNull.Value ? null : (string)r["vision"], r["mission"] == DBNull.Value ? null : (string)r["mission"], - r["photourl"] == DBNull.Value ? null : (string)r["photourl"] + r["photourl"] == DBNull.Value ? null : (string)r["photourl"], + r["seleksi"] == DBNull.Value ? null : (string)r["seleksi"], + r["nilaipilih"] == DBNull.Value ? null : DateOnly.FromDateTime((DateTime)r["nilaipilih"]), + r["eviden"] == DBNull.Value ? null : (string)r["eviden"], + r["dokumentasi"] == DBNull.Value ? null : (string)r["dokumentasi"] ),CTS.Token); } Console.WriteLine("Done."); diff --git a/Partials.cs b/Partials.cs index e61c2bd..f0f5fd6 100644 --- a/Partials.cs +++ b/Partials.cs @@ -4,7 +4,7 @@ using System.Text.Json.Serialization; using System.Text.RegularExpressions; namespace perubahan; -internal partial record Agent(string AgentID, string Name, string Jabatan, short DeplID, string SKAngkat, DateOnly TMT, string? SKPerb, DateOnly? TMUbah, string? Vision, string? Mission, string? PhotoURL); +internal partial record Agent(string AgentID, string Name, string Jabatan, short DeplID, string SKAngkat, DateOnly TMT, string? SKPerb, DateOnly? TMUbah, string? Vision, string? Mission, string? PhotoURL, string? Seleksi, DateOnly? NilaiPilih, string? Eviden, string? Dokumentasi); internal partial record ApiResponse(int Status, string Message, object Data); internal partial record Deployment(short DeplID, string UnitKerja); internal partial record LoginUser(string Username, string Password); @@ -29,10 +29,11 @@ internal partial record User(string Username, string AgentID, string Password, b [JsonSerializable(typeof(User))] //////////----------DICTIONARIES----------////////// [JsonSerializable(typeof(Dictionary))] -// [JsonSerializable(typeof(ConcurrentDictionary))] +[JsonSerializable(typeof(ConcurrentDictionary))] //////////-------------LISTS--------------////////// [JsonSerializable(typeof(List))] [JsonSerializable(typeof(List))] +[JsonSerializable(typeof(List))] [JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] internal partial class SGContext : JsonSerializerContext { }