Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds server app #21

Open
wants to merge 10 commits into
base: client
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ will start simple Python HTTP server on port 8082, therefore guest application s

In order to connect frontend clients to a custom server, modify `guest-app/index.html` and `staff-app/index.html` files.

Find a line starting with `const BASE_URL = "..."` , replace the value with your custom server base URL, and you should be ready to go.
Find a line starting with `const BASE_URL = "..."` , replace the value with your custom server base URL, and you should be ready to go.

## Server Local setup
open README file inside `server-app` directory
75 changes: 44 additions & 31 deletions guest-app/index.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
<!doctype html>
<html lang="en">
<head>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<title>Restaurant at the End of the Universe</title>
</head>
<body>
</head>

<body>
<div class="container" id="app">
<div class="row">
<div class="col-sm">
<h1>The Restaurant at the End of the Universe</h1>
<p><router-link to="/">So long, and thanks for all the fish!</router-link></p>
<p>
<router-link to="/">So long, and thanks for all the fish!</router-link>
</p>
</div>
</div>
<div class="row">
<router-view></router-view>
<router-view></router-view>
</div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vue-router.js"></script>
<script type="text/javascript">
const BASE_URL = 'http://localhost:8081/';

axios.defaults.baseURL = BASE_URL;
const BASE_URL = 'http://localhost:8080/';

const axiosClient = axios.default;
const axiosClient = axios.create({
baseURL: BASE_URL,
headers: { 'Content-Type': 'application/json' }
});

class MenuItemService {

Expand Down Expand Up @@ -74,7 +86,7 @@ <h1>The Restaurant at the End of the Universe</h1>

static fromData(data) {
let items = [];

if ('order_items' in data) {
items = data['order_items'].map(OrderItem.fromData);
}
Expand All @@ -92,7 +104,7 @@ <h1>The Restaurant at the End of the Universe</h1>
menuItems.forEach((menuItem) => {
menuItemsMap[menuItem.itemId] = menuItem;
});

order.orderItems.forEach((orderItem) => {
orderItem.menuItem = menuItemsMap[orderItem.itemId];
});
Expand Down Expand Up @@ -163,11 +175,11 @@ <h5 class="card-title">{{ item.itemTitle }}</h5>
<div class="input-group">
<input class="form-control" v-model="qty" type="number" min="0" max="10">
<div class="input-group-append">
<button v-on:click="add()" class="form-control btn-primary" type="button">Add</button>
<button v-on:click="add()" class="form-control btn-primary" type="button">Add</button>
</div>
</div>
</div>
</div>
</div>
`,
methods: {
add() {
Expand Down Expand Up @@ -199,34 +211,34 @@ <h5 class="card-title">{{ item.itemTitle }}</h5>
return p;
},
addToCart(menuItem, qty) {
let cartItem = this.cart[menuItem.itemId] || {menuItem: menuItem, qty: 0};
let cartItem = this.cart[menuItem.itemId] || { menuItem: menuItem, qty: 0 };
cartItem.qty += parseInt(qty);

this.$set(this.cart, menuItem.itemId, cartItem);
},
submit () {
submit() {
let itemsPayload = Object.keys(this.cart).map((cartItemId) => {
return {
item_id: cartItemId,
quantity: this.cart[cartItemId].qty
};
});

axios.post('/api/orders', {
axiosClient.post('/api/orders', {
table_id: 'test-table',
items: itemsPayload
})
.then((response) => {
let order = Order.fromData(response.data);
this.$router.push({ path: `/order/${order.orderId}` });
});
.then((response) => {
let order = Order.fromData(response.data);
this.$router.push({ path: `/order/${order.orderId}` });
});
}
},
template: `
<div>
<div class="card-deck col-sm-12">
<menu-item
v-for="menuItem in menuItems"
<menu-item
v-for="menuItem in menuItems"
v-bind:item="menuItem"
v-on:add="addToCart"
>
Expand Down Expand Up @@ -257,9 +269,9 @@ <h2>Cart</h2>
menuItemService.fetchMenuItems().then((menuItems) => {
this.menuItems = menuItems;
this.loadOrder();
setInterval(() => {
this.loadOrder();

setInterval(() => {
this.loadOrder();
}, 5000);
});
},
Expand Down Expand Up @@ -304,5 +316,6 @@ <h5 class="card-title">{{ orderItem.menuItem.itemTitle }}</h5>
router
});
</script>
</body>
</html>
</body>

</html>
28 changes: 28 additions & 0 deletions server-app/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Server-app",
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "server-app",
// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workspace"
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",
// Uncomment the next line to run commands after the container is created - for example installing curl.
// "postCreateCommand": "apt-get update && apt-get install -y curl",
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
}
38 changes: 38 additions & 0 deletions server-app/.devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3.9'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
server-app:
# If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
# property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks,
# debugging) to execute as the user. Uncomment the next line if you want the entire
# container to run as this user instead. Note that, on Linux, you may need to
# ensure the UID and GID of the container user you create matches your local user.
# See https://aka.ms/vscode-remote/containers/non-root for details.
#
# user: vscode

# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
# build:
# context: .
# dockerfile: .devcontainer/Dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- .:/workspace:cached

# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
# - /var/run/docker.sock:/var/run/docker.sock

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"

7 changes: 7 additions & 0 deletions server-app/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
29 changes: 29 additions & 0 deletions server-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

# Ignore master key for decrypting credentials and more.
/config/master.key
1 change: 1 addition & 0 deletions server-app/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
1 change: 1 addition & 0 deletions server-app/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-3.1.2
9 changes: 9 additions & 0 deletions server-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ruby:3.1.2-bullseye

WORKDIR /server-app

COPY . .
RUN bundle install

# CMD ["rails", "server"]
CMD ["rails", "server", "-b", "0.0.0.0", "-p", "8080"]
7 changes: 7 additions & 0 deletions server-app/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ruby:3.1.2-bullseye

WORKDIR /server-app

COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
37 changes: 37 additions & 0 deletions server-app/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.2"

gem "rails", "~> 7.0.4"

gem "pg", "~> 1.1"
gem "puma", "~> 5.0"
gem "jbuilder"
gem "bootsnap", require: false
gem "rack-cors"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]


# Custom Server-app gems
gem 'monetize', '~> 1.12'
gem 'money-rails', '~> 1.15'
gem 'jwt'

group :development, :test do
gem 'rspec-rails', '~> 6.0', '>= 6.0.1'
gem 'faker', git: 'https://github.com/faker-ruby/faker', branch: 'main'
gem 'factory_bot_rails', '~> 6.2'
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

group :test do
gem 'shoulda-matchers', '~> 5.0'
end
Loading