ts support, public api support

This commit is contained in:
2023-12-04 18:18:47 -06:00
parent af34139067
commit ed4a8ea43d
16 changed files with 134 additions and 10 deletions

7
.gitignore vendored
View File

@@ -7,6 +7,7 @@
__notes__
*.env
UnbinderSandbox
package-lock.json
# Files for/generated by Docker Compose
secrets
@@ -44,8 +45,8 @@ bld/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
wwwroot/
wwwroot/lib/
wwwroot/js/
# Visual Studio 2017 auto generated files
Generated\ Files/
@@ -370,3 +371,5 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd
/Unbinder/wwwroot/lib
/Unbinder/wwwroot/js

View File

@@ -1 +1,3 @@
__notes__
__notes__
db_data
.eslintrc.js

5
Unbinder/.eslintrc.js Normal file
View File

@@ -0,0 +1,5 @@
module.exports = {
extends: [
'semistandard'
]
};

View File

@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Unbinder.Repositories;
namespace Unbinder.Controllers.Api
{
[ApiController]
public class IngredientApiController(IIngredientRepository repository) : ControllerBase
{
private readonly IIngredientRepository _repository = repository;
[HttpGet]
[Route("/api/ingredients")]
public IActionResult GetAll()
{
var result = _repository.GetAll;
return result == null ? NotFound() : Ok(result);
}
}
}

View File

@@ -32,6 +32,7 @@ builder.Services.AddDbContext<UnbinderDbContext>(options =>
// configure MVC
builder.Services.AddControllersWithViews();
builder.Services.AddControllers(); // map additional controllers for exposed REST API routes
builder.Services.AddRazorPages();
builder.Services.AddCors(options =>

View File

@@ -21,12 +21,15 @@
<PackageReference Include="Microsoft.Identity.Web" Version="2.15.3" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="2.15.3" />
<PackageReference Include="Microsoft.SqlServer.Server" Version="1.0.0" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="DB\SQL\" />
<Folder Include="secrets\" />
<Folder Include="TagHelpers\" />
<Folder Include="__notes__\" />
</ItemGroup>

View File

@@ -28,6 +28,12 @@
<textarea class="w-5/6 text-black" asp-for="RecipeText"></textarea>
</div>
<div id="ingredient-section">
<option id="ingredient-selector"></option>
</div>
<button type="submit">Publish Recipe</button>
</div>
</form>
</form>
<script src="~/js/createRecipe.js"></script>

View File

@@ -33,12 +33,12 @@
message.innerHTML = query ? `Viewing ${@Model.ToArray().Length} results for: ${query}` : "Enter a new search term below:";
// handle search updates on client side
searchButton.onclick = async () => {
const newResult = await fetch(`/api/recipe/search?q=${textField.value}`);
searchButton.onclick = () => {
// const newResult = await fetch(`/api/recipe/search?q=${textField.value}`);
console.log(newResult);
// console.log(newResult);
const newResultJson = await newResult.json();
// const newResultJson = await newResult.json();
window.location.search = `?q=${textField.value}`;
}
});

View File

@@ -2,8 +2,10 @@
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<script type="text/javascript">var exports = {};</script>
<script src="~/js/site.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<script src="~/lib/pdf.js/pdf.min.mjs"></script>
<link href="~/css/site.css" rel="stylesheet" />
<base href="/" />
</head>

View File

@@ -1,5 +1,10 @@
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": []
"libraries": [
{
"library": "pdf.js@4.0.269",
"destination": "wwwroot/lib/pdf.js/"
}
]
}

21
Unbinder/package.json Normal file
View File

@@ -0,0 +1,21 @@
{
"name": "unbinder",
"version": "1.0.0",
"description": "",
"main": "wwwroot/js/index.js",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mikayla Dobson",
"license": "ISC",
"devDependencies": {
"eslint": "^8.55.0",
"eslint-config-semistandard": "^17.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-promise": "^6.1.1",
"typescript": "^5.3.2"
}
}

21
Unbinder/tsconfig.json Normal file
View File

@@ -0,0 +1,21 @@
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"lib": ["ES2015", "DOM"],
"module": "CommonJS",
"target": "ES5",
"moduleResolution": "Node",
"outDir": "wwwroot/js"
},
"include": [
"wwwroot/ts/**/*"
],
"exclude": [
"node_modules",
"wwwroot/js"
]
}

View File

@@ -0,0 +1,18 @@
html {
font-size: 14px;
}
@media (min-width: 768px) {
html {
font-size: 16px;
}
}
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 60px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@@ -0,0 +1,18 @@
export async function getAllIngredients () {
const ingredients = await fetch('/api/ingredients');
return await ingredients.json();
}
document.addEventListener('DOMContentLoaded', async () => {
const ingredients = await getAllIngredients();
console.log({ ingredients });
const dropdown = document.getElementById('ingredient-selector');
ingredients.forEach(ingredient => {
const option = document.createElement('option');
option.value = ingredient.id;
option.innerText = ingredient.name;
dropdown.appendChild(option);
});
});

View File