Skip to content

Instantly share code, notes, and snippets.

View vaneves's full-sized avatar
⚔️
I'm gladiator!

Van Neves vaneves

⚔️
I'm gladiator!
View GitHub Profile
@vaneves
vaneves / api.php
Created September 23, 2015 20:18
Curso Ninja - API/ DELETE
<?php
$app->delete('/posts/{id}', function ($id) use ($app) {
$em = $app['orm.em'];
$post = $em->getRepository('App\Entities\Post')->find($id);
$em->remove($post);
$em->flush();
return $app->json(true);
});
@vaneves
vaneves / index.html
Created September 23, 2015 22:41
Blog Ninja - Index
<!DOCTYPE html>
<html lang="pt-br" ng-app="ninja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Blog Ninja</title>
<!-- css de terceiros -->
<link href="assets/vendor/bower/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
@vaneves
vaneves / app.js
Created September 23, 2015 23:55
Blog Ninja - App
'use strict';
var app = angular.module('ninja', ['ngRoute', 'ngResource', 'ngAnimate', 'ninja.services', 'ninja.controllers', 'toastr']);
app.constant('API', 'api.php');
app.config(function ($routeProvider) {
$routeProvider.when('/', {
controller: 'BlogListCtrl',
templateUrl: 'view/blog/list.html'
@vaneves
vaneves / service-post.js
Last active September 24, 2015 11:45
Blog Ninja - Service
'use strict';
var services = angular.module('ninja.services', []);
services.factory('PostService', function ($resource, API) {
return $resource(API + '/posts/:id', {id: '@id'}, {
update:{
method:'PUT'
}
});
@vaneves
vaneves / controller-post.js
Last active September 24, 2015 11:49
Curso Ninja - Controller Post List
'use strict';
var controllers = angular.module('ninja.controllers', []);
controllers.controller('PostListCtrl', function ($scope, PostService, toastr) {
$scope.posts = PostService.query();
$scope.delete = function (id) {
PostService.delete({id: id})
.$promise
@vaneves
vaneves / controller-post.js
Created September 24, 2015 11:49
Curso Ninja - Controller Post Creat
controllers.controller('PostCreateCtrl', function ($scope, $location, PostService, toastr) {
$scope.save = function () {
PostService.save($scope.post)
.$promise
.then(function () {
toastr.success('Post salvo com sucesso');
$location.path('#/list');
}, function () {
toastr.error('Ocorreu um erro ao tentar salvar o post');
});
@vaneves
vaneves / controller-post.js
Created September 24, 2015 12:29
Curso Ninja - Controller Post Edit
controllers.controller('PostEditCtrl', function ($scope, $routeParams, $location, PostService, toastr) {
$scope.post = PostService.get({id: $routeParams.id});
$scope.save = function () {
PostService.update({id: $routeParams.id}, $scope.post)
.$promise
.then(function () {
toastr.success('Post salvo com sucesso');
$location.path('#/list');
}, function () {
@vaneves
vaneves / controller-post.js
Last active September 24, 2015 13:18
Curso Ninja - Controllers Blog
controllers.controller('BlogListCtrl', function ($scope, PostService) {
$scope.posts = PostService.query();
});
controllers.controller('BlogDetailCtrl', function ($scope, $routeParams, PostService) {
$scope.post = PostService.get({id: $routeParams.id});
});
@vaneves
vaneves / post-list.html
Created September 24, 2015 18:48
Blog Ninja - Post List HTML
<a href="#/add" class="btn btn-primary">Criar</a>
<table class="table table-striped">
<thead>
<tr>
<th>Título</th>
<th>Data</th>
<th style="width: 60px;"></th>
<th style="width: 60px;"></th>
</tr>
</thead>
@vaneves
vaneves / post-add.html
Created September 24, 2015 19:02
Curso Ninja - Post Create HTML
<form ng-submit="save()">
<div class="form-group">
<label for="title">Título</label>
<input type="text" ng-model="post.title" class="form-control" id="title">
</div>
<div class="form-group">
<label for="content">Conteúdo</label>
<textarea ng-model="post.content" class="form-control" id="content" rows="5"></textarea>
</div>
<button type="submit" class="btn btn-primary">Salvar</button>