Skip to content

Commit

Permalink
feat: arquivo: dtos
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed Mar 29, 2024
1 parent 54a8a08 commit 5c33eb5
Show file tree
Hide file tree
Showing 23 changed files with 414 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './IArquivoModel';
export * from './operations';
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './IImagemArquivoModel';
export * from './operations';
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './IImagemModel';
export * from './operations';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { ApiBody, ApiConsumes, ApiProduces, ApiTags } from '@nestjs/swagger';
import { Paginate, PaginateQuery } from 'nestjs-paginate';
import * as Dto from '../../(spec)';
import { IContextoDeAcesso } from '../../../../domain';
Expand Down Expand Up @@ -44,6 +44,7 @@ export class BlocoController {
}

@Get('/:id/imagem/capa')
@ApiProduces('application/octet-stream', 'image/jpeg')
@DtoOperationFindOne(BlocoOperations.BLOCO_GET_IMAGEM_CAPA)
async blocoGetImagemCapa(
@ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ValidationContractUuid, createDtoOperationOptions } from '../../../../.
// ======================================================

export const BLOCO_GET_IMAGEM_CAPA = createDtoOperationOptions({
description: 'Realiza a consulta a um bloco por ID.',
description: 'Obtêm a imagem de capa do bloco.',

gql: null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
createDtoPropertyMap,
createValidationContract,
} from '../../../../../infrastructure';
import { ImagemDto, ImagemFindOneResultDto } from '../../../base/imagem/dtos';
import { CampusDto, CampusFindOneResultDto } from '../../campus/dtos';

// ======================================================
Expand Down Expand Up @@ -81,6 +82,18 @@ export const BlocoDtoProperties = createDtoPropertyMap({
type: () => CampusFindOneResultDto,
},
},

BLOCO_IMAGEM_CAPA_OUTPUT: {
nullable: true,
description: 'Imagem de capa do bloco.',
//
gql: {
type: () => ImagemDto,
},
swagger: {
type: ImagemFindOneResultDto,
},
},
});

