-
Notifications
You must be signed in to change notification settings - Fork 7
Feature/add image guardian #119
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
andersonnaz
wants to merge
19
commits into
develop
Choose a base branch
from
feature/add-image-guardian
base: develop
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
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e00990f
chore: removed deprecated version and put especifc version on docker …
andersonnaz defc19d
feat: add image field on database
andersonnaz 7acfb11
feat: create update image on guardian repository
andersonnaz 5a237d6
refactor: change pet image field name
andersonnaz c2e04c1
feat: add image field and new dependencies on add guardian use case
andersonnaz 3826a63
feat: updated to receive image on create guardian use case implementa…
andersonnaz 1f704b1
feat: updated to get image on signup controller
andersonnaz 78f5c1c
feat: add upload middleware on signup route
andersonnaz 8bb1b15
feat: updated add guardian use case implementation factory
andersonnaz a448a61
docs: update documentation with new type of request on signup route
andersonnaz f6d44db
fix: add verification if guardian already exists
andersonnaz 05c9cee
test: add methods in mocks and stubs to test add guardian image field
andersonnaz 98c9ed5
test: add image field on signup
andersonnaz ccbd100
test: add image field and filestorage dependencies on add guardian us…
andersonnaz 634c85d
test: add default image field on add pet use case
andersonnaz d960a82
test: delete property of fakeUser in pet route
andersonnaz 032abca
test: change test structure to multpart form data in signup route
andersonnaz 74f150a
Update src/infra/repos/postgresql/guardian-account-repository.ts
andersonnaz a3a41ae
refactor: change select to omit in prisma update query
andersonnaz 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
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
19 changes: 19 additions & 0 deletions
19
src/data/protocols/db/guardian/update-guardian-image-repository.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,19 @@ | ||
| export interface UpdateGuardianImageRepository { | ||
| updateImage: (params: UpdateGuardianImageRepository.Params) => Promise<UpdateGuardianImageRepository.Result> | ||
| } | ||
|
|
||
| export namespace UpdateGuardianImageRepository { | ||
| export type Params = { | ||
| guardianId: string | ||
| image?: string | ||
| } | ||
|
|
||
| export type Result = { | ||
| id: string | ||
| firstName: string | ||
| lastName: string | ||
| email: string | ||
| phone: string | ||
| image: string | ||
| } | undefined | ||
| } |
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,17 +1,43 @@ | ||
| import { type AddGuardian } from '@/domain/use-cases' | ||
| import { type AddGuardianRepository, type HashGenerator } from '@/data/protocols' | ||
| import { type FileStorage, type AddGuardianRepository, type HashGenerator, type UpdateGuardianImageRepository } from '@/data/protocols' | ||
|
|
||
| export class DbAddGuardian implements AddGuardian { | ||
| private readonly guardianRepository: AddGuardianRepository | ||
| private readonly guardianRepository: AddGuardianRepository & UpdateGuardianImageRepository | ||
| private readonly hashService: HashGenerator | ||
| private readonly fileStorage: FileStorage | ||
| private readonly defaultGuardianImageUrl: string | ||
|
|
||
| constructor ({ guardianRepository, hashService }: AddGuardian.Dependencies) { | ||
| constructor ({ guardianRepository, hashService, fileStorage, defaultGuardianImageUrl }: AddGuardian.Dependencies) { | ||
| this.guardianRepository = guardianRepository | ||
| this.hashService = hashService | ||
| this.fileStorage = fileStorage | ||
| this.defaultGuardianImageUrl = defaultGuardianImageUrl | ||
| } | ||
|
|
||
| async add (guardianData: AddGuardian.Params): Promise<AddGuardian.Result> { | ||
| const hashedPassword = await this.hashService.encrypt({ value: guardianData.password }) | ||
| return await this.guardianRepository.add(Object.assign({}, guardianData, { password: hashedPassword })) | ||
| const guardian = await this.guardianRepository.add(Object.assign({}, { ...guardianData, image: '' }, { password: hashedPassword })) | ||
|
|
||
| if (!guardian) { | ||
| return undefined | ||
| } | ||
|
|
||
| let imageUrl: string = '' | ||
| if (guardianData.image) { | ||
| imageUrl = await this.fileStorage.save({ file: guardianData.image, fileName: `images/guardian-${guardian?.id}` }) | ||
| } | ||
|
|
||
| if (imageUrl) { | ||
| await this.guardianRepository.updateImage({ guardianId: guardian?.id, image: imageUrl }) | ||
| } | ||
|
|
||
| return { | ||
| id: guardian?.id, | ||
| email: guardian?.email, | ||
| firstName: guardian?.firstName, | ||
| lastName: guardian?.lastName, | ||
| phone: guardian?.phone, | ||
| image: imageUrl ?? this.defaultGuardianImageUrl | ||
| } | ||
| } | ||
| } |
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
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
2 changes: 2 additions & 0 deletions
2
src/infra/repos/postgresql/prisma/migrations/20260207183158_add_image_guardian/migration.sql
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,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "guardians" ADD COLUMN "image" TEXT NOT NULL DEFAULT ''; |
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
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 |
|---|---|---|
|
|
@@ -13,6 +13,9 @@ export const guardianSchema = { | |
| }, | ||
| phone: { | ||
| type: 'string' | ||
| }, | ||
| image: { | ||
| type: 'binary' | ||
| } | ||
| } | ||
| } | ||
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
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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import { type Router } from 'express' | ||
| import { adaptRoute } from '@/main/adapters' | ||
| import { makeSignUpController } from '@/main/factories' | ||
| import { upload } from '../middlewares' | ||
|
|
||
| export default (router: Router): void => { | ||
| router.post('/signup', adaptRoute(makeSignUpController())) | ||
| router.post('/signup', upload, adaptRoute(makeSignUpController())) | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.