From ccdcc1891b01b43069991cf58a588145b7559090 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Fri, 27 May 2022 23:35:22 -0400 Subject: meta: API Scaffold Initial implementation of a CRUD API for Ships. Should probably at some point support getting specific Ships based on something like shasum or an ID, so that solard can more easily pull it down --- flake.nix | 8 +++++++- src/handlers/mod.rs | 1 + src/handlers/ships.rs | 23 +++++++++++++++++++++++ src/main.rs | 7 +++++-- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/handlers/mod.rs create mode 100644 src/handlers/ships.rs diff --git a/flake.nix b/flake.nix index 4764b03..d1f211b 100644 --- a/flake.nix +++ b/flake.nix @@ -9,12 +9,18 @@ system: let pkgs = nixpkgs.legacyPackages."${system}"; naersk-lib = naersk.lib."${system}"; + + deps = with pkgs; [ + libvirt + ]; in rec { # `nix build` packages.homeworld = naersk-lib.buildPackage { pname = "homeworld"; root = ./.; + nativeBuildInputs = deps; + buildInputs = deps; }; defaultPackage = packages.homeworld; @@ -26,7 +32,7 @@ # `nix develop` devShell = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ rustc cargo ]; + nativeBuildInputs = with pkgs; [ rustc cargo ] ++ deps; }; } ); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs new file mode 100644 index 0000000..2b5bfaf --- /dev/null +++ b/src/handlers/mod.rs @@ -0,0 +1 @@ +pub mod ships; diff --git a/src/handlers/ships.rs b/src/handlers/ships.rs new file mode 100644 index 0000000..5e8c000 --- /dev/null +++ b/src/handlers/ships.rs @@ -0,0 +1,23 @@ +use axum::{Json, extract::Path}; +use solarlib::ship::{Ship, Sha256}; + +use crate::errors::{JsonResult, StringResult}; + + +pub async fn list() -> JsonResult>> { + let mut result: Vec = Vec::new(); + + Ok(Json(result)) +} + +pub async fn new(Json(new_ship): Json) -> StringResult { + unimplemented!(); +} + +pub async fn update(Json(new_ship): Json) -> StringResult { + todo!(); +} + +pub async fn delete(Path(shasum): Path) -> StringResult { + todo!(); +} diff --git a/src/main.rs b/src/main.rs index ba319d9..31271e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use axum::{ error_handling::HandleErrorLayer, http::StatusCode, response::IntoResponse, - routing::get, + routing::{get, post, delete}, Json, Router }; @@ -32,7 +32,10 @@ async fn main() { let app = Router::new() .route("/health", get(health_check)) - .route("/waifus/list", get(handlers::waifus::list)) + .route("/ships/list", get(handlers::ships::list)) + .route("/ships/new", post(handlers::ships::new)) + .route("/ships/update", post(handlers::ships::update)) + .route("/ships/delete/:shasum", delete(handlers::ships::delete)) .layer( ServiceBuilder::new() .layer(HandleErrorLayer::new(|error: BoxError| async move { if error.is::() { -- cgit v1.2.3