-
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.
- Loading branch information
johnathan
committed
Apr 3, 2020
1 parent
6b25cee
commit 67c7851
Showing
19 changed files
with
584 additions
and
0 deletions.
There are no files selected for viewing
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,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; } | ||
} | ||
} |
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,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(); | ||
} | ||
} | ||
} |
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,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(); | ||
} | ||
} | ||
} |
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,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> |
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,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 |
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,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; } | ||
} | ||
} |
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,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; } | ||
|
||
} | ||
} |
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,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; } | ||
} | ||
} |
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,10 @@ | ||
namespace GroceriesApi.Models | ||
{ | ||
public interface IGroceryDatabaseSettings | ||
{ | ||
string GroceryListCollectionName { get; set; } | ||
string GroceryPurchasedCollectionName { get; set; } | ||
string ConnectionString { get; set; } | ||
string DatabaseName { get; set; } | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace GroceriesApi.Models | ||
{ | ||
public interface IGroceryListModel : IGroceryModel | ||
{ | ||
bool onlist { get; set; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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>(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.