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

v2.0.2 #145

Merged
merged 2 commits into from
Jun 23, 2022
Merged
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
16 changes: 11 additions & 5 deletions app/controllers/check_votes_and_bonuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ def index
screen_name = Presenter::Common.normalized_screen_name(params[:screen_name])
user = User.find_by(screen_name: screen_name)

# TODO: エラーハンドリング
return render json: {} if user.blank?
error_response = {
gss2022: [],
unite_attacks: [],
short_stories: [],
fav_quotes: [],
sosenkyo_campaigns: []
}
return render json: error_response if user.blank?

gss2022_tweets = user.tweets.gensosenkyo_2022_votes_for_api
unite_attacks_tweets = user.tweets.unite_attacks_votes_for_api
short_stories = user.tweets.short_stories
fav_quotes = user.tweets.fav_quotes
sosenkyo_campaigns = user.tweets.sosenkyo_campaigns
short_stories = user.tweets.short_stories_for_api
fav_quotes = user.tweets.fav_quotes_for_api
sosenkyo_campaigns = user.tweets.sosenkyo_campaigns_for_api

# react-twitter-embed へ渡すためには文字列のほうが都合がいい
@gss2022_tweets = gss2022_tweets.map { |t| t.id_number.to_s }
Expand Down
39 changes: 39 additions & 0 deletions app/models/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ def self.short_stories
.order(id_number: :asc)
end

# API では "is_public" と 期間 に注意する
def self.short_stories_for_api
where(is_public: true)
.not_retweet
.contains_hashtag('幻水総選挙お題小説')
.not_by_gensosenkyo_family
.where(
tweeted_at: Time.zone.parse('2022-05-01 12:00:00')..Time.zone.parse('2022-07-31 23:59:59')
)
.order(tweeted_at: :asc)
.order(id_number: :asc)
end

# スプレッドシートに書き込むことを前提としているので、制限は緩い
def self.fav_quotes
not_retweet
Expand All @@ -120,6 +133,19 @@ def self.fav_quotes
.order(id_number: :asc)
end

# API では "is_public" と 期間 に注意する
def self.fav_quotes_for_api
where(is_public: true)
.not_retweet
.contains_hashtag('幻水総選挙推し台詞')
.not_by_gensosenkyo_family
.where(
tweeted_at: Time.zone.parse('2022-05-01 12:00:00')..Time.zone.parse('2022-07-31 23:59:59')
)
.order(tweeted_at: :asc)
.order(id_number: :asc)
end

# スプレッドシートに書き込むことを前提としているので、制限は緩い
def self.sosenkyo_campaigns
not_retweet
Expand All @@ -132,6 +158,19 @@ def self.sosenkyo_campaigns
.order(id_number: :asc)
end

# API では "is_public" と 期間 に注意する
def self.sosenkyo_campaigns_for_api
where(is_public: true)
.not_retweet
.contains_hashtag('幻水総選挙運動')
.not_by_gensosenkyo_family
.where(
tweeted_at: Time.zone.parse('2022-05-01 12:00:00')..Time.zone.parse('2022-07-31 23:59:59')
)
.order(tweeted_at: :asc)
.order(id_number: :asc)
end

def valid_term_vote?
begin_datetime = Time.zone.parse('2022-06-24 21:00:00')
end_datetime = Time.zone.parse('2022-06-26 23:59:59')
Expand Down
10 changes: 9 additions & 1 deletion spec/requests/check_votes_and_bonuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
get check_votes_and_bonuses_path(screen_name: '@test_user')

expect(response).to have_http_status :ok
expect(response.body).to eq '{}'
expect(JSON.parse(response.body)).to eq(
{
"gss2022" => [],
"unite_attacks" => [],
"short_stories" => [],
"fav_quotes" => [],
"sosenkyo_campaigns" => []
}
)
end

it 'データベースに存在するとき、期待通りのレスポンスが返ってくること' do
Expand Down