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
Christian Raphael Heryanto
bambangshop
Commits
10a20e90
Commit
10a20e90
authored
2 weeks ago
by
Christian Raphael Heryanto
Browse files
Options
Downloads
Patches
Plain Diff
Implement publish function in Program service and Program controller.
parent
075d3910
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
+13
-6
13 additions, 6 deletions
src/controller/product.rs
src/service/product.rs
+20
-6
20 additions, 6 deletions
src/service/product.rs
with
35 additions
and
13 deletions
src/controller/mod.rs
+
2
−
1
View file @
10a20e90
...
...
@@ -12,7 +12,8 @@ pub fn route_stage() -> AdHoc {
product
::
create
,
product
::
list
,
product
::
read
,
product
::
delete
product
::
delete
,
product
::
publish
,
],
)
.mount
(
...
...
This diff is collapsed.
Click to expand it.
src/controller/product.rs
+
13
−
6
View file @
10a20e90
use
rocket
::
response
::
status
::
Created
;
use
rocket
::
serde
::
json
::
Json
;
use
bambangshop
::
Result
;
use
crate
::
model
::
product
::
Product
;
use
crate
::
service
::
product
::
ProductService
;
use
bambangshop
::
Result
;
#[post(
"/"
,
data
=
"<product>"
)]
pub
fn
create
(
product
:
Json
<
Product
>
)
->
Result
<
Created
<
Json
<
Product
>>>
{
return
match
ProductService
::
create
(
product
.into_inner
())
{
Ok
(
f
)
=>
Ok
(
Created
::
new
(
"/"
)
.body
(
Json
::
from
(
f
))),
Err
(
e
)
=>
Err
(
e
)
Err
(
e
)
=>
Err
(
e
)
,
};
}
...
...
@@ -18,7 +17,7 @@ pub fn create(product: Json<Product>) -> Result<Created<Json<Product>>> {
pub
fn
list
()
->
Result
<
Json
<
Vec
<
Product
>>>
{
return
match
ProductService
::
list
()
{
Ok
(
f
)
=>
Ok
(
Json
::
from
(
f
)),
Err
(
e
)
=>
Err
(
e
)
Err
(
e
)
=>
Err
(
e
)
,
};
}
...
...
@@ -26,7 +25,7 @@ pub fn list() -> Result<Json<Vec<Product>>> {
pub
fn
read
(
id
:
usize
)
->
Result
<
Json
<
Product
>>
{
return
match
ProductService
::
read
(
id
)
{
Ok
(
f
)
=>
Ok
(
Json
::
from
(
f
)),
Err
(
e
)
=>
Err
(
e
)
Err
(
e
)
=>
Err
(
e
)
,
};
}
...
...
@@ -34,6 +33,14 @@ pub fn read(id: usize) -> Result<Json<Product>> {
pub
fn
delete
(
id
:
usize
)
->
Result
<
Json
<
Product
>>
{
return
match
ProductService
::
delete
(
id
)
{
Ok
(
f
)
=>
Ok
(
Json
::
from
(
f
)),
Err
(
e
)
=>
Err
(
e
)
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
),
};
}
This diff is collapsed.
Click to expand it.
src/service/product.rs
+
20
−
6
View file @
10a20e90
use
rocket
::
http
::
Status
;
use
rocket
::
serde
::
json
::
Json
;
use
bambangshop
::{
Result
,
compose_error_response
};
use
crate
::
model
::
product
::
Product
;
use
crate
::
repository
::
product
::
ProductRepository
;
use
crate
::
service
::
notification
::
NotificationService
;
use
bambangshop
::{
compose_error_response
,
Result
};
use
rocket
::
http
::
Status
;
use
rocket
::
serde
::
json
::
Json
;
pub
struct
ProductService
;
...
...
@@ -24,7 +24,7 @@ impl ProductService {
if
product_opt
.is_none
()
{
return
Err
(
compose_error_response
(
Status
::
NotFound
,
String
::
from
(
"Product not found."
)
String
::
from
(
"Product not found."
)
,
));
}
return
Ok
(
product_opt
.unwrap
());
...
...
@@ -35,11 +35,25 @@ impl ProductService {
if
product_opt
.is_none
()
{
return
Err
(
compose_error_response
(
Status
::
NotFound
,
String
::
from
(
"Product not found."
)
String
::
from
(
"Product not found."
)
,
));
}
let
product
:
Product
=
product_opt
.unwrap
();
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