This commit is contained in:
Adrian Woźniak 2022-07-22 13:05:13 +02:00
parent 45aee77327
commit b1b8029e87
No known key found for this signature in database
GPG Key ID: 0012845A89C7352B
60 changed files with 567 additions and 79 deletions

0
.env Normal file
View File

2
.gitignore vendored
View File

@ -6,3 +6,5 @@ client/dist/app.js.map
client/dist/app.js
client/dist/admin.js.map
client/dist/admin.js
web/tmp
web/build

200
Cargo.lock generated
View File

@ -112,7 +112,7 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"rand",
"sha1",
"sha1 0.10.1",
"smallvec",
"tracing",
"zstd",
@ -243,7 +243,7 @@ dependencies = [
"ahash",
"bytes",
"bytestring",
"cfg-if",
"cfg-if 1.0.0",
"cookie",
"derive_more",
"encoding_rs",
@ -309,7 +309,7 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cipher",
"cpufeatures",
"opaque-debug",
@ -459,6 +459,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base-x"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270"
[[package]]
name = "base64"
version = "0.13.0"
@ -552,6 +558,12 @@ dependencies = [
"jobserver",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -635,7 +647,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -644,7 +656,7 @@ version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"crossbeam-utils",
]
@ -654,7 +666,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"crossbeam-utils",
]
@ -664,7 +676,7 @@ version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"once_cell",
]
@ -696,7 +708,7 @@ dependencies = [
"convert_case",
"proc-macro2",
"quote",
"rustc_version",
"rustc_version 0.4.0",
"syn",
]
@ -731,6 +743,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "discard"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "dotenv"
version = "0.15.0"
@ -749,7 +767,7 @@ version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -912,7 +930,7 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
@ -1094,7 +1112,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -1182,7 +1200,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -1206,6 +1224,12 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memory_units"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
[[package]]
name = "mime"
version = "0.3.16"
@ -1371,7 +1395,7 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"instant",
"libc",
"redox_syscall",
@ -1385,7 +1409,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"smallvec",
@ -1471,7 +1495,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"opaque-debug",
"universal-hash",
@ -1650,13 +1674,22 @@ dependencies = [
"winapi",
]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver 0.9.0",
]
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
"semver 1.0.12",
]
[[package]]
@ -1702,6 +1735,15 @@ dependencies = [
"untrusted",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver"
version = "1.0.12"
@ -1709,19 +1751,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
[[package]]
name = "serde"
version = "1.0.139"
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.139"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb"
checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da"
dependencies = [
"proc-macro2",
"quote",
@ -1757,29 +1805,44 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
]
[[package]]
name = "sha1"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770"
dependencies = [
"sha1_smol",
]
[[package]]
name = "sha1"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
]
[[package]]
name = "sha1_smol"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]]
name = "sha2"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
]
@ -1942,6 +2005,67 @@ dependencies = [
"tokio-rustls",
]
[[package]]
name = "stdweb"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
dependencies = [
"discard",
"rustc_version 0.2.3",
"serde",
"serde_json",
"stdweb-derive",
"stdweb-internal-macros",
"stdweb-internal-runtime",
"wasm-bindgen",
]
[[package]]
name = "stdweb-derive"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde",
"serde_derive",
"syn",
]
[[package]]
name = "stdweb-internal-macros"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"serde_json",
"sha1 0.6.1",
"syn",
]
[[package]]
name = "stdweb-internal-runtime"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "stdweb-logger"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c00e8795899ea8ef2fb1a5e2e7349c1b974f4c281a1b4859790e8ab47d999adc"
dependencies = [
"log",
"stdweb",
]
[[package]]
name = "stringprep"
version = "0.1.2"
@ -2136,7 +2260,7 @@ version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"log",
"pin-project-lite",
"tracing-attributes",
@ -2387,7 +2511,7 @@ version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"wasm-bindgen-macro",
]
@ -2435,6 +2559,17 @@ version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be"
[[package]]
name = "web"
version = "0.1.0"
dependencies = [
"serde",
"stdweb",
"stdweb-derive",
"stdweb-logger",
"wee_alloc",
]
[[package]]
name = "web-sys"
version = "0.3.58"
@ -2464,6 +2599,19 @@ dependencies = [
"webpki",
]
[[package]]
name = "wee_alloc"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
dependencies = [
"cfg-if 0.1.10",
"libc",
"memory_units",
"spin",
"winapi",
]
[[package]]
name = "whoami"
version = "1.2.1"

View File

@ -1,35 +1,5 @@
[package]
name = "oswilno"
version = "0.1.0"
edition = "2021"
[dependencies]
actix = { version = "*" }
actix-cors = { version = "*" }
actix-files = { version = "*" }
actix-http = { version = "3.2.1" }
actix-identity = { version = "0.4.0" }
actix-multipart = { version = "0.4.0" }
actix-rt = { version = "*" }
actix-utils = { version = "3.0.0" }
actix-web = { version = "*" }
argon2 = { version = "0.4.1" }
askama = { version = "*", features = ["serde-json"] }
byteorder = { version = "1.4.3" }
chrono = { version = "*", features = ["serde"] }
futures = { version = "0.3.21", features = ["async-await", "std"] }
futures-util = { version = "0.3.21", features = [] }
gumdrop = { version = "*" }
password-hash = { version = "0.4.2" }
postgres = { version = "0.19.3" }
rand = { version = "0.8.5", features = [] }
serde = { version = "*", features = ["derive"] }
serde_json = { version = "*" }
sqlx = { version = "*", features = ["runtime-actix-rustls", "postgres", "uuid", "chrono"] }
sqlx-core = { version = "0.6.0" }
tracing = { version = "*" }
tracing-actix-web = { version = "*" }
tracing-subscriber = { version = "*" }
uuid = { version = "*", features = ["serde"] }
validator = { version = "0.14", features = ["derive"] }
base64 = "0.13.0"
[workspace]
members = [
'server',
'web',
]

View File

@ -33,7 +33,7 @@ customElements.define('marketplace-offer', class extends Component {
:host([price-range-max="0"]) #sep {
display: none;
}
section {
#details {
display: grid;
column-gap: 16px;
grid-template-areas: "img img img"
@ -58,9 +58,13 @@ customElements.define('marketplace-offer', class extends Component {
grid-area: max;
justify-self: start;
}
#contacts {
display: flex;
justify-content: end;
}
@media only screen and (min-device-width: 1200px) {
section {
#details {
display: grid;
column-gap: 16px;
grid-template-areas: "img desc desc desc desc desc"
@ -100,7 +104,7 @@ customElements.define('marketplace-offer', class extends Component {
}
${ INPUT_STYLE }
</style>
<section>
<section id="details">
<div id="preview">
<image-popup src="" id="picture">
</image-popup>
@ -110,6 +114,10 @@ customElements.define('marketplace-offer', class extends Component {
<span id="sep">-</span>
<span id="price-max"></span>
</section>
<section id="contacts">
<span style="margin-right: 10px; font-weight: bold">Kontakt:</span>
<slot name="contacts"></slot>
</section>
`);
this.#price_range = new PriceRange(0, 0);
}

View File

@ -14,6 +14,9 @@ customElements.define('offer-form', class extends Component {
font-style: italic;
color: var(--border-slim-color)
}
#description {
height: 200px;
}
@media only screen and (min-device-width: 1200px) {
section > form {
display: flex;

View File

@ -4,7 +4,7 @@ const MODES = { 'view': 'view', 'form': 'form' };
customElements.define('user-edit-offer', class extends Component {
static get observedAttributes() {
return ['mode', 'offer-id', 'description', 'picture-url', 'price-range-min', 'price-range-max'];
return ['mode', 'state' , 'offer-id', 'description', 'picture-url', 'price-range-min', 'price-range-max'];
}
constructor() {
@ -18,10 +18,18 @@ customElements.define('user-edit-offer', class extends Component {
}
:host([mode='view']) #view { display: block; }
:host([mode='form']) #form { display: block; }
#actions > input {
#actions {
width: 120px;
}
#actions input {
width: 100%;
}
#state {
font-weight: bold;
margin-bottom: 8px;
display: block;
text-align: center;
}
@media only screen and (min-device-width: 1200px) {
:host([mode='view']) #view { display: flex; }
#actions {
@ -33,8 +41,12 @@ customElements.define('user-edit-offer', class extends Component {
<section id="view">
<slot></slot>
<div id="actions">
<div id="state"></div>
<input type="button" value="Edytuj" id="edit" />
<input type="button" slot="action" id="finish" value="Zakończ" />
<form action="/offers/finish" method="post">
<input type="hidden" name="id" class="id" value="" />
<input type="submit" slot="action" id="finish" value="Zakończ" />
</form>
</div>
</section>
<section id="form">
@ -74,6 +86,8 @@ customElements.define('user-edit-offer', class extends Component {
v = parseInt(v);
this.setAttribute('offer-id', v);
this.shadowRoot.querySelector('offer-form').offer_id = v;
for (const el of this.shadowRoot.querySelectorAll('.id'))
el.value = v;
}
get description() {
@ -111,4 +125,31 @@ customElements.define('user-edit-offer', class extends Component {
this.setAttribute('price-range-max', v);
this.shadowRoot.querySelector('offer-form').price_range_max = v;
}
get state() {
return this.getAttribute('state');
}
set state(v) {
this.setAttribute('state', v);
const el = this.shadowRoot.querySelector('#state');
switch (v) {
case 'Pending': {
el.textContent = 'Oczekuje';
break;
}
case 'Approved': {
el.textContent = 'Zaakceptowane';
break;
}
case 'Banned': {
el.textContent = 'Odrzucone';
break;
}
case 'Finished': {
el.textContent = 'Zakończone';
break;
}
}
}
});

View File

@ -0,0 +1,2 @@
ALTER TYPE "OfferState"
ADD VALUE 'Finished';

0
scripts/create_pg_dict.sh Normal file → Executable file
View File

32
scripts/dev.sh Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
RSASS_PATH=$(command -v rsass)
if [[ "${RSASS_PATH}" == "" ]]; then
cargo install rsass --features=commandline
fi
WASM_PACK_PATH=$(command -v wasm-pack)
if [[ "${WASM_PACK_PATH}" == "" ]]; then
cargo install wasm-pack
fi
export PROJECT_ROOT=$(git rev-parse --show-toplevel)
export CLIENT_ROOT=${PROJECT_ROOT}/web
export MODE=force
export BUILD_TYPE=--dev
export COPY_TO=${PROJECT_ROOT}/client/dist
echo $PROJECT_ROOT
echo $CLIENT_ROOT
cd ${CLIENT_ROOT}
. .env
cargo watch \
-i ${CLIENT_ROOT}/src/location.rs \
-s ${PROJECT_ROOT}/scripts/run-wasm-pack.sh \
-w ${CLIENT_ROOT}/src \
-w ${CLIENT_ROOT}/Cargo.toml \
-w ${CLIENT_ROOT}/static \
-w ${CLIENT_ROOT}/js

23
scripts/run-wasm-pack.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -ex
. ${PWD}/../.env
rm -Rf tmp
mkdir -p tmp
mkdir -p target
cd ${CLIENT_ROOT}
wasm-pack --verbose build --mode ${MODE} ${BUILD_TYPE} --out-name oswilno --out-dir ${CLIENT_ROOT}/build --target web
cd ${CLIENT_ROOT}
rm -Rf ${COPY_TO}/styles.css
rsass -t Expanded ${CLIENT_ROOT}/js/styles.css >${COPY_TO}/styles.css
cp -r ${CLIENT_ROOT}/static/* ${COPY_TO}
cp ${CLIENT_ROOT}/build/*.{js,wasm} ${COPY_TO}/
sed -i 's/\([a-z0-9]*\)Element {/\1Element extends HTMLElement {/g' ${COPY_TO}/oswilno.js
sed -i 's/constructor\(([a-z0-9 ,]*)\) {/constructor() {super();const el = this;/g' ${COPY_TO}/oswilno.js

35
server/Cargo.toml Normal file
View File

@ -0,0 +1,35 @@
[package]
name = "oswilno"
version = "0.1.0"
edition = "2021"
[dependencies]
actix = { version = "*" }
actix-cors = { version = "*" }
actix-files = { version = "*" }
actix-http = { version = "3.2.1" }
actix-identity = { version = "0.4.0" }
actix-multipart = { version = "0.4.0" }
actix-rt = { version = "*" }
actix-utils = { version = "3.0.0" }
actix-web = { version = "*" }
argon2 = { version = "0.4.1" }
askama = { version = "*", features = ["serde-json"] }
byteorder = { version = "1.4.3" }
chrono = { version = "*", features = ["serde"] }
futures = { version = "0.3.21", features = ["async-await", "std"] }
futures-util = { version = "0.3.21", features = [] }
gumdrop = { version = "*" }
password-hash = { version = "0.4.2" }
postgres = { version = "0.19.3" }
rand = { version = "0.8.5", features = [] }
serde = { version = "*", features = ["derive"] }
serde_json = { version = "*" }
sqlx = { version = "*", features = ["runtime-actix-rustls", "postgres", "uuid", "chrono"] }
sqlx-core = { version = "0.6.0" }
tracing = { version = "*" }
tracing-actix-web = { version = "*" }
tracing-subscriber = { version = "*" }
uuid = { version = "*", features = ["serde"] }
validator = { version = "0.14", features = ["derive"] }
base64 = "0.13.0"

View File

@ -23,8 +23,8 @@
<contact-info
mode="icon"
contact-id="{{contact.id}}"
content="{{h.render_contact(contact.contact_type.as_str(), contact.content.as_str())}}"
contact-type="{{contact.contact_type}}"
content="{{h.render_contact(contact.contact_type.as_str(), contact.content.as_str())}}"
></contact-info>
{% endfor %}
</contact-info-list>

View File

@ -35,14 +35,16 @@ pub enum OfferState {
Pending,
Approved,
Banned,
Finished,
}
impl OfferState {
pub fn as_str(&self) -> &str {
match self {
OfferState::Pending => "pending",
OfferState::Approved => "approved",
OfferState::Banned => "banned",
OfferState::Pending => "Pending",
OfferState::Approved => "Approved",
OfferState::Banned => "Banned",
OfferState::Finished => "Finished",
}
}
}
@ -237,13 +239,17 @@ impl<'l> sqlx::Decode<'l, Postgres> for PriceRange {
}
}
fn encode(n: i32, buf: &mut <Postgres as HasArguments<'_>>::ArgumentBuffer) {
let _ = <i32 as sqlx::Encode<'_, Postgres>>::encode(n, buf);
}
impl<'l> sqlx::Encode<'l, Postgres> for PriceRange {
fn encode_by_ref(&self, buf: &mut <Postgres as HasArguments<'l>>::ArgumentBuffer) -> IsNull {
let _ = 2i32.encode(buf);
encode(2i32, buf);
fn write_value(n: &i32, buf: &mut <Postgres as HasArguments<'_>>::ArgumentBuffer) {
let _ = 23.encode(buf);
let _ = 4.encode(buf);
let _ = n.encode(buf);
encode(23i32, buf);
encode(4i32, buf);
encode(*n, buf);
}
match self {
PriceRange::Free => {

View File

@ -3,6 +3,7 @@ use std::sync::Arc;
use actix_web::web::{Data, Form, ServiceConfig};
use actix_web::{get, post, web, HttpResponse};
use askama::*;
use serde::Deserialize;
use sqlx::PgPool;
use crate::model::db::{self, OfferState, PriceRange};
@ -170,10 +171,54 @@ async fn update_offer(
}
}
#[derive(Debug, Deserialize)]
struct AffectedOffer {
id: i32,
}
#[post("/finish")]
async fn user_finish_offer(
db: Data<PgPool>,
id: Identity,
form: Form<AffectedOffer>,
) -> 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::set_offer_state(&mut t, form.id, db::OfferState::Finished).await {
Ok(_) => {
t.commit().await.ok();
Ok(HttpResponse::SeeOther()
.append_header(("Location", "/account/offers"))
.finish())
}
Err(e) => {
dbg!(e);
let offers = offers(&mut t, account.id).await;
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(),
))
}
}
}
pub fn configure(config: &mut ServiceConfig) {
config.service(account_offers).service(
web::scope("/offers")
.service(create_offer)
.service(update_offer),
.service(update_offer)
.service(user_finish_offer),
);
}

View File

@ -33,7 +33,6 @@ async fn marketplace(req: HttpRequest, db: Data<PgPool>, id: Identity) -> Result
_ => None,
};
let offers = queries::visible_offers(&mut t).await.unwrap_or_default();
let contacts = queries::all_contacts(&mut t)
.await
.unwrap_or_default()
@ -41,7 +40,9 @@ async fn marketplace(req: HttpRequest, db: Data<PgPool>, id: Identity) -> Result
.map(Arc::new)
.collect::<Vec<_>>();
let offers = offers
let offers = queries::visible_offers(&mut t)
.await
.unwrap_or_default()
.into_iter()
.map(|o| view::Offer::from((o, &contacts)))
.collect::<Vec<_>>();

43
web/Cargo.toml Normal file
View File

@ -0,0 +1,43 @@
[package]
name = "web"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
name = "web"
path = "src/lib.rs"
[dependencies]
[dependencies.serde]
version = "1.0.140"
features = ['derive']
[dependencies.stdweb]
version = "0.4.20"
features = []
[dependencies.stdweb-derive]
version = "0.5.3"
features = []
[dependencies.stdweb-logger]
version = "0.1.1"
features = []
#[dependencies.wasm-bindgen]
#version = "0.2.81"
#features = []
#
#[dependencies.web-sys]
#version = "0.3.58"
#features = ['HtmlElement']
#
#[dependencies.js-sys]
#version = "0.3.58"
#features = []
[dependencies.wee_alloc]
version = "*"
features = ["static_array_backend"]

65
web/src/back.rs Normal file
View File

@ -0,0 +1,65 @@
use wasm_bindgen::prelude::*;
use web_sys::HtmlElement;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
pub trait Component {
fn tag_name() -> String;
fn created(&mut self) {}
fn connected_callback(&self) {}
fn disconnected_callback(&mut self) {}
fn attribute_changed(
&mut self,
_name: String,
_old_value: Option<String>,
_new_value: Option<String>,
) {
}
}
#[wasm_bindgen(extends = web_sys::HtmlElement, extends = web_sys::Object)]
pub struct FooElement {
el: HtmlElement,
}
#[wasm_bindgen]
impl FooElement {
#[wasm_bindgen]
pub fn tag_name() -> String {
"foo-element".into()
}
#[wasm_bindgen(constructor)]
pub fn new(el: HtmlElement) -> Self {
Self { el }
}
#[wasm_bindgen(js_name = connectedCallback)]
pub fn connected_callback(&self) {}
}
#[wasm_bindgen(extends = web_sys::HtmlElement, extends = web_sys::Object)]
pub struct BarElement {
el: HtmlElement,
}
#[wasm_bindgen]
impl BarElement {
#[wasm_bindgen]
pub fn tag_name() -> String {
"bar-element".into()
}
#[wasm_bindgen(constructor)]
pub fn new(el: HtmlElement) -> Self {
Self { el }
}
#[wasm_bindgen(js_name = connectedCallback)]
pub fn connected_callback(&self) {}
}

64
web/src/lib.rs Normal file
View File

@ -0,0 +1,64 @@
use stdweb::web::HtmlElement;
use stdweb::*;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
pub trait Component {
fn tag_name() -> String;
fn create(el: HtmlElement) -> Self;
fn created(&mut self) {}
fn connected_callback(&self) {}
fn disconnected_callback(&mut self) {}
fn attribute_changed(
&mut self,
_name: String,
_old_value: Option<String>,
_new_value: Option<String>,
) {
}
}
pub struct FooElement {
el: HtmlElement,
}
impl Component for FooElement {
fn tag_name() -> String {
"foo-element".into()
}
fn create(el: HtmlElement) -> Self {
Self { el }
}
fn connected_callback(&self) {}
}
pub struct BarElement {
el: HtmlElement,
}
impl Component for BarElement {
fn tag_name() -> String {
"bar-element".into()
}
fn create(el: HtmlElement) -> Self {
Self { el }
}
fn connected_callback(&self) {}
}
pub fn define() {
let tag_name = BarElement::tag_name();
js! {
customerElemenets.define(@{tag_name}, class extends HTMLElement {});
}
}