Skip to content

Commit

Permalink
Add facade
Browse files Browse the repository at this point in the history
All request handlers facade
  • Loading branch information
gustapp committed Jan 21, 2019
1 parent 208fcec commit 7b5b058
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 5 deletions.
20 changes: 20 additions & 0 deletions functions/src/entity-factory.ts
@@ -0,0 +1,20 @@
import { object } from "firebase-functions/lib/providers/storage";

/**
* @class
* ORM (Object-Relational Mapping) Factory
* Creates 'Entity' objects
*/
export class EntityFactory {
/**
* @constructor
* @param db
*/
constructor(private db: FirebaseFirestore.Firestore){}
/**
* @function createRef
*/
public createRef(collectionName: string){
return this.db.collection(collectionName);
}
}
155 changes: 155 additions & 0 deletions functions/src/handler-facade.ts
@@ -0,0 +1,155 @@
import { WebhookClient, Card, Suggestion } from 'dialogflow-fulfillment';
import { EntityFactory } from './entity-factory';
/**
* @class
* Facade for all handlers
*/
export class HandlerFacade {

private entityFactory: EntityFactory;
/**
* @constructor
* @param db firestore manager
*/
constructor(db: FirebaseFirestore.Firestore){
this.entityFactory = new EntityFactory(db);
}
/**
* @function welcome
* @param agent
*/
public welcome(agent: WebhookClient) {
agent.add(`Hello! Lets chat 🔥`);
}
/**
* @function fallback
* @param agent
*/
public fallback(agent: WebhookClient) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
/**
* @function yourFunction
* @param agent
*/
public yourFunction(agent: WebhookClient) {
agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
agent.add(new Card({
title: `Title: this is a card title`,
imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
text: `This is the body text of a card. You can even use line\n breaks and emoji! 💁`,
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);
agent.add(new Suggestion(`Quick Reply`));
agent.add(new Suggestion(`Suggestion`));
agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }});
}
/**
* @function getCourse
* @param agent
*/
public getCourse(agent: WebhookClient) {

}
/**
* @function getCourseInfo
* @param agent
*/
public getCourseInfo(agent: WebhookClient) {

}
/**
* @function getCourseRequirements
* @param agent
*/
public getCourseRequirements(agent: WebhookClient) {

}
/**
* @function getCourseWorkload
* @param agent
*/
public getCourseWorkload(agent: WebhookClient) {

}
/**
* @function getCourseTeacher
* @param agent
*/
public getCourseTeacher(agent: WebhookClient) {

}
/**
* @function getCourseSchedule
* @param agent
*/
public getCourseSchedule(agent: WebhookClient) {

}
/**
* @function getCourseCredit
* @param agent
*/
public getCourseCredit(agent: WebhookClient) {

}
/**
* @function getCourseFromScheduleDay
* @param agent
*/
public getCourseFromScheduleDay(agent: WebhookClient) {

}
/**
* @function getCourseFromScheduleDayHour
* @param agent
*/
public getCourseFromScheduleDayHour(agent: WebhookClient) {

}
/**
* @function fallbackGetCourseId2
* @param agent
*/
public fallbackGetCourseId2(agent: WebhookClient) {

}
/**
* @function getCourseSuggestion
* @param agent
*/
public getCourseSuggestion(agent: WebhookClient) {

}
/**
* @function getCourseSuggestionBefore
* @param agent
*/
public getCourseSuggestionBefore(agent: WebhookClient) {

}
/**
* @function getCourseSuggestionAfter
* @param agent
*/
public getCourseSuggestionAfter(agent: WebhookClient) {

}
/**
* @function getCourseSuggestionBetween
* @param agent
*/
public getCourseSuggestionBetween(agent: WebhookClient) {

}
/**
* @function getCourseSuggestionDays
* @param agent
*/
public getCourseSuggestionDays(agent: WebhookClient) {

}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions functions/src/index.ts
Expand Up @@ -2,16 +2,15 @@ import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

import { WebhookClient } from 'dialogflow-fulfillment';

import { welcome, fallback, yourFunction } from './handlers/silly';
import { getCourse, getCourseInfo, getCourseRequirements, getCourseWorkload, getCourseTeacher, getCourseSchedule, getCourseCredit, getCourseFromScheduleDay, getCourseFromScheduleDayHour, fallbackGetCourseId2 } from './jupiter/info'
import { getCourseSuggestion, getCourseSuggestionBefore, getCourseSuggestionAfter, getCourseSuggestionBetween, getCourseSuggestionDays } from './jupiter/suggestion'
import { HandlerFacade } from './handler-facade';

process.env.DEBUG = 'dialogflow:debug';

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();

const facade = new HandlerFacade(db);

/**
* @function helloWorld
* Test function
Expand All @@ -33,7 +32,7 @@ export const dialogflowFirebaseFulfillment = functions.https.onRequest((request,
const intentMap = new Map();

// Test intents
intentMap.set('Welcome', welcome);
intentMap.set('Welcome', facade.welcome);
intentMap.set('Fallback', fallback);
intentMap.set('Test', yourFunction);

Expand Down
5 changes: 5 additions & 0 deletions functions/src/interfaces/avaliacao.ts
@@ -0,0 +1,5 @@
export interface IAvaliacao {
metodo: String,
criterio: String,
recuperacao: String
}
4 changes: 4 additions & 0 deletions functions/src/interfaces/credito.ts
@@ -0,0 +1,4 @@
export interface ICredito {
aula: number,
trabalho: number
}
20 changes: 20 additions & 0 deletions functions/src/interfaces/curso.ts
@@ -0,0 +1,20 @@
import { ICredito as Credito } from './credito';
import { IDocente as Docente } from './docente';
import { IAvaliacao as Avaliacao } from './avaliacao';
import { IRequisito as Requisito } from './requisito';
import { IOferecimento as Oferecimento } from './oferecimento';

interface ICurso {
sigla: String,
name: String,
creditos: Credito,
carga_horaria: Number,
objetivos: String,
docentes: Docente[],
programa: String,
programa_resumido: String,
avaliacao: Avaliacao,
bibliografia: String[],
requisitos: Requisito[],
oferecimento: Oferecimento[]
}
3 changes: 3 additions & 0 deletions functions/src/interfaces/docente.ts
@@ -0,0 +1,3 @@
export interface IDocente {
nome: string
}
6 changes: 6 additions & 0 deletions functions/src/interfaces/horario.ts
@@ -0,0 +1,6 @@
export interface IHorario {
dia: String,
horario_inicio: String,
horario_fim: String,
professor: String
}
7 changes: 7 additions & 0 deletions functions/src/interfaces/oferecimento.ts
@@ -0,0 +1,7 @@
import { IHorario as Horario } from './horario';

export interface IOferecimento {
codigo_turma: String,
tipo_turma: String,
horario: Horario[]
}
3 changes: 3 additions & 0 deletions functions/src/interfaces/requisito.ts
@@ -0,0 +1,3 @@
export interface IRequisito {
nome: String
}

0 comments on commit 7b5b058

Please sign in to comment.