Exemplo n.º 1
0
        public MaterialResponseDTO GetFileByUUIDAndSection(string sectionUUID, string fileUUID)
        {
            MaterialResponseDTO response = this._autoMapper.Map <MaterialResponseDTO>(this.FindOneBySectionAndFile(sectionUUID, fileUUID));

            if (response == null)
            {
                throw new EntityNotFoundException($"Section with uuid: {sectionUUID} and file with uuid: {fileUUID} does not exist!", GeneralConsts.MICROSERVICE_NAME);
            }
            response.section = this._sectionService.GetSectionByUuid(sectionUUID);
            return(response);
        }
Exemplo n.º 2
0
        public MaterialResponseDTO Delete(string sectionUUID, string fileUUID)
        {
            if (this.FindOneBySectionAndFile(sectionUUID, fileUUID) == null)
            {
                throw new EntityNotFoundException($"Section with uuid: {sectionUUID} and file with uuid: {fileUUID} does not exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            MaterialResponseDTO response = this.GetFileByUUIDAndSection(sectionUUID, fileUUID);

            _ = this._queryExecutor.Execute <Material>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.DELETE_FILE_FROM_SECTION(sectionUUID, fileUUID), this._modelMapper.MapToMaterial);
            return(response);
        }
Exemplo n.º 3
0
        public MaterialResponseDTO Create(CreateMaterialRequestDTO requestDTO)
        {
            if (this.FindOneBySectionAndFile(requestDTO.sectionUUID, requestDTO.fileUUID) != null)
            {
                throw new EntityNotFoundException($"Section with uuid: {requestDTO.sectionUUID} and file with uuid: {requestDTO.fileUUID} already exists!", GeneralConsts.MICROSERVICE_NAME);
            }

            FileDTO file = this._httpClientService.SendRequest <FileDTO>(HttpMethod.Get, "http://localhost:40003/api/files/" + requestDTO.fileUUID, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;

            if (file == null)
            {
                throw new EntityAlreadyExistsException($"File with uuid {requestDTO.fileUUID} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            Material material = new Material()
            {
                section = new Section()
                {
                    uuid = requestDTO.sectionUUID
                },
                file = new File()
                {
                    uuid     = requestDTO.fileUUID,
                    filePath = file.filePath
                },
                visible = requestDTO.visible
            };

            material = this._queryExecutor.Execute <Material>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.ADD_FILE_TO_SECTION(material), this._modelMapper.MapToMaterial);

            MaterialResponseDTO response = this._autoMapper.Map <MaterialResponseDTO>(material);

            response.file    = file;
            response.section = this._sectionService.GetSectionByUuid(requestDTO.sectionUUID);
            return(response);
        }