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

ian/#38/view accepted submissions #68

Open
wants to merge 4 commits into
base: main
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
3 changes: 2 additions & 1 deletion api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ gem 'require_all', '~> 3.0'

gem 'rubocop', '~> 1.46', require: false

gem 'sqlite3', '~> 1.6', '>= 1.6.1'

group :development do
gem 'faker'
gem 'rack-env', '~> 0.1.3'
Expand All @@ -33,5 +35,4 @@ end
group :test do
gem 'rack-test', '~> 2.0', '>= 2.0.2'
gem 'rspec', '~> 3.12'
gem 'sqlite3', '~> 1.6', '>= 1.6.1'
end
40 changes: 38 additions & 2 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ This section will describe the schema definitions for our database.
- This section describes all the API endpoints including their expected request and response objects.


1. `/projects` - List all projects submitted.
1. `/guest/projects` - List all accepted submissions.

```{json}
--------------
@METHOD => GET
--------------

---------------
@AUTH => Bearer
@AUTH => None
---------------

----------------
Expand All @@ -184,6 +184,42 @@ This section will describe the schema definitions for our database.
}],
"message": "SUCCESS"
}

-----------------
```
2. `/guest/projects/search/:query` - Search for accepted submissions that have their titles or description match the `:query` path parameter.

```{json}
--------------
@METHOD => GET
--------------

---------------
@AUTH => None
---------------

----------------
@REQUEST => None
----------------

-----------------
@RESPONSE => JSON

{
"data": [
{
"id": 2,
"title": "The force",
"category": "Fin-tech",
"description": "The force is here.",
"repository_link": "https://github.com/sinatra-pod/the-force",
"banner_image": "https://calebbii.io/banner.png",
"tech_stacks": "React, Ruby, Typscript",
"license": "https://github.com/lisence-moringahub"
"status": "CREATED"
}],
"message": "SUCCESS"
}

-----------------
```
28 changes: 28 additions & 0 deletions api/app/controllers/visitor_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# @CONTROLLER: visitor
class VisitorController < BaseController
# list all accepted submissions
get '/guest/projects' do
@projects = Project.where(submission_status: 'ACCEPTED').order(created_at: :desc)
json_response(data: { projects: @projects })
end

# search by description, (stack) or title
get '/guest/projects/search/:query' do
query = params[:query].to_s
if query
begin
sql = "(title LIKE :query OR description LIKE :query) AND submission_status = 'ACCEPTED'"
@projects = Project
.where(sql, { query: "%#{query}%" })
.order(created_at: :desc)
json_response(data: { projects: @projects })
rescue StandardError => e
error_response(err: e)
end
else
json_response(data: { info: 'Your search request was empty' }, code: 422)
end
end
end
2 changes: 1 addition & 1 deletion api/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

require_relative './config/environment'

# use TodoController
use VisitorController
run BaseController