-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- This example application is used in the module *software quality* - See [exercise on CI](https://github.com/fhswf/softwarequalitaet/blob/main/Exercises/CI_ToDo/README.md)
- Loading branch information
Showing
16 changed files
with
10,057 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM mcr.microsoft.com/devcontainers/javascript-node:0-18 | ||
|
||
# Install MongoDB command line tools - though mongo-database-tools not available on arm64 | ||
ARG MONGO_TOOLS_VERSION=6.0 | ||
RUN . /etc/os-release \ | ||
&& curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ | ||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ | ||
&& apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get install -y mongodb-mongosh \ | ||
&& if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \ | ||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* | ||
|
||
# [Optional] Uncomment this section to install additional OS packages. | ||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
# && apt-get -y install --no-install-recommends <your-package-list-here> | ||
|
||
# [Optional] Uncomment if you want to install an additional version of node using nvm | ||
# ARG EXTRA_NODE_VERSION=10 | ||
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" | ||
|
||
# [Optional] Uncomment if you want to install more global node modules | ||
# RUN su node -c "npm install -g <your-package-list-here>" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-mongo | ||
{ | ||
"name": "Node.js & Mongo DB", | ||
"dockerComposeFile": "docker-compose.yml", | ||
"service": "app", | ||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
// Configure tool-specific properties. | ||
"customizations": { | ||
// Configure properties specific to VS Code. | ||
"vscode": { | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"mongodb.mongodb-vscode" | ||
] | ||
} | ||
}, | ||
"features": { | ||
// "ghcr.io/devcontainers-contrib/features/jshint:2": {} | ||
}, | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
"forwardPorts": [ | ||
3000, | ||
27017 | ||
], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "yarn install", | ||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
version: '3.8' | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
volumes: | ||
- ../..:/workspaces:cached | ||
|
||
# Overrides default command so things don't shut down after the process ends. | ||
command: sleep infinity | ||
|
||
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. | ||
network_mode: service:db | ||
|
||
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) | ||
|
||
db: | ||
image: mongo:latest | ||
restart: unless-stopped | ||
volumes: | ||
- mongodb-data:/data/db | ||
|
||
# Uncomment to change startup options | ||
# environment: | ||
# MONGO_INITDB_ROOT_USERNAME: root | ||
# MONGO_INITDB_ROOT_PASSWORD: example | ||
# MONGO_INITDB_DATABASE: your-database-here | ||
|
||
# Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) | ||
|
||
volumes: | ||
mongodb-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,3 +128,5 @@ dist | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
sonar-scanner-5.0.1.3006-linux/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# todo | ||
Sample todo project | ||
# ToDo-Anwendung | ||
|
||
Diese Anwendung dient als Beispiel für das [Modul Softwarequalität](https://elearning.fh-swf.de/course/view.php?id=19693). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { MongoClient, ObjectId } from 'mongodb'; | ||
|
||
const MONGO_URI = process.env.MONGO_URI || 'mongodb://localhost:27017/todos'; | ||
const MONGO_DB = process.env.MONGO_DB || 'todos'; | ||
|
||
let db = null; | ||
let collection = null; | ||
let client = null; | ||
|
||
export default class DB { | ||
|
||
/** Connect to MongoDB and open client */ | ||
connect() { | ||
return MongoClient.connect(MONGO_URI) | ||
.then(function (_client) { | ||
client = _client; | ||
db = client.db(MONGO_DB); | ||
collection = db.collection('todos'); | ||
}) | ||
} | ||
|
||
/** Close client connection to MongoDB */ | ||
close() { | ||
return client.close() | ||
} | ||
|
||
/** Get all todos | ||
* @returns {Promise} - Promise with all todos | ||
*/ | ||
queryAll() { | ||
return collection.find().toArray(); | ||
} | ||
|
||
/** Get todo by id | ||
* @param {string} id - id of todo to query | ||
* @returns {Promise} - Promise with todo | ||
*/ | ||
queryById(id) { | ||
let _id = new ObjectId(id); | ||
return collection.findOne({ _id }); | ||
} | ||
|
||
/** Update todo by id | ||
* @param {string} id - id of todo to update | ||
* @returns {Promise} - Promise with updated todo | ||
*/ | ||
update(id, todo) { | ||
let _id = new ObjectId(id); | ||
if (typeof todo._id === 'string') { | ||
todo._id = _id; | ||
} | ||
return collection | ||
.replaceOne({ _id }, todo) | ||
.then(result => { | ||
if (result.modifiedCount === 1) { | ||
return todo; | ||
} | ||
else { | ||
console.log('Error updating todo: %o, %s', result, id); | ||
throw new Error('Error updating todo'); | ||
} | ||
}) | ||
.catch(err => { | ||
console.log('Error updating todo: %o, %s', err, id); | ||
throw err; | ||
}); | ||
} | ||
|
||
/** Delete todo by id | ||
* @param {string} id - id of todo to delete | ||
* @returns {Promise} - Promise with deleted todo | ||
*/ | ||
delete(id) { | ||
let _id = new ObjectId(id); | ||
return collection.findOneAndDelete({ _id }) | ||
.then(result => { | ||
if (result.ok) { | ||
return result.value; | ||
} | ||
else { | ||
console.log('Error deleting todo: %o, %s', result, id); | ||
throw new Error('Error deleting todo'); | ||
} | ||
}) | ||
} | ||
|
||
/** Insert todo | ||
* @param {object} todo - todo to insert | ||
* @returns {Promise} - Promise with inserted todo | ||
*/ | ||
insert(todo) { | ||
return collection | ||
.insertOne(todo) | ||
.then(result => { | ||
if (result.acknowledged) { | ||
todo._id = result.insertedId; | ||
return todo; | ||
} | ||
else { | ||
console.log('Error inserting todo: %o', result); | ||
throw new Error('Error inserting todo'); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.