Skip to content

Commit 28a25eb

Browse files
committed
Add response objects, and
1 parent e9b5da4 commit 28a25eb

File tree

8 files changed

+112
-23
lines changed

8 files changed

+112
-23
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
skip_app_build: false
3232
app_location: "./ui" # Location of the built application
3333
output_location: "dist/home-library/browser"
34+
app_build_command: "npm run build"
3435
# API
3536
skip_api_build: false
3637
api_location: "./api"

api/Dto/BaseResponse.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Gemstone.HomeLibrary.Dto;
2+
3+
/// <summary>
4+
/// Base response object for API endpoints.
5+
/// </summary>
6+
public class BaseResponse
7+
{
8+
public required string Message { get; set; }
9+
}

api/Dto/BooksResponse.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Gemstone.HomeLibrary.Models;
2+
3+
namespace Gemstone.HomeLibrary.Dto;
4+
5+
/// <summary>
6+
/// Response object for fetching books.
7+
/// </summary>
8+
public class BooksResponse : BaseResponse
9+
{
10+
public required Book[] Books { get; set; }
11+
}

api/Endpoints/GetBooks.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Azure.Functions.Worker;
4+
using Microsoft.Extensions.Logging;
5+
using Gemstone.HomeLibrary.Dto;
6+
using Gemstone.HomeLibrary.Models;
7+
8+
namespace Gemstone.HomeLibrary;
9+
10+
/// <summary>
11+
/// Fetch books from the library.
12+
/// </summary>
13+
public class GetBooks
14+
{
15+
private readonly ILogger<GetBooks> _logger;
16+
17+
public GetBooks(ILogger<GetBooks> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
[Function("GetBooks")]
23+
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
24+
{
25+
_logger.LogInformation("Fetching books");
26+
27+
// TODO fetch books from "somewhere"
28+
Book[] books = [
29+
new() { Title = "A Wrinkle in Time" },
30+
new() { Title = "The Hobbit" },
31+
new() { Title = "Hyperion" },
32+
];
33+
34+
return new JsonResult(new BooksResponse
35+
{
36+
Message = "Books retrieved successfully",
37+
Books = books
38+
});
39+
}
40+
}

api/Endpoints/SaveBook.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Azure.Functions.Worker;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace Gemstone.HomeLibrary;
7+
8+
/// <summary>
9+
/// Save a book to the library, or update if it already exists.
10+
/// </summary>
11+
public class SaveBook
12+
{
13+
private readonly ILogger<SaveBook> _logger;
14+
15+
public SaveBook(ILogger<SaveBook> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
[Function("SaveBook")]
21+
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
22+
{
23+
// TODO update the book in "somewhere"
24+
25+
return new JsonResult(new { Message = "SaveBook function executed successfully." });
26+
}
27+
}

api/GetBooks.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

api/Models/Book.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Gemstone.HomeLibrary.Models;
2+
3+
/// <summary>
4+
/// Represents a book in the library.
5+
/// </summary>
6+
public class Book
7+
{
8+
public required string Title { get; set; }
9+
}

swa-cli.config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"configurations": {
3+
"app": {
4+
"appLocation": "./ui",
5+
"apiLocation": "./api",
6+
"outputLocation": "dist/home-library/browser",
7+
"apiLanguage": "dotnetisolated",
8+
"apiVersion": "9.0",
9+
"appBuildCommand": "npm run build",
10+
"apiBuildCommand": "dotnet publish -c Release",
11+
"run": "npm run start",
12+
"appDevserverUrl": "http://localhost:4200"
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)