some fix
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
RakVhalate 2022-10-20 22:28:12 +10:00
commit 2a71885a85
3 changed files with 36 additions and 12 deletions

View File

@ -10,7 +10,8 @@ namespace NeDvachAPI.Controllers
[HttpGet(Name = "GetPosts")] [HttpGet(Name = "GetPosts")]
public string Get() public string Get()
{ {
Post[] posts = DBchat.DbList(); //Post[] posts = DBchat.DbList();
List<Post> posts = DBchat.DbList();
string postsJson = JsonSerializer.Serialize(posts); string postsJson = JsonSerializer.Serialize(posts);
Console.WriteLine("Запрошен список постов."); Console.WriteLine("Запрошен список постов.");
return postsJson ; return postsJson ;

View File

@ -12,11 +12,12 @@ namespace NeDvachAPI
private static string Password = "postgres"; private static string Password = "postgres";
private static string Port = "5432"; private static string Port = "5432";
public static Post[] DbList() public static List<Post> DbList()
{ {
// Build connection string using parameters from portal // Build connection string using parameters from portal
Post[] posts = new Post[10]; //Post[] posts = new Post[10];
int postCount = 0; List<Post> posts = new List<Post>();
//int postCount = 0;
string received = ""; string received = "";
string connString = string connString =
String.Format( String.Format(
@ -34,13 +35,22 @@ namespace NeDvachAPI
conn.Open(); conn.Open();
using (var command = new NpgsqlCommand(@" // 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 * FROM
(SELECT post_id, substring(post,1,200) (
FROM dvach SELECT post_id, post
ORDER BY post_id FROM dvach
DESC limit 10) ORDER BY post_id DESC
subquery ORDER BY post_id ASC", conn)) ) subquery
ORDER BY post_id ASC", conn) )
{ {
var reader = command.ExecuteReader(); var reader = command.ExecuteReader();
@ -59,8 +69,9 @@ namespace NeDvachAPI
Id = reader.GetInt32(0), Id = reader.GetInt32(0),
Text = reader.GetString(1) Text = reader.GetString(1)
}; };
posts[postCount] = receivedPost; posts.Add(receivedPost);
postCount++; //posts[postCount] = receivedPost;
//postCount++;
} }
reader.Close(); reader.Close();
} }

View File

@ -6,14 +6,26 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
<<<<<<< HEAD
=======
>>>>>>> 0efca3b0b5781ab54d78c97a62b20b0f47d7dabf
builder.Services.AddCors(setup => builder.Services.AddCors(setup =>
{ {
setup.AddDefaultPolicy(policyBuilder => setup.AddDefaultPolicy(policyBuilder =>
{ {
<<<<<<< HEAD
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("PUT", "POST").WithHeaders("*"); policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("PUT", "POST").WithHeaders("*");
}); });
}); });
=======
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200");
});
});
//builder.Services.AddSwaggerGen();
>>>>>>> 0efca3b0b5781ab54d78c97a62b20b0f47d7dabf
var app = builder.Build(); var app = builder.Build();