done
This commit is contained in:
@@ -9,9 +9,7 @@ namespace Server
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open the connection
|
||||
conn.Open();
|
||||
// Prepare the SQL query
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = @"
|
||||
@@ -120,7 +118,6 @@ BEGIN
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Handle any connection errors
|
||||
string errorMessage = $"Error: {ex.Message}";
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
||||
response.ContentType = "text/plain";
|
||||
|
||||
+5
-7
@@ -23,9 +23,9 @@ namespace Server
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open the connection
|
||||
// open connection
|
||||
conn.Open();
|
||||
// Prepare the SQL query
|
||||
// prepare SQL query
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
// get url params
|
||||
@@ -36,8 +36,7 @@ namespace Server
|
||||
string? offset = queryString["offset"];
|
||||
string? order = queryString["order"];
|
||||
order = order == "true" ? "ASC" : "DESC";
|
||||
// this shenanigan is needed to remove the "" around
|
||||
// group by
|
||||
// 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
|
||||
FROM Timelog t
|
||||
INNER JOIN Project p ON p.id=t.project
|
||||
@@ -60,7 +59,7 @@ namespace Server
|
||||
cmd.Parameters.AddWithValue("@from", from);
|
||||
cmd.Parameters.AddWithValue("@to", to);
|
||||
|
||||
// Execute the query and read the results
|
||||
// execute query and read results
|
||||
MySqlDataReader reader = cmd.ExecuteReader();
|
||||
|
||||
List<All> entries = new List<All>();
|
||||
@@ -77,7 +76,7 @@ namespace Server
|
||||
mail = reader["mail"],
|
||||
});
|
||||
}
|
||||
// serialize the data to JSON
|
||||
// serialize JSON
|
||||
string jsonResponse = JsonConvert.SerializeObject(entries);
|
||||
// prepare response
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse);
|
||||
@@ -88,7 +87,6 @@ namespace Server
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Handle any connection errors
|
||||
string errorMessage = $"Error: {ex.Message}";
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
||||
response.ContentType = "text/plain";
|
||||
|
||||
@@ -21,9 +21,9 @@ namespace Server
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open the connection
|
||||
// open db connection
|
||||
conn.Open();
|
||||
// Prepare the SQL query
|
||||
// prepare SQL query
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
var queryString = request.QueryString;
|
||||
@@ -70,7 +70,6 @@ namespace Server
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Handle any connection errors
|
||||
string errorMessage = $"Error: {ex.Message}";
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
||||
response.ContentType = "text/plain";
|
||||
|
||||
@@ -12,9 +12,9 @@ namespace Server
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open the connection
|
||||
// open connection
|
||||
conn.Open();
|
||||
// Prepare the SQL query
|
||||
// prepare SQL query
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = @"SELECT p.name, SUM(t.time)
|
||||
@@ -26,7 +26,7 @@ namespace Server
|
||||
var queryString = request.QueryString;
|
||||
string? userid = queryString["userid"];
|
||||
cmd.Parameters.AddWithValue("@userid", userid);
|
||||
// Execute the query and read the results
|
||||
// execute query and read results
|
||||
MySqlDataReader reader = cmd.ExecuteReader();
|
||||
dynamic expando = new ExpandoObject();
|
||||
while (reader.Read())
|
||||
@@ -34,7 +34,7 @@ namespace Server
|
||||
((IDictionary<string?, object>)expando)[reader["name"].ToString()] = reader["SUM(t.time)"];
|
||||
|
||||
}
|
||||
// Serialize the data to JSON
|
||||
// serialize JSON
|
||||
string jsonResponse = JsonConvert.SerializeObject(expando);
|
||||
// prepare response
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse);
|
||||
@@ -45,13 +45,13 @@ namespace Server
|
||||
}
|
||||
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);
|
||||
}
|
||||
// close db connection
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-10
@@ -19,12 +19,9 @@ namespace Server
|
||||
listener.Prefixes.Add("http://localhost:5000/api/reset/");
|
||||
listener.Prefixes.Add("http://localhost:5000/api/createp/");
|
||||
|
||||
// Start listening for incoming requests
|
||||
// listen
|
||||
listener.Start();
|
||||
Console.WriteLine("Server is listening on http://localhost:5000/");
|
||||
// god knows what that is
|
||||
/* Thread listenerThread = new Thread(() => */
|
||||
/* { */
|
||||
while (true)
|
||||
{
|
||||
// wait for request
|
||||
@@ -37,8 +34,7 @@ namespace Server
|
||||
MySqlConnection conn = new MySqlConnection(connectionString);
|
||||
|
||||
// url after localhost:5000/
|
||||
// i think the validation is unnecessry but the compiler has
|
||||
// more experience
|
||||
// i think the validation is unnecessry but the compiler doesn't
|
||||
string uri;
|
||||
if (request != null && request.Url != null)
|
||||
{
|
||||
@@ -74,12 +70,9 @@ namespace Server
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
break;
|
||||
}
|
||||
// Close the response
|
||||
// send the response
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
/* }); */
|
||||
/* // Start the listener thread */
|
||||
/* listenerThread.Start(); */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
// Create an HttpListener to handle incoming HTTP requests
|
||||
HttpListener listener = new HttpListener();
|
||||
|
||||
// Add a prefix to listen to, e.g., http://localhost:8080/
|
||||
listener.Prefixes.Add("http://localhost:5000/");
|
||||
|
||||
// Start listening for incoming requests
|
||||
listener.Start();
|
||||
Console.WriteLine("Server is listening on http://localhost:5000/");
|
||||
|
||||
// Handle requests on a separate thread to keep server responsive
|
||||
Thread listenerThread = new Thread(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// Wait for a request
|
||||
HttpListenerContext context = listener.GetContext();
|
||||
// Get the request and response objects
|
||||
HttpListenerRequest request = context.Request;
|
||||
HttpListenerResponse response = context.Response;
|
||||
// Check if the requested URL is /api
|
||||
if (request.Url.AbsolutePath == "/api")
|
||||
{
|
||||
string connectionString = "Server=localhost;Port=5050;Database=your_database;User ID=your_user;Password=your_password;";
|
||||
MySqlConnection conn = new MySqlConnection(connectionString);
|
||||
|
||||
try
|
||||
{
|
||||
// Open the connection
|
||||
conn.Open();
|
||||
|
||||
// Prepare the SQL query
|
||||
string query = "SELECT * FROM User;";
|
||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||
|
||||
// Execute the query and read the results
|
||||
MySqlDataReader reader = cmd.ExecuteReader();
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
// Assuming User table has columns "id", "name", and "email"
|
||||
result.AppendLine($"ID: {reader["id"]}, Name: {reader["name"]}, Email: {reader["email"]}");
|
||||
// Prepare the response message
|
||||
string responseMessage = result.ToString();
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(responseMessage))
|
||||
{
|
||||
responseMessage = "No data found.";
|
||||
}
|
||||
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(responseMessage);
|
||||
|
||||
// Set the response content type and write the response
|
||||
response.ContentType = "text/plain";
|
||||
response.ContentLength64 = buffer.Length;
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
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);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close the connection
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return 404 for other paths
|
||||
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);
|
||||
}
|
||||
|
||||
// Close the response
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
});
|
||||
|
||||
// Start the listener thread
|
||||
listenerThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
// Create an HttpListener to handle incoming HTTP requests
|
||||
HttpListener listener = new HttpListener();
|
||||
|
||||
// Add a prefix to listen to, e.g., http://localhost:8080/
|
||||
listener.Prefixes.Add("http://localhost:5000/");
|
||||
|
||||
// Start listening for incoming requests
|
||||
listener.Start();
|
||||
Console.WriteLine("Server is listening on http://localhost:5000/");
|
||||
|
||||
// Handle requests on a separate thread to keep server responsive
|
||||
Thread listenerThread = new Thread(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// Wait for a request
|
||||
HttpListenerContext context = listener.GetContext();
|
||||
|
||||
// Get the request and response objects
|
||||
HttpListenerRequest request = context.Request;
|
||||
HttpListenerResponse response = context.Response;
|
||||
|
||||
// Check if the requested URL is /api
|
||||
if (request.Url.AbsolutePath == "/api")
|
||||
{
|
||||
// Prepare a response message
|
||||
string responseMessage = "Hello from the API endpoint!";
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(responseMessage);
|
||||
|
||||
// Set the response content type and write the response
|
||||
response.ContentType = "text/plain";
|
||||
response.ContentLength64 = buffer.Length;
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return 404 for other paths
|
||||
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);
|
||||
}
|
||||
|
||||
// Close the response
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
});
|
||||
|
||||
// Start the listener thread
|
||||
listenerThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,9 +10,9 @@ namespace Server
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open the connection
|
||||
// open connection
|
||||
conn.Open();
|
||||
// Prepare the SQL query
|
||||
// prepare SQL query
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = "CALL InitDB";
|
||||
|
||||
@@ -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+4496672d19c31da56be4394168028d97a19d3a6b")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+06ea52ead66c1038b248ca644ce0e0a29ee0065f")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("TimelogBackend")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("TimelogBackend")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
9366787f5f967306279f95e5eb689ad57d8d916a1aff008ae6b71d7ccaf910fe
|
||||
b1cc7558bcbf1cf4d6ac3236c7ebc2c474885e8b8b600c803a037c8c84382d4c
|
||||
|
||||
@@ -44,9 +44,7 @@ const LeftSide = ({
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
const resp = await api.get("/getall", {
|
||||
params,
|
||||
});
|
||||
const resp = await api.get("/getall", { params });
|
||||
if (resp.data.length) setUsers(resp.data);
|
||||
}
|
||||
async function resetData() {
|
||||
@@ -62,9 +60,7 @@ const LeftSide = ({
|
||||
|
||||
const viewProjectHours = (userid: number) => {
|
||||
async function fetchHours() {
|
||||
const resp = await api.get("/getuser", {
|
||||
params: { userid },
|
||||
});
|
||||
const resp = await api.get("/getuser", { params: { userid } });
|
||||
const entriesArray = Object.entries(resp.data);
|
||||
alert(entriesArray);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import axios from "axios";
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: "http://localhost:5000/api",
|
||||
timeout: 1000,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user