From 75b9958b973c2f37ce7f0f944de89dcdd7baf2bd Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:36:25 +1000 Subject: [PATCH 01/12] asdf --- DBchat.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/DBchat.cs b/DBchat.cs index 1c7d677..9f54aca 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -45,7 +45,7 @@ namespace NeDvachAPI using ( var command = new NpgsqlCommand(@" SELECT * FROM ( - SELECT post_id, post + SELECT post_id, post, post_timestamp FROM dvach ORDER BY post_id DESC ) subquery @@ -64,9 +64,10 @@ namespace NeDvachAPI //); Post receivedPost = new() { - Date = DateTime.Now, - Id = reader.GetInt32(0), - Text = reader.GetString(1) + // Date = DateTime.Now, + Id = reader.GetInt32(0), + Text = reader.GetString(1), + Date = reader.GetString(2) }; posts.Add(receivedPost); //posts[postCount] = receivedPost; From 26df236ae7c7584d8233040b6db4b86ad9a0f8cc Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:38:24 +1000 Subject: [PATCH 02/12] recieve date --- DBchat.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DBchat.cs b/DBchat.cs index d8203c6..aa159ae 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -65,9 +65,10 @@ namespace NeDvachAPI //); Post receivedPost = new() { - Date = DateTime.Now, + //Date = DateTime.Now, Id = reader.GetInt32(0), - Text = reader.GetString(1) + Text = reader.GetString(1), + Date = reader.GetString(2) }; posts.Add(receivedPost); //posts[postCount] = receivedPost; From 07de4fa97246b4ed2566aa991efece9e5d9e93d6 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:40:06 +1000 Subject: [PATCH 03/12] recieve date --- DBchat.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DBchat.cs b/DBchat.cs index aa159ae..11273d7 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -66,9 +66,9 @@ namespace NeDvachAPI Post receivedPost = new() { //Date = DateTime.Now, - Id = reader.GetInt32(0), - Text = reader.GetString(1), - Date = reader.GetString(2) + Id = reader.GetInt32(0), + Text = reader.GetString(1), + Timestamp = reader.GetString(2) }; posts.Add(receivedPost); //posts[postCount] = receivedPost; From be02399eb0b2308b9829c80562e9885f65bdd9d0 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:48:50 +1000 Subject: [PATCH 04/12] send date --- DBchat.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DBchat.cs b/DBchat.cs index 11273d7..81aa10d 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -128,10 +128,10 @@ namespace NeDvachAPI using (var command = new NpgsqlCommand(@" INSERT INTO dvach " + @"(post_id, post, post_timestamp) - VALUES (DEFAULT, @postText, @postTimeStamp)", conn)) + VALUES (DEFAULT, @postText, (SELECT date_trunc('second', now()::timestamp(0)) AT TIME ZONE 'UTC-10') )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); - command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); + //command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); int nRows = command.ExecuteNonQuery(); Console.Out.WriteLine("Добавлен пост"); From 218484a0f12baf20cee134f2815b015b529aac17 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:51:09 +1000 Subject: [PATCH 05/12] send date --- DBchat.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBchat.cs b/DBchat.cs index 81aa10d..4c0a8b9 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -128,7 +128,7 @@ namespace NeDvachAPI using (var command = new NpgsqlCommand(@" INSERT INTO dvach " + @"(post_id, post, post_timestamp) - VALUES (DEFAULT, @postText, (SELECT date_trunc('second', now()::timestamp(0)) AT TIME ZONE 'UTC-10') )", conn)) + VALUES (DEFAULT, @postText, ( SELECT date_trunc('second', now()::timestamp(0) ) )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); //command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); From 2c485665b0660778d9af2351a6e2824c17deb236 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:51:57 +1000 Subject: [PATCH 06/12] send date --- DBchat.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DBchat.cs b/DBchat.cs index 4c0a8b9..e4c295b 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -127,8 +127,10 @@ namespace NeDvachAPI conn.Open(); using (var command = new NpgsqlCommand(@" - INSERT INTO dvach " + @"(post_id, post, post_timestamp) - VALUES (DEFAULT, @postText, ( SELECT date_trunc('second', now()::timestamp(0) ) )", conn)) + INSERT INTO dvach (post_id, post, post_timestamp) + VALUES ( DEFAULT, @postText, ( + SELECT date_trunc('second', now()::timestamp(0) + ) )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); //command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); From c1edc35c28cca49f95b9c0d613d8999f179d0da5 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:56:11 +1000 Subject: [PATCH 07/12] backing up my SKOBKA --- DBchat.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBchat.cs b/DBchat.cs index e4c295b..3bd255f 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -129,7 +129,7 @@ namespace NeDvachAPI using (var command = new NpgsqlCommand(@" INSERT INTO dvach (post_id, post, post_timestamp) VALUES ( DEFAULT, @postText, ( - SELECT date_trunc('second', now()::timestamp(0) + SELECT date_trunc( 'second', now()::timestamp(0) ) ) )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); From b3768afb91ba096f21f672ea06cfbe21df312a12 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:58:32 +1000 Subject: [PATCH 08/12] back to VDK --- DBchat.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DBchat.cs b/DBchat.cs index 3bd255f..0a0a255 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -129,7 +129,7 @@ namespace NeDvachAPI using (var command = new NpgsqlCommand(@" INSERT INTO dvach (post_id, post, post_timestamp) VALUES ( DEFAULT, @postText, ( - SELECT date_trunc( 'second', now()::timestamp(0) ) + SELECT date_trunc( 'second', now()::timestamp(0) AT TIME ZONE 'UTC+10') ) )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); From 86d3e2d9b56adce1d493007f6cd3b04a3a0666ae Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sat, 29 Oct 2022 14:11:01 +1000 Subject: [PATCH 09/12] timestamp type fix --- DBchat.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DBchat.cs b/DBchat.cs index 0a0a255..5940149 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -129,7 +129,10 @@ namespace NeDvachAPI using (var command = new NpgsqlCommand(@" INSERT INTO dvach (post_id, post, post_timestamp) VALUES ( DEFAULT, @postText, ( - SELECT date_trunc( 'second', now()::timestamp(0) AT TIME ZONE 'UTC+10') + SELECT date_trunc( + 'second', + (now()::timestamp(0) AT TIME ZONE 'UTC+10')::TIMESTAMP + ) ) )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); From 5228f74c4900aa4fafa5eec71c2e7cb3aab9fbc0 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Wed, 2 Nov 2022 00:56:19 +1000 Subject: [PATCH 10/12] getting ip addresses --- Controllers/GetPosts.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Controllers/GetPosts.cs b/Controllers/GetPosts.cs index be53cfd..cef9270 100644 --- a/Controllers/GetPosts.cs +++ b/Controllers/GetPosts.cs @@ -10,10 +10,12 @@ namespace NeDvachAPI.Controllers [HttpGet(Name = "GetPosts")] public string Get() { + var remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress; + //Post[] posts = DBchat.DbList(); List posts = DBchat.DbList(); string postsJson = JsonSerializer.Serialize(posts); - Console.WriteLine("Запрошен список постов."); + Console.WriteLine($"Запрошен список постов для {remoteIpAddress}"); return postsJson ; From 0dc55aa9dfa34c575eaed71a967e1861a4291fe2 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Wed, 2 Nov 2022 00:58:07 +1000 Subject: [PATCH 11/12] getting ip addresses --- Controllers/GetPosts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controllers/GetPosts.cs b/Controllers/GetPosts.cs index cef9270..a773590 100644 --- a/Controllers/GetPosts.cs +++ b/Controllers/GetPosts.cs @@ -10,7 +10,7 @@ namespace NeDvachAPI.Controllers [HttpGet(Name = "GetPosts")] public string Get() { - var remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress; + var remoteIpAddress = httpContext.GetFeature()?.RemoteIpAddress; //Post[] posts = DBchat.DbList(); List posts = DBchat.DbList(); From 10b089091585b363d2cf227a688da611f5870b5d Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Wed, 2 Nov 2022 01:00:29 +1000 Subject: [PATCH 12/12] not getting ip addresses --- Controllers/GetPosts.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Controllers/GetPosts.cs b/Controllers/GetPosts.cs index a773590..e244c68 100644 --- a/Controllers/GetPosts.cs +++ b/Controllers/GetPosts.cs @@ -9,13 +9,12 @@ namespace NeDvachAPI.Controllers { [HttpGet(Name = "GetPosts")] public string Get() - { - var remoteIpAddress = httpContext.GetFeature()?.RemoteIpAddress; + { //Post[] posts = DBchat.DbList(); List posts = DBchat.DbList(); string postsJson = JsonSerializer.Serialize(posts); - Console.WriteLine($"Запрошен список постов для {remoteIpAddress}"); + Console.WriteLine("Запрошен список постов.); return postsJson ;