Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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_20230617
Commits
cbfe08b2
You need to sign in or sign up before continuing.
Commit
cbfe08b2
authored
Aug 20, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Poprawki w wersji XML
parent
0830ce1d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
11 deletions
+78
-11
Price.java
PC32-RestSerwer/src/main/java/sklep/model/Price.java
+33
-0
ProductList.java
PC32-RestSerwer/src/main/java/sklep/model/ProductList.java
+37
-0
RProductsXML.java
PC32-RestSerwer/src/main/java/sklep/rest/RProductsXML.java
+8
-11
No files found.
PC32-RestSerwer/src/main/java/sklep/model/Price.java
0 → 100644
View file @
cbfe08b2
package
sklep
.
model
;
import
java.math.BigDecimal
;
import
jakarta.xml.bind.annotation.XmlRootElement
;
import
jakarta.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
();
}
}
PC32-RestSerwer/src/main/java/sklep/model/ProductList.java
0 → 100644
View file @
cbfe08b2
package
sklep
.
model
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
jakarta.xml.bind.annotation.XmlElement
;
import
jakarta.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
();
}
}
PC32-RestSerwer/src/main/java/sklep/rest/RProductsXML.java
View file @
cbfe08b2
package
sklep
.
rest
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
jakarta.ws.rs.Consumes
;
import
jakarta.ws.rs.DELETE
;
import
jakarta.ws.rs.GET
;
...
...
@@ -15,7 +12,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
;
@Path
(
"/products.xml"
)
@Produces
(
"application/xml"
)
...
...
@@ -23,10 +22,10 @@ import sklep.model.Product;
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
()
);
}
}
...
...
@@ -41,24 +40,22 @@ 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
putPrice
(
@PathParam
(
"id"
)
int
productId
,
BigDecimal
newPrice
)
throws
DBException
,
RecordNotFound
{
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