Skip to content
Snippets Groups Projects
Commit 294627e1 authored by Treadway, Ross T (UG - Computer Science)'s avatar Treadway, Ross T (UG - Computer Science)
Browse files

Merge branch 'master' into main

parents 38cd35a9 d956b6ae
Branches master
No related tags found
1 merge request!1initial commit
Showing
with 417 additions and 0 deletions
# 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
# 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
.byebug_history
# Ignore master key for decrypting credentials and more.
/config/master.key
ruby-2.7.0
# syntax=docker/dockerfile:1
FROM ruby:2.7.0
RUN apt-get update -qq && apt-get install -y nodejs default-mysql-client
WORKDIR /event-service
COPY Gemfile /event-service/Gemfile
COPY Gemfile.lock /event-service/Gemfile.lock
RUN bundle install
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]
Gemfile 0 → 100644
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.5'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.5'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.5)
actionpack (= 6.1.5)
activesupport (= 6.1.5)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.5)
actionpack (= 6.1.5)
activejob (= 6.1.5)
activerecord (= 6.1.5)
activestorage (= 6.1.5)
activesupport (= 6.1.5)
mail (>= 2.7.1)
actionmailer (6.1.5)
actionpack (= 6.1.5)
actionview (= 6.1.5)
activejob (= 6.1.5)
activesupport (= 6.1.5)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.5)
actionview (= 6.1.5)
activesupport (= 6.1.5)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.5)
actionpack (= 6.1.5)
activerecord (= 6.1.5)
activestorage (= 6.1.5)
activesupport (= 6.1.5)
nokogiri (>= 1.8.5)
actionview (6.1.5)
activesupport (= 6.1.5)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.5)
activesupport (= 6.1.5)
globalid (>= 0.3.6)
activemodel (6.1.5)
activesupport (= 6.1.5)
activerecord (6.1.5)
activemodel (= 6.1.5)
activesupport (= 6.1.5)
activestorage (6.1.5)
actionpack (= 6.1.5)
activejob (= 6.1.5)
activerecord (= 6.1.5)
activesupport (= 6.1.5)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
bootsnap (1.11.1)
msgpack (~> 1.2)
builder (3.2.4)
byebug (11.1.3)
concurrent-ruby (1.1.10)
crass (1.0.6)
erubi (1.10.0)
ffi (1.15.5)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.16.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.15.0)
msgpack (1.5.1)
mysql2 (0.5.3)
nio4r (2.5.8)
nokogiri (1.13.4)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
puma (5.6.4)
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.5)
actioncable (= 6.1.5)
actionmailbox (= 6.1.5)
actionmailer (= 6.1.5)
actionpack (= 6.1.5)
actiontext (= 6.1.5)
actionview (= 6.1.5)
activejob (= 6.1.5)
activemodel (= 6.1.5)
activerecord (= 6.1.5)
activestorage (= 6.1.5)
activesupport (= 6.1.5)
bundler (>= 1.15.0)
railties (= 6.1.5)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
railties (6.1.5)
actionpack (= 6.1.5)
activesupport (= 6.1.5)
method_source
rake (>= 12.2)
thor (~> 1.0)
rake (13.0.6)
rb-fsevent (0.11.1)
rb-inotify (0.10.1)
ffi (~> 1.0)
spring (4.0.0)
sprockets (4.0.3)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
thor (1.2.1)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.5.4)
PLATFORMS
ruby
DEPENDENCIES
bootsnap (>= 1.4.4)
byebug
listen (~> 3.3)
mysql2 (~> 0.5)
puma (~> 5.0)
rails (~> 6.1.5)
spring
tzinfo-data
RUBY VERSION
ruby 2.7.0p0
BUNDLED WITH
2.1.2
# Cheat sheet
# H1
## H2
### H3
**bold text**
*italicized text*
> blockquote
1. First item
`code`
---p
[title](https://www.example.com)
## Code Notes
When in Docker, prepend all commands with the following
`docker-compose run web`
To create a new REST api rails app
`rails new Shelter_API --api --database=postgresql`
To create a shelter scaffold
`rails generate scaffold Shelter name:string description:text email:string phone_number:string address_id:integer`
To check bundle version
`bundle version`
To test the shelters database on postman as json
`{'name': 'Shelter1', 'description': 'This is Shelter1', 'email': 'shelter1@mail.com', 'phone_number': '0123456789' 'address_id':1}`
Delete scaffold `rails destroy scaffold Shelter`
Login to postgresql as postgres `psql -U postgres`
Install gem by putting the following in Gemfile `gem 'jwt'`
Curl command to get request `curl http://localhost:3000/shelters`
Curl command to POST request (USE POSTMAN) `curl --header "Content-Type: application/json" --request POST --data '{'name': 'Shelter1', 'description': 'This is Shelter1', 'email': 'shelter1@mail.com', 'phone_number': '0123456789' 'address_id':1} http://localhost:3000/shelters -v`
## Reference
- [What Is JWT](https://www.youtube.com/watch?v=7Q17ubqLfaM&ab_channel=WebDevSimplifiex)
- [RAILS 6 & 7 API Authentication with JWT](https://www.bluebash.co/blog/rails-6-7-api-authentication-with-jwt/)
- [Securing a Ruby on Rails API with JWTs](https://fusionauth.io/blog/2020/06/11/building-protected-api-with-rails-and-jwt)
- [Docker Rails Quickstart](https://docs.docker.com/samples/rails/)
- [Rails API and Postgres start](https://www.youtube.com/watch?v=n9V_1X8uGZM&ab_channel=AlexMerced-FullStackDeveloper)
- [Github for working JWT](https://github.com/FusionAuth/fusionauth-example-rails-api/tree/master/test)
- [Help with Rails API playlist](fusionauth.io/blog/2020/06/11/building-protected-api-with-rails-and-jwt)
- [Similar JWT Rails Project](https://github.com/thecatcampaign/Tinder-Backend/tree/master/src)
- [Docker Rails Guide](https://betterprogramming.pub/rails-6-development-with-docker-55437314a1ad)
- [How to load secret env variables](https://www.youtube.com/watch?v=mZ_gverN4Co&ab_channel=RailscastsReloaded)
## Additional Notes
- Postgres master password: pgAdmin
- posgresql password: MyPassword
## Git Notes
- `git init`
- `git pull https://github.com/NinthAutumn/com3014CW2Group2.git`
- `git checkout -b <branch_name>`
- `git add .`
- `git commit -m "Made changes to this and that"`
- `git remote add origin git@github.com:NinthAutumn/com3014CW2Group2.git`
- `git push -u origin <branch_name>`
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative "config/application"
Rails.application.load_tasks
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
class ApplicationController < ActionController::API
end
class EventsController < ApplicationController
before_action :set_event, only: [:show, :update, :destroy]
# GET /events
def index
@events = Event.all
render json: @events
end
# GET /events/1
def show
render json: @event
end
# POST /events
def create
@event = Event.new(event_params)
if @event.save
render json: @event, status: :created, location: @event
else
render json: @event.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /events/1
def update
if @event.update(event_params)
render json: @event
else
render json: @event.errors, status: :unprocessable_entity
end
end
# DELETE /events/1
def destroy
@event.destroy
end
private
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find(params[:id])
end
# Only allow a list of trusted parameters through.
def event_params
params.require(:event).permit(:title, :description, :active, :createdAt, :scheduledAt)
end
end
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class Event < ApplicationRecord
end
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>
<%= yield %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment