fin route comment + debut Source

pull/6/head^2
Kevin MONDEJAR 3 weeks ago
parent 0d29cc0626
commit 6e1825f6ff

@ -38,20 +38,28 @@ namespace Contextlib
.Include(q => q.Commentarys) // collection des commentaires est chargée
.FirstOrDefaultAsync(q => q.Id == idQuote);
var dbU = new DbUsersManager(_context);
var User = await dbU.GetUserByUsername(comment.User.UserName);
if (User == null)
{
throw new ArgumentException("Quote not exist", nameof(comment.User.UserName));
}
if (quote == null)
{
throw new ArgumentException("Quote not exist", nameof(idQuote));
}
comment.User = User;
comment.IdUser = User.Id;
// Lien entre le commentaire et la citation
comment.Quote = quote;
comment.IdQuote = idQuote;
// Ajout commentaire à la collection des commentaires de la citation
quote.Commentarys.Add(comment);
_repo.Insert(comment);
// Ajout commentaire à la collection des commentaires de la citation
//_repo.Insert(comment);
_context.Add(comment);
await _context.SaveChangesAsync();
}
@ -163,7 +171,13 @@ namespace Contextlib
public async Task RemoveCommentary(int id)
{
_repo.Delete(id);
Commentary? commentary = await GetCommentaryById(id);
if (commentary == null)
{
throw new KeyNotFoundException($"Error : No comment found with the ID: {id}.");
}
_repo.Delete(commentary);
await _context.SaveChangesAsync();
}

@ -53,7 +53,7 @@ namespace Contextlib
.HasMany<Quote>()
.WithMany()
.UsingEntity<Commentary>(
i => i.HasKey(e => new { e.IdUser, e.IdQuote })
i => i.HasKey(e => e.Id)
);
modelBuilder.Entity<Commentary>()

@ -270,7 +270,9 @@ namespace Dto2Entities
commentary.Id = item.Id;
commentary.DateCommentary = item.Date;
commentary.Comment = item.Comment;
commentary.User = new Users();
commentary.User.UserName = item.User;
commentary.User.Images = new Images();
commentary.User.Images.ImgPath = item.ImagePath;
return commentary;
}

@ -42,7 +42,14 @@ namespace ServicesApi
public async Task<CommentaryDTO> GetCommentaryById(int id)
{
return commentaryService.GetCommentaryById(id).Result.ToDto();
try
{
return (await commentaryService.GetCommentaryById(id)).ToDto();
}
catch(KeyNotFoundException)
{
throw new KeyNotFoundException($"No comments found with the given ID: {id}.");
}
}
public async Task<PaginationResult<CommentaryDTO>> GetCommentaryByQuote(int quoteId, int index, int pageSize)

@ -36,9 +36,10 @@ 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 +52,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();
}

File diff suppressed because it is too large Load Diff

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class migr1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

File diff suppressed because it is too large Load Diff

@ -1,126 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class migr5 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsValid",
table: "question",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.CreateTable(
name: "admins",
columns: table => new
{
IdUsers = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_admins", x => x.IdUsers);
table.ForeignKey(
name: "FK_admins_users_UserId",
column: x => x.UserId,
principalTable: "users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 1,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 2,
column: "IsValid",
value: false);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 3,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 4,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 5,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 6,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 7,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 8,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 9,
column: "IsValid",
value: true);
migrationBuilder.UpdateData(
table: "question",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: true);
migrationBuilder.CreateIndex(
name: "IX_admins_UserId",
table: "admins",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "admins");
migrationBuilder.DropColumn(
name: "IsValid",
table: "question");
}
}
}

@ -1,61 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class suprDailyQuote : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "dailyquotes");
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "dailyquotes",
columns: table => new
{
IdQuote = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_dailyquotes", x => x.IdQuote);
table.ForeignKey(
name: "FK_dailyquotes_quotes_IdQuote",
column: x => x.IdQuote,
principalTable: "quotes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "dailyquotes",
column: "IdQuote",
values: new object[]
{
1,
5
});
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: true);
}
}
}

@ -1,32 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class myFirstMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: true);
}
}
}

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class migration204 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class migration1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

