From 5fee059b51ddb52f54da0a8f65118725f98b1223 Mon Sep 17 00:00:00 2001 From: rak Date: Tue, 18 Oct 2022 20:35:11 +1000 Subject: [PATCH 1/4] Added Test echo posting --- .vscode/launch.json | 35 ++++++++++++++++++++++++++++++ .vscode/tasks.json | 41 ++++++++++++++++++++++++++++++++++++ Controllers/TestPosting.cs | 17 +++++++++++++++ DBchat.cs | 14 ++++++++---- appsettings.Development.json | 2 +- appsettings.json | 2 +- 6 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 Controllers/TestPosting.cs diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..862c268 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net6.0/NeDvachAPI.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..9142f12 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/NeDvachAPI.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/NeDvachAPI.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/NeDvachAPI.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Controllers/TestPosting.cs b/Controllers/TestPosting.cs new file mode 100644 index 0000000..ffd7454 --- /dev/null +++ b/Controllers/TestPosting.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; +using System.Text.Json; + +namespace NeDvachAPI.Controllers +{ + [ApiController] + [Route("[controller]")] + public class TestPostingController : ControllerBase + { + [HttpPost(Name = "TestPostPosts")] + public Post ReceivePost([FromBody] Post ReceivedPost) + { + //DBchat.SendPost(ReceivedPost); + return ReceivedPost; + } + } +} diff --git a/DBchat.cs b/DBchat.cs index 7125fae..a9b5655 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -5,7 +5,6 @@ namespace NeDvachAPI public class DBchat { // Obtain connection string information from the portal - // private static string Host = "postgres.vdk2ch.ru"; private static string User = "postgres"; private static string DBname = "postgres"; @@ -34,7 +33,13 @@ namespace NeDvachAPI conn.Open(); - using (var command = new NpgsqlCommand("SELECT * FROM (SELECT post_id, substring(post,1,200) FROM dvach ORDER BY post_id DESC limit 10) subquery ORDER BY post_id ASC", conn)) + using (var command = new NpgsqlCommand(@" + SELECT * FROM + (SELECT post_id, substring(post,1,200) + FROM dvach + ORDER BY post_id + DESC limit 10) + subquery ORDER BY post_id ASC", conn)) { var reader = command.ExecuteReader(); @@ -113,8 +118,9 @@ namespace NeDvachAPI Console.Out.WriteLine("Opening connection"); conn.Open(); - using (var command = new NpgsqlCommand("INSERT INTO dvach " + - "(post_id, post) VALUES (DEFAULT, @postText)", conn)) + using (var command = new NpgsqlCommand(@" + INSERT INTO dvach " + @"(post_id, post) + VALUES (DEFAULT, @postText)", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); diff --git a/appsettings.Development.json b/appsettings.Development.json index 0c208ae..a6e86ac 100644 --- a/appsettings.Development.json +++ b/appsettings.Development.json @@ -1,7 +1,7 @@ { "Logging": { "LogLevel": { - "Default": "Information", + "Default": "Debug", "Microsoft.AspNetCore": "Warning" } } diff --git a/appsettings.json b/appsettings.json index 10f68b8..23039ed 100644 --- a/appsettings.json +++ b/appsettings.json @@ -1,7 +1,7 @@ { "Logging": { "LogLevel": { - "Default": "Information", + "Default": "Debug", "Microsoft.AspNetCore": "Warning" } }, From cd5d50f06b9ae022674efe857218fb4c2db1a42e Mon Sep 17 00:00:00 2001 From: rak Date: Tue, 18 Oct 2022 22:10:33 +1000 Subject: [PATCH 2/4] Added Test echo posting --- Controllers/TestPosting.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Controllers/TestPosting.cs b/Controllers/TestPosting.cs index ffd7454..dfeaf20 100644 --- a/Controllers/TestPosting.cs +++ b/Controllers/TestPosting.cs @@ -7,11 +7,11 @@ namespace NeDvachAPI.Controllers [Route("[controller]")] public class TestPostingController : ControllerBase { - [HttpPost(Name = "TestPostPosts")] - public Post ReceivePost([FromBody] Post ReceivedPost) + [HttpPost("{text}", Name = "ReceivePost")] + public string ReceivePost(string text) { //DBchat.SendPost(ReceivedPost); - return ReceivedPost; + return text; } } } From 13acfdc7da2d2991e1c2b7140a87a59208c1ea44 Mon Sep 17 00:00:00 2001 From: rak Date: Tue, 18 Oct 2022 22:35:19 +1000 Subject: [PATCH 3/4] Added Test echo posting2 --- Controllers/TestPosting.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Controllers/TestPosting.cs b/Controllers/TestPosting.cs index dfeaf20..c036eef 100644 --- a/Controllers/TestPosting.cs +++ b/Controllers/TestPosting.cs @@ -7,11 +7,11 @@ namespace NeDvachAPI.Controllers [Route("[controller]")] public class TestPostingController : ControllerBase { - [HttpPost("{text}", Name = "ReceivePost")] - public string ReceivePost(string text) + [HttpPost] + public string Area(int altitude , int height) { //DBchat.SendPost(ReceivedPost); - return text; + return $"Первое значение {altitude} и второе значение {height}"; } } } From 7dad7f6aaef3c160c482b7620ddbeb285e39bc4f Mon Sep 17 00:00:00 2001 From: rak Date: Tue, 18 Oct 2022 22:40:27 +1000 Subject: [PATCH 4/4] Added Test echo posting2 --- Controllers/TestPosting.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Controllers/TestPosting.cs b/Controllers/TestPosting.cs index c036eef..da917f4 100644 --- a/Controllers/TestPosting.cs +++ b/Controllers/TestPosting.cs @@ -8,10 +8,10 @@ namespace NeDvachAPI.Controllers public class TestPostingController : ControllerBase { [HttpPost] - public string Area(int altitude , int height) + public int Area(int altitude , int height) { //DBchat.SendPost(ReceivedPost); - return $"Первое значение {altitude} и второе значение {height}"; + return altitude+height; } } }