Fakultas Ilmu Komputer UI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bambangshop-receiver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Christian Raphael Heryanto
bambangshop-receiver
Commits
4714845e
Commit
4714845e
authored
1 week ago
by
Christian Raphael Heryanto
Browse files
Options
Downloads
Patches
Plain Diff
Implement subscribe function in Notification service.
parent
f8150853
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/service/notification.rs
+42
-1
42 additions, 1 deletion
src/service/notification.rs
with
42 additions
and
1 deletion
src/service/notification.rs
+
42
−
1
View file @
4714845e
...
...
@@ -12,4 +12,45 @@ use bambangshop_receiver::{compose_error_response, Result, APP_CONFIG, REQWEST_C
pub
struct
NotificationService
;
impl
NotificationService
{}
impl
NotificationService
{
#[tokio::main]
async
fn
subscribe_request
(
product_type
:
String
)
->
Result
<
SubscriberRequest
>
{
let
product_type_upper
:
String
=
product_type
.to_uppercase
();
let
product_type_str
:
&
str
=
product_type_upper
.as_str
();
let
notification_receiver_url
:
String
=
format!
(
"{}/receive"
,
APP_CONFIG
.get_instance_name
()
.to_string
());
let
payload
:
SubscriberRequest
=
SubscriberRequest
{
name
:
APP_CONFIG
.get_instance_name
()
.to_string
(),
url
:
notification_receiver_url
,
};
let
request_url
:
String
=
format!
(
"{}/notification/subscribe/{}"
,
APP_CONFIG
.get_publisher_root_url
(),
product_type_str
);
let
request
=
REQWEST_CLIENT
.post
(
request_url
.clone
())
.header
(
"Content-Type"
,
"application/json"
)
.header
(
"Accept"
,
"application/json"
)
.body
(
to_string
(
&
payload
)
.unwrap
())
.send
()
.await
;
log
::
warn_!
(
"Sent subscribe request to: {}"
,
request_url
);
return
match
request
{
Ok
(
f
)
=>
match
f
.json
::
<
SubscriberRequest
>
()
.await
{
Ok
(
x
)
=>
Ok
(
x
),
Err
(
y
)
=>
Err
(
compose_error_response
(
Status
::
NotAcceptable
,
y
.to_string
())),
},
Err
(
e
)
=>
Err
(
compose_error_response
(
Status
::
NotFound
,
e
.to_string
())),
};
}
pub
fn
subscribe
(
product_type
:
&
str
)
->
Result
<
SubscriberRequest
>
{
let
product_type_clone
=
String
::
from
(
product_type
);
return
thread
::
spawn
(
move
||
Self
::
subscribe_request
(
product_type_clone
))
.join
()
.unwrap
();
}
}
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