Skip to content

Commit

Permalink
refactor: add description for prompt and move field description from …
Browse files Browse the repository at this point in the history
…input into schema
  • Loading branch information
Randoooom committed Mar 17, 2024
1 parent ddbe535 commit 76b1e85
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ script = "docker compose -f tests/_common/oidc-mock/docker-compose.yaml up -d"
script = "docker run --name postgres -e POSTGRES_PASSWORD=password -e POSTGRES_USERNAME=postgres -p 5150:5432 -d postgres && sleep 1"

[tasks.postgres_tests]
env = { DATABASE = "POSTGRES", POSTGRES_USERNAME = "postgres", POSTGRES_PASSWORD = "password", POSTGRES_ENDPOINT = "localhost:5150", POSTGRES_DATABASE = "postgres", "OIDC_DISCOVERY_URL" = "http://localhost:5151", OIDC_CLIENT_ID = "client", OIDC_CLIENT_SECRET = "secret", OIDC_SCOPE = "api:feedback-fusion" }
env = { DATABASE = "POSTGRES", POSTGRES_USERNAME = "postgres", POSTGRES_PASSWORD = "password", POSTGRES_ENDPOINT = "localhost:5150", POSTGRES_DATABASE = "postgres", "OIDC_DISCOVERY_URL" = "http://localhost:5151", OIDC_CLIENT_ID = "client", OIDC_CLIENT_SECRET = "secret", OIDC_SCOPE = "api:feedback-fusion", RUST_LOG = "INFO" }
command = "cargo"
args = [
"test",
Expand Down
4 changes: 3 additions & 1 deletion src/database/postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS feedback_target (
CREATE TABLE IF NOT EXISTS feedback_prompt (
id VARCHAR(32) UNIQUE NOT NULL,
title VARCHAR(32) NOT NULL,
description VARCHAR(255) NOT NULL,
target VARCHAR(32) REFERENCES feedback_target(id) NOT NULL,
active BOOLEAN NOT NULL,
updated_at TIMESTAMP,
Expand All @@ -17,7 +18,8 @@ CREATE TABLE IF NOT EXISTS feedback_prompt (

CREATE TABLE IF NOT EXISTS feedback_prompt_field (
id VARCHAR(32) UNIQUE NOT NULL,
title VARCHAR(255) NOT NULL,
title VARCHAR(32) NOT NULL,
description VARCHAR(255),
prompt VARCHAR(32) REFERENCES feedback_prompt(id) NOT NULL,
type VARCHAR(32) NOT NULL,
options JSON NOT NULL,
Expand Down
4 changes: 0 additions & 4 deletions src/database/schema/feedback/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ impl PartialEq<FeedbackPromptInputOptions> for FeedbackPromptInputType {
#[builder(field_defaults(setter(into)))]
#[cfg_attr(feature = "bindings", derive(TS))]
pub struct TextOptions {
#[validate(length(max = 255))]
description: String,
#[validate(length(max = 255))]
placeholder: String,
}
Expand All @@ -58,8 +56,6 @@ pub struct TextOptions {
#[builder(field_defaults(setter(into)))]
#[cfg_attr(feature = "bindings", derive(TS))]
pub struct RatingOptions {
#[validate(length(max = 255))]
description: String,
max: u8,
}

Expand Down
6 changes: 5 additions & 1 deletion src/database/schema/feedback/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub struct FeedbackPrompt {
id: String,
#[validate(length(max = 255))]
title: String,
#[validate(length(max = 255))]
description: String,
target: String,
#[builder(default = true)]
active: bool,
Expand Down Expand Up @@ -92,8 +94,10 @@ pub enum FeedbackPromptInputType {
pub struct FeedbackPromptField {
#[builder(default_code = r#"nanoid::nanoid!()"#)]
id: String,
#[validate(length(max = 255))]
#[validate(length(max = 32))]
title: String,
#[validate(length(max = 255))]
description: Option<String>,
prompt: String,
r#type: FeedbackPromptInputType,
#[cfg(not(feature = "bindings"))]
Expand Down
10 changes: 8 additions & 2 deletions src/routes/v1/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ pub async fn router(state: FeedbackFusionState) -> Router<FeedbackFusionState> {
#[derive(ToSchema, Deserialize, Debug, Clone, Validate)]
#[cfg_attr(feature = "bindings", derive(TS))]
pub struct CreateFeedbackPromptRequest {
#[validate(length(max = 255))]
#[validate(length(max = 32))]
title: String,
#[serde(default = "bool_true")]
active: bool,
#[validate(length(max = 255))]
description: String,
}

fn bool_true() -> bool {
Expand All @@ -66,6 +68,7 @@ pub async fn post_prompt(
// build the prompt
let prompt = FeedbackPrompt::builder()
.title(data.title)
.description(data.description)
.active(data.active)
.target(target)
.build();
Expand Down Expand Up @@ -166,8 +169,10 @@ pub async fn delete_prompt(
#[derive(Debug, Clone, ToSchema, Deserialize, Validate)]
#[cfg_attr(feature = "bindings", derive(TS))]
pub struct CreateFeedbackPromptFieldRequest {
#[validate(length(max = 255))]
#[validate(length(max = 32))]
title: String,
#[validate(length(max = 255))]
description: Option<String>,
r#type: FeedbackPromptInputType,
options: FeedbackPromptInputOptions,
}
Expand Down Expand Up @@ -197,6 +202,7 @@ pub async fn post_field(
let options = data.options;
let field = FeedbackPromptField::builder()
.title(data.title)
.description(data.description)
.r#type(data.r#type)
.options(options)
.prompt(prompt)
Expand Down
4 changes: 2 additions & 2 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::{
path::Path,
process::{Child, Command, Stdio},
};
use tracing::debug;
use tracing::{debug, info};

pub const HTTP_ENDPOINT: &'static str = "http://localhost:8000";

Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn run_server() -> BackendServer {
let stderr = Stdio::from(
File::create(Path::new(env!("OUT_DIR")).join(format!("{}stderr", seed))).unwrap(),
);
debug!("OUT={} SEED={}", env!("OUT_DIR"), seed);
info!("OUT={} SEED={}", env!("OUT_DIR"), seed);

command.stdin(Stdio::piped());
command.stdout(stdout);
Expand Down
12 changes: 8 additions & 4 deletions tests/http_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ async fn test_prompt_endpoints() {
let response = client
.post(format!("{}/v1/target/{}/prompt", HTTP_ENDPOINT, &target.id))
.json(&serde_json::json!({
"title": "title"
"title": "title",
"description": "description"
}))
.send()
.await
Expand Down Expand Up @@ -362,7 +363,8 @@ async fn test_prompt_field_endpoints() {
let response = client
.post(format!("{}/v1/target/{}/prompt", HTTP_ENDPOINT, &target.id))
.json(&serde_json::json!({
"title": "title"
"title": "title",
"description": "description"
}))
.send()
.await
Expand All @@ -375,7 +377,8 @@ async fn test_prompt_field_endpoints() {
.post(format!("{}/v1/target/{}/prompt", HTTP_ENDPOINT, &target.id))
.json(&serde_json::json!({
"title": "title",
"active": false
"active": false,
"description": "description"
}))
.send()
.await
Expand Down Expand Up @@ -602,7 +605,8 @@ async fn test_response_endpoints() {
let response = client
.post(format!("{}/v1/target/{}/prompt", HTTP_ENDPOINT, &target.id))
.json(&serde_json::json!({
"title": "title"
"title": "title",
"description": "description"
}))
.send()
.await
Expand Down

0 comments on commit 76b1e85

Please sign in to comment.