Create offer
This commit is contained in:
parent
d922326ce3
commit
0abaee78f9
24
README.md
Normal file
24
README.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# OS Wilno
|
||||||
|
|
||||||
|
## PostgreSQL dictionary
|
||||||
|
|
||||||
|
https://github.com/dominem/postgresql_fts_polish_dict
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE TEXT SEARCH DICTIONARY polish (
|
||||||
|
Template = ispell,
|
||||||
|
DictFile = polish,
|
||||||
|
AffFile = polish,
|
||||||
|
StopWords = polish
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TEXT SEARCH CONFIGURATION polish(parser = default);
|
||||||
|
|
||||||
|
ALTER TEXT SEARCH CONFIGURATION polish
|
||||||
|
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
|
||||||
|
WITH polish;
|
||||||
|
```
|
12
db/dictionary/create_dict.psql
Normal file
12
db/dictionary/create_dict.psql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
CREATE TEXT SEARCH DICTIONARY polish (
|
||||||
|
Template = ispell,
|
||||||
|
DictFile = polish,
|
||||||
|
AffFile = polish,
|
||||||
|
StopWords = polish
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TEXT SEARCH CONFIGURATION polish(parser = default);
|
||||||
|
|
||||||
|
ALTER TEXT SEARCH CONFIGURATION polish
|
||||||
|
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
|
||||||
|
WITH polish;
|
8627
db/dictionary/polish.affix
Normal file
8627
db/dictionary/polish.affix
Normal file
File diff suppressed because it is too large
Load Diff
358719
db/dictionary/polish.dict
Normal file
358719
db/dictionary/polish.dict
Normal file
File diff suppressed because it is too large
Load Diff
347
db/dictionary/polish.stop
Normal file
347
db/dictionary/polish.stop
Normal file
@ -0,0 +1,347 @@
|
|||||||
|
a
|
||||||
|
aby
|
||||||
|
ach
|
||||||
|
acz
|
||||||
|
aczkolwiek
|
||||||
|
aj
|
||||||
|
albo
|
||||||
|
ale
|
||||||
|
alez
|
||||||
|
ależ
|
||||||
|
ani
|
||||||
|
az
|
||||||
|
aż
|
||||||
|
bardziej
|
||||||
|
bardzo
|
||||||
|
beda
|
||||||
|
bedzie
|
||||||
|
deda
|
||||||
|
będą
|
||||||
|
bede
|
||||||
|
będę
|
||||||
|
będzie
|
||||||
|
bo
|
||||||
|
bowiem
|
||||||
|
by
|
||||||
|
byc
|
||||||
|
być
|
||||||
|
byl
|
||||||
|
byla
|
||||||
|
byli
|
||||||
|
bylo
|
||||||
|
byly
|
||||||
|
był
|
||||||
|
była
|
||||||
|
było
|
||||||
|
były
|
||||||
|
bynajmniej
|
||||||
|
cala
|
||||||
|
cali
|
||||||
|
caly
|
||||||
|
cała
|
||||||
|
cały
|
||||||
|
ci
|
||||||
|
cie
|
||||||
|
ciebie
|
||||||
|
cię
|
||||||
|
co
|
||||||
|
cokolwiek
|
||||||
|
cos
|
||||||
|
coś
|
||||||
|
czasami
|
||||||
|
czasem
|
||||||
|
czemu
|
||||||
|
czy
|
||||||
|
czyli
|
||||||
|
daleko
|
||||||
|
dla
|
||||||
|
dlaczego
|
||||||
|
dlatego
|
||||||
|
do
|
||||||
|
dobrze
|
||||||
|
dokad
|
||||||
|
dokąd
|
||||||
|
dosc
|
||||||
|
dość
|
||||||
|
duzo
|
||||||
|
dużo
|
||||||
|
dwa
|
||||||
|
dwaj
|
||||||
|
dwie
|
||||||
|
dwoje
|
||||||
|
dzis
|
||||||
|
dzisiaj
|
||||||
|
dziś
|
||||||
|
gdy
|
||||||
|
gdyby
|
||||||
|
gdyz
|
||||||
|
gdyż
|
||||||
|
gdzie
|
||||||
|
gdziekolwiek
|
||||||
|
gdzies
|
||||||
|
gdzieś
|
||||||
|
i
|
||||||
|
ich
|
||||||
|
ile
|
||||||
|
im
|
||||||
|
inna
|
||||||
|
inne
|
||||||
|
inny
|
||||||
|
innych
|
||||||
|
iz
|
||||||
|
iż
|
||||||
|
ja
|
||||||
|
jak
|
||||||
|
jakas
|
||||||
|
jakaś
|
||||||
|
jakby
|
||||||
|
jaki
|
||||||
|
jakichs
|
||||||
|
jakichś
|
||||||
|
jakie
|
||||||
|
jakis
|
||||||
|
jakiś
|
||||||
|
jakiz
|
||||||
|
jakiż
|
||||||
|
jakkolwiek
|
||||||
|
jako
|
||||||
|
jakos
|
||||||
|
jakoś
|
||||||
|
ją
|
||||||
|
je
|
||||||
|
jeden
|
||||||
|
jedna
|
||||||
|
jednak
|
||||||
|
jednakze
|
||||||
|
jednakże
|
||||||
|
jedno
|
||||||
|
jego
|
||||||
|
jej
|
||||||
|
jemu
|
||||||
|
jesli
|
||||||
|
jest
|
||||||
|
jestem
|
||||||
|
jeszcze
|
||||||
|
jeśli
|
||||||
|
jezeli
|
||||||
|
jeżeli
|
||||||
|
juz
|
||||||
|
już
|
||||||
|
kazdy
|
||||||
|
każdy
|
||||||
|
kiedy
|
||||||
|
kilka
|
||||||
|
kims
|
||||||
|
kimś
|
||||||
|
kto
|
||||||
|
ktokolwiek
|
||||||
|
ktora
|
||||||
|
ktore
|
||||||
|
ktorego
|
||||||
|
ktorej
|
||||||
|
ktory
|
||||||
|
ktorych
|
||||||
|
ktorym
|
||||||
|
ktorzy
|
||||||
|
ktos
|
||||||
|
ktoś
|
||||||
|
która
|
||||||
|
które
|
||||||
|
którego
|
||||||
|
której
|
||||||
|
który
|
||||||
|
których
|
||||||
|
którym
|
||||||
|
którzy
|
||||||
|
ku
|
||||||
|
lat
|
||||||
|
lecz
|
||||||
|
lub
|
||||||
|
ma
|
||||||
|
mają
|
||||||
|
mało
|
||||||
|
mam
|
||||||
|
mi
|
||||||
|
miedzy
|
||||||
|
między
|
||||||
|
mimo
|
||||||
|
mna
|
||||||
|
mną
|
||||||
|
mnie
|
||||||
|
moga
|
||||||
|
mogą
|
||||||
|
moi
|
||||||
|
moim
|
||||||
|
moj
|
||||||
|
moja
|
||||||
|
moje
|
||||||
|
moze
|
||||||
|
mozliwe
|
||||||
|
mozna
|
||||||
|
może
|
||||||
|
możliwe
|
||||||
|
można
|
||||||
|
mój
|
||||||
|
mu
|
||||||
|
musi
|
||||||
|
my
|
||||||
|
na
|
||||||
|
nad
|
||||||
|
nam
|
||||||
|
nami
|
||||||
|
nas
|
||||||
|
nasi
|
||||||
|
nasz
|
||||||
|
nasza
|
||||||
|
nasze
|
||||||
|
naszego
|
||||||
|
naszych
|
||||||
|
natomiast
|
||||||
|
natychmiast
|
||||||
|
nawet
|
||||||
|
nia
|
||||||
|
nią
|
||||||
|
nic
|
||||||
|
nich
|
||||||
|
nie
|
||||||
|
niech
|
||||||
|
niego
|
||||||
|
niej
|
||||||
|
niemu
|
||||||
|
nigdy
|
||||||
|
nim
|
||||||
|
nimi
|
||||||
|
niz
|
||||||
|
niż
|
||||||
|
no
|
||||||
|
o
|
||||||
|
obok
|
||||||
|
od
|
||||||
|
około
|
||||||
|
on
|
||||||
|
ona
|
||||||
|
one
|
||||||
|
oni
|
||||||
|
ono
|
||||||
|
oraz
|
||||||
|
oto
|
||||||
|
owszem
|
||||||
|
pan
|
||||||
|
pana
|
||||||
|
pani
|
||||||
|
po
|
||||||
|
pod
|
||||||
|
podczas
|
||||||
|
pomimo
|
||||||
|
ponad
|
||||||
|
poniewaz
|
||||||
|
ponieważ
|
||||||
|
powinien
|
||||||
|
powinna
|
||||||
|
powinni
|
||||||
|
powinno
|
||||||
|
poza
|
||||||
|
prawie
|
||||||
|
przeciez
|
||||||
|
przecież
|
||||||
|
przed
|
||||||
|
przede
|
||||||
|
przedtem
|
||||||
|
przez
|
||||||
|
przy
|
||||||
|
roku
|
||||||
|
rowniez
|
||||||
|
również
|
||||||
|
sama
|
||||||
|
są
|
||||||
|
sie
|
||||||
|
się
|
||||||
|
skad
|
||||||
|
skąd
|
||||||
|
soba
|
||||||
|
sobą
|
||||||
|
sobie
|
||||||
|
sposob
|
||||||
|
sposób
|
||||||
|
swoje
|
||||||
|
ta
|
||||||
|
tak
|
||||||
|
taka
|
||||||
|
taki
|
||||||
|
takie
|
||||||
|
takze
|
||||||
|
także
|
||||||
|
tam
|
||||||
|
te
|
||||||
|
tego
|
||||||
|
tej
|
||||||
|
ten
|
||||||
|
teraz
|
||||||
|
też
|
||||||
|
to
|
||||||
|
toba
|
||||||
|
tobą
|
||||||
|
tobie
|
||||||
|
totez
|
||||||
|
toteż
|
||||||
|
totobą
|
||||||
|
trzeba
|
||||||
|
tu
|
||||||
|
tutaj
|
||||||
|
twoi
|
||||||
|
twoim
|
||||||
|
twoj
|
||||||
|
twoja
|
||||||
|
twoje
|
||||||
|
twój
|
||||||
|
twym
|
||||||
|
ty
|
||||||
|
tych
|
||||||
|
tylko
|
||||||
|
tym
|
||||||
|
u
|
||||||
|
w
|
||||||
|
wam
|
||||||
|
wami
|
||||||
|
was
|
||||||
|
wasz
|
||||||
|
wasza
|
||||||
|
wasze
|
||||||
|
we
|
||||||
|
według
|
||||||
|
wiele
|
||||||
|
wielu
|
||||||
|
więc
|
||||||
|
więcej
|
||||||
|
wlasnie
|
||||||
|
właśnie
|
||||||
|
wszyscy
|
||||||
|
wszystkich
|
||||||
|
wszystkie
|
||||||
|
wszystkim
|
||||||
|
wszystko
|
||||||
|
wtedy
|
||||||
|
wy
|
||||||
|
z
|
||||||
|
za
|
||||||
|
zaden
|
||||||
|
zadna
|
||||||
|
zadne
|
||||||
|
zadnych
|
||||||
|
zapewne
|
||||||
|
zawsze
|
||||||
|
ze
|
||||||
|
zeby
|
||||||
|
zeznowu
|
||||||
|
zł
|
||||||
|
znow
|
||||||
|
znowu
|
||||||
|
znów
|
||||||
|
zostal
|
||||||
|
został
|
||||||
|
żaden
|
||||||
|
żadna
|
||||||
|
żadne
|
||||||
|
żadnych
|
||||||
|
że
|
||||||
|
żeby
|
2
migrations/20220719135951_remove_name_from_offers.sql
Normal file
2
migrations/20220719135951_remove_name_from_offers.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE offers
|
||||||
|
DROP COLUMN name;
|
9
scripts/create_pg_dict.sh
Normal file
9
scripts/create_pg_dict.sh
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
ROOT=${PWD}
|
||||||
|
|
||||||
|
sudo cp ./db/dictionary/polish.affix `pg_config --sharedir`/tsearch_data/
|
||||||
|
sudo cp ./db/dictionary/polish.dict `pg_config --sharedir`/tsearch_data/
|
||||||
|
sudo cp ./db/dictionary/polish.stop `pg_config --sharedir`/tsearch_data/
|
||||||
|
|
||||||
|
psql oswilno postgres -f ./db/dictionary/create_dict.psql
|
@ -25,6 +25,8 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
queries::test_dictionary(&pool).await;
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
let policy = CookieIdentityPolicy::new(&[0; 32])
|
let policy = CookieIdentityPolicy::new(&[0; 32])
|
||||||
.name("auth-cookie")
|
.name("auth-cookie")
|
||||||
|
@ -221,3 +221,16 @@ pub struct UpdateContactInfoInput {
|
|||||||
pub struct DeleteContactInfoInput {
|
pub struct DeleteContactInfoInput {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct CreateOfferInput {
|
||||||
|
pub description: String,
|
||||||
|
pub picture_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct UpdateOfferInput {
|
||||||
|
pub id: i32,
|
||||||
|
pub description: String,
|
||||||
|
pub picture_url: String,
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
use sqlx::PgPool;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::model::db;
|
use crate::model::db;
|
||||||
@ -96,6 +97,13 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||||||
|
|
||||||
pub type T<'l> = sqlx::Transaction<'l, sqlx::Postgres>;
|
pub type T<'l> = sqlx::Transaction<'l, sqlx::Postgres>;
|
||||||
|
|
||||||
|
pub async fn test_dictionary(pool: &PgPool) {
|
||||||
|
sqlx::query(r#" SELECT ts_lexize('polish', 'platforma') "#)
|
||||||
|
.execute(pool)
|
||||||
|
.await
|
||||||
|
.expect("Polish dictionary not found");
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn create_item(
|
pub async fn create_item(
|
||||||
t: &mut T<'_>,
|
t: &mut T<'_>,
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use actix_web::web::{Data, ServiceConfig};
|
use actix_web::web::{Data, Form, ServiceConfig};
|
||||||
use actix_web::{get, HttpResponse};
|
use actix_web::{get, post, web, HttpResponse};
|
||||||
use askama::*;
|
use askama::*;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::model::db;
|
use crate::model::db::OfferState;
|
||||||
use crate::model::view::Page;
|
use crate::model::view::Page;
|
||||||
|
use crate::model::{db, view};
|
||||||
use crate::routes::{Identity, Result};
|
use crate::routes::{Identity, Result};
|
||||||
use crate::view::Helper;
|
use crate::view::Helper;
|
||||||
use crate::{authorize, ok_or_internal, queries};
|
use crate::{authorize, ok_or_internal, queries};
|
||||||
@ -31,17 +32,103 @@ pub async fn account_offers(id: Identity, db: Data<PgPool>) -> Result<HttpRespon
|
|||||||
|
|
||||||
t.commit().await.ok();
|
t.commit().await.ok();
|
||||||
|
|
||||||
let body = AccountOffersTemplate {
|
Ok(HttpResponse::Ok().content_type("text/html").body(
|
||||||
account: Some(account),
|
AccountOffersTemplate {
|
||||||
offers,
|
account: Some(account),
|
||||||
page: Page::AccountOffers,
|
offers,
|
||||||
..Default::default()
|
page: Page::AccountOffers,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.render()
|
||||||
|
.unwrap(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/create")]
|
||||||
|
async fn create_offer(
|
||||||
|
id: Identity,
|
||||||
|
db: Data<PgPool>,
|
||||||
|
form: Form<view::CreateOfferInput>,
|
||||||
|
) -> Result<HttpResponse> {
|
||||||
|
let pool = db.into_inner();
|
||||||
|
let mut t = ok_or_internal!(pool.begin().await);
|
||||||
|
let account = authorize!(&mut t, id);
|
||||||
|
let form = form.into_inner();
|
||||||
|
dbg!(&form);
|
||||||
|
|
||||||
|
match queries::create_offer(
|
||||||
|
&mut t,
|
||||||
|
db::CreateOfferInput {
|
||||||
|
description: form.description,
|
||||||
|
picture_url: form.picture_url,
|
||||||
|
state: OfferState::Pending,
|
||||||
|
owner_id: account.id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => {
|
||||||
|
t.commit().await.ok();
|
||||||
|
Ok(HttpResponse::SeeOther()
|
||||||
|
.append_header(("Location", "/account/offers"))
|
||||||
|
.finish())
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
dbg!(e);
|
||||||
|
let offers = queries::account_offers(&mut t, account.id)
|
||||||
|
.await
|
||||||
|
.unwrap_or_default();
|
||||||
|
t.rollback().await.ok();
|
||||||
|
Ok(HttpResponse::Ok().content_type("text/html").body(
|
||||||
|
AccountOffersTemplate {
|
||||||
|
account: Some(account),
|
||||||
|
offers,
|
||||||
|
page: Page::AccountOffers,
|
||||||
|
error: Some("Problem z utworzeniem wpisu".into()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.render()
|
||||||
|
.unwrap(),
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.render()
|
}
|
||||||
.unwrap();
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(body))
|
#[post("/update")]
|
||||||
|
async fn update_offer(
|
||||||
|
id: Identity,
|
||||||
|
db: Data<PgPool>,
|
||||||
|
form: Form<view::UpdateOfferInput>,
|
||||||
|
) -> Result<HttpResponse> {
|
||||||
|
let pool = db.into_inner();
|
||||||
|
let mut t = ok_or_internal!(pool.begin().await);
|
||||||
|
let _account = authorize!(&mut t, id);
|
||||||
|
let form = form.into_inner();
|
||||||
|
dbg!(&form);
|
||||||
|
|
||||||
|
match queries::update_offer(
|
||||||
|
&mut t,
|
||||||
|
db::UpdateOfferInput {
|
||||||
|
id: form.id,
|
||||||
|
description: form.description,
|
||||||
|
picture_url: form.picture_url,
|
||||||
|
state: Default::default(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(_) => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.commit().await.ok();
|
||||||
|
Ok(HttpResponse::NotImplemented().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn configure(config: &mut ServiceConfig) {
|
pub fn configure(config: &mut ServiceConfig) {
|
||||||
config.service(account_offers);
|
config.service(account_offers).service(
|
||||||
|
web::scope("/offers")
|
||||||
|
.service(create_offer)
|
||||||
|
.service(update_offer),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user