Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnathan committed Apr 3, 2020
1 parent 6b25cee commit 67c7851
Show file tree
Hide file tree
Showing 19 changed files with 584 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Controllers/DocumentIdController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;


namespace GroceriesApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DocumentIdController : ControllerBase
{
public DocumentIdController(ILogger<DocumentIdController> logger)
{
_logger = logger;
}

private readonly ILogger<DocumentIdController> _logger;

// GET: api/DocumentId
[HttpGet]
public DocumentId Get()
{
string documentId = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 23);// mongodb id is 24 chars in length
return new DocumentId
{
id = documentId
};
}
}

public class DocumentId
{
public string id { get; set; }
}
}
79 changes: 79 additions & 0 deletions Controllers/GroceryListController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using GroceriesApi.Models;
using GroceriesApi.Services;

namespace GroceriesApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class GroceryListController : ControllerBase
{

private readonly GroceryListService _groceryListService;

public GroceryListController(GroceryListService groceryListService)
{
_groceryListService = groceryListService;
}

[HttpGet]
public ActionResult<List<GroceryListModel>> Get() =>
_groceryListService.Get();

[HttpGet("{id:length(24)}", Name = "GetGroceryListItem")]
public ActionResult<GroceryListModel> Get(string id)
{
var groceryListItem = _groceryListService.Get(id);

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

return groceryListItem;
}

[HttpPost]
public ActionResult<GroceryListModel> Create(GroceryListModel groceryListModel)
{
_groceryListService.Create(groceryListModel);

return CreatedAtRoute("GetGroceryListItem", new { id = groceryListModel.id.ToString() }, groceryListModel);
}

[HttpPut("{id:length(24)}")]
public IActionResult Update(string id, GroceryListModel groceryListModelIn)
{
var groceryListModel = _groceryListService.Get(id);

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

_groceryListService.Update(id, groceryListModelIn);

return NoContent();
}

[HttpDelete("{id:length(24)}")]
public IActionResult Delete(string id)
{
var groceryListModel = _groceryListService.Get(id);

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

_groceryListService.Remove(groceryListModel.id);

return NoContent();
}
}
}
78 changes: 78 additions & 0 deletions Controllers/GroceryPurchasedController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using GroceriesApi.Models;
using GroceriesApi.Services;

namespace GroceriesApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class GroceryPurchasedController : ControllerBase
{
private readonly GroceryPurchasedService _groceryPurchasedService;

public GroceryPurchasedController(GroceryPurchasedService groceryPurchasedService)
{
_groceryPurchasedService = groceryPurchasedService;
}

[HttpGet]
public ActionResult<List<GroceryPurchasedModel>> Get() =>
_groceryPurchasedService.Get();

[HttpGet("{id:length(24)}", Name = "GetGroceryPurchasedItem")]
public ActionResult<GroceryPurchasedModel> Get(string id)
{
var groceryPurchasedItem = _groceryPurchasedService.Get(id);

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

return groceryPurchasedItem;
}

[HttpPost]
public ActionResult<GroceryPurchasedModel> Create(GroceryPurchasedModel groceryPurchasedModel)
{
_groceryPurchasedService.Create(groceryPurchasedModel);

return CreatedAtRoute("GetGroceryPurchasedItem", new { id = groceryPurchasedModel.id.ToString() }, groceryPurchasedModel);
}

[HttpPut("{id:length(24)}")]
public IActionResult Update(string id, GroceryPurchasedModel groceryPurchasedModelIn)
{
var groceryPurchasedModel = _groceryPurchasedService.Get(id);

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

_groceryPurchasedService.Update(id, groceryPurchasedModelIn);

return NoContent();
}

[HttpDelete("{id:length(24)}")]
public IActionResult Delete(string id)
{
var groceryPurchasedModel = _groceryPurchasedService.Get(id);

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

_groceryPurchasedService.Remove(groceryPurchasedModel.id);

return NoContent();
}
}
}
13 changes: 13 additions & 0 deletions GroceriesApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.10.2" />
</ItemGroup>


</Project>
25 changes: 25 additions & 0 deletions GroceriesApi.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29926.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GroceriesApi", "GroceriesApi.csproj", "{E9CD22F4-3E57-4B31-ACF9-2AF695AA5A4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E9CD22F4-3E57-4B31-ACF9-2AF695AA5A4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9CD22F4-3E57-4B31-ACF9-2AF695AA5A4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9CD22F4-3E57-4B31-ACF9-2AF695AA5A4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9CD22F4-3E57-4B31-ACF9-2AF695AA5A4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E7B99C5-E5FF-41AC-BCE9-2C6BAC9CDCD6}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions Models/GroceryDatabaseSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GroceriesApi.Models
{
public class GroceryDatabaseSettings : IGroceryDatabaseSettings
{
public string GroceryListCollectionName { get; set; }
public string GroceryPurchasedCollectionName { get; set; }
public string ConnectionString { get; set; }
public string DatabaseName { get; set; }
}
}
21 changes: 21 additions & 0 deletions Models/GroceryListModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace GroceriesApi.Models
{
public class GroceryListModel : IGroceryListModel
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string id { get; set; }
public bool onlist { get; set; }
public string section { get; set; }
public string brand { get; set; }
public string grocery { get; set; }
public decimal quantity { get; set; }

}
}
24 changes: 24 additions & 0 deletions Models/GroceryPurchasedModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace GroceriesApi.Models
{
public class GroceryPurchasedModel : IGroceryPurchasedModel
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string id { get; set; }
public decimal itemprice { get; set; }
public decimal totalprice { get; set; }
public string section { get; set; }
public string store { get; set; }
public string brand { get; set; }
public string grocery { get; set; }
public decimal quantity { get; set; }
public DateTime date { get; set; }
}
}
10 changes: 10 additions & 0 deletions Models/IGroceryDatabaseSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace GroceriesApi.Models
{
public interface IGroceryDatabaseSettings
{
string GroceryListCollectionName { get; set; }
string GroceryPurchasedCollectionName { get; set; }
string ConnectionString { get; set; }
string DatabaseName { get; set; }
}
}
11 changes: 11 additions & 0 deletions Models/IGroceryListModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GroceriesApi.Models
{
public interface IGroceryListModel : IGroceryModel
{
bool onlist { get; set; }
}
}
13 changes: 13 additions & 0 deletions Models/IGroceryModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace GroceriesApi.Models
{
public interface IGroceryModel
{
public string id { get; set; }
public string section { get; set; }
string brand { get; set; }
string grocery { get; set; }
decimal quantity { get; set; }
}
}
14 changes: 14 additions & 0 deletions Models/IGroceryPurchasedModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GroceriesApi.Models
{
public interface IGroceryPurchasedModel : IGroceryModel
{
decimal itemprice { get; set; }
decimal totalprice { get; set; }
string store { get; set; }
DateTime date { get; set; }
}
}
26 changes: 26 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace GroceriesApi
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Loading

0 comments on commit 67c7851

Please sign in to comment.