aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers/TimelineV2Controller.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-12 18:07:17 +0800
committercrupest <crupest@outlook.com>2022-04-12 18:07:17 +0800
commitbdcbe0612ae3e4e173754c5e663e2668e9f380ec (patch)
treec8f2b703302b0fed91925962a1695c2394bf345a /BackEnd/Timeline/Controllers/TimelineV2Controller.cs
parent3fc0cd57711b41e3a65e24e30ceaa3f95d7d4415 (diff)
downloadtimeline-bdcbe0612ae3e4e173754c5e663e2668e9f380ec.tar.gz
timeline-bdcbe0612ae3e4e173754c5e663e2668e9f380ec.tar.bz2
timeline-bdcbe0612ae3e4e173754c5e663e2668e9f380ec.zip
...
Diffstat (limited to 'BackEnd/Timeline/Controllers/TimelineV2Controller.cs')
-rw-r--r--BackEnd/Timeline/Controllers/TimelineV2Controller.cs152
1 files changed, 0 insertions, 152 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelineV2Controller.cs b/BackEnd/Timeline/Controllers/TimelineV2Controller.cs
deleted file mode 100644
index 9811cbed..00000000
--- a/BackEnd/Timeline/Controllers/TimelineV2Controller.cs
+++ /dev/null
@@ -1,152 +0,0 @@
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using Timeline.Entities;
-using Timeline.Models.Http;
-using Timeline.Models.Validation;
-using Timeline.Services;
-using Timeline.Services.Mapper;
-using Timeline.Services.Timeline;
-using Timeline.Services.User;
-
-namespace Timeline.Controllers
-{
- [ApiController]
- [Route("v2/timelines")]
- public class TimelineV2Controller : MyControllerBase
- {
- private ITimelineService _timelineService;
- private IGenericMapper _mapper;
- private IUserService _userService;
-
- public TimelineV2Controller(ITimelineService timelineService, IGenericMapper mapper, IUserService userService)
- {
- _timelineService = timelineService;
- _mapper = mapper;
- _userService = userService;
- }
-
- private Task<HttpTimeline> MapAsync(TimelineEntity entity)
- {
- return _mapper.MapAsync<HttpTimeline>(entity, Url, User);
- }
-
- [HttpGet("{owner}/{timeline}")]
- public async Task<ActionResult<HttpTimeline>> GetAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline)
- {
- var timelineId = await _timelineService.GetTimelineIdAsync(owner, timeline);
- var t = await _timelineService.GetTimelineAsync(timelineId);
- return await MapAsync(t);
- }
-
- [HttpPatch("{owner}/{timeline}")]
- [Authorize]
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status401Unauthorized)]
- [ProducesResponseType(StatusCodes.Status403Forbidden)]
- [ProducesResponseType(StatusCodes.Status404NotFound)]
- [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
- public async Task<ActionResult<HttpTimeline>> PatchAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline, [FromBody] HttpTimelinePatchRequest body)
- {
- var timelineId = await _timelineService.GetTimelineIdAsync(owner, timeline);
- if (!UserHasPermission(UserPermission.AllTimelineManagement) && !await _timelineService.HasManagePermissionAsync(timelineId, GetAuthUserId()))
- {
- return Forbid();
- }
- await _timelineService.ChangePropertyAsync(timelineId, _mapper.AutoMapperMap<TimelineChangePropertyParams>(body));
- var t = await _timelineService.GetTimelineAsync(timelineId);
- return await MapAsync(t);
- }
-
- [HttpDelete("{owner}/{timeline}")]
- [Authorize]
- [ProducesResponseType(StatusCodes.Status204NoContent)]
- [ProducesResponseType(StatusCodes.Status401Unauthorized)]
- [ProducesResponseType(StatusCodes.Status403Forbidden)]
- [ProducesResponseType(StatusCodes.Status404NotFound)]
- [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
- public async Task<ActionResult> DeleteAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline)
- {
- var timelineId = await _timelineService.GetTimelineIdAsync(owner, timeline);
- if (!UserHasPermission(UserPermission.AllTimelineManagement) && !await _timelineService.HasManagePermissionAsync(timelineId, GetAuthUserId()))
- {
- return Forbid();
- }
- await _timelineService.DeleteTimelineAsync(timelineId);
- return NoContent();
- }
-
- [HttpPut("{owner}/{timeline}/members/{member}")]
- [Authorize]
- [ProducesResponseType(StatusCodes.Status204NoContent)]
- [ProducesResponseType(StatusCodes.Status401Unauthorized)]
- [ProducesResponseType(StatusCodes.Status403Forbidden)]
- [ProducesResponseType(StatusCodes.Status404NotFound)]
- [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
- public async Task<ActionResult> MemberPutAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline, [FromRoute][Username] string member)
- {
- var timelineId = await _timelineService.GetTimelineIdAsync(owner, timeline);
- if (!UserHasPermission(UserPermission.AllTimelineManagement) && !await _timelineService.HasManagePermissionAsync(timelineId, GetAuthUserId()))
- {
- return Forbid();
- }
-
- long userId;
- try
- {
- userId = await _userService.GetUserIdByUsernameAsync(member);
- }
- catch (EntityNotExistException e) when (e.EntityType.Equals(EntityTypes.User))
- {
- return UnprocessableEntity(new CommonResponse(ErrorCodes.Common.InvalidModel, "Member username does not exist."));
- }
- await _timelineService.AddMemberAsync(timelineId, userId);
- return NoContent();
- }
-
- [HttpDelete("{owner}/{timeline}/members/{member}")]
- [Authorize]
- [ProducesResponseType(StatusCodes.Status204NoContent)]
- [ProducesResponseType(StatusCodes.Status401Unauthorized)]
- [ProducesResponseType(StatusCodes.Status403Forbidden)]
- [ProducesResponseType(StatusCodes.Status404NotFound)]
- [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
- public async Task<ActionResult> MemberDeleteAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline, [FromRoute][Username] string member)
- {
- var timelineId = await _timelineService.GetTimelineIdAsync(owner, timeline);
- if (!UserHasPermission(UserPermission.AllTimelineManagement) && !await _timelineService.HasManagePermissionAsync(timelineId, GetAuthUserId()))
- {
- return Forbid();
- }
-
- long userId;
- try
- {
- userId = await _userService.GetUserIdByUsernameAsync(member);
- }
- catch (EntityNotExistException e) when (e.EntityType.Equals(EntityTypes.User))
- {
- return UnprocessableEntity(new CommonResponse(ErrorCodes.Common.InvalidModel, "Member username does not exist."));
- }
- await _timelineService.RemoveMemberAsync(timelineId, userId);
- return NoContent();
- }
-
- [HttpPost]
- [Authorize]
- [ProducesResponseType(StatusCodes.Status201Created)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [ProducesResponseType(StatusCodes.Status401Unauthorized)]
- [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
- public async Task<ActionResult<HttpTimeline>> TimelineCreate([FromBody] HttpTimelineCreateRequest body)
- {
- var authUserId = GetAuthUserId();
- var authUser = await _userService.GetUserAsync(authUserId);
- var timeline = await _timelineService.CreateTimelineAsync(authUserId, body.Name);
- var result = await MapAsync(timeline);
- return CreatedAtAction("Get", new { owner = authUser.Username, timeline = body.Name }, result);
- }
- }
-}
-