Browse Source

Add more files

master
jbell 2 months ago
parent
commit
d7689fafc5
17 changed files with 1807 additions and 0 deletions
  1. +1573
    -0
      Cargo.lock
  2. +12
    -0
      Cargo.toml
  3. +9
    -0
      diesel.toml
  4. +6
    -0
      migrations/00000000000000_diesel_initial_setup/down.sql
  5. +36
    -0
      migrations/00000000000000_diesel_initial_setup/up.sql
  6. +2
    -0
      migrations/2024-10-06-234524_create_issues/down.sql
  7. +8
    -0
      migrations/2024-10-06-234524_create_issues/up.sql
  8. +2
    -0
      migrations/2024-10-06-235235_create_sessions/down.sql
  9. +11
    -0
      migrations/2024-10-06-235235_create_sessions/up.sql
  10. +2
    -0
      migrations/2024-10-07-195451_create_paragraphs/down.sql
  11. +7
    -0
      migrations/2024-10-07-195451_create_paragraphs/up.sql
  12. +2
    -0
      migrations/2024-10-07-200931_create_votes/down.sql
  13. +8
    -0
      migrations/2024-10-07-200931_create_votes/up.sql
  14. +3
    -0
      migrations/2024-10-11-210542_create_comments/down.sql
  15. +17
    -0
      migrations/2024-10-11-210542_create_comments/up.sql
  16. +33
    -0
      src/main.rs
  17. +76
    -0
      src/schema.rs

+ 1573
- 0
Cargo.lock
File diff suppressed because it is too large
View File


+ 12
- 0
Cargo.toml View File

@@ -0,0 +1,12 @@
[package]
name = "puffpastry-backend"
version = "0.1.0"
edition = "2021"

[dependencies]
actix-web = { version = "4", features = ["cookies"] }
serde = { version = "1.0", features = ["derive"] }
diesel = { version = "2.2.0", features = ["postgres", "chrono"] }
dotenvy = "0.15"
chrono = { version = "0.4.38", features = ["serde"] }
uuid = { version = "1.10.0", features = ["v4"] }

+ 9
- 0
diesel.toml View File

@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]

[migrations_directory]
dir = "/home/jbell/RustroverProjects/puffpastry-backend/migrations"

+ 6
- 0
migrations/00000000000000_diesel_initial_setup/down.sql View File

@@ -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();

+ 36
- 0
migrations/00000000000000_diesel_initial_setup/up.sql View File

@@ -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;

+ 2
- 0
migrations/2024-10-06-234524_create_issues/down.sql View File

@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
drop table issues;

+ 8
- 0
migrations/2024-10-06-234524_create_issues/up.sql View File

@@ -0,0 +1,8 @@
-- Your SQL goes here
create table issues (
id serial primary key,
title text not null,
paragraph_count smallint,
telegram_handle text not null,
created_at timestamp
);

+ 2
- 0
migrations/2024-10-06-235235_create_sessions/down.sql View File

@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
drop table sessions;

+ 11
- 0
migrations/2024-10-06-235235_create_sessions/up.sql View File

@@ -0,0 +1,11 @@
-- Your SQL goes here
create table sessions (
id bigserial primary key,
session_id text not null,
user_id bigint not null,
auth_date bigint,
username text,
first_name text,
last_name text,
photo_url text
)

+ 2
- 0
migrations/2024-10-07-195451_create_paragraphs/down.sql View File

@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
drop table paragraphs;

+ 7
- 0
migrations/2024-10-07-195451_create_paragraphs/up.sql View File

@@ -0,0 +1,7 @@
-- Your SQL goes here
create table paragraphs (
id bigserial primary key,
content text not null,
index int not null,
post_id int not null references issues(id)
);

+ 2
- 0
migrations/2024-10-07-200931_create_votes/down.sql View File

@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
drop table issue_votes;

+ 8
- 0
migrations/2024-10-07-200931_create_votes/up.sql View File

@@ -0,0 +1,8 @@
-- Your SQL goes here
create table issue_votes (
id bigserial primary key,
positive boolean,
issue_id int not null references issues (id),
user_id bigint not null,
unique (issue_id, user_id)
);

+ 3
- 0
migrations/2024-10-11-210542_create_comments/down.sql View File

@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
drop table comment_votes;
drop table comments;

+ 17
- 0
migrations/2024-10-11-210542_create_comments/up.sql View File

@@ -0,0 +1,17 @@
-- Your SQL goes here
create table comments (
id bigserial primary key,
content text not null,
parent bigint references comments (id) on delete cascade,
telegram_handle text not null,
issue_id int not null references issues (id),
created_at timestamp
);

create table comment_votes (
id bigserial primary key,
positive boolean,
comment_id bigint not null references comments(id),
user_id bigint not null,
unique (comment_id, user_id)
)

+ 33
- 0
src/main.rs View File

@@ -0,0 +1,33 @@
pub mod db;
pub mod models;
pub mod schema;
pub mod repositories;
pub mod api;

use actix_web::{web, App, HttpServer, Responder};
use api::{issue, session};
use crate::api::comment;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(
web::scope("/issues")
.route("/create", web::post().to(issue::add_issue))
.route("/list", web::get().to(issue::list_issues))
.route("/paragraphs", web::get().to(issue::get_paragraphs))
.route("/vote", web::post().to(issue::vote_issue))
.route("/get_vote", web::get().to(issue::get_user_vote))
.route("/comments", web::get().to(comment::get_comments))
)
.service(
web::scope("/sessions")
.route("/authenticate", web::post().to(session::authenticate))
.route("/get_username", web::get().to(session::get_username))
)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}

+ 76
- 0
src/schema.rs View File

@@ -0,0 +1,76 @@
// @generated automatically by Diesel CLI.

diesel::table! {
comment_votes (id) {
id -> Int8,
positive -> Nullable<Bool>,
comment_id -> Int8,
user_id -> Int8,
}
}

diesel::table! {
comments (id) {
id -> Int8,
content -> Text,
parent -> Nullable<Int8>,
telegram_handle -> Text,
issue_id -> Int4,
created_at -> Nullable<Timestamp>,
}
}

diesel::table! {
issue_votes (id) {
id -> Int8,
positive -> Nullable<Bool>,
issue_id -> Int4,
user_id -> Int8,
}
}

diesel::table! {
issues (id) {
id -> Int4,
title -> Text,
paragraph_count -> Nullable<Int2>,
telegram_handle -> Text,
created_at -> Nullable<Timestamp>,
}
}

diesel::table! {
paragraphs (id) {
id -> Int8,
content -> Text,
index -> Int4,
post_id -> Int4,
}
}

diesel::table! {
sessions (id) {
id -> Int8,
session_id -> Text,
user_id -> Int8,
auth_date -> Nullable<Int8>,
username -> Nullable<Text>,
first_name -> Nullable<Text>,
last_name -> Nullable<Text>,
photo_url -> Nullable<Text>,
}
}

diesel::joinable!(comment_votes -> comments (comment_id));
diesel::joinable!(comments -> issues (issue_id));
diesel::joinable!(issue_votes -> issues (issue_id));
diesel::joinable!(paragraphs -> issues (post_id));

diesel::allow_tables_to_appear_in_same_query!(
comment_votes,
comments,
issue_votes,
issues,
paragraphs,
sessions,
);

Loading…
Cancel
Save