Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GrowBros
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tomato
GrowBros
Commits
ae921f6f
Commit
ae921f6f
authored
1 year ago
by
Lukas Karsch
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/main' into backend-connector
parents
a4acde6f
7fa1c96d
No related branches found
No related tags found
1 merge request
!28
Closes #40 : Custom useGrowbrosFetcher hook to make calls to the backend.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/hdm/mi/growbros/controllers/PlantsController.java
+11
-5
11 additions, 5 deletions
...in/java/hdm/mi/growbros/controllers/PlantsController.java
src/main/java/hdm/mi/growbros/service/PlantsService.java
+5
-1
5 additions, 1 deletion
src/main/java/hdm/mi/growbros/service/PlantsService.java
with
16 additions
and
6 deletions
src/main/java/hdm/mi/growbros/controllers/PlantsController.java
+
11
−
5
View file @
ae921f6f
package
hdm.mi.growbros.controllers
;
import
hdm.mi.growbros.exceptions.PlantNotFoundException
;
import
hdm.mi.growbros.models.dto.CustomPageDto
;
import
hdm.mi.growbros.models.plant.Plant
;
import
hdm.mi.growbros.models.search.SearchRequest
;
...
...
@@ -12,12 +13,12 @@ import java.util.Collection;
@RestController
@CrossOrigin
@RequestMapping
(
"/api/v1"
)
@RequestMapping
(
"/api/v1
/plants
"
)
@RequiredArgsConstructor
public
class
PlantsController
{
private
final
PlantsService
plantsService
;
@GetMapping
(
"/plants"
)
@GetMapping
public
CustomPageDto
<
Plant
>
getAllPlants
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"25"
)
int
pageSize
...
...
@@ -25,17 +26,22 @@ public class PlantsController {
return
plantsService
.
getPlants
(
page
,
pageSize
);
}
@GetMapping
(
"/plants/randomPlants/{numberOfPlants}"
)
@GetMapping
(
"/{id}"
)
public
Plant
getPlant
(
@PathVariable
long
id
)
{
return
plantsService
.
findById
(
id
).
orElseThrow
(()
->
new
PlantNotFoundException
(
id
));
}
@GetMapping
(
"/randomPlants/{numberOfPlants}"
)
public
Collection
<
Plant
>
getRandomPlants
(
@PathVariable
Integer
numberOfPlants
)
{
return
plantsService
.
getRandomPlants
(
numberOfPlants
);
}
@GetMapping
(
"/
plants/
search"
)
@GetMapping
(
"/search"
)
public
Collection
<
Plant
>
getPlantsSearchedFor
(
@RequestBody
@Valid
SearchRequest
searchRequest
)
{
return
plantsService
.
getPlantsSearchedFor
(
searchRequest
);
}
@PostMapping
(
"/plants"
)
@PostMapping
public
void
createPlant
(
@RequestBody
@Valid
Plant
plant
)
{
plantsService
.
createPlant
(
plant
);
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/hdm/mi/growbros/service/PlantsService.java
+
5
−
1
View file @
ae921f6f
...
...
@@ -3,8 +3,8 @@ package hdm.mi.growbros.service;
import
hdm.mi.growbros.models.dto.CustomPageDto
;
import
hdm.mi.growbros.models.plant.Plant
;
import
hdm.mi.growbros.models.search.PlantSpecification
;
import
hdm.mi.growbros.repositories.PlantRepository
;
import
hdm.mi.growbros.models.search.SearchRequest
;
import
hdm.mi.growbros.repositories.PlantRepository
;
import
lombok.RequiredArgsConstructor
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -55,4 +55,8 @@ public class PlantsService {
log
.
info
(
"Saving plant '{}' to repository."
,
plant
.
getName
());
plantRepository
.
save
(
plant
);
}
public
Optional
<
Plant
>
findById
(
long
id
)
{
return
plantRepository
.
findById
(
id
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment