Skip to content

Commit

Permalink
Merge pull request #64 from werlleyg/refactor/change-structure
Browse files Browse the repository at this point in the history
Refactor/change structure
  • Loading branch information
werlleyg authored Nov 5, 2024
2 parents ba8d729 + a8405c5 commit 5e6a24f
Show file tree
Hide file tree
Showing 44 changed files with 43 additions and 43 deletions.
Empty file removed src/domain/index.ts
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions src/domain/services/ai.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ListMoviesEntity, MovieEntity } from "../entities";

export interface AiService {
generateResponse: (prompt: AiService.Params) => Promise<AiService.Model>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/ai/chatGPTAiClient.infra.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AiClient, AiPrompt, AiResponse } from "@/data/protocols/ai";
import { AiClient, AiPrompt, AiResponse } from "@/domain/protocols/ai";
import { chunkProcessor, G4F } from "g4f";

export class ChatGPTAiClient implements AiClient {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/infrastructure/http/axiosHttpClient.infra.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpRequest, HttpResponse, HttpClient } from "@/data/protocols/http";
import { HttpRequest, HttpResponse, HttpClient } from "@/domain/protocols/http";

import axios, { AxiosResponse } from "axios";

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ListMoviesEntity, MovieEntity } from "@/domain/entities";
import { MoviesRepository } from "@/domain/repositories";
import { HttpClient, HttpStatusCode } from "../protocols/http";
import { HttpClient, HttpStatusCode } from "../../domain/protocols/http";
import { Environment } from "@/main/config";
import {
AccessDeniedError,
NotFoundError,
UnexpectedError,
} from "@/domain/errors";
import { movieFromJson, moviesFromJsonList } from "@/helpers";
import { movieFromJson, moviesFromJsonList } from "@/infrastructure/helpers";

export class MoviesRepositoryImpl implements MoviesRepository {
constructor(private readonly httpClient: HttpClient) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
NotFoundError,
UnexpectedError,
} from "@/domain/errors";
import { HttpClient, HttpStatusCode } from "../protocols/http";
import { HttpClient, HttpStatusCode } from "../../domain/protocols/http";
import { AiService } from "./../../domain/services/ai.service";

export class AiServiceImpl implements AiService {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/main/factories/repositories/movies.factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { makeAxiosHttpClient } from "../http/axiosHttpClient.factory";

Expand Down
2 changes: 1 addition & 1 deletion src/main/factories/services/ai.factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AiServiceImpl } from "@/data/services";
import { AiService } from "@/domain/services";
import { makeAxiosHttpClient } from "../http/axiosHttpClient.factory";
import { Environment } from "@/main/config";
import { AiServiceImpl } from "@/infrastructure/services";

export const makeAiService = (): AiService =>
new AiServiceImpl(makeAxiosHttpClient(), Environment.baseUrlAi);
2 changes: 1 addition & 1 deletion src/main/factories/usecases/getMovie.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetMovieUsecase } from "@/domain/usecases";
import { GetMovieUsecaseImpl } from "@/usecases";
import { makeMoviesRepository } from "../repositories/movies.factory";
import { GetMovieUsecaseImpl } from "@/infrastructure/usecases";

export const makeGetMovieUsecase = (): GetMovieUsecase =>
new GetMovieUsecaseImpl(makeMoviesRepository());
2 changes: 1 addition & 1 deletion src/main/factories/usecases/getMovieSuggestion.factory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GetMovieSuggestionUsecase } from "@/domain/usecases";

import { makeMoviesRepository } from "../repositories/movies.factory";
import { GetMovieSuggestionUsecaseImpl } from "@/usecases/getMovieSuggestion.usecase";
import { makeAiService } from "../services/ai.factory";
import { GetMovieSuggestionUsecaseImpl } from "@/infrastructure/usecases/getMovieSuggestion.usecase";

export const makeGetMovieSuggestionUsecase = (): GetMovieSuggestionUsecase =>
new GetMovieSuggestionUsecaseImpl(makeMoviesRepository(), makeAiService());
2 changes: 1 addition & 1 deletion src/main/factories/usecases/getMovies.factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetMoviesUsecase } from "@/domain/usecases";
import { GetMoviesUsecaseImpl } from "@/usecases";
import { makeMoviesRepository } from "../repositories/movies.factory";
import { GetMoviesUsecaseImpl } from "@/infrastructure/usecases";

export const makeGetMoviesUsecase = (): GetMoviesUsecase =>
new GetMoviesUsecaseImpl(makeMoviesRepository());
1 change: 0 additions & 1 deletion src/pages/api/chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ChatGPTAiClient } from "@/infrastructure/ai/chatGPTAiClient.infra";
import { makeChatGptAiClient } from "@/main/factories/ai/chatGPTAiClient.factory";
import { NextApiRequest, NextApiResponse } from "next";

Expand Down
3 changes: 0 additions & 3 deletions tests/data/mocks/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/domain/mocks/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions tests/infrastructure/http/axiosHttpClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AxiosHttpClient } from "@/infrastructure/http";
import { mockAxios, mockHttpResponse } from "../mocks";
import { mockHttpRequest } from "../../data/mocks";
import { mockAxios, mockHttpRequest, mockHttpResponse } from "../mocks";

import axios from "axios";

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
HttpResponse,
HttpStatusCode,
HttpClient,
} from "@/data/protocols/http";
} from "@/domain/protocols/http";

import { faker } from "@faker-js/faker";

Expand Down
4 changes: 4 additions & 0 deletions tests/infrastructure/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from "./axios.mock";
export * from "./http.mock";
export * from "./moviesRepositoryImpl.mock";
export * from "./aiServiceImpl.mock";
export * from "./movie.mock";
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MoviesRepositoryImpl } from "@/data/repositories/moviesImpl.repository";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories/moviesImpl.repository";
import {
HttpClientSpy,
mockGetMovieRepositoryImpl,
mockGetMoviesRepositoryImpl,
} from "../mocks";
import { HttpStatusCode } from "@/data/protocols/http";
import { HttpStatusCode } from "@/domain/protocols/http";
import { Environment } from "@/main/config";
import {
AccessDeniedError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AiServiceImpl } from "@/data/services";
import { HttpClientSpy, mockGenerateResponse } from "../mocks";
import { Environment } from "@/main/config";
import { HttpStatusCode } from "@/data/protocols/http";
import { HttpStatusCode } from "@/domain/protocols/http";
import {
BadRequestError,
NotFoundError,
UnexpectedError,
} from "@/domain/errors";
import { AiServiceImpl } from "@/infrastructure/services";

type SutTypes = {
sut: AiServiceImpl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { AiServiceImpl } from "@/data/services";
import { GetMovieSuggestionUsecaseImpl } from "@/usecases/getMovieSuggestion.usecase";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { mock } from "jest-mock-extended";
import {
listMoviesMock,
mockGenerateResponse,
movieMock,
} from "./mocks/getMovieSuggestionUsecaseImpl.mock";
} from "../mocks/getMovieSuggestionUsecaseImpl.mock";
import { ListMoviesEntity } from "@/domain/entities";
import { UnexpectedError } from "@/domain/errors";
import { AiServiceImpl } from "@/infrastructure/services";
import { GetMovieSuggestionUsecaseImpl } from "@/infrastructure/usecases/getMovieSuggestion.usecase";

type SutTypes = {
repository: ReturnType<typeof mock<MoviesRepositoryImpl>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { GetMovieUsecaseImpl } from "@/usecases";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { mock } from "jest-mock-extended";
import { movieMock } from "./mocks/getMovieUsecaseImpl.mock";
import { movieMock } from "../mocks/getMovieUsecaseImpl.mock";
import { GetMovieUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
movieRepository: ReturnType<typeof mock<MoviesRepositoryImpl>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { GetMoviesUsecaseImpl } from "@/usecases";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { mock } from "jest-mock-extended";
import { listMoviesMock, movieMock } from "./mocks/getMovieUsecaseImpl.mock";
import { listMoviesMock, movieMock } from "../mocks/getMovieUsecaseImpl.mock";
import { GetMoviesUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
movieRepository: ReturnType<typeof mock<MoviesRepositoryImpl>>;
Expand Down
2 changes: 1 addition & 1 deletion tests/main/factories/repositories/movies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { AxiosHttpClient } from "@/infrastructure/http";

Expand Down
2 changes: 1 addition & 1 deletion tests/main/factories/services/ai.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AiServiceImpl } from "@/data/services";
import { AiService } from "@/domain/services";
import { AxiosHttpClient } from "@/infrastructure/http";
import { AiServiceImpl } from "@/infrastructure/services";
import { Environment } from "@/main/config";

type SutTypes = {
Expand Down
4 changes: 2 additions & 2 deletions tests/main/factories/usecases/getMovie.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { GetMovieUsecase } from "@/domain/usecases";
import { AxiosHttpClient } from "@/infrastructure/http";
import { GetMovieUsecaseImpl } from "@/usecases";
import { GetMovieUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
axiosHttpClient: AxiosHttpClient;
Expand Down
7 changes: 4 additions & 3 deletions tests/main/factories/usecases/getMovieSuggestion.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { AiServiceImpl } from "@/data/services";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";

import { MoviesRepository } from "@/domain/repositories";
import { AiService } from "@/domain/services";
import { GetMovieSuggestionUsecase, GetMoviesUsecase } from "@/domain/usecases";
import { AxiosHttpClient } from "@/infrastructure/http";
import { Environment } from "@/main/config";
import { GetMovieSuggestionUsecaseImpl } from "@/usecases/getMovieSuggestion.usecase";
import { AiServiceImpl } from "@/infrastructure/services";
import { GetMovieSuggestionUsecaseImpl } from "@/infrastructure/usecases/getMovieSuggestion.usecase";

type SutTypes = {
axiosHttpClient: AxiosHttpClient;
Expand Down
4 changes: 2 additions & 2 deletions tests/main/factories/usecases/getMovies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MoviesRepositoryImpl } from "@/data/repositories";
import { MoviesRepositoryImpl } from "@/infrastructure/repositories";
import { MoviesRepository } from "@/domain/repositories";
import { GetMoviesUsecase } from "@/domain/usecases";
import { AxiosHttpClient } from "@/infrastructure/http";
import { GetMoviesUsecaseImpl } from "@/usecases";
import { GetMoviesUsecaseImpl } from "@/infrastructure/usecases";

type SutTypes = {
axiosHttpClient: AxiosHttpClient;
Expand Down

0 comments on commit 5e6a24f

Please sign in to comment.