Move models
This commit is contained in:
parent
7c33a4943c
commit
effa662b4c
@ -1,9 +1,8 @@
|
||||
use seed::{prelude::*, *};
|
||||
|
||||
use jirs_data::UserRole;
|
||||
use jirs_data::{ToVec, UsersFieldId};
|
||||
use jirs_data::{UserRole, WsMsg};
|
||||
|
||||
use crate::api::send_ws_msg;
|
||||
use crate::model::{Model, Page, PageContent, UsersPage};
|
||||
use crate::shared::styled_button::StyledButton;
|
||||
use crate::shared::styled_field::StyledField;
|
||||
|
@ -434,6 +434,7 @@ pub struct ErrorResponse {
|
||||
pub errors: Vec<String>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "backend", derive(Queryable))]
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub struct Project {
|
||||
pub id: ProjectId,
|
||||
@ -466,6 +467,20 @@ pub struct Issue {
|
||||
pub user_ids: Vec<i32>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "backend", derive(Queryable))]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Invitation {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
pub state: InvitationState,
|
||||
pub project_id: i32,
|
||||
pub invited_by_id: i32,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "backend", derive(Queryable))]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Comment {
|
||||
pub id: CommentId,
|
||||
@ -476,6 +491,7 @@ pub struct Comment {
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "backend", derive(Queryable))]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct User {
|
||||
pub id: UserId,
|
||||
@ -488,6 +504,7 @@ pub struct User {
|
||||
pub user_role: UserRole,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "backend", derive(Queryable))]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Token {
|
||||
pub id: TokenId,
|
||||
@ -496,6 +513,7 @@ pub struct Token {
|
||||
pub refresh_token: Uuid,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
pub bind_token: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, PartialOrd, Hash)]
|
||||
@ -515,6 +533,16 @@ pub struct UpdateIssuePayload {
|
||||
pub user_ids: Vec<UserId>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "backend", derive(Queryable))]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct IssueAssignee {
|
||||
pub id: i32,
|
||||
pub issue_id: i32,
|
||||
pub user_id: i32,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl From<Issue> for UpdateIssuePayload {
|
||||
fn from(issue: Issue) -> Self {
|
||||
Self {
|
||||
|
@ -2,9 +2,10 @@ use actix::{Handler, Message};
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use jirs_data::{Token, User};
|
||||
|
||||
use crate::db::{DbExecutor, DbPool, SyncQuery};
|
||||
use crate::errors::ServiceErrors;
|
||||
use crate::models::{Token, User};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct AuthorizeUser {
|
||||
@ -12,11 +13,11 @@ pub struct AuthorizeUser {
|
||||
}
|
||||
|
||||
impl Message for AuthorizeUser {
|
||||
type Result = Result<crate::models::User, ServiceErrors>;
|
||||
type Result = Result<User, ServiceErrors>;
|
||||
}
|
||||
|
||||
impl Handler<AuthorizeUser> for DbExecutor {
|
||||
type Result = Result<crate::models::User, ServiceErrors>;
|
||||
type Result = Result<User, ServiceErrors>;
|
||||
|
||||
fn handle(&mut self, msg: AuthorizeUser, _: &mut Self::Context) -> Self::Result {
|
||||
use crate::schema::tokens::dsl::{access_token, tokens};
|
||||
@ -41,7 +42,7 @@ impl Handler<AuthorizeUser> for DbExecutor {
|
||||
}
|
||||
|
||||
impl SyncQuery for AuthorizeUser {
|
||||
type Result = std::result::Result<crate::models::User, crate::errors::ServiceErrors>;
|
||||
type Result = std::result::Result<User, crate::errors::ServiceErrors>;
|
||||
|
||||
fn handle(&self, pool: &DbPool) -> Self::Result {
|
||||
use crate::schema::tokens::dsl::{access_token, tokens};
|
||||
|
@ -2,9 +2,10 @@ use actix::{Handler, Message};
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use jirs_data::Comment;
|
||||
|
||||
use crate::db::DbExecutor;
|
||||
use crate::errors::ServiceErrors;
|
||||
use crate::models::Comment;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct LoadIssueComments {
|
||||
|
@ -2,9 +2,10 @@ use actix::{Handler, Message};
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use jirs_data::IssueAssignee;
|
||||
|
||||
use crate::db::DbExecutor;
|
||||
use crate::errors::ServiceErrors;
|
||||
use crate::models::IssueAssignee;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct LoadAssignees {
|
||||
|
@ -2,11 +2,10 @@ use actix::{Handler, Message};
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use jirs_data::ProjectCategory;
|
||||
use jirs_data::{Project, ProjectCategory};
|
||||
|
||||
use crate::db::DbExecutor;
|
||||
use crate::errors::ServiceErrors;
|
||||
use crate::models::Project;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct LoadCurrentProject {
|
||||
|
@ -3,11 +3,11 @@ use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use jirs_data::UserId;
|
||||
use jirs_data::{Token, UserId};
|
||||
|
||||
use crate::db::DbExecutor;
|
||||
use crate::errors::ServiceErrors;
|
||||
use crate::models::{Token, TokenForm};
|
||||
use crate::models::TokenForm;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindBindToken {
|
||||
@ -15,11 +15,11 @@ pub struct FindBindToken {
|
||||
}
|
||||
|
||||
impl Message for FindBindToken {
|
||||
type Result = Result<crate::models::Token, ServiceErrors>;
|
||||
type Result = Result<Token, ServiceErrors>;
|
||||
}
|
||||
|
||||
impl Handler<FindBindToken> for DbExecutor {
|
||||
type Result = Result<crate::models::Token, ServiceErrors>;
|
||||
type Result = Result<Token, ServiceErrors>;
|
||||
|
||||
fn handle(&mut self, msg: FindBindToken, _: &mut Self::Context) -> Self::Result {
|
||||
use crate::schema::tokens::dsl::{bind_token, tokens};
|
||||
@ -28,7 +28,7 @@ impl Handler<FindBindToken> for DbExecutor {
|
||||
.get()
|
||||
.map_err(|_| ServiceErrors::DatabaseConnectionLost)?;
|
||||
|
||||
let token: crate::models::Token = tokens
|
||||
let token: Token = tokens
|
||||
.filter(bind_token.eq(Some(msg.token)))
|
||||
.first(conn)
|
||||
.map_err(|_e| ServiceErrors::RecordNotFound(format!("token for {}", msg.token)))?;
|
||||
@ -49,11 +49,11 @@ pub struct CreateBindToken {
|
||||
}
|
||||
|
||||
impl Message for CreateBindToken {
|
||||
type Result = Result<crate::models::Token, ServiceErrors>;
|
||||
type Result = Result<Token, ServiceErrors>;
|
||||
}
|
||||
|
||||
impl Handler<CreateBindToken> for DbExecutor {
|
||||
type Result = Result<crate::models::Token, ServiceErrors>;
|
||||
type Result = Result<Token, ServiceErrors>;
|
||||
|
||||
fn handle(&mut self, msg: CreateBindToken, _: &mut Self::Context) -> Self::Result {
|
||||
use crate::schema::tokens::dsl::tokens;
|
||||
|
@ -2,9 +2,11 @@ use actix::{Handler, Message};
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use jirs_data::{IssueAssignee, Project, User};
|
||||
|
||||
use crate::db::{DbExecutor, DbPooledConn};
|
||||
use crate::errors::ServiceErrors;
|
||||
use crate::models::{CreateProjectForm, IssueAssignee, Project, User, UserForm};
|
||||
use crate::models::{CreateProjectForm, UserForm};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindUser {
|
||||
@ -180,7 +182,7 @@ fn count_matching_users(name: &str, email: &str, conn: &DbPooledConn) -> i64 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::db::build_pool;
|
||||
use crate::models::{CreateProjectForm, Project};
|
||||
use crate::models::CreateProjectForm;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -6,6 +6,8 @@ use actix_web::http::HeaderMap;
|
||||
use actix_web::{dev::ServiceRequest, dev::ServiceResponse, Error};
|
||||
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready};
|
||||
|
||||
use jirs_data::User;
|
||||
|
||||
use crate::db::SyncQuery;
|
||||
|
||||
type Db = actix_web::web::Data<crate::db::DbPool>;
|
||||
@ -93,7 +95,7 @@ pub fn token_from_headers(
|
||||
fn check_token(
|
||||
headers: &HeaderMap,
|
||||
pool: Db,
|
||||
) -> std::result::Result<crate::models::User, crate::errors::ServiceErrors> {
|
||||
) -> std::result::Result<User, crate::errors::ServiceErrors> {
|
||||
token_from_headers(headers).and_then(|access_token| {
|
||||
use crate::db::authorize_user::AuthorizeUser;
|
||||
AuthorizeUser { access_token }.handle(&pool)
|
||||
|
@ -2,39 +2,11 @@ use chrono::NaiveDateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use jirs_data::{
|
||||
InvitationState, InvitationStateType, IssuePriority, IssueStatus, IssueType, ProjectCategory,
|
||||
UserRole,
|
||||
};
|
||||
use jirs_data::{InvitationState, IssuePriority, IssueStatus, IssueType, ProjectCategory};
|
||||
|
||||
use crate::schema::*;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Queryable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Comment {
|
||||
pub id: i32,
|
||||
pub body: String,
|
||||
pub user_id: i32,
|
||||
pub issue_id: i32,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Into<jirs_data::Comment> for Comment {
|
||||
fn into(self) -> jirs_data::Comment {
|
||||
jirs_data::Comment {
|
||||
id: self.id,
|
||||
body: self.body,
|
||||
user_id: self.user_id,
|
||||
issue_id: self.issue_id,
|
||||
created_at: self.created_at,
|
||||
updated_at: self.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Insertable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[table_name = "comments"]
|
||||
pub struct CommentForm {
|
||||
pub body: String,
|
||||
@ -43,11 +15,9 @@ pub struct CommentForm {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Queryable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Issue {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
#[serde(rename = "type")]
|
||||
pub issue_type: IssueType,
|
||||
pub status: IssueStatus,
|
||||
pub priority: IssuePriority,
|
||||
@ -88,11 +58,9 @@ impl Into<jirs_data::Issue> for Issue {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Insertable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[table_name = "issues"]
|
||||
pub struct CreateIssueForm {
|
||||
pub title: String,
|
||||
#[serde(rename = "type")]
|
||||
pub issue_type: IssueType,
|
||||
pub status: IssueStatus,
|
||||
pub priority: IssuePriority,
|
||||
@ -106,49 +74,13 @@ pub struct CreateIssueForm {
|
||||
pub project_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Queryable)]
|
||||
pub struct IssueAssignee {
|
||||
pub id: i32,
|
||||
pub issue_id: i32,
|
||||
pub user_id: i32,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Insertable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[table_name = "issue_assignees"]
|
||||
pub struct CreateIssueAssigneeForm {
|
||||
pub issue_id: i32,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Queryable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Project {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub url: String,
|
||||
pub description: String,
|
||||
pub category: ProjectCategory,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Into<jirs_data::Project> for Project {
|
||||
fn into(self) -> jirs_data::Project {
|
||||
jirs_data::Project {
|
||||
id: self.id,
|
||||
name: self.name,
|
||||
url: self.url,
|
||||
description: self.description,
|
||||
category: self.category,
|
||||
created_at: self.created_at,
|
||||
updated_at: self.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Insertable)]
|
||||
#[table_name = "projects"]
|
||||
pub struct UpdateProjectForm {
|
||||
@ -167,50 +99,7 @@ pub struct CreateProjectForm {
|
||||
pub category: ProjectCategory,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Queryable)]
|
||||
pub struct User {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
pub avatar_url: Option<String>,
|
||||
pub project_id: i32,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
pub user_role: UserRole,
|
||||
}
|
||||
|
||||
impl Into<jirs_data::User> for User {
|
||||
fn into(self) -> jirs_data::User {
|
||||
jirs_data::User {
|
||||
id: self.id,
|
||||
name: self.name,
|
||||
email: self.email,
|
||||
avatar_url: self.avatar_url,
|
||||
project_id: self.project_id,
|
||||
created_at: self.created_at,
|
||||
updated_at: self.updated_at,
|
||||
user_role: self.user_role,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<jirs_data::User> for &User {
|
||||
fn into(self) -> jirs_data::User {
|
||||
jirs_data::User {
|
||||
id: self.id,
|
||||
name: self.name.clone(),
|
||||
email: self.email.clone(),
|
||||
avatar_url: self.avatar_url.clone(),
|
||||
project_id: self.project_id,
|
||||
created_at: self.created_at,
|
||||
updated_at: self.updated_at,
|
||||
user_role: self.user_role,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Insertable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[table_name = "users"]
|
||||
pub struct UserForm {
|
||||
pub name: String,
|
||||
@ -219,30 +108,6 @@ pub struct UserForm {
|
||||
pub project_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Queryable)]
|
||||
pub struct Token {
|
||||
pub id: i32,
|
||||
pub user_id: i32,
|
||||
pub access_token: Uuid,
|
||||
pub refresh_token: Uuid,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
pub bind_token: Option<Uuid>,
|
||||
}
|
||||
|
||||
impl Into<jirs_data::Token> for Token {
|
||||
fn into(self) -> jirs_data::Token {
|
||||
jirs_data::Token {
|
||||
id: self.id,
|
||||
user_id: self.user_id,
|
||||
access_token: self.access_token,
|
||||
refresh_token: self.refresh_token,
|
||||
created_at: self.created_at,
|
||||
updated_at: self.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Insertable)]
|
||||
#[table_name = "tokens"]
|
||||
pub struct TokenForm {
|
||||
@ -252,18 +117,6 @@ pub struct TokenForm {
|
||||
pub bind_token: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Queryable)]
|
||||
pub struct Invitation {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
pub state: InvitationState,
|
||||
pub project_id: i32,
|
||||
pub invited_by_id: i32,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Insertable)]
|
||||
#[table_name = "invitations"]
|
||||
pub struct InvitationForm {
|
||||
|
@ -5,11 +5,12 @@ use actix_web::web::Data;
|
||||
use actix_web::{HttpRequest, HttpResponse};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use jirs_data::User;
|
||||
|
||||
use crate::db::authorize_user::AuthorizeUser;
|
||||
use crate::db::DbExecutor;
|
||||
use crate::errors::ServiceErrors;
|
||||
use crate::middleware::authorize::token_from_headers;
|
||||
use crate::models::User;
|
||||
|
||||
pub async fn user_from_request(
|
||||
req: HttpRequest,
|
||||
|
@ -4,7 +4,7 @@ use actix::*;
|
||||
use actix_web::web::Data;
|
||||
use futures::executor::block_on;
|
||||
|
||||
use jirs_data::{IssueFieldId, PayloadVariant, WsMsg};
|
||||
use jirs_data::{IssueAssignee, IssueFieldId, PayloadVariant, WsMsg};
|
||||
|
||||
use crate::db::issue_assignees::LoadAssignees;
|
||||
use crate::db::issues::{LoadProjectIssues, UpdateIssue};
|
||||
@ -81,7 +81,6 @@ impl Handler<UpdateIssueHandler> for WebSocketActor {
|
||||
_ => return Ok(None),
|
||||
};
|
||||
|
||||
use crate::models::IssueAssignee;
|
||||
let assignees: Vec<IssueAssignee> =
|
||||
match block_on(self.db.send(LoadAssignees { issue_id: issue.id })) {
|
||||
Ok(Ok(v)) => v,
|
||||
|
@ -8,7 +8,7 @@ use actix_web::{get, web, Error, HttpRequest, HttpResponse};
|
||||
use actix_web_actors::ws;
|
||||
use futures::executor::block_on;
|
||||
|
||||
use jirs_data::{ProjectId, UserId, WsMsg};
|
||||
use jirs_data::{ProjectId, Token, UserId, WsMsg};
|
||||
|
||||
use crate::db::authorize_user::AuthorizeUser;
|
||||
use crate::db::tokens::FindBindToken;
|
||||
@ -203,8 +203,7 @@ impl WebSocketActor {
|
||||
}
|
||||
|
||||
async fn check_bind_token(&mut self, bind_token: uuid::Uuid) -> WsResult {
|
||||
let token: crate::models::Token =
|
||||
match self.db.send(FindBindToken { token: bind_token }).await {
|
||||
let token: Token = match self.db.send(FindBindToken { token: bind_token }).await {
|
||||
Ok(Ok(token)) => token,
|
||||
Ok(Err(_)) => return Ok(Some(WsMsg::BindTokenBad)),
|
||||
_ => return Ok(None),
|
||||
|
Loading…
Reference in New Issue
Block a user