using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Nuuru.Server.Extensions; using Nuuru.Server.Services; namespace Nuuru.Server.Controllers { [ApiController] [Route("api/activity")] public class ActivityController : ControllerBase { private readonly IActivityService _activityService; private readonly ILogger _logger; public ActivityController(IActivityService activityService, ILogger logger) { _activityService = activityService; _logger = logger; } [HttpGet("comments")] [AllowAnonymous] public async Task GetRecentComments([FromQuery] int groupCount = 5, [FromQuery] int commentsPerGroup = 3) { try { groupCount = Math.Clamp(groupCount, 1, 10); commentsPerGroup = Math.Clamp(commentsPerGroup, 1, 5); var result = await _activityService.GetRecentCommentGroupsAsync(groupCount, commentsPerGroup); return Ok(result); } catch (Exception ex) { _logger.LogError(ex, "Error getting recent comments"); return StatusCode(500, new { error = "Failed to get recent comments" }); } } [HttpGet("forum-posts")] [AllowAnonymous] public async Task GetRecentForumPosts([FromQuery] int groupCount = 5, [FromQuery] int postsPerGroup = 3) { try { groupCount = Math.Clamp(groupCount, 1, 10); postsPerGroup = Math.Clamp(postsPerGroup, 1, 5); var result = await _activityService.GetRecentForumPostGroupsAsync(User.GetUserId(), groupCount, postsPerGroup); return Ok(result); } catch (Exception ex) { _logger.LogError(ex, "Error getting recent forum posts"); return StatusCode(500, new { error = "Failed to get recent forum posts" }); } } [HttpGet("forum-threads")] [AllowAnonymous] public async Task GetRecentForumThreads([FromQuery] int count = 10) { try { count = Math.Clamp(count, 1, 20); var result = await _activityService.GetRecentForumThreadsAsync(User.GetUserId(), count); return Ok(result); } catch (Exception ex) { _logger.LogError(ex, "Error getting recent forum threads"); return StatusCode(500, new { error = "Failed to get recent forum threads" }); } } [HttpGet("news-threads")] [AllowAnonymous] public async Task GetRecentNewsThreads([FromQuery] int count = 3) { try { count = Math.Clamp(count, 1, 10); var result = await _activityService.GetRecentNewsThreadsAsync(User.GetUserId(), count); return Ok(result); } catch (Exception ex) { _logger.LogError(ex, "Error getting recent news threads"); return StatusCode(500, new { error = "Failed to get recent news threads" }); } } } }