Skip to content

Commit 9dd7b41

Browse files
author
Brian Schroer
committed
Merge branch 'master' of https://github.com/ShelterTechSF/askdarcel-api into 1188-html-to-pdf-endpoint
2 parents 86cf879 + 3687db2 commit 9dd7b41

5 files changed

Lines changed: 220 additions & 4 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
class NewsArticlesController < ApplicationController
4+
def create
5+
news_article = params[:news_article]
6+
persisted_news_article = NewsArticle.create(headline: news_article[:headline], effective_date: news_article[:effective_date],
7+
body: news_article[:body], priority: news_article[:priority],
8+
expiration_date: news_article[:expiraton_date])
9+
render status: :created, json: NewsArticlePresenter.present(persisted_news_article)
10+
end
11+
12+
def index
13+
news_articles = NewsArticle.where("effective_date <= ? and (expiration_date is null or expiration_date>=?)", Time.current,
14+
Time.current)
15+
16+
render json: NewsArticlePresenter.present(news_articles)
17+
end
18+
19+
# rubocop:disable Metrics/AbcSize
20+
def update
21+
news_article = NewsArticle.find(params[:id])
22+
news_article.headline = params[:news_article][:headline]
23+
news_article.effective_date = params[:news_article][:effective_date]
24+
news_article.body = params[:news_article][:body]
25+
news_article.priority = params[:news_article][:priority]
26+
news_article.expiration_date = params[:news_article][:expiration_date]
27+
news_article.save
28+
29+
render status: :ok, json: NewsArticlePresenter.present(news_article)
30+
end
31+
# rubocop:enable Metrics/AbcSize
32+
33+
def destroy
34+
news_article = NewsArticle.find params[:id]
35+
news_article.delete
36+
37+
render status: :ok
38+
end
39+
end

config/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@
7373
end
7474
end
7575
resources :documents, only: %i[create update destroy]
76+
resources :news_articles do
77+
post :create
78+
get :index
79+
put :update
80+
delete :destroy
81+
end
7682
get 'reindex' => "algolia#reindex"
7783
end

db/migrate/20220909212857_create_news_article.rb renamed to db/migrate/20220909212858_create_news_articles.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
class CreateNewsArticle < ActiveRecord::Migration[6.1]
1+
class CreateNewsArticles < ActiveRecord::Migration[6.1]
22
def change
3-
create_table :news_article do |t|
3+
create_table :news_articles do |t|
44
t.string :headline
55
t.datetime :effective_date
66
t.string :body

db/schema.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2022_09_09_212857) do
13+
ActiveRecord::Schema.define(version: 2022_09_09_212858) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -253,6 +253,16 @@
253253
t.datetime "updated_at", precision: 6, null: false
254254
end
255255

256+
create_table "news_articles", force: :cascade do |t|
257+
t.string "headline"
258+
t.datetime "effective_date"
259+
t.string "body"
260+
t.integer "priority"
261+
t.datetime "expiration_date"
262+
t.datetime "created_at", precision: 6, null: false
263+
t.datetime "updated_at", precision: 6, null: false
264+
end
265+
256266
create_table "notes", force: :cascade do |t|
257267
t.text "note"
258268
t.integer "resource_id"

