Improve create offer
This commit is contained in:
parent
d703ddffdf
commit
1efb7df848
@ -62,7 +62,7 @@ customElements.define('marketplace-offers', class extends Component {
|
||||
this.shadowRoot.querySelector('#publish').addEventListener('click', ev => {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
location.href = '/account/offers';
|
||||
location.href = '/offers/new';
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,16 @@ customElements.define('offer-form', class extends Component {
|
||||
:host { display: block; }
|
||||
#description {
|
||||
height: 200px;
|
||||
width: 100%;
|
||||
}
|
||||
@media only screen and (min-device-width: 1200px) {
|
||||
section {
|
||||
padding: 8px;
|
||||
}
|
||||
@media only screen and (min-device-width: 1000px) {
|
||||
section > form {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
justify-items: stretch;
|
||||
}
|
||||
#imageSection {
|
||||
margin-right: 16px;
|
||||
|
@ -1,7 +1,5 @@
|
||||
{% extends "../base.html" %}
|
||||
{% block content %}
|
||||
<marketplace-offers {{h.account_id_tag(account)}}>
|
||||
<h2>Tworzenie oferty</h2>
|
||||
<offer-form></offer-form>
|
||||
</marketplace-offers>
|
||||
<h2>Tworzenie oferty</h2>
|
||||
<offer-form {{h.account_id_tag(account)}}></offer-form>
|
||||
{% endblock %}
|
||||
|
@ -1,8 +0,0 @@
|
||||
{% extends "../base.html" %}
|
||||
{% block content %}
|
||||
<marketplace-offers {{h.account_id_tag(account)}}>
|
||||
<h2>Sprzedaż niepotrzebnych rzeczy</h2>
|
||||
|
||||
<offer-form></offer-form>
|
||||
</marketplace-offers>
|
||||
{% endblock %}
|
@ -12,29 +12,48 @@ use crate::routes::{HttpResult, Identity};
|
||||
use crate::view::Helper;
|
||||
use crate::{authorize, not_xss, ok_or_internal, queries};
|
||||
|
||||
#[derive(Default, Debug, Template, Serialize)]
|
||||
#[template(path = "./offers/index.html")]
|
||||
struct AccountOffersTemplate {
|
||||
#[derive(Default, Serialize, Template)]
|
||||
#[template(path = "./marketplace/new.html")]
|
||||
struct NewOfferTemplate {
|
||||
account: Option<db::Account>,
|
||||
error: Option<String>,
|
||||
page: Page,
|
||||
#[serde(skip)]
|
||||
h: Helper,
|
||||
}
|
||||
|
||||
#[get("/account/offers")]
|
||||
pub async fn account_offers(req: HttpRequest, id: Identity, db: Data<PgPool>) -> HttpResult {
|
||||
#[get("/new")]
|
||||
async fn new_offer(req: HttpRequest, db: Data<PgPool>, id: Identity) -> HttpResult {
|
||||
let pool = db.into_inner();
|
||||
let mut t = ok_or_internal!(&req, pool.begin().await);
|
||||
let account = authorize!(&req, &mut t, id);
|
||||
let mut t = crate::ok_or_internal!(&req, pool.begin().await);
|
||||
let account = match id.identity() {
|
||||
Some(id) => queries::account_by_id(&mut t, id).await,
|
||||
_ => None,
|
||||
};
|
||||
let account = match account {
|
||||
Some(a) => a,
|
||||
_ => {
|
||||
return HttpResult::res(
|
||||
&req,
|
||||
StatusCode::NOT_FOUND,
|
||||
NewOfferTemplate {
|
||||
page: Page::Marketplace,
|
||||
account,
|
||||
error: Some("Musisz być zalogowany żeby to zrobić".into()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
t.commit().await.ok();
|
||||
|
||||
HttpResult::res(
|
||||
&req,
|
||||
StatusCode::OK,
|
||||
AccountOffersTemplate {
|
||||
NewOfferTemplate {
|
||||
page: Page::Marketplace,
|
||||
account: Some(account),
|
||||
page: Page::AccountOffers,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
@ -80,7 +99,7 @@ async fn create_offer(
|
||||
HttpResult::res(
|
||||
&req,
|
||||
StatusCode::BAD_REQUEST,
|
||||
AccountOffersTemplate {
|
||||
NewOfferTemplate {
|
||||
account: Some(account),
|
||||
page: Page::AccountOffers,
|
||||
error: Some("Problem z utworzeniem wpisu".into()),
|
||||
@ -130,7 +149,7 @@ async fn update_offer(
|
||||
HttpResult::res(
|
||||
&req,
|
||||
StatusCode::BAD_REQUEST,
|
||||
AccountOffersTemplate {
|
||||
NewOfferTemplate {
|
||||
account: Some(account),
|
||||
page: Page::AccountOffers,
|
||||
error: Some("Problem z utworzeniem wpisu".into()),
|
||||
@ -170,7 +189,7 @@ async fn user_finish_offer(
|
||||
HttpResult::res(
|
||||
&req,
|
||||
StatusCode::BAD_REQUEST,
|
||||
AccountOffersTemplate {
|
||||
NewOfferTemplate {
|
||||
account: Some(account),
|
||||
page: Page::AccountOffers,
|
||||
error: Some("Problem z utworzeniem wpisu".into()),
|
||||
@ -182,8 +201,9 @@ async fn user_finish_offer(
|
||||
}
|
||||
|
||||
pub fn configure(config: &mut ServiceConfig) {
|
||||
config.service(account_offers).service(
|
||||
config.service(
|
||||
web::scope("/offers")
|
||||
.service(new_offer)
|
||||
.service(create_offer)
|
||||
.service(update_offer)
|
||||
.service(user_finish_offer),
|
||||
|
@ -73,53 +73,6 @@ async fn marketplace(req: HttpRequest, db: Data<PgPool>, id: Identity) -> HttpRe
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Template)]
|
||||
#[template(path = "./marketplace/new.html")]
|
||||
struct NewOfferTemplate {
|
||||
account: Option<db::Account>,
|
||||
error: Option<String>,
|
||||
page: Page,
|
||||
#[serde(skip)]
|
||||
h: Helper,
|
||||
}
|
||||
|
||||
#[get("/new")]
|
||||
async fn new_marketplace(req: HttpRequest, db: Data<PgPool>, id: Identity) -> HttpResult {
|
||||
let pool = db.into_inner();
|
||||
let mut t = crate::ok_or_internal!(&req, pool.begin().await);
|
||||
let account = match id.identity() {
|
||||
Some(id) => queries::account_by_id(&mut t, id).await,
|
||||
_ => None,
|
||||
};
|
||||
let account = match account {
|
||||
Some(a) => a,
|
||||
_ => {
|
||||
return HttpResult::res(
|
||||
&req,
|
||||
StatusCode::NOT_FOUND,
|
||||
NewOfferTemplate {
|
||||
page: Page::Marketplace,
|
||||
account,
|
||||
error: Some("Musisz być zalogowany żeby to zrobić".into()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
t.commit().await.ok();
|
||||
|
||||
HttpResult::res(
|
||||
&req,
|
||||
StatusCode::OK,
|
||||
NewOfferTemplate {
|
||||
page: Page::Marketplace,
|
||||
account: Some(account),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Template)]
|
||||
#[template(path = "./marketplace/edit.html")]
|
||||
struct EditOfferTemplate {
|
||||
@ -195,7 +148,6 @@ async fn edit_marketplace(
|
||||
pub fn configure(config: &mut ServiceConfig) {
|
||||
config.service(
|
||||
web::scope("/marketplace")
|
||||
.service(new_marketplace)
|
||||
.service(edit_marketplace)
|
||||
.service(marketplace),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user