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")]
public string Get()
{
Post[] posts = DBchat.DbList();
//Post[] posts = DBchat.DbList();
List<Post> posts = DBchat.DbList();
string postsJson = JsonSerializer.Serialize(posts);
Console.WriteLine("Запрошен список постов.");
return postsJson ;

View File

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

View File

@ -6,14 +6,26 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
<<<<<<< HEAD
=======
>>>>>>> 0efca3b0b5781ab54d78c97a62b20b0f47d7dabf
builder.Services.AddCors(setup =>
{
setup.AddDefaultPolicy(policyBuilder =>
{
<<<<<<< HEAD
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();