-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
6 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
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
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,64 @@ | ||
class PropertiesController <ApplicationController | ||
skip_before_action :require_login, only: :index | ||
before_action :set_property, only: %i[ show update destroy] | ||
|
||
def owned | ||
render json: current_user.properties, status: :ok | ||
end | ||
|
||
def index | ||
if current_user | ||
render json: Property.where.not(user: current_user), status: :ok | ||
else | ||
render json: Property.all, status: :ok | ||
end | ||
end | ||
|
||
def show | ||
render json: @property, status: :ok | ||
end | ||
|
||
def create | ||
property = Property.new(property_params) | ||
property.user = current_user | ||
if property.save | ||
render json: property, status: :created | ||
else | ||
render json: property.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @property.update(property_params) | ||
render json: @property | ||
else | ||
render json: @property.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@property.destroy | ||
end | ||
|
||
private | ||
|
||
def set_property | ||
@property = Property.find(params[:id]) | ||
end | ||
|
||
def property_params | ||
params.permit( | ||
:operationType, | ||
:address, | ||
:rentType, | ||
:rentAmount, | ||
:maintenance, | ||
:propertyType, | ||
:bedrooms, | ||
:bathrooms, | ||
:area, | ||
:petsAllowed, | ||
:about | ||
) | ||
end | ||
end |
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
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
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
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
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,15 @@ | ||
# Be sure to restart your server when you modify this file. | ||
# Avoid CORS issues when API is called from the frontend app. | ||
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. | ||
# Read more: https://github.com/cyu/rack-cors | ||
|
||
Rails.application.config.middleware.insert_before 0, Rack::Cors do | ||
allow do | ||
origins "*" | ||
|
||
resource "*", | ||
headers: :any, | ||
methods: %i[get post put patch delete options head] | ||
end | ||
end | ||
|
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,8 +1,16 @@ | ||
Rails.application.routes.draw do | ||
# User | ||
get "/profile", to: "users#show" | ||
patch "/profile", to: "users#update" | ||
post "/signup", to: "users#create" | ||
|
||
# Sessions | ||
post "/login", to: "sessions#create" | ||
post "/signup", to: "users#create" | ||
delete "/logout", to: "sessions#destroy" | ||
|
||
# Properties" | ||
resource :properties do | ||
get "/index", to: "properties#index" | ||
get "/owned", to: "properties#owned" | ||
end | ||
end |
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