I, as either a self-learner who is learning on my own and gleaning inspiration from others or as a current student looking to mirror the same classes or study schedules as my friends, should be able to add either custom classes or pre-existing classes that have been made by other students to my schedule.
Acceptance Criteria
Endpoint URL: '/schedule/{id}/addClass'
Endpoint URL: '/schedule/{id}/removeClass'
WHEN I, the user, go through the class selection or deletion from a schedule process, an affordance should exist to allow me to either add or remove classes to my current schedule.
Dependencies
All setup tickets must be created before work can be done on this issue.
Dev Notes
Add Class/Remove Class DTO must be created
Add and Deleting M2M relationship, Rare
public static void Map(WebApplication app)
{
//add tag to post
app.MapPatch("/api/posts/{postId}/tag", (RareDbContext db, PostTagDto postTag) =>
{
Post post = db.Posts
.Include(p => p.Tags)
.SingleOrDefault(p => p.Id == postTag.Post_Id);
Tag tag = db.Tags
.SingleOrDefault(t => t.Id == postTag.Tag_Id);
if (post == null)
{
return Results.BadRequest("Invalid data submitted");
}
try
{
post.Tags.Add(tag);
db.SaveChanges();
return Results.Ok(postTag);
}
catch (ArgumentNullException)
{
return Results.BadRequest("Tag not found");
}
});
//remove tag from post
app.MapPatch("/api/posts/{postId}/remove", (RareDbContext db, PostTagDto postTag) =>
{
Post post = db.Posts
.Include(p => p.Tags)
.SingleOrDefault(p => p.Id == postTag.Post_Id);
if (post == null)
{
return Results.BadRequest("Invalid data submitted");
}
if (post.Tags.Count < 1)
{
return Results.BadRequest("No tags found");
}
Tag tagToRemove = post.Tags
.SingleOrDefault(t => t.Id == postTag.Tag_Id);
if (tagToRemove == null)
{
return Results.BadRequest("Tag not found");
}
post.Tags.Remove(tagToRemove);
db.SaveChanges();
return Results.Ok("tag removed");
});
User Story
I, as either a self-learner who is learning on my own and gleaning inspiration from others or as a current student looking to mirror the same classes or study schedules as my friends, should be able to add either custom classes or pre-existing classes that have been made by other students to my schedule.
Acceptance Criteria
Dependencies
Dev Notes
Add and Deleting M2M relationship, Rare