From e2410d0d48737032bd7bac21e17a6c3d975662e6 Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Thu, 22 Jun 2023 20:45:34 -0500 Subject: [PATCH] Remove unused todo API from DPOP sample --- .../v6/BFF/DPoP/DPoP.Api/ToDoController.cs | 100 ------------------ .../v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.html | 48 --------- .../v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.js | 94 ---------------- 3 files changed, 242 deletions(-) delete mode 100644 IdentityServer/v6/BFF/DPoP/DPoP.Api/ToDoController.cs delete mode 100644 IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.html delete mode 100644 IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.js diff --git a/IdentityServer/v6/BFF/DPoP/DPoP.Api/ToDoController.cs b/IdentityServer/v6/BFF/DPoP/DPoP.Api/ToDoController.cs deleted file mode 100644 index 5feee52c..00000000 --- a/IdentityServer/v6/BFF/DPoP/DPoP.Api/ToDoController.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// See LICENSE in the project root for license information. - -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.Logging; - -namespace DPoP.Api -{ - [Authorize("RequireInteractiveUser")] - public class ToDoController : ControllerBase - { - private readonly ILogger _logger; - - private static readonly List __data = new List() - { - new ToDo { Id = ToDo.NewId(), Date = DateTimeOffset.UtcNow, Name = "Demo ToDo API", User = "bob" }, - new ToDo { Id = ToDo.NewId(), Date = DateTimeOffset.UtcNow.AddHours(1), Name = "Stop Demo", User = "bob" }, - new ToDo { Id = ToDo.NewId(), Date = DateTimeOffset.UtcNow.AddHours(4), Name = "Have Dinner", User = "alice" }, - }; - - public ToDoController(ILogger logger) - { - _logger = logger; - } - - [HttpGet("todos")] - public IActionResult GetAll() - { - _logger.LogInformation("GetAll"); - - return Ok(__data.AsEnumerable()); - } - - [HttpGet("todos/{id}")] - public IActionResult Get(int id) - { - var item = __data.FirstOrDefault(x => x.Id == id); - if (item == null) return NotFound(); - - _logger.LogInformation("Get {id}", id); - return Ok(item); - } - - [HttpPost("todos")] - public IActionResult Post([FromBody] ToDo model) - { - model.Id = ToDo.NewId(); - model.User = $"{User.FindFirst("sub").Value} ({User.FindFirst("name").Value})"; - - __data.Add(model); - _logger.LogInformation("Add {name}", model.Name); - - return Created(Url.Action(nameof(Get), new { id = model.Id }), model); - } - - [HttpPut("todos/{id}")] - public IActionResult Put(int id, [FromBody] ToDo model) - { - var item = __data.FirstOrDefault(x => x.Id == id); - if (item == null) return NotFound(); - - item.Date = model.Date; - item.Name = model.Name; - - _logger.LogInformation("Update {name}", model.Name); - - return NoContent(); - } - - [HttpDelete("todos/{id}")] - public IActionResult Delete(int id) - { - var item = __data.FirstOrDefault(x => x.Id == id); - if (item == null) return NotFound(); - - __data.Remove(item); - _logger.LogInformation("Delete {id}", id); - - return NoContent(); - } - } - - public class ToDo - { - static int _nextId = 1; - public static int NewId() - { - return _nextId++; - } - - public int Id { get; set; } - public DateTimeOffset Date { get; set; } - public string Name { get; set; } - public string User { get; set; } - } -} diff --git a/IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.html b/IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.html deleted file mode 100644 index 22f656fc..00000000 --- a/IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - -
- - -
-

Add New

-
- - - - - -
-
- -
- - - - - - - - - - - -
IdDateNoteUser
-
-
- - - - diff --git a/IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.js b/IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.js deleted file mode 100644 index 01923480..00000000 --- a/IdentityServer/v6/BFF/DPoP/DPoP.Bff/wwwroot/todo.js +++ /dev/null @@ -1,94 +0,0 @@ -const todoUrl = "/api/todos"; -const todos = document.getElementById("todos"); - -document.getElementById("createNewButton").addEventListener("click", createTodo); -const name = document.getElementById("name"); -const date = document.getElementById("date"); - - -async function createTodo() { - let request = new Request(todoUrl, { - method: "POST", - headers: { - "content-type": "application/json", - 'x-csrf': '1' - }, - body: JSON.stringify({ - name: name.value, - date: date.value, - }) - }); - - let result = await fetch(request); - if (result.ok) { - var item = await result.json(); - addRow(item); - } -} - -async function showTodos() { - let result = await fetch(new Request(todoUrl, { - headers: { - 'x-csrf': '1' - }, - })); - - if (result.ok) { - let data = await result.json(); - data.forEach(item => addRow(item)); - } -} - -function addRow(item) { - let row = document.createElement("tr"); - row.dataset.id = item.id; - todos.appendChild(row); - - function addCell(row, text) { - let cell = document.createElement("td"); - cell.innerText = text; - row.appendChild(cell); - } - - function addDeleteButton(row, id) { - let cell = document.createElement("td"); - row.appendChild(cell); - let btn = document.createElement("button"); - cell.appendChild(btn); - btn.textContent = "delete"; - btn.addEventListener("click", async () => await deleteTodo(id)); - } - - addDeleteButton(row, item.id); - addCell(row, item.id); - addCell(row, item.date); - addCell(row, item.name); - addCell(row, item.user); -} - - -async function deleteRow(id) { - let row = todos.querySelector(`tr[data-id='${id}']`); - if (row) { - todos.removeChild(row); - } -} - -async function deleteTodo(id) { - let request = new Request(todoUrl + "/" + id, { - headers: { - 'x-csrf': '1' - }, - method: "DELETE" - }); - - let result = await fetch(request); - if (result.ok) { - deleteRow(id); - } -} - - -showTodos(); - -