Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSE-108c Project 1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cheuk Pui Lam
CSE-108c Project 1
Commits
83763a5e
Verified
Commit
83763a5e
authored
2 months ago
by
Korben Tompkin
Browse files
Options
Downloads
Patches
Plain Diff
feat(server): init working
parent
fad12d49
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
feat(server): Server implementation
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+4
-1
4 additions, 1 deletion
.gitignore
Cargo.lock
+1506
-109
1506 additions, 109 deletions
Cargo.lock
server/Cargo.toml
+1
-0
1 addition, 0 deletions
server/Cargo.toml
server/src/main.rs
+18
-8
18 additions, 8 deletions
server/src/main.rs
with
1529 additions
and
118 deletions
.gitignore
+
4
−
1
View file @
83763a5e
...
...
@@ -3,4 +3,7 @@
static/syn*
static/venv
venv
\ No newline at end of file
venv
*.json
*.log
This diff is collapsed.
Click to expand it.
Cargo.lock
+
1506
−
109
View file @
83763a5e
This diff is collapsed.
Click to expand it.
server/Cargo.toml
+
1
−
0
View file @
83763a5e
...
...
@@ -7,4 +7,5 @@ edition = "2021"
axum
=
"0.8.1"
serde
=
"1.0.217"
serde_json
=
"1.0.138"
sqlx
=
{
version
=
"0.8.3"
,
features
=
[
"runtime-tokio"
]
}
tokio
=
{
version
=
"1.43.0"
,
features
=
[
"macros"
,
"rt-multi-thread"
]
}
This diff is collapsed.
Click to expand it.
server/src/main.rs
+
18
−
8
View file @
83763a5e
...
...
@@ -9,6 +9,11 @@ use serde_json::{json, Value};
use
std
::{
collections
::
HashMap
,
fs
};
use
tokio
;
#[derive(Serialize,
Deserialize)]
struct
ED
{
db
:
HashMap
<
String
,
String
>
,
}
#[tokio::main]
async
fn
main
()
{
let
app
=
Router
::
new
()
...
...
@@ -22,18 +27,23 @@ async fn main() {
}
async
fn
init
(
Json
(
payload
):
Json
<
Value
>
)
->
Result
<
(),
StatusCode
>
{
match
payload
.as_str
()
{
Some
(
db
)
=>
{
if
let
Ok
(
_
)
=
fs
::
write
(
"./db/database.json"
,
db
)
{
Ok
(())
}
else
{
Err
(
StatusCode
::
INTERNAL_SERVER_ERROR
)
}
match
fs
::
write
(
"./db.json"
,
payload
.to_string
())
{
Ok
(
_
)
=>
Ok
(()),
Err
(
x
)
=>
{
println!
(
"{:#?}"
,
x
);
Err
(
StatusCode
::
INTERNAL_SERVER_ERROR
)
}
None
=>
Err
(
StatusCode
::
INTERNAL_SERVER_ERROR
),
}
}
async
fn
search
(
Path
(
query
):
Path
<
String
>
)
->
Result
<
Json
<
Value
>
,
StatusCode
>
{
let
data_string
=
match
fs
::
read_to_string
(
"./db.json"
)
{
Ok
(
x
)
=>
x
,
Err
(
_
)
=>
String
::
from
(
""
),
};
let
ed
:
ED
=
ED
{
db
:
serde_json
::
from_str
(
&
data_string
)
.unwrap
(),
};
println!
(
"{:#?}"
,
ed
.db
);
Ok
(
Json
(
json!
({
query
:
""
})))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment