Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_java2b_20250412
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
alx_java2b_20250412
Commits
aff1fefa
Commit
aff1fefa
authored
Jun 01, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SpringJersey: Pozostałe elementy implementacji
parent
af868a09
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
0 deletions
+92
-0
CustomerRepository.java
...ey/src/main/java/sklep/repository/CustomerRepository.java
+7
-0
DefaultExceptionMapper.java
...rsey/src/main/java/sklep/rest/DefaultExceptionMapper.java
+27
-0
RCustomers.java
PC38-SpringJersey/src/main/java/sklep/rest/RCustomers.java
+58
-0
No files found.
PC38-SpringJersey/src/main/java/sklep/repository/CustomerRepository.java
0 → 100644
View file @
aff1fefa
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
sklep.model.Customer
;
public
interface
CustomerRepository
extends
JpaRepository
<
Customer
,
String
>
{
}
PC38-SpringJersey/src/main/java/sklep/rest/DefaultExceptionMapper.java
0 → 100644
View file @
aff1fefa
package
sklep
.
rest
;
import
jakarta.ws.rs.core.Response
;
import
jakarta.ws.rs.core.Response.Status
;
import
jakarta.ws.rs.ext.ExceptionMapper
;
import
jakarta.ws.rs.ext.Provider
;
@Provider
public
class
DefaultExceptionMapper
implements
ExceptionMapper
<
Exception
>
{
@Override
public
Response
toResponse
(
Exception
e
)
{
String
tresc
=
String
.
format
(
"<html><body>"
+
"<h1>Błąd</h1>"
+
"<div>Błąd typu <code>%s</code></div>"
+
"<div style='color:red'>%s</div>"
+
"</body></html>"
,
e
.
getClass
().
getName
(),
e
.
getMessage
());
return
Response
.
status
(
Status
.
INTERNAL_SERVER_ERROR
)
.
type
(
"text/html;charset=utf-8"
)
.
entity
(
tresc
)
.
build
();
}
}
PC38-SpringJersey/src/main/java/sklep/rest/RCustomers.java
0 → 100644
View file @
aff1fefa
package
sklep
.
rest
;
import
java.util.List
;
import
java.util.Optional
;
import
jakarta.ws.rs.Consumes
;
import
jakarta.ws.rs.DELETE
;
import
jakarta.ws.rs.GET
;
import
jakarta.ws.rs.POST
;
import
jakarta.ws.rs.PUT
;
import
jakarta.ws.rs.Path
;
import
jakarta.ws.rs.PathParam
;
import
jakarta.ws.rs.Produces
;
import
jakarta.ws.rs.core.Response
;
import
jakarta.ws.rs.core.Response.Status
;
import
jakarta.ws.rs.core.UriBuilder
;
import
sklep.model.Customer
;
import
sklep.repository.CustomerRepository
;
@Path
(
"/customers"
)
@Produces
({
"application/xml"
,
"application/json"
,
"text/plain"
})
@Consumes
({
"application/xml"
,
"application/json"
})
public
class
RCustomers
{
private
CustomerRepository
customerRepository
;
@POST
public
Response
create
(
final
Customer
customer
)
{
customerRepository
.
save
(
customer
);
return
Response
.
created
(
UriBuilder
.
fromResource
(
RCustomers
.
class
).
path
(
customer
.
getCustomerEmail
()).
build
()).
build
();
}
@GET
@Path
(
"/{email}"
)
public
Response
findByEmail
(
@PathParam
(
"email"
)
final
String
email
)
{
Optional
<
Customer
>
customer
=
customerRepository
.
findById
(
email
);
if
(
customer
.
isPresent
())
{
return
Response
.
ok
(
customer
.
get
()).
build
();
}
else
{
return
Response
.
status
(
Status
.
NOT_FOUND
).
build
();
}
}
@GET
public
List
<
Customer
>
listAll
()
{
return
customerRepository
.
findAll
();
}
// public List<Customer> listAll(@QueryParam("start") final Integer startPosition,
// @QueryParam("max") final Integer maxResult) { customerRepository.findAll(Pageable.ofSize(max).....) }
@DELETE
@Path
(
"/{email}"
)
public
Response
deleteById
(
@PathParam
(
"email"
)
final
String
email
)
{
customerRepository
.
deleteById
(
email
);
return
Response
.
noContent
().
build
();
}
}
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