@ -12,8 +12,8 @@ using StubbedContextLib;
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubWTFContext))]
[Migration("20250402105029_migration1")]
partial class migration1
[Migration("20250402113707_pm_api")]
partial class pm_api
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)

@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class migrationTest1 : Migration
public partial class pm_api : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -37,7 +37,8 @@ namespace StubbedContextLib.Migrations
AnswerB = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
AnswerC = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
AnswerD = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
CorrectAnswer = table.Column<string>(type: "nvarchar(1)", maxLength: 1, nullable: false)
CorrectAnswer = table.Column<string>(type: "nvarchar(1)", maxLength: 1, nullable: false),
IsValid = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
@ -147,6 +148,25 @@ namespace StubbedContextLib.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "admins",
columns: table => new
{
IdUsers = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_admins", x => x.IdUsers);
table.ForeignKey(
name: "FK_admins_users_UserId",
column: x => x.UserId,
principalTable: "users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "quotes",
columns: table => new
@ -210,23 +230,6 @@ namespace StubbedContextLib.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "dailyquotes",
columns: table => new
{
IdQuote = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_dailyquotes", x => x.IdQuote);
table.ForeignKey(
name: "FK_dailyquotes_quotes_IdQuote",
column: x => x.IdQuote,
principalTable: "quotes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "favorites",
columns: table => new
@ -268,19 +271,19 @@ namespace StubbedContextLib.Migrations
migrationBuilder.InsertData(
table: "question",
columns: new[] { "Id", "AnswerA", "AnswerB", "AnswerC", "AnswerD", "CorrectAnswer", "Text" },
columns: new[] { "Id", "AnswerA", "AnswerB", "AnswerC", "AnswerD", "CorrectAnswer", "IsValid", "Text" },
values: new object[,]
{
{ 1, "Gimli", "Aragorn", "Frodon", "Gandalf", "B", "Qui est le leader de la Communauté de l'Anneau ?" },
{ 2, "Serdaigle", "Gryffondor", "Serpentard", "Poufsouffle", "B", "Dans quelle maison Harry Potter est-il ?" },
{ 3, "Saroumane", "Sauron", "Gollum", "Gothmog", "B", "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" },
{ 4, "Han Solo", "Princesse Leia", "Chewbacca", "R2-D2", "A", "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" },
{ 5, "Reine Jadis", "Aslan", "Edmund", "Lucy", "B", "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" },
{ 6, "Smaug", "Falkor", "Norbert", "Shenron", "A", "Quel est le nom du dragon dans Le Hobbit ?" },
{ 7, "Bella Swan", "Edward Cullen", "Jacob Black", "Victoria", "A", "Qui est la première personne à être mordue par un vampire dans Twilight ?" },
{ 8, "Obi-Wan Kenobi", "Yoda", "Han Solo", "Luke Skywalker", "A", "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" },
{ 9, "Dr. Ellie Sattler", "Alan Grant", "John Hammond", "Dennis Nedry", "B", "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" },
{ 10, "Cersei Lannister", "Arya Stark", "Daenerys Targaryen", "Sansa Stark", "C", "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" }
{ 1, "Gimli", "Aragorn", "Frodon", "Gandalf", "B", true, "Qui est le leader de la Communauté de l'Anneau ?" },
{ 2, "Serdaigle", "Gryffondor", "Serpentard", "Poufsouffle", "B", false, "Dans quelle maison Harry Potter est-il ?" },
{ 3, "Saroumane", "Sauron", "Gollum", "Gothmog", "B", true, "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" },
{ 4, "Han Solo", "Princesse Leia", "Chewbacca", "R2-D2", "A", true, "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" },
{ 5, "Reine Jadis", "Aslan", "Edmund", "Lucy", "B", true, "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" },
{ 6, "Smaug", "Falkor", "Norbert", "Shenron", "A", true, "Quel est le nom du dragon dans Le Hobbit ?" },
{ 7, "Bella Swan", "Edward Cullen", "Jacob Black", "Victoria", "A", true, "Qui est la première personne à être mordue par un vampire dans Twilight ?" },
{ 8, "Obi-Wan Kenobi", "Yoda", "Han Solo", "Luke Skywalker", "A", true, "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" },
{ 9, "Dr. Ellie Sattler", "Alan Grant", "John Hammond", "Dennis Nedry", "B", true, "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" },
{ 10, "Cersei Lannister", "Arya Stark", "Daenerys Targaryen", "Sansa Stark", "C", true, "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" }
});
migrationBuilder.InsertData(
@ -369,7 +372,7 @@ namespace StubbedContextLib.Migrations
{ 7, "Je suis la dernière Targaryen. Je suis la reine des dragons", 7, 3, 1, true, 1, 11025 },
{ 8, "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", 8, 5, 1, true, 1, 11025 },
{ 9, "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", 9, 5, 1, true, 1, 11025 },
{ 10, "La quoi ?", 10, 4, 1, true, 1, 11025 }
{ 10, "La quoi ?", 10, 4, 1, false, 1, 11025 }
});
migrationBuilder.InsertData(
@ -381,15 +384,6 @@ namespace StubbedContextLib.Migrations
{ 1, 3, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 2 }
});
migrationBuilder.InsertData(
table: "dailyquotes",
column: "IdQuote",
values: new object[]
{
1,
5
});
migrationBuilder.InsertData(
table: "favorites",
columns: new[] { "IdQuote", "IdUsers" },
@ -406,6 +400,11 @@ namespace StubbedContextLib.Migrations
{ 10, 5 }
});
migrationBuilder.CreateIndex(
name: "IX_admins_UserId",
table: "admins",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_characters_IdImage",
table: "characters",
@ -456,10 +455,10 @@ namespace StubbedContextLib.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "comments");
name: "admins");
migrationBuilder.DropTable(
name: "dailyquotes");
name: "comments");
migrationBuilder.DropTable(
name: "favorites");

