add tag func

This commit is contained in:
2023-07-09 19:48:22 +05:00
parent 2666010003
commit 4bc30dbda7
2 changed files with 32 additions and 1 deletions
+28
View File
@@ -82,5 +82,33 @@ namespace YandexGameServer.Controllers
return Ok(sb.ToString());
}
[HttpGet("tags/{city:int}")]
public async Task<IActionResult> GetTags(int cityCode)
{
Cities city = (Cities)cityCode;
var result = await _databaseService.GetTagsAsync();
if (result == null) return NotFound();
var tags = result.Where(x => x.city == city).ToList();
if (tags.Count == 0) return NotFound();
else return Ok(tags);
}
[HttpPost("tags/add")]
public async Task SetTags(Tag tag)
{
var tagsInUse = await _databaseService.GetTagsAsync();
if(tagsInUse == null)
{
await _databaseService.CreateAsync(tag);
return;
}
Tag? tagInUse = tagsInUse.Find(x => x.game == tag.game && x.city == tag.city);
if (tagInUse == null) await _databaseService.CreateAsync(tag);
else await _databaseService.UpdateAsync(tag);
}
}
}
+4 -1
View File
@@ -1,5 +1,7 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using YandexGameServer.Services;
using YandexGameServer.Controllers;
namespace YandexGameServer.Models
{
@@ -8,7 +10,8 @@ namespace YandexGameServer.Models
{
[BsonId, BsonRepresentation(BsonType.ObjectId)]
public string id { get; set; }
public Games game { get; set; }
public string descrition { get; set; }
public string? city { get; set; }
public Cities city { get; set; }
}
}