From 16dc8a073e0be9e6523e62397d5e8837323cfbd0 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 22 Sep 2025 11:09:21 +0200 Subject: [PATCH 1/2] Fixed request URL path --- exercise.wwwapi/Endpoints/CohortEndpoints.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercise.wwwapi/Endpoints/CohortEndpoints.cs b/exercise.wwwapi/Endpoints/CohortEndpoints.cs index 5130962..8405b1b 100644 --- a/exercise.wwwapi/Endpoints/CohortEndpoints.cs +++ b/exercise.wwwapi/Endpoints/CohortEndpoints.cs @@ -17,10 +17,10 @@ public static void ConfigureCohortEndpoints(this WebApplication app) var cohorts = app.MapGroup("cohorts"); cohorts.MapPost("/", CreateCohort).WithSummary("Create a cohort"); cohorts.MapGet("/", GetAllCohorts).WithSummary("Get all cohorts"); - cohorts.MapGet("/{id}", GetCohort).WithSummary("Get a cohort by ID"); + cohorts.MapGet("/cohortId/{cohortId}", GetCohort).WithSummary("Get a cohort by ID"); //cohorts.MapGet("/{userId}", GetCohortByUserId).WithSummary(""); - cohorts.MapPost("/{cohortId}/{userId}/{courseId}", AddUserToCohort).WithSummary("Add a user to a cohort"); - cohorts.MapDelete("/{cohortId}/{userId}/{courseId}", DeleteUserFromCohort).WithSummary("Delete a user from a cohort"); + cohorts.MapPost("/cohortId/{cohortId}/userId/{userId}/courseId/{courseId}", AddUserToCohort).WithSummary("Add a user to a cohort"); + cohorts.MapDelete("/cohortId/{cohortId}/userId/{userId}/courseId/{courseId}", DeleteUserFromCohort).WithSummary("Delete a user from a cohort"); } [ProducesResponseType(StatusCodes.Status200OK)] From 79981cade8086c974a25ea2f91495bca1208e284 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 22 Sep 2025 11:23:07 +0200 Subject: [PATCH 2/2] Added course Id to the response --- exercise.wwwapi/DTOs/Cohort/CourseInCohortDTO.cs | 2 ++ exercise.wwwapi/Tools/MappingProfile.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/exercise.wwwapi/DTOs/Cohort/CourseInCohortDTO.cs b/exercise.wwwapi/DTOs/Cohort/CourseInCohortDTO.cs index 7774b1b..e975129 100644 --- a/exercise.wwwapi/DTOs/Cohort/CourseInCohortDTO.cs +++ b/exercise.wwwapi/DTOs/Cohort/CourseInCohortDTO.cs @@ -5,6 +5,8 @@ namespace exercise.wwwapi.DTOs.Cohort public class CourseInCohortDTO { public string Title { get; set; } + public int Id { get; set; } + public ICollection Students { get; set; } = new List(); public ICollection Teachers { get; set; } = new List(); //public ICollection Students { get; set; } = new List(); diff --git a/exercise.wwwapi/Tools/MappingProfile.cs b/exercise.wwwapi/Tools/MappingProfile.cs index ecdc12e..ede4bcb 100644 --- a/exercise.wwwapi/Tools/MappingProfile.cs +++ b/exercise.wwwapi/Tools/MappingProfile.cs @@ -23,6 +23,7 @@ public MappingProfile() .ForMember(dest => dest.Cohort, opt => opt.MapFrom(src => src.Cohort.Title)); CreateMap() + .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.CourseId)) .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Course.Title)) .ForMember(dest => dest.Students, opt => opt.MapFrom( src => src.CohortCourseUsers