UploadRequest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\ApiResources\Core\File;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\Metadata\Put;
  8. use App\Enum\Core\FileTypeEnum;
  9. use App\State\Processor\Core\UploadRequestProcessor;
  10. use App\State\Provider\Core\DownloadRequestProvider;
  11. use Ramsey\Uuid\Uuid;
  12. /**
  13. * A request to upload the given content to a File
  14. */
  15. #[ApiResource(
  16. operations: [
  17. new Post(
  18. uriTemplate: '/upload',
  19. requirements: ['id' => '\\d+'],
  20. security: 'is_granted("ROLE_FILE")',
  21. processor: UploadRequestProcessor::class
  22. )
  23. ]
  24. )]
  25. class UploadRequest
  26. {
  27. /**
  28. * Only because id is required
  29. * @var int | null
  30. */
  31. #[ApiProperty(identifier: true)]
  32. private ?int $fileId = null;
  33. /**
  34. * Le nom du fichier
  35. * @var string
  36. */
  37. private string $filename;
  38. /**
  39. * The content of the uploaded file
  40. * @var string
  41. */
  42. private string $content;
  43. /**
  44. * Si vrai, le propriétaire du fichier ne sera pas l'utilisateur en cours, mais l'organisation à laquelle il
  45. * appartient.
  46. * @var bool
  47. */
  48. private bool $organizationOwned = false;
  49. /**
  50. * Le type de fichier uploadé, si connu
  51. * @var FileTypeEnum
  52. */
  53. private FileTypeEnum $type;
  54. /**
  55. * Visibilité du fichier
  56. * @var string
  57. */
  58. private string $visibility = 'NOBODY';
  59. /**
  60. * Type mime (il sera déduit automatiquement du nom du fichier s'il n'est pas fourni ici)
  61. * @var string|null
  62. */
  63. private ?string $mimeType = null;
  64. public function __construct()
  65. {
  66. $this->type = FileTypeEnum::NONE();
  67. }
  68. /**
  69. * @return int
  70. */
  71. public function getFileId() : int
  72. {
  73. return $this->fileId;
  74. }
  75. /**
  76. * @param int $id
  77. * @return self
  78. */
  79. public function setFileId(int $id) : self
  80. {
  81. $this->fileId = $id;
  82. return $this;
  83. }
  84. /**
  85. * @return string
  86. */
  87. public function getContent(): string
  88. {
  89. return $this->content;
  90. }
  91. /**
  92. * @param string $content
  93. * @return void
  94. */
  95. public function setContent(string $content): void
  96. {
  97. $this->content = $content;
  98. }
  99. /**
  100. * @return bool
  101. */
  102. public function isOrganizationOwned(): bool
  103. {
  104. return $this->organizationOwned;
  105. }
  106. /**
  107. * @param bool $organizationOwned
  108. * @return self
  109. */
  110. public function setOrganizationOwned(bool $organizationOwned): self
  111. {
  112. $this->organizationOwned = $organizationOwned;
  113. return $this;
  114. }
  115. /**
  116. * @return string
  117. */
  118. public function getFilename(): string
  119. {
  120. return $this->filename;
  121. }
  122. /**
  123. * @param string $filename
  124. * @return self
  125. */
  126. public function setFilename(string $filename): self
  127. {
  128. $this->filename = $filename;
  129. return $this;
  130. }
  131. /**
  132. * @return FileTypeEnum
  133. */
  134. public function getType(): FileTypeEnum
  135. {
  136. return $this->type;
  137. }
  138. /**
  139. * @param FileTypeEnum $type
  140. * @return self
  141. */
  142. public function setType(FileTypeEnum $type): self
  143. {
  144. $this->type = $type;
  145. return $this;
  146. }
  147. /**
  148. * @return string
  149. */
  150. public function getVisibility(): string
  151. {
  152. return $this->visibility;
  153. }
  154. /**
  155. * @param string $visibility
  156. * @return self
  157. */
  158. public function setVisibility(string $visibility): self
  159. {
  160. $this->visibility = $visibility;
  161. return $this;
  162. }
  163. /**
  164. * @return string|null
  165. */
  166. public function getMimeType(): ?string
  167. {
  168. return $this->mimeType;
  169. }
  170. /**
  171. * @param string|null $mimeType
  172. * @return self
  173. */
  174. public function setMimeType(?string $mimeType): self
  175. {
  176. $this->mimeType = $mimeType;
  177. return $this;
  178. }
  179. }