Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba committed Jun 12, 2016
1 parent 2d0f2ef commit b53c58a
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 16 deletions.
10 changes: 10 additions & 0 deletions examples/social-network/app/controllers/categorizations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller } from 'lux-framework';

class CategorizationsController extends Controller {
params = [
'postId',
'tagId'
];
}

export default CategorizationsController;
9 changes: 9 additions & 0 deletions examples/social-network/app/controllers/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Controller } from 'lux-framework';

class TagsController extends Controller {
params = [
'name'
];
}

export default TagsController;
15 changes: 15 additions & 0 deletions examples/social-network/app/models/categorization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Model } from 'lux-framework';

class Categorization extends Model {
static belongsTo = {
tag: {
inverse: 'posts'
},

post: {
inverse: 'tags'
}
};
}

export default Categorization;
13 changes: 10 additions & 3 deletions examples/social-network/app/models/friendship.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Model } from 'lux-framework';

/* TODO: Add support for self-join on users through a join table.
* https://github.com/postlight/lux/issues/76
*/
class Friendship extends Model {
static belongsTo = {
follower: {
model: 'user',
inverse: 'followers',
},

followee: {
model: 'user',
inverse: 'followees',
}
};
}

export default Friendship;
5 changes: 5 additions & 0 deletions examples/social-network/app/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Post extends Model {

reactions: {
inverse: 'post'
},

tags: {
inverse: 'posts',
through: 'categorization'
}
};

Expand Down
2 changes: 1 addition & 1 deletion examples/social-network/app/models/reaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Reaction extends Model {
},

post: {
inverse: 'reaction'
inverse: 'reactions'
},

user: {
Expand Down
12 changes: 12 additions & 0 deletions examples/social-network/app/models/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Model } from 'lux-framework';

class Tag extends Model {
static hasMany = {
posts: {
inverse: 'tags',
through: 'categorization'
}
};
}

export default Tag;
12 changes: 12 additions & 0 deletions examples/social-network/app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ class User extends Model {
inverse: 'user'
},

followees: {
model: 'user',
inverse: 'followers',
through: 'friendship'
},

followers: {
model: 'user',
inverse: 'followees',
through: 'friendship'
},

reactions: {
inverse: 'user'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/social-network/app/routes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default function routes(route, resource) {
resource('comments');
resource('friendships');
resource('posts');
resource('reactions');
resource('tags');
resource('users');

route('actions', {
Expand Down
10 changes: 10 additions & 0 deletions examples/social-network/app/serializers/categorizations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Serializer } from 'lux-framework';

class CategorizationsSerializer extends Serializer {
hasOne = [
'post',
'tag'
];
}

export default CategorizationsSerializer;
5 changes: 4 additions & 1 deletion examples/social-network/app/serializers/friendships.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Serializer } from 'lux-framework';

class FriendshipsSerializer extends Serializer {

hasOne = [
'followee',
'follower'
];
}

export default FriendshipsSerializer;
3 changes: 2 additions & 1 deletion examples/social-network/app/serializers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class PostsSerializer extends Serializer {

hasMany = [
'comments',
'reactions'
'reactions',
'tags'
];
}

Expand Down
13 changes: 13 additions & 0 deletions examples/social-network/app/serializers/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Serializer } from 'lux-framework';

class TagsSerializer extends Serializer {
attributes = [
'name'
];

hasMany = [
'posts'
];
}

export default TagsSerializer;
2 changes: 2 additions & 0 deletions examples/social-network/app/serializers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class UsersSerializer extends Serializer {
hasMany = [
'comments',
'posts',
'followees',
'followers',
'reactions'
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ export function up(schema) {
table.increments('id');

table
.integer('user_id')
.integer('followee_id')
.notNullable();

table
.integer('friend_id')
.integer('follower_id')
.notNullable();

table.timestamps();

table.index([
'id',
'user_id',
'friend_id',
'followee_id',
'follower_id',
'created_at',
'updated_at'
]);
Expand Down
18 changes: 18 additions & 0 deletions examples/social-network/db/migrate/2016061214092135-create-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function up(schema) {
return schema.createTable('tags', table => {
table.increments('id');
table.string('name');
table.timestamps();

table.index([
'id',
'name',
'created_at',
'updated_at'
]);
});
}

export function down(schema) {
return schema.dropTable('tags');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function up(schema) {
return schema.createTable('categorizations', table => {
table.increments('id');
table.integer('post_id');
table.integer('tag_id');
table.timestamps();

table.index([
'id',
'post_id',
'tag_id',
'created_at',
'updated_at'
]);
});
}

export function down(schema) {
return schema.dropTable('categorizations');
}
23 changes: 21 additions & 2 deletions examples/social-network/db/seed.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import faker from 'faker';

import Categorization from '../app/models/categorization';
import Comment from '../app/models/comment';
import Post from '../app/models/post';
import Reaction from '../app/models/reaction';
import Tag from '../app/models/tag';
import User from '../app/models/user';
import Friendship from '../app/models/friendship';

Expand Down Expand Up @@ -33,8 +35,8 @@ export default async function seed() {
await Promise.all(
[...range(1, 100)].map(() => {
return Friendship.create({
userId: randomize([...range(1, 100)]),
friendId: randomize([...range(1, 100)])
followerId: randomize([...range(1, 100)]),
followeeId: randomize([...range(1, 100)])
});
})
);
Expand All @@ -50,6 +52,23 @@ export default async function seed() {
})
);

await Promise.all(
[...range(1, 100)].map(() => {
return Tag.create({
name: lorem.word()
});
})
);

await Promise.all(
[...range(1, 100)].map(() => {
return Categorization.create({
postId: randomize([...range(1, 100)]),
tagId: randomize([...range(1, 100)])
});
})
);

await Promise.all(
[...range(1, 100)].map(() => {
return Comment.create({
Expand Down
2 changes: 1 addition & 1 deletion examples/social-network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"babel-core": "6.9.1",
"babel-preset-lux": "1.0.0",
"knex": "0.11.5",
"lux-framework": "0.0.1-beta.10",
"lux-framework": "0.0.1-beta.11",
"sqlite3": "3.1.4"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/todo/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "social-network",
"name": "todo",
"version": "0.0.1",
"description": "",
"main": "app/index.js",
Expand All @@ -13,7 +13,7 @@
"babel-core": "6.9.1",
"babel-preset-lux": "1.0.0",
"knex": "0.11.5",
"lux-framework": "0.0.1-beta.10",
"lux-framework": "0.0.1-beta.11",
"sqlite3": "3.1.4"
},
"devDependencies": {
Expand Down

0 comments on commit b53c58a

Please sign in to comment.