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

Feature/api favorite #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
172 changes: 172 additions & 0 deletions api/src/app/favorites.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
Promise = require("q").Promise
v = require("../lib/validator")
dbOper = require("../../dbOper")
favoriteOper = dbOper.getFavoriteInstance()

getData = (query, field) ->
return Promise (resolve, reject) ->
console.log "get"
return

# Favorite list 取得
# http://localhost:3000/favorites?userID=62e052b1bf85a688897597c97c062e8a
exports.index = (req, res) ->
console.log "index"

param = req.query
#adminFlg = query.adminFlg
#certificatedFlg = query.certificatedFlg
#delFlg = query.delFlg
#search = query.search
#skip = query.skip
#limit = query.limit
#sort = query.sort

#console.log input
# Validation
v.checkParam param, (err) ->
if err
res.status err.code
.send err.msg
else
input = {}

if param.userID
input.userID = param.userID

# skip, limit
if param.limit
input.start = param.skip ? 0
input.count = param.limit
# sort
if param.sort
input.sort =
column: param.sort ? "favoriteID"
type: "asc"

console.log input
# MySQL処理
favoriteOper.getFav input, (results) ->
console.log results

output =
code: results.code
result: results.Favorite

if results.code
outCode = 200
else
outCode = 400
res.status outCode
.send output
return
return

return

# Favorite 取得
# http://localhost:3000/favorites/ac4bbfedfb12d85ecd493bb955eeb853
exports.show = (req, res) ->
console.log "show"

input = req.query
input.favoriteID = req.params.id

#console.log input
# Validation
v.checkParam input, (err) ->
if err
res.status err.code
.send err.msg
else
# MySQL処理
favoriteOper.getFav input, (results) ->
console.log results

output =
code: results.code
result: results.Favorite[0]

if results.code
outCode = 200
else
outCode = 400
res.status outCode
.send output
return
return

return

# Favorite 追加
exports.create = (req, res) ->
console.log "create"

input = req.body

# Test inputデータ
# curl -X POST http://localhost:3000/favorites -d "userID=27cb87f3a94b9317f7ca8e4b12330c40&productID=85d7809a5cba506532db79232c998232&shopID=767792164ce5faad5a468738b0c83fee"

# Validation
v.checkParam input, (err) ->
if err
res.status err.code
.send err.msg
else
# MySQL処理
favoriteOper.insertFav input, (results) ->
console.log results
output =
code: results.code
result: results

if results.code
outCode = 200
else
outCode = 400
res.status outCode
.send output
return
return
return

# Favorite 更新
exports.update = (req, res) ->
console.log "update"

input = req.body
input.favoriteID = req.params.id
# Test inputデータ
# curl -X PUT http://localhost:3000/favorites/ac4bbfedfb12d85ecd493bb955eeb853 -d "delFlg=1"

# Validation
v.checkParam input, (err) ->
if err
res.status err.code
.send err.msg
else
# MySQL処理
favoriteOper.updateFav input, (results) ->
console.log results
output =
code: results.code
result: results
if results.code
outCode = 200
else
outCode = 400
res.status outCode
.send output
return
return

return

# Favorite 削除
exports.destroy = (req, res) ->
console.log "destroy"
res.status 404
.send "Not Found"

return