diff --git a/Controllers/GameController.cs b/Controllers/GameController.cs index 0c4eb43..07e2aac 100644 --- a/Controllers/GameController.cs +++ b/Controllers/GameController.cs @@ -82,5 +82,33 @@ namespace YandexGameServer.Controllers return Ok(sb.ToString()); } + + [HttpGet("tags/{city:int}")] + public async Task 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); + } } } diff --git a/Models/Tag.cs b/Models/Tag.cs index 41a521e..3e5c982 100644 --- a/Models/Tag.cs +++ b/Models/Tag.cs @@ -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; } } } \ No newline at end of file