Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified BookStoreApi/.vs/BookStoreApi/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!--

IIS configuration sections.
Expand Down
Binary file modified BookStoreApi/.vs/BookStoreApi/v16/.suo
Binary file not shown.
108 changes: 108 additions & 0 deletions BookStoreApi/BookStoreApi/Controllers/NoteController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using BookStoreApi.Model;

namespace BookStoreApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class NoteController : ControllerBase
{
private readonly DatabaseContext _context;

public NoteController(DatabaseContext context)
{
_context = context;
}

// GET: api/Note
[HttpGet]
public async Task<ActionResult<IEnumerable<Note>>> GetNotes()
{
return await _context.Notes.ToListAsync(); //lista wszystkich notatek
}


// GET: api/Note/5
[HttpGet("{id}")]
public async Task<ActionResult<Note>> GetNote(int id)
{
var note = await _context.Notes.FindAsync(id);

if (note == null)
{
return NotFound();
}

return note;
}

// PUT: api/Note/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutNote(int id, Note note)
{
if (id != note.noteId)
{
return BadRequest();
}

_context.Entry(note).State = EntityState.Modified;

try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!NoteExists(id))
{
return NotFound();
}
else
{
throw;
}
}

return NoContent();
}

// POST: api/Note
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Note>> PostNote(Note note)
{
_context.Notes.Add(note);
await _context.SaveChangesAsync();

return CreatedAtAction("GetNote", new { id = note.noteId }, note);
}

// DELETE: api/Note/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteNote(int id)
{
var note = await _context.Notes.FindAsync(id);
if (note == null)
{
return NotFound();
}

_context.Notes.Remove(note);
await _context.SaveChangesAsync();

return NoContent();
}

private bool NoteExists(int id)
{
return _context.Notes.Any(e => e.noteId == id);
}
}
}

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
Expand Up @@ -3,7 +3,7 @@

namespace BookStoreApi.Migrations
{
public partial class initialCreate : Migration
public partial class updt1 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
Expand Down Expand Up @@ -64,6 +64,32 @@ protected override void Up(MigrationBuilder migrationBuilder)
table.PrimaryKey("PK_Books", x => x.ID);
});

migrationBuilder.CreateTable(
name: "FavoriteBooks",
columns: table => new
{
HolderId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FavoriteBooks", x => x.HolderId);
});

migrationBuilder.CreateTable(
name: "Notes",
columns: table => new
{
noteId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
userId = table.Column<int>(type: "INTEGER", nullable: false),
bookId = table.Column<int>(type: "INTEGER", nullable: false),
comment = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Notes", x => x.noteId);
});

migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
Expand Down Expand Up @@ -228,6 +254,12 @@ protected override void Down(MigrationBuilder migrationBuilder)
migrationBuilder.DropTable(
name: "Books");

migrationBuilder.DropTable(
name: "FavoriteBooks");

migrationBuilder.DropTable(
name: "Notes");

migrationBuilder.DropTable(
name: "AspNetRoles");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Books");
});

modelBuilder.Entity("BookStoreApi.Model.FavoriteBook", b =>
{
b.Property<string>("HolderId")
.HasColumnType("TEXT");

b.HasKey("HolderId");

b.ToTable("FavoriteBooks");
});

modelBuilder.Entity("BookStoreApi.Model.Note", b =>
{
b.Property<int>("noteId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");

b.Property<int>("bookId")
.HasColumnType("INTEGER");

b.Property<string>("comment")
.HasColumnType("TEXT");

b.Property<int>("userId")
.HasColumnType("INTEGER");

b.HasKey("noteId");

b.ToTable("Notes");
});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
Expand Down
1 change: 1 addition & 0 deletions BookStoreApi/BookStoreApi/Model/DatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

public virtual DbSet<Book> Books { get; set; }

public virtual DbSet<Note> Notes { get; set; }
public virtual DbSet<FavoriteBook> FavoriteBooks { get; set; }
}
}
21 changes: 21 additions & 0 deletions BookStoreApi/BookStoreApi/Model/Note.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace BookStoreApi.Model
{
public class Note
{
[Key]
public int noteId { get; set; }

public int userId { get; set; }

public int bookId { get; set; }

public string comment { get; set; }

}
}
Binary file modified BookStoreApi/BookStoreApi/bin/Debug/net5.0/BookStoreApi.dll
Binary file not shown.
Binary file modified BookStoreApi/BookStoreApi/bin/Debug/net5.0/BookStoreApi.pdb
Binary file not shown.
Binary file not shown.
Binary file modified BookStoreApi/BookStoreApi/bookStore.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7b729e2ab59602f1d1e609825ad730479853020a
3ed5d49a546e8db8a4b453ad7d54865a43899ca0
Loading