| | | 1 | | using pva.SuperV.Api.Exceptions; |
| | | 2 | | using pva.SuperV.Api.Mappers; |
| | | 3 | | using pva.SuperV.Engine; |
| | | 4 | | using pva.SuperV.Engine.Exceptions; |
| | | 5 | | using pva.SuperV.Engine.HistoryStorage; |
| | | 6 | | using pva.SuperV.Model.HistoryRepositories; |
| | | 7 | | using pva.SuperV.Model.Services; |
| | | 8 | | |
| | | 9 | | namespace pva.SuperV.Api.Services.HistoryRepositories |
| | | 10 | | { |
| | | 11 | | public class HistoryRepositoryService : BaseService, IHistoryRepositoryService |
| | | 12 | | { |
| | | 13 | | private readonly ILogger logger; |
| | | 14 | | |
| | 6 | 15 | | public HistoryRepositoryService(ILoggerFactory loggerFactory) |
| | 6 | 16 | | { |
| | 6 | 17 | | this.logger = loggerFactory.CreateLogger(this.GetType()); |
| | 6 | 18 | | } |
| | | 19 | | |
| | | 20 | | public async Task<List<HistoryRepositoryModel>> GetHistoryRepositoriesAsync(string projectId) |
| | 1 | 21 | | { |
| | 1 | 22 | | logger.LogDebug("Getting history repositories for project {ProjectId}", |
| | 1 | 23 | | projectId); |
| | 1 | 24 | | Project project = GetProjectEntity(projectId); |
| | 1 | 25 | | return await Task.FromResult(project.HistoryRepositories.Values.Select(HistoryRepositoryMapper.ToDto).ToList |
| | 1 | 26 | | } |
| | | 27 | | |
| | | 28 | | public async Task<HistoryRepositoryModel> GetHistoryRepositoryAsync(string projectId, string historyRepositoryNa |
| | 1 | 29 | | { |
| | 1 | 30 | | logger.LogDebug("Getting history repository {HistoryRepository} for project {ProjectId}", |
| | 1 | 31 | | historyRepositoryName, projectId); |
| | 1 | 32 | | if (GetProjectEntity(projectId).HistoryRepositories.TryGetValue(historyRepositoryName, out HistoryRepository |
| | 1 | 33 | | { |
| | 1 | 34 | | return await Task.FromResult(HistoryRepositoryMapper.ToDto(historyRepository)); |
| | | 35 | | } |
| | 0 | 36 | | return await Task.FromException<HistoryRepositoryModel>(new UnknownEntityException("History repository", his |
| | 1 | 37 | | } |
| | | 38 | | |
| | | 39 | | public async Task<HistoryRepositoryModel> CreateHistoryRepositoryAsync(string projectId, HistoryRepositoryModel |
| | 2 | 40 | | { |
| | 2 | 41 | | logger.LogDebug("Creating history repository {HistoryRepository} for project {ProjectId}", |
| | 2 | 42 | | historyRepositoryCreateRequest.Name, projectId); |
| | 2 | 43 | | if (GetProjectEntity(projectId) is WipProject wipProject) |
| | 2 | 44 | | { |
| | 2 | 45 | | HistoryRepository historyRepository = HistoryRepositoryMapper.FromDto(historyRepositoryCreateRequest); |
| | 2 | 46 | | wipProject.AddHistoryRepository(historyRepository); |
| | 2 | 47 | | return await Task.FromResult(HistoryRepositoryMapper.ToDto(historyRepository)); |
| | | 48 | | } |
| | 0 | 49 | | return await Task.FromException<HistoryRepositoryModel>(new NonWipProjectException(projectId)); |
| | 2 | 50 | | } |
| | | 51 | | |
| | | 52 | | public async Task<HistoryRepositoryModel> UpdateHistoryRepositoryAsync(string projectId, string historyRepositor |
| | 0 | 53 | | { |
| | 0 | 54 | | logger.LogDebug("Updating history repository {HistoryRepository} for project {ProjectId}", |
| | 0 | 55 | | historyRepositoryUpdateRequest.Name, projectId); |
| | 0 | 56 | | if (GetProjectEntity(projectId) is WipProject wipProject) |
| | 0 | 57 | | { |
| | 0 | 58 | | HistoryRepository historyRepositoryUpdate = HistoryRepositoryMapper.FromDto(historyRepositoryUpdateReque |
| | 0 | 59 | | wipProject.UpdateHistoryRepository(historyRepositoryName, historyRepositoryUpdate); |
| | 0 | 60 | | return await Task.FromResult(HistoryRepositoryMapper.ToDto(historyRepositoryUpdate)); |
| | | 61 | | } |
| | 0 | 62 | | return await Task.FromException<HistoryRepositoryModel>(new NonWipProjectException(projectId)); |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | public async ValueTask DeleteHistoryRepositoryAsync(string projectId, string historyRepositoryName) |
| | 2 | 66 | | { |
| | 2 | 67 | | logger.LogDebug("Deleting history repository {HistoryRepository} for project {ProjectId}", |
| | 2 | 68 | | historyRepositoryName, projectId); |
| | 2 | 69 | | if (GetProjectEntity(projectId) is WipProject wipProject) |
| | 2 | 70 | | { |
| | 2 | 71 | | wipProject.RemoveHistoryRepository(historyRepositoryName); |
| | 1 | 72 | | await ValueTask.CompletedTask; |
| | 1 | 73 | | return; |
| | | 74 | | } |
| | 0 | 75 | | await ValueTask.FromException(new NonWipProjectException(projectId)); |
| | 1 | 76 | | } |
| | | 77 | | } |
| | | 78 | | } |