postman/AskDarcel%20API.postman_collection.json

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "03c3fafa-ce04-488a-9b78-b08f2959a62f",
3+
"_postman_id": "fca7c8d9-8e45-4f57-a7b4-cd66fcc57bf7",
44
"name": "AskDarcel API",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
66
"_exporter_id": "680011"
@@ -2656,6 +2656,167 @@
26562656
}
26572657
},
26582658
"response": []
2659+
},
2660+
{
2661+
"name": "Add Breaking News",
2662+
"event": [
2663+
{
2664+
"listen": "test",
2665+
"script": {
2666+
"exec": [
2667+
"pm.test(\"Adding breaking news\", function () {",
2668+
" pm.response.to.have.status(201);",
2669+
"});"
2670+
],
2671+
"type": "text/javascript"
2672+
}
2673+
}
2674+
],
2675+
"request": {
2676+
"method": "POST",
2677+
"header": [],
2678+
"body": {
2679+
"mode": "raw",
2680+
"raw": "{\n \"news_article\": {\n \"headline\": \"headline\",\n \"body\": \"Lorem Ipsum etc etc etc\",\n \"effective_date\": \"2022-12-01\",\n \"priority\": \"1\"\n }\n}",
2681+
"options": {
2682+
"raw": {
2683+
"language": "json"
2684+
}
2685+
}
2686+
},
2687+
"url": {
2688+
"raw": "{{base_url}}/news_articles",
2689+
"host": [
2690+
"{{base_url}}"
2691+
],
2692+
"path": [
2693+
"news_articles"
2694+
]
2695+
}
2696+
},
2697+
"response": []
2698+
},
2699+
{
2700+
"name": "Update Breaking News",
2701+
"event": [
2702+
{
2703+
"listen": "test",
2704+
"script": {
2705+
"exec": [
2706+
"pm.test(\"Modifying breaking news\", function () {",
2707+
" pm.response.to.have.status(200);",
2708+
"});"
2709+
],
2710+
"type": "text/javascript"
2711+
}
2712+
}
2713+
],
2714+
"request": {
2715+
"method": "PUT",
2716+
"header": [],
2717+
"body": {
2718+
"mode": "raw",
2719+
"raw": "{\n \"news_article\": {\n \"headline\": \"modified headline\",\n \"body\": \"Lorem Ipsum etc etc etc (modified)\"\n }\n}",
2720+
"options": {
2721+
"raw": {
2722+
"language": "json"
2723+
}
2724+
}
2725+
},
2726+
"url": {
2727+
"raw": "{{base_url}}/news_articles/1",
2728+
"host": [
2729+
"{{base_url}}"
2730+
],
2731+
"path": [
2732+
"news_articles",
2733+
"1"
2734+
]
2735+
}
2736+
},
2737+
"response": []
2738+
},
2739+
{
2740+
"name": "Delete Breaking News",
2741+
"event": [
2742+
{
2743+
"listen": "test",
2744+
"script": {
2745+
"exec": [
2746+
"pm.test(\"Deleting breaking news\", function () {",
2747+
" pm.response.to.have.status(200);",
2748+
"});"
2749+
],
2750+
"type": "text/javascript"
2751+
}
2752+
}
2753+
],
2754+
"request": {
2755+
"method": "DELETE",
2756+
"header": [],
2757+
"body": {
2758+
"mode": "raw",
2759+
"raw": "{\n \"document\": {\n \"document\": \"test document\",\n \"service_id\": 1\n }\n}",
2760+
"options": {
2761+
"raw": {
2762+
"language": "json"
2763+
}
2764+
}
2765+
},
2766+
"url": {
2767+
"raw": "{{base_url}}/news_articles/1",
2768+
"host": [
2769+
"{{base_url}}"
2770+
],
2771+
"path": [
2772+
"news_articles",
2773+
"1"
2774+
]
2775+
}
2776+
},
2777+
"response": []
2778+
},
2779+
{
2780+
"name": "Retrieve Breaking News",
2781+
"event": [
2782+
{
2783+
"listen": "test",
2784+
"script": {
2785+
"exec": [
2786+
"pm.test(\"Retrieving breaking news\", function () {",
2787+
" pm.response.to.have.status(200);",
2788+
"});"
2789+
],
2790+
"type": "text/javascript"
2791+
}
2792+
}
2793+
],
2794+
"protocolProfileBehavior": {
2795+
"disableBodyPruning": true
2796+
},
2797+
"request": {
2798+
"method": "GET",
2799+
"header": [],
2800+
"body": {
2801+
"mode": "raw",
2802+
"raw": "{\n \"document\": {\n \"document\": \"test document\",\n \"service_id\": 1\n }\n}",
2803+
"options": {
2804+
"raw": {
2805+
"language": "json"
2806+
}
2807+
}
2808+
},
2809+
"url": {
2810+
"raw": "{{base_url}}/news_articles",
2811+
"host": [
2812+
"{{base_url}}"
2813+
],
2814+
"path": [
2815+
"news_articles"
2816+
]
2817+
}
2818+
},
2819+
"response": []
26592820
}
26602821
],
26612822
"event": [

0 commit comments

Comments
 (0)