add tag func
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user