From 4f02499d36c762eaa0ff9281c3d36036580a0a15 Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Sun, 28 Aug 2016 01:16:54 -0600 Subject: [PATCH] [WIP] Show user details. The intent is to eventually be able to go to a user's profile page and see a list of their crates. See #409. --- app/router.js | 1 + app/routes/user.js | 12 ++++++++++++ app/templates/user.hbs | 19 +++++++++++++++++++ src/lib.rs | 1 + src/user/mod.rs | 15 +++++++++++++++ tests/unit/routes/user-test.js | 11 +++++++++++ 6 files changed, 59 insertions(+) create mode 100644 app/routes/user.js create mode 100644 app/templates/user.hbs create mode 100644 tests/unit/routes/user-test.js diff --git a/app/router.js b/app/router.js index d858f0d5c9..8e48c6c8ca 100644 --- a/app/router.js +++ b/app/router.js @@ -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'); diff --git a/app/routes/user.js b/app/routes/user.js new file mode 100644 index 0000000000..3a702ed09b --- /dev/null +++ b/app/routes/user.js @@ -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'); + } + }); + }, +}); diff --git a/app/templates/user.hbs b/app/templates/user.hbs new file mode 100644 index 0000000000..dcc7506f17 --- /dev/null +++ b/app/templates/user.hbs @@ -0,0 +1,19 @@ +
+ +

{{ model.login }}

+
+ +
+

{{ model.login }}

+ +
+ {{#user-link user=model }} {{user-avatar user=model size='medium'}} {{/user-link}} + +
+
Name
+
{{ model.name }}
+
GitHub Account
+
{{ model.login }}
+
+
+
diff --git a/src/lib.rs b/src/lib.rs index 3d01759d20..33596374d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,6 +100,7 @@ pub fn middleware(app: Arc) -> 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(); diff --git a/src/user/mod.rs b/src/user/mod.rs index 3d7a2a68f7..904e1a0904 100644 --- a/src/user/mod.rs +++ b/src/user/mod.rs @@ -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; @@ -288,6 +289,20 @@ pub fn me(req: &mut Request) -> CargoResult { 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 { + 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 { let user = try!(req.user()); diff --git a/tests/unit/routes/user-test.js b/tests/unit/routes/user-test.js new file mode 100644 index 0000000000..b63eea3e21 --- /dev/null +++ b/tests/unit/routes/user-test.js @@ -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); +});