Skip to content

Commit

Permalink
fix package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkplug0025 committed Sep 6, 2024
1 parent 5821a85 commit 5ca24c7
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 51 deletions.
22 changes: 21 additions & 1 deletion services/user/Workshop/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions services/user/Workshop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
[workspace]
resolver = "2"
members = ["service", "query", "plugin"]

[package]
name = "workshop_package"
edition = "2021"

[workspace.package]
version = "0.1.0"
rust-version = "1.64"
edition = "2021"
publish = false
repository = "https://github.com/gofractally/psibase"
homepage = "https://psibase.io"

[package.metadata.psibase]
package-name = "Workshop"
package-name = "workshop"
description = "Workshop for psibase apps"
services = ["workshop"]

[profile.release]
codegen-units = 1
opt-level = "s"
debug = false
strip = true
lto = true

[lib]
crate-type = ["rlib"]

[dependencies]
workshop = { path = "service", version = "0.1.0" }
r-workshop = { path = "query", version = "0.1.0" }
workshop = { path = "service" }
r-workshop = { path = "query" }
12 changes: 8 additions & 4 deletions services/user/Workshop/plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[package]
name = "workshop-plugin"
version = "0.1.0"
edition = "2021"
name = "plugin"
version.workspace = true
rust-version.workspace = true
repository.workspace = true
homepage.workspace = true
edition.workspace = true
publish = false

[dependencies]
wit-bindgen-rt = { version = "0.26.0", features = ["bitflags"] }
wit-bindgen-rt = { version = "0.30.0", features = ["bitflags"] }
psibase = { path="../../../../rust/psibase" }
workshop = { path="../service" }

Expand Down
10 changes: 8 additions & 2 deletions services/user/Workshop/query/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[package]
name = "r-workshop"
description = "Query service for Workshop"
version.workspace = true
rust-version.workspace = true
repository.workspace = true
homepage.workspace = true
edition = "2021"
version = "0.1.0"
publish = false

[package.metadata.psibase]
Expand All @@ -11,5 +14,8 @@ plugin = "workshop-plugin"
[dependencies]
psibase = { path = "../../../../rust/psibase" }
serde = "1.0"
workshop = { path = "../service", version = "0.1.0" }
workshop = { path = "../service" }
async-graphql = "7.0.7"

[dev-dependencies]
workshop_package = { path = ".." }
25 changes: 13 additions & 12 deletions services/user/Workshop/query/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#[psibase::service]
#[allow(non_snake_case)]
mod service {
use workshop;
use async_graphql::*;
use psibase::*;
use workshop;

#[table(record = "WebContentRow", index = 0)]
struct WebContentTable;

#[action]
fn storeSys(path: String, contentType: String, content: Hex<Vec<u8>>) {
println!("{} {}", path, contentType);
store_content(path, contentType, content, &WebContentTable::new()).unwrap()
}

pub struct Query;

Expand All @@ -14,22 +23,14 @@ mod service {
&self,
account_id: AccountNumber,
) -> Option<workshop::service::AppMetadata> {
workshop::service::AppMetadataTable::new()
.get_index_pk()
.get(&account_id)
}

async fn event(
&self,
id: u64,
) -> Result<workshop::service::event_structs::HistoryEvents, anyhow::Error> {
get_event(id)
let x = workshop::Wrapper::call().getAppMetadata(account_id);
x
}
}

#[action]
fn serveSys(request: HttpRequest) -> Option<HttpReply> {
None.or_else(|| serve_content(&request, &workshop::service::WebContentTable::new()))
None.or_else(|| serve_content(&request, &WebContentTable::new()))
.or_else(|| serve_simple_ui::<workshop::Wrapper>(&request))
.or_else(|| serve_graphql(&request, Query))
.or_else(|| serve_graphiql(&request))
Expand Down
14 changes: 7 additions & 7 deletions services/user/Workshop/service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[package]
name = "workshop"
description = "Workshop Service"
edition = "2021"
version = "0.1.0"
version.workspace = true
rust-version.workspace = true
repository.workspace = true
homepage.workspace = true
edition.workspace = true
publish = false

[package.metadata.psibase]
server = "r-workshop"

[package.metadata.psibase.dependencies]
HttpServer = "0.12.0"

# [lib]
# path = "src/lib.rs"
# crate-type = ["cdylib"]

[dependencies]
psibase = { path = "../../../../rust/psibase" }
serde = { version = "1", features = ["derive"] }
async-graphql = "7.0.7"
serde_json = "1.0.120"

[dev-dependencies]
workshop_package = { path = "..", version = "0.1.0" }
workshop_package = { path = ".." }
27 changes: 6 additions & 21 deletions services/user/Workshop/service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#[psibase::service]
#[allow(non_snake_case)]
mod service {
pub mod service {
use async_graphql::*;
use psibase::*;
use serde::{Deserialize, Serialize};

/// Holds metadata for a registered app
#[table(name = "AppMetadataTable", index = 0)]
#[derive(Debug, Clone, Fracpack, ToSchema, Serialize, Deserialize, SimpleObject)]
struct AppMetadata {
pub struct AppMetadata {
/// The unique identifier for the app
#[primary_key]
account_id: AccountNumber,
Expand Down Expand Up @@ -38,9 +38,6 @@ mod service {
status: String, // todo: change to enum
}

#[table(record = "WebContentRow", index = 1)]
struct WebContentTable;

#[action]
fn getAppMetadata(account_id: AccountNumber) -> Option<AppMetadata> {
AppMetadataTable::new().get_index_pk().get(&account_id)
Expand All @@ -61,6 +58,8 @@ mod service {
let app_metadata_table = AppMetadataTable::new();
let account_id = get_sender();

// todo: read the app metadata first and only update the fields that are passed in

let app_metadata = AppMetadata {
account_id,
name,
Expand All @@ -75,25 +74,11 @@ mod service {

app_metadata_table.put(&app_metadata).unwrap();

Wrapper::emit().history().setAppMetadata(app_metadata);
}

#[action]
fn storeSys(path: String, contentType: String, content: Hex<Vec<u8>>) {
println!("{} {}", path, contentType);
store_content(path, contentType, content, &WebContentTable::new()).unwrap()
Wrapper::emit().history().appMetaChanged(app_metadata);
}

#[event(history)]
fn setAppMetadata(app_metadata: AppMetadata) {}

// #[action]
// fn serveSys(request: HttpRequest) -> Option<HttpReply> {
// None.or_else(|| serve_content(&request, &WebContentTable::new()))
// .or_else(|| serve_simple_ui::<Wrapper>(&request))
// .or_else(|| serve_graphql(&request, Query))
// .or_else(|| serve_graphiql(&request))
// }
fn appMetaChanged(app_metadata: AppMetadata) {}
}

#[psibase::test_case(packages("Workshop"))]
Expand Down

0 comments on commit 5ca24c7

Please sign in to comment.