WIP: GlobalBulletin controller

pull/1165/head
Rick Carlino 2019-04-18 23:08:15 -07:00
parent 69e096cb09
commit 06a98ea6e0
8 changed files with 120 additions and 1 deletions

View File

@ -0,0 +1,16 @@
module Api
class GlobalBulletinsController < Api::AbstractController
skip_before_action :authenticate_user!
skip_before_action :check_fbos_version
def show
render json: GlobalBulletinSerializer.new(search_results).as_json
end
private
def search_results
@search_results ||= GlobalBulletin.find_by(slug: params[:id])
end
end
end

View File

@ -0,0 +1,9 @@
class GlobalBulletin < ApplicationRecord
self.inheritance_column = "none"
validates_uniqueness_of :slug
validates_presence_of :content, :href, :slug, :type
def maybe_broadcast
# Opt out of auto sync
end
end

View File

@ -0,0 +1,3 @@
class GlobalBulletinSerializer < BasePointSerializer
attributes :content, :href, :slug, :type
end

View File

@ -11,6 +11,7 @@ FarmBot::Application.routes.draw do
enigmas: [:create, :destroy, :index],
farm_events: [:create, :destroy, :index, :show, :update],
farmware_envs: [:create, :destroy, :index, :show, :update],
global_bulletins: [:show],
images: [:create, :destroy, :index, :show],
password_resets: [:create, :update],
peripherals: [:create, :destroy, :index, :show, :update],

View File

@ -0,0 +1,12 @@
class CreateGlobalBulletin < ActiveRecord::Migration[5.2]
def change
create_table :global_bulletins do |t|
t.text :content
t.string :href
t.string :slug
t.string :type
t.string :name
t.timestamps
end
end
end

View File

@ -618,6 +618,41 @@ CREATE SEQUENCE public.fragments_id_seq
ALTER SEQUENCE public.fragments_id_seq OWNED BY public.fragments.id;
--
-- Name: global_bulletins; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.global_bulletins (
id bigint NOT NULL,
content text,
href character varying,
slug character varying,
type character varying,
name character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: global_bulletins_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.global_bulletins_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: global_bulletins_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.global_bulletins_id_seq OWNED BY public.global_bulletins.id;
--
-- Name: global_configs; Type: TABLE; Schema: public; Owner: -
--
@ -1659,6 +1694,13 @@ ALTER TABLE ONLY public.firmware_configs ALTER COLUMN id SET DEFAULT nextval('pu
ALTER TABLE ONLY public.fragments ALTER COLUMN id SET DEFAULT nextval('public.fragments_id_seq'::regclass);
--
-- Name: global_bulletins id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.global_bulletins ALTER COLUMN id SET DEFAULT nextval('public.global_bulletins_id_seq'::regclass);
--
-- Name: global_configs id; Type: DEFAULT; Schema: public; Owner: -
--
@ -1939,6 +1981,14 @@ ALTER TABLE ONLY public.fragments
ADD CONSTRAINT fragments_pkey PRIMARY KEY (id);
--
-- Name: global_bulletins global_bulletins_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.global_bulletins
ADD CONSTRAINT global_bulletins_pkey PRIMARY KEY (id);
--
-- Name: global_configs global_configs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -2903,6 +2953,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190411222900'),
('20190416035406'),
('20190417165636'),
('20190419001321');
('20190419001321'),
('20190419052844');

View File

@ -0,0 +1,13 @@
require "spec_helper"
describe Api::GlobalBulletinsController do
include Devise::Test::ControllerHelpers
describe "#show" do
it "shows bulletins" do
gb = FactoryBot.create(:global_bulletin)
get :show, params: { id: gb.slug }, format: :json
expect(response.status).to eq(200)
end
end
end

View File

@ -0,0 +1,14 @@
FactoryBot.define do
factory :global_bulletin do
content do
"we're now accepting pre-orders for Genesis XL v1.5!"
end
href do
"https://farm.bot/blogs/news/pre-order-farmbot-genesis-xl-v1-5"
end
slug { Faker::Food.vegetables }
type { "info" }
end
end