Skip to content

Commit e7b0d02

Browse files
committed
finished API with react frontend
1 parent fdb57b4 commit e7b0d02

25 files changed

+15464
-23
lines changed

test-api/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ gem 'puma', '~> 3.11'
2626
gem 'bootsnap', '>= 1.1.0', require: false
2727

2828
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
29-
# gem 'rack-cors'
29+
gem 'rack-cors', :require => 'rack/cors'
3030

3131
group :development, :test do
3232
# Call 'byebug' anywhere in the code to stop execution and get a debugger console

test-api/Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ GEM
7777
mini_portile2 (~> 2.3.0)
7878
puma (3.12.0)
7979
rack (2.0.6)
80+
rack-cors (1.0.2)
8081
rack-test (1.1.0)
8182
rack (>= 1.0, < 3)
8283
rails (5.2.1)
@@ -137,6 +138,7 @@ DEPENDENCIES
137138
byebug
138139
listen (>= 3.0.5, < 3.2)
139140
puma (~> 3.11)
141+
rack-cors
140142
rails (~> 5.2.1)
141143
spring
142144
spring-watcher-listen (~> 2.0.0)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class Api::V1::MoviesController < ApplicationController
2+
before_action :set_movie, only: [:show, :update, :destroy]
3+
4+
# GET /movies
5+
def index
6+
@movies = Movie.all
7+
8+
render json: @movies
9+
end
10+
11+
# GET /movies/1
12+
def show
13+
render json: @movie
14+
end
15+
16+
# POST /movies
17+
def create
18+
@movie = Movie.new(movie_params)
19+
20+
if @movie.save
21+
render json: @movie, status: :created, location: @movie
22+
else
23+
render json: @movie.errors, status: :unprocessable_entity
24+
end
25+
end
26+
27+
# PATCH/PUT /movies/1
28+
def update
29+
if @movie.update(movie_params)
30+
render json: @movie
31+
else
32+
render json: @movie.errors, status: :unprocessable_entity
33+
end
34+
end
35+
36+
# DELETE /movies/1
37+
def destroy
38+
@movie.destroy
39+
end
40+
41+
private
42+
# Use callbacks to share common setup or constraints between actions.
43+
def set_movie
44+
@movie = Movie.find(params[:id])
45+
end
46+
47+
# Only allow a trusted parameter "white list" through.
48+
def movie_params
49+
params.require(:movie).permit(:name, :rating)
50+
end
51+
end

test-api/app/models/movie.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Movie < ApplicationRecord
2+
end

test-api/client/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

test-api/client/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.<br>
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br>
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.<br>
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.<br>
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br>
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `npm run eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).

0 commit comments

Comments
 (0)