fininalisation Route Quote
continuous-integration/drone/push Build is failing Details

pull/6/head
kekentin 3 weeks ago
parent 0d29cc0626
commit a263050ab6

@ -68,15 +68,10 @@ namespace Contextlib
/// <param name="name">The name of the character to retrieve.</param>
/// <returns>A task that represents the asynchronous operation, with a <see cref="Character"/> as its result.</returns>
/// <exception cref="KeyNotFoundException">Thrown when no character is found with the given name.</exception>
public async Task<Character> GetCharByName(string name)
public async Task<Character?> GetCharByName(string name)
{
var character = _repo.GetItems(item => item.Name == name,0,1, [nameof(Character.Images)]).FirstOrDefault();
if (character == null)
{
throw new KeyNotFoundException($"Error : No character found with the name: {name}.");
}
return character;
}

@ -33,7 +33,7 @@ namespace Contextlib
return new PaginationResult<Images>(await CountImage(), 0, await CountImage(), _repository.GetItems(0, await CountImage()).ToList());
}
public async Task<Images> GetImageById(int id)
public async Task<Images?> GetImageById(int id)
{
return _repository.GetById(id);
}

@ -31,24 +31,37 @@ namespace Contextlib
}
public async Task AddQuote(Quote quote)
public async Task<Quote> AddQuote(Quote quote)
{
if (quote == null)
{
throw new ArgumentNullException(nameof(quote), "quote cannot be null.");
}
//Character
var c = await _dbC.GetCharByName(quote.Character.Name);
if (c != null)
{
quote.IdCharacter = c.Id;
quote.Character = c;
}
//Image
var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath);
if (i != null)
{
quote.Character.IdImage = i.Id;
quote.Character.Images = i;
}
//Source
var s = await _dbS.GetSourceByTitle(quote.Source.Title);
if (s != null)
{
quote.IdSource = s.Id;
quote.Source = s;
}
_repo.Insert(quote);
await _context.SaveChangesAsync();
return quote;
}
public async Task<PaginationResult<Quote>> GetAllQuote()
@ -197,6 +210,28 @@ namespace Contextlib
public async Task UpdateQuote(int quoteId, Quote quote)
{
//Character
var c = await _dbC.GetCharByName(quote.Character.Name);
if (c != null)
{
quote.IdCharacter = c.Id;
quote.Character = c;
}
//Image
var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath);
if (c != null)
{
quote.Character.IdImage = i.Id;
quote.Character.Images = i;
}
//Source
var s = await _dbS.GetSourceByTitle(quote.Source.Title);
if (c != null)
{
quote.IdSource = s.Id;
quote.Source = s;
}
Quote? q = _repo.GetById(quoteId);
if (q != null)
{

@ -58,27 +58,17 @@ namespace Contextlib
return source;
}
public async Task<Source> GetSourceByTitle(string title)
public async Task<Source?> GetSourceByTitle(string title)
{
var source = _repo.GetItems(item => item.Title == title, 0, 1, []).FirstOrDefault();
if (source == null)
{
throw new KeyNotFoundException($"Error : No source found with the title: {title}.");
}
return source;
}
public async Task<Source> GetSourceByType(int type)
public async Task<Source?> GetSourceByType(int type)
{
var source = _repo.GetItems(item => item.TypeSrc == (TypeSrcEnum)type, 0, 1, []).FirstOrDefault();
if (source == null)
{
throw new KeyNotFoundException($"Error : No source found with the type: {(TypeSrcEnum)type}.");
}
return source;
}

@ -20,9 +20,9 @@ namespace ServicesApi
quoteService = quote;
}
public async Task AddQuote(QuoteDTO quote)
public async Task<QuoteDTO> AddQuote(QuoteDTO quote)
{
await quoteService.AddQuote(quote.ToEntity());
return (await quoteService.AddQuote(quote.ToEntity())).ToDto();
}
public async Task<PaginationResult<QuoteDTO>> GetAllQuote()

@ -36,9 +36,11 @@ namespace ServicesApi
return await srcService.GetLastSourceId();
}
public async Task<SourceDTO> GetSourceByDate(string date)
public async Task<PaginationResult<SourceDTO>> GetSourceByDate(int date)
{
return srcService.GetSourceByDate(date).Result.ToDto();
var sources = ( await srcService.GetSourceByDate(date)).items;
return new PaginationResult<SourceDTO>(sources.Count(), 0, 10, sources.ToDto());
}
public async Task<SourceDTO> GetSourceById(int id)
@ -51,7 +53,7 @@ namespace ServicesApi
return srcService.GetSourceByTitle(title).Result.ToDto();
}
public async Task<SourceDTO> GetSourceByType(string type)
public async Task<SourceDTO> GetSourceByType(int type)
{
return srcService.GetSourceByType(type).Result.ToDto();
}

@ -76,7 +76,7 @@ namespace Shared
// Adds a new quote.
// 'quote' is the quote object that will be added.
Task AddQuote(TQuote quote);
Task<TQuote> AddQuote(TQuote quote);
// Updates an existing quote identified by 'quoteId' with new details.
// 'quoteId' is the ID of the quote to be updated

@ -39,9 +39,10 @@ namespace StubApi
};
}
public async Task AddQuote(QuoteDTO quote)
public async Task<QuoteDTO> AddQuote(QuoteDTO quote)
{
_quotes.Add(quote);
return quote;
}
public async Task<PaginationResult<QuoteDTO>> GetAllQuote()

@ -272,7 +272,7 @@ namespace WfApi.Controllers
return Conflict(new { message = "Une quote avec cet ID existe déjà." });
}
newQuote.IsValide=false;
var quote=_quote.AddQuote(newQuote);
var quote=await _quote.AddQuote(newQuote);
return CreatedAtAction(nameof(CreateQuote), new { id = newQuote.Id }, quote);
}

@ -268,7 +268,7 @@ namespace XUnitTest
_mockUserService.Setup(service => service.GetUserById(id)).ReturnsAsync(existingPlayer);
_mockUserService.Setup(service => service.RemoveUser(existingPlayer)).Verifiable();
_mockUserService.Setup(service => service.RemoveUser(existingPlayer.Id)).Verifiable();
// Act
var result = await _userController.DeletePlayer(id);

Loading…
Cancel
Save