Clean up and add additional endpoints
This commit is contained in:
@@ -4,12 +4,13 @@ module API
|
||||
module V1
|
||||
class Base < Grape::API
|
||||
format :json
|
||||
mount API::V1::Docs
|
||||
mount API::V1::Categories
|
||||
mount API::V1::Docs
|
||||
mount API::V1::Forums
|
||||
mount API::V1::Topics
|
||||
mount API::V1::Posts
|
||||
mount API::V1::Users
|
||||
use ::WineBouncer::OAuth2
|
||||
add_swagger_documentation
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,7 @@ module API
|
||||
entity: Entity::Category,
|
||||
notes: "Lists all active categories defined for the knowledgebase"
|
||||
}
|
||||
oauth2 'public'
|
||||
get "", root: :categories do
|
||||
categories = Category.active.all
|
||||
present categories, with: Entity::Category
|
||||
@@ -31,6 +32,7 @@ module API
|
||||
params do
|
||||
requires :id, type: String, desc: "Category to list docs from"
|
||||
end
|
||||
oauth2 'public'
|
||||
get ":id", root: :categories do
|
||||
category = Category.where(id: permitted_params[:id]).first
|
||||
present category, with: Entity::Category, docs: true
|
||||
@@ -42,15 +44,16 @@ module API
|
||||
notes: "Create a new category"
|
||||
}
|
||||
params do
|
||||
requires :name, String, desc: "The name of the category of articles"
|
||||
optional :icon, String, desc: "An icon that represents the category"
|
||||
optional :keywords, String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, Integer, desc: "The rank can be used to determine the ordering of categories"
|
||||
optional :front_page, String, desc: "Whether or not the category should appear on the front page"
|
||||
optional :active, Boolean, desc: "Whether or not the category is live on the site"
|
||||
requires :name, type: String, desc: "The name of the category of articles"
|
||||
optional :icon, type: String, desc: "An icon that represents the category"
|
||||
optional :keywords, type: String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, type: String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, type: String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, type: Integer, desc: "The rank can be used to determine the ordering of categories"
|
||||
optional :front_page, type: String, desc: "Whether or not the category should appear on the front page"
|
||||
optional :active, type: Boolean, desc: "Whether or not the category is live on the site"
|
||||
end
|
||||
oauth2
|
||||
post "", root: :categories do
|
||||
category = Category.create!(
|
||||
name: permitted_params[:name],
|
||||
@@ -65,22 +68,23 @@ module API
|
||||
present category, with: Entity::Category
|
||||
end
|
||||
|
||||
# EDIT CATEGORY
|
||||
desc "Edit a single category", {
|
||||
# UPDATE CATEGORY
|
||||
desc "Update a single category", {
|
||||
entity: Entity::Category,
|
||||
notes: "Edit a single category"
|
||||
}
|
||||
params do
|
||||
requires :id, type: Integer, desc: "Category to update"
|
||||
requires :name, String, desc: "The name of the category of articles"
|
||||
optional :icon, String, desc: "An icon that represents the category"
|
||||
optional :keywords, String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, Integer, desc: "The rank can be used to determine the ordering of categories"
|
||||
optional :front_page, String, desc: "Whether or not the category should appear on the front page"
|
||||
optional :active, Boolean, desc: "Whether or not the category is live on the site"
|
||||
requires :name, type: String, desc: "The name of the category of articles"
|
||||
optional :icon, type: String, desc: "An icon that represents the category"
|
||||
optional :keywords, type: String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, type: String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, type: String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, type: Integer, desc: "The rank can be used to determine the ordering of categories"
|
||||
optional :front_page, type: String, desc: "Whether or not the category should appear on the front page"
|
||||
optional :active, type: Boolean, desc: "Whether or not the category is live on the site"
|
||||
end
|
||||
oauth2
|
||||
patch ":id", root: :categories do
|
||||
category = Category.where(id: permitted_params[:id]).first
|
||||
category.update!(
|
||||
|
||||
@@ -18,6 +18,10 @@ module API
|
||||
def logger
|
||||
Rails.logger
|
||||
end
|
||||
|
||||
def current_user
|
||||
resource_owner
|
||||
end
|
||||
end
|
||||
|
||||
rescue_from ActiveRecord::RecordNotFound do |e|
|
||||
|
||||
@@ -31,16 +31,16 @@ module API
|
||||
notes: "Create a new doc"
|
||||
}
|
||||
params do
|
||||
requires :title, String, desc: "The name of the articles"
|
||||
requires :category_id, Integer, desc: "The category the doc belongs to"
|
||||
requires :body, String, desc: "The body/text of the article"
|
||||
requires :user_id, Integer, desc: "The author of the article"
|
||||
optional :keywords, String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, Integer, desc: "The rank can be used to determine the ordering of docs"
|
||||
optional :front_page, String, desc: "Whether or not the doc should appear on the front page"
|
||||
optional :active, Boolean, desc: "Whether or not the doc is live on the site"
|
||||
requires :title, type: String, desc: "The name of the articles"
|
||||
requires :category_id, type: Integer, desc: "The category the doc belongs to"
|
||||
requires :body, type: String, desc: "The body/text of the article"
|
||||
requires :user_id, type: Integer, desc: "The author of the article"
|
||||
optional :keywords, type: String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, type: String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, type: String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, type: Integer, desc: "The rank can be used to determine the ordering of docs"
|
||||
optional :front_page, type: String, desc: "Whether or not the doc should appear on the front page"
|
||||
optional :active, type: Boolean, desc: "Whether or not the doc is live on the site"
|
||||
end
|
||||
post "", root: :docs do
|
||||
doc = Doc.create!(
|
||||
@@ -64,17 +64,17 @@ module API
|
||||
notes: "Update a doc"
|
||||
}
|
||||
params do
|
||||
requires :id, Integer, desc: "The ID of the Doc being updated"
|
||||
requires :title, String, desc: "The name of the category of articles"
|
||||
requires :category_id, Integer, desc: "The category the doc belongs to"
|
||||
requires :body, String, desc: "The body/text of the article"
|
||||
requires :user_id, Integer, desc: "The author of the article"
|
||||
optional :keywords, String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, Integer, desc: "The rank can be used to determine the ordering of docs"
|
||||
optional :front_page, String, desc: "Whether or not the doc should appear on the front page"
|
||||
optional :active, Boolean, desc: "Whether or not the doc is live on the site"
|
||||
requires :id, type: Integer, desc: "The ID of the Doc being updated"
|
||||
requires :title, type: String, desc: "The name of the category of articles"
|
||||
requires :category_id, type: Integer, desc: "The category the doc belongs to"
|
||||
requires :body, type: String, desc: "The body/text of the article"
|
||||
requires :user_id, type: Integer, desc: "The author of the article"
|
||||
optional :keywords, type: String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, type: String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, type: String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, type: Integer, desc: "The rank can be used to determine the ordering of docs"
|
||||
optional :front_page, type: String, desc: "Whether or not the doc should appear on the front page"
|
||||
optional :active, type: Boolean, desc: "Whether or not the doc is live on the site"
|
||||
end
|
||||
patch ":id", root: :docs do
|
||||
doc = Doc.where(id: permitted_params[:id])
|
||||
|
||||
@@ -41,10 +41,10 @@ module API
|
||||
notes: "Create a new forum"
|
||||
}
|
||||
params do
|
||||
requires :name, String, desc: "The name of the forum"
|
||||
requires :allow_post_voting, String, desc: "Should topic replies be voteable?"
|
||||
requires :allow_topic_voting, String, desc: "Should topics be voteable?"
|
||||
requires :layout, String, desc: "The author of the article"
|
||||
requires :name, type: String, desc: "The name of the forum"
|
||||
requires :allow_post_voting, type: String, desc: "Should topic replies be voteable?"
|
||||
requires :allow_topic_voting, type: String, desc: "Should topics be voteable?"
|
||||
requires :layout, type: String, desc: "The author of the article"
|
||||
end
|
||||
post "", root: :forums do
|
||||
forum = Forum.create!(
|
||||
@@ -62,17 +62,17 @@ module API
|
||||
notes: "Update a forum"
|
||||
}
|
||||
params do
|
||||
requires :id, Integer, desc: "The ID of the Doc being updated"
|
||||
requires :title, String, desc: "The name of the category of articles"
|
||||
requires :category_id, Integer, desc: "The category the doc belongs to"
|
||||
requires :body, String, desc: "The body/text of the article"
|
||||
requires :user_id, Integer, desc: "The author of the article"
|
||||
optional :keywords, String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, Integer, desc: "The rank can be used to determine the ordering of docs"
|
||||
optional :front_page, String, desc: "Whether or not the doc should appear on the front page"
|
||||
optional :active, Boolean, desc: "Whether or not the doc is live on the site"
|
||||
requires :id, type: Integer, desc: "The ID of the Doc being updated"
|
||||
requires :title, type: String, desc: "The name of the category of articles"
|
||||
requires :category_id, type: Integer, desc: "The category the doc belongs to"
|
||||
requires :body, type: String, desc: "The body/text of the article"
|
||||
requires :user_id, type: Integer, desc: "The author of the article"
|
||||
optional :keywords, type: String, desc: "Keywords that will be used for internal search and SEO"
|
||||
optional :title_tag, type: String, desc: "An alternate title tag that will be used if provided"
|
||||
optional :meta_description, type: String, desc: "A short description for SEO and internal purposes"
|
||||
optional :rank, type: Integer, desc: "The rank can be used to determine the ordering of docs"
|
||||
optional :front_page, type: String, desc: "Whether or not the doc should appear on the front page"
|
||||
optional :active, type: Boolean, desc: "Whether or not the doc is live on the site"
|
||||
end
|
||||
patch ":id", root: :forums do
|
||||
forum = Forum.where(id: permitted_params[:id])
|
||||
|
||||
@@ -11,6 +11,8 @@ module API
|
||||
|
||||
include API::V1::Defaults
|
||||
resource :posts do
|
||||
|
||||
# LIST ALL POSTS FOR TOPIC
|
||||
desc "Return all posts in a given topic", {
|
||||
entity: Entity::Post,
|
||||
notes: "List all posts for supplied topic"
|
||||
@@ -23,6 +25,7 @@ module API
|
||||
present posts, with: Entity::Post
|
||||
end
|
||||
|
||||
# CREATE NEW POST
|
||||
desc "Add a new post to an existing topic"
|
||||
params do
|
||||
requires :topic_id, type: String, desc: "Topic to add post to"
|
||||
|
||||
@@ -88,7 +88,6 @@ module API
|
||||
end
|
||||
|
||||
patch ":id", root: :topics do
|
||||
|
||||
ticket = Topic.where(id: permitted_params[:id]).first
|
||||
ticket.update!(
|
||||
forum_id: 1,
|
||||
@@ -98,13 +97,12 @@ module API
|
||||
)
|
||||
present ticket, with: Entity::Topic, posts: true
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
# PUBLIC TOPIC ENDPOINTS FOR COMMUNITY FORUMS
|
||||
resource :topics do
|
||||
|
||||
# LIST ALL TOPICS IN A FORUM
|
||||
desc "List all public topics for a forum", {
|
||||
entity: Entity::Topic,
|
||||
notes: "List all topics for a given forum"
|
||||
@@ -116,6 +114,24 @@ module API
|
||||
topics = Forum.find(permitted_params[:forum_id]).topics.all
|
||||
present topics, with: Entity::Topic
|
||||
end
|
||||
|
||||
# VOTE FOR A TOPIC
|
||||
desc "Vote for a topic", {
|
||||
entity: Entity::Topic,
|
||||
notes: "Vote for a given topic"
|
||||
}
|
||||
params do
|
||||
requires :id, type: Integer, desc: "The ID of the topic to vote for"
|
||||
#requires :user_id, type: Integer
|
||||
end
|
||||
put ':id/vote', root: :topics do
|
||||
topic = Topic.where(id: permitted_params[:id]).first
|
||||
topic.votes.create!(
|
||||
user_id: current_user #|| permitted_params[:user_id]
|
||||
)
|
||||
present topic, with: Entity::Topic
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# CREATE A NEW TOPIC
|
||||
|
||||
@@ -10,12 +10,150 @@ module API
|
||||
# end
|
||||
|
||||
include API::V1::Defaults
|
||||
|
||||
# LIST ALL USERS
|
||||
resource :users do
|
||||
desc "Return all topics"
|
||||
desc "List all users", {
|
||||
entity: Entity::User,
|
||||
notes: "List all users"
|
||||
}
|
||||
get "", root: :users do
|
||||
User.all
|
||||
users = User.all
|
||||
present users, with: Entity::User
|
||||
end
|
||||
end
|
||||
|
||||
# SHOW USER
|
||||
resource :users do
|
||||
desc "Show details of a user", {
|
||||
entity: Entity::User,
|
||||
notes: "Show details of a user"
|
||||
}
|
||||
params do
|
||||
requires :id, type: Integer, desc: "User ID"
|
||||
end
|
||||
get ":id", root: :users do
|
||||
user = User.where(id: permitted_params[:id])
|
||||
present user, with: Entity::User
|
||||
end
|
||||
end
|
||||
|
||||
# CREATE A USER
|
||||
resource :users do
|
||||
desc "Create a new user", {
|
||||
entity: Entity::User,
|
||||
notes: "Create a new user"
|
||||
}
|
||||
params do
|
||||
requires :name, type: String, desc: "Users full name"
|
||||
requires :email, type: String, desc: "Users email address"
|
||||
requires :password, type: String, desc: "Users password"
|
||||
optional :login, type: String, desc: "Users login (optional)"
|
||||
# optional :admin, type: Boolean, desc: "Admin Status"
|
||||
optional :bio, type: String, desc: "Users bio"
|
||||
optional :signature, type: String, desc: "Users signature"
|
||||
optional :role, type: String, desc: "Users role", values: ['user', 'editor', 'agent', 'admin'], default: 'user'
|
||||
optional :home_phone, type: String, desc: "Users home phone"
|
||||
optional :work_phone, type: String, desc: "Users work phone"
|
||||
optional :cell_phone, type: String, desc: "Users cell phone"
|
||||
optional :company, type: String, desc: "Users company"
|
||||
optional :street, type: String, desc: "Users street"
|
||||
optional :city, type: String, desc: "Users city"
|
||||
optional :state, type: String, desc: "Users state"
|
||||
optional :zip, type: String, desc: "Users Postal Code"
|
||||
optional :title, type: String, desc: "Users title"
|
||||
optional :twitter, type: String, desc: "Users Twitter handle"
|
||||
optional :linkedin, type: String, desc: "Users Linkedin username"
|
||||
optional :language, type: String, desc: "Users prefered language"
|
||||
optional :active, type: Boolean, desc: "User active or deactivated", default: true
|
||||
end
|
||||
post "", root: :users do
|
||||
user = User.create!(
|
||||
login: permitted_params[:login],
|
||||
email: permitted_params[:email],
|
||||
password: permitted_params[:password],
|
||||
name: permitted_params[:name],
|
||||
# admin: permitted_params[:admin],
|
||||
bio: permitted_params[:bio],
|
||||
signature: permitted_params[:signature],
|
||||
role: permitted_params[:role],
|
||||
home_phone: permitted_params[:home_phone],
|
||||
work_phone: permitted_params[:work_phone],
|
||||
cell_phone: permitted_params[:cell_phone],
|
||||
company: permitted_params[:company],
|
||||
street: permitted_params[:street],
|
||||
city: permitted_params[:city],
|
||||
state: permitted_params[:state],
|
||||
zip: permitted_params[:zip],
|
||||
title: permitted_params[:title],
|
||||
twitter: permitted_params[:twitter],
|
||||
linkedin: permitted_params[:linkedin],
|
||||
language: permitted_params[:language],
|
||||
active: permitted_params[:active]
|
||||
)
|
||||
present user, with: Entity::User
|
||||
end
|
||||
end
|
||||
|
||||
# UPDATE A USER
|
||||
resource :users do
|
||||
desc "Update a user", {
|
||||
entity: Entity::User,
|
||||
notes: "Update a user"
|
||||
}
|
||||
params do
|
||||
requires :id, type: Integer, desc: "User ID"
|
||||
requires :name, type: String, desc: "Users full name"
|
||||
requires :email, type: String, desc: "Users email address"
|
||||
requires :password, type: String, desc: "Users password"
|
||||
optional :login, type: String, desc: "Users login (optional)"
|
||||
# optional :admin, type: Boolean, desc: "Admin Status"
|
||||
optional :bio, type: String, desc: "Users bio"
|
||||
optional :signature, type: String, desc: "Users signature"
|
||||
optional :role, type: String, desc: "Users role", values: ['user', 'editor', 'agent', 'admin'], default: 'user'
|
||||
optional :home_phone, type: String, desc: "Users home phone"
|
||||
optional :work_phone, type: String, desc: "Users work phone"
|
||||
optional :cell_phone, type: String, desc: "Users cell phone"
|
||||
optional :company, type: String, desc: "Users company"
|
||||
optional :street, type: String, desc: "Users street"
|
||||
optional :city, type: String, desc: "Users city"
|
||||
optional :state, type: String, desc: "Users state"
|
||||
optional :zip, type: String, desc: "Users Postal Code"
|
||||
optional :title, type: String, desc: "Users title"
|
||||
optional :twitter, type: String, desc: "Users Twitter handle"
|
||||
optional :linkedin, type: String, desc: "Users Linkedin username"
|
||||
optional :language, type: String, desc: "Users prefered language"
|
||||
optional :active, type: Boolean, desc: "User active or deactivated"
|
||||
end
|
||||
patch ":id", root: :users do
|
||||
user = User.where(id: permitted_params[:id]).first
|
||||
user.update!(
|
||||
login: permitted_params[:login],
|
||||
email: permitted_params[:email],
|
||||
password: permitted_params[:password],
|
||||
name: permitted_params[:name],
|
||||
# admin: permitted_params[:admin],
|
||||
bio: permitted_params[:bio],
|
||||
signature: permitted_params[:signature],
|
||||
role: permitted_params[:role],
|
||||
home_phone: permitted_params[:home_phone],
|
||||
work_phone: permitted_params[:work_phone],
|
||||
cell_phone: permitted_params[:cell_phone],
|
||||
company: permitted_params[:company],
|
||||
street: permitted_params[:street],
|
||||
city: permitted_params[:city],
|
||||
state: permitted_params[:state],
|
||||
zip: permitted_params[:zip],
|
||||
title: permitted_params[:title],
|
||||
twitter: permitted_params[:twitter],
|
||||
linkedin: permitted_params[:linkedin],
|
||||
language: permitted_params[:language],
|
||||
active: permitted_params[:active]
|
||||
)
|
||||
present user, with: Entity::User
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
module Entity
|
||||
class User < Base
|
||||
expose :id
|
||||
expose :login
|
||||
expose :name
|
||||
# expose :admin
|
||||
expose :bio
|
||||
expose :signature
|
||||
expose :role
|
||||
expose :home_phone
|
||||
expose :work_phone
|
||||
expose :cell_phone
|
||||
expose :company
|
||||
expose :street
|
||||
expose :city
|
||||
expose :state
|
||||
expose :zip
|
||||
expose :title
|
||||
expose :twitter
|
||||
expose :linkedin
|
||||
expose :thumbnail
|
||||
expose :medium_image
|
||||
expose :large_image
|
||||
expose :language
|
||||
expose :assigned_ticket_count
|
||||
expose :topics_count
|
||||
expose :active
|
||||
expose :created_at
|
||||
expose :updated_at
|
||||
expose :email
|
||||
expose :sign_in_count
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#!/usr/bin/env ruby
|
||||
begin
|
||||
load File.expand_path("../spring", __FILE__)
|
||||
rescue LoadError
|
||||
end
|
||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||
require_relative '../config/boot'
|
||||
require 'rails/commands'
|
||||
|
||||
Reference in New Issue
Block a user