// ======================================================
Expand All @@ -103,9 +116,11 @@ export class BlocoDto implements Dto.IBlocoModel {

//

ambientes!: Dto.IAmbienteModel[];
@DtoProperty(BlocoDtoProperties.BLOCO_IMAGEM_CAPA_OUTPUT)
imagemCapa!: IImagemModel | null;

//
ambientes!: Dto.IAmbienteModel[];
//

dateCreated!: Dto.IEntityDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller, Get, StreamableFile } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ApiProduces, ApiTags } from '@nestjs/swagger';
import { IContextoDeAcesso } from '../../../../domain';
import { ContextoDeAcessoHttp, DtoOperationFindOne, HttpDtoParam } from '../../../../infrastructure';
import { HttpDtoQuery } from '../../../../infrastructure/api-documentate/HttpDtoQuery';
Expand All @@ -12,6 +12,7 @@ export class ArquivoController {
constructor(private arquivoService: ArquivoService) {}

@Get(':id')
@ApiProduces('application/octet-stream')
@DtoOperationFindOne(ArquivoOperations.ARQUIVO_GET_FILE)
async getFile(
@ContextoDeAcessoHttp() contextoDeAcesso: IContextoDeAcesso,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ObjectType } from '@nestjs/graphql';
import * as Dto from '../../../(spec)';
import { DtoProperty } from '../../../../../infrastructure';
import { ArquivoDtoProperties } from './arquivo.dto';

// ======================================================

@ObjectType('ArquivoFindOneResultDto')
export class ArquivoFindOneResultDto implements Dto.IArquivoFindOneResultDto {
@DtoProperty(ArquivoDtoProperties.ARQUIVO_ID)
id!: string;

//

@DtoProperty(ArquivoDtoProperties.ARQUIVO_NOME)
nome!: string | null;

@DtoProperty(ArquivoDtoProperties.ARQUIVO_MIME_TYPE)
mimeType!: string | null;

@DtoProperty(ArquivoDtoProperties.ARQUIVO_SIZE_BYTES)
sizeBytes!: number | null;

@DtoProperty(ArquivoDtoProperties.ARQUIVO_STORAGE_TYPE)
storageType!: string | null;
}

// ======================================================
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export const ARQUIVO_GET_FILE = createDtoOperationOptions({
gql: null,

swagger: {
returnType: '',
returnType: {
schema: {
type: 'string',
format: 'binary',
},
},

params: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Int, ObjectType } from '@nestjs/graphql';
import { ObjectType } from '@nestjs/graphql';
import * as yup from 'yup';
import * as Dto from '../../../(spec)';
import {
CommonPropertyInteger,
CommonPropertyString,
CommonPropertyUuid,
DtoProperty,
ValidationContractNumber,
Expand All @@ -13,65 +15,52 @@ import {

// ======================================================

export const DisciplinaDtoValidationContract = createValidationContract(() => {
export const ArquivoDtoValidationContract = createValidationContract(() => {
return yup.object({
id: ValidationContractUuid(),

//

nome: ValidationContractString().required().nonNullable(), // disciplina
cargaHoraria: ValidationContractNumber().required().nonNullable().integer().moreThan(0), // disciplina

//
nome: ValidationContractString().nullable(),
mimeType: ValidationContractString().nullable(),
//
sizeBytes: ValidationContractNumber().integer().positive().required().nullable(),
storageType: ValidationContractString().nullable(),
});
});

// ======================================================

export const DisciplinaDtoProperties = createDtoPropertyMap({
DISCIPLINA_ID: CommonPropertyUuid('ID de "disciplina"'),
export const ArquivoDtoProperties = createDtoPropertyMap({
ARQUIVO_ID: CommonPropertyUuid('ID do arquivo'),

//

DISCIPLINA_NOME: {
nullable: false,
description: 'Nome da disciplina.',
//
gql: {
type: () => String,
},
swagger: {
type: 'string',
},
},
DISCIPLINA_CARGA_HORARIA: {
nullable: false,
description: 'Carga horária da disciplina.',
//
gql: {
type: () => Int,
},
swagger: {
type: 'integer',
},
},
//
ARQUIVO_NOME: CommonPropertyString('Nome do arquivo', true),
ARQUIVO_MIME_TYPE: CommonPropertyString('Mime-type do arquivo', true),
ARQUIVO_SIZE_BYTES: CommonPropertyInteger('Tamanho do arquivo (em bytes)', true),
ARQUIVO_STORAGE_TYPE: CommonPropertyString('Estratégia de armazenamento do arquivo', true),
});

// ======================================================

@ObjectType('Disciplina')
export class DisciplinaDto implements Dto.IDisciplinaModel {
@DtoProperty(DisciplinaDtoProperties.DISCIPLINA_ID)
@ObjectType('Arquivo')
export class ArquivoDto implements Dto.IArquivoModel {
@DtoProperty(ArquivoDtoProperties.ARQUIVO_ID)
id!: string;

//

@DtoProperty(DisciplinaDtoProperties.DISCIPLINA_NOME)
nome!: string;
@DtoProperty(ArquivoDtoProperties.ARQUIVO_NOME)
nome!: string | null;

@DtoProperty(ArquivoDtoProperties.ARQUIVO_MIME_TYPE)
mimeType!: string | null;

@DtoProperty(ArquivoDtoProperties.ARQUIVO_SIZE_BYTES)
sizeBytes!: number | null;

@DtoProperty(DisciplinaDtoProperties.DISCIPLINA_CARGA_HORARIA)
cargaHoraria!: number;
@DtoProperty(ArquivoDtoProperties.ARQUIVO_STORAGE_TYPE)
storageType!: string | null;

//

Expand Down
3 changes: 2 additions & 1 deletion luna-backend/src/application/business/base/base.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Module } from '@nestjs/common';
import { ArquivoModule } from './arquivo/arquivo.module';
import { ImagemArquivoModule } from './imagem-arquivo/imagem-arquivo.module';
import { ImagemModule } from './imagem/imagem.module';

@Module({
imports: [ImagemModule, ArquivoModule],
imports: [ImagemModule, ArquivoModule, ImagemArquivoModule],
controllers: [],
providers: [],
exports: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ObjectType } from '@nestjs/graphql';
import * as Dto from '../../../(spec)';
import { DtoProperty } from '../../../../../infrastructure';
import { ImagemArquivoDtoProperties } from './imagem-arquivo.dto';

// ======================================================

@ObjectType('ImagemArquivoFindOneResultDto')
export class ImagemArquivoFindOneResultDto implements Dto.IImagemArquivoFindOneResultDto {
@DtoProperty(ImagemArquivoDtoProperties.IMAGEM_ARQUIVO_ID)
id!: string;

//
@DtoProperty(ImagemArquivoDtoProperties.IMAGEM_ARQUIVO_LARGURA)
largura!: number;
@DtoProperty(ImagemArquivoDtoProperties.IMAGEM_ARQUIVO_ALTURA)
altura!: number;
//
@DtoProperty(ImagemArquivoDtoProperties.IMAGEM_ARQUIVO_FORMATO)
formato!: string;
@DtoProperty(ImagemArquivoDtoProperties.IMAGEM_ARQUIVO_MIME_TYPE)
mimeType!: string;
//

//
@DtoProperty(ImagemArquivoDtoProperties.IMAGEM_ARQUIVO_IMAGEM_OUTPUT)
imagem!: Dto.IImagemModel;
@DtoProperty(ImagemArquivoDtoProperties.IMAGEM_ARQUIVO_ARQUIVO_OUTPUT)
arquivo!: Dto.IArquivoModel;
//
}

// ======================================================
Loading

0 comments on commit 5c33eb5

Please sign in to comment.