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

アニメデータのステータスを追加し、管理画面に表示する #536

Open
wants to merge 4 commits into
base: master
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
9 changes: 9 additions & 0 deletions app/decorators/anime_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class AnimeDecorator < Draper::Decorator
delegate_all

def human_status_name
I18n.t("labels.status.#{status}")
end
end
2 changes: 2 additions & 0 deletions app/models/anime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Anime < ApplicationRecord
validates :wiki_url,
length: { maximum: Settings.anime.wiki_url.maximum_length }

enum status: { unpublished: 0, prepared: 1, published: 2 }

mount_uploader :picture, PictureUploader

def airing?
Expand Down
2 changes: 2 additions & 0 deletions app/models/season.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Season < ApplicationRecord
validates :previous_name, :behind_name,
length: { maximum: Settings.season.name.maximum_length }

enum status: { unpublished: 0, prepared: 1, published: 2 }

def self.airing(date)
where('seasons.start_on <= ?', date)
.where('seasons.end_on >= ? or seasons.end_on is null', date)
Expand Down
1 change: 1 addition & 0 deletions app/views/api/admin/animes/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
json.animes do
json.array! @animes do |anime|
json.id anime.id
json.status_name anime.decorate.human_status_name
json.title anime.title
json.picture anime.picture.url
json.airing anime.airing?
Expand Down
5 changes: 5 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ ja:
extension_whitelist_error: にアップロードできる拡張子は、jpg/jpeg/png/gifのみです
sessions:
invalid_parameters: メールアドレスまたはパスワードが正しくありません
labels:
status:
unpublished: 非公開
prepared: 準備中
published: 公開
6 changes: 6 additions & 0 deletions db/migrate/20170913092757_add_status_to_animes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddStatusToAnimes < ActiveRecord::Migration[5.1]
def change
# NOTE: default 0 is :unpublished
add_column :animes, :status, :integer, null: false, default: 0
end
end
6 changes: 6 additions & 0 deletions db/migrate/20170914085437_add_status_to_seasons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddStatusToSeasons < ActiveRecord::Migration[5.1]
def change
# NOTE: default 0 is :unpublished
add_column :seasons, :status, :integer, null: false, default: 0
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170910082027) do
ActiveRecord::Schema.define(version: 20170914085437) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -54,6 +54,7 @@
t.datetime "updated_at", null: false
t.integer "created_by"
t.integer "updated_by"
t.integer "status", default: 0, null: false
end

create_table "appearances", id: :serial, force: :cascade do |t|
Expand Down Expand Up @@ -111,6 +112,7 @@
t.string "previous_name"
t.integer "created_by"
t.integer "updated_by"
t.integer "status", default: 0, null: false
end

create_table "singers", id: :serial, force: :cascade do |t|
Expand Down
11 changes: 11 additions & 0 deletions spec/factories/animes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@
sequence(:summary) { |n| "あらすじ#{n}" }
wiki_url Faker::Internet.url
picture { fixture_file_upload('spec/fixtures/clover.gif', 'image/gif') }
status { Anime.statuses.keys.sample }

trait :unpublished do
status :unpublished
end
trait :prepared do
status :prepared
end
trait :published do
status :published
end
end
end
6 changes: 4 additions & 2 deletions spec/requests/admin/animes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require 'rails_helper'

describe 'GET /api/admin/animes', autodoc: true do
let!(:anime1) { create(:anime, created_at: 2.minutes.ago) }
let!(:anime2) { create(:anime) }
let!(:anime1) { create(:anime, :published, created_at: 2.minutes.ago) }
let!(:anime2) { create(:anime, :prepared) }
let!(:season1) { create(:season, anime: anime1, phase: 1).decorate }
let!(:season2) { create(:season, anime: anime1, phase: 2).decorate }
let!(:melody1) { create(:melody, :op, season: season1) }
Expand All @@ -28,13 +28,15 @@
animes: [
{
id: anime2.id,
status_name: '準備中',
title: anime2.title,
picture: anime2.picture.url,
airing: false,
seasons: []
},
{
id: anime1.id,
status_name: '公開',
title: anime1.title,
picture: anime1.picture.url,
airing: true,
Expand Down