done
This commit is contained in:
@@ -9,9 +9,7 @@ namespace Server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open the connection
|
|
||||||
conn.Open();
|
conn.Open();
|
||||||
// Prepare the SQL query
|
|
||||||
MySqlCommand cmd = new MySqlCommand();
|
MySqlCommand cmd = new MySqlCommand();
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandText = @"
|
cmd.CommandText = @"
|
||||||
@@ -120,7 +118,6 @@ BEGIN
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Handle any connection errors
|
|
||||||
string errorMessage = $"Error: {ex.Message}";
|
string errorMessage = $"Error: {ex.Message}";
|
||||||
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
||||||
response.ContentType = "text/plain";
|
response.ContentType = "text/plain";
|
||||||
|
|||||||
+5
-7
@@ -23,9 +23,9 @@ namespace Server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open the connection
|
// open connection
|
||||||
conn.Open();
|
conn.Open();
|
||||||
// Prepare the SQL query
|
// prepare SQL query
|
||||||
MySqlCommand cmd = new MySqlCommand();
|
MySqlCommand cmd = new MySqlCommand();
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
// get url params
|
// get url params
|
||||||
@@ -36,8 +36,7 @@ namespace Server
|
|||||||
string? offset = queryString["offset"];
|
string? offset = queryString["offset"];
|
||||||
string? order = queryString["order"];
|
string? order = queryString["order"];
|
||||||
order = order == "true" ? "ASC" : "DESC";
|
order = order == "true" ? "ASC" : "DESC";
|
||||||
// this shenanigan is needed to remove the "" around
|
// this shenanigan is needed to remove the "" around group by
|
||||||
// group by
|
|
||||||
string sqlQ = @"SELECT u.f_name,u.l_name,u.mail,p.name,t.time,t.date,t.user
|
string sqlQ = @"SELECT u.f_name,u.l_name,u.mail,p.name,t.time,t.date,t.user
|
||||||
FROM Timelog t
|
FROM Timelog t
|
||||||
INNER JOIN Project p ON p.id=t.project
|
INNER JOIN Project p ON p.id=t.project
|
||||||
@@ -60,7 +59,7 @@ namespace Server
|
|||||||
cmd.Parameters.AddWithValue("@from", from);
|
cmd.Parameters.AddWithValue("@from", from);
|
||||||
cmd.Parameters.AddWithValue("@to", to);
|
cmd.Parameters.AddWithValue("@to", to);
|
||||||
|
|
||||||
// Execute the query and read the results
|
// execute query and read results
|
||||||
MySqlDataReader reader = cmd.ExecuteReader();
|
MySqlDataReader reader = cmd.ExecuteReader();
|
||||||
|
|
||||||
List<All> entries = new List<All>();
|
List<All> entries = new List<All>();
|
||||||
@@ -77,7 +76,7 @@ namespace Server
|
|||||||
mail = reader["mail"],
|
mail = reader["mail"],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// serialize the data to JSON
|
// serialize JSON
|
||||||
string jsonResponse = JsonConvert.SerializeObject(entries);
|
string jsonResponse = JsonConvert.SerializeObject(entries);
|
||||||
// prepare response
|
// prepare response
|
||||||
byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse);
|
byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse);
|
||||||
@@ -88,7 +87,6 @@ namespace Server
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Handle any connection errors
|
|
||||||
string errorMessage = $"Error: {ex.Message}";
|
string errorMessage = $"Error: {ex.Message}";
|
||||||
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
||||||
response.ContentType = "text/plain";
|
response.ContentType = "text/plain";
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ namespace Server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open the connection
|
// open db connection
|
||||||
conn.Open();
|
conn.Open();
|
||||||
// Prepare the SQL query
|
// prepare SQL query
|
||||||
MySqlCommand cmd = new MySqlCommand();
|
MySqlCommand cmd = new MySqlCommand();
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
var queryString = request.QueryString;
|
var queryString = request.QueryString;
|
||||||
@@ -70,7 +70,6 @@ namespace Server
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Handle any connection errors
|
|
||||||
string errorMessage = $"Error: {ex.Message}";
|
string errorMessage = $"Error: {ex.Message}";
|
||||||
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
||||||
response.ContentType = "text/plain";
|
response.ContentType = "text/plain";
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ namespace Server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open the connection
|
// open connection
|
||||||
conn.Open();
|
conn.Open();
|
||||||
// Prepare the SQL query
|
// prepare SQL query
|
||||||
MySqlCommand cmd = new MySqlCommand();
|
MySqlCommand cmd = new MySqlCommand();
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandText = @"SELECT p.name, SUM(t.time)
|
cmd.CommandText = @"SELECT p.name, SUM(t.time)
|
||||||
@@ -26,7 +26,7 @@ namespace Server
|
|||||||
var queryString = request.QueryString;
|
var queryString = request.QueryString;
|
||||||
string? userid = queryString["userid"];
|
string? userid = queryString["userid"];
|
||||||
cmd.Parameters.AddWithValue("@userid", userid);
|
cmd.Parameters.AddWithValue("@userid", userid);
|
||||||
// Execute the query and read the results
|
// execute query and read results
|
||||||
MySqlDataReader reader = cmd.ExecuteReader();
|
MySqlDataReader reader = cmd.ExecuteReader();
|
||||||
dynamic expando = new ExpandoObject();
|
dynamic expando = new ExpandoObject();
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
@@ -34,7 +34,7 @@ namespace Server
|
|||||||
((IDictionary<string?, object>)expando)[reader["name"].ToString()] = reader["SUM(t.time)"];
|
((IDictionary<string?, object>)expando)[reader["name"].ToString()] = reader["SUM(t.time)"];
|
||||||
|
|
||||||
}
|
}
|
||||||
// Serialize the data to JSON
|
// serialize JSON
|
||||||
string jsonResponse = JsonConvert.SerializeObject(expando);
|
string jsonResponse = JsonConvert.SerializeObject(expando);
|
||||||
// prepare response
|
// prepare response
|
||||||
byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse);
|
byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse);
|
||||||
@@ -45,13 +45,13 @@ namespace Server
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Handle any connection errors
|
|
||||||
string errorMessage = $"Error: {ex.Message}";
|
string errorMessage = $"Error: {ex.Message}";
|
||||||
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
|
||||||
response.ContentType = "text/plain";
|
response.ContentType = "text/plain";
|
||||||
response.ContentLength64 = buffer.Length;
|
response.ContentLength64 = buffer.Length;
|
||||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||||
}
|
}
|
||||||
|
// close db connection
|
||||||
conn.Close();
|
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/reset/");
|
||||||
listener.Prefixes.Add("http://localhost:5000/api/createp/");
|
listener.Prefixes.Add("http://localhost:5000/api/createp/");
|
||||||
|
|
||||||
// Start listening for incoming requests
|
// listen
|
||||||
listener.Start();
|
listener.Start();
|
||||||
Console.WriteLine("Server is listening on http://localhost:5000/");
|
Console.WriteLine("Server is listening on http://localhost:5000/");
|
||||||
// god knows what that is
|
|
||||||
/* Thread listenerThread = new Thread(() => */
|
|
||||||
/* { */
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// wait for request
|
// wait for request
|
||||||
@@ -37,8 +34,7 @@ namespace Server
|
|||||||
MySqlConnection conn = new MySqlConnection(connectionString);
|
MySqlConnection conn = new MySqlConnection(connectionString);
|
||||||
|
|
||||||
// url after localhost:5000/
|
// url after localhost:5000/
|
||||||
// i think the validation is unnecessry but the compiler has
|
// i think the validation is unnecessry but the compiler doesn't
|
||||||
// more experience
|
|
||||||
string uri;
|
string uri;
|
||||||
if (request != null && request.Url != null)
|
if (request != null && request.Url != null)
|
||||||
{
|
{
|
||||||
@@ -74,12 +70,9 @@ namespace Server
|
|||||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Close the response
|
// send the response
|
||||||
response.OutputStream.Close();
|
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
|
try
|
||||||
{
|
{
|
||||||
// Open the connection
|
// open connection
|
||||||
conn.Open();
|
conn.Open();
|
||||||
// Prepare the SQL query
|
// prepare SQL query
|
||||||
MySqlCommand cmd = new MySqlCommand();
|
MySqlCommand cmd = new MySqlCommand();
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandText = "CALL InitDB";
|
cmd.CommandText = "CALL InitDB";
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("TimelogBackend")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("TimelogBackend")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("TimelogBackend")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("TimelogBackend")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("TimelogBackend")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
9366787f5f967306279f95e5eb689ad57d8d916a1aff008ae6b71d7ccaf910fe
|
b1cc7558bcbf1cf4d6ac3236c7ebc2c474885e8b8b600c803a037c8c84382d4c
|
||||||
|
|||||||
@@ -44,9 +44,7 @@ const LeftSide = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const resp = await api.get("/getall", {
|
const resp = await api.get("/getall", { params });
|
||||||
params,
|
|
||||||
});
|
|
||||||
if (resp.data.length) setUsers(resp.data);
|
if (resp.data.length) setUsers(resp.data);
|
||||||
}
|
}
|
||||||
async function resetData() {
|
async function resetData() {
|
||||||
@@ -62,9 +60,7 @@ const LeftSide = ({
|
|||||||
|
|
||||||
const viewProjectHours = (userid: number) => {
|
const viewProjectHours = (userid: number) => {
|
||||||
async function fetchHours() {
|
async function fetchHours() {
|
||||||
const resp = await api.get("/getuser", {
|
const resp = await api.get("/getuser", { params: { userid } });
|
||||||
params: { userid },
|
|
||||||
});
|
|
||||||
const entriesArray = Object.entries(resp.data);
|
const entriesArray = Object.entries(resp.data);
|
||||||
alert(entriesArray);
|
alert(entriesArray);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import axios from "axios";
|
|||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: "http://localhost:5000/api",
|
baseURL: "http://localhost:5000/api",
|
||||||
|
timeout: 1000,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user