Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
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
20230403
Commits
ce4312e4
Commit
ce4312e4
authored
May 26, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Orders
parent
25d7d4b6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
OrderRepository.java
...pring/src/main/java/sklep/repository/OrderRepository.java
+11
-0
OrderController.java
...-RestSpring/src/main/java/sklep/rest/OrderController.java
+38
-0
No files found.
PC36-RestSpring/src/main/java/sklep/repository/OrderRepository.java
0 → 100644
View file @
ce4312e4
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
sklep.model.Order
;
@Repository
public
interface
OrderRepository
extends
JpaRepository
<
Order
,
Integer
>
{
}
PC36-RestSpring/src/main/java/sklep/rest/OrderController.java
0 → 100644
View file @
ce4312e4
package
sklep
.
rest
;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.server.ResponseStatusException
;
import
sklep.model.Order
;
import
sklep.repository.OrderRepository
;
@RestController
@RequestMapping
(
"/orders"
)
public
class
OrderController
{
@Autowired
private
OrderRepository
orderRepository
;
@GetMapping
public
List
<
Order
>
readAll
()
{
return
orderRepository
.
findAll
();
}
@GetMapping
(
"/{id}"
)
public
Order
readOne
(
@PathVariable
(
"id"
)
int
id
)
{
Optional
<
Order
>
order
=
orderRepository
.
findById
(
id
);
if
(
order
.
isPresent
())
{
return
order
.
get
();
}
else
{
throw
new
ResponseStatusException
(
HttpStatus
.
NOT_FOUND
,
"Nie ma zamówienia o numerze "
+
id
);
}
}
}
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