Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e5ed26f76 | ||
|
|
d97095a38d | ||
|
|
e48507901e | ||
|
|
a43ef8ec04 | ||
|
|
874f25aa80 | ||
|
|
12a730a394 | ||
|
|
bdcd41f54d | ||
|
|
96fb8eb7d3 | ||
|
|
d2c333dbd6 | ||
|
|
054f0f63ff | ||
|
|
eb05ea5994 |
Generated
+168
-8
@@ -115,6 +115,56 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "0.6.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"once_cell",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "any_ascii"
|
name = "any_ascii"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -796,6 +846,12 @@ dependencies = [
|
|||||||
"inout",
|
"inout",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@@ -1097,6 +1153,29 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
|
checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_filter"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_logger"
|
||||||
|
version = "0.11.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"env_filter",
|
||||||
|
"jiff",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@@ -1847,15 +1926,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed"
|
checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "imphnen-backend-service"
|
name = "imphnen-backend"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
"axum-test",
|
"axum-test",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"env_logger",
|
||||||
"imphnen-entities",
|
"imphnen-entities",
|
||||||
"imphnen-gateway-service",
|
"imphnen-gateway",
|
||||||
|
"imphnen-iam",
|
||||||
"imphnen-libs",
|
"imphnen-libs",
|
||||||
"imphnen-utils",
|
"imphnen-utils",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -1872,7 +1953,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "imphnen-dimentorin-service"
|
name = "imphnen-dimentorin"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@@ -1907,7 +1988,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "imphnen-gacha-service"
|
name = "imphnen-gacha"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@@ -1931,7 +2012,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "imphnen-gateway-service"
|
name = "imphnen-gateway"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@@ -1939,8 +2020,9 @@ dependencies = [
|
|||||||
"axum-test",
|
"axum-test",
|
||||||
"chrono",
|
"chrono",
|
||||||
"imphnen-entities",
|
"imphnen-entities",
|
||||||
"imphnen-iam-service",
|
"imphnen-iam",
|
||||||
"imphnen-libs",
|
"imphnen-libs",
|
||||||
|
"imphnen-middleware",
|
||||||
"imphnen-utils",
|
"imphnen-utils",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"rand 0.9.0",
|
"rand 0.9.0",
|
||||||
@@ -1956,7 +2038,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "imphnen-iam-service"
|
name = "imphnen-iam"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@@ -1994,6 +2076,33 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "imphnen-middleware"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"axum",
|
||||||
|
"axum-test",
|
||||||
|
"chrono",
|
||||||
|
"futures",
|
||||||
|
"imphnen-entities",
|
||||||
|
"imphnen-iam",
|
||||||
|
"imphnen-libs",
|
||||||
|
"imphnen-utils",
|
||||||
|
"lazy_static",
|
||||||
|
"rand 0.9.0",
|
||||||
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"surrealdb",
|
||||||
|
"tokio",
|
||||||
|
"tower",
|
||||||
|
"tower-http",
|
||||||
|
"utoipa",
|
||||||
|
"utoipa-swagger-ui",
|
||||||
|
"validator",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "imphnen-utils"
|
name = "imphnen-utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -2048,6 +2157,12 @@ version = "2.11.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
|
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.10.5"
|
version = "0.10.5"
|
||||||
@@ -2081,6 +2196,30 @@ version = "1.0.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jiff"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f02000660d30638906021176af16b17498bd0d12813dbfe7b276d8bc7f3c0806"
|
||||||
|
dependencies = [
|
||||||
|
"jiff-static",
|
||||||
|
"log",
|
||||||
|
"portable-atomic",
|
||||||
|
"portable-atomic-util",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jiff-static"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3c30758ddd7188629c6713fc45d1188af4f44c90582311d0c8d8c9907f60c48"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.100",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.77"
|
version = "0.3.77"
|
||||||
@@ -2817,6 +2956,21 @@ version = "0.3.32"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic-util"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
|
||||||
|
dependencies = [
|
||||||
|
"portable-atomic",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "powerfmt"
|
name = "powerfmt"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -4265,7 +4419,7 @@ dependencies = [
|
|||||||
"axum-test",
|
"axum-test",
|
||||||
"chrono",
|
"chrono",
|
||||||
"imphnen-entities",
|
"imphnen-entities",
|
||||||
"imphnen-iam-service",
|
"imphnen-iam",
|
||||||
"imphnen-libs",
|
"imphnen-libs",
|
||||||
"imphnen-utils",
|
"imphnen-utils",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -4713,6 +4867,12 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utoipa"
|
name = "utoipa"
|
||||||
version = "5.3.1"
|
version = "5.3.1"
|
||||||
|
|||||||
+13
-1
@@ -1,10 +1,19 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"imphnen-*",
|
|
||||||
"tests",
|
"tests",
|
||||||
|
"imphnen-iam",
|
||||||
|
"imphnen-libs",
|
||||||
|
"imphnen-utils",
|
||||||
|
"imphnen-gacha",
|
||||||
|
"imphnen-gateway",
|
||||||
|
"imphnen-backend",
|
||||||
|
"imphnen-entities",
|
||||||
|
"imphnen-dimentorin",
|
||||||
|
"imphnen-middleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
axum = { version = "0.8.1", features = ["multipart"] }
|
axum = { version = "0.8.1", features = ["multipart"] }
|
||||||
log = "0.4.25"
|
log = "0.4.25"
|
||||||
@@ -27,6 +36,9 @@ lazy_static = "1.4.0"
|
|||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
axum-test = "17.2.0"
|
axum-test = "17.2.0"
|
||||||
fancy-regex = "0.14.0"
|
fancy-regex = "0.14.0"
|
||||||
|
futures = "0.3.31"
|
||||||
|
tower = "0.5.2"
|
||||||
|
env_logger = "0.11.8"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = "fat"
|
lto = "fat"
|
||||||
|
|||||||
@@ -1,78 +1,107 @@
|
|||||||
# Axum SurrealDB Boilerplate
|
# IMPHNEN Backend Service
|
||||||
|
|
||||||
## Features
|
<p align="center">
|
||||||
|
<img src="docs/logo.svg" alt="IMPHNEN">
|
||||||
|
</p>
|
||||||
|
|
||||||
- **Authentication Ready**: Preconfigured authentication and middleware for secure API access.
|
This repository serves as the **monorepo** for all backend services of IMPHNEN. It encompasses several main services:
|
||||||
- **Database Integration**: SurrealDB seamlessly integrated as an Axum Extension.
|
|
||||||
- **CORS Handling**: Fine-tuned CORS management with Tower HTTP `CorsLayer`.
|
|
||||||
- **API Documentation**: Fully documented with OpenAPI and Swagger UI.
|
|
||||||
- **Optimized for Performance**: Asynchronous, lightweight, and scalable architecture.
|
|
||||||
|
|
||||||
## Prerequisites
|
1. **Core Service** - Provides fundamental functionalities and shared resources for other services.
|
||||||
|
2. **IAM Service** - Handles identity and access management across IMPHNEN applications.
|
||||||
|
3. **CMS Service** - Supports the cms services by IMPHNEN [Landing Page website](https://imphnen.dev/).
|
||||||
|
4. **Gacha Service** - Supports the gacha services by IMPHNEN [Gacha website](https://gacha.imphnen.dev/).
|
||||||
|
5. **Dimentorin Service** - Supports the mentoring services by IMPHNEN [Dimentorin website](https://dimentorin.imphnen.dev/).
|
||||||
|
6. **Gateway Service** - Acts as the API gateway, routing requests to appropriate services.
|
||||||
|
|
||||||
- **Rust**: Install Rust from [rust-lang.org](https://www.rust-lang.org/).
|
## How to Install
|
||||||
- **Database**: Set up a SurrealDB instance and configure connection details.
|
|
||||||
- **Docker**: Required for containerized deployment, install from [docker.com](https://www.docker.com/).
|
|
||||||
- **Nix (Optional)**: For reproducible builds, install from [nixos.org](https://nixos.org/).
|
|
||||||
|
|
||||||
## Getting Started
|
1. **Clone the repository**:
|
||||||
|
|
||||||
1. **Clone the Repository**:
|
```sh
|
||||||
|
git clone https://github.com/IMPHNEN/imphnen-backend-service.git
|
||||||
|
cd imphnen-backend-service
|
||||||
|
```
|
||||||
|
|
||||||
- `git clone https://github.com/maulanasdqn/axum-surrealdb-boilerplate`
|
2. **Set up the environment**:
|
||||||
|
|
||||||
2. **Set Up Environment Variables**:
|
- Copy the example environment files:
|
||||||
|
|
||||||
- Copy `.env.example` and rename it to `.env`
|
```sh
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
- **Windows**: Run the script: `./apply-env.ps1`
|
if you use windows based system
|
||||||
- **Unix-based systems (Linux, macOS, BSD)**: Run the script: `./apply-env.sh`
|
|
||||||
|
|
||||||
3. **Install Dependencies**:
|
```sh
|
||||||
|
./apply-env.ps1
|
||||||
|
```
|
||||||
|
|
||||||
- `cargo install .`
|
if you use unix based system
|
||||||
|
|
||||||
4. **Setup Database**:
|
```sh
|
||||||
|
sh apply-env.sh
|
||||||
|
```
|
||||||
|
|
||||||
- Install the surrealDB
|
- Modify the `.env` files with your specific configuration settings.
|
||||||
- **Windows**: `iwr https://windows.surrealdb.com -useb | iex`
|
|
||||||
- **Unix-based systems (Linux, macOS, BSD)**: `curl -sSf https://install.surrealdb.com | sh`
|
|
||||||
- Start the database `surreal start --user root --pass root`
|
|
||||||
|
|
||||||
5. **Start the Server**:
|
3. **Install dependencies**:
|
||||||
|
|
||||||
- Install Cargo Watch `cargo install cargo-watch`
|
Ensure you have [Rust](https://www.rust-lang.org/) installed. Then, run:
|
||||||
- Run it with cargo watch `cargo watch -x run`
|
|
||||||
|
|
||||||
The API will be available at `http://localhost:3000/docs`.
|
```sh
|
||||||
|
cargo build
|
||||||
|
```
|
||||||
|
|
||||||
## Docker
|
## How to Run
|
||||||
|
|
||||||
1. **Build the Docker Image**:
|
### Development
|
||||||
|
|
||||||
2. **Run the Docker Container**:
|
To run the services in development mode:
|
||||||
|
|
||||||
The API will be accessible at `http://localhost:3000/docs`.
|
1. **Start the database and other dependencies** using Docker Compose:
|
||||||
|
|
||||||
## Using Nix as Builder (Optional)
|
```sh
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
1. **Install Nix**:
|
2. **Run the desired service**. For example, to run the Core Service:
|
||||||
|
|
||||||
2. **Enter Nix Shell or Use Nix Flakes**:
|
```sh
|
||||||
|
cargo run -p imphnen-core-service --bin api
|
||||||
|
```
|
||||||
|
|
||||||
3. **Build the Project**:
|
### Production
|
||||||
|
|
||||||
4. **Run the Server**:
|
For production deployment:
|
||||||
|
|
||||||
## Contributing
|
1. **Build the Docker image**:
|
||||||
|
|
||||||
Contributions are welcome! Fork the repository and create a pull request with your improvements.
|
```sh
|
||||||
|
docker build -t imphnen-backend-service .
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
2. **Run the Docker container**:
|
||||||
|
|
||||||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
```sh
|
||||||
|
docker run -d --env-file .env -p 8080:8080 imphnen-backend-service
|
||||||
|
```
|
||||||
|
|
||||||
## Acknowledgements
|
Adjust the port and environment variables as needed.
|
||||||
|
|
||||||
- [Axum](https://github.com/tokio-rs/axum)
|
## How to Contribute
|
||||||
- [SurrealDB](https://github.com/surrealdb/surrealdb)
|
|
||||||
|
1. **Fork the repository** and clone it locally.
|
||||||
|
2. **Create a new branch** for your feature or fix:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git checkout -b feat/your-feature-name
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Make your changes**, commit them, and push to your forked repository.
|
||||||
|
4. **Create a pull request** to the `develop` branch of this repository.
|
||||||
|
|
||||||
|
If you encounter any issues or have questions, feel free to create a new issue in the repository.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
_Note: For detailed API documentation, please refer to our [API Docs](https://api.imphnen.dev/docs)._
|
||||||
|
|||||||
@@ -6,3 +6,11 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "${PORT}:${PORT}"
|
- "${PORT}:${PORT}"
|
||||||
env_file: ".env"
|
env_file: ".env"
|
||||||
|
depends_on:
|
||||||
|
- surrealdb
|
||||||
|
|
||||||
|
surrealdb:
|
||||||
|
image: surrealdb/surrealdb:latest
|
||||||
|
command: start --log trace --user root --pass root
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 351 KiB |
@@ -0,0 +1,27 @@
|
|||||||
|
[package]
|
||||||
|
name = "imphnen-backend"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
imphnen-libs = { version = "0.1.0", path = "../imphnen-libs" }
|
||||||
|
imphnen-utils = { version = "0.1.0", path = "../imphnen-utils" }
|
||||||
|
imphnen-gateway = { version = "0.1.0", path = "../imphnen-gateway" }
|
||||||
|
imphnen-entities = { version = "0.1.0", path = "../imphnen-entities" }
|
||||||
|
imphnen-iam = { version = "0.1.0", path = "../imphnen-iam" }
|
||||||
|
axum.workspace = true
|
||||||
|
serde.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
utoipa.workspace = true
|
||||||
|
lazy_static.workspace = true
|
||||||
|
regex.workspace = true
|
||||||
|
validator.workspace = true
|
||||||
|
axum-test.workspace = true
|
||||||
|
surrealdb.workspace = true
|
||||||
|
rand.workspace = true
|
||||||
|
tokio.workspace = true
|
||||||
|
chrono.workspace = true
|
||||||
|
anyhow.workspace = true
|
||||||
|
tower-http.workspace = true
|
||||||
|
utoipa-swagger-ui.workspace = true
|
||||||
|
env_logger.workspace = true
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
use imphnen_gateway_service::gateway_service;
|
use env_logger;
|
||||||
|
use imphnen_gateway::gateway_service;
|
||||||
use imphnen_libs::axum_init;
|
use imphnen_libs::axum_init;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
env_logger::init();
|
||||||
axum_init(|surrealdb_ws, surrealdb_mem| async {
|
axum_init(|surrealdb_ws, surrealdb_mem| async {
|
||||||
gateway_service(surrealdb_ws, surrealdb_mem).await
|
gateway_service(surrealdb_ws, surrealdb_mem).await
|
||||||
})
|
})
|
||||||
+13
-13
@@ -25,8 +25,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
(
|
(
|
||||||
"0269ed71-0ae0-4c43-ad29-e3d861d8f9a0",
|
"0269ed71-0ae0-4c43-ad29-e3d861d8f9a0",
|
||||||
"Create Permissions",
|
"Create Permissions",
|
||||||
None,
|
Some("2025-01-29T05:11:01.265+00"),
|
||||||
None,
|
Some("2025-01-29T05:11:01.265001+00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"299cb4d5-6556-4cc9-b6c1-32e6d31e0f9b",
|
"299cb4d5-6556-4cc9-b6c1-32e6d31e0f9b",
|
||||||
@@ -37,20 +37,20 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
(
|
(
|
||||||
"319ee593-ff0a-4f29-bbaf-9feb3174a3a2",
|
"319ee593-ff0a-4f29-bbaf-9feb3174a3a2",
|
||||||
"Create Roles",
|
"Create Roles",
|
||||||
None,
|
Some("2025-01-29T05:11:01.265+00"),
|
||||||
None,
|
Some("2025-01-29T05:11:01.265001+00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"319ee593-ff0a-4f29-bbaf-9feb3174a3a6",
|
"319ee593-ff0a-4f29-bbaf-9feb3174a3a6",
|
||||||
"Read Detail Users",
|
"Read Detail Users",
|
||||||
None,
|
Some("2025-01-29T05:11:01.265+00"),
|
||||||
None,
|
Some("2025-01-29T05:11:01.265001+00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"35b0d992-65c8-4b62-b030-e6e0320e4048",
|
"35b0d992-65c8-4b62-b030-e6e0320e4048",
|
||||||
"Delete Roles",
|
"Delete Roles",
|
||||||
None,
|
Some("2025-01-29T05:34:40.621554+00"),
|
||||||
None,
|
Some("2025-01-29T05:34:40.621555+00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"4da8b434-89f9-4d91-85ae-eebd63cdbeda",
|
"4da8b434-89f9-4d91-85ae-eebd63cdbeda",
|
||||||
@@ -91,8 +91,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
(
|
(
|
||||||
"9164ca6e-c7e3-4238-a15f-f36ab9577e7e",
|
"9164ca6e-c7e3-4238-a15f-f36ab9577e7e",
|
||||||
"Read List Roles",
|
"Read List Roles",
|
||||||
None,
|
Some("2025-01-29T05:34:40.621554+00"),
|
||||||
None,
|
Some("2025-01-29T05:34:40.621555+00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"96df0689-2ae9-4894-bf00-837c19415e5c",
|
"96df0689-2ae9-4894-bf00-837c19415e5c",
|
||||||
@@ -109,8 +109,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
(
|
(
|
||||||
"a00d5608-4c48-4542-845c-dfe004687022",
|
"a00d5608-4c48-4542-845c-dfe004687022",
|
||||||
"Update Roles",
|
"Update Roles",
|
||||||
None,
|
Some("2025-01-29T05:34:40.621554+00"),
|
||||||
None,
|
Some("2025-01-29T05:34:40.621555+00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"b2dc3928-86ba-4c59-a03d-0b57d5183ebc",
|
"b2dc3928-86ba-4c59-a03d-0b57d5183ebc",
|
||||||
@@ -140,6 +140,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
.await?;
|
.await?;
|
||||||
println!("✅ Inserted: {}", name);
|
println!("✅ Inserted: {}", name);
|
||||||
}
|
}
|
||||||
println!("✅ Semua permissions berhasil disimpan ke SurrealDB!");
|
println!("✅ All Permissions seeded");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -65,6 +65,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
.await?;
|
.await?;
|
||||||
println!("✅ Inserted role: {}", name);
|
println!("✅ Inserted role: {}", name);
|
||||||
}
|
}
|
||||||
println!("✅ Semua role berhasil disimpan ke SurrealDB!");
|
println!("✅ All Roles seeded");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
use imphnen_iam::{get_iso_date, make_thing, Env};
|
||||||
|
use std::error::Error;
|
||||||
|
use surrealdb::{engine::remote::ws::Ws, opt::auth::Root, Surreal};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
let env = Env::new();
|
||||||
|
let db = Surreal::new::<Ws>(env.surrealdb_url).await?;
|
||||||
|
|
||||||
|
db.signin(Root {
|
||||||
|
username: &env.surrealdb_username,
|
||||||
|
password: &env.surrealdb_password,
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
db.use_ns(env.surrealdb_namespace)
|
||||||
|
.use_db(env.surrealdb_dbname)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let admin_permissions = vec![
|
||||||
|
"023e2dfe-93c3-4008-94a8-b5dff403f73b",
|
||||||
|
"0269ed71-0ae0-4c43-ad29-e3d861d8f9a0",
|
||||||
|
"299cb4d5-6556-4cc9-b6c1-32e6d31e0f9b",
|
||||||
|
"319ee593-ff0a-4f29-bbaf-9feb3174a3a2",
|
||||||
|
"319ee593-ff0a-4f29-bbaf-9feb3174a3a6",
|
||||||
|
"35b0d992-65c8-4b62-b030-e6e0320e4048",
|
||||||
|
"4da8b434-89f9-4d91-85ae-eebd63cdbeda",
|
||||||
|
"73888d18-b3e9-4f62-95a5-ba2c0d69fccb",
|
||||||
|
"7c15e31d-36e2-49f9-97db-138c03fb0cf6",
|
||||||
|
"7d4b1379-4960-416a-b045-98cd82c0cac9",
|
||||||
|
"8195eeb8-e64f-4172-aa57-596492c84a72",
|
||||||
|
"81eba91d-b8ab-44b9-bbfe-4e6da2f98952",
|
||||||
|
"9164ca6e-c7e3-4238-a15f-f36ab9577e7e",
|
||||||
|
"96df0689-2ae9-4894-bf00-837c19415e5c",
|
||||||
|
"98b3dc4c-0124-461f-afcd-166637c5e6e8",
|
||||||
|
"a00d5608-4c48-4542-845c-dfe004687022",
|
||||||
|
"b2dc3928-86ba-4c59-a03d-0b57d5183ebc",
|
||||||
|
"dad435cf-042c-41bd-a946-cea61ed2ffbc",
|
||||||
|
];
|
||||||
|
|
||||||
|
let admin_role_id = "f6b03f25-e416-4893-ac88-caaa690afb07";
|
||||||
|
|
||||||
|
let permission_refs_admin: Vec<_> = admin_permissions
|
||||||
|
.into_iter()
|
||||||
|
.map(|perm_id| make_thing("app_permissions", perm_id))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
db.query("UPDATE type::thing('app_roles', $role_id) SET permissions = $permissions, updated_at = $updated_at WHERE is_deleted = false")
|
||||||
|
.bind(("role_id", admin_role_id))
|
||||||
|
.bind(("permissions", permission_refs_admin))
|
||||||
|
.bind(("updated_at", get_iso_date()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
println!("✅ All permissions successfully added to each role");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,31 +1,8 @@
|
|||||||
|
use imphnen_iam::UsersSchema;
|
||||||
use imphnen_utils::{get_iso_date, hash_password, Env};
|
use imphnen_utils::{get_iso_date, hash_password, Env};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use surrealdb::{engine::remote::ws::Ws, opt::auth::Root, sql::Thing, Surreal};
|
use surrealdb::{engine::remote::ws::Ws, opt::auth::Root, sql::Thing, Surreal};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct UsersSchema {
|
|
||||||
pub id: Thing,
|
|
||||||
pub fullname: String,
|
|
||||||
pub email: String,
|
|
||||||
pub password: String,
|
|
||||||
pub avatar: Option<String>,
|
|
||||||
pub phone_number: String,
|
|
||||||
pub referral_code: Option<String>,
|
|
||||||
pub referred_by: Option<String>,
|
|
||||||
pub identity_number: Option<String>,
|
|
||||||
pub is_active: bool,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub student_type: String,
|
|
||||||
pub religion: Option<String>,
|
|
||||||
pub gender: Option<String>,
|
|
||||||
pub birthdate: Option<String>,
|
|
||||||
pub is_profile_completed: bool,
|
|
||||||
pub role: Thing,
|
|
||||||
pub created_at: String,
|
|
||||||
pub updated_at: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let env = Env::new();
|
let env = Env::new();
|
||||||
@@ -68,16 +45,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
password: hash_password("password").unwrap(),
|
password: hash_password("password").unwrap(),
|
||||||
avatar: None,
|
avatar: None,
|
||||||
phone_number: "081234567890".into(),
|
phone_number: "081234567890".into(),
|
||||||
referral_code: None,
|
|
||||||
referred_by: None,
|
|
||||||
identity_number: None,
|
|
||||||
is_active: true,
|
is_active: true,
|
||||||
is_deleted: false,
|
is_deleted: false,
|
||||||
student_type: "TNI".into(),
|
|
||||||
religion: None,
|
|
||||||
gender: None,
|
gender: None,
|
||||||
birthdate: None,
|
birthdate: None,
|
||||||
is_profile_completed: false,
|
|
||||||
role: Thing::from(("app_roles", role_id)),
|
role: Thing::from(("app_roles", role_id)),
|
||||||
created_at: get_iso_date(),
|
created_at: get_iso_date(),
|
||||||
updated_at: get_iso_date(),
|
updated_at: get_iso_date(),
|
||||||
@@ -90,6 +61,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
println!("✅ Inserted user: {} ({})", fullname, email);
|
println!("✅ Inserted user: {} ({})", fullname, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("✅ Semua users berhasil disimpan ke SurrealDB!");
|
println!("✅ All Users seeded");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use imphnen_gateway_service::gateway_service;
|
use imphnen_gateway::gateway_service;
|
||||||
use imphnen_libs::axum_init;
|
use imphnen_libs::axum_init;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
use imphnen_utils::{get_iso_date, make_thing, Env};
|
|
||||||
use std::error::Error;
|
|
||||||
use surrealdb::{engine::remote::ws::Ws, opt::auth::Root, Surreal};
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
|
||||||
let env = Env::new();
|
|
||||||
let db = Surreal::new::<Ws>(env.surrealdb_url).await?;
|
|
||||||
|
|
||||||
db.signin(Root {
|
|
||||||
username: &env.surrealdb_username,
|
|
||||||
password: &env.surrealdb_password,
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
db.use_ns(env.surrealdb_namespace)
|
|
||||||
.use_db(env.surrealdb_dbname)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let role_permissions = vec![
|
|
||||||
(
|
|
||||||
"50133429-f4b1-4249-9f97-7b86e6ee9d86", // Staf
|
|
||||||
vec![
|
|
||||||
"7c15e31d-36e2-49f9-97db-138c03fb0cf6", // Read List Users
|
|
||||||
"319ee593-ff0a-4f29-bbaf-9feb3174a3a6", // Read Detail Users
|
|
||||||
],
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"f6b03f25-e416-4893-ac88-caaa690afb07", // Admin
|
|
||||||
vec![
|
|
||||||
"023e2dfe-93c3-4008-94a8-b5dff403f73b", // Create Users
|
|
||||||
"96df0689-2ae9-4894-bf00-837c19415e5c", // Delete Users
|
|
||||||
"98b3dc4c-0124-461f-afcd-166637c5e6e8", // Update Users
|
|
||||||
"319ee593-ff0a-4f29-bbaf-9feb3174a3a6", // Read Detail Users
|
|
||||||
"7c15e31d-36e2-49f9-97db-138c03fb0cf6", // Read List Users
|
|
||||||
"9164ca6e-c7e3-4238-a15f-f36ab9577e7e", // Read List Roles
|
|
||||||
"319ee593-ff0a-4f29-bbaf-9feb3174a3a2", // Create Roles
|
|
||||||
"a00d5608-4c48-4542-845c-dfe004687022", // Update Roles
|
|
||||||
"35b0d992-65c8-4b62-b030-e6e0320e4048", // Delete Roles
|
|
||||||
],
|
|
||||||
),
|
|
||||||
];
|
|
||||||
for (role_id, permission_ids) in role_permissions {
|
|
||||||
let permission_refs: Vec<_> = permission_ids
|
|
||||||
.into_iter()
|
|
||||||
.map(|perm_id| make_thing("app_permissions", perm_id))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
db.query("UPDATE type::thing('app_roles', $role_id) SET permissions = $permissions, updated_at = $updated_at")
|
|
||||||
.bind(("role_id", role_id))
|
|
||||||
.bind(("permissions", permission_refs))
|
|
||||||
.bind(("updated_at", get_iso_date()))
|
|
||||||
.await?;
|
|
||||||
println!("✅ Updated permissions for role ID: {}", role_id);
|
|
||||||
}
|
|
||||||
println!("✅ Semua roles telah diperbarui dengan permissions di SurrealDB!");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "imphnen-iam-service"
|
name = "imphnen-dimentorin"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
imphnen-entities = { version = "0.1.0", path = "../imphnen-entities" }
|
|
||||||
imphnen-libs = { version = "0.1.0", path = "../imphnen-libs" }
|
imphnen-libs = { version = "0.1.0", path = "../imphnen-libs" }
|
||||||
imphnen-utils = { version = "0.1.0", path = "../imphnen-utils" }
|
imphnen-utils = { version = "0.1.0", path = "../imphnen-utils" }
|
||||||
|
imphnen-entities = { version = "0.1.0", path = "../imphnen-entities" }
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
@@ -6,6 +6,6 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
surrealdb = { workspace = true, features = ["kv-mem"] }
|
|
||||||
thiserror.workspace = true
|
|
||||||
utoipa.workspace = true
|
utoipa.workspace = true
|
||||||
|
surrealdb.workspace = true
|
||||||
|
thiserror.workspace = true
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use surrealdb::sql::Thing;
|
|
||||||
use utoipa::ToSchema;
|
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
|
||||||
pub struct GachaItemRequestDto {
|
|
||||||
#[validate(length(min = 1, message = "Item name must not be empty"))]
|
|
||||||
pub name: String,
|
|
||||||
#[validate(length(min = 1, message = "Image URL must not be empty"))]
|
|
||||||
pub image_url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
|
||||||
pub struct GachaClaimRequestDto {
|
|
||||||
#[validate(length(min = 1, message = "User ID must not be empty"))]
|
|
||||||
pub user_id: String,
|
|
||||||
|
|
||||||
#[validate(length(min = 1, message = "Item ID must not be empty"))]
|
|
||||||
pub item_id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
|
||||||
pub struct GachaRollRequestDto {
|
|
||||||
#[validate(length(min = 1, message = "Item ID must not be empty"))]
|
|
||||||
pub item_id: String,
|
|
||||||
|
|
||||||
#[validate(range(min = 1, message = "Weight must be greater than zero"))]
|
|
||||||
pub weight: f32,
|
|
||||||
|
|
||||||
#[validate(range(min = 1, message = "Quantity must be at least 1"))]
|
|
||||||
pub quantity: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
|
||||||
pub struct GachaItemDto {
|
|
||||||
pub id: String,
|
|
||||||
pub name: String,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct GachaItemDtoRaw {
|
|
||||||
pub id: Thing,
|
|
||||||
pub name: String,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
|
||||||
pub struct GachaClaimDto {
|
|
||||||
pub id: String,
|
|
||||||
pub user: String,
|
|
||||||
pub item: String,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct GachaClaimDtoRaw {
|
|
||||||
pub id: Thing,
|
|
||||||
pub user: Thing,
|
|
||||||
pub item: Thing,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
|
||||||
pub struct GachaRollDto {
|
|
||||||
pub id: String,
|
|
||||||
pub item: String,
|
|
||||||
pub weight: String,
|
|
||||||
pub quantity: i32,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct GachaRollDtoRaw {
|
|
||||||
pub id: Thing,
|
|
||||||
pub item: Thing,
|
|
||||||
pub weight: String,
|
|
||||||
pub quantity: i32,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
use crate::{make_thing, ResourceEnum};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use surrealdb::{sql::Thing, Uuid};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct GachaItemSchema {
|
|
||||||
pub id: Thing,
|
|
||||||
pub name: String,
|
|
||||||
pub image_url: String,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for GachaItemSchema {
|
|
||||||
fn default() -> Self {
|
|
||||||
GachaItemSchema {
|
|
||||||
id: make_thing(
|
|
||||||
&ResourceEnum::GachaItems.to_string(),
|
|
||||||
&Uuid::new_v4().to_string(),
|
|
||||||
),
|
|
||||||
name: String::new(),
|
|
||||||
image_url: String::new(),
|
|
||||||
is_deleted: false,
|
|
||||||
created_at: None,
|
|
||||||
updated_at: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct GachaClaimSchema {
|
|
||||||
pub id: Thing,
|
|
||||||
pub user: Thing,
|
|
||||||
pub item: Thing,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for GachaClaimSchema {
|
|
||||||
fn default() -> Self {
|
|
||||||
GachaClaimSchema {
|
|
||||||
id: make_thing(
|
|
||||||
&ResourceEnum::GachaClaims.to_string(),
|
|
||||||
&Uuid::new_v4().to_string(),
|
|
||||||
),
|
|
||||||
user: make_thing(
|
|
||||||
&ResourceEnum::Users.to_string(),
|
|
||||||
&Uuid::new_v4().to_string(),
|
|
||||||
),
|
|
||||||
item: make_thing(
|
|
||||||
&ResourceEnum::GachaItems.to_string(),
|
|
||||||
&Uuid::new_v4().to_string(),
|
|
||||||
),
|
|
||||||
is_deleted: false,
|
|
||||||
created_at: None,
|
|
||||||
updated_at: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct GachaRollSchema {
|
|
||||||
pub id: Thing,
|
|
||||||
pub item: Thing,
|
|
||||||
pub weight: f32,
|
|
||||||
pub quantity: i32,
|
|
||||||
pub is_deleted: bool,
|
|
||||||
pub created_at: Option<String>,
|
|
||||||
pub updated_at: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for GachaRollSchema {
|
|
||||||
fn default() -> Self {
|
|
||||||
GachaRollSchema {
|
|
||||||
id: make_thing(
|
|
||||||
&ResourceEnum::GachaRolls.to_string(),
|
|
||||||
&Uuid::new_v4().to_string(),
|
|
||||||
),
|
|
||||||
item: make_thing(
|
|
||||||
&ResourceEnum::GachaItems.to_string(),
|
|
||||||
&Uuid::new_v4().to_string(),
|
|
||||||
),
|
|
||||||
weight: 0.2,
|
|
||||||
quantity: 2,
|
|
||||||
is_deleted: false,
|
|
||||||
created_at: None,
|
|
||||||
updated_at: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
pub mod gacha_dto;
|
|
||||||
pub mod gacha_repository;
|
|
||||||
pub mod gacha_schema;
|
|
||||||
|
|
||||||
pub use gacha_repository::*;
|
|
||||||
pub use gacha_schema::*;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
pub mod gacha;
|
|
||||||
pub use gacha::*;
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "imphnen-gacha-service"
|
name = "imphnen-gacha"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
imphnen-entities = { version = "0.1.0", path = "../imphnen-entities" }
|
|
||||||
imphnen-libs = { version = "0.1.0", path = "../imphnen-libs" }
|
imphnen-libs = { version = "0.1.0", path = "../imphnen-libs" }
|
||||||
imphnen-utils = { version = "0.1.0", path = "../imphnen-utils" }
|
imphnen-utils = { version = "0.1.0", path = "../imphnen-utils" }
|
||||||
|
imphnen-entities = { version = "0.1.0", path = "../imphnen-entities" }
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use surrealdb::sql::Thing;
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
||||||
|
pub struct GachaClaimRequestDto {
|
||||||
|
#[validate(length(min = 1, message = "User ID must not be empty"))]
|
||||||
|
pub user_id: String,
|
||||||
|
|
||||||
|
#[validate(length(min = 1, message = "Item ID must not be empty"))]
|
||||||
|
pub item_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||||
|
pub struct GachaClaimDto {
|
||||||
|
pub id: String,
|
||||||
|
pub user: String,
|
||||||
|
pub item: String,
|
||||||
|
pub is_deleted: bool,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
pub updated_at: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct GachaClaimDtoRaw {
|
||||||
|
pub id: Thing,
|
||||||
|
pub user: Thing,
|
||||||
|
pub item: Thing,
|
||||||
|
pub is_deleted: bool,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
pub updated_at: Option<String>,
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
use super::GachaClaimSchema;
|
||||||
|
use crate::{AppState, ResourceEnum};
|
||||||
|
use anyhow::{Result, bail};
|
||||||
|
|
||||||
|
pub struct GachaClaimRepository<'a> {
|
||||||
|
state: &'a AppState,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> GachaClaimRepository<'a> {
|
||||||
|
pub fn new(state: &'a AppState) -> Self {
|
||||||
|
Self { state }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn query_gacha_claim_by_id(
|
||||||
|
&self,
|
||||||
|
id: String,
|
||||||
|
) -> Result<GachaClaimSchema> {
|
||||||
|
let db = &self.state.surrealdb_ws;
|
||||||
|
let result: Option<GachaClaimSchema> = db
|
||||||
|
.select((ResourceEnum::GachaClaims.to_string(), id.clone()))
|
||||||
|
.await?;
|
||||||
|
match result {
|
||||||
|
Some(claim) if !claim.is_deleted => Ok(claim),
|
||||||
|
_ => bail!("Gacha Claim not found"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn query_create_gacha_claim(
|
||||||
|
&self,
|
||||||
|
data: GachaClaimSchema,
|
||||||
|
) -> Result<String> {
|
||||||
|
let db = &self.state.surrealdb_ws;
|
||||||
|
let record: Option<GachaClaimSchema> = db
|
||||||
|
.create(ResourceEnum::GachaClaims.to_string())
|
||||||
|
.content(data)
|
||||||
|
.await?;
|
||||||
|
match record {
|
||||||
|
Some(_) => Ok("Success create Gacha Claim".into()),
|
||||||
|
None => bail!("Failed to create Gacha Claim"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
use crate::{ResourceEnum, make_thing};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use surrealdb::{Uuid, sql::Thing};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct GachaClaimSchema {
|
||||||
|
pub id: Thing,
|
||||||
|
pub user: Thing,
|
||||||
|
pub item: Thing,
|
||||||
|
pub is_deleted: bool,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
pub updated_at: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for GachaClaimSchema {
|
||||||
|
fn default() -> Self {
|
||||||
|
GachaClaimSchema {
|
||||||
|
id: make_thing(
|
||||||
|
&ResourceEnum::GachaClaims.to_string(),
|
||||||
|
&Uuid::new_v4().to_string(),
|
||||||
|
),
|
||||||
|
user: make_thing(
|
||||||
|
&ResourceEnum::Users.to_string(),
|
||||||
|
&Uuid::new_v4().to_string(),
|
||||||
|
),
|
||||||
|
item: make_thing(
|
||||||
|
&ResourceEnum::GachaItems.to_string(),
|
||||||
|
&Uuid::new_v4().to_string(),
|
||||||
|
),
|
||||||
|
is_deleted: false,
|
||||||
|
created_at: None,
|
||||||
|
updated_at: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pub mod gacha_claim_dto;
|
||||||
|
pub mod gacha_claim_repository;
|
||||||
|
pub mod gacha_claim_schema;
|
||||||
|
|
||||||
|
pub use gacha_claim_dto::*;
|
||||||
|
pub use gacha_claim_repository::*;
|
||||||
|
pub use gacha_claim_schema::*;
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use surrealdb::sql::Thing;
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
||||||
|
pub struct GachaItemRequestDto {
|
||||||
|
#[validate(length(min = 1, message = "Item name must not be empty"))]
|
||||||
|
pub name: String,
|
||||||
|
#[validate(length(min = 1, message = "Image URL must not be empty"))]
|
||||||
|
pub image_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||||
|
pub struct GachaItemDto {
|
||||||
|
pub id: String,
|
||||||
|
pub name: String,
|
||||||
|
pub is_deleted: bool,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
pub updated_at: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct GachaItemDtoRaw {
|
||||||
|
pub id: Thing,
|
||||||
|
pub name: String,
|
||||||
|
pub is_deleted: bool,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
pub updated_at: Option<String>,
|
||||||
|
}
|
||||||
+6
-58
@@ -1,15 +1,15 @@
|
|||||||
use super::{GachaClaimSchema, GachaItemSchema, GachaRollSchema};
|
use super::GachaItemSchema;
|
||||||
use crate::{
|
use crate::{
|
||||||
AppState, MetaRequestDto, ResourceEnum, ResponseListSuccessDto, get_id,
|
AppState, MetaRequestDto, ResourceEnum, ResponseListSuccessDto, get_id,
|
||||||
make_thing, query_list_with_meta,
|
make_thing, query_list_with_meta,
|
||||||
};
|
};
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
|
|
||||||
pub struct GachaRepository<'a> {
|
pub struct GachaItemRepository<'a> {
|
||||||
state: &'a AppState,
|
state: &'a AppState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GachaRepository<'a> {
|
impl<'a> GachaItemRepository<'a> {
|
||||||
pub fn new(state: &'a AppState) -> Self {
|
pub fn new(state: &'a AppState) -> Self {
|
||||||
Self { state }
|
Self { state }
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,9 @@ impl<'a> GachaRepository<'a> {
|
|||||||
&meta,
|
&meta,
|
||||||
conditions,
|
conditions,
|
||||||
None,
|
None,
|
||||||
|
"name",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -97,59 +100,4 @@ impl<'a> GachaRepository<'a> {
|
|||||||
None => bail!("Failed to delete Gacha Item"),
|
None => bail!("Failed to delete Gacha Item"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn query_gacha_claim_by_id(
|
|
||||||
&self,
|
|
||||||
id: String,
|
|
||||||
) -> Result<GachaClaimSchema> {
|
|
||||||
let db = &self.state.surrealdb_ws;
|
|
||||||
let result: Option<GachaClaimSchema> = db
|
|
||||||
.select((ResourceEnum::GachaClaims.to_string(), id.clone()))
|
|
||||||
.await?;
|
|
||||||
match result {
|
|
||||||
Some(claim) if !claim.is_deleted => Ok(claim),
|
|
||||||
_ => bail!("Gacha Claim not found"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn query_create_gacha_claim(
|
|
||||||
&self,
|
|
||||||
data: GachaClaimSchema,
|
|
||||||
) -> Result<String> {
|
|
||||||
let db = &self.state.surrealdb_ws;
|
|
||||||
let record: Option<GachaClaimSchema> = db
|
|
||||||
.create(ResourceEnum::GachaClaims.to_string())
|
|
||||||
.content(data)
|
|
||||||
.await?;
|
|
||||||
match record {
|
|
||||||
Some(_) => Ok("Success create Gacha Claim".into()),
|
|
||||||
None => bail!("Failed to create Gacha Claim"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn query_gacha_roll_by_id(&self, id: String) -> Result<GachaRollSchema> {
|
|
||||||
let db = &self.state.surrealdb_ws;
|
|
||||||
let result: Option<GachaRollSchema> = db
|
|
||||||
.select((ResourceEnum::GachaRolls.to_string(), id.clone()))
|
|
||||||
.await?;
|
|
||||||
match result {
|
|
||||||
Some(roll) if !roll.is_deleted => Ok(roll),
|
|
||||||
_ => bail!("Gacha Roll not found"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn query_create_gacha_roll(
|
|
||||||
&self,
|
|
||||||
data: GachaRollSchema,
|
|
||||||
) -> Result<String> {
|
|
||||||
let db = &self.state.surrealdb_ws;
|
|
||||||
let record: Option<GachaRollSchema> = db
|
|
||||||
.create(ResourceEnum::GachaRolls.to_string())
|
|
||||||
.content(data)
|
|
||||||
.await?;
|
|
||||||
match record {
|
|
||||||
Some(_) => Ok("Success create Gacha Roll".into()),
|
|
||||||
None => bail!("Failed to create Gacha Roll"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+8
-6
@@ -1,24 +1,26 @@
|
|||||||
use crate::{make_thing, ResourceEnum};
|
use crate::{ResourceEnum, make_thing};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use surrealdb::{sql::Thing, Uuid};
|
use surrealdb::{Uuid, sql::Thing};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct PermissionsSchema {
|
pub struct GachaItemSchema {
|
||||||
pub id: Thing,
|
pub id: Thing,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub image_url: String,
|
||||||
pub is_deleted: bool,
|
pub is_deleted: bool,
|
||||||
pub created_at: Option<String>,
|
pub created_at: Option<String>,
|
||||||
pub updated_at: Option<String>,
|
pub updated_at: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PermissionsSchema {
|
impl Default for GachaItemSchema {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
PermissionsSchema {
|
GachaItemSchema {
|
||||||
id: make_thing(
|
id: make_thing(
|
||||||
&ResourceEnum::Permissions.to_string(),
|
&ResourceEnum::GachaItems.to_string(),
|
||||||
&Uuid::new_v4().to_string(),
|
&Uuid::new_v4().to_string(),
|
||||||
),
|
),
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
|
image_url: String::new(),
|
||||||
is_deleted: false,
|
is_deleted: false,
|
||||||
created_at: None,
|
created_at: None,
|
||||||
updated_at: None,
|
updated_at: None,
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pub mod gacha_item_dto;
|
||||||
|
pub mod gacha_item_repository;
|
||||||
|
pub mod gacha_item_schema;
|
||||||
|
|
||||||
|
pub use gacha_item_dto::*;
|
||||||
|
pub use gacha_item_repository::*;
|
||||||
|
pub use gacha_item_schema::*;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use surrealdb::sql::Thing;
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
||||||
|
pub struct GachaRollRequestDto {
|
||||||
|
#[validate(length(min = 1, message = "Item ID must not be empty"))]
|
||||||
|
pub item_id: String,
|
||||||
|
|
||||||
|
#[validate(range(min = 1, message = "Weight must be greater than zero"))]
|
||||||
|
pub weight: f32,
|
||||||
|
|
||||||
|
#[validate(range(min = 1, message = "Quantity must be at least 1"))]
|
||||||
|
pub quantity: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||||
|
pub struct GachaRollDto {
|
||||||
|
pub id: String,
|
||||||
|
pub item: String,
|
||||||
|
pub weight: String,
|
||||||
|
pub quantity: i32,
|
||||||
|
pub is_deleted: bool,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
pub updated_at: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct GachaRollDtoRaw {
|
||||||
|
pub id: Thing,
|
||||||
|
pub item: Thing,
|
||||||
|
pub weight: String,
|
||||||
|
pub quantity: i32,
|
||||||
|
pub is_deleted: bool,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
pub updated_at: Option<String>,
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
use super::GachaRollSchema;
|
||||||
|
use crate::{AppState, ResourceEnum};
|
||||||
|
use anyhow::{Result, bail};
|
||||||
|
|
||||||
|
pub struct GachaRollRepository<'a> {
|
||||||
|
state: &'a AppState,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> GachaRollRepository<'a> {
|
||||||
|
pub fn new(state: &'a AppState) -> Self {
|
||||||
|
Self { state }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn query_gacha_roll_by_id(&self, id: String) -> Result<GachaRollSchema> {
|
||||||
|
let db = &self.state.surrealdb_ws;
|
||||||
|
let result: Option<GachaRollSchema> = db
|
||||||
|
.select((ResourceEnum::GachaRolls.to_string(), id.clone()))
|
||||||
|
.await?;
|
||||||
|
match result {
|
||||||
|
Some(roll) if !roll.is_deleted => Ok(roll),
|
||||||
|
_ => bail!("Gacha Roll not found"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn query_create_gacha_roll(
|
||||||
|
&self,
|
||||||
|
data: GachaRollSchema,
|
||||||
|
) -> Result<String> {
|
||||||
|
let db = &self.state.surrealdb_ws;
|
||||||
|
let record: Option<GachaRollSchema> = db
|
||||||
|
.create(ResourceEnum::GachaRolls.to_string())
|
||||||
|
.content(data)
|
||||||
|
.await?;
|
||||||
|
match record {
|
||||||
|
Some(_) => Ok("Success create Gacha Roll".into()),
|
||||||
|
None => bail!("Failed to create Gacha Roll"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
-13
@@ -1,30 +1,31 @@
|
|||||||
|
use crate::{ResourceEnum, make_thing};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use surrealdb::{sql::Thing, Uuid};
|
use surrealdb::{Uuid, sql::Thing};
|
||||||
|
|
||||||
use crate::{make_thing, ResourceEnum};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct RolesSchema {
|
pub struct GachaRollSchema {
|
||||||
pub id: Thing,
|
pub id: Thing,
|
||||||
pub name: String,
|
pub item: Thing,
|
||||||
|
pub weight: f32,
|
||||||
|
pub quantity: i32,
|
||||||
pub is_deleted: bool,
|
pub is_deleted: bool,
|
||||||
pub permissions: Vec<Thing>,
|
|
||||||
pub created_at: Option<String>,
|
pub created_at: Option<String>,
|
||||||
pub updated_at: Option<String>,
|
pub updated_at: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RolesSchema {
|
impl Default for GachaRollSchema {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
RolesSchema {
|
GachaRollSchema {
|
||||||
id: make_thing(
|
id: make_thing(
|
||||||
&ResourceEnum::Roles.to_string(),
|
&ResourceEnum::GachaRolls.to_string(),
|
||||||
&Uuid::new_v4().to_string(),
|
&Uuid::new_v4().to_string(),
|
||||||
),
|
),
|
||||||
permissions: vec![make_thing(
|
item: make_thing(
|
||||||
&ResourceEnum::Permissions.to_string(),
|
&ResourceEnum::GachaItems.to_string(),
|
||||||
&Uuid::new_v4().to_string(),
|
&Uuid::new_v4().to_string(),
|
||||||
)],
|
),
|
||||||
name: String::new(),
|
weight: 0.2,
|
||||||
|
quantity: 2,
|
||||||
is_deleted: false,
|
is_deleted: false,
|
||||||
created_at: None,
|
created_at: None,
|
||||||
updated_at: None,
|
updated_at: None,
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pub mod gacha_roll_dto;
|
||||||
|
pub mod gacha_roll_repository;
|
||||||
|
pub mod gacha_roll_schema;
|
||||||
|
|
||||||
|
pub use gacha_roll_dto::*;
|
||||||
|
pub use gacha_roll_repository::*;
|
||||||
|
pub use gacha_roll_schema::*;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pub mod gacha_claim;
|
||||||
|
pub mod gacha_item;
|
||||||
|
pub mod gacha_roll;
|
||||||
|
|
||||||
|
pub use gacha_claim::*;
|
||||||
|
pub use gacha_item::*;
|
||||||
|
pub use gacha_roll::*;
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
use axum::{
|
|
||||||
Extension,
|
|
||||||
extract::Request,
|
|
||||||
http::{HeaderValue, Method, StatusCode, header},
|
|
||||||
middleware::Next,
|
|
||||||
response::Response,
|
|
||||||
};
|
|
||||||
use imphnen_iam_service::{UsersItemDtoRaw, UsersRepository};
|
|
||||||
use imphnen_libs::{AppState, Env};
|
|
||||||
use imphnen_utils::{common_response, extract_email};
|
|
||||||
use std::convert::Infallible;
|
|
||||||
use tower_http::cors::CorsLayer;
|
|
||||||
|
|
||||||
pub async fn auth_middleware(
|
|
||||||
Extension(state): Extension<AppState>,
|
|
||||||
mut req: Request,
|
|
||||||
next: Next,
|
|
||||||
) -> Result<Response, Infallible> {
|
|
||||||
let headers = req.headers();
|
|
||||||
let email = match extract_email(headers) {
|
|
||||||
Some(email) => email,
|
|
||||||
None => {
|
|
||||||
return Ok(common_response(
|
|
||||||
StatusCode::UNAUTHORIZED,
|
|
||||||
"Invalid or expired token",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let repository = UsersRepository::new(&state);
|
|
||||||
let user: Option<UsersItemDtoRaw> =
|
|
||||||
match repository.query_user_by_email(email).await {
|
|
||||||
Ok(user) => Some(user),
|
|
||||||
Err(err) => {
|
|
||||||
return Ok(common_response(
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
&err.to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if user.is_none() {
|
|
||||||
return Ok(common_response(
|
|
||||||
StatusCode::UNAUTHORIZED,
|
|
||||||
"Unauthorized user",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
req.extensions_mut().insert(user.unwrap());
|
|
||||||
Ok(next.run(req).await)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cors_middleware() -> CorsLayer {
|
|
||||||
let env = Env::new();
|
|
||||||
let cors_origins = match env.rust_env.as_str() {
|
|
||||||
"development" => vec!["http://localhost:3000"],
|
|
||||||
"production" => {
|
|
||||||
vec!["https://gacha.imphnen.dev", "https://imphnen.dev"]
|
|
||||||
}
|
|
||||||
_ => vec![
|
|
||||||
"http://localhost:3000",
|
|
||||||
"https://gacha.imphnen.dev",
|
|
||||||
"https://imphnen.dev",
|
|
||||||
],
|
|
||||||
};
|
|
||||||
let allowed_origins: Vec<HeaderValue> = cors_origins
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|origin| origin.parse::<HeaderValue>().ok())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
CorsLayer::new()
|
|
||||||
.allow_origin(allowed_origins)
|
|
||||||
.allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE])
|
|
||||||
.allow_headers([header::AUTHORIZATION, header::CONTENT_TYPE])
|
|
||||||
.allow_credentials(true)
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "imphnen-gateway-service"
|
name = "imphnen-gateway"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
imphnen-iam-service = { version = "0.1.0", path = "../imphnen-iam-service" }
|
imphnen-iam = { version = "0.1.0", path = "../imphnen-iam" }
|
||||||
imphnen-entities = { version = "0.1.0", path = "../imphnen-entities" }
|
|
||||||
imphnen-libs = { version = "0.1.0", path = "../imphnen-libs" }
|
imphnen-libs = { version = "0.1.0", path = "../imphnen-libs" }
|
||||||
imphnen-utils = { version = "0.1.0", path = "../imphnen-utils" }
|
imphnen-utils = { version = "0.1.0", path = "../imphnen-utils" }
|
||||||
|
imphnen-entities = { version = "0.1.0", path = "../imphnen-entities" }
|
||||||
|
imphnen-middleware = { version = "0.1.0", path = "../imphnen-middleware" }
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
File diff suppressed because one or more lines are too long
@@ -2,14 +2,12 @@ use axum::{
|
|||||||
Extension, Router, middleware::from_fn, response::Redirect, routing::get,
|
Extension, Router, middleware::from_fn, response::Redirect, routing::get,
|
||||||
};
|
};
|
||||||
use imphnen_entities::{AppState, SurrealMemClient, SurrealWsClient};
|
use imphnen_entities::{AppState, SurrealMemClient, SurrealWsClient};
|
||||||
use imphnen_iam_service::{iam_protected_routes, iam_public_routes};
|
use imphnen_iam::{iam_protected_routes, iam_public_routes};
|
||||||
|
use imphnen_middleware::{auth_middleware, cors_middleware};
|
||||||
|
use utoipa_swagger_ui::SwaggerUi;
|
||||||
|
|
||||||
pub mod docs;
|
pub mod docs;
|
||||||
pub mod middleware;
|
|
||||||
|
|
||||||
pub use docs::*;
|
pub use docs::*;
|
||||||
pub use middleware::*;
|
|
||||||
use utoipa_swagger_ui::SwaggerUi;
|
|
||||||
|
|
||||||
pub async fn gateway_service(
|
pub async fn gateway_service(
|
||||||
surrealdb_ws: SurrealWsClient,
|
surrealdb_ws: SurrealWsClient,
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user