Skip to content

Conversation

@HashimotoLogly
Copy link
Owner

@HashimotoLogly HashimotoLogly commented Jun 21, 2019

OJTのAPI開発(view,click)を行いました。
まだ細かい部分(いらないファイル等)は修正できておりませんが随時修正していきます
RSpecは随時追加していきます。

対応issue #6

Copy link

@tmk-hsn tmk-hsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ひとまずコメントしたので修正お願い


class AdApiController < ApplicationController
def view
array=[]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

イコールの左右は空けること

array=[]

target_ids = Ad.pluck(:id).sample( params[:count].to_i)
ads=Ad.find(target_ids)
Copy link

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|
Copy link

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

Copy link

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|
Copy link

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|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • テーブル名を変更してほしい
  • カラムの並び順を変えてほしい
  • created_at, updated_atを足してほしい


def click

if repo = Repo.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スペース2つ分空いてる?から1つ分に変更して

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要スペースは削除で



private
def count_p
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このprivateメソッド使ってる?

p repo.totalcost

else
render status: 500, json: { status: 500, message: 'Ad was not existed! ' }
Copy link

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]
Copy link

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を加算する為に使用しているのでここでも使っています
Copy link

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といったように単語の間に区切りを入れましょう。


# frozen_string_literal: true
class AdApiController < ApplicationController
def view
Copy link

@tmk-hsn tmk-hsn Jun 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • view はメソッド名としてよくない(viewsというディレクトリが存在するので初見の人が混乱する)ので、register_impとかに変えてほしい

render json: array
end

def click
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clickをどうするのか、明確にしたメソッド名にしてほしい

def count_p

report.click += 1
report.totalcost += Ad.find(params[:ad_id]).price
Copy link

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
Copy link

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

メソッド名を変えよう

@@ -0,0 +1,40 @@

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要な行は削除しよう


# frozen_string_literal: true
class AdApiController < ApplicationController
def view_make_report
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本来であれば1メソッドで1つの役割を持たせるべきで、一言で説明できないメソッドにすべきではないです。
今回は時間がないのでそこまで対応せず大丈夫ですが、配属後はこうした部分にも気をつけて開発をしてみてくださいね。

render json: array
end

def click_make_report
Copy link

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'
Copy link

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'
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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 = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrayは変えて

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants