-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working get api
- Loading branch information
Showing
63 changed files
with
247 additions
and
123 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
95 changes: 95 additions & 0 deletions
95
Library.Encyclopedia.API/Controllers/EncylopediaController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| using Library.Encyclopedia.DataAccess; | ||
| using Library.Encyclopedia.DataAccess.DataAccess; | ||
| using Library.Encyclopedia.Entity.Interfaces; | ||
| using Library.Encyclopedia.Entity.Models.External; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Extensions.Logging; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Library.Encyclopedia.Controllers | ||
| { | ||
| /// <summary> | ||
| /// CRUD operations on Main Table | ||
| /// </summary> | ||
| [ApiController] | ||
| [Route("[controller]")] | ||
| public class EncylopediaController : ControllerBase | ||
| { | ||
| private readonly ILogger<EncylopediaController> _logger; | ||
| private readonly IMainDataAccess mainDataAccess; | ||
|
|
||
| /// <summary> | ||
| /// Constructor | ||
| /// </summary> | ||
| /// <param name="logger"></param> | ||
| /// <param name="dbContext"></param> | ||
| public EncylopediaController(ILogger<EncylopediaController> logger, IApplicationDbContext dbContext) | ||
| { | ||
| _logger = logger; | ||
| this.mainDataAccess = new MainDataAccess(dbContext); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get all items based on search query | ||
| /// </summary> | ||
| /// <param name="query"></param> | ||
| /// <param name="offset"></param> | ||
| /// <param name="size"></param> | ||
| /// <param name="asc"></param> | ||
| /// <returns></returns> | ||
| [HttpGet] | ||
| public async Task<IActionResult> Get(string query, | ||
| int offset = 0, | ||
| int size = 10, | ||
| bool asc = true) | ||
| { | ||
| try | ||
| { | ||
| var response = await mainDataAccess.GetAsync(query, offset, size, asc); | ||
|
|
||
| if (response == null) | ||
| { | ||
| return StatusCode(204); | ||
| } | ||
| else | ||
| { | ||
| return Ok(response); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, $"an error has occured {ex.Message}"); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Create new entry | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| [HttpPost] | ||
| public async Task<IActionResult> Create() | ||
| { | ||
| try | ||
| { | ||
| var response = await mainDataAccess.CreateAsync(null); | ||
|
|
||
| if (response == null) | ||
| { | ||
| return StatusCode(204); | ||
| } | ||
| else | ||
| { | ||
| return Ok(); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, $"an error has occured {ex.Message}"); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 30 additions & 6 deletions
36
Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,61 @@ | ||
| using Library.Encyclopedia.Entity.Interfaces; | ||
| using Library.Encyclopedia.Entity.Models; | ||
| using Library.Encyclopedia.Entity.Models.External; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Library.Encyclopedia.DataAccess.DataAccess | ||
| { | ||
| public class MainDataAccess : IMainDataAccess | ||
| { | ||
| public MainDataAccess() | ||
| private IApplicationDbContext _dbcontext; | ||
| public MainDataAccess(IApplicationDbContext dbcontext) | ||
| { | ||
| _dbcontext = dbcontext; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| #region GET | ||
| async Task<MainMinimizedExternalCollection> IMainDataAccess.GetAsync(string query, int offset, int pagesize, bool ascending) | ||
| { | ||
| var data = await _dbcontext.Main.Where(s => s.Description.Contains(query) || s.Title.Contains(query)) | ||
| .Skip(offset) | ||
| .Take(pagesize) | ||
| .OrderBy(s => s.Title) | ||
| .ThenBy(s => s.Description) | ||
| .ToListAsync(); | ||
|
|
||
| MainMinimizedExternalCollection result = new MainMinimizedExternalCollection(data, ) | ||
| } | ||
|
|
||
| Task<IEnumerable<Main>> IMainDataAccess.Get(string query, int offset, int pagesize, bool ascending) | ||
| Task<Main> IMainDataAccess.GetAsync(string id) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| Task<Main> IMainDataAccess.Get(string id) | ||
| Task<IEnumerable<Main>> IMainDataAccess.GetAsync(char startingAlphabet) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| Task<IEnumerable<Main>> IMainDataAccess.Get(char startingAlphabet) | ||
| Task<IEnumerable<Main>> IMainDataAccess.GetByCategoryAsync(string category, int offset, int pagesize, bool ascending) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
| #endregion | ||
|
|
||
| Task<IEnumerable<Main>> IMainDataAccess.GetByCategory(string category, int offset, int pagesize, bool ascending) | ||
| #region CREATE | ||
| public async Task<Guid> CreateAsync(Main main) | ||
| { | ||
| throw new NotImplementedException(); | ||
| await _dbcontext.Main.AddAsync(main); | ||
| await _dbcontext.SaveChanges(); | ||
| return main.Id; | ||
| } | ||
| #endregion | ||
| } | ||
| } |
47 changes: 31 additions & 16 deletions
47
...ns/20211130180621_NewDatabase.Designer.cs → ...0211130183310_Update_11302021.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.