Skip to content

Commit af90b2d

Browse files
1155: Propose new MVC module layout r=carols10cents This pull request proposes a new module layout following a model-view-controller style. For now, the functionality is re-exported from the new locations and the `use` statements have been updated to use the new locations. If we define where things should be moved to now, it should be easier to split future changes into small, reviewable PRs. ## Controllers - `src/api/*` For now, this is an empty placeholder, but the api route declarations and endpoints would be moved here. (In a [separate branch](jtgeibel/crates.io@master...mvc-example) I have some examples where the existing logic is moved.) ## Views - `src/views/*` Currently this is JSON only and most existing types are prefixed with `Encodable`. The major exception to this is the types from the `cargo publish` endpoint, which has been moved to `views::krate_publish`. ## Models - `src/models/*` All of the Diesel types would move to here. Many of these were previously reexported from the crate root. Going forward, I think many of the `New*` structs can go away using the new syntax as shown in: https://github.com/rust-lang/crates.io/blob/e0e57b9843c2fb244997a2e47d8cedc40fa9b516/src/boot/categories.rs#L105-L109 # Future work We can consider additional top level modules. For instance, the outgoing email and github_auth functionality could be moved to a module for `external` services. Additionally, `src/pagination.rs` could be moved into `src/api/mod.rs` and a few more things could probably move to `util`. I'm not sure yet where something like the README rendering would fit in.
2 parents 6cb501f + 005e800 commit af90b2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+192
-158
lines changed

src/badge.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use krate::Crate;
2-
use schema::badges;
3-
41
use diesel::pg::Pg;
52
use diesel::prelude::*;
63
use serde_json;
74
use std::collections::HashMap;
85

6+
use models::Crate;
7+
use schema::badges;
8+
99
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
1010
#[serde(rename_all = "kebab-case", tag = "badge_type", content = "attributes")]
1111
pub enum Badge {

src/bin/delete-crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::env;
1515
use std::io;
1616
use std::io::prelude::*;
1717

18-
use cargo_registry::Crate;
18+
use cargo_registry::models::Crate;
1919
use cargo_registry::schema::crates;
2020

2121
#[allow(dead_code)]

src/bin/delete-version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::env;
1515
use std::io;
1616
use std::io::prelude::*;
1717

18-
use cargo_registry::{Crate, Version};
18+
use cargo_registry::models::{Crate, Version};
1919
use cargo_registry::schema::versions;
2020

2121
#[allow(dead_code)]

src/bin/render-readmes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ use std::thread;
3232
use tar::Archive;
3333
use url::Url;
3434

35-
use cargo_registry::{Config, Version};
36-
use cargo_registry::schema::*;
35+
use cargo_registry::Config;
3736
use cargo_registry::render::readme_to_html;
3837

38+
use cargo_registry::models::Version;
39+
use cargo_registry::schema::*;
40+
3941
const DEFAULT_PAGE_SIZE: usize = 25;
4042
const USAGE: &str = "
4143
Usage: render-readmes [options]

src/bin/transfer-crates.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use std::env;
1313
use std::io;
1414
use std::io::prelude::*;
1515

16-
use cargo_registry::{Crate, User};
17-
use cargo_registry::owner::OwnerKind;
16+
use cargo_registry::models::{Crate, OwnerKind, User};
1817
use cargo_registry::schema::*;
1918

2019
fn main() {

src/bin/update-downloads.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use diesel::prelude::*;
88
use std::env;
99
use std::time::Duration;
1010

11-
use cargo_registry::VersionDownload;
11+
use cargo_registry::models::VersionDownload;
1212
use cargo_registry::schema::*;
1313

1414
static LIMIT: i64 = 1000;
@@ -118,9 +118,7 @@ mod test {
118118
use diesel::insert_into;
119119
use super::*;
120120
use cargo_registry::env;
121-
use cargo_registry::krate::{Crate, NewCrate};
122-
use cargo_registry::user::{NewUser, User};
123-
use cargo_registry::version::{NewVersion, Version};
121+
use cargo_registry::models::{Crate, NewCrate, NewUser, NewVersion, User, Version};
124122

125123
fn conn() -> PgConnection {
126124
let conn = PgConnection::establish(&env("TEST_DATABASE_URL")).unwrap();

src/category.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use conduit::{Request, Response};
33
use conduit_router::RequestParams;
44
use diesel::*;
55

6-
use Crate;
76
use db::RequestTransaction;
8-
use schema::*;
97
use util::{CargoResult, RequestUtils};
108

9+
use models::Crate;
10+
use schema::*;
11+
1112
#[derive(Clone, Identifiable, Queryable, QueryableByName, Debug)]
1213
#[table_name = "categories"]
1314
pub struct Category {

src/controllers/helpers/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod pagination;
2+
3+
pub use self::pagination::Paginate;

src/pagination.rs renamed to src/controllers/helpers/pagination.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use diesel::query_builder::*;
33
use diesel::sql_types::BigInt;
44
use diesel::pg::Pg;
55

6+
#[derive(Debug)]
67
pub struct Paginated<T> {
78
query: T,
89
limit: i64,

src/controllers/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// TODO: All endpoints would be moved to submodules here
2+
3+
pub mod helpers;

0 commit comments

Comments
 (0)