conflict resolution
continuous-integration/drone/push Build is failing Details

pull/6/head
Kevin MONDEJAR 3 weeks ago
commit f53718694e

@ -55,13 +55,9 @@ namespace Contextlib
List<Quote> quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
.ToListAsync();
if (quotes.Count() == 0) return null;
Quote quote = quotes[date.DayNumber % quotes.Count()];
/*Quote quote = await _context.quotes.Where(item => item.Id == date.DayNumber % quotes.Count())
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
.FirstOrDefaultAsync() ?? quotes.First();*/
//Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First();
return quote;
}
@ -106,15 +102,12 @@ namespace Contextlib
return lastQuoteId;
}
public async Task<Quote> GetQuoteById(int id)
public async Task<Quote?> GetQuoteById(int id)
{
Quote? quote = _context.quotes.Where(item => item.Id == id)
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
.First();
if (quote == null)
{
throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}.");
}
.FirstOrDefault();
return quote;
}
@ -179,8 +172,9 @@ namespace Contextlib
public async Task RemoveQuote(int quoteId)
{
_repo.Delete( _repo.GetById(quoteId) );
var quote = _repo.GetById(quoteId);
if (quote == null) throw new KeyNotFoundException();
_repo.Delete( quote );
await _context.SaveChangesAsync();
}
@ -210,11 +204,27 @@ namespace Contextlib
q.IdUsersPropose = quote.IdUsersPropose;
change = true;
}
if (quote.Content != null || quote.Content =="")
if (quote.Content != null || quote.Content == "")
{
q.Content = quote.Content;
change = true;
}
if (quote.IsValid != q.IsValid)
{
q.IsValid = quote.IsValid;
change = true;
}
if (quote.Likes != q.Likes)
{
q.Likes = quote.Likes;
change = true;
}
if (quote.Langage != q.Langage)
{
q.Langage = quote.Langage;
change = true;
}
_repo.Update(q);
if (change) _context.SaveChanges();
}

@ -388,13 +388,17 @@ namespace Dto2Entities
Quote quote = new Quote();
quote.Id = item.Id;
quote.Content = item.Content;
quote.Source = new Source();
quote.Source.Year = item.DateSource;
quote.Character = new Character();
quote.Character.Name = item.Character;
quote.Source.Title = item.TitleSource;
quote.Langage = item.Langage.ToEntity();
quote.Character.Images = new Images();
quote.Character.Images.ImgPath = item.ImagePath;
quote.Likes = item.Like;
quote.Source.TypeSrc = item.Type.ToEntity();
quote.IsValid = item.IsValide;
return quote;
}

@ -65,9 +65,11 @@ namespace ServicesApi
return await quoteService.GetLastQuoteId();
}
public async Task<QuoteDTO> GetQuoteById(int id)
public async Task<QuoteDTO?> GetQuoteById(int id)
{
return quoteService.GetQuoteById(id).Result.ToDto();
var quote= quoteService.GetQuoteById(id).Result;
if (quote != null) return quote.ToDto();
else return null;
}
public async Task<PaginationResult<QuoteDTO>> GetSomeQuote(int index, int pageSize)

@ -33,7 +33,10 @@ namespace WfApi.Controllers
try
{
var result = await _quote.GetQuoteById(id);
if (result == null)
{
throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}.");
}
if (result!=null)
{
return await Task.FromResult<IActionResult>(Ok(result));
@ -256,20 +259,27 @@ namespace WfApi.Controllers
{
try
{
if (newQuote == null)
try
{
return BadRequest(new { message = "Les données de la quote sont requises." });
}
if (newQuote == null)
{
return BadRequest(new { message = "Les données de la quote sont requises." });
}
var existingPlayer = _quote.GetQuoteById(newQuote.Id).Result;
if (existingPlayer != null)
{
return Conflict(new { message = "Une quote avec cet ID existe déjà." });
}
_quote.AddQuote(newQuote);
if (await _quote.GetQuoteById(newQuote.Id) != null)
{
return Conflict(new { message = "Une quote avec cet ID existe déjà." });
}
newQuote.IsValide=false;
var quote=_quote.AddQuote(newQuote);
return CreatedAtAction(nameof(GetAllQuote), new { id = newQuote.Id }, newQuote);
return CreatedAtAction(nameof(CreateQuote), new { id = newQuote.Id }, quote);
}
catch (KeyNotFoundException e)
{
return StatusCode((int)HttpStatusCode.NotFound, e);
}
}
catch (Exception)
{
@ -331,22 +341,24 @@ namespace WfApi.Controllers
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteQuote([FromQuery] int idQuote)
{
try
{
var result = _quote.RemoveQuote(idQuote);
if (result.IsCompletedSuccessfully)
try {
try
{
return await Task.FromResult<IActionResult>(Ok(result));
_quote.RemoveQuote(idQuote).Wait();
return await Task.FromResult<IActionResult>(Ok());
}
else
catch (KeyNotFoundException e)
{
return NotFound();
return StatusCode((int)HttpStatusCode.NotFound, e);
}
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
return StatusCode((int) HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." });
}
}
}

Loading…
Cancel
Save