Skip to content

Commit

Permalink
Merge pull request #180 from bhenn/master
Browse files Browse the repository at this point in the history
Estória 29. Criado método para cancelar o livro.
  • Loading branch information
raffacabofrio authored Dec 30, 2018
2 parents 4776e9a + b847c8a commit f4d4ce7
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ShareBook/ShareBook.Api/Controllers/BookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public PagedList<BooksVM> Paged(int page, int items)
[AuthorizationFilter(Permissions.Permission.ApproveBook)]
public Result<Book> Approve(string id, [FromBody] ApproveBookVM model) => _service.Approve(new Guid(id), model?.ChooseDate);

[Authorize("Bearer")]
[HttpPost("Cancel/{id}")]
public Result<Book> Cancel(string id) => _service.Cancel(new Guid(id), false);

[Authorize("Bearer")]
[HttpPost("CancelAdmin/{id}")]
[AuthorizationFilter(Permissions.Permission.DonateBook)]
public Result<Book> CancelAdmin(string id) => _service.Cancel(new Guid(id), true);

[HttpGet("FreightOptions")]
public IList<dynamic> FreightOptions()
{
Expand Down
5 changes: 5 additions & 0 deletions ShareBook/ShareBook.Domain/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class Book : BaseEntity

public bool Approved { get; set; } = false;

public bool Canceled { get; set; } = false;

public virtual ICollection<BookUser> BookUsers { get; set; }

public string ImageUrl { get; set; }
Expand All @@ -55,6 +57,9 @@ public BookStatus Status()
if (Donated())
return BookStatus.Donated;

if(Canceled)
return BookStatus.Canceled;

if (Approved)
return BookStatus.Available;

Expand Down
4 changes: 3 additions & 1 deletion ShareBook/ShareBook.Domain/Enums/BookStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public enum BookStatus
[Description("Invisível")]
Invisible,
[Description("Doado")]
Donated
Donated,
[Description("Cancelado")]
Canceled
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace ShareBook.Repository.Migrations
{
public partial class NewField_Book_Canceled : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "Canceled",
table: "Books",
nullable: false,
defaultValue: false);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Canceled",
table: "Books");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("varchar(200)")
.HasMaxLength(50);

b.Property<bool>("Canceled");

b.Property<Guid>("CategoryId");

b.Property<DateTime?>("ChooseDate");
Expand Down
Loading

0 comments on commit f4d4ce7

Please sign in to comment.