Objetivo: desenvolver uma API GraphQL em C# + .NET Core simulando um caixa eletrônico.
Nesta simulação considere que não há necessidade de autenticação.
SENDO EU um correntista do banco
QUERO poder movimentar a minha conta corrente
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Web; | |
| using System.Web.Mvc; | |
| using Newtonsoft.Json; | |
| using PosGraduacao.Models; | |
| namespace PosGraduacao.Controllers | |
| { |
| <?php | |
| return [ | |
| 'urlManager' => [ | |
| // URLs limpas = 'enablePrettyUrl' => true, | |
| // URLs sem o index.php = 'showScriptName' => false, | |
| 'rules' => [ | |
| // Regras específicas | |
| 'api/v2/clientes/<id_cliente>/historicos' => 'api/v2/historicos/index', | |
| // Regra geral: | |
| 'api/v2/<controller:\w+>/<action:\w+>' => 'api/v2/<controller>/<action>', |
| <?php | |
| interface IdentificavelPorChaveDeAutenticacao | |
| { | |
| public static function encontrarIdentidade($id); | |
| public function getId(); | |
| public function getChaveAutenticacao(); | |
| public function validarChaveAutenticacao($chaveAutenticacao); | |
| } | |
| interface IdentificavelPorToken |
| <?php | |
| class Usuario extends ActiveRecord implements Identificavel | |
| { | |
| ... | |
| public function getChaveAutenticacao() | |
| { | |
| throw new NaoImplementadoException(); // :-( | |
| } | |
| <?php | |
| class Usuario extends ActiveRecord implements Identificavel | |
| { | |
| public static function encontrarIdentidade($id) | |
| { | |
| return static::findOne($id); | |
| } | |
| public static function encontrarIdentidadePeloToken($token, $tipo = null) | |
| { |
| <?php | |
| interface Identificavel | |
| { | |
| public static function encontrarIdentidade($id); | |
| public static function encontrarIdentidadePeloToken($token, $tipo = null); | |
| public function getId(); | |
| public function getChaveAutenticacao(); | |
| public function validarChaveAutenticacao($chaveAutenticacao); | |
| } |
| <?php | |
| interface Estocavel | |
| { | |
| public function retirar($quantidade); | |
| public function depositar($quantidade); | |
| } | |
| interface Valoravel | |
| { | |
| public function getValor(); |