|
@@ -15,20 +15,17 @@ public class TracksController : ControllerBase
|
|
|
{
|
|
{
|
|
|
private readonly IFileStorage _fileStorage;
|
|
private readonly IFileStorage _fileStorage;
|
|
|
private readonly GpxParser _gpxParser;
|
|
private readonly GpxParser _gpxParser;
|
|
|
- private readonly QueryFactory _queryFactory;
|
|
|
|
|
private readonly IRequestRouter _requestRouter;
|
|
private readonly IRequestRouter _requestRouter;
|
|
|
private readonly ApiSettings _settings;
|
|
private readonly ApiSettings _settings;
|
|
|
|
|
|
|
|
public TracksController(
|
|
public TracksController(
|
|
|
IFileStorage fileStorage,
|
|
IFileStorage fileStorage,
|
|
|
GpxParser gpxParser,
|
|
GpxParser gpxParser,
|
|
|
- QueryFactory queryFactory,
|
|
|
|
|
IOptions<ApiSettings> apiOptions,
|
|
IOptions<ApiSettings> apiOptions,
|
|
|
IRequestRouter requestRouter)
|
|
IRequestRouter requestRouter)
|
|
|
{
|
|
{
|
|
|
_fileStorage = fileStorage;
|
|
_fileStorage = fileStorage;
|
|
|
_gpxParser = gpxParser;
|
|
_gpxParser = gpxParser;
|
|
|
- _queryFactory = queryFactory;
|
|
|
|
|
_requestRouter = requestRouter;
|
|
_requestRouter = requestRouter;
|
|
|
_settings = apiOptions.Value;
|
|
_settings = apiOptions.Value;
|
|
|
}
|
|
}
|
|
@@ -62,8 +59,12 @@ public class TracksController : ControllerBase
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
var gpxSummary = _gpxParser.ExtractSummary(_fileStorage.OpenFileRead(fileName));
|
|
var gpxSummary = _gpxParser.ExtractSummary(_fileStorage.OpenFileRead(fileName));
|
|
|
- var user = _queryFactory.GetUserQuery().Get(ApiUser.Current.UserId);
|
|
|
|
|
- var track = _queryFactory.CreateTrackCommand().Create(user, fileName, gpxSummary);
|
|
|
|
|
|
|
+ var user = _requestRouter.For(ApiUser.Current.UserId).Process<UserProfile>();
|
|
|
|
|
+
|
|
|
|
|
+ var track = _requestRouter
|
|
|
|
|
+ .For(new CreateTrackRequest(user, fileName, gpxSummary))
|
|
|
|
|
+ .Process<Track>();
|
|
|
|
|
+
|
|
|
return Ok(track);
|
|
return Ok(track);
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -76,7 +77,7 @@ public class TracksController : ControllerBase
|
|
|
[HttpGet("{id}")]
|
|
[HttpGet("{id}")]
|
|
|
public ActionResult<Track> GetTrack(string id)
|
|
public ActionResult<Track> GetTrack(string id)
|
|
|
{
|
|
{
|
|
|
- var track = _queryFactory.TrackQuery().Get(new ObjectId(id));
|
|
|
|
|
|
|
+ var track = _requestRouter.For(new ObjectId(id)).Process<Track>();
|
|
|
|
|
|
|
|
return Ok(track);
|
|
return Ok(track);
|
|
|
}
|
|
}
|
|
@@ -88,7 +89,8 @@ public class TracksController : ControllerBase
|
|
|
{
|
|
{
|
|
|
throw new ArgumentException("Object ID in URL does not match track ID");
|
|
throw new ArgumentException("Object ID in URL does not match track ID");
|
|
|
}
|
|
}
|
|
|
- var result = _queryFactory.UpdateTrackCommand().Update(ApiUser.Current.UserId, track);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var result = _requestRouter.For(new TrackUpdate(ApiUser.Current.UserId, track)).Process<Track>();
|
|
|
|
|
|
|
|
return Ok(result);
|
|
return Ok(result);
|
|
|
}
|
|
}
|
|
@@ -96,7 +98,10 @@ public class TracksController : ControllerBase
|
|
|
[HttpDelete("{id}")]
|
|
[HttpDelete("{id}")]
|
|
|
public ActionResult DeleteTrack(string id)
|
|
public ActionResult DeleteTrack(string id)
|
|
|
{
|
|
{
|
|
|
- var fileName = _queryFactory.DeleteTrackCommand().Delete(ApiUser.Current.UserId, new ObjectId(id));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var fileName = _requestRouter
|
|
|
|
|
+ .For(new TrackReference(ApiUser.Current.UserId, new ObjectId(id)))
|
|
|
|
|
+ .Process<FileName>();
|
|
|
_fileStorage.DeleteFile(fileName);
|
|
_fileStorage.DeleteFile(fileName);
|
|
|
|
|
|
|
|
return Ok();
|
|
return Ok();
|
|
@@ -106,7 +111,7 @@ public class TracksController : ControllerBase
|
|
|
[AllowAnonymous]
|
|
[AllowAnonymous]
|
|
|
public ActionResult DownloadGpx(string hash)
|
|
public ActionResult DownloadGpx(string hash)
|
|
|
{
|
|
{
|
|
|
- var track = _queryFactory.TrackQuery().GetByFileHash(hash);
|
|
|
|
|
|
|
+ var track = _requestRouter.For(hash).Process<Track>();
|
|
|
return _fileStorage.FileDownload(track);
|
|
return _fileStorage.FileDownload(track);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|