db test
This commit is contained in:
@@ -1,11 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace file_finder__test.DataBaseModules{
|
||||
|
||||
//Alloufi Yazan
|
||||
public class DataBase
|
||||
//Quinn
|
||||
public class DataBase:IDisposable
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
private readonly string _baseUrl;
|
||||
|
||||
public DataBase(string baseUrl)
|
||||
{
|
||||
_baseUrl = baseUrl.TrimEnd('/');
|
||||
_client = new HttpClient();
|
||||
}
|
||||
|
||||
// Core method to send JSON requests
|
||||
private async Task<string> SendRequestAsync(string endpoint, object data)
|
||||
{
|
||||
string url = $"{_baseUrl}/{endpoint}";
|
||||
string jsonData = System.Text.Json.JsonSerializer.Serialize(data);
|
||||
|
||||
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = await _client.PostAsync(url, content);
|
||||
|
||||
response.EnsureSuccessStatusCode(); // throw if erro
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
// User methods
|
||||
public Task<string> UserSet(object userData)
|
||||
=> SendRequestAsync("user/set.php", userData);
|
||||
|
||||
public Task<string> UserGet(object requestData)
|
||||
=> SendRequestAsync("user/get.php", requestData);
|
||||
|
||||
public Task<string> UserCreate(object userData)
|
||||
=> SendRequestAsync("user/create.php", userData);
|
||||
|
||||
// Media methods
|
||||
public Task<string> MediaGet(object requestData)
|
||||
=> SendRequestAsync("media/get.php", requestData);
|
||||
|
||||
public Task<string> MediaAdd(object mediaData)
|
||||
=> SendRequestAsync("media/add.php", mediaData);
|
||||
|
||||
public Task<string> MediaRemove(object mediaData)
|
||||
=> SendRequestAsync("media/remove.php", mediaData);
|
||||
|
||||
// update muvie watch counter
|
||||
public Task<string> MovieWatchIncrement(object requestData)
|
||||
=> SendRequestAsync("movie/watch.php", requestData);
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_client.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
37
file finder test/Modules/DataBaseModules/mediaUpdate.cs
Normal file
37
file finder test/Modules/DataBaseModules/mediaUpdate.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace file_finder__test.DataBaseModules
|
||||
{
|
||||
public class mediaUpdate
|
||||
{
|
||||
public int Uid { get; set; }
|
||||
public string MovieName { get; set; }
|
||||
|
||||
DataBase tmp = new DataBase("http//:localhost//file_finder/mediaUpdate");
|
||||
public string Json { get; private set; }
|
||||
public mediaUpdate(int uid, string movieName)
|
||||
{
|
||||
Uid = uid;
|
||||
MovieName = movieName;
|
||||
|
||||
// Serialize to JSON
|
||||
Json = JsonSerializer.Serialize(new
|
||||
{
|
||||
uid = Uid,
|
||||
movieName = MovieName
|
||||
});
|
||||
Console.WriteLine(Json);
|
||||
using var db = new DataBase("https://yourserver.com/api");
|
||||
string response = db.MovieWatchIncrement(Json).Result;
|
||||
|
||||
if(response.Contains("302"))
|
||||
Console.WriteLine("db not found");
|
||||
else
|
||||
{
|
||||
Console.WriteLine(response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("file finder test")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8325267b1ee9a9d989a012b4424ff5a82fabd2dc")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+31e285348e08c73328cdf74e9365b74d3d52cebe")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("file finder test")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("file finder test")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@@ -1 +1 @@
|
||||
191a99e79cd3f420bd587bb460eff2aebc97037046155ce3d7c7042bf0b7c27e
|
||||
54902fc7076061e851b27fe864585e7c25ff257e41a52253814b289ee3d0fa13
|
||||
|
@@ -1 +1 @@
|
||||
e4c75367b96fe966bbfb7d4e53e4acd5e4f6d7322d8b9ba65d3d987bedb4cf9b
|
||||
45f88c71b79bcce5e13e2bc88821be88637e3d7c7093b0ebcaefb24ff7d4c1da
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user