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
21459e8a
Commit
21459e8a
authored
Nov 09, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wiele formatów w jednej klasie - RProducts
parent
5f05ee74
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
9 deletions
+6
-9
RProducts.java
PC35-RestSerwer/src/main/java/rest/RProducts.java
+6
-6
RProductsXML.java
PC35-RestSerwer/src/main/java/rest/RProductsXML.java
+0
-3
No files found.
PC35-RestSerwer/src/main/java/rest/RProducts.java
View file @
21459e8a
...
...
@@ -17,11 +17,11 @@ import sklep.db.ProductDAO;
import
sklep.db.RecordNotFound
;
import
sklep.model.Product
;
@Path
(
"products"
)
@Path
(
"
/
products"
)
public
class
RProducts
{
@GET
@Produces
(
"application/json"
)
@Produces
(
{
"application/json"
,
"application/xml"
,
"text/plain"
}
)
public
List
<
Product
>
readAll
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
...
...
@@ -31,7 +31,7 @@ public class RProducts {
@GET
@Path
(
"/{id}"
)
@Produces
(
"application/json"
)
@Produces
(
{
"application/json"
,
"application/xml"
,
"text/plain"
}
)
public
Product
readOne
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
...
...
@@ -40,7 +40,7 @@ public class RProducts {
}
@POST
@Consumes
(
"application/json"
)
@Consumes
(
{
"application/json"
,
"application/xml"
}
)
// 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.
...
...
@@ -59,7 +59,7 @@ public class RProducts {
// Właściwą strukturą adresu będzie wtedy np. products/3/price
@GET
@Path
(
"/{id}/price"
)
@Produces
(
"application/json"
)
@Produces
(
{
"application/json"
,
"text/plain"
}
)
public
BigDecimal
getPrice
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
...
...
@@ -70,7 +70,7 @@ public class RProducts {
// Metoda PUT służy w HTTP do zapisywania danych DOKŁADNIE POD PODANYM ADRESEM
@PUT
@Path
(
"/{id}/price"
)
@Consumes
(
"application/json"
)
@Consumes
(
{
"application/json"
,
"text/plain"
}
)
public
void
setPrice
(
@PathParam
(
"id"
)
int
productId
,
BigDecimal
newPrice
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
...
...
PC35-RestSerwer/src/main/java/rest/RProductsXML.java
View file @
21459e8a
package
rest
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
jakarta.ws.rs.Consumes
;
import
jakarta.ws.rs.DELETE
;
import
jakarta.ws.rs.GET
;
...
...
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