Academatica.Api/Academatica.Api.Course/Controllers/CourseController.cs
/// <summary>
/// Endpoind used to get completed topics for the authenticated user.
/// </summary>
/// <returns>Completed topics.</returns>
Endpoind used to get completed topics for the authenticated user.
Endpoind used to get completed topics for the authenticated user .
[HttpGet]
        [Route("topics/completed")]
        public IActionResult GetCompletedTopics()
        {
            var userId = User.FindFirst("sub")?.Value;
            if (string.IsNullOrEmpty(userId))
            {
                return BadRequest("User ID was null.");
            }
            var user = _academaticaDbContext.Users.Where(x => x.Id.ToString() == userId).FirstOrDefault();
            if (user == null)
            {
                return NotFound("Invalid user ID.");
            }
            var completedTopics = _academaticaDbContext.UserTopic.Where(x => x.UserId.ToString() == userId).Join(_academaticaDbContext.Topics, 
                ut => ut.TopicId,
                t => t.Id,
                (ut, t) => t).AsEnumerable();
            return Ok(new GetCompletedTopicsResponseDto()
            {
                Topics = completedTopics
            });
        }
[ HttpGet ] [ Route ( " " ) ] public IActionResult GetCompletedTopics ( ) { var userId = User . FindFirst ( " " ) ? . Value ; if ( string . IsNullOrEmpty ( userId ) ) { return BadRequest ( " " ) ; } var user = _academaticaDbContext . Users . Where ( x => x . Id . ToString ( ) == userId ) . FirstOrDefault ( ) ; if ( user == null ) { return NotFound ( " " ) ; } var completedTopics = _academaticaDbContext . UserTopic . Where ( x => x . UserId . ToString ( ) == userId ) . Join ( _academaticaDbContext . Topics , ut => ut . TopicId , t => t . Id , ( ut , t ) => t ) . AsEnumerable ( ) ; return Ok ( new GetCompletedTopicsResponseDto ( ) { Topics = completedTopics } ) ; }
Endpoind used to get completed topics for the authenticated user.
Endpoind used to get completed topics for the authenticated user .
None