Skip to content

Commit

Permalink
[WIP] Show user details.
Browse files Browse the repository at this point in the history
The intent is to eventually be able to go to a user's profile page and
see a list of their crates.

See rust-lang#409.
  • Loading branch information
wlonk committed Aug 28, 2016
1 parent 621d1ea commit 4c2e19b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Router.map(function() {
this.route('crates');
this.route('following');
});
this.route('user', { path: '/users/:user_id' });
this.route('install');
this.route('search');
this.route('dashboard');
Expand Down
12 changes: 12 additions & 0 deletions app/routes/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';

export default Ember.Route.extend({
model(params) {
return this.store.find('user', params.user_id).catch(e => {
if (e.errors.any(e => e.detail === 'Not Found')) {
this.controllerFor('application').set('nextFlashError', `User '${params.user_id}' does not exist`);
return this.replaceWith('index');
}
});
},
});
19 changes: 19 additions & 0 deletions app/templates/user.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div id='crates-heading'>
<img class='gear logo' src="/assets/gear.png"/>
<h1>{{ model.login }}</h1>
</div>

<div id='user-profile'>
<h2>{{ model.login }}</h2>

<div class='info'>
{{#user-link user=model }} {{user-avatar user=model size='medium'}} {{/user-link}}

<dl>
<dt>Name</dt>
<dd>{{ model.name }}</dd>
<dt>GitHub Account</dt>
<dd>{{ model.login }}</dd>
</dl>
</div>
</div>
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub fn middleware(app: Arc<App>) -> MiddlewareBuilder {
api_router.get("/versions/:version_id", C(version::show));
api_router.get("/keywords", C(keyword::index));
api_router.get("/keywords/:keyword_id", C(keyword::show));
api_router.get("/users/:user_id", C(user::show));
let api_router = Arc::new(R404(api_router));

let mut router = RouteBuilder::new();
Expand Down
15 changes: 15 additions & 0 deletions src/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;

use conduit::{Request, Response};
use conduit_cookie::{RequestSession};
use conduit_router::RequestParams;
use pg::GenericConnection;
use pg::rows::Row;
use pg::types::Slice;
Expand Down Expand Up @@ -288,6 +289,20 @@ pub fn me(req: &mut Request) -> CargoResult<Response> {
Ok(req.json(&R{ user: user.clone().encodable(), api_token: token }))
}

/// Handles the `GET /users/:user_id` route.
pub fn show(req: &mut Request) -> CargoResult<Response> {
let name = &req.params()["user_id"];
let conn = try!(req.tx());
let user = try!(User::find_by_login(conn, &name));

#[derive(RustcEncodable)]
struct R {
user: EncodableUser,
}
Ok(req.json(&R{ user: user.clone().encodable() }))
}


/// Handles the `GET /me/updates` route.
pub fn updates(req: &mut Request) -> CargoResult<Response> {
let user = try!(req.user());
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/routes/user-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('route:user', 'Unit | Route | user', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});

test('it exists', function(assert) {
let route = this.subject();
assert.ok(route);
});

0 comments on commit 4c2e19b

Please sign in to comment.