Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
javab_20230928
Commits
678333c6
Commit
678333c6
authored
Nov 09, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
POST zwracający minimalny dokumenci JSON
parent
4d68b715
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
RCustomers.java
PC35-RestSerwer/src/main/java/rest/RCustomers.java
+1
-0
RProducts.java
PC35-RestSerwer/src/main/java/rest/RProducts.java
+22
-1
RProductsJSON.java
PC35-RestSerwer/src/main/java/rest/RProductsJSON.java
+22
-1
No files found.
PC35-RestSerwer/src/main/java/rest/RCustomers.java
View file @
678333c6
...
...
@@ -46,6 +46,7 @@ public class RCustomers {
CustomerDAO
customerDAO
=
db
.
customerDAO
();
customerDAO
.
save
(
customer
);
db
.
commit
();
// Zwracamy informację, pod jakim adresem został zapisany rekord.
URI
uri
=
UriBuilder
.
fromResource
(
RCustomers
.
class
)
.
path
(
String
.
valueOf
(
customer
.
getEmail
()))
...
...
PC35-RestSerwer/src/main/java/rest/RProducts.java
View file @
678333c6
...
...
@@ -75,14 +75,35 @@ public class RProducts {
@POST
@Consumes
({
"application/json"
,
"application/xml"
})
@Produces
({
"application/json"
})
// W metodach typu POST i PUT powinien znajdować się dokładnie jeden parametr nieozanczony żadną adnotacją.
// Do tego parametru zostanie przekazana wartość utworzona na podstawie treści zapytania (content / body / entity).
// W adnotacji @Consumes określamy format, w jakim te dane mają być przysłane.
public
void
saveProduct
(
Product
product
)
throws
DBException
{
public
InformacjaZwrotna
saveProduct
(
Product
product
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
productDAO
.
save
(
product
);
db
.
commit
();
return
new
InformacjaZwrotna
(
product
.
getProductId
());
}
}
public
static
class
InformacjaZwrotna
{
private
int
noweId
;
public
InformacjaZwrotna
()
{
}
public
InformacjaZwrotna
(
int
noweId
)
{
this
.
noweId
=
noweId
;
}
public
int
getNoweId
()
{
return
noweId
;
}
public
void
setNoweId
(
int
noweId
)
{
this
.
noweId
=
noweId
;
}
}
...
...
PC35-RestSerwer/src/main/java/rest/RProductsJSON.java
View file @
678333c6
...
...
@@ -48,11 +48,32 @@ public class RProductsJSON {
// W metodach typu POST i PUT powinien znajdować się dokładnie jeden parametr nieozanczony żadną adnotacją.
// Do tego parametru zostanie przekazana wartość utworzona na podstawie treści zapytania (content / body / entity).
// W adnotacji @Consumes określamy format, w jakim te dane mają być przysłane.
public
void
saveProduct
(
Product
product
)
throws
DBException
{
public
InformacjaZwrotna
saveProduct
(
Product
product
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
productDAO
.
save
(
product
);
db
.
commit
();
return
new
InformacjaZwrotna
(
product
.
getProductId
());
}
}
// klasa definiująca, co jest zwracane w wyniku POST po zapisaniu produktu
public
static
class
InformacjaZwrotna
{
private
int
noweId
;
public
InformacjaZwrotna
()
{
}
public
InformacjaZwrotna
(
int
noweId
)
{
this
.
noweId
=
noweId
;
}
public
int
getNoweId
()
{
return
noweId
;
}
public
void
setNoweId
(
int
noweId
)
{
this
.
noweId
=
noweId
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment