Skip to content

Commit

Permalink
#21 added controller to space adding and updated space model storing
Browse files Browse the repository at this point in the history
  • Loading branch information
sipakov committed May 22, 2023
1 parent 6858e1a commit 54b2733
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 24 deletions.
3 changes: 0 additions & 3 deletions AlgoTecture.Data.Persistence.Ef/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

var newSpaceProperty1 = new SpaceProperty
{
SpaceId = 1,
Name = "Santa María",
SpacePropertyId = Guid.Parse("4c4f455c-bc98-47da-9f4b-9dcc25a17fe5"),
Description = "best boat in the world"
Expand All @@ -104,7 +103,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
});
var newSpaceProperty2 = new SpaceProperty
{
SpaceId = 2,
Name = "Niña",
SpacePropertyId = Guid.Parse("7d2dc2f3-4f52-4244-8ade-73eba2772a51"),
Description = "best boat in the world"
Expand All @@ -116,7 +114,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
});
var newSpaceProperty3 = new SpaceProperty
{
SpaceId = 3,
Name = "Pinta",
SpacePropertyId = Guid.Parse("a5f8e388-0c2f-491c-82ff-d4c92da97aaa"),
Description = "best boat in the world"
Expand Down
26 changes: 26 additions & 0 deletions AlgoTecture.Domain/Models/SpaceDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace AlgoTecture.Domain.Models;

public class SpaceDetails
{
public string BuildingYear { get; set; }

public string BuildingCategory { get; set; }

public string BuildingClass { get; set; }

public string BuildingName { get; set; }

public string Levels { get; set; }

public string Area { get; set; }

public string FloorArea { get; set; }

public string Flats { get; set; }

public string PlaceName { get; set; }

public string MunicipalityId { get; set; }

public string MunicipalityName { get; set; }
}
6 changes: 1 addition & 5 deletions AlgoTecture.Domain/Models/SpaceProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ public class SpaceProperty
{
public Guid SpacePropertyId { get; set; }

public long SpaceId { get; set; }

public string Name { get; set; }

public string Description { get; set; }

public int UtilizationTypeId { get; set; }

public double TotalArea { get; set; }
public SpaceDetails SpaceDetails { get; set; }

public long OwnerId { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions AlgoTecture.Domain/Models/SubSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public SubSpace()

public int SubSpaceIdHash { get; set; }

public long SpaceId { get; set; }

private List<SubSpace> _subSpaces;

public SubSpaceDetails SubSpaceDetails { get; set; }

public double Area { get; set; }

Expand Down
12 changes: 12 additions & 0 deletions AlgoTecture.Domain/Models/SubSpaceDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace AlgoTecture.Domain.Models;

public class SubSpaceDetails
{
public string Levels { get; set; }

public string Area { get; set; }

public string FloorArea { get; set; }

public string Flats { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AlgoTecture.Data.Persistence\AlgoTecture.Data.Persistence.csproj" />
<ProjectReference Include="..\AlgoTecture.Libraries.Reservations\AlgoTecture.Libraries.Reservations.csproj" />
<ProjectReference Include="..\AlgoTecture.Libraries.Spaces\AlgoTecture.Libraries.Spaces.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using AlgoTecture.Domain.Models;
using AlgoTecture.Libraries.Spaces.Models.Dto;
using Newtonsoft.Json;
using NUnit.Framework;

namespace AlgoTecture.Libraries.Reservations.Tests.Serialization;

public class ClassToJsonSerializationTests
{
[Test]
public void ConversationClassToJsonSimpleTest()
{
var addSpaceModel = new AddSpaceModel
{
UtilizationTypeId = 1,
SpaceAddress = "Unterstaldig 1 6106 Werthenstein",
Latitude = 47.04173191647986,
Longitude = 8.097301555686508,
SpaceProperty = new AddSpacePropertyModel
{
Name = string.Empty,
Description = string.Empty,
SpaceDetails = new SpaceDetails
{
BuildingYear = "2023",
BuildingName = string.Empty,
Levels = "3",
Area = "456.4",
Flats = "1",
FloorArea = "674",
BuildingClass = "Gebäude mit 1 Wohnung",
BuildingCategory = "Andere Wohngebäude",
PlaceName = "Werthenstein",
MunicipalityId = "1009",
MunicipalityName = "Werthenstein"
},
SubSpaces = new List<AddSubSpaceModel>()
{
new AddSubSpaceModel
{
UtilizationTypeId = 1,
Description = string.Empty,
SubSpaceDetails = new SubSpaceDetails
{
Levels = "1",
Area = "300",
Flats = "1",
FloorArea = "477",
}
},
new AddSubSpaceModel
{
UtilizationTypeId = 1,
Description = string.Empty,
SubSpaceDetails = new SubSpaceDetails
{
Levels = "2",
Area = "200",
Flats = "1",
FloorArea = "287",
}
}
}
}
};

void Code() => JsonConvert.SerializeObject(addSpaceModel);

var serializedModel = JsonConvert.SerializeObject(addSpaceModel);

Assert.That(Code, Throws.Nothing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AlgoTecture.Libraries.Spaces.Implementations;

public class SpaceService : ISpaceService
{
public Task<Space> AddOrUpdateSpace(AddSpaceModel addSpaceModel)
public Task<Space> AddSpace(AddSpaceModel addSpaceModel)
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion AlgoTecture.Libraries.Spaces/Interfaces/ISpaceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace AlgoTecture.Libraries.Spaces.Interfaces;

public interface ISpaceService
{
Task<Space> AddOrUpdateSpace(AddSpaceModel addSpaceModel);
Task<Space> AddSpace(AddSpaceModel addSpaceModel);
}
14 changes: 6 additions & 8 deletions AlgoTecture.Libraries.Spaces/Models/Dto/AddSpaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ namespace AlgoTecture.Libraries.Spaces.Models.Dto
{
public class AddSpaceModel
{
public string UserEmail { get; set; }
public int UtilizationTypeId { get; set; }

public string Address { get; set; }
public string SpaceAddress { get; set; }

public string Latitude { get; set; }
public double Latitude { get; set; }

public string Longitude { get; set; }

public string DateStart { get; set; }

public string DateStop { get; set; }
public double Longitude { get; set; }

public AddSpacePropertyModel SpaceProperty { get; set; }
}
}
14 changes: 14 additions & 0 deletions AlgoTecture.Libraries.Spaces/Models/Dto/AddSpacePropertyModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using AlgoTecture.Domain.Models;

namespace AlgoTecture.Libraries.Spaces.Models.Dto;

public class AddSpacePropertyModel
{
public string Name { get; set; }

public string Description { get; set; }

public SpaceDetails SpaceDetails { get; set; }

public List<AddSubSpaceModel> SubSpaces { get; set; }
}
25 changes: 25 additions & 0 deletions AlgoTecture.Libraries.Spaces/Models/Dto/AddSubSpaceModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using AlgoTecture.Domain.Models;

namespace AlgoTecture.Libraries.Spaces.Models.Dto;

public class AddSubSpaceModel
{
public AddSubSpaceModel()
{
_subSpaces = new List<AddSubSpaceModel>();
}

private List<AddSubSpaceModel> _subSpaces;

public SubSpaceDetails SubSpaceDetails { get; set; }

public int UtilizationTypeId { get; set; }

public string Description { get; set; }

public List<AddSubSpaceModel> Subspaces
{
get { return _subSpaces; }
set { _subSpaces = value; }
}
}
1 change: 1 addition & 0 deletions AlgoTecture.Libraries.Spaces/UseSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static IServiceCollection UseSpaceLibrary([NotNull] this IServiceCollecti
if (serviceCollection == null) throw new ArgumentNullException(nameof(serviceCollection));

serviceCollection.AddTransient<ISpaceGetter, SpaceGetter>();
serviceCollection.AddTransient<ISpaceService, SpaceService>();

return serviceCollection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ private async Task PressAddressToRentButton(string geoAdminFeatureId)
var newSubSpaceId = Guid.NewGuid();
var newSpaceProperty = new SpaceProperty
{
SpaceId = spaceEntity.Id,
SpacePropertyId = Guid.NewGuid(),
SubSpaces = new List<SubSpace>()
{
Expand Down
15 changes: 13 additions & 2 deletions AlgoTecture.WebApi/Controllers/SpaceController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Threading.Tasks;
using AlgoTecture.Domain.Models.Dto;
using AlgoTecture.Domain.Models.RepositoryModels;
using AlgoTecture.Libraries.Spaces.Interfaces;
using AlgoTecture.Libraries.Spaces.Models.Dto;
using AlgoTecture.WebApi.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using AddSubSpaceModel = AlgoTecture.Domain.Models.Dto.AddSubSpaceModel;

namespace AlgoTecture.WebApi.Controllers
{
Expand All @@ -14,11 +15,13 @@ public class SpaceController : Controller
{
private readonly ISpaceGetter _spaceGetter;
private readonly ISubSpaceService _subSpaceService;
private readonly ISpaceService _spaceService;

public SpaceController(ISpaceGetter spaceGetter, ISubSpaceService subSpaceService)
public SpaceController(ISpaceGetter spaceGetter, ISubSpaceService subSpaceService, ISpaceService spaceService)
{
_spaceGetter = spaceGetter ?? throw new ArgumentNullException(nameof(spaceGetter));
_subSpaceService = subSpaceService ?? throw new ArgumentNullException(nameof(subSpaceService));
_spaceService = spaceService;
}

[HttpGet("GetByCoordinates")]
Expand All @@ -37,5 +40,13 @@ public async Task<ActionResult<Space>> AddSubSpace([FromBody] AddSubSpaceModel a

return await _subSpaceService.AddSubSpaceToSpace(addSubSpaceModel);
}

[HttpPost("AddSpace")]
public async Task<ActionResult<Space>> AddSpace([FromBody] AddSpaceModel addSpaceModel)
{
if (!ModelState.IsValid) return BadRequest();

return await _spaceService.AddSpace(addSpaceModel);
}
}
}
2 changes: 1 addition & 1 deletion AlgoTecture.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static async Task Main(string[] args)

var jwtIssuer = webAppBuilder.Configuration.GetSection("AuthenticationOptions").GetChildren().First(x=>x.Key == "JwtIssuer").Value;
var jwtAlgotectureSecret = webAppBuilder.Configuration.GetSection("AuthenticationOptions").GetChildren().First(x=>x.Key == "JwtAlgotectureSecret").Value;

webAppBuilder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
Expand Down
1 change: 1 addition & 0 deletions AlgoTecture.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d19db880_002Dbfa3_002D456f_002D9d89_002Dcff01e02f298/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Assert_That_Will_be_Returned_Null_If_In_Target_Time_Reservation_Exist" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;NUnit3x::1EC8134E-12A2-4EEB-83F7-A128164E15E7::net6.0::AlgoTecture.Libraries.Reservations.Tests.ReservationTests&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::1EC8134E-12A2-4EEB-83F7-A128164E15E7::net6.0::AlgoTecture.Libraries.Reservations.Tests.Serialization.ClassToJsonSerializationTests.ConversationClassToJsonSimpleTest&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String>

Expand Down

0 comments on commit 54b2733

Please sign in to comment.