-
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.
feat: Implement Firebase integration with Eyedrops and Database repos…
…itories; add EXAME_STATUS enum; enhance Exame model with status management; update MainPage for data synchronization
- Loading branch information
Showing
19 changed files
with
2,262 additions
and
242 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
Large diffs are not rendered by default.
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
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,34 @@ | ||
import { ExameService } from "src/app/services/exame.service" | ||
import { DatabaseRepository } from "./DatabaseRepository" | ||
import firebase from "firebase/compat/app" | ||
import "firebase/firestore" | ||
|
||
const firebaseConfig = { | ||
apiKey: "AIzaSyDpMfldg10XJfdkap0lsQkfaFTzbVTv3Lo", | ||
authDomain: "grade-anp-testes.firebaseapp.com", | ||
projectId: "grade-anp-testes", | ||
storageBucket: "grade-anp-testes.firebasestorage.app", | ||
messagingSenderId: "486118580910", | ||
appId: "1:486118580910:web:de3c6d36d5b1672d86c33f", | ||
} | ||
|
||
export const DatabaseProvider = [ | ||
// provider for ExameService | ||
{ | ||
provide: ExameService, | ||
useFactory: (repository: any) => { | ||
return new ExameService(repository) | ||
}, | ||
inject: [DatabaseRepository], | ||
}, | ||
// provider for DatabaseRepository | ||
{ | ||
provide: "EYEDROPS_REPOSITORY", | ||
useClass: DatabaseRepository, | ||
}, | ||
// provider for firebase | ||
{ | ||
provide: firebase.initializeApp(firebaseConfig), | ||
useValue: firebase.initializeApp(firebaseConfig), | ||
}, | ||
] |
Empty file.
79 changes: 79 additions & 0 deletions
79
src/app/Repository/DatabaseRepository/DatabaseRepository.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,79 @@ | ||
import { Injectable } from "@angular/core" | ||
import { AngularFirestore, CollectionReference } from "@angular/fire/compat/firestore" | ||
import { EyedropsRepository } from "../EyedropsRepository" | ||
import { Exame } from "src/app/models" | ||
import "firebase/compat/firestore" | ||
|
||
@Injectable({ | ||
providedIn: "root", | ||
}) | ||
export class DatabaseRepository implements EyedropsRepository { | ||
eyedropsCollection: CollectionReference | ||
|
||
constructor(private firestore: AngularFirestore) { | ||
this.eyedropsCollection = this.firestore.collection("eyedrops").ref | ||
this.getByCodigo("0123/2024 GO") | ||
.then((exame) => { | ||
console.log("exame", exame) | ||
}) | ||
.catch((error) => { | ||
console.error("Error getting document: ", error) | ||
}) | ||
} | ||
async getByCodigo(codigo: string): Promise<any> { | ||
try { | ||
const eyedropsRef = this.eyedropsCollection.where("codigo", "==", codigo) | ||
const eyedropsQuery = await eyedropsRef.limit(1).get() | ||
if (eyedropsQuery.empty) return null | ||
const exame: Exame = await eyedropsQuery.docs.map(async (doc: any) => { | ||
const data: any = { | ||
...doc.data(), | ||
id: doc.id, | ||
exame: doc.data(), | ||
} | ||
return data | ||
})[0] | ||
return exame | ||
} catch (error) { | ||
console.error(`Erro ao buscar documento codigo:${codigo}`, error) | ||
throw error | ||
} | ||
} | ||
getByUF(codigo: string): Promise<any[]> { | ||
throw new Error("Method not implemented.") | ||
} | ||
|
||
async save(exame: Exame): Promise<void> { | ||
try { | ||
const query = await this.eyedropsCollection.where("codigo", "==", exame.material.codigo).get() | ||
if (query.empty) { | ||
console.log("save - create", query.empty) | ||
await this.eyedropsCollection.doc().set({ codigo: exame.material.codigo, exame: JSON.stringify(exame) }) | ||
} else { | ||
console.log("save - update", query.docs[0].id) | ||
await this.eyedropsCollection | ||
.doc(query.docs[0].id) | ||
.set({ codigo: exame.material.codigo, exame: JSON.stringify(exame) }) | ||
} | ||
} catch (error) { | ||
console.error("Erro ao criar o documento:", error) | ||
throw new Error(error.message) | ||
} | ||
} | ||
|
||
// async remove(gradeId: string): Promise<void> { | ||
// try { | ||
// const gradeRef = this.#gradeCollection.doc(gradeId) | ||
// if (!gradeRef) throw Error(`Grade ID: ${gradeId} não existe no repositório!`) | ||
// await gradeRef.delete() | ||
// return null | ||
// } catch (error) { | ||
// console.error(`Erro ao buscar documento ID:${gradeId}`, error) | ||
// throw error | ||
// } | ||
// } | ||
|
||
async truncate() { | ||
return Promise.resolve() | ||
} | ||
} |
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,8 @@ | ||
import { Exame } from "../models" | ||
|
||
export interface EyedropsRepository { | ||
save(exame: Exame): Promise<void> | ||
getByCodigo(codigo: string): Promise<any> | ||
getByUF(codigo: string): Promise<any[]> | ||
truncate(): Promise<void> | ||
} |
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 { ExameService } from "src/app/services/exame.service" | ||
import { InMemoryRepository } from "./InMemoryRepository" | ||
|
||
export const InMemoryProvider = [ | ||
{ | ||
provide: ExameService, | ||
useFactory: (repository: any) => { | ||
return new ExameService(repository) | ||
}, | ||
inject: [InMemoryRepository], | ||
}, | ||
] |
34 changes: 34 additions & 0 deletions
34
src/app/Repository/InMemoryRepository/InMemoryRepository.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,34 @@ | ||
import { Exame } from "src/app/models" | ||
import { EyedropsRepository } from "../EyedropsRepository" | ||
|
||
export class InMemoryRepository implements EyedropsRepository { | ||
getByCodigo(codigo: string): Promise<any> { | ||
return Promise.resolve( | ||
this.exames.find((exame) => `${exame.material.numero} ${exame.material.uf.toUpperCase()}` === codigo.toUpperCase()) | ||
) | ||
} | ||
exames: Exame[] = [] | ||
|
||
async getByUF(uf: string): Promise<any[]> { | ||
return Promise.resolve(this.exames.filter((exame) => exame.material.uf === uf)) | ||
} | ||
|
||
async save(exame: Exame): Promise<void> { | ||
const index = this.exames.findIndex( | ||
(e) => | ||
`${e.material.numero} ${e.material.uf.toUpperCase()}` === | ||
`${exame.material.numero} ${exame.material.uf.toUpperCase()}` | ||
) | ||
if (index < 0) { | ||
this.exames.push(exame) | ||
} else { | ||
this.exames[index] = exame | ||
} | ||
return | ||
} | ||
|
||
truncate() { | ||
this.exames = [] | ||
return Promise.resolve() | ||
} | ||
} |
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,5 @@ | ||
// @index(['./**/*.ts',/spec/g], f => `export * from '${f.path}'`) | ||
export * from "./DatabaseRepository/DatabaseRepository" | ||
export * from "./EyedropsRepository" | ||
export * from "./InMemoryRepository/InMemoryRepository" | ||
// @endindex |
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,38 @@ | ||
import firebase from "firebase/compat/app" | ||
import "firebase/compat/firestore" | ||
import { DatabaseRepository } from "../Repository" | ||
|
||
const firebaseProvider = { | ||
provide: "FIREBASE_APP", | ||
useFactory: () => { | ||
const firebaseConfig = { | ||
apiKey: "AIzaSyCychbq3p2CtKdv1-Q5ABJB7gA_r_En_x0", | ||
authDomain: "grade-anp.firebaseapp.com", | ||
projectId: "grade-anp", | ||
storageBucket: "grade-anp.firebasestorage.app", | ||
messagingSenderId: "761229602912", | ||
appId: "1:761229602912:web:67aa3a36a10111fb965305", | ||
} | ||
|
||
if (!firebase.apps.length) { | ||
firebase.initializeApp(firebaseConfig) | ||
} | ||
|
||
return firebase.firestore() | ||
}, | ||
} | ||
|
||
@Module({ | ||
providers: [ | ||
firebaseProvider, | ||
{ | ||
provide: DatabaseRepository, | ||
useFactory: (db: any) => { | ||
return new DatabaseRepository(db) | ||
}, | ||
inject: ["FIREBASE_APP"], | ||
}, | ||
], | ||
exports: [DatabaseRepository], | ||
}) | ||
export class FirebaseModule {} |
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
Oops, something went wrong.