Selaa lähdekoodia

Added endpoint & service for archive ad

pull/92/head
Ermin Bronja 3 vuotta sitten
vanhempi
commit
7a2e9d63e1

+ 22
- 0
Diligent.WebAPI.Business/Services/AdService.cs Näytä tiedosto

@@ -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}");

+ 2
- 2
Diligent.WebAPI.Business/Services/AuthenticationService.cs Näytä tiedosto

@@ -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
}
};
}

+ 2
- 0
Diligent.WebAPI.Business/Services/Interfaces/IAdService.cs Näytä tiedosto

@@ -18,6 +18,8 @@ namespace Diligent.WebAPI.Business.Services.Interfaces

Task UpdateAsync(int id, AdUpdateDto adUpdateDto);

Task ArchiveAdAsync(int id);

Task DeleteAsync(int id);
}
}

+ 8
- 0
Diligent.WebAPI.Host/Controllers/V1/AdsController.cs Näytä tiedosto

@@ -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)
{

Loading…
Peruuta
Tallenna