forked from corincerami/mars-photo-api
-
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.
Merge pull request #1 from mxkay/photo-size-parameter
Implement photo size parameter
- Loading branch information
Showing
16 changed files
with
426 additions
and
110 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 |
---|---|---|
@@ -1 +1 @@ | ||
2.7.1 | ||
3.0.0 |
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,7 +1,7 @@ | ||
language: ruby | ||
|
||
rvm: | ||
- 2.7.1 | ||
- 3.0.0 | ||
|
||
before_script: | ||
- psql -c 'create database mars_curiosity_test;' -U postgres | ||
|
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,6 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
ruby '2.7.1' | ||
ruby '3.0.0' | ||
|
||
gem 'pg', '~> 1.0' | ||
gem 'rake' | ||
|
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 |
---|---|---|
@@ -1,26 +1,21 @@ | ||
class Api::V1::LatestPhotosController < ApplicationController | ||
def index | ||
def index | ||
@rover = Rover.find_by name: params[:rover_id].titleize | ||
if @rover | ||
render json: search_photos, each_serializer: PhotoSerializer, root: :latest_photos | ||
else | ||
render json: { errors: "Invalid Rover Name" }, status: :bad_request | ||
end | ||
end | ||
end | ||
@rover = Rover.find_by name: params[:rover_id].titleize | ||
|
||
private | ||
if @rover then | ||
validated_params = params | ||
.permit(:rover_id, :camera, :earth_date, :size, :page, :per_page) | ||
.merge(sol: @rover.photos.maximum(:sol)) | ||
photos = @rover.photos.search validated_params, @rover | ||
photos = helpers.resize_photos photos, validated_params | ||
|
||
def photo_params | ||
params.permit(:camera, :earth_date).merge(sol: @rover.photos.maximum(:sol)) | ||
end | ||
|
||
def search_photos | ||
photos = @rover.photos.order(:camera_id, :id).search photo_params, @rover | ||
if params[:page] | ||
photos = photos.page(params[:page]).per params[:per_page] | ||
if photos != 'size error' | ||
render json: photos, each_serializer: PhotoSerializer, root: :latest_photos | ||
else | ||
render json: { errors: "Invalid size parameter '#{validated_params[:size]}' for #{@rover.name.titleize}" }, status: :bad_request | ||
end | ||
else | ||
render json: { errors: "Invalid Rover Name" }, status: :bad_request | ||
end | ||
photos | ||
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
Oops, something went wrong.