|
|
@ -14,16 +14,17 @@ struct AppState {
|
|
|
|
#[get("/comments")]
|
|
|
|
#[get("/comments")]
|
|
|
|
async fn get_comments(data: web::Data<AppState>) -> impl Responder {
|
|
|
|
async fn get_comments(data: web::Data<AppState>) -> impl Responder {
|
|
|
|
let db = &data.db.lock().unwrap();
|
|
|
|
let db = &data.db.lock().unwrap();
|
|
|
|
/*db.create_comment(&Comment {
|
|
|
|
HttpResponse::Ok().json(&db.get_comments().unwrap())
|
|
|
|
author: Some("Elnu".to_string()),
|
|
|
|
|
|
|
|
text: "Hello world".to_string()
|
|
|
|
|
|
|
|
}).unwrap();*/
|
|
|
|
|
|
|
|
HttpResponse::Ok().body(format!("{}", db.get_comments().unwrap().get(0).unwrap_or(&Comment { author: None, text: "No comments yet!".to_string() }).text))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
|
|
let state = web::Data::new(AppState { db: Mutex::new(Database::new().unwrap()) });
|
|
|
|
let db = Database::new().unwrap();
|
|
|
|
|
|
|
|
db.create_comment(&Comment {
|
|
|
|
|
|
|
|
author: None,
|
|
|
|
|
|
|
|
text: "This is anonymous test comment!".to_string(),
|
|
|
|
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let state = web::Data::new(AppState { db: Mutex::new(db) });
|
|
|
|
HttpServer::new(move || {
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
App::new()
|
|
|
|
.service(get_comments)
|
|
|
|
.service(get_comments)
|
|
|
|