Compare commits
No commits in common. "ce4e5848dbc7dd5624083c763f50944e5bbab674" and "3d0d9faf12052a22f4ba32d2632e1ddad6c817e8" have entirely different histories.
ce4e5848db
...
3d0d9faf12
@ -17,7 +17,7 @@ public class StreetController : ControllerBase
|
|||||||
public async Task<IActionResult> CreateStreet([FromBody] CreateStreetDTO dto)
|
public async Task<IActionResult> CreateStreet([FromBody] CreateStreetDTO dto)
|
||||||
{
|
{
|
||||||
if (dto == null)
|
if (dto == null)
|
||||||
return BadRequest();
|
return BadRequest("Invalid request body.");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -28,9 +28,9 @@ public class StreetController : ControllerBase
|
|||||||
|
|
||||||
return Created();
|
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);
|
var street = await StreetService.GetStreetAsync(streetname);
|
||||||
return Ok(street);
|
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);
|
var deleted = await StreetService.DeleteStreetAsync(streetname);
|
||||||
if (!deleted)
|
if (!deleted)
|
||||||
return NotFound();
|
return NotFound($"Street '{streetname}' not found.");
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
@ -65,24 +65,24 @@ public class StreetController : ControllerBase
|
|||||||
public async Task<IActionResult> AddPoint(string streetname, [FromBody] AddPointDTO dto)
|
public async Task<IActionResult> AddPoint(string streetname, [FromBody] AddPointDTO dto)
|
||||||
{
|
{
|
||||||
if (dto == null)
|
if (dto == null)
|
||||||
return BadRequest();
|
return BadRequest("Invalid request body.");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await StreetService.AddPointAsync(streetname, StreetService.ToGeometryPoint(dto.Point), dto.usePostGIS);
|
await StreetService.AddPointAsync(streetname, StreetService.ToGeometryPoint(dto.Point), dto.usePostGIS);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException)
|
catch (KeyNotFoundException ex)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound(ex);
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException ex)
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest(ex);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return Conflict();
|
return Conflict("Concurrency conflict. Please retry your request.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
geometry = new[] { new { x = 10, y = 20 }, new { x = 15, y = 25 } }
|
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);
|
var post_response = await client.PostAsJsonAsync("/api/streets/", street);
|
||||||
|
|
||||||
post_response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);
|
post_response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);
|
||||||
|
|||||||
@ -18,12 +18,6 @@ public class StreetWebApplicationFactory<Program> : WebApplicationFactory<Progra
|
|||||||
builder.ConfigureServices(services =>
|
builder.ConfigureServices(services =>
|
||||||
{
|
{
|
||||||
|
|
||||||
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<StreetDbContext>));
|
|
||||||
if (descriptor != null)
|
|
||||||
{
|
|
||||||
services.Remove(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the test database
|
// Use the test database
|
||||||
services.AddDbContext<StreetDbContext>(options => options.UseNpgsql(dbTestContainer.GetConnectionString(), o => o.UseNetTopologySuite()));
|
services.AddDbContext<StreetDbContext>(options => options.UseNpgsql(dbTestContainer.GetConnectionString(), o => o.UseNetTopologySuite()));
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user