Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Refactor: Remove duplicated code in custom-server.js #197

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ jobs:
docker-compose -f docker-compose.yml -f docker-compose.prod.yml pull
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d

- name: Rolling updates
uses: appleboy/ssh-action@master
with:
host: 167.172.180.155 # Leader IP
USERNAME: root
KEY: ${{ secrets.CI_swarm_private_key }}
script: |
echo ${{ secrets.db-config }} >> db-config
source db-config
docker stack up minitwit -c minitwit_stack.yml
docker service update -d --image dagandersen/frontend:latest minitwit_fontend

Comment on lines +119 to +130
Copy link
Member

@dag-andersen dag-andersen May 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tænker ikke det giver så meget mening at merge det her - eftersom at clusteret er nede, og dette vil breake pipelinen

Så giver det mere mening at beholde den nede på linje 146/158, som den allerede er på

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OBS: på dette PR står rolling-updates steppet 2 gange i pipelinen

- name: Bump version and push tag
id: tagger
uses: anothrNick/[email protected]
Expand Down
28 changes: 7 additions & 21 deletions backend/src/custom-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,46 +117,32 @@ app.get('/user/:username/:currentUserId?', async (req, res) => {
}
});

app.post('/:username/follow', async (req, res) => {
async function processFollowRequest(req, res, followFunction) {
try {
const { currentUserId } = req.body;
const { username } = req.params;

if (!currentUserId) return res.status(401).send({ error: 'currentUserId is missing' });

const follower = await userRepository.getById(currentUserId);

const followed = await userRepository.getByUsername(username);

if (!follower || !followed) return res.status(404).send({ error: 'User not found' });

await userRepository.addFollow(follower, followed);
await followFunction(follower, followed);

return res.status(204).send();
} catch (err) {
return res.status(500).send(err.message);
}
}

app.post('/:username/follow', async (req, res) => {
await processFollowRequest(req, res, userRepository.addFollow);
});

app.post('/:username/unfollow', async (req, res) => {
try {
const { currentUserId } = req.body;
const { username } = req.params;

if (!currentUserId) return res.status(401).send({ error: 'currentUserId is missing' });

const follower = await userRepository.getById(currentUserId);

const followed = await userRepository.getByUsername(username);

if (!follower || !followed) return res.status(404).send({ error: 'User not found' });

await userRepository.removeFollow(follower, followed);

return res.status(204).send();
} catch (err) {
return res.status(500).send(err.message);
}
await processFollowRequest(req, res, userRepository.removeFollow);
});

app.post('/add_message', async (req, res) => {
Expand Down