-
Notifications
You must be signed in to change notification settings - Fork 1
add mongo db atlas, free tier and use cases services #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leandro-codee
wants to merge
1
commit into
tuttodev:main
Choose a base branch
from
leandro-codee:feature/add-mongodb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| import { ContentCreator } from "../../domain/entities/content-creator"; | ||
| import { ContentCreatorRepository } from "../../domain/repositories/ContentCreatorRepository"; | ||
|
|
||
| export class ContentCreatorSave { | ||
| constructor( | ||
| private readonly contentCreatorRepository: ContentCreatorRepository | ||
| ) {} | ||
|
|
||
| async execute( | ||
| contentCreatorPayload: Omit<ContentCreator, "id"> | ||
| ): Promise<ContentCreator> { | ||
| return await this.contentCreatorRepository.save(contentCreatorPayload); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,14 @@ | ||
| import { PrismaClient } from "@prisma/client" | ||
|
|
||
| export class PrismaDBClient { | ||
| private static _INSTANCE: PrismaClient | ||
|
|
||
| static getInstance(): PrismaClient { | ||
| if (this._INSTANCE === undefined) { | ||
| this._INSTANCE = new PrismaClient() | ||
| } | ||
|
|
||
| return this._INSTANCE | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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,30 @@ | ||
| // This is your Prisma schema file, | ||
| // learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
|
||
| // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? | ||
| // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init | ||
|
|
||
| generator client { | ||
| provider = "prisma-client-js" | ||
| } | ||
|
|
||
| datasource db { | ||
| provider = "mongodb" | ||
| url = env("DATABASE_URL") | ||
| } | ||
|
|
||
| model ContentCreator { | ||
| id String @id @default(auto()) @map("_id") @db.ObjectId | ||
| name String @unique | ||
| language String | ||
| logoUrl String | ||
| socialNetworks SocialNetworks @map("socialnetworks") | ||
| } | ||
|
|
||
| type SocialNetworks { | ||
| ig String[] | ||
| youtube String[] | ||
| x String[] | ||
| twitch String[] | ||
| github String[] | ||
| } |
This file contains hidden or 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,132 @@ | ||
| import { PrismaDBClient } from "."; | ||
| import { ContentCreator } from "../../../domain/entities/content-creator"; | ||
|
|
||
| const prismaClient = PrismaDBClient.getInstance(); | ||
|
|
||
| async function main() { | ||
| const contentCreators: ContentCreator[] = [ | ||
| { | ||
| name: "tuttodev", | ||
| language: "spanish", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/tuttodev.png", | ||
| socialNetworks: { | ||
| ig: ["tuttodev"], | ||
| youtube: ["@tuttodev"], | ||
| twitch: [], | ||
| x: ["tuttodevv"], | ||
| github: ["tuttodev"], | ||
| }, | ||
| }, | ||
| { | ||
| name: "midudev", | ||
| language: "spanish", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/midudev.png", | ||
| socialNetworks: { | ||
| ig: ["midu.dev"], | ||
| youtube: ["@midudev", "@midulive"], | ||
| twitch: ["midudev"], | ||
| x: ["midudev"], | ||
| github: ["midudev"], | ||
| }, | ||
| }, | ||
| { | ||
| name: "NetworkChuck", | ||
| language: "english", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/networkchuck.png", | ||
| socialNetworks: { | ||
| ig: ["networkchuck"], | ||
| youtube: ["@NetworkChuck"], | ||
| twitch: ["networkchuck"], | ||
| x: ["networkchuck"], | ||
| github: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "Fazt", | ||
| language: "spanish", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/fazt.png", | ||
| socialNetworks: { | ||
| ig: ["fazttech"], | ||
| youtube: ["@FaztCode", "@FaztTech"], | ||
| x: ["FaztTech"], | ||
| github: ["fazt", "faztcommunity", "FaztWeb"], | ||
| twitch: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "Programador X", | ||
| language: "spanish", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/programador-x.png", | ||
| socialNetworks: { | ||
| ig: ["programador.x"], | ||
| youtube: ["@ProgramadorX"], | ||
| x: ["programador_x_"], | ||
| github: [], | ||
| twitch: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "MoureDev", | ||
| language: "spanish", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/mouredev.png", | ||
| socialNetworks: { | ||
| ig: ["mouredev"], | ||
| youtube: ["@mouredevtv"], | ||
| x: ["MoureDev"], | ||
| twitch: ["mouredev"], | ||
| github: ["mouredev"], | ||
| }, | ||
| }, | ||
| { | ||
| name: "Traversy Media", | ||
| language: "english", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/traversy-media.png", | ||
| socialNetworks: { | ||
| ig: ["traversymedia"], | ||
| youtube: ["@TraversyMedia"], | ||
| x: ["traversymedia"], | ||
| github: ["bradtraversy"], | ||
| twitch: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "developedbyed", | ||
| language: "english", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/developedbyed.png", | ||
| socialNetworks: { | ||
| ig: ["developedbyed"], | ||
| youtube: ["@developedbyed"], | ||
| x: ["developedbyed"], | ||
| github: [], | ||
| twitch: [], | ||
| }, | ||
| }, | ||
| { | ||
| name: "munoncode", | ||
| language: "spanish", | ||
| logoUrl: "https://resources.creadoresapi.com/logos/munoncode.png", | ||
| socialNetworks: { | ||
| ig: ["munoncode"], | ||
| youtube: ["@munoncode"], | ||
| github: [], | ||
| twitch: [], | ||
| x: [], | ||
| }, | ||
| }, | ||
| ] as unknown as any; | ||
|
|
||
| for (const creator of contentCreators) { | ||
| await prismaClient.contentCreator.create({ | ||
| data: creator as any, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| main() | ||
| .catch((e) => { | ||
| console.error(e); | ||
| process.exit(1); | ||
| }) | ||
| .finally(async () => { | ||
| await prismaClient.$disconnect(); | ||
| }); |
19 changes: 17 additions & 2 deletions
19
infrastructure/entry/express/routes/v1/content-creator/index.ts
This file contains hidden or 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,18 +1,33 @@ | ||
| import { Request, Response } from 'express' | ||
| import Router from 'express-promise-router' | ||
| import { ContentCreatorGetter } from '../../../../../../application/usecases/ContentCreatorGetter' | ||
| import { JSONFileContentCreatorRepository } from '../../../../../persistence/json/JSONFileContentCreatorRepository' | ||
| import { MongoContentCreatorRepository } from '../../../../../persistence/mongodb/MongoContentCreatorRepository' | ||
| import { ContentCreatorSave } from '../../../../../../application/usecases/ContentCreatorSave' | ||
| import { contentCreatorSchema } from '../../../utils/contentCreatorSchema' | ||
|
|
||
| const router = Router() | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
| router.get('/', async (_req: Request, res: Response): Promise<void> => { | ||
| const repository = new JSONFileContentCreatorRepository() | ||
| const repository = new MongoContentCreatorRepository() | ||
| const usecase = new ContentCreatorGetter(repository) | ||
|
|
||
| const contentCreators = await usecase.execute() | ||
|
|
||
| res.json(contentCreators) | ||
| }) | ||
|
|
||
| router.post("/", async (req: Request, res: Response): Promise<void> => { | ||
| const repository = new MongoContentCreatorRepository() | ||
| const usecase = new ContentCreatorSave(repository) | ||
|
|
||
| const contentCreatorPayloadValidated = contentCreatorSchema.safeParse(req.body) | ||
| if (contentCreatorPayloadValidated.success) { | ||
| const newContentCreator = await usecase.execute(contentCreatorPayloadValidated.data) | ||
| res.status(200).json(newContentCreator) | ||
| } else { | ||
| res.status(400).json(contentCreatorPayloadValidated.error) | ||
| } | ||
| }) | ||
|
|
||
| export default router |
14 changes: 14 additions & 0 deletions
14
infrastructure/entry/express/utils/contentCreatorSchema.ts
This file contains hidden or 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,14 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const contentCreatorSchema = z.object({ | ||
| name: z.string(), | ||
| language: z.string(), | ||
| logoUrl: z.string(), | ||
| socialNetworks: z.object({ | ||
| ig: z.array(z.string()).nullable(), | ||
| youtube: z.array(z.string()).nullable(), | ||
| x: z.array(z.string()).nullable(), | ||
| twitch: z.array(z.string()).nullable(), | ||
| github: z.array(z.string()).nullable(), | ||
| }), | ||
| }); |
This file contains hidden or 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
63 changes: 63 additions & 0 deletions
63
infrastructure/persistence/mongodb/MongoContentCreatorRepository.ts
This file contains hidden or 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,63 @@ | ||
| import { ContentCreator } from "../../../domain/entities/content-creator"; | ||
| import { ContentCreatorRepository } from "../../../domain/repositories/ContentCreatorRepository"; | ||
| import { PrismaDBClient } from "../../driven-adapters/prisma"; | ||
|
|
||
| export class MongoContentCreatorRepository implements ContentCreatorRepository { | ||
| private _prismaClient = PrismaDBClient.getInstance(); | ||
|
|
||
| async getAll(): Promise<ContentCreator[]> { | ||
| const contentCreators = await this._prismaClient.contentCreator.findMany(); | ||
| console.log("Esto viene desde el Cluster Mongo DB Atlas"); | ||
| console.log(contentCreators); | ||
| return contentCreators.map((contentCreator) => { | ||
| return { | ||
| id: contentCreator.id, | ||
| name: contentCreator.name, | ||
| language: contentCreator.language, | ||
| logoUrl: contentCreator.logoUrl, | ||
| socialNetworks: { | ||
| ig: contentCreator.socialNetworks.ig, | ||
| youtube: contentCreator.socialNetworks.youtube, | ||
| x: contentCreator.socialNetworks.x, | ||
| twitch: contentCreator.socialNetworks.twitch, | ||
| github: contentCreator.socialNetworks.github, | ||
| }, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| async save( | ||
| contentCreatorPayload: Omit<ContentCreator, "id"> | ||
| ): Promise<ContentCreator> { | ||
| const savedContentCreator: ContentCreator = | ||
| await this._prismaClient.contentCreator.create({ | ||
| data: { | ||
| ...contentCreatorPayload, | ||
| socialNetworks: { | ||
| ig: | ||
| contentCreatorPayload.socialNetworks.ig === null | ||
| ? [] | ||
| : contentCreatorPayload.socialNetworks.ig, | ||
| youtube: | ||
| contentCreatorPayload.socialNetworks.youtube === null | ||
| ? [] | ||
| : contentCreatorPayload.socialNetworks.youtube, | ||
| x: | ||
| contentCreatorPayload.socialNetworks.x === null | ||
| ? [] | ||
| : contentCreatorPayload.socialNetworks.x, | ||
| twitch: | ||
| contentCreatorPayload.socialNetworks.twitch === null | ||
| ? [] | ||
| : contentCreatorPayload.socialNetworks.twitch, | ||
| github: | ||
| contentCreatorPayload.socialNetworks.github === null | ||
| ? [] | ||
| : contentCreatorPayload.socialNetworks.github, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| return savedContentCreator; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
console.log