-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#21 - added capability to adding the space
- Loading branch information
Showing
10 changed files
with
100 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 55 additions & 2 deletions
57
AlgoTecture.Libraries.Spaces/Implementations/SpaceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,66 @@ | ||
using AlgoTecture.Data.Persistence.Core.Interfaces; | ||
using AlgoTecture.Domain.Models; | ||
using AlgoTecture.Domain.Models.RepositoryModels; | ||
using AlgoTecture.Libraries.Spaces.Interfaces; | ||
using AlgoTecture.Libraries.Spaces.Models.Dto; | ||
using Newtonsoft.Json; | ||
|
||
namespace AlgoTecture.Libraries.Spaces.Implementations; | ||
|
||
public class SpaceService : ISpaceService | ||
{ | ||
public Task<Space> AddSpace(AddSpaceModel addSpaceModel) | ||
private readonly IUnitOfWork _unitOfWork; | ||
|
||
public SpaceService(IUnitOfWork unitOfWork) | ||
{ | ||
_unitOfWork = unitOfWork; | ||
} | ||
|
||
public async Task<Space> AddSpace(AddSpaceModel addSpaceModel) | ||
{ | ||
var targetSpace = await _unitOfWork.Spaces.GetByCoordinates(addSpaceModel.Latitude, addSpaceModel.Longitude); | ||
|
||
if (targetSpace != null) | ||
{ | ||
throw new InvalidOperationException($"Space with coordinates {addSpaceModel.Latitude},{addSpaceModel.Longitude} already exists"); | ||
} | ||
|
||
var spaceProperty = new SpaceProperty() | ||
{ | ||
SpacePropertyId = Guid.NewGuid(), | ||
Name = addSpaceModel.SpaceProperty.Name, | ||
Description = addSpaceModel.SpaceProperty.Description, | ||
OwnerId = 0, | ||
ContractId = 0, | ||
Properties = addSpaceModel.SpaceProperty.Properties, | ||
}; | ||
|
||
RecursiveFindAndAddGuidToSubSpace(addSpaceModel.SpaceProperty.SubSpaces); | ||
spaceProperty.SubSpaces = addSpaceModel.SpaceProperty.SubSpaces; | ||
|
||
var serializedSpaceProperty = JsonConvert.SerializeObject(spaceProperty); | ||
|
||
var entityToInsert = new Space | ||
{ | ||
Latitude = addSpaceModel.Latitude, Longitude = addSpaceModel.Longitude, SpaceAddress = addSpaceModel.SpaceAddress, | ||
UtilizationTypeId = addSpaceModel.UtilizationTypeId, SpaceProperty = serializedSpaceProperty | ||
}; | ||
|
||
var insertedEntity = await _unitOfWork.Spaces.Add(entityToInsert); | ||
await _unitOfWork.CompleteAsync(); | ||
|
||
return insertedEntity; | ||
} | ||
|
||
private static void RecursiveFindAndAddGuidToSubSpace(List<SubSpace> subSpaces) | ||
{ | ||
return null; | ||
for (var i = 0; i < subSpaces.Count; i++) | ||
{ | ||
if (subSpaces[i].SubSpaceId == Guid.Empty) | ||
{ | ||
subSpaces[i].SubSpaceId = Guid.NewGuid(); | ||
} | ||
RecursiveFindAndAddGuidToSubSpace(subSpaces[i].Subspaces); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
AlgoTecture.Libraries.Spaces/Models/Dto/AddSpacePropertyModel.cs
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
AlgoTecture.Libraries.Spaces/Models/Dto/AddSubSpaceModel.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"urls": "http://0.0.0.0:5000" | ||
"urls": "http://0.0.0.0:5100" | ||
} |