Procházet zdrojové kódy

Added endpoint & service for archive ad

pull/92/head
Ermin Bronja před 3 roky
rodič
revize
7a2e9d63e1

+ 22
- 0
Diligent.WebAPI.Business/Services/AdService.cs Zobrazit soubor

await result; 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) public async Task DeleteAsync(int id)
{ {
_logger.LogInformation($"Start searching Ad with id = {id}"); _logger.LogInformation($"Start searching Ad with id = {id}");

+ 2
- 2
Diligent.WebAPI.Business/Services/AuthenticationService.cs Zobrazit soubor

FirstName = userk.FirstName, FirstName = userk.FirstName,
LastName = userk.LastName, LastName = userk.LastName,
Username = userk.UserName, Username = userk.UserName,
Token = model.Token,
RefreshToken = model.RefreshToken
Token = token,
RefreshToken = token
} }
}; };
} }

+ 2
- 0
Diligent.WebAPI.Business/Services/Interfaces/IAdService.cs Zobrazit soubor



Task UpdateAsync(int id, AdUpdateDto adUpdateDto); Task UpdateAsync(int id, AdUpdateDto adUpdateDto);


Task ArchiveAdAsync(int id);

Task DeleteAsync(int id); Task DeleteAsync(int id);
} }
} }

+ 8
- 0
Diligent.WebAPI.Host/Controllers/V1/AdsController.cs Zobrazit soubor

return Ok(); return Ok();
} }


[HttpPut("archive-active-ad/{id}")]
public async Task<IActionResult> ArchiveActiveAd([FromRoute] int id)
{
await _adService.ArchiveAdAsync(id);

return Ok();
}

[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<IActionResult> DeleteAd([FromRoute]int id) public async Task<IActionResult> DeleteAd([FromRoute]int id)
{ {

Načítá se…
Zrušit
Uložit