aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-08 17:39:07 +0800
committercrupest <crupest@outlook.com>2022-04-08 17:39:07 +0800
commit27e1360ffe4b2f5aa7d240e1de88c5459587b489 (patch)
tree29c7ebd95d0eb9896766f72930dbad3fa83db7c9 /BackEnd/Timeline/Controllers
parentcfc3f74d583d1c2eff634459d57a26647d212a5a (diff)
downloadtimeline-27e1360ffe4b2f5aa7d240e1de88c5459587b489.tar.gz
timeline-27e1360ffe4b2f5aa7d240e1de88c5459587b489.tar.bz2
timeline-27e1360ffe4b2f5aa7d240e1de88c5459587b489.zip
...
Diffstat (limited to 'BackEnd/Timeline/Controllers')
-rw-r--r--BackEnd/Timeline/Controllers/TimelineV2Controller.cs18
1 files changed, 11 insertions, 7 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelineV2Controller.cs b/BackEnd/Timeline/Controllers/TimelineV2Controller.cs
index c82fde2b..63beb357 100644
--- a/BackEnd/Timeline/Controllers/TimelineV2Controller.cs
+++ b/BackEnd/Timeline/Controllers/TimelineV2Controller.cs
@@ -2,6 +2,7 @@
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.Mapper;
@@ -16,23 +17,26 @@ namespace Timeline.Controllers
{
private ITimelineService _timelineService;
private IGenericMapper _mapper;
- private TimelineMapper _timelineMapper;
private IUserService _userService;
- public TimelineV2Controller(ITimelineService timelineService, IGenericMapper mapper, TimelineMapper timelineMapper, IUserService userService)
+ public TimelineV2Controller(ITimelineService timelineService, IGenericMapper mapper, IUserService userService)
{
_timelineService = timelineService;
_mapper = mapper;
- _timelineMapper = timelineMapper;
_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 _timelineMapper.MapAsync(t, Url, User);
+ return await MapAsync(t);
}
[HttpPatch("{owner}/{timeline}")]
@@ -51,7 +55,7 @@ namespace Timeline.Controllers
}
await _timelineService.ChangePropertyAsync(timelineId, _mapper.AutoMapperMap<TimelineChangePropertyParams>(body));
var t = await _timelineService.GetTimelineAsync(timelineId);
- return await _timelineMapper.MapAsync(t, Url, User);
+ return await MapAsync(t);
}
[HttpDelete("{owner}/{timeline}")]
@@ -123,8 +127,8 @@ namespace Timeline.Controllers
var authUserId = GetAuthUserId();
var authUser = await _userService.GetUserAsync(authUserId);
var timeline = await _timelineService.CreateTimelineAsync(authUserId, body.Name);
- var result = await _timelineMapper.MapAsync(timeline, Url, User);
- return CreatedAtAction(nameof(GetAsync), new { owner = authUser.Username, timeline = body.Name }, result);
+ var result = await MapAsync(timeline);
+ return CreatedAtAction("Get", new { owner = authUser.Username, timeline = body.Name }, result);
}
}
}