| @@ -145,6 +145,28 @@ | |||
| await result; | |||
| } | |||
| public async Task ArchiveAdAsync(int id) | |||
| { | |||
| _logger.LogInformation($"Start searching Ad with id = {id}"); | |||
| var ad = await _context.Ads.FindAsync(id); | |||
| if (ad is null) | |||
| { | |||
| _logger.LogError($"Ad with id = {id} not found"); | |||
| throw new EntityNotFoundException("Ad not found"); | |||
| } | |||
| _logger.LogInformation($"Change ad expired time"); | |||
| ad.ExpiredAt = DateTime.UtcNow; | |||
| _logger.LogInformation($"Ad expired time changed successfully"); | |||
| _context.Entry(ad).State = EntityState.Modified; | |||
| var result = _context.SaveChangesAsync(); | |||
| _logger.LogInformation($"Ad saved to DB"); | |||
| await result; | |||
| } | |||
| public async Task DeleteAsync(int id) | |||
| { | |||
| _logger.LogInformation($"Start searching Ad with id = {id}"); | |||
| @@ -278,8 +278,8 @@ namespace Diligent.WebAPI.Business.Services | |||
| FirstName = userk.FirstName, | |||
| LastName = userk.LastName, | |||
| Username = userk.UserName, | |||
| Token = model.Token, | |||
| RefreshToken = model.RefreshToken | |||
| Token = token, | |||
| RefreshToken = token | |||
| } | |||
| }; | |||
| } | |||
| @@ -18,6 +18,8 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| Task UpdateAsync(int id, AdUpdateDto adUpdateDto); | |||
| Task ArchiveAdAsync(int id); | |||
| Task DeleteAsync(int id); | |||
| } | |||
| } | |||
| @@ -47,6 +47,14 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| return Ok(); | |||
| } | |||
| [HttpPut("archive-active-ad/{id}")] | |||
| public async Task<IActionResult> ArchiveActiveAd([FromRoute] int id) | |||
| { | |||
| await _adService.ArchiveAdAsync(id); | |||
| return Ok(); | |||
| } | |||
| [HttpDelete("{id}")] | |||
| public async Task<IActionResult> DeleteAd([FromRoute]int id) | |||
| { | |||