This repository was archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Integracão reserva api #9
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
323939b
Ajustes para integração com API
ericbreno 3b9d374
versão estável, básico em funcionamento
ericbreno 059d963
ok, agora deu certo
ericbreno 2eb623e
Ajustes nos mocks de reserva
ericbreno 5e08031
ajustes para input de titulo. Ajuste para botões do calendario
ericbreno a433146
Merge remote-tracking branch 'origin' into integraca-reserva-api
ericbreno 030d360
Adicionada verificação de choque de horarios no servidor
ericbreno 0e37cfa
Ajuste para salvar reserva
ericbreno 56dc976
Ajustes para merge
ericbreno fd1f449
Ajustes para merge com master
ericbreno 3712fd2
Extração função que verifica choque de horários, deleção função morta
ericbreno 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ let sequenceReserva = 1; | |
/** | ||
* Factory que representa a entidade de reserva. | ||
*/ | ||
angular.module('agendamentoModulo', []).factory('Reserva', ['$http', '$q', function ($http, $q) { | ||
angular.module('agendamentoModulo', []).factory('Reserva', ['$http', function ($http) { | ||
|
||
const COR_DEFAULT = '', COR_TEXTO_DEFAULT = '', | ||
DIA_INDICE = 0, MES_INDICE = 1, ANO_INDICE = 2, | ||
HORA_INDICE = 0, MINUTO_INDICE = 1; | ||
|
||
const API = "/api/reservas"; | ||
|
||
/* | ||
* Obs: Provavelmente terá que ser adicionado duas funções privadas para criação de | ||
* uma reserva, uma para quando nós iremos montar e outra para quando receber o evento | ||
|
@@ -18,7 +20,7 @@ let sequenceReserva = 1; | |
* | ||
* Todo: Remover id, o qual será gerado pelo mongodb | ||
*/ | ||
function Reserva({id = sequenceReserva++, | ||
function Reserva({_id, | ||
autor, | ||
titulo, | ||
descricao, | ||
|
@@ -28,7 +30,7 @@ let sequenceReserva = 1; | |
cor = COR_DEFAULT, | ||
corTexto = COR_TEXTO_DEFAULT}) { | ||
|
||
Object.assign(this, {id, | ||
obterPropriedades(this, {_id, | ||
autor, | ||
titulo, | ||
descricao, | ||
|
@@ -39,38 +41,64 @@ let sequenceReserva = 1; | |
corTexto}); | ||
} | ||
|
||
/** | ||
* Define todas as propriedades da origem para | ||
* o destino. Shallow copy. | ||
* | ||
* @param {*} instancia Objeto de destino. | ||
* @param {*} props Objeto de origem das propriedades. | ||
*/ | ||
function obterPropriedades(instancia, props) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSDoc |
||
Object.assign(instancia, props); | ||
} | ||
|
||
/** | ||
* Recupera a reserva original do servidor. | ||
* @return Promise da requisição. | ||
*/ | ||
Reserva.prototype.carregar = function () { | ||
return $q.when({}); | ||
return $http.get(`${API}/${this._id}`).then(data => { | ||
obterPropriedades(this, data.data); | ||
return data; | ||
}); | ||
}; | ||
|
||
/** | ||
* Persiste a reserva. | ||
* @return Promise da requisição. | ||
*/ | ||
Reserva.prototype.salvar = function () { | ||
return $q.when(this); | ||
if (this._id) { | ||
return this.atualizar(); | ||
} | ||
return $http.post(API, this).then(data => { | ||
obterPropriedades(this, data.data); | ||
return data; | ||
}); | ||
}; | ||
|
||
/** | ||
* Exclui a reserva do servidor. | ||
* @return Promise da requisição. | ||
*/ | ||
Reserva.prototype.excluir = function () { | ||
delete this.autor; | ||
delete this.descricao; | ||
return this.salvar(); | ||
return $http.delete(`${API}/${this._id}`).then(data => { | ||
delete this.autor; | ||
delete this.descricao; | ||
delete this.titulo; | ||
return data; | ||
}); | ||
}; | ||
|
||
/** | ||
* Atualiza a requisição no servidor. | ||
* @return Promise da requisição. | ||
*/ | ||
Reserva.prototype.atualizar = function () { | ||
return $q.when({}); | ||
return $http.patch(`${API}/${this._id}`, this).then(data => { | ||
obterPropriedades(this, data.data); | ||
return data; | ||
}); | ||
}; | ||
|
||
/** | ||
|
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.
Toaster para notificar sucesso