Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse ajuste resolve a rota, mas ainda mantém o domínio antigo service-areas acoplado ao controller.

Como a issue pede padronização de nomenclatura e separação de responsabilidades, acredito que o ideal seria renomear o domínio para service-types de forma consistente: controller, service, repository, DTOs e Swagger.

Manter /service-areas junto com /service-types só faria sentido como compatibilidade temporária.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.List;

@RequestMapping("/service-areas")
@RequestMapping({ "/service-areas", "/service-types" })
public interface ServiceAreaController {

@Operation(summary = "Cadastrar área de atendimento", description = "Cria uma nova área de atendimento no sistema.", responses = {
Expand Down

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse teste cobre /service-types, mas ainda mantém toda a nomenclatura como ServiceArea.

Como a issue pede padronização, o ideal seria renomear também testes, métodos, services e DTOs para ServiceType.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
class ServiceAreaControllerTest {

private static final String URI = "/service-areas";
private static final String SERVICE_TYPES_URI = "/service-types";

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -150,6 +151,24 @@ void shouldReturnEmptyListWhenThereAreNoServiceAreas() throws Exception {

verify(service).findAllServiceAreas();
}

@Test
@DisplayName("Deve listar areas de atendimento pela rota padronizada /service-types")
void shouldGetAllServiceAreasThroughServiceTypesRoute() throws Exception {
List<ServiceAreaResponseDTO> response = List.of(
new ServiceAreaResponseDTO(1, "Fisioterapia")
);

when(service.findAllServiceAreas()).thenReturn(response);

mockMvc.perform(get(SERVICE_TYPES_URI))
.andExpect(status().isOk())
.andExpect(jsonPath("$.length()").value(1))
.andExpect(jsonPath("$[0].id").value(1))
.andExpect(jsonPath("$[0].area").value("Fisioterapia"));

verify(service).findAllServiceAreas();
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { EditServiceTypePage } from "@/domains/service-types/pages/edit-service-type-page";

export default function Page() {
return <EditServiceTypePage />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ServiceTypesPage } from "@/domains/service-types/pages/service-types-page";

export default function Page() {
return <ServiceTypesPage />;
}

This file was deleted.

103 changes: 0 additions & 103 deletions apps/management-app/src/app/(protected)/tipo-atendimento/page.tsx

This file was deleted.

105 changes: 105 additions & 0 deletions apps/management-app/src/app/api/patients/[id]/documents/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { AxiosError } from "axios";
import { NextRequest, NextResponse } from "next/server";

import { createBaseApi } from "@/lib/axios";

const categoryRouteMap: Record<string, string> = {
medical: "medicals",
medicals: "medicals",
medicos: "medicals",
personal: "personals",
personals: "personals",
pessoais: "personals",
school: "schools",
schools: "schools",
escolares: "schools",
};

function normalizeCategory(category: string | null) {
if (!category) {
return null;
}

return categoryRouteMap[category.toLowerCase()] || null;
}

export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
const category = normalizeCategory(request.nextUrl.searchParams.get("category"));
const year = request.nextUrl.searchParams.get("year");
const type = request.nextUrl.searchParams.get("type");

if (!category) {
return NextResponse.json({ message: "Categoria de documento invalida." }, { status: 400 });
}

try {
const api = await createBaseApi();
const searchParams = new URLSearchParams();

if (year) {
searchParams.set("year", year);
}

const suffix = searchParams.size > 0 ? `?${searchParams.toString()}` : "";
const response = await api.get(`/patients/${id}/documents/${category}${suffix}`);
const documents = Array.isArray(response.data) ? response.data : [];
const filteredDocuments = type
? documents.filter((document: { type?: string }) => document.type === type)
: documents;

return NextResponse.json(filteredDocuments);
} catch (error) {
const err = error as AxiosError;
return NextResponse.json(
{ message: err.response?.data || "Erro ao buscar documentos" },
{ status: err.response?.status || 500 },
);
}
}

export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;

try {
const incomingFormData = await request.formData();
const file = incomingFormData.get("file");
const category = incomingFormData.get("category");
const type = incomingFormData.get("type");
const year = incomingFormData.get("year");

if (!(file instanceof File) || typeof category !== "string" || typeof type !== "string") {
return NextResponse.json({ message: "Dados de upload invalidos." }, { status: 400 });
}

const formData = new FormData();
formData.append("file", file);
formData.append("category", category);
formData.append("type", type);

if (typeof year === "string" && year.trim()) {
formData.append("year", year);
}

const api = await createBaseApi();
const response = await api.post(`/patients/${id}/documents`, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});

return NextResponse.json(response.data, { status: response.status });
} catch (error) {
const err = error as AxiosError;
return NextResponse.json(
{ message: err.response?.data || "Erro ao enviar documento" },
{ status: err.response?.status || 500 },
);
}
}
Loading