Skip to content

Commit

Permalink
Merge pull request #24 from okdas/dev-tag
Browse files Browse the repository at this point in the history
Теги для магазина
  • Loading branch information
Evgeny Frolov committed Sep 16, 2013
2 parents 2053db1 + be1244a commit 9b7d6ad
Show file tree
Hide file tree
Showing 22 changed files with 955 additions and 117 deletions.
8 changes: 8 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ module.exports= (grunt) ->
dest: '<%= pkg.config.build.app.node %>/db/sql'
}]

watch:
scripts:
files: '<%= pkg.config.build.src.node %>/views/assets/**/*'
tasks: ['jade', 'less', 'copy:views']
options:
event: ['added', 'deleted', 'changed']

#coffeelint:
# app:
# options:
Expand Down Expand Up @@ -106,6 +113,7 @@ module.exports= (grunt) ->
grunt.loadNpmTasks 'grunt-contrib-jade'
grunt.loadNpmTasks 'grunt-contrib-less'
grunt.loadNpmTasks 'grunt-yaml'
grunt.loadNpmTasks 'grunt-contrib-watch'
#grunt.loadNpmTasks 'grunt-coffeelint'
#grunt.loadNpmTasks 'grunt-docco'

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "apiserver.builder",
"repository": { "type": "git", "url": "https://github.com/okdas/apiserver.git" },
"repository": {
"type": "git",
"url": "https://github.com/okdas/apiserver.git"
},
"private": true,
"config": {
"build": {
Expand Down Expand Up @@ -28,7 +31,8 @@
"grunt-contrib-less": "0.6.4",
"grunt-yaml": "0.2.1",
"grunt-cli": "0.1.9",
"coffee-script": "1.6.3"
"coffee-script": "1.6.3",
"grunt-contrib-watch": "0.5.3"
},
"engines": {
"node": "0.10.17"
Expand Down
49 changes: 49 additions & 0 deletions source/node/db/sql/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,52 @@ CREATE TABLE IF NOT EXISTS `server_item` (
CONSTRAINT `server_id_item` FOREIGN KEY (`serverId`) REFERENCES `server` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `server_item_id_item` FOREIGN KEY (`itemId`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



CREATE TABLE `tag` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`titleRuPlural` varchar(255) DEFAULT NULL,
`titleRuSingular` varchar(255) DEFAULT NULL,
`titleEnPlural` varchar(45) DEFAULT NULL,
`titleEnSingular` varchar(255) DEFAULT NULL,
`descRu` mediumtext,
`descEn` mediumtext,
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='тег';

CREATE TABLE `tag_tags` (
`childId` int(11) NOT NULL,
`tagId` int(11) NOT NULL,
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`childId`,`tagId`),
KEY `f_tag_tags_child_idx` (`childId`),
KEY `f_tag_tags_tag_idx` (`tagId`),
CONSTRAINT `f_tag_tags_child` FOREIGN KEY (`childId`) REFERENCES `tag` (`id`) ON DELETE CASCADE,
CONSTRAINT `f_tag_tags_tag` FOREIGN KEY (`tagId`) REFERENCES `tag` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='теги тега';

CREATE TABLE `server_tag` (
`serverId` int(11) NOT NULL,
`tagId` int(11) NOT NULL,
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`serverId`,`tagId`),
KEY `f_server_tag_server_idx` (`serverId`),
KEY `f_server_tag_tag_idx` (`tagId`),
CONSTRAINT `f_server_tag_server` FOREIGN KEY (`serverId`) REFERENCES `server` (`id`) ON DELETE CASCADE,
CONSTRAINT `f_server_tag_tag` FOREIGN KEY (`tagId`) REFERENCES `tag` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='теги сервера';

CREATE TABLE `item_tag` (
`itemId` int(11) NOT NULL,
`tagId` int(11) NOT NULL,
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`itemId`,`tagId`),
KEY `f_item_tag_item_idx` (`itemId`),
KEY `f_item_tag_tag_idx` (`tagId`),
CONSTRAINT `f_item_tag_item` FOREIGN KEY (`itemId`) REFERENCES `item` (`id`) ON DELETE CASCADE,
CONSTRAINT `f_item_tag_tag` FOREIGN KEY (`tagId`) REFERENCES `tag` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='теги предмета';
15 changes: 15 additions & 0 deletions source/node/handlers/Manage/Api/V1/Project/Players/Player.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ app.post '/', access, (req, res, next) ->
(conn, done) ->
conn.query 'INSERT INTO player SET ?'
, [req.body]
, (err, resp) ->
playerId= resp.insertId
return done err, conn, playerId

(conn, playerId, done) ->
conn.query '
INSERT
INTO player_balance
SET
playerId = ?,
amount = 0.00,
updatedAt = NOW()'
, [playerId]
, (err, resp) ->
return done err, conn

Expand Down Expand Up @@ -101,6 +114,8 @@ app.get '/:playerId(\\d+)', access, (req, res, next) ->
WHERE id = ?'
, [req.params.playerId]
, (err, resp) ->
console.log 'err', err
console.log 'player', player
player= do resp.shift if not err
return done err, conn, player

Expand Down
47 changes: 47 additions & 0 deletions source/node/handlers/Manage/Api/V1/Project/Servers/Item.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ app.post '/', access, (req, res, next) ->
VALUES ?
"
, [bulk]
, (err, resp) ->
return done err, conn, id

(conn, id, done) ->
# а есть ли теги
if not req.body.tags
return done null, conn

bulk= []
for tag in req.body.tags
bulk.push [id, tag.id]
conn.query "
INSERT INTO item_tag
(`itemId`, `tagId`)
VALUES ?
"
, [bulk]
, (err, resp) ->
return done err, conn

Expand Down Expand Up @@ -185,6 +202,19 @@ app.get '/:itemId(\\d+)', access, (req, res, next) ->
item.servers= resp
return done err, conn, item

(conn, item, done) ->
conn.query '
SELECT
tag.*
FROM item_tag AS connection
JOIN tag AS tag
ON tag.id = connection.tagId
WHERE itemId = ?'
, [req.params.itemId]
, (err, resp) ->
item.tags= resp
return done err, conn, item

], (err, conn, item) ->
do conn.end if conn

Expand All @@ -209,6 +239,9 @@ app.put '/:itemId(\\d+)', access, (req, res, next) ->
servers= item.servers or []
delete item.servers

tags= item.tags or []
delete item.tags

async.waterfall [

(done) ->
Expand Down Expand Up @@ -258,6 +291,20 @@ app.put '/:itemId(\\d+)', access, (req, res, next) ->
, (err, resp) ->
return done err, conn

(conn, done) ->
conn.query 'DELETE FROM item_tag WHERE itemId = ?'
, [itemId]
, (err, resp) ->
return done err, conn if err
return done err, conn if not tags.length

bulk= []
for tag in tags
bulk.push [itemId, tag.id]
conn.query 'INSERT INTO item_tag (`itemId`, `tagId`) VALUES ?'
, [bulk]
, (err, resp) ->
return done err, conn

(conn, done) ->
conn.query 'COMMIT', (err) ->
Expand Down
Loading

0 comments on commit 9b7d6ad

Please sign in to comment.