Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

url structure

  • Loading branch information...
commit bb2e68e0169d1e944b70fa93d9b653455bc804fc 1 parent 9b3d4e2
@bhazzard authored
View
7 models/post.js
@@ -15,16 +15,11 @@ PostSchema.pre('save', function(next) {
this.topics = this.message.match(/#(\w+)/gi);
next();
});
-/*
+
PostSchema.pre('save', function(next) {
this.mentions = this.message.match(/@(\w+)/gi);
next();
});
-*/
-PostSchema.pre('save', function(next) {
- this.domain = this.user.split('@')[1];
- next();
-});
var Post = mongoose.model('Post', PostSchema);
View
26 soapbox.js
@@ -3,36 +3,40 @@ var express = require('express'),
Post = require('./models/post');
/* lets do a simple twitter clone */
-app.get('/users/:user/posts', function(req, res) {
+app.get('/domains/:domain/users/:user/posts', function(req, res) {
Post.find(req.params, function(err, posts) {
+ if (err) return res.send(err);
res.send(posts);
});
});
-app.post('/users/:user/posts', function(req, res) {
- var post = new Post();
- post.user = req.params.user;
- post.message = "blah #asdf or #wojd";
+app.post('/domains/:domain/users/:user/posts', function(req, res) {
+ var post = new Post(req.params);
+ post.message = req.body.message;
post.save(function(err) {
- res.send(err);
+ if (err) return res.send(err);
+ res.send(201);
});
});
/* lets do a simple twitter clone */
-app.get('/users/:user/posts/:_id', function(req, res) {
+app.get('/domains/:domain/users/:user/posts/:_id', function(req, res) {
Post.findOne(req.params, function(err, posts) {
- res.send(posts);
+ res.render('post.ejs', posts);
});
});
-app.delete('/users/:user/posts/:_id', function(req, res) {
+app.delete('/domains/:domain/users/:user/posts/:_id', function(req, res) {
Post.remove(req.params, function(err) {
res.send(err);
});
});
-app.get('/topics/:topic', function(req, res) {
-
+app.get('/domains/:domain/topics/:topic', function(req, res) {
+ Post.find({ topics: '#' + req.params.topic }, function(err, topics) {
+ if (err) return res.send(err);
+ res.send(topics);
+ });
});
app.listen(process.env.PORT);
View
9 views/layout.ejs
@@ -1,8 +1 @@
-<html>
- <head>
- <title>Blah</title>
- </head>
- <body>
- <%- body %>
- </body>
-</html>
+<%- body %>
View
7 views/post.ejs
@@ -0,0 +1,7 @@
+{
+ "_links": {
+ self: { href: "/domains/<%= domain %>/users/<%= user %>/posts/<%= _id %>" }
+ },
+ poster: "<%= user %>@<%= domain %>",
+ message: "<%= message %>",
+}
View
6 views/registration.ejs
@@ -1,6 +0,0 @@
-<section itemscope itemtype="/vocab/userregistration">
- <form action="/register" method="post">
- <input itemprop="username" name="username" type="text" />
- <input itemprop="password" name="password" type="text" />
- </form>
-<section>
Please sign in to comment.
Something went wrong with that request. Please try again.