compiling state [wip]
parent
f105b2ef2e
commit
3256c7f5fe
|
@ -0,0 +1,8 @@
|
|||
# For documentation on how to configure this file,
|
||||
# see https://diesel.rs/guides/configuring-diesel-cli
|
||||
|
||||
[print_schema]
|
||||
file = "src/schema.rs"
|
||||
|
||||
[migrations_directory]
|
||||
dir = "migrations"
|
|
@ -0,0 +1,12 @@
|
|||
version: "3.7"
|
||||
services:
|
||||
postgres:
|
||||
container_name: 'to-do-postgres'
|
||||
image: 'postgres:latest'
|
||||
restart: always
|
||||
ports:
|
||||
- '5432:5432'
|
||||
environment:
|
||||
- 'POSTGRES_USER=admin'
|
||||
- 'POSTGRES_DB=to_do'
|
||||
- 'POSTGRES_PASSWORD=secret+123'
|
|
@ -0,0 +1,6 @@
|
|||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
|
||||
DROP FUNCTION IF EXISTS diesel_set_updated_at();
|
|
@ -0,0 +1,36 @@
|
|||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
|
||||
|
||||
|
||||
-- Sets up a trigger for the given table to automatically set a column called
|
||||
-- `updated_at` whenever the row is modified (unless `updated_at` was included
|
||||
-- in the modified columns)
|
||||
--
|
||||
-- # Example
|
||||
--
|
||||
-- ```sql
|
||||
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
|
||||
--
|
||||
-- SELECT diesel_manage_updated_at('users');
|
||||
-- ```
|
||||
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
|
||||
BEGIN
|
||||
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
|
||||
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
IF (
|
||||
NEW IS DISTINCT FROM OLD AND
|
||||
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
|
||||
) THEN
|
||||
NEW.updated_at := current_timestamp;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
|
@ -0,0 +1,2 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE users;
|
|
@ -0,0 +1,10 @@
|
|||
-- Your SQL goes here
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR NOT NULL,
|
||||
email VARCHAR NOT NULL,
|
||||
password VARCHAR NOT NULL,
|
||||
unique_id VARCHAR NOT NULL,
|
||||
UNIQUE (email),
|
||||
UNIQUE (username)
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
pub mod user;
|
|
@ -0,0 +1,3 @@
|
|||
pub mod new_user;
|
||||
pub mod user;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
extern crate bcrypt;
|
||||
|
||||
use bcrypt::{hash, DEFAULT_COST};
|
||||
use diesel::Insertable;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::schema::users;
|
||||
|
||||
#[derive(Insertable, Clone)]
|
||||
#[diesel(table_name=users)]
|
||||
pub struct NewUser {
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub unique_id: String,
|
||||
}
|
||||
|
||||
impl NewUser {
|
||||
pub fn new(username: String, email: String, password: String) -> NewUser {
|
||||
let hashed_password: String = hash(password.as_str(), DEFAULT_COST).unwrap();
|
||||
let uuid = Uuid::new_v4();
|
||||
NewUser {
|
||||
username,
|
||||
email,
|
||||
password: hashed_password,
|
||||
unique_id: uuid.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
extern crate bcrypt;
|
||||
|
||||
use bcrypt::verify;
|
||||
use diesel::{Identifiable, Queryable};
|
||||
|
||||
use crate::schema::users;
|
||||
|
||||
#[derive(Queryable, Identifiable)]
|
||||
#[diesel(table_name=users)]
|
||||
#[derive(Clone)]
|
||||
pub struct User {
|
||||
pub id: i32,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub unique_id: String,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn verify(self, password: String) -> bool {
|
||||
return verify(password.as_str(), &self.password).unwrap();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
use std::error::Error;
|
||||
|
||||
use rss::Channel;
|
||||
|
||||
pub async fn get_feed(feed: &String) -> Result<Channel, Box<dyn Error>> {
|
||||
let content = reqwest::get(feed).await?.bytes().await?;
|
||||
let channel = Channel::read_from(&content[..])?;
|
||||
Ok(channel)
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pub mod feeds;
|
|
@ -0,0 +1,11 @@
|
|||
// @generated automatically by Diesel CLI.
|
||||
|
||||
diesel::table! {
|
||||
users (id) {
|
||||
id -> Int4,
|
||||
username -> Varchar,
|
||||
email -> Varchar,
|
||||
password -> Varchar,
|
||||
unique_id -> Varchar,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
use actix_web::web;
|
||||
|
||||
pub fn views_factory(app: &mut web::ServiceConfig) {
|
||||
// auth::auth_factory(app);
|
||||
// to_do::item_factory(app);
|
||||
// app::app_factory(app);
|
||||
// users::user_factory(app);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
pub struct Path {
|
||||
pub prefix: String,
|
||||
pub backend: bool,
|
||||
}
|
||||
|
||||
impl Path {
|
||||
pub fn define(&self, following_path: String) -> String {
|
||||
match self.backend {
|
||||
true => {
|
||||
let path: String = self.prefix.to_owned() + &following_path;
|
||||
return String::from("/api/v1") + &path;
|
||||
}
|
||||
false => self.prefix.to_owned() + &following_path,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue