Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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
java_dzienna_15_09
Commits
da548994
Commit
da548994
authored
Oct 07, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Obsługa XML z dodatkowymi "opakowaniami"
parent
2bd7ca5f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
11 deletions
+78
-11
Price.java
PC34-RestSerwer/src/main/java/sklep/model/Price.java
+33
-0
ProductList.java
PC34-RestSerwer/src/main/java/sklep/model/ProductList.java
+37
-0
RProductsXML.java
PC34-RestSerwer/src/main/java/sklep/rest/RProductsXML.java
+8
-11
No files found.
PC34-RestSerwer/src/main/java/sklep/model/Price.java
0 → 100644
View file @
da548994
package
sklep
.
model
;
import
java.math.BigDecimal
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlValue
;
@XmlRootElement
public
class
Price
{
@XmlValue
private
BigDecimal
value
;
public
Price
()
{
this
.
value
=
BigDecimal
.
ZERO
;
}
public
Price
(
BigDecimal
value
)
{
this
.
value
=
value
;
}
public
BigDecimal
getValue
()
{
return
value
;
}
public
void
setValue
(
BigDecimal
value
)
{
this
.
value
=
value
;
}
@Override
public
String
toString
()
{
return
value
.
toString
();
}
}
PC34-RestSerwer/src/main/java/sklep/model/ProductList.java
0 → 100644
View file @
da548994
package
sklep
.
model
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
(
name
=
"products"
)
public
class
ProductList
{
@XmlElement
(
name
=
"product"
)
private
final
List
<
Product
>
products
=
new
ArrayList
<>();
public
ProductList
()
{
// zostawia pustą listę
}
public
ProductList
(
Collection
<
Product
>
products
)
{
this
.
products
.
addAll
(
products
);
}
public
List
<
Product
>
getProducts
()
{
return
Collections
.
unmodifiableList
(
this
.
products
);
}
public
void
setProducts
(
Collection
<
Product
>
products
)
{
this
.
products
.
clear
();
this
.
products
.
addAll
(
products
);
}
@Override
public
String
toString
()
{
return
this
.
products
.
toString
();
}
}
PC34-RestSerwer/src/main/java/sklep/rest/RProductsXML.java
View file @
da548994
package
sklep
.
rest
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
...
...
@@ -16,7 +13,9 @@ import sklep.db.DBConnection;
import
sklep.db.DBException
;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.model.Price
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
import
sklep.photo.PhotoUtil
;
@Path
(
"/products.xml"
)
...
...
@@ -25,10 +24,10 @@ import sklep.photo.PhotoUtil;
public
class
RProductsXML
{
@GET
public
List
<
Product
>
readAll
()
throws
DBException
{
public
ProductList
readAll
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
readAll
(
);
return
new
ProductList
(
productDAO
.
readAll
()
);
}
}
...
...
@@ -43,23 +42,21 @@ public class RProductsXML {
@GET
@Path
(
"/{id}/price"
)
@Produces
(
"text/plain"
)
public
BigDecimal
getPrice
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
public
Price
getPrice
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
Product
product
=
productDAO
.
findById
(
productId
);
return
product
.
getPrice
(
);
return
new
Price
(
product
.
getPrice
()
);
}
}
@PUT
@Path
(
"/{id}/price"
)
@Consumes
(
"text/plain"
)
public
void
setPrice
(
@PathParam
(
"id"
)
int
productId
,
BigDecimal
newPrice
)
throws
DBException
,
RecordNotFound
{
public
void
setPrice
(
@PathParam
(
"id"
)
int
productId
,
Price
newPrice
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
Product
product
=
productDAO
.
findById
(
productId
);
product
.
setPrice
(
newPrice
);
product
.
setPrice
(
newPrice
.
getValue
()
);
productDAO
.
update
(
product
);
db
.
commit
();
}
...
...
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