@ -12,8 +12,8 @@ using StubbedContextLib;
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubWTFContext))]
[Migration("20250401141906_suprDailyQuote")]
partial class suprDailyQuote
[Migration("20250402134601_pm_apiV2")]
partial class pm_apiV2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -130,11 +130,11 @@ namespace StubbedContextLib.Migrations
modelBuilder.Entity("Entity.Commentary", b =>
{
b.Property<int>("IdUser")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("IdQuote")
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Comment")
.IsRequired()
@ -145,34 +145,36 @@ namespace StubbedContextLib.Migrations
.HasColumnType("date")
.HasColumnName("DateCommentary");
b.Property<int>("Id")
.ValueGeneratedOnAdd()
b.Property<int>("IdQuote")
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("IdUser")
.HasColumnType("int");
b.HasKey("IdUser", "IdQuote");
b.HasKey("Id");
b.HasIndex("IdQuote");
b.HasIndex("IdUser");
b.ToTable("comments");
b.HasData(
new
{
IdUser = 2,
IdQuote = 1,
Id = 1,
Comment = "Ce film est le meilleur",
DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified),
Id = 1
IdQuote = 1,
IdUser = 2
},
new
{
IdUser = 3,
IdQuote = 1,
Id = 2,
Comment = "Very good",
DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified),
Id = 2
IdQuote = 1,
IdUser = 3
});
});

@ -0,0 +1,86 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class pm_apiV2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_comments",
table: "comments");
migrationBuilder.DeleteData(
table: "comments",
keyColumns: new[] { "IdQuote", "IdUser" },
keyValues: new object[] { 1, 2 });
migrationBuilder.DeleteData(
table: "comments",
keyColumns: new[] { "IdQuote", "IdUser" },
keyValues: new object[] { 1, 3 });
migrationBuilder.AddPrimaryKey(
name: "PK_comments",
table: "comments",
column: "Id");
migrationBuilder.InsertData(
table: "comments",
columns: new[] { "Id", "Comment", "DateCommentary", "IdQuote", "IdUser" },
values: new object[,]
{
{ 1, "Ce film est le meilleur", new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 2 },
{ 2, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 3 }
});
migrationBuilder.CreateIndex(
name: "IX_comments_IdUser",
table: "comments",
column: "IdUser");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_comments",
table: "comments");
migrationBuilder.DropIndex(
name: "IX_comments_IdUser",
table: "comments");
migrationBuilder.DeleteData(
table: "comments",
keyColumn: "Id",
keyValue: 1);
migrationBuilder.DeleteData(
table: "comments",
keyColumn: "Id",
keyValue: 2);
migrationBuilder.AddPrimaryKey(
name: "PK_comments",
table: "comments",
columns: new[] { "IdUser", "IdQuote" });
migrationBuilder.InsertData(
table: "comments",
columns: new[] { "IdQuote", "IdUser", "Comment", "DateCommentary", "Id" },
values: new object[,]
{
{ 1, 2, "Ce film est le meilleur", new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), 1 },
{ 1, 3, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 2 }
});
}
}
}

