diff --git a/API/API.Client.Test/App.config b/API/API.Client.Test/App.config
index ff78c45..190af5a 100644
--- a/API/API.Client.Test/App.config
+++ b/API/API.Client.Test/App.config
@@ -1,39 +1,24 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/API/API.Client.Test/OdataTests.cs b/API/API.Client.Test/OdataTests.cs
index 4e4a95f..0aef2f9 100644
--- a/API/API.Client.Test/OdataTests.cs
+++ b/API/API.Client.Test/OdataTests.cs
@@ -1,10 +1,11 @@
-using System;
+using API.Models;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Simple.OData.Client;
+using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
-using API.Models;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Simple.OData.Client;
+using File = System.IO.File;
namespace API.Client.Test {
[TestClass]
@@ -12,7 +13,7 @@ namespace API.Client.Test {
private const string TEST_CASE_IDENTIFIER = "TESTCASE";
private static Song testSong;
-
+
[ClassInitialize]
public static async Task TestInitialize(TestContext tc) {
@@ -39,7 +40,7 @@ namespace API.Client.Test {
var client = new Client();
var data = await client.Get();
- Assert.IsTrue(data.Any(_=>_.ID == testSong.ID));
+ Assert.IsTrue(data.Any(_ => _.ID == testSong.ID));
}
[TestMethod]
@@ -64,6 +65,29 @@ namespace API.Client.Test {
Assert.AreEqual(newSong.Name, insertedSong.Name);
}
+ [TestMethod]
+ public async Task PatchItem() {
+ var client = new Client();
+ var newSong = new Song {
+ Name = Guid.NewGuid().ToString(),
+ Text = TEST_CASE_IDENTIFIER,
+ Comments = "Item to Patch"
+ };
+
+ var response = await client.Post(newSong);
+ try {
+ var patchedSong = await client.Patch(response.ID, new { Comments = "patched" });
+ } catch (WebRequestException ex) {
+ File.WriteAllText("error.html", ex.Response);
+ throw;
+ }
+ var insertedSong = await client.Get(response.ID);
+
+ Assert.AreEqual("patched", insertedSong.Comments);
+ Assert.AreEqual(newSong.Name, insertedSong.Name);
+ Assert.AreEqual(TEST_CASE_IDENTIFIER, insertedSong.Text);
+ }
+
[TestMethod]
public async Task DeleteItem() {
var client = new Client();
@@ -75,9 +99,14 @@ namespace API.Client.Test {
var response = await client.Post(newSong);
var insertedSong = await client.Get(response.ID);
Assert.AreEqual(newSong.Name, insertedSong.Name);
+ try {
- var count = await client.Delete(response.ID);
- Assert.AreEqual(1, count);
+ var count = await client.Delete(response.ID);
+ Assert.AreEqual(1, count);
+ } catch (WebRequestException ex) {
+ File.WriteAllText("error.html", ex.Response);
+ throw;
+ }
try {
await client.Get(response.ID);
diff --git a/API/API.Client/Client.cs b/API/API.Client/Client.cs
index aacd004..5cba7ae 100644
--- a/API/API.Client/Client.cs
+++ b/API/API.Client/Client.cs
@@ -35,6 +35,12 @@ namespace API.Client {
return insertedSong;
}
+ public async Task Patch(long id, object value) {
+ var client = new ODataClient(url).For().Key(id);
+ var insertedSong = await client.Set(value).UpdateEntryAsync();
+ return insertedSong;
+ }
+
public async Task Delete(long id) {
var client = new ODataClient(url).For();
var count = await client.Key(id).DeleteEntriesAsync();
diff --git a/API/API/API.csproj b/API/API/API.csproj
index 8850c31..7bc5bac 100644
--- a/API/API/API.csproj
+++ b/API/API/API.csproj
@@ -179,7 +179,6 @@
-
@@ -194,7 +193,9 @@
201903172028249_Log.cs
-
+
+
+
10.0
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
diff --git a/API/API/Controllers/FilesController.cs b/API/API/Controllers/FilesController.cs
index 1e809cd..d5436d0 100644
--- a/API/API/Controllers/FilesController.cs
+++ b/API/API/Controllers/FilesController.cs
@@ -1,4 +1,5 @@
using API.Database;
+using API.Models;
using API.Services;
using System.Net;
using System.Net.Http;
@@ -27,22 +28,18 @@ namespace API.Controllers {
}
// GET: api/Files/5
- [Route("api/songs/{songId}/files/{fileId}")]
- public HttpResponseMessage Get(long songId, long fileId) {
+ [Route("api/songs/{songId}/files/{fileId}", Order = 1)]
+ public async Task Get(long songId, long fileId) {
var response = new HttpResponseMessage(HttpStatusCode.OK);
fileGarbageCollectionService.Collect(dataPath);
- var file = dataContext.Files.Find(fileId);
+ var file = await dataContext.Files.FindAsync(fileId);
if (file == null || file.Song.ID != songId) return new HttpResponseMessage(HttpStatusCode.NotFound);
var reference = file.ReferenceFile;
- var filename = file.Name;
var stream = fileService.Load(dataPath, reference.ToString());
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
- response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") {
- FileName = filename
- };
return response;
}
@@ -65,7 +62,7 @@ namespace API.Controllers {
var filename = await fileService.Save(stream, dataPath, c);
// attach file reference to song
- song.Files.Add(new Models.File {
+ song.Files.Add(new File {
Name = file.FileName,
ReferenceFile = filename
});
@@ -74,9 +71,29 @@ namespace API.Controllers {
return new HttpResponseMessage(HttpStatusCode.OK);
}
+ [Route("api/songs/{songId}/files/{fileId}/edit"), HttpGet]
+ public async Task Edit(long songId, long fileId, string Name, FileType FileType, CancellationToken c) {
+ var file = await dataContext.Files.FindAsync(fileId);
+ if (file == null || file.Song.ID != songId) return new HttpResponseMessage(HttpStatusCode.NotFound);
+ file.Name = Name;
+ file.FileType = FileType;
+ await dataContext.SaveChangesAsync();
+ return new HttpResponseMessage(HttpStatusCode.OK);
+ }
+ [Route("api/songs/{songId}/files/{fileId}/delete"), HttpGet]
+ public async Task Delete(long songId, long fileId, CancellationToken c) {
+ var file = await dataContext.Files.FindAsync(fileId);
+ if (file == null || file.Song.ID != songId) return new HttpResponseMessage(HttpStatusCode.NotFound);
+
+ dataContext.Files.Remove(file);
+ await dataContext.SaveChangesAsync();
+ fileGarbageCollectionService.Collect(dataPath);
+
+ return new HttpResponseMessage(HttpStatusCode.OK);
+ }
//// PUT: api/Files/5
diff --git a/API/API/Web.config b/API/API/Web.config
index 0b6a427..3c45620 100644
--- a/API/API/Web.config
+++ b/API/API/Web.config
@@ -30,8 +30,15 @@
-
+
+
+
+
+
+
+
+
diff --git a/API/Migration/App.config b/API/Migration/App.config
index 36ae0e8..190af5a 100644
--- a/API/Migration/App.config
+++ b/API/Migration/App.config
@@ -6,34 +6,19 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file