Academatica.Api/Academatica.Api.Course/Controllers/CourseController.cs
/// <summary>
/// Endpoint used to get user activity for the authenticated user.
/// </summary>
/// <returns>User activity data.</returns>
Endpoint used to get user activity for the authenticated user.
Endpoint used to get user activity for the authenticated user .
[HttpGet]
        [Route("activity")]
        public IActionResult GetUserActivity()
        {
            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 activityMatrix = new Dictionary<DateTime, int>();
            var day = DateTime.Today;
            for (int diff = 0; diff < 365; diff++)
            {
                var completedClasses = _academaticaDbContext.UserClasses.Where(x => x.UserId.ToString() == userId && x.CompletedAt.Date == day.AddDays(-1 * diff).Date).Count();
                activityMatrix.Add(day.AddDays(-1 * diff).Date, completedClasses);
            }
            return Ok(new GetUserActivityResponseDto()
            {
                ActivityMatrix = activityMatrix
            });
        }
[ HttpGet ] [ Route ( " " ) ] public IActionResult GetUserActivity ( ) { 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 activityMatrix = new Dictionary < DateTime , int > ( ) ; var day = DateTime . Today ; for ( int diff = 0 ; diff < 365 ; diff ++ ) { var completedClasses = _academaticaDbContext . UserClasses . Where ( x => x . UserId . ToString ( ) == userId && x . CompletedAt . Date == day . AddDays ( - 1 * diff ) . Date ) . Count ( ) ; activityMatrix . Add ( day . AddDays ( - 1 * diff ) . Date , completedClasses ) ; } return Ok ( new GetUserActivityResponseDto ( ) { ActivityMatrix = activityMatrix } ) ; }
Endpoint used to get user activity for the authenticated user.
Endpoint used to get user activity for the authenticated user .
User activity data.
User activity data .