@ -127,11 +127,11 @@ namespace StubbedContextLib.Migrations
modelBuilder.Entity("Entity.Commentary", b =>
{
b.Property<int>("IdUser")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("IdQuote")
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Comment")
.IsRequired()
@ -142,34 +142,36 @@ namespace StubbedContextLib.Migrations
.HasColumnType("date")
.HasColumnName("DateCommentary");
b.Property<int>("Id")
.ValueGeneratedOnAdd()
b.Property<int>("IdQuote")
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("IdUser")
.HasColumnType("int");
b.HasKey("IdUser", "IdQuote");
b.HasKey("Id");
b.HasIndex("IdQuote");
b.HasIndex("IdUser");
b.ToTable("comments");
b.HasData(
new
{
IdUser = 2,
IdQuote = 1,
Id = 1,
Comment = "Ce film est le meilleur",
DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified),
Id = 1
IdQuote = 1,
IdUser = 2
},
new
{
IdUser = 3,
IdQuote = 1,
Id = 2,
Comment = "Very good",
DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified),
Id = 2
IdQuote = 1,
IdUser = 3
});
});

@ -18,4 +18,8 @@
<ProjectReference Include="..\Entity\Entity.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

@ -57,15 +57,17 @@ namespace WfApi.Controllers
return BadRequest(new { message = "Comment data is required." });
}
var existingCommentary = _commentary.GetCommentaryById(newCommentary.Id).Result;
if (existingCommentary != null)
try
{
var existingCommentary = await _commentary.GetCommentaryById(newCommentary.Id);
return Conflict(new { message = "A comment with this ID already exists." });
}
catch (KeyNotFoundException e)
{
await _commentary.AddComment(newCommentary, idQuote);
await _commentary.AddComment(newCommentary, idQuote);
return CreatedAtAction(nameof(GetCommentary), new { id = newCommentary.Id }, newCommentary);
return CreatedAtAction(nameof(GetCommentary), new { id = newCommentary.Id }, newCommentary);
}
}
catch (Exception)
{
@ -89,7 +91,7 @@ namespace WfApi.Controllers
return NotFound(new { message = "Commentary not found." });
}
_commentary.RemoveCommentary(existingCommentary.Id);
await _commentary.RemoveCommentary(existingCommentary.Id);
return Ok(new { message = $"Commentary {id} deleted successfully." });
}

@ -33,13 +33,9 @@ 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));
return Ok(result);
}
else
{

@ -0,0 +1,84 @@
using System.Net;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Shared;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace WfApi.Controllers
{
[Route("api/v1/source")]
[ApiController]
public class SourceController : ControllerBase
{
private readonly ISourceService<SourceDTO> _source;
private readonly ILogger<SourceController> _logger;
public SourceController(ISourceService<SourceDTO> sourceService, ILogger<SourceController> logger)
{
_source = sourceService;
_logger = logger;
}
[HttpGet("{id}")] // Indiquer que l'id est dans l'URL
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetSource(int id)
{
try
{
var source = await _source.GetSourceById(id);
if(source != null)
{
return Ok(source);
}
else
{
return NoContent();
}
}
catch(Exception e)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" });
}
}
[HttpGet("all")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetAllSource(int index = 0, int count = 10)
{
}
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> CreateSource([FromBody] SourceDTO newSource)
{
}
[HttpPut()]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> UpdateSource([FromQuery] int id, [FromBody] SourceDTO updatedSource)
{
}
[HttpDelete("delete")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> DeleteSource([FromQuery] int idSource)
{
}
}
}
Loading…
Cancel
Save