-
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?
Changes from 1 commit
b57d7ff
9fc95ea
159cd36
ac3f826
a543d86
adfd2ca
0fa59bc
592f6e1
fc6c62b
3675ac0
1de31b3
792c80f
9f42631
a8952d5
53645a0
7445b15
69841ea
26e04f9
7296024
39d598f
299dc5a
c2c9734
0a6a8c2
7b9e86a
11e2cc2
cf3dc25
2e9eefd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,37 @@ | ||
|
|
||
| # frozen_string_literal: true | ||
| class AdApiController < ApplicationController | ||
| def view | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| array=[] | ||
| array = [] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. totalcostって多分登録できてないよ |
||
| report.save | ||
| end | ||
|
|
||
|
|
||
| end | ||
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.
不要な行は削除しよう