Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b57d7ff
make api routes
HashimotoLogly Jun 4, 2019
9fc95ea
add imp,click counter on api_controller
HashimotoLogly Jun 4, 2019
159cd36
add errorlog if ad.id was matched nothing
HashimotoLogly Jun 4, 2019
ac3f826
fix Db tables
HashimotoLogly Jun 14, 2019
a543d86
add api html.erb
HashimotoLogly Jun 4, 2019
adfd2ca
fix ad_api
HashimotoLogly Jun 21, 2019
0fa59bc
fix model name
HashimotoLogly Jun 21, 2019
592f6e1
fix db
HashimotoLogly Jun 21, 2019
fc6c62b
fix model name
HashimotoLogly Jun 21, 2019
3675ac0
autocorrected by rubocop
HashimotoLogly Jun 21, 2019
1de31b3
fix model saving
HashimotoLogly Jun 21, 2019
792c80f
add comment
HashimotoLogly Jun 21, 2019
9f42631
change totalprice to price
HashimotoLogly Jun 21, 2019
a8952d5
fix db column type
HashimotoLogly Jun 24, 2019
53645a0
add travel_to method for testing rspec
HashimotoLogly Jun 24, 2019
7445b15
add view rspec
HashimotoLogly Jun 24, 2019
69841ea
add click rspec
HashimotoLogly Jun 25, 2019
26e04f9
add_ media.site.htm
HashimotoLogly Jun 27, 2019
7296024
change action name(view,click)
HashimotoLogly Jun 27, 2019
39d598f
add rspec
HashimotoLogly Jun 27, 2019
299dc5a
rubocop --auto-correct
HashimotoLogly Jun 27, 2019
c2c9734
change html name corresponding to action names
HashimotoLogly Jun 27, 2019
0a6a8c2
delete unused files
HashimotoLogly Jun 27, 2019
7b9e86a
rename files
HashimotoLogly Jun 27, 2019
11e2cc2
delete unused files
HashimotoLogly Jun 27, 2019
cf3dc25
delete comment
HashimotoLogly Jun 27, 2019
2e9eefd
fix action names
HashimotoLogly Jun 28, 2019
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
50 changes: 18 additions & 32 deletions app/controllers/ad_api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@

Copy link
Copy Markdown

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

@tmk-hsn tmk-hsn Jun 21, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

array=[]
array = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arrayは変えて

reports = []

target_ids = Ad.pluck(:id).sample( params[:count].to_i)
ads=Ad.find(target_ids)
target_ids = Ad.pluck(:id).sample(params[:count].to_i)
ads = Ad.find(target_ids)
ads.each do |ad|

repo = Repo.find_by(ad_id: ad.id, adspot_id: params[:adspot_id])
unless repo
repo = Repo.new(ad_id: ad.id,adspot_id: params[:adspot_id])
report = Report.find_by(ad_id: ad.id, adspot_id: params[:adspot_id])
unless report
report = Report.new(ad_id: ad.id, adspot_id: params[:adspot_id])
end

repo.imp += 1
repo.save
p repo.imp
report.imp += 1
reports.push(report)

array.push(
{ img_url: ad.image,
body: ad.text,
ad_id: ad.id }
img_url: ad.image,
body: ad.text,
ad_id: ad.id
)
end
Report.import(reports)
render json: array
end

def click

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id])

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
repo.save

p repo.click
p repo.totalcost

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


private
def count_p

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

totalcostって多分登録できてないよ

report.save
end


end
6 changes: 3 additions & 3 deletions app/views/ad/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<%= image_tag ad.image.to_s %>
</li>
<div class="edit_button">
<%= link_to("Edit", edit_ad_path(ad)) %>
<%= link_to("変更", edit_ad_path(ad)) %>
</div>
<div class="delete_button">
<%= link_to("Delete", ad_path(ad) ,method: :delete) %>
<%= link_to("削除", ad_path(ad) ,method: :delete) %>
</div>
<% end %>
<div>
<%= link_to("New", new_ad_path) %>
<%= link_to("新規作成", new_ad_path) %>
</div>
</div>
</div>