Skip to content

Commit

Permalink
feat: Update data model (#119)
Browse files Browse the repository at this point in the history
Update data model
Rename RevisionContainer -> Container
Rename Reviewer -> TagReviewer
  • Loading branch information
taustad authored Nov 6, 2023
1 parent 2fbb69c commit c7d5ee1
Show file tree
Hide file tree
Showing 107 changed files with 1,494 additions and 2,037 deletions.
53 changes: 53 additions & 0 deletions datasheetapi/Adapters/ContainerAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace datasheetapi.Adapters;
public static class ContainerAdapter
{
public static ContainerDto? ToDtoOrNull(this Container? revisionContainer)
{
if (revisionContainer is null) { return null; }
return revisionContainer.ToDto();
}

private static ContainerDto ToDto(this Container revisionContainer)
{

return new ContainerDto
{
Id = revisionContainer.Id,
ContainerName = revisionContainer.ContainerName,
RevisionNumber = revisionContainer.RevisionNumber,
ContainerDate = revisionContainer.ContainerDate,
ContractId = revisionContainer.ContractId,
TagNos = revisionContainer.Tags.Select(t => t.TagNo).ToList()
};
}

public static List<ContainerDto> ToDto(this List<Container>? revisionContainers)
{
if (revisionContainers is null) { return new List<ContainerDto>(); }
return revisionContainers.Select(ToDto).ToList();
}

public static Container? ToModelOrNull(this ContainerDto? revisionContainerDto)
{
if (revisionContainerDto is null) { return null; }
return revisionContainerDto.ToModel();
}

private static Container ToModel(this ContainerDto revisionContainerDto)
{
return new Container
{
Id = revisionContainerDto.Id,
ContainerName = revisionContainerDto.ContainerName,
RevisionNumber = revisionContainerDto.RevisionNumber,
ContainerDate = revisionContainerDto.ContainerDate,
ContractId = revisionContainerDto.ContractId,
};
}

public static List<Container> ToModel(this List<ContainerDto>? revisionContainerDtos)
{
if (revisionContainerDtos is null) { return new List<Container>(); }
return revisionContainerDtos.Select(ToModel).ToList();
}
}
62 changes: 62 additions & 0 deletions datasheetapi/Adapters/ContainerReviewAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using datasheetapi.Dtos.ContainerReview;

namespace datasheetapi.Adapters;
public static class ContainerReviewAdapter
{
public static ContainerReviewDto ToDto(this ContainerReview revisionContainerReview)
{
return new ContainerReviewDto
{
Id = revisionContainerReview.Id,
State = MapContainerReviewStateModelToDto(revisionContainerReview.State),
CommentResponsible = revisionContainerReview.CommentResponsible,
ContainerId = revisionContainerReview.ContainerId,
};
}

public static List<ContainerReviewDto> ToDto(this List<ContainerReview>? revisionContainerReviews)
{
if (revisionContainerReviews is null) { return new List<ContainerReviewDto>(); }
return revisionContainerReviews.Select(ToDto).ToList();
}

public static ContainerReview ToModel(this ContainerReviewDto revisionContainerReviewDto)
{
return new ContainerReview
{
Id = revisionContainerReviewDto.Id,
State = MapContainerReviewStateDtoToModel(revisionContainerReviewDto.State),
CommentResponsible = revisionContainerReviewDto.CommentResponsible,
ContainerId = revisionContainerReviewDto.ContainerId,
};
}

public static ContainerReview ToModel(this CreateContainerReviewDto dto)
{
return new ContainerReview
{
ContainerId = dto.RevisionContainerId,
State = MapContainerReviewStateDtoToModel(dto.State),
};
}

public static ContainerReviewStateEnumDto MapContainerReviewStateModelToDto(ContainerReviewStateEnum state)
{
return state switch
{
ContainerReviewStateEnum.Active => ContainerReviewStateEnumDto.Active,
ContainerReviewStateEnum.SentToContractor => ContainerReviewStateEnumDto.SentToContractor,
_ => throw new ArgumentOutOfRangeException(nameof(state), $"Unknown state: {state}"),
};
}

public static ContainerReviewStateEnum MapContainerReviewStateDtoToModel(ContainerReviewStateEnumDto state)
{
return state switch
{
ContainerReviewStateEnumDto.Active => ContainerReviewStateEnum.Active,
ContainerReviewStateEnumDto.SentToContractor => ContainerReviewStateEnum.SentToContractor,
_ => throw new ArgumentOutOfRangeException(nameof(state), $"Unknown state: {state}"),
};
}
}
58 changes: 58 additions & 0 deletions datasheetapi/Adapters/ContainerReviewerAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using datasheetapi.Dtos.ContainerReview;
using datasheetapi.Dtos.ContainerReviewer;
using datasheetapi.Dtos.TagReviewer;

namespace datasheetapi.Adapters;

public static class ContainerReviewerAdapter
{
public static ContainerReviewer ToModel(this CreateContainerReviewerDto dto)
{
return new ContainerReviewer
{
UserId = dto.UserId,
State = ContainerReviewerStateEnum.Open,
TagReviewers = dto.TagReviewers?.ToModel() ?? new List<TagReviewer>()
};
}

public static ContainerReviewerDto ToDto(this ContainerReviewer model, Dictionary<Guid, string> userIdNameMap)
{
return new ContainerReviewerDto
{
Id = model.Id,
ContainerReviewId = model.ContainerReviewId,
State = MapContainerReviewStateModelToDto(model.State),
UserId = model.UserId,
TagReviewers = model.TagReviewers.ToDto(userIdNameMap),
};
}

public static List<ContainerReviewerDto> ToDto(this List<ContainerReviewer> model,
Dictionary<Guid, string> userIdNameMap)
{
return model.Select(m => m.ToDto(userIdNameMap)).ToList();
}

public static ContainerReviewerStateEnumDto MapContainerReviewStateModelToDto(ContainerReviewerStateEnum state)
{
return state switch
{
ContainerReviewerStateEnum.Open => ContainerReviewerStateEnumDto.Open,
ContainerReviewerStateEnum.Abandoned => ContainerReviewerStateEnumDto.Abandoned,
ContainerReviewerStateEnum.Complete => ContainerReviewerStateEnumDto.Complete,
_ => throw new ArgumentOutOfRangeException(nameof(state), $"Unknown state: {state}"),
};
}

public static ContainerReviewerStateEnum MapContainerReviewStateDtoToModel(ContainerReviewerStateEnumDto state)
{
return state switch
{
ContainerReviewerStateEnumDto.Open => ContainerReviewerStateEnum.Open,
ContainerReviewerStateEnumDto.Abandoned => ContainerReviewerStateEnum.Abandoned,
ContainerReviewerStateEnumDto.Complete => ContainerReviewerStateEnum.Complete,
_ => throw new ArgumentOutOfRangeException(nameof(state), $"Unknown state: {state}"),
};
}
}
8 changes: 2 additions & 6 deletions datasheetapi/Adapters/ContractAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ private static ContractDto ToDto(this Contract contract)
return new ContractDto
{
Id = contract.Id,
CreatedDate = contract.CreatedDate,
ModifiedDate = contract.ModifiedDate,
ContractName = contract.ContractName,
ContractorId = contract.ContractorId,
ProjectId = contract.ProjectId,
RevisionContainers = contract.RevisionContainers.ToDto(),
RevisionContainers = contract.Containers.ToDto(),
};
}

Expand All @@ -38,9 +35,8 @@ private static Contract ToModel(this ContractDto contractDto)
return new Contract
{
ContractName = contractDto.ContractName,
ContractorId = contractDto.ContractorId,
ProjectId = contractDto.ProjectId,
RevisionContainers = contractDto.RevisionContainers.ToModel(),
Containers = contractDto.RevisionContainers.ToModel(),
};
}

Expand Down
4 changes: 0 additions & 4 deletions datasheetapi/Adapters/ProjectAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public static ProjectDto ToDto(this Project project)
return new ProjectDto
{
Id = project.Id,
CreatedDate = project.CreatedDate,
ModifiedDate = project.ModifiedDate,
Contracts = project.Contracts.ToDto(),
};
}
Expand All @@ -29,8 +27,6 @@ private static Project ToModel(this ProjectDto projectDto)
return new Project
{
Id = projectDto.Id,
CreatedDate = projectDto.CreatedDate,
ModifiedDate = projectDto.ModifiedDate,
Contracts = projectDto.Contracts.ToModel(),
};
}
Expand Down
39 changes: 0 additions & 39 deletions datasheetapi/Adapters/ReviewerAdapter.cs

This file was deleted.

60 changes: 0 additions & 60 deletions datasheetapi/Adapters/RevisionContainerAdapter.cs

This file was deleted.

62 changes: 0 additions & 62 deletions datasheetapi/Adapters/RevisionContainerReviewAdapter.cs

This file was deleted.

2 changes: 0 additions & 2 deletions datasheetapi/Adapters/TagDataAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ private static T DefaultToDto<T>(ITagData tagData)
System = tagData.System,
TagType = tagData.TagType,
SubTagType = tagData.SubTagType,
Version = tagData.Version,
RevisionContainer = null,
};
}
}
Loading

0 comments on commit c7d5ee1

Please sign in to comment.