Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimi Mikadze committed Sep 30, 2019
0 parents commit f9fe43c
Show file tree
Hide file tree
Showing 162 changed files with 21,166 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dependencies
node_modules/

# IDE
.idea/
.vscode/

# Misc
.env
.DS_Store

# Package manager
npm-debug.log*
yarn-debug.log*
yarn-error.log*

44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# The Wall

## API GraphQL

Create `.env` file with the following content

(replace user, password and SECRET with your custom one)

```
# API PORT
API_PORT=4000
# API URL
API_URL=http://localhost
# CLIENT URL
CLIENT_URL=http://localhost:3000
# MONGO URL
MONGO_URL=mongodb://tazokochievi:[email protected]:55606/the-wall
# SECRET
SECRET=mskfasjnfakjsnfkjasnfjkasnfjkansjk
# CLOUDINARY
CLOUDINARY_CLOUD_NAME=drwkapa8p
CLOUDINARY_API_KEY=292887744273742
CLOUDINARY_SECRET=kUsxrMtHmnO6eBe0JHRRAn_aFp4
```

npm install dependencies `npm i`
start server `npm start`

## Client React App

Create `.env` file with the following content

```
# API URL
REACT_APP_API_URL=http://localhost:4000/graphql
```

npm install dependencies `npm i`
start server `npm start`
21 changes: 21 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# API Post
API_PORT=4000

# Front end URL
FRONTEND_URL=http://localhost:3000

# MongoDB URL from mlab.com or Local one
MONGO_URL=mongodb://demo:[email protected]:21099/create-social-network

# Secret
SECRET=Super!@Strong!!@::!Secret

# Cloudinary CDN
CLOUDINARY_CLOUD_NAME=dkkf9iqnd
CLOUDINARY_API_KEY=345283128864692
CLOUDINARY_SECRET=lx3iSxt-1c_LO5ma3P_RLT8TF3Q

# Mail Provider
MAIL_SERVICE="Gmail" # Email services
MAIL_USER="[email protected]" # Email address
MAIL_PASS="password" # Email password
1 change: 1 addition & 0 deletions api/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
9 changes: 9 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* We are using ESM ECMAScript module loader
* to use import/export syntax without using babel or any other compiler
* https://github.com/standard-things/esm
*/

require = require("esm")(module);

module.exports = require("./server.js");
28 changes: 28 additions & 0 deletions api/models/Comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import mongoose from "mongoose";

const Schema = mongoose.Schema;

/**
* Comments schema that has reference to Post and user schemas
*/
const commentSchema = Schema(
{
comment: {
type: String,
required: true
},
post: {
type: Schema.Types.ObjectId,
ref: "Post"
},
author: {
type: Schema.Types.ObjectId,
ref: "User"
}
},
{
timestamps: true
}
);

export default mongoose.model("Comment", commentSchema);
24 changes: 24 additions & 0 deletions api/models/Follow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mongoose from "mongoose";

const Schema = mongoose.Schema;

/**
* Follow schema that has references to User schema
*/
const followSchema = Schema(
{
user: {
type: Schema.Types.ObjectId,
ref: "User"
},
follower: {
type: Schema.Types.ObjectId,
ref: "User"
}
},
{
timestamps: true
}
);

export default mongoose.model("Follow", followSchema);
24 changes: 24 additions & 0 deletions api/models/Like.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mongoose from "mongoose";

const Schema = mongoose.Schema;

/**
* Like schema that has references to Post and User schema
*/
const likeSchema = Schema(
{
post: {
type: Schema.Types.ObjectId,
ref: "Post"
},
user: {
type: Schema.Types.ObjectId,
ref: "User"
}
},
{
timestamps: true
}
);

export default mongoose.model("Like", likeSchema);
41 changes: 41 additions & 0 deletions api/models/Notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import mongoose from "mongoose";

const Schema = mongoose.Schema;

/**
* Notification schema that has references to User, Like, Follow and Comment schemas
*/
const notificationSchema = Schema(
{
author: {
type: Schema.Types.ObjectId,
ref: "User"
},
user: {
type: Schema.Types.ObjectId,
ref: "User"
},
post: Schema.Types.ObjectId,
like: {
type: Schema.Types.ObjectId,
ref: "Like"
},
follow: {
type: Schema.Types.ObjectId,
ref: "Follow"
},
comment: {
type: Schema.Types.ObjectId,
ref: "Comment"
},
seen: {
type: Boolean,
default: false
}
},
{
timestamps: true
}
);

export default mongoose.model("Notification", notificationSchema);
35 changes: 35 additions & 0 deletions api/models/Post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import mongoose from "mongoose";

const Schema = mongoose.Schema;

/**
* Post schema that has references to User, Like and Comment schemas
*/
const postSchema = Schema(
{
title: String,
image: String,
imagePublicId: String,
author: {
type: Schema.Types.ObjectId,
ref: "User"
},
likes: [
{
type: Schema.Types.ObjectId,
ref: "Like"
}
],
comments: [
{
type: Schema.Types.ObjectId,
ref: "Comment"
}
]
},
{
timestamps: true
}
);

export default mongoose.model("Post", postSchema);
101 changes: 101 additions & 0 deletions api/models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import mongoose from "mongoose";
import bcrypt from "bcryptjs";

const Schema = mongoose.Schema;

/**
* User schema that has references to Post, Like, Comment, Follow and Notification schemas
*/
const userSchema = new Schema(
{
fullName: {
type: String,
required: true
},
email: {
type: String,
required: true,
lowercase: true,
trim: true,
unique: true
},
username: {
type: String,
required: true,
lowercase: true,
trim: true,
unique: true
},
passwordResetToken: String,
passwordResetTokenExpiry: Date,
password: {
type: String,
required: true
},
image: String,
imagePublicId: String,
coverImage: String,
coverImagePublicId: String,
posts: [
{
type: Schema.Types.ObjectId,
ref: "Post"
}
],
likes: [
{
type: Schema.Types.ObjectId,
ref: "Like"
}
],
comments: [
{
type: Schema.Types.ObjectId,
ref: "Comment"
}
],
followers: [
{
type: Schema.Types.ObjectId,
ref: "Follow"
}
],
following: [
{
type: Schema.Types.ObjectId,
ref: "Follow"
}
],
notifications: [
{
type: Schema.Types.ObjectId,
ref: "Notification"
}
]
},
{
timestamps: true
}
);

/**
* Hashes the users password when saving it to DB
*/
userSchema.pre("save", function(next) {
if (!this.isModified("password")) {
return next();
}

bcrypt.genSalt(10, (err, salt) => {
if (err) return next(err);

bcrypt.hash(this.password, salt, (err, hash) => {
if (err) return next(err);

this.password = hash;
next();
});
});
});

export default mongoose.model("User", userSchema);
15 changes: 15 additions & 0 deletions api/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import User from "./User";
import Post from "./Post";
import Like from "./Like";
import Follow from "./Follow";
import Comment from "./Comment";
import Notification from "./Notification";

export default {
User,
Post,
Like,
Follow,
Comment,
Notification
};
9 changes: 9 additions & 0 deletions api/models/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Models

Models are fancy constructors compiled from Schema definitions. An instance of a model is called a document. Models are responsible for creating and reading documents from the underlying MongoDB database.

https://mongoosejs.com/docs/models.html

### Referencing documents in other collections

https://mongoosejs.com/docs/populate.html
Loading

0 comments on commit f9fe43c

Please sign in to comment.