From 92146cc2a4e79959a41712721703d969f1c899d8 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Thu, 29 Aug 2019 11:02:27 +0200 Subject: [PATCH 1/2] added sql table creation and config --- src/config.yaml | 6 +++++ src/index.ts | 2 -- src/sql/create-tables.sql | 49 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/config.yaml create mode 100644 src/sql/create-tables.sql diff --git a/src/config.yaml b/src/config.yaml new file mode 100644 index 0000000..536f82f --- /dev/null +++ b/src/config.yaml @@ -0,0 +1,6 @@ +database: + url: localhost + port: 54332 + user: greenvironment + password: greendev + database: greenvironment diff --git a/src/index.ts b/src/index.ts index bd59c0e..b4265bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,3 @@ import App from "./app"; const app = new App(); - -// TODO: init and start diff --git a/src/sql/create-tables.sql b/src/sql/create-tables.sql new file mode 100644 index 0000000..046541f --- /dev/null +++ b/src/sql/create-tables.sql @@ -0,0 +1,49 @@ +CREATE TABLE IF NOT EXISTS users ( + id SERIAL PRIMARY KEY, + name varchar(128) NOT NULL, + password varchar(1024) NOT NULL, + email varchar(128) UNIQUE NOT NULL, + greenpoints INTEGER DEFAULT 0 +); + +CREATE TABLE IF NOT EXISTS feed_items ( + id BIGSERIAL PRIMARY KEY, + upvotes INTEGER DEFAULT 0, + downvotes INTEGER DEFAULT 0, + created_at TIMESTAMP DEFAULT now(), + content text, + author SERIAL REFERENCES users (id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS votes ( + user_id SERIAL REFERENCES users (id) ON DELETE CASCADE, + item_id BIGSERIAL REFERENCES feed_items (id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS events ( + id BIGSERIAL PRIMARY KEY, + time TIMESTAMP, + owner SERIAL REFERENCES users (id) +); + +CREATE TABLE IF NOT EXISTS event_members ( + event BIGSERIAL REFERENCES events (id), + member SERIAL REFERENCES users (id) +); + +CREATE TABLE IF NOT EXISTS chats ( + id BIGSERIAL PRIMARY KEY +); + +CREATE TABLE IF NOT EXISTS chat_messages ( + chat BIGSERIAL REFERENCES chats (id) ON DELETE CASCADE, + author SERIAL REFERENCES users (id) ON DELETE SET NULL, + content VARCHAR(1024) NOT NULL, + created_at TIMESTAMP DEFAULT now(), + PRIMARY KEY (chat, author, created_at) +); + +CREATE TABLE IF NOT EXISTS chat_members ( + chat BIGSERIAL REFERENCES chats (id) ON DELETE CASCADE, + member SERIAL REFERENCES users (id) ON DELETE CASCADE +); From b7d10454ab23e286827ed63d2081c8972fc461f3 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Thu, 29 Aug 2019 13:21:11 +0200 Subject: [PATCH 2/2] Changed tables and graphql schema --- src/public/graphql/schema.graphql | 149 +++++++++++++----------------- src/sql/create-tables.sql | 16 +++- 2 files changed, 76 insertions(+), 89 deletions(-) diff --git a/src/public/graphql/schema.graphql b/src/public/graphql/schema.graphql index 35862f3..f5feb67 100644 --- a/src/public/graphql/schema.graphql +++ b/src/public/graphql/schema.graphql @@ -1,121 +1,100 @@ type Query { - getUser(userId: Id): User - getPost(postId: Id): Post - getChat(chatId: Id): Chat - getRequest(requestId: Id): Request + "returns the user object for a given user id" + getUser(userId: ID): User + "returns the post object for a post id" + getPost(postId: ID): Post + "returns the chat object for a chat id" + getChat(chatId: ID): ChatRoom + "returns the request object for a request id" + getRequest(requestId: ID): Request + "find a post by the posted date or content" + findPost(first: Int, offset: Int, text: String!, postedDate: String): [Post] + "find a user by user name or handle" + findUser(first: Int, offset: Int, name: String!, handle: String!): [User] } type Mutation { - #_____Post_____ - #"Upvote/downvote a Post" - vote(postId: id!, type: [VoteType!]!): Bool - #"Report the post" - report(postId: id!): Bool - #_____Request_____ - #"if u accept a request" - acceptRequest(requestId: id!): bool - #_____ChatRoom_____ - #"send a assage in a Chatroom" - sendMassage(chatId: Id!, massage: String!): bool + "Upvote/downvote a Post" + vote(postId: ID!, type: [VoteType!]!): Boolean + "Report the post" + report(postId: ID!): Boolean + "lets you accept a request for a given request id" + acceptRequest(requestId: ID!): Boolean + "send a message in a Chatroom" + sendMessage(chatId: ID!, content: String!): Boolean } +"represents a single user account" type User { - #"ProfilPicture of the User" - profilPicture: String! - #"name from the User" + "url for the Profile picture of the User" + profilePicture: String! + "name of the User" name: String! - #"unique name from the User" + "unique identifier name from the User" handle: String! - #"Id from the User" - userId: ID! - #"Counted number of al Posts he posted" - numberOfPosts: int - #"show the posts of the User" - getAllPosts(first: int, offset: int): [Post] - #"Date when he/she Created the account" - JoinedDate: Date! - #"all chats for the mainsite(left)" - pinnedChats: [Chats] - #"all friends of the user" + "Id of the User" + id: ID! + "the total number of posts the user posted" + numberOfPosts: Int + "returns a given number of posts of a user" + getAllPosts(first: Int=10, offset: Int): [Post] + "creation date of the user account" + joinedDate: String! + "returns chats the user pinned" + pinnedChats: [ChatRoom] + "returns all friends of the user" friends: [User] - #"all request for groupChats/friends/events" - friends: [Request] + "all request for groupChats/friends/events" + requests: [Request] } +"represents a single user post" type Post { - #"PicturePath" + "returns the path to the posts picture if it has one" picture: String - #"posted Text" + "returns the text of the post" text: String - #"upvotes from Post" + "upvotes of the Post" upvotes: Int! - #"downvotes from Post" + "downvotes of the Post" downvotes: Int! - #"The AuthorID of the Post" + "the user that is the author of the Post" author: User! - #"Creationdate of the Post" - creationDate: Date! - #"Upvoteted/Downvoted the User already (NoVote(Null),Upvote,Downvote)" - alreadyVoted: [VoteType] - #"with tags u can find the post in a research" + "date the post was created" + creationDate: String! + "returns the type of vote the user performed on the post" + alreadyVoted: VoteType + "returns the tags of the post" tags: [String] } -type Search { - #"u can find posts with a name(text) or posted time" - findPost(first: int, offset: int, text: String!, postedDate: Date): [Post] - #"u can find a User with his Name or handle" - findUser(first: int, offset: int, name: String!, handle: string!): [User] -} - +"represents a request of any type" type Request { - #"RequestId" - requestId: Id! - #"RequestType" - requestType: [RequestType!]! + "id of the request" + id: ID! + "type of the request" + requestType: RequestType! } +"represents a chatroom" type ChatRoom { - #"Every User in the room" - members: [Users!] - #"Get the Chat" - getMessages(first: int, offset: int): [String] - #"chatId" - chatId: Id! + "the members of the chatroom" + members: [User!] + "return a specfic range of messages posted in the chat" + getMessages(first: Int, offset: Int): [String] + "id of the chat" + id: ID! } +"represents the type of vote performed on a post" enum VoteType { - UPDATE + UPVOTE DOWNVOTE } +"represents the type of request that the user has received" enum RequestType { FRIENDREQUEST GROUPINVITE EVENTINVITE } - -#type Event { -#} - -#type Comment { -# #"CommentId" -# commentId: Id! -# #"text from the Comment" -# text: String -# #"PostId" -# postId: Id -# #"Upvotes of the comment" -# upvotes: int! -# #"Downvotes of the comment" -# downvotes: int! -# #"Upvoteted/Downvoted the User already (NoVote(Null),Upvote,Downvote)" -# alreadyVoted: [VoteType] -# #"Creationdate of the Post" -# creationDate: Date! -#Comment -# #"Upvote/downvote a Comment" -# vote(CommentId: id!, type: [VoteType!]!): Bool -# #"Report the Comment" -# report(CommentId: id!): Bool -#} diff --git a/src/sql/create-tables.sql b/src/sql/create-tables.sql index 046541f..0d02b2f 100644 --- a/src/sql/create-tables.sql +++ b/src/sql/create-tables.sql @@ -1,23 +1,26 @@ CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, name varchar(128) NOT NULL, + handle varchar(128) UNIQUE NOT NULL, password varchar(1024) NOT NULL, email varchar(128) UNIQUE NOT NULL, - greenpoints INTEGER DEFAULT 0 + greenpoints INTEGER DEFAULT 0, + joined_at TIMESTAMP DEFAULT now() ); -CREATE TABLE IF NOT EXISTS feed_items ( +CREATE TABLE IF NOT EXISTS posts ( id BIGSERIAL PRIMARY KEY, upvotes INTEGER DEFAULT 0, downvotes INTEGER DEFAULT 0, created_at TIMESTAMP DEFAULT now(), content text, - author SERIAL REFERENCES users (id) ON DELETE CASCADE + author SERIAL REFERENCES users (id) ON DELETE CASCADE, + type varchar(16) NOT NULL ); CREATE TABLE IF NOT EXISTS votes ( user_id SERIAL REFERENCES users (id) ON DELETE CASCADE, - item_id BIGSERIAL REFERENCES feed_items (id) ON DELETE CASCADE + item_id BIGSERIAL REFERENCES posts (id) ON DELETE CASCADE ); CREATE TABLE IF NOT EXISTS events ( @@ -47,3 +50,8 @@ CREATE TABLE IF NOT EXISTS chat_members ( chat BIGSERIAL REFERENCES chats (id) ON DELETE CASCADE, member SERIAL REFERENCES users (id) ON DELETE CASCADE ); + +CREATE TABLE IF NOT EXISTS user_friends ( + user_id SERIAL REFERENCES users (id) ON DELETE CASCADE, + friend_id SERIAL REFERENCES users (id) ON DELETE CASCADE +);