| | | 1 | | using pva.SuperV.Api.Exceptions; |
| | | 2 | | using pva.SuperV.Engine; |
| | | 3 | | using pva.SuperV.Engine.Exceptions; |
| | | 4 | | using pva.SuperV.Engine.HistoryStorage; |
| | | 5 | | using pva.SuperV.Model.HistoryRepositories; |
| | | 6 | | using pva.SuperV.Model.Services; |
| | | 7 | | |
| | | 8 | | namespace pva.SuperV.Api.Services.HistoryRepositories |
| | | 9 | | { |
| | | 10 | | public class HistoryRepositoryService : BaseService, IHistoryRepositoryService |
| | | 11 | | { |
| | | 12 | | public async Task<List<HistoryRepositoryModel>> GetHistoryRepositoriesAsync(string projectId) |
| | 1 | 13 | | { |
| | 1 | 14 | | Project project = GetProjectEntity(projectId); |
| | 1 | 15 | | return await Task.FromResult(project.HistoryRepositories.Values.Select(HistoryRepositoryMapper.ToDto).ToList |
| | 1 | 16 | | } |
| | | 17 | | |
| | | 18 | | public async Task<HistoryRepositoryModel> GetHistoryRepositoryAsync(string projectId, string historyRepositoryNa |
| | 1 | 19 | | { |
| | 1 | 20 | | if (GetProjectEntity(projectId).HistoryRepositories.TryGetValue(historyRepositoryName, out HistoryRepository |
| | 1 | 21 | | { |
| | 1 | 22 | | return await Task.FromResult(HistoryRepositoryMapper.ToDto(historyRepository)); |
| | | 23 | | } |
| | 0 | 24 | | return await Task.FromException<HistoryRepositoryModel>(new UnknownEntityException("History repository", his |
| | 1 | 25 | | } |
| | | 26 | | |
| | | 27 | | public async Task<HistoryRepositoryModel> CreateHistoryRepositoryAsync(string projectId, HistoryRepositoryModel |
| | 2 | 28 | | { |
| | 2 | 29 | | if (GetProjectEntity(projectId) is WipProject wipProject) |
| | 2 | 30 | | { |
| | 2 | 31 | | HistoryRepository historyRepository = HistoryRepositoryMapper.FromDto(historyRepositoryCreateRequest); |
| | 2 | 32 | | wipProject.AddHistoryRepository(historyRepository); |
| | 2 | 33 | | return await Task.FromResult(HistoryRepositoryMapper.ToDto(historyRepository)); |
| | | 34 | | } |
| | 0 | 35 | | return await Task.FromException<HistoryRepositoryModel>(new NonWipProjectException(projectId)); |
| | 2 | 36 | | } |
| | | 37 | | |
| | | 38 | | public async Task<HistoryRepositoryModel> UpdateHistoryRepositoryAsync(string projectId, string historyRepositor |
| | 0 | 39 | | { |
| | 0 | 40 | | if (GetProjectEntity(projectId) is WipProject wipProject) |
| | 0 | 41 | | { |
| | 0 | 42 | | HistoryRepository historyRepositoryUpdate = HistoryRepositoryMapper.FromDto(historyRepositoryUpdateReque |
| | 0 | 43 | | wipProject.UpdateHistoryRepository(historyRepositoryName, historyRepositoryUpdate); |
| | 0 | 44 | | return await Task.FromResult(HistoryRepositoryMapper.ToDto(historyRepositoryUpdate)); |
| | | 45 | | } |
| | 0 | 46 | | return await Task.FromException<HistoryRepositoryModel>(new NonWipProjectException(projectId)); |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | public async ValueTask DeleteHistoryRepositoryAsync(string projectId, string historyRepositoryName) |
| | 2 | 50 | | { |
| | 2 | 51 | | if (GetProjectEntity(projectId) is WipProject wipProject) |
| | 2 | 52 | | { |
| | 2 | 53 | | wipProject.RemoveHistoryRepository(historyRepositoryName); |
| | 1 | 54 | | await ValueTask.CompletedTask; |
| | 1 | 55 | | return; |
| | | 56 | | } |
| | 0 | 57 | | await ValueTask.FromException(new NonWipProjectException(projectId)); |
| | 1 | 58 | | } |
| | | 59 | | } |
| | | 60 | | } |