diff --git a/backend/sql/current.sql b/backend/sql/current.sql index b0df285..b02cd47 100644 --- a/backend/sql/current.sql +++ b/backend/sql/current.sql @@ -7,11 +7,6 @@ DELIMITER $$; CREATE PROCEDURE CleanTables() BEGIN - TRUNCATE TABLE Timelog; - TRUNCATE TABLE Project; - SET foreign_key_checks = 0; - TRUNCATE TABLE User; - SET foreign_key_checks = 1; END $$ DELIMITER ; @@ -20,7 +15,13 @@ DELIMITER ; DELIMITER $$ CREATE PROCEDURE InitDB() BEGIN -CALL CleanTables(); +DECLARE i INT DEFAULT 1; +TRUNCATE TABLE Timelog; +TRUNCATE TABLE Project; +SET foreign_key_checks = 0; +TRUNCATE TABLE User; +SET foreign_key_checks = 1; + INSERT INTO Project(name) VALUES("My own"),("Outcons"),("Free Time"); CREATE TEMPORARY TABLE temp_fname (fname VARCHAR(255)); @@ -55,14 +56,15 @@ INSERT INTO temp_mail (mail) VALUES ( "hotmail.com" ), ( "gmail.com" ), ( "live.com" ); - -INSERT INTO User (f_name, l_name, mail) -SELECT - (SELECT fname FROM temp_fname ORDER BY RAND() LIMIT 1), - (SELECT lname FROM temp_lname ORDER BY RAND() LIMIT 1), - (SELECT mail FROM temp_mail ORDER BY RAND() LIMIT 1) -FROM - (SELECT 1 FROM information_schema.tables LIMIT 100) AS temp; + +WHILE i <= 100 DO + INSERT INTO User (f_name, l_name, mail) + SELECT + (SELECT fname FROM temp_fname ORDER BY RAND() LIMIT 1), + (SELECT lname FROM temp_lname ORDER BY RAND() LIMIT 1), + (SELECT mail FROM temp_mail ORDER BY RAND() LIMIT 1); + SET i = i + 1; +END WHILE; UPDATE User SET User.mail = CONCAT(User.f_name,".", User.l_name,"@", User.mail); @@ -83,7 +85,7 @@ BEGIN DECLARE logs INT; DECLARE hours FLOAT; DECLARE project INT; - DECLARE curDate DATE DEFAULT "2024-11-18"; + DECLARE curDate DATE DEFAULT '2024-11-18'; DECLARE h2 INT; WHILE users <= 100 DO @@ -118,7 +120,7 @@ DELIMITER ; ## -- get data SELECT t.time,t.date,p.name,u.f_name,u.l_name,u.mail FROM Timelog t INNER JOIN Project p ON p.id=t.project INNER JOIN User u ON u.id=t.user; - +-- old timelog with adding each on a new day CREATE PROCEDURE fill_timelog () BEGIN DECLARE j INT DEFAULT 1; diff --git a/backendCs/CreateProcedure.cs b/backendCs/CreateProcedure.cs new file mode 100644 index 0000000..1374120 --- /dev/null +++ b/backendCs/CreateProcedure.cs @@ -0,0 +1,133 @@ +using System.Net; +using System.Text; +using MySql.Data.MySqlClient; +namespace Server +{ + public class CreateProcedure + { + public static void run(MySqlConnection conn, HttpListenerRequest request, HttpListenerResponse response) + { + try + { + // Open the connection + conn.Open(); + // Prepare the SQL query + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandText = @" +CREATE PROCEDURE fill_timelog () +BEGIN + DECLARE j INT DEFAULT 1; + DECLARE users INT DEFAULT 1; + DECLARE logs INT; + DECLARE hours FLOAT; + DECLARE project INT; + DECLARE curDate DATE DEFAULT '2024-11-18'; + DECLARE h2 INT; + + WHILE users <= 100 DO + SET logs = FLOOR(1 + (RAND() * 20)); + SET j = 1; + WHILE j <= logs DO + SET project = FLOOR(1 + (RAND() * 3)); + SET curDate = DATE_ADD('2020-01-01', INTERVAL FLOOR(RAND() * DATEDIFF('2020-02-01', '2020-01-01')) DAY); + SET hours = (RAND() * (8 - 0.25)) + 0.25; + + SELECT SUM(time) INTO h2 + FROM Timelog + WHERE date = curdate && user = users; + + WHILE(h2 + hours) > 8 DO + SET curDate = DATE_ADD('2020-01-01', INTERVAL FLOOR(RAND() * DATEDIFF('2020-02-01', '2020-01-01')) DAY); + + SELECT SUM(time)INTO h2 + FROM Timelog + WHERE date = curdate && user = users; + + END WHILE; + INSERT INTO Timelog(user, project, date, time) VALUES(users, project, curDate, hours); + SET j = j + 1; + END WHILE; + SET users = users + 1; + END WHILE; +END;"; + cmd.ExecuteNonQuery(); + cmd.CommandText = @"CREATE PROCEDURE InitDB() +BEGIN + DECLARE i INT DEFAULT 1; + TRUNCATE TABLE Timelog; + TRUNCATE TABLE Project; + SET foreign_key_checks = 0; + TRUNCATE TABLE User; + SET foreign_key_checks = 1; + + INSERT INTO Project(name) VALUES('My own'),('Outcons'),('Free Time'); + + CREATE TEMPORARY TABLE temp_fname (fname VARCHAR(255)); + INSERT INTO temp_fname (fname) VALUES + ( 'John' ), + ( 'Gringo' ), + ( 'Mark' ), + ( 'Lisa' ), + ( 'Maria' ), + ( 'Sonya' ), + ( 'Philip' ), + ( 'Jose' ), + ( 'Lorenzo' ), + ( 'George' ), + ( 'Justin' ); + + CREATE TEMPORARY TABLE temp_lname (lname VARCHAR(255)); + INSERT INTO temp_lname (lname) VALUES + ( 'Johnson' ), + ( 'Lamas' ), + ( 'Jackson' ), + ( 'Brown' ), + ( 'Mason' ), + ( 'Rodriguez' ), + ( 'Roberts' ), + ( 'Thomas' ), + ( 'Rose' ), + ( 'McDonalds' ); + + CREATE TEMPORARY TABLE temp_mail (mail VARCHAR(255)); + INSERT INTO temp_mail (mail) VALUES + ( 'hotmail.com' ), + ( 'gmail.com' ), + ( 'live.com' ); + + WHILE i <= 100 DO + INSERT INTO User (f_name, l_name, mail) + SELECT + (SELECT fname FROM temp_fname ORDER BY RAND() LIMIT 1), + (SELECT lname FROM temp_lname ORDER BY RAND() LIMIT 1), + (SELECT mail FROM temp_mail ORDER BY RAND() LIMIT 1); + SET i = i + 1; + END WHILE; + + UPDATE User + SET User.mail = CONCAT(User.f_name,'.', User.l_name,'@', User.mail); + + CALL fill_timelog(); + DROP TABLE temp_mail; + DROP TABLE temp_fname; + DROP TABLE temp_lname; + END;"; + cmd.ExecuteNonQuery(); + // prepare response + response.StatusCode = (int)HttpStatusCode.OK; + response.StatusDescription = "Status OK"; + } + catch (Exception ex) + { + // Handle any connection errors + string errorMessage = $"Error: {ex.Message}"; + byte[] buffer = Encoding.UTF8.GetBytes(errorMessage); + response.ContentType = "text/plain"; + response.ContentLength64 = buffer.Length; + response.OutputStream.Write(buffer, 0, buffer.Length); + } + conn.Close(); + } + } +} diff --git a/backendCs/Getall.cs b/backendCs/Getall.cs index 0b628d4..160f781 100644 --- a/backendCs/Getall.cs +++ b/backendCs/Getall.cs @@ -1,4 +1,3 @@ -using System; using System.Net; using System.Text; using MySql.Data.MySqlClient; @@ -6,15 +5,16 @@ using Newtonsoft.Json; namespace Server { + // there should be a better way to deal with data comming from sql public class All { - public object f_name { get; set; } - public object l_name { get; set; } - public object mail { get; set; } - public object name { get; set; } - public object time { get; set; } - public object date { get; set; } - public object user { get; set; } + public object? f_name { get; set; } + public object? l_name { get; set; } + public object? mail { get; set; } + public object? name { get; set; } + public object? time { get; set; } + public object? date { get; set; } + public object? user { get; set; } } public class Getall @@ -26,14 +26,16 @@ namespace Server // Open the connection conn.Open(); // Prepare the SQL query - MySqlCommand myCommand = new MySqlCommand(); - myCommand.Connection = conn; + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + // get url params var queryString = request.QueryString; - string from = queryString["from"]; - string to = queryString["to"]; - string sortby = queryString["sortby"]; - string offset = queryString["offset"]; - + string? from = queryString["from"]; + string? to = queryString["to"]; + string? sortby = queryString["sortby"]; + string? offset = queryString["offset"]; + string? order = queryString["order"]; + order = order == "true" ? "ASC" : "DESC"; // this shenanigan is needed to remove the "" around // group by string sqlQ = @"SELECT u.f_name,u.l_name,u.mail,p.name,t.time,t.date,t.user @@ -41,6 +43,7 @@ namespace Server INNER JOIN Project p ON p.id=t.project INNER JOIN User u ON u.id=t.user "; string offsetQ = " LIMIT 10 OFFSET " + offset + ";"; + // depending on the incoming parameters construct a Query if (!string.IsNullOrEmpty(to) && !string.IsNullOrEmpty(from)) { string whereQ = " WHERE t.date BETWEEN @from AND @to "; @@ -48,15 +51,18 @@ namespace Server } if (!string.IsNullOrEmpty(sortby)) { - string orderQ = " ORDER BY " + sortby; + string orderQ = " ORDER BY " + sortby + " " + order; sqlQ = sqlQ + orderQ; } - myCommand.CommandText = sqlQ + offsetQ; - myCommand.Parameters.AddWithValue("@from", from); - myCommand.Parameters.AddWithValue("@to", to); + // add the final line to the query + cmd.CommandText = sqlQ + offsetQ; + // those don't produce error if they don't find their variables + cmd.Parameters.AddWithValue("@from", from); + cmd.Parameters.AddWithValue("@to", to); // Execute the query and read the results - MySqlDataReader reader = myCommand.ExecuteReader(); + MySqlDataReader reader = cmd.ExecuteReader(); + List entries = new List(); while (reader.Read()) { @@ -71,7 +77,7 @@ namespace Server mail = reader["mail"], }); } - // Serialize the data to JSON + // serialize the data to JSON string jsonResponse = JsonConvert.SerializeObject(entries); // prepare response byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse); diff --git a/backendCs/Gettopten.cs b/backendCs/Gettopten.cs index 315ba3b..b1d818f 100644 --- a/backendCs/Gettopten.cs +++ b/backendCs/Gettopten.cs @@ -1,4 +1,3 @@ -using System; using System.Net; using System.Text; using MySql.Data.MySqlClient; @@ -8,13 +7,13 @@ namespace Server { public class TopTen { - public object user { get; set; } - public object date { get; set; } - public object project { get; set; } - public object f_name { get; set; } - public object l_name { get; set; } - public object name { get; set; } - public object total_time { get; set; } + public object? user { get; set; } + public object? date { get; set; } + public object? project { get; set; } + public object? f_name { get; set; } + public object? l_name { get; set; } + public object? name { get; set; } + public object? total_time { get; set; } } public class Gettopten { @@ -25,12 +24,12 @@ namespace Server // Open the connection conn.Open(); // Prepare the SQL query - MySqlCommand myCommand = new MySqlCommand(); - myCommand.Connection = conn; + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; var queryString = request.QueryString; - string from = queryString["from"]; - string to = queryString["to"]; - string filterBy = queryString["filterBy"]; + string? from = queryString["from"]; + string? to = queryString["to"]; + string? filterBy = queryString["filterBy"]; // this shenanigan is needed to remove the "" around // group by string req = @"SELECT t.user,t.date,t.project,u.f_name,u.l_name,p.name,SUM(t.time) as total_time @@ -40,12 +39,12 @@ namespace Server WHERE t.date BETWEEN @from AND @to GROUP BY " + filterBy + @" ORDER BY total_time DESC LIMIT 10;"; - myCommand.CommandText = req; - myCommand.Parameters.AddWithValue("@from", from); - myCommand.Parameters.AddWithValue("@to", to); + cmd.CommandText = req; + cmd.Parameters.AddWithValue("@from", from); + cmd.Parameters.AddWithValue("@to", to); // Execute the query and read the results - MySqlDataReader reader = myCommand.ExecuteReader(); + MySqlDataReader reader = cmd.ExecuteReader(); List entries = new List(); while (reader.Read()) { diff --git a/backendCs/Getuser.cs b/backendCs/Getuser.cs index b97583d..96e5722 100644 --- a/backendCs/Getuser.cs +++ b/backendCs/Getuser.cs @@ -1,37 +1,11 @@ -using System; using System.Net; using System.Text; using MySql.Data.MySqlClient; +using System.Dynamic; using Newtonsoft.Json; namespace Server { - class DynamicObject - { - // A dictionary to store dynamic properties/fields - public Dictionary Fields { get; set; } - - public DynamicObject() - { - Fields = new Dictionary(); - } - - // Adding a dynamic field - public void AddField(object key, object value) - { - Fields[key] = value; - } - - // Retrieving a dynamic field - public object GetField(object key) - { - if (Fields.ContainsKey(key)) - { - return Fields[key]; - } - return null; - } - } public class Getuser { public static void run(MySqlConnection conn, HttpListenerRequest request, HttpListenerResponse response) @@ -41,27 +15,27 @@ namespace Server // Open the connection conn.Open(); // Prepare the SQL query - MySqlCommand myCommand = new MySqlCommand(); - myCommand.Connection = conn; - myCommand.CommandText = @"SELECT p.name, SUM(t.time) + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandText = @"SELECT p.name, SUM(t.time) FROM Timelog t INNER JOIN Project p ON p.id=t.project INNER JOIN User u ON u.id=t.user WHERE User = @userid GROUP BY name;"; var queryString = request.QueryString; - string userid = queryString["userid"]; - myCommand.Parameters.AddWithValue("@userid", userid); + string? userid = queryString["userid"]; + cmd.Parameters.AddWithValue("@userid", userid); // Execute the query and read the results - MySqlDataReader reader = myCommand.ExecuteReader(); - DynamicObject dO = new DynamicObject(); + MySqlDataReader reader = cmd.ExecuteReader(); + dynamic expando = new ExpandoObject(); while (reader.Read()) { - dO.AddField(reader["name"], reader["SUM(t.time)"]); + ((IDictionary)expando)[reader["name"].ToString()] = reader["SUM(t.time)"]; } // Serialize the data to JSON - string jsonResponse = JsonConvert.SerializeObject(dO); + string jsonResponse = JsonConvert.SerializeObject(expando); // prepare response byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse); response.ContentType = "application/json"; diff --git a/backendCs/Program.cs b/backendCs/Program.cs index b1914e8..48b5195 100644 --- a/backendCs/Program.cs +++ b/backendCs/Program.cs @@ -1,10 +1,7 @@ -using System; -using System.Net; +using System.Net; using System.Text; -using System.Threading; using MySql.Data.MySqlClient; -using Newtonsoft.Json; -using System.Collections.Generic; +/* using System.Threading; */ namespace Server @@ -20,56 +17,69 @@ namespace Server listener.Prefixes.Add("http://localhost:5000/api/gettopten/"); listener.Prefixes.Add("http://localhost:5000/api/getuser/"); listener.Prefixes.Add("http://localhost:5000/api/reset/"); + listener.Prefixes.Add("http://localhost:5000/api/createp/"); // Start listening for incoming requests listener.Start(); Console.WriteLine("Server is listening on http://localhost:5000/"); // god knows what that is - Thread listenerThread = new Thread(() => + /* Thread listenerThread = new Thread(() => */ + /* { */ + while (true) { - while (true) + // wait for request + HttpListenerContext context = listener.GetContext(); + // get response and request + HttpListenerRequest request = context.Request; + HttpListenerResponse response = context.Response; + // mysql connection + string connectionString = "server=127.0.0.1;uid=monty;pwd=some_pass;database=timelog"; + MySqlConnection conn = new MySqlConnection(connectionString); + + // url after localhost:5000/ + // i think the validation is unnecessry but the compiler has + // more experience + string uri; + if (request != null && request.Url != null) { - // wait for request - HttpListenerContext context = listener.GetContext(); - // get response and request - HttpListenerRequest request = context.Request; - HttpListenerResponse response = context.Response; - // mysql connection - string connectionString = "server=127.0.0.1;uid=monty;pwd=some_pass;database=timelog"; - MySqlConnection conn = new MySqlConnection(connectionString); - - // url after localhost:5000/ - var uri = request.Url.AbsolutePath; - - switch (uri) - { - case "/api/reset": - Reset.run(conn, request, response); - break; - case "/api/getall": - Getall.run(conn, request, response); - break; - case "/api/gettopten": - Gettopten.run(conn, request, response); - break; - case "/api/getuser": - Getuser.run(conn, request, response); - break; - default: - response.StatusCode = 404; - string errorMessage = "Not Found"; - byte[] buffer = Encoding.UTF8.GetBytes(errorMessage); - response.ContentType = "text/plain"; - response.ContentLength64 = buffer.Length; - response.OutputStream.Write(buffer, 0, buffer.Length); - break; - } - // Close the response - response.OutputStream.Close(); + uri = request.Url.AbsolutePath; } - }); - // Start the listener thread - listenerThread.Start(); + else + { + return; + } + switch (uri) + { + case "/api/reset": + Reset.run(conn, request, response); + break; + case "/api/getall": + Getall.run(conn, request, response); + break; + case "/api/gettopten": + Gettopten.run(conn, request, response); + break; + case "/api/getuser": + Getuser.run(conn, request, response); + break; + case "/api/createp": + CreateProcedure.run(conn, request, response); + break; + default: + response.StatusCode = 404; + string errorMessage = "Not Found"; + byte[] buffer = Encoding.UTF8.GetBytes(errorMessage); + response.ContentType = "text/plain"; + response.ContentLength64 = buffer.Length; + response.OutputStream.Write(buffer, 0, buffer.Length); + break; + } + // Close the response + response.OutputStream.Close(); + } + /* }); */ + /* // Start the listener thread */ + /* listenerThread.Start(); */ } } } diff --git a/backendCs/Reset.cs b/backendCs/Reset.cs index c3f55bc..27c7dd4 100644 --- a/backendCs/Reset.cs +++ b/backendCs/Reset.cs @@ -1,11 +1,9 @@ -using System; using System.Net; using System.Text; using MySql.Data.MySqlClient; namespace Server { - public class Reset { public static void run(MySqlConnection conn, HttpListenerRequest request, HttpListenerResponse response) @@ -15,11 +13,12 @@ namespace Server // Open the connection conn.Open(); // Prepare the SQL query - MySqlCommand myCommand = new MySqlCommand(); - myCommand.Connection = conn; - myCommand.CommandText = "CALL InitDB"; - MySqlDataReader reader = myCommand.ExecuteReader(); - + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandText = "CALL InitDB"; + // execute query + cmd.ExecuteNonQuery(); + // set up and send response response.StatusCode = (int)HttpStatusCode.OK; response.StatusDescription = "Status OK"; } diff --git a/backendCs/bin/Debug/net8.0/TimelogBackend.dll b/backendCs/bin/Debug/net8.0/TimelogBackend.dll index 8a7362e..fc574a6 100644 Binary files a/backendCs/bin/Debug/net8.0/TimelogBackend.dll and b/backendCs/bin/Debug/net8.0/TimelogBackend.dll differ diff --git a/backendCs/bin/Debug/net8.0/TimelogBackend.pdb b/backendCs/bin/Debug/net8.0/TimelogBackend.pdb index 800fdf6..3825956 100644 Binary files a/backendCs/bin/Debug/net8.0/TimelogBackend.pdb and b/backendCs/bin/Debug/net8.0/TimelogBackend.pdb differ diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfo.cs b/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfo.cs index b2142c7..de6aa4e 100644 --- a/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfo.cs +++ b/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("TimelogBackend")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4496672d19c31da56be4394168028d97a19d3a6b")] [assembly: System.Reflection.AssemblyProductAttribute("TimelogBackend")] [assembly: System.Reflection.AssemblyTitleAttribute("TimelogBackend")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfoInputs.cache b/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfoInputs.cache index 5c8483e..dd5ef12 100644 --- a/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfoInputs.cache +++ b/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfoInputs.cache @@ -1 +1 @@ -4dc0d476a06a0877992a3936924b0e881bcf70b32aef70b9fa285a64b7d9395c +9366787f5f967306279f95e5eb689ad57d8d916a1aff008ae6b71d7ccaf910fe diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.GeneratedMSBuildEditorConfig.editorconfig b/backendCs/obj/Debug/net8.0/TimelogBackend.GeneratedMSBuildEditorConfig.editorconfig index b23881e..3b69067 100644 --- a/backendCs/obj/Debug/net8.0/TimelogBackend.GeneratedMSBuildEditorConfig.editorconfig +++ b/backendCs/obj/Debug/net8.0/TimelogBackend.GeneratedMSBuildEditorConfig.editorconfig @@ -8,6 +8,6 @@ build_property.PlatformNeutralAssembly = build_property.EnforceExtendedAnalyzerRules = build_property._SupportedPlatformList = Linux,macOS,Windows build_property.RootNamespace = TimelogBackend -build_property.ProjectDir = /home/arch/temp/HelloWorldApp/ +build_property.ProjectDir = /home/arch/projects/wip/timelog-interview/backendCs/ build_property.EnableComHosting = build_property.EnableGeneratedComInterfaceComImportInterop = diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.assets.cache b/backendCs/obj/Debug/net8.0/TimelogBackend.assets.cache index f30be33..4920860 100644 Binary files a/backendCs/obj/Debug/net8.0/TimelogBackend.assets.cache and b/backendCs/obj/Debug/net8.0/TimelogBackend.assets.cache differ diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.CoreCompileInputs.cache b/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.CoreCompileInputs.cache index c384fa3..d00c3e0 100644 --- a/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.CoreCompileInputs.cache +++ b/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -a26e25722337c85065d06325a739b066cff412c2c9a8e669c741ff1bfb48e5f6 +8cb7b4e3896ea6e4199194b8ade89330b75c191994f715b16fe2d035c7102d40 diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.FileListAbsolute.txt b/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.FileListAbsolute.txt index 144c228..07bf854 100644 --- a/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.FileListAbsolute.txt +++ b/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.FileListAbsolute.txt @@ -36,3 +36,41 @@ /home/arch/temp/HelloWorldApp/obj/Debug/net8.0/TimelogBackend.pdb /home/arch/temp/HelloWorldApp/obj/Debug/net8.0/TimelogBackend.genruntimeconfig.cache /home/arch/temp/HelloWorldApp/obj/Debug/net8.0/ref/TimelogBackend.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/TimelogBackend +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/TimelogBackend.deps.json +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/TimelogBackend.runtimeconfig.json +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/TimelogBackend.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/TimelogBackend.pdb +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/BouncyCastle.Cryptography.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/Google.Protobuf.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/K4os.Compression.LZ4.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/K4os.Compression.LZ4.Streams.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/K4os.Hash.xxHash.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/MySql.Data.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/Newtonsoft.Json.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/System.Configuration.ConfigurationManager.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/System.Diagnostics.EventLog.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/System.IO.Pipelines.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/System.Security.Cryptography.ProtectedData.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/System.Security.Permissions.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/System.Windows.Extensions.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/ZstdSharp.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win-x64/native/comerr64.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win-x64/native/gssapi64.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win-x64/native/k5sprt64.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win-x64/native/krb5_64.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win-x64/native/krbcc64.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.Messages.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.dll +/home/arch/projects/wip/timelog-interview/backendCs/bin/Debug/net8.0/runtimes/win/lib/net8.0/System.Windows.Extensions.dll +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.AssemblyReference.cache +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.GeneratedMSBuildEditorConfig.editorconfig +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfoInputs.cache +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.AssemblyInfo.cs +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.CoreCompileInputs.cache +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.csproj.CopyComplete +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.dll +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/refint/TimelogBackend.dll +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.pdb +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/TimelogBackend.genruntimeconfig.cache +/home/arch/projects/wip/timelog-interview/backendCs/obj/Debug/net8.0/ref/TimelogBackend.dll diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.dll b/backendCs/obj/Debug/net8.0/TimelogBackend.dll index 8a7362e..fc574a6 100644 Binary files a/backendCs/obj/Debug/net8.0/TimelogBackend.dll and b/backendCs/obj/Debug/net8.0/TimelogBackend.dll differ diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.genruntimeconfig.cache b/backendCs/obj/Debug/net8.0/TimelogBackend.genruntimeconfig.cache index 859adea..3af0758 100644 --- a/backendCs/obj/Debug/net8.0/TimelogBackend.genruntimeconfig.cache +++ b/backendCs/obj/Debug/net8.0/TimelogBackend.genruntimeconfig.cache @@ -1 +1 @@ -349d85780636e3e61d35aee10e34ef55954b239c07ad0a356798a097ceae0148 +b9db7be95623da1c56ce81f0a2fe43bd17220a8c9689f0c3bac4131258accda2 diff --git a/backendCs/obj/Debug/net8.0/TimelogBackend.pdb b/backendCs/obj/Debug/net8.0/TimelogBackend.pdb index 800fdf6..3825956 100644 Binary files a/backendCs/obj/Debug/net8.0/TimelogBackend.pdb and b/backendCs/obj/Debug/net8.0/TimelogBackend.pdb differ diff --git a/backendCs/obj/Debug/net8.0/ref/TimelogBackend.dll b/backendCs/obj/Debug/net8.0/ref/TimelogBackend.dll index 45183af..90a1f1f 100644 Binary files a/backendCs/obj/Debug/net8.0/ref/TimelogBackend.dll and b/backendCs/obj/Debug/net8.0/ref/TimelogBackend.dll differ diff --git a/backendCs/obj/Debug/net8.0/refint/TimelogBackend.dll b/backendCs/obj/Debug/net8.0/refint/TimelogBackend.dll index 45183af..90a1f1f 100644 Binary files a/backendCs/obj/Debug/net8.0/refint/TimelogBackend.dll and b/backendCs/obj/Debug/net8.0/refint/TimelogBackend.dll differ diff --git a/backendCs/obj/TimelogBackend.csproj.nuget.dgspec.json b/backendCs/obj/TimelogBackend.csproj.nuget.dgspec.json index a8065a7..5b2e011 100644 --- a/backendCs/obj/TimelogBackend.csproj.nuget.dgspec.json +++ b/backendCs/obj/TimelogBackend.csproj.nuget.dgspec.json @@ -1,17 +1,17 @@ { "format": 1, "restore": { - "/home/arch/temp/HelloWorldApp/TimelogBackend.csproj": {} + "/home/arch/projects/wip/timelog-interview/backendCs/TimelogBackend.csproj": {} }, "projects": { - "/home/arch/temp/HelloWorldApp/TimelogBackend.csproj": { + "/home/arch/projects/wip/timelog-interview/backendCs/TimelogBackend.csproj": { "version": "1.0.0", "restore": { - "projectUniqueName": "/home/arch/temp/HelloWorldApp/TimelogBackend.csproj", + "projectUniqueName": "/home/arch/projects/wip/timelog-interview/backendCs/TimelogBackend.csproj", "projectName": "TimelogBackend", - "projectPath": "/home/arch/temp/HelloWorldApp/TimelogBackend.csproj", + "projectPath": "/home/arch/projects/wip/timelog-interview/backendCs/TimelogBackend.csproj", "packagesPath": "/home/arch/.nuget/packages/", - "outputPath": "/home/arch/temp/HelloWorldApp/obj/", + "outputPath": "/home/arch/projects/wip/timelog-interview/backendCs/obj/", "projectStyle": "PackageReference", "configFilePaths": [ "/home/arch/.nuget/NuGet/NuGet.Config" diff --git a/backendCs/obj/project.assets.json b/backendCs/obj/project.assets.json index fceb6e6..efb95ba 100644 --- a/backendCs/obj/project.assets.json +++ b/backendCs/obj/project.assets.json @@ -1658,11 +1658,11 @@ "project": { "version": "1.0.0", "restore": { - "projectUniqueName": "/home/arch/temp/HelloWorldApp/TimelogBackend.csproj", + "projectUniqueName": "/home/arch/projects/wip/timelog-interview/backendCs/TimelogBackend.csproj", "projectName": "TimelogBackend", - "projectPath": "/home/arch/temp/HelloWorldApp/TimelogBackend.csproj", + "projectPath": "/home/arch/projects/wip/timelog-interview/backendCs/TimelogBackend.csproj", "packagesPath": "/home/arch/.nuget/packages/", - "outputPath": "/home/arch/temp/HelloWorldApp/obj/", + "outputPath": "/home/arch/projects/wip/timelog-interview/backendCs/obj/", "projectStyle": "PackageReference", "configFilePaths": [ "/home/arch/.nuget/NuGet/NuGet.Config" diff --git a/backendCs/obj/project.nuget.cache b/backendCs/obj/project.nuget.cache index 6dd0eab..e5d9d5a 100644 --- a/backendCs/obj/project.nuget.cache +++ b/backendCs/obj/project.nuget.cache @@ -1,8 +1,8 @@ { "version": 2, - "dgSpecHash": "p6MNaUN/SYJSFf9M574e8kcv9EqEwjPgKKmmL1309Lwqd26TTBeTctoKZziGbcJiysFehsYg0kxDJKBlru2uCA==", + "dgSpecHash": "05fTwHDwROQn3aS1fZFUfkni+eNLFijwdR49kiMZyADYQWkBGYKVh4QK8CMaBFfif3DNASYK7goRXVy8COyb4A==", "success": true, - "projectFilePath": "/home/arch/temp/HelloWorldApp/TimelogBackend.csproj", + "projectFilePath": "/home/arch/projects/wip/timelog-interview/backendCs/TimelogBackend.csproj", "expectedPackageFiles": [ "/home/arch/.nuget/packages/bouncycastle.cryptography/2.3.1/bouncycastle.cryptography.2.3.1.nupkg.sha512", "/home/arch/.nuget/packages/google.protobuf/3.26.1/google.protobuf.3.26.1.nupkg.sha512", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8950053..6d74c1b 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -8,7 +8,7 @@ function App() { const [reset, setReset] = useState(true); return ( - + diff --git a/frontend/src/components/LeftSide.tsx b/frontend/src/components/LeftSide.tsx index 5b9864b..f82b274 100644 --- a/frontend/src/components/LeftSide.tsx +++ b/frontend/src/components/LeftSide.tsx @@ -7,18 +7,37 @@ import { TableCell, TableHead, Table, + Button, } from "@mui/material"; -const LeftSide = ({ reset, setReset }) => { - // next prev and sort - const [users, setUsers] = useState(); - const [params, setParams] = useState({ offset: 0, sortby: "f_name" }); - // reset button - // const [reset, setReset] = useState(true); +interface User { + date: string; + f_name: string; + l_name: string; + mail: string; + name: string; + time: number; + user: number; +} - // date - const [date, setDate] = useState({ from: "2021-01-01", to: "2028-01-01" }); - const [dateToSubmit, setDateToSubmit] = useState({ +const LeftSide = ({ + reset, + setReset, +}: { + reset: boolean; + setReset: Function; +}) => { + // next prev and sort buttons + const [users, setUsers] = useState(); + const [params, setParams] = useState({ + offset: 0, + sortby: "f_name", + from: "2000-01-01", + to: "2028-01-01", + order: true, + }); + // date buttons + const [date, setDate] = useState({ from: "2021-01-01", to: "2028-01-01", }); @@ -28,7 +47,7 @@ const LeftSide = ({ reset, setReset }) => { const resp = await api.get("/getall", { params, }); - setUsers(resp.data); + if (resp.data.length) setUsers(resp.data); } async function resetData() { await api.get("/reset"); @@ -39,15 +58,14 @@ const LeftSide = ({ reset, setReset }) => { } fetchData(); - }, [reset, params, dateToSubmit]); + }, [reset, params]); - const viewProjectHours = (user) => { + const viewProjectHours = (userid: number) => { async function fetchHours() { const resp = await api.get("/getuser", { - params: { userid: user }, + params: { userid }, }); - // const entriesArray = Object.entries(resp.data); - const entriesArray = Object.entries(resp.data.Fields); + const entriesArray = Object.entries(resp.data); alert(entriesArray); } fetchHours(); @@ -56,7 +74,7 @@ const LeftSide = ({ reset, setReset }) => { if (!users) return <>; return ( - + { type="date" id="to" name="to" - value={date.to} + value={params.to} onChange={(event) => setDate({ ...date, to: event.target.value })} /> - - - - Select a sort: - + Submit Date + - - + + +