-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from werlleyg/refactor/change-usecase-structure
Refactor/change usecase structure
- Loading branch information
Showing
23 changed files
with
87 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "quefilme", | ||
"version": "0.0.6", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { MovieEntity } from "../entities"; | ||
import { MoviesRepository } from "@/domain/repositories"; | ||
import { GetMovieUsecase } from "@/domain/usecases/interfaces"; | ||
|
||
export interface GetMovieUsecase { | ||
exec: (params: GetMovieUsecase.Params) => Promise<GetMovieUsecase.Model>; | ||
} | ||
export class GetMovieUsecaseImpl implements GetMovieUsecase { | ||
constructor(private readonly repository: MoviesRepository) {} | ||
|
||
export namespace GetMovieUsecase { | ||
export type Params = string; | ||
export type Model = MovieEntity; | ||
async exec(imdbID: GetMovieUsecase.Params): Promise<GetMovieUsecase.Model> { | ||
return await this.repository.getMovie(imdbID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import { ListMoviesEntity, MovieEntity } from "../entities"; | ||
import { UnexpectedError } from "@/domain/errors"; | ||
import { MoviesRepository } from "@/domain/repositories"; | ||
import { AiService } from "@/domain/services"; | ||
import { GetMovieSuggestionUsecase } from "@/domain/usecases/interfaces"; | ||
|
||
export interface GetMovieSuggestionUsecase { | ||
exec: ( | ||
export class GetMovieSuggestionUsecaseImpl | ||
implements GetMovieSuggestionUsecase | ||
{ | ||
constructor( | ||
private readonly repository: MoviesRepository, | ||
private readonly service: AiService, | ||
) {} | ||
async exec( | ||
params: GetMovieSuggestionUsecase.Params, | ||
) => Promise<GetMovieSuggestionUsecase.Model>; | ||
} | ||
): Promise<GetMovieSuggestionUsecase.Model> { | ||
const listOfMovies = params.movies.map((movie) => movie.title).join(", "); | ||
|
||
const prompt = `Seja direto e siga exatamente o exemplo proposto a seguir após os dois pontos, me indique apenas um filme baseado na lista ${listOfMovies}, mas não pode ser nenhum dessa lista e nem repetir a sugestão anterior, seja criativo na escolha mas retorne algo que combine com os itens de lista, e coloque seu imdb CORRETO no final, ex: Cidade de Deus - tt0317248`; | ||
|
||
const promptResponse = await this.service.generateResponse(prompt); | ||
|
||
const parts = promptResponse?.split(" - "); | ||
if (!parts || parts?.length < 2) { | ||
throw new UnexpectedError(); | ||
} | ||
const suggestMovieImdb = parts[1]; | ||
|
||
export namespace GetMovieSuggestionUsecase { | ||
export type Params = ListMoviesEntity; | ||
export type Model = MovieEntity; | ||
return await this.repository.getMovie(suggestMovieImdb); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { ListMoviesEntity } from "../entities"; | ||
import { MoviesRepository } from "@/domain/repositories"; | ||
import { GetMoviesUsecase } from "@/domain/usecases/interfaces"; | ||
|
||
export interface GetMoviesUsecase { | ||
exec: (params: GetMoviesUsecase.Params) => Promise<GetMoviesUsecase.Model>; | ||
} | ||
export class GetMoviesUsecaseImpl implements GetMoviesUsecase { | ||
constructor(private readonly repository: MoviesRepository) {} | ||
|
||
export namespace GetMoviesUsecase { | ||
export type Params = string; | ||
export type Model = ListMoviesEntity; | ||
async exec(title: GetMoviesUsecase.Params): Promise<GetMoviesUsecase.Model> { | ||
return await this.repository.getMovieList(title.trim().toLowerCase()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from "./getMovie.usecase"; | ||
export * from "./getMovies.usecase"; | ||
export * from "./getMovieSuggestion.usecase"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { MovieEntity } from "../../entities"; | ||
|
||
export interface GetMovieUsecase { | ||
exec: (params: GetMovieUsecase.Params) => Promise<GetMovieUsecase.Model>; | ||
} | ||
|
||
export namespace GetMovieUsecase { | ||
export type Params = string; | ||
export type Model = MovieEntity; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/domain/usecases/interfaces/getMovieSuggestion.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ListMoviesEntity, MovieEntity } from "../../entities/"; | ||
|
||
export interface GetMovieSuggestionUsecase { | ||
exec: ( | ||
params: GetMovieSuggestionUsecase.Params, | ||
) => Promise<GetMovieSuggestionUsecase.Model>; | ||
} | ||
|
||
export namespace GetMovieSuggestionUsecase { | ||
export type Params = ListMoviesEntity; | ||
export type Model = MovieEntity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ListMoviesEntity } from "../../entities"; | ||
|
||
export interface GetMoviesUsecase { | ||
exec: (params: GetMoviesUsecase.Params) => Promise<GetMoviesUsecase.Model>; | ||
} | ||
|
||
export namespace GetMoviesUsecase { | ||
export type Params = string; | ||
export type Model = ListMoviesEntity; | ||
} |
1 change: 1 addition & 0 deletions
1
src/infrastructure/usecases/index.ts → src/domain/usecases/interfaces/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./getMovie.usecase"; | ||
export * from "./getMovies.usecase"; | ||
export * from "./getMovieSuggestion.usecase"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { GetMovieUsecase } from "@/domain/usecases"; | ||
import { GetMovieUsecase } from "@/domain/usecases/interfaces"; | ||
import { makeMoviesRepository } from "../repositories/movies.factory"; | ||
import { GetMovieUsecaseImpl } from "@/infrastructure/usecases"; | ||
import { GetMovieUsecaseImpl } from "@/domain/usecases"; | ||
|
||
export const makeGetMovieUsecase = (): GetMovieUsecase => | ||
new GetMovieUsecaseImpl(makeMoviesRepository()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { GetMovieSuggestionUsecase } from "@/domain/usecases"; | ||
import { GetMovieSuggestionUsecase } from "@/domain/usecases/interfaces"; | ||
|
||
import { makeMoviesRepository } from "../repositories/movies.factory"; | ||
import { makeAiService } from "../services/ai.factory"; | ||
import { GetMovieSuggestionUsecaseImpl } from "@/infrastructure/usecases/getMovieSuggestion.usecase"; | ||
import { GetMovieSuggestionUsecaseImpl } from "@/domain/usecases/getMovieSuggestion.usecase"; | ||
|
||
export const makeGetMovieSuggestionUsecase = (): GetMovieSuggestionUsecase => | ||
new GetMovieSuggestionUsecaseImpl(makeMoviesRepository(), makeAiService()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { GetMoviesUsecase } from "@/domain/usecases"; | ||
import { GetMoviesUsecase } from "@/domain/usecases/interfaces"; | ||
import { makeMoviesRepository } from "../repositories/movies.factory"; | ||
import { GetMoviesUsecaseImpl } from "@/infrastructure/usecases"; | ||
import { GetMoviesUsecaseImpl } from "@/domain/usecases"; | ||
|
||
export const makeGetMoviesUsecase = (): GetMoviesUsecase => | ||
new GetMoviesUsecaseImpl(makeMoviesRepository()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters