예제 #1
0
        public async Task <IActionResult> Delete(long?id,
                                                 [FromServices] DataAccess.Repositories.Interfaces.TenantRepositories.ITrainingHistoryRepository trainingHistoryRepository)
        {
            //データの入力チェック
            if (id == null)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            //データの存在チェック
            var git = await gitRepository.GetByIdAsync(id.Value);

            if (git == null)
            {
                return(JsonNotFound($"Git ID {id.Value} is not found."));
            }
            //データの編集可否チェック
            if (git.IsNotEditable)
            {
                return(JsonBadRequest($"Git ID {id.Value} is not allowed to delete."));
            }

            //このGitを登録しているテナントがいた場合、削除はできない
            var tenant = gitRepository.GetTenant(git.Id);

            if (tenant != null)
            {
                return(JsonConflict($"Git {git.Id}:{git.Name} is used at Tenant {tenant.Id}:{tenant.Name}."));
            }
            //このGitを使った履歴がある場合、削除はできない
            var training = trainingHistoryRepository.Find(t => t.ModelGitId == git.Id);

            if (training != null)
            {
                return(JsonConflict($"Git {git.Id}:{git.Name} is used at training {training.Id} in Tenant {training.TenantId}."));
            }

            gitRepository.Delete(git);
            unitOfWork.Commit();

            return(JsonNoContent());
        }
예제 #2
0
        public async Task <IActionResult> Delete(long?id,
                                                 [FromServices] IPreprocessRepository preprocessRepository,
                                                 [FromServices] INotebookHistoryRepository notebookHistoryRepository,
                                                 [FromServices] ITrainingHistoryRepository trainingHistoryRepository,
                                                 [FromServices] IInferenceHistoryRepository inferenceHistoryRepository
                                                 )
        {
            // データの入力チェック
            if (id == null)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            // データの存在チェック
            var git = await gitRepository.GetByIdAsync(id.Value);

            if (git == null)
            {
                return(JsonNotFound($"Git ID {id.Value} is not found."));
            }

            // データの編集可否チェック
            if (git.IsNotEditable)
            {
                return(JsonBadRequest($"Git ID {id.Value} is not allowed to delete."));
            }

            // このGitを登録しているテナントがいた場合、削除はできない
            var tenant = gitRepository.GetTenant(git.Id);

            if (tenant != null)
            {
                return(JsonConflict($"Git {git.Id}:{git.Name} is used at Tenant {tenant.Id}:{tenant.Name}."));
            }

            // このGitを使った履歴がある場合、削除はできない
            // 前処理チェック
            var preprocessing = preprocessRepository.Find(p => p.RepositoryGitId == git.Id);

            if (preprocessing != null)
            {
                return(JsonConflict($"Git {git.Id}:{git.Name} is used at preprocessing {preprocessing.Id} in Tenant {preprocessing.TenantId}."));
            }
            // ノートブック履歴チェック
            var notebook = notebookHistoryRepository.Find(n => n.ModelGitId == git.Id);

            if (notebook != null)
            {
                return(JsonConflict($"Git {git.Id}:{git.Name} is used at notebook {notebook.Id} in Tenant {notebook.TenantId}."));
            }
            // 学習履歴チェック
            var training = trainingHistoryRepository.Find(t => t.ModelGitId == git.Id);

            if (training != null)
            {
                return(JsonConflict($"Git {git.Id}:{git.Name} is used at training {training.Id} in Tenant {training.TenantId}."));
            }
            // 推論履歴チェック
            var inference = inferenceHistoryRepository.Find(i => i.ModelGitId == git.Id);

            if (inference != null)
            {
                return(JsonConflict($"Git {git.Id}:{git.Name} is used at inference {inference.Id} in Tenant {inference.TenantId}."));
            }

            gitRepository.Delete(git);
            unitOfWork.Commit();

            return(JsonNoContent());
        }