Compare commits

..

No commits in common. "ce4e5848dbc7dd5624083c763f50944e5bbab674" and "3d0d9faf12052a22f4ba32d2632e1ddad6c817e8" have entirely different histories.

3 changed files with 14 additions and 18 deletions

View File

@ -17,7 +17,7 @@ public class StreetController : ControllerBase
public async Task<IActionResult> CreateStreet([FromBody] CreateStreetDTO dto)
{
if (dto == null)
return BadRequest();
return BadRequest("Invalid request body.");
try
{
@ -28,9 +28,9 @@ public class StreetController : ControllerBase
return Created();
}
catch
catch (InvalidOperationException ex)
{
return Conflict();
return Conflict(ex);
}
}
@ -43,9 +43,9 @@ public class StreetController : ControllerBase
var street = await StreetService.GetStreetAsync(streetname);
return Ok(street);
}
catch
catch (KeyNotFoundException ex)
{
return NotFound();
return NotFound(ex);
}
}
@ -55,7 +55,7 @@ public class StreetController : ControllerBase
{
var deleted = await StreetService.DeleteStreetAsync(streetname);
if (!deleted)
return NotFound();
return NotFound($"Street '{streetname}' not found.");
return NoContent();
}
@ -65,24 +65,24 @@ public class StreetController : ControllerBase
public async Task<IActionResult> AddPoint(string streetname, [FromBody] AddPointDTO dto)
{
if (dto == null)
return BadRequest();
return BadRequest("Invalid request body.");
try
{
await StreetService.AddPointAsync(streetname, StreetService.ToGeometryPoint(dto.Point), dto.usePostGIS);
return Ok();
}
catch (KeyNotFoundException)
catch (KeyNotFoundException ex)
{
return NotFound();
return NotFound(ex);
}
catch (ArgumentException)
catch (ArgumentException ex)
{
return BadRequest();
return BadRequest(ex);
}
catch
{
return Conflict();
return Conflict("Concurrency conflict. Please retry your request.");
}
}
}

View File

@ -32,6 +32,8 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
geometry = new[] { new { x = 10, y = 20 }, new { x = 15, y = 25 } }
};
Console.WriteLine(JsonConvert.SerializeObject(street));
var post_response = await client.PostAsJsonAsync("/api/streets/", street);
post_response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);

View File

@ -18,12 +18,6 @@ public class StreetWebApplicationFactory<Program> : WebApplicationFactory<Progra
builder.ConfigureServices(services =>
{
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<StreetDbContext>));
if (descriptor != null)
{
services.Remove(descriptor);
}
// Use the test database
services.AddDbContext<StreetDbContext>(options => options.UseNpgsql(dbTestContainer.GetConnectionString(), o => o.UseNetTopologySuite()));