Skip to content

Commit

Permalink
first working commit
Browse files Browse the repository at this point in the history
working get api
  • Loading branch information
mazumdes committed Nov 30, 2021
1 parent 437db1e commit fb0735a
Show file tree
Hide file tree
Showing 63 changed files with 247 additions and 123 deletions.
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 Library.Encyclopedia.API/Controllers/EncylopediaController.cs
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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<BuildServerSideRenderer>false</BuildServerSideRenderer>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.21" />
</ItemGroup>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Library.Encyclopedia": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using Library.Encyclopedia.DataAccess;
using Library.Encyclopedia.DataAccess.DataAccess;
using Library.Encyclopedia.Entity.Interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -31,12 +27,7 @@ public void ConfigureServices(IServiceCollection services)
configuration.RootPath = "ClientApp/dist";
});

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection"),
ef => ef.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));
services.AddScoped<IApplicationDbContext>(provider => provider.GetService<ApplicationDbContext>());

services.AddTransient<IMainDataAccess, MainDataAccess>();
services.AddScoped<IApplicationDbContext, ApplicationDbContext>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 30 additions & 6 deletions Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs
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
}
}

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

Loading

0 comments on commit fb0735a

Please sign in to comment.