Skip to content

Commit

Permalink
Merge pull request #21 from HoseaCodes/feat/gamePage
Browse files Browse the repository at this point in the history
feat(*): add game console
  • Loading branch information
HoseaCodes authored May 23, 2024
2 parents 0083008 + 5d86a14 commit 40283a6
Show file tree
Hide file tree
Showing 389 changed files with 20,021 additions and 1,267 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
npm-debug.log
yarn-error.log
.DS_Store
.git
.gitignore
*.md
26 changes: 26 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
# - uses: AppThreat/sast-scan-action@master
# with:
# type: "python"

# - uses: actions/upload-artifact@v1
# with:
# name: reports
# path: reports
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ src/.eslintrc.js

test/coverage

animation
animation

dump

output.json
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM node:20

# Set the working directory in the container
WORKDIR /usr/src/app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
Expand All @@ -17,11 +17,7 @@ COPY . .
RUN npm run build

# Expose the port the app runs on
EXPOSE 3000

# Set environment variables from .env file
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
EXPOSE 3001

# Copy .env file to the working directory
COPY .env .
Expand Down
53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,20 @@ Dependencies used:

See [wiki](https://github.com/HoseaCodes/Blog/wiki/Frontend) for details.

## Data

See [wiki](https://github.com/HoseaCodes/Blog/wiki/Data) for details.

## Backend

### Security

#### Basic Auth & JWT

![Security](https://i.imgur.com/ZD1gtVH.png)

![JWT](https://i.imgur.com/lFIJa0b.png)

See [wiki](https://github.com/HoseaCodes/Blog/wiki/Backend) for details.

## Dev Ops
Expand Down Expand Up @@ -116,14 +128,33 @@ See [wiki](https://github.com/HoseaCodes/Blog/wiki/External-APIs) for details.
Build image locally

```docker
docker build -t hoseacodes_blog .
docker build -t hoseacodes-blog .
```
Run local image in container

```docker
docker run --name hoseacodes_blog_c -p 3000:3000 -d hoseacodes_blog
docker run --name hoseacodes-blog-c -p 3001:3001 -d hoseacodes-blog
```

Tag Image for push

```docker
docker tag ${imageID} hoseacodes/hoseacodes/hoseacodes-blog:latest
```

Push Docker Image

```docker
docker push hoseacodes/hoseacodes-blog:latest
```

## How To Deploy App

```bash
git push heroku-staging HEAD:main
```


## Unsolved Problems

- [ ] Fix Docker Image
Expand All @@ -141,8 +172,8 @@ docker run --name hoseacodes_blog_c -p 3000:3000 -d hoseacodes_blog
- Syntax/Code Highlighting
- Tags - Topics
- Reactions
- ~~View Comment~~
- ~~Minutes Read~~
- [x] ~~View Comment~~
- [x] ~~Minutes Read~~

https://github.com/saadpasta/react-blog-github

Expand All @@ -151,13 +182,13 @@ docker run --name hoseacodes_blog_c -p 3000:3000 -d hoseacodes_blog
- Sign up to newletter on blog page.
- with Brevo
- Article Updates
- Save a blog post to favorites
- Save blog post as a draft
- Schedule blog post
- Track views to blog post
- Like a comment
- Handle notifications button on blog post
- Allow signed in user the ability to edit post.
- [ ] Save a blog post to favorites
- [x] Save blog post as a draft
- [ ] Schedule blog post
- [ ] Track views to blog post
- [ ] Like a comment
- [ ] Handle notifications button on blog post
- [ ] Allow signed in user the ability to edit post.
- User Updates
- Save user to favorite authors
- Follow the author
Expand Down
3 changes: 3 additions & 0 deletions config/db.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import mongoose from 'mongoose';
import dotenv from 'dotenv';

dotenv.config();

const connectDB = async () => {
const URI = process.env.MONGODB_URL || "mongodb://localhost:27017/"
Expand Down
40 changes: 17 additions & 23 deletions controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ async function createArticle(req, res) {
subtitle,
markdown,
description,
draft,
scheduled,
scheduledDateTime,
images,
categories,
dev,
Expand Down Expand Up @@ -110,11 +113,21 @@ async function createArticle(req, res) {
return res.status(400).json({ msg: "This article already exists." });
}

if (scheduled & scheduledDateTime) {
if (new Date(scheduledDateTime) < new Date()) {
logger.error("Scheduled date is in the past.");
return res.status(400).json({ msg: "Scheduled date is in the past." });
}
}

const newArticle = new Articles({
article_id,
title,
subtitle,
markdown,
draft,
scheduled,
scheduledDateTime,
description,
images,
postedBy,
Expand Down Expand Up @@ -267,42 +280,23 @@ async function updateArticleComment(req, res) {

async function updateArticle(req, res) {
try {
const {
title,
subtitle,
description,
content,
images,
category,
comments,
draft,
archive,
} = req.body;
const originalBody = req.body;
const { title, comments, draft, archive, ...rest } = originalBody;

const originalArticle = await Articles.findOne({ _id: req.params.id });

res.clearCookie("articles-cache");

const originalBody = req.body;

if (comments) {
await Articles.findOneAndUpdate(
{ _id: req.params.id },
{
// title: title.toLowerCase(),
// subtitle,
// description,
// content,
// images,
// category,
comments: [originalArticle.comments, ...comments],
}
);
}

if (draft) {
console.log(`draft`);
console.log(draft);
await Articles.findOneAndUpdate(
{ _id: req.params.id },
{
Expand All @@ -312,8 +306,6 @@ async function updateArticle(req, res) {
}

if (archive) {
console.log(`archive`);
console.log(archive);
await Articles.findOneAndUpdate(
{ _id: req.params.id },
{
Expand All @@ -322,6 +314,8 @@ async function updateArticle(req, res) {
);
}

await Articles.findOneAndUpdate({ _id: req.params.id }, rest);

const preparedLog = `Changing the following: ${originalBody} to ${req.body} for the article ${title}`;

logger.info(preparedLog);
Expand Down
118 changes: 118 additions & 0 deletions controllers/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import Payments from "../models/player";
import Users from "../models/user.js";


async function getPlayers(req, res) {
try {
const players = await Player.find();
res.json(players);
} catch (err) {
return res.status(500).json({ msg: err.message });
}
}

async function getbadges(req, res) {
try {
const players = await Player.find({username: req.params.username});
res.json(players.badges);
} catch (err) {
return res.status(500).json({ msg: err.message });
}
}

async function createPlayer(req, res) {
try {
const user = await Users.findById(req.user.id);
if (!user) return res.status(400).json({ msg: "User does not exist" });

let { username, paymentID } = req.body;

const { _id, name, email } = user;

const newPlayer = new Player({
user_id: _id,
name: name,
email: email,
username: username,
paymentID: paymentID,
rank: 0,
reputation: 0,
badges: {
name: "New User",
points: 10
}
});

await newPlayer.save();
res.json({ msg: "Player created successfully" });
} catch (err) {
return res.status(500).json({ msg: err.message });
}
}

async function createbadge(req, res) {
try {
const { badge } = req.body;

const player = await Player.findOneAndUpdate({ _id: req.params.id }, {
badges: badge
})

if (!player) return res.status(400).json({ msg: "Plater does not exist" });


res.json({ msg: "Badge assigned successfully" });
} catch (err) {
return res.status(500).json({ msg: err.message });
}
}

async function deletePlayer(req, res) {
try {

await Player.findByIdAndDelete(req.params.id)

logger.info(`Deleted player ${req.params.id} has been deleted`);

res.json({ msg: `Deleted player: ${req.params.id}` })
} catch (err) {

logger.error(err)

return res.status(500).json({ msg: err.message })
}
}

async function updatePlayer(req, res) {
try {
const { rank, username, reputation, paymentID, badges } = req.body;

const originalBody = req.body

await Player.findOneAndUpdate({ _id: req.params.id }, {
rank, username, reputation, paymentID, badges
})

const preparedLog = `Changing the following: ${originalBody} to ${req.body} for the player ${username}`;

logger.info(preparedLog);

res.json({ msg: `Updated player ${username}` })
} catch (err) {

logger.error(err);

return res.status(500).json({ msg: err.message });
}
}



export {
createPlayer,
createbadge,
getPlayers,
getbadges,
deletePlayer,
updatePlayer
};
Loading

0 comments on commit 40283a6

Please sign in to comment.