Fakultas Ilmu Komputer UI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bambangshop
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
Ferdinand Bonfilio Simamora
bambangshop
Commits
c34136cd
Commit
c34136cd
authored
2 months ago
by
Ferdinand57
Browse files
Options
Downloads
Patches
Plain Diff
Implement publish function in Program service and Program controller.
parent
b7ab15e2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/controller/mod.rs
+2
-1
2 additions, 1 deletion
src/controller/mod.rs
src/controller/product.rs
+8
-0
8 additions, 0 deletions
src/controller/product.rs
src/service/product.rs
+14
-0
14 additions, 0 deletions
src/service/product.rs
with
24 additions
and
1 deletion
src/controller/mod.rs
+
2
−
1
View file @
c34136cd
...
...
@@ -6,7 +6,8 @@ use rocket::fairing::AdHoc;
pub
fn
route_stage
()
->
AdHoc
{
return
AdHoc
::
on_ignite
(
"Initializing controller routes..."
,
|
rocket
|
async
{
rocket
.mount
(
"/product"
,
routes!
[
product
::
create
,
product
::
list
,
product
::
read
,
product
::
delete
])
.mount
(
"/product"
,
routes!
[
product
::
create
,
product
::
list
,
product
::
read
,
product
::
delete
,
product
::
publish
])
.mount
(
"/notification"
,
routes!
[
notification
::
subscribe
,
notification
::
unsubscribe
])
});
}
This diff is collapsed.
Click to expand it.
src/controller/product.rs
+
8
−
0
View file @
c34136cd
...
...
@@ -37,3 +37,11 @@ pub fn delete(id: usize) -> Result<Json<Product>> {
Err
(
e
)
=>
Err
(
e
)
};
}
#[post(
"/<id>/publish"
)]
pub
fn
publish
(
id
:
usize
)
->
Result
<
Json
<
Product
>>
{
return
match
ProductService
::
publish
(
id
)
{
Ok
(
f
)
=>
Ok
(
Json
::
from
(
f
)),
Err
(
e
)
=>
Err
(
e
)
};
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/service/product.rs
+
14
−
0
View file @
c34136cd
...
...
@@ -42,4 +42,18 @@ impl ProductService {
return
Ok
(
Json
::
from
(
product
));
}
pub
fn
publish
(
id
:
usize
)
->
Result
<
Product
>
{
let
product_opt
:
Option
<
Product
>
=
ProductRepository
::
get_by_id
(
id
);
if
product_opt
.is_none
()
{
return
Err
(
compose_error_response
(
Status
::
NotFound
,
String
::
from
(
"Product not found."
)
));
}
let
product
:
Product
=
product_opt
.unwrap
();
NotificationService
.notify
(
&
product
.product_type
,
"PROMOTION"
,
product
.clone
());
return
Ok
(
product
);
}
}
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