-
Notifications
You must be signed in to change notification settings - Fork 0
Feature web api #9
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
base: master
Are you sure you want to change the base?
Conversation
tmk-hsn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ひとまずコメントしたので修正お願い
app/controllers/ad_api_controller.rb
Outdated
|
|
||
| class AdApiController < ApplicationController | ||
| def view | ||
| array=[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
イコールの左右は空けること
app/controllers/ad_api_controller.rb
Outdated
| array=[] | ||
|
|
||
| target_ids = Ad.pluck(:id).sample( params[:count].to_i) | ||
| ads=Ad.find(target_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
イコールの左右は空けること
同じことを言われないように注意すること
| @@ -0,0 +1,15 @@ | |||
| class CreateRepos < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :repos do |t| | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
カラムを以下の順番に変更して。
t.integer :ad_id,null: false
t.integer :adspot_id, null: false
t.integer :click, null: false, default: 0
t.integer :imp, null: false, default: 0
t.integer :cv, null: false, default: 0
t.integer :price, null: false, default: 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- created_at, updated_atを足してほしい
db/schema.rb
Outdated
| t.integer 'cv' | ||
| ActiveRecord::Schema.define(version: 2019_06_14_041856) do | ||
|
|
||
| create_table "ads", force: :cascade do |t| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adsテーブルってここで作るんだっけ?
db/schema.rb
Outdated
| t.datetime "updated_at", null: false | ||
| end | ||
|
|
||
| create_table "repos", force: :cascade do |t| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- テーブル名を変更してほしい
- カラムの並び順を変えてほしい
- created_at, updated_atを足してほしい
app/controllers/ad_api_controller.rb
Outdated
|
|
||
| def click | ||
|
|
||
| if repo = Repo.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
スペース2つ分空いてる?から1つ分に変更して
app/controllers/ad_api_controller.rb
Outdated
| if repo = Repo.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) | ||
|
|
||
| repo.click += 1 | ||
| repo.totalcost += Ad.find( params[:ad_id]).price |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要スペースは削除で
app/controllers/ad_api_controller.rb
Outdated
|
|
||
|
|
||
| private | ||
| def count_p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このprivateメソッド使ってる?
app/controllers/ad_api_controller.rb
Outdated
| p repo.totalcost | ||
|
|
||
| else | ||
| render status: 500, json: { status: 500, message: 'Ad was not existed! ' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レスポンス500ではない気がするので、改めて検討してみて
| @@ -1,8 +0,0 @@ | |||
| # frozen_string_literal: true | |||
| class AddReportColumnToAds < ActiveRecord::Migration[5.2] | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この変更は入稿でしなければいけないのでは?
db/schema.rb
Outdated
|
|
||
| ActiveRecord::Schema.define(version: 2019_06_14_041856) do | ||
| create_table 'ads', force: :cascade do |t| # reportsテーブルのtotalpriceにpriceを加算する為に使用 | ||
| create_table 'ads', force: :cascade do |t| # reportsテーブルのtotalpriceにpriceを加算する為に使用しているのでここでも使っています |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totalpriceではなく、priceで良いです。
日付が入っているので、その日付のtotal priceであることが明らかだからです。
また、totalpriceとつけたい場合は、total_priceといったように単語の間に区切りを入れましょう。
app/controllers/ad_api_controller.rb
Outdated
|
|
||
| # frozen_string_literal: true | ||
| class AdApiController < ApplicationController | ||
| def view |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- view はメソッド名としてよくない(viewsというディレクトリが存在するので初見の人が混乱する)ので、register_impとかに変えてほしい
app/controllers/ad_api_controller.rb
Outdated
| render json: array | ||
| end | ||
|
|
||
| def click |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clickをどうするのか、明確にしたメソッド名にしてほしい
app/controllers/ad_api_controller.rb
Outdated
| def count_p | ||
|
|
||
| report.click += 1 | ||
| report.totalcost += Ad.find(params[:ad_id]).price |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totalcostって多分登録できてないよ
| describe "GET #view" do | ||
| it "returns http success" do | ||
| end | ||
| describe 'GET #view' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メソッド名を変えよう
|
|
||
| describe "GET #click" do | ||
| it "returns http success" do | ||
| describe 'GET #click' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メソッド名を変えよう
f1ecd9b to
a8952d5
Compare
app/controllers/ad_api_controller.rb
Outdated
| @@ -0,0 +1,40 @@ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要な行は削除しよう
app/controllers/ad_api_controller.rb
Outdated
|
|
||
| # frozen_string_literal: true | ||
| class AdApiController < ApplicationController | ||
| def view_make_report |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本来であれば1メソッドで1つの役割を持たせるべきで、一言で説明できないメソッドにすべきではないです。
今回は時間がないのでそこまで対応せず大丈夫ですが、配属後はこうした部分にも気をつけて開発をしてみてくださいね。
app/controllers/ad_api_controller.rb
Outdated
| render json: array | ||
| end | ||
|
|
||
| def click_make_report |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メソッド名変更で
config/routes.rb
Outdated
| @@ -1,5 +1,6 @@ | |||
| # frozen_string_literal: true | |||
| Rails.application.routes.draw do | |||
| get '/view' => 'ad_api#view_make_report' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routing変更
config/routes.rb
Outdated
| # frozen_string_literal: true | ||
| Rails.application.routes.draw do | ||
| get '/view' => 'ad_api#view_make_report' | ||
| get '/click' => 'ad_api#click_make_report' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routing変更
| ad3_ispresent = false | ||
|
|
||
| jsons.each do |json| | ||
| if json['ad_id'] == @ad1.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rspecではif文は使わないで
| end | ||
| end | ||
|
|
||
| describe 'GET #click_make_report' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メソッド名変更で
| expect(response).to have_http_status(:success) | ||
| end | ||
|
|
||
| describe 'Report' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- describeの囲いは統一してほしい
- if, unlessで別れていたら都度テストケースを書いてほしい
| # frozen_string_literal: true | ||
| require 'rails_helper' | ||
|
|
||
| # Specs in this file have access to a helper object that includes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
消してOK
| # frozen_string_literal: true | ||
| class AdApiController < ApplicationController | ||
| def view_make_report | ||
| array = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arrayは変えて
OJTのAPI開発(view,click)を行いました。
まだ細かい部分(いらないファイル等)は修正できておりませんが随時修正していきます
RSpecは随時追加していきます。
対応issue #6