Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable Noming Clature Changed #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
26 changes: 13 additions & 13 deletions BookAPI/Controllers/BooksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ namespace BookAPI.Controllers
[ApiController]
public class BooksController : ControllerBase
{
private readonly IBookRepository _bookRepository;
private readonly IBookRepository bookRepository;

public BooksController(IBookRepository bookRepository)
{
_bookRepository = bookRepository;
this.bookRepository = bookRepository;
}

[HttpGet]
public async Task<IEnumerable<Books>> GetBooks()
[HttpGet("{id}")]
public async Task<ActionResult<Books>> GetBooks(int id)
{
return await _bookRepository.Get();
return await bookRepository.Get(id);
}

[HttpGet("{id}")]
public async Task<ActionResult<Books>> GetBooks(int id)
[HttpGet]
public async Task<IEnumerable<Books>> GetBooks()
{
return await _bookRepository.Get(id);
return await bookRepository.Get();
}

[HttpPost]
public async Task<ActionResult<Books>> PostBooks([FromBody] Books book)
{
var newBook = await _bookRepository.Create(book);
var newBook = await bookRepository.Create(book);
return CreatedAtAction(nameof(GetBooks), new { id = newBook.ID}, newBook);
}

Expand All @@ -44,19 +44,19 @@ public async Task<ActionResult> PutBooks(int id, [FromBody] Books book)
return BadRequest();
}

await _bookRepository.Update(book);
await bookRepository.Update(book);

return NoContent();
}

[HttpDelete("{id}")]
public async Task<ActionResult> Delete(int id)
{
var bookToDelete = await _bookRepository.Get(id);
var bookToDelete = await bookRepository.Get(id);
if (bookToDelete == null)
return NotFound();

await _bookRepository.Delete(bookToDelete.ID);
await bookRepository.Delete(bookToDelete.ID);
return NoContent();
}
}
Expand Down
1 change: 0 additions & 1 deletion BookAPI/Repositories/BookRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task<Books> Create(Books book)
{
context.Books.Add(book);
await context.SaveChangesAsync();

return book;
}
public async Task Update(Books book)
Expand Down