diff options
Diffstat (limited to 'BackEnd/Timeline')
3 files changed, 18 insertions, 4 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs b/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs index c2130b5a..2b31f43e 100644 --- a/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs +++ b/BackEnd/Timeline/Controllers/TimelineBookmarkV2Controller.cs @@ -32,7 +32,8 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] [HttpGet] - public async Task<ActionResult<Page<TimelineBookmark>>> ListAsync([FromRoute][Username] string username, [FromQuery] int? page, [FromQuery] int? pageSize) + public async Task<ActionResult<Page<TimelineBookmark>>> ListAsync([FromRoute][Username] string username, + [FromQuery][PositiveInteger] int? page, [FromQuery][PositiveInteger] int? pageSize) { var userId = await _userService.GetUserIdByUsernameAsync(username); if (!UserHasPermission(UserPermission.UserBookmarkManagement) && !await _timelineBookmarkService.CanReadBookmarksAsync(userId, GetOptionalAuthUserId())) @@ -47,7 +48,7 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] [HttpGet("{index}")] - public async Task<ActionResult<TimelineBookmark>> GetAsync([FromRoute][Username] string username, [FromRoute] int index) + public async Task<ActionResult<TimelineBookmark>> GetAsync([FromRoute][Username] string username, [FromRoute][PositiveInteger] int index) { var userId = await _userService.GetUserIdByUsernameAsync(username); if (!UserHasPermission(UserPermission.UserBookmarkManagement) && !await _timelineBookmarkService.CanReadBookmarksAsync(userId, GetOptionalAuthUserId())) diff --git a/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs b/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs index 435ffece..c80cda17 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs @@ -43,14 +43,15 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] - public async Task<ActionResult<Page<HttpTimelinePost>>> ListAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline, [FromQuery] DateTime? modifiedSince, [FromQuery][Range(0, int.MaxValue)] int? page, [FromQuery][Range(1, int.MaxValue)] int? numberPerPage) + public async Task<ActionResult<Page<HttpTimelinePost>>> ListAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline, [FromQuery] DateTime? modifiedSince, + [FromQuery][PositiveInteger] int? page, [FromQuery][PositiveInteger] int? pageSize) { var timelineId = await _timelineService.GetTimelineIdAsync(owner, timeline); if (!UserHasPermission(UserPermission.AllTimelineManagement) && !await _timelineService.HasReadPermissionAsync(timelineId, GetOptionalAuthUserId())) { return Forbid(); } - var postPage = await _postService.GetPostsV2Async(timelineId, modifiedSince, page, numberPerPage); + var postPage = await _postService.GetPostsV2Async(timelineId, modifiedSince, page, pageSize); var items = await _mapper.MapListAsync<HttpTimelinePost>(postPage.Items, Url, User); return postPage.WithItems(items); } diff --git a/BackEnd/Timeline/Models/Validation/PositiveIntegerAttribute.cs b/BackEnd/Timeline/Models/Validation/PositiveIntegerAttribute.cs new file mode 100644 index 00000000..78e2f0b4 --- /dev/null +++ b/BackEnd/Timeline/Models/Validation/PositiveIntegerAttribute.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; + +namespace Timeline.Models.Validation +{ + public class PositiveIntegerAttribute : RangeAttribute + { + public PositiveIntegerAttribute() : base(1, int.MaxValue) + { + } + } +} + |