fighting weird bug with branches

This commit is contained in:
QkoSad
2025-07-12 10:50:44 +03:00
parent d0ea12ff8c
commit e11af3ad2a
27 changed files with 1458 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
using System.Net;
using MySql.Data.MySqlClient;
namespace Server;
public class DeleteRoute : SecuredRoute
{
protected static void DeleteFromDB(
HttpListenerRequest request,
string table,
List<string> validParamNames,
bool requireId
)
// TODO should return error when it cant find the comment
{
// extract userid compare userid to the comment userid
string user_id = ExtractUserId(request);
var bodyParamValues = ExtractBody(request, validParamNames);
if (requireId && bodyParamValues["id"] is null)
throw new Exception("missing id");
validParamNames.Add("user_id");
bodyParamValues["user_id"] = user_id;
table += requireId ? " Where user_id=@user_id;" : " WHERE id=@id AND user_id=@user_id;";
MySqlCommand cmd = new("DELETE from " + table);
cmd = AddValuesToCmd(bodyParamValues, cmd);
using MySqlConnection conn = new(connectionString);
conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}