v0.11-updatingP1
This commit is contained in:
@@ -107,27 +107,36 @@ impl Mutation {
|
||||
.save(db)
|
||||
.await
|
||||
}
|
||||
/*
|
||||
pub async fn update_post_by_id(
|
||||
|
||||
pub async fn update_book_by_id(
|
||||
db: &DbConn,
|
||||
id: i32,
|
||||
form_data: post::Model,
|
||||
) -> Result<post::Model, DbErr> {
|
||||
let post: post::ActiveModel = Post::find_by_id(id)
|
||||
form_data: book::Model,
|
||||
) -> Result<book::Model, DbErr> {
|
||||
|
||||
let book: book::ActiveModel = Book::find_by_id(id)
|
||||
.one(db)
|
||||
.await?
|
||||
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
|
||||
.ok_or(DbErr::Custom("Cannot find book.".to_owned()))
|
||||
.map(Into::into)?;
|
||||
|
||||
post::ActiveModel {
|
||||
id: post.id,
|
||||
book::ActiveModel {
|
||||
id: book.id,
|
||||
open_library_key: Set(form_data.open_library_key.to_owned()),
|
||||
title: Set(form_data.title.to_owned()),
|
||||
text: Set(form_data.text.to_owned()),
|
||||
}
|
||||
.update(db)
|
||||
.await
|
||||
edition_count: Set(form_data.edition_count.to_owned()),
|
||||
first_publish_year: Set(form_data.first_publish_year.to_owned()),
|
||||
median_page_count: Set(form_data.median_page_count.to_owned()),
|
||||
goodread_id: Set(form_data.goodread_id.to_owned()),
|
||||
description: Set(form_data.description.to_owned()),
|
||||
cover: Set(form_data.cover.to_owned()),
|
||||
location: Set(form_data.location.to_owned()),
|
||||
time_added: Set(form_data.time_added.to_owned()),
|
||||
rating: Set(form_data.rating.to_owned()),
|
||||
comments: Set(form_data.comments.to_owned()),
|
||||
}.update(db).await
|
||||
}
|
||||
*/
|
||||
|
||||
pub async fn delete_book(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
|
||||
let book: book::ActiveModel = Book::find_by_id(id)
|
||||
.one(db)
|
||||
@@ -138,6 +147,53 @@ impl Mutation {
|
||||
book.delete(db).await
|
||||
}
|
||||
|
||||
|
||||
pub async fn delete_book_author(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
|
||||
book_author::Entity::delete_many().filter(
|
||||
Condition::any()
|
||||
.add(book_author::Column::BookId.eq(id))
|
||||
).exec(db).await
|
||||
}
|
||||
|
||||
pub async fn delete_book_person(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
|
||||
book_person::Entity::delete_many().filter(
|
||||
Condition::any()
|
||||
.add(book_person::Column::BookId.eq(id))
|
||||
).exec(db).await
|
||||
}
|
||||
|
||||
|
||||
pub async fn delete_book_place(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
|
||||
book_place::Entity::delete_many().filter(
|
||||
Condition::any()
|
||||
.add(book_place::Column::BookId.eq(id))
|
||||
).exec(db).await
|
||||
}
|
||||
|
||||
|
||||
pub async fn delete_book_subject(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
|
||||
book_subject::Entity::delete_many().filter(
|
||||
Condition::any()
|
||||
.add(book_subject::Column::BookId.eq(id))
|
||||
).exec(db).await
|
||||
}
|
||||
|
||||
pub async fn delete_book_time(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
|
||||
book_time::Entity::delete_many().filter(
|
||||
Condition::any()
|
||||
.add(book_time::Column::BookId.eq(id))
|
||||
).exec(db).await
|
||||
}
|
||||
|
||||
|
||||
pub async fn delete_book_isbn(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
|
||||
book_isbn::Entity::delete_many().filter(
|
||||
Condition::any()
|
||||
.add(book_isbn::Column::BookId.eq(id))
|
||||
).exec(db).await
|
||||
}
|
||||
|
||||
|
||||
pub async fn delete_all_books(db: &DbConn) -> Result<DeleteResult, DbErr> {
|
||||
Book::delete_many().exec(db).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user