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
f26d25d1
Commit
f26d25d1
authored
1 year ago
by
Lukas Karsch
Browse files
Options
Downloads
Patches
Plain Diff
#40
all fetch calls for garden controller
parent
12d88631
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
growbros-frontend/src/utils/BackendConnectorImpl.ts
+67
-0
67 additions, 0 deletions
growbros-frontend/src/utils/BackendConnectorImpl.ts
growbros-frontend/src/utils/IBackendConnector.ts
+10
-0
10 additions, 0 deletions
growbros-frontend/src/utils/IBackendConnector.ts
with
77 additions
and
0 deletions
growbros-frontend/src/utils/BackendConnectorImpl.ts
+
67
−
0
View file @
f26d25d1
...
...
@@ -70,6 +70,73 @@ export class BackendConnectorImpl implements IBackendConnector {
return
result
;
}
async
addToGarden
(
plantId
:
number
):
Promise
<
FetchResult
<
void
>>
{
let
result
:
FetchResult
<
void
>
=
{};
try
{
await
fetch
(
this
.
baseUrl
+
"
/garden/add
"
+
plantId
);
}
catch
(
e
)
{
console
.
error
(
"
An error occurred while adding plant with ID
"
,
plantId
,
"
to garden
"
);
console
.
error
(
e
);
result
=
{
err
:
e
};
}
return
result
;
}
async
clearGarden
():
Promise
<
FetchResult
<
void
>>
{
let
result
:
FetchResult
<
void
>
=
{};
try
{
await
fetch
(
this
.
baseUrl
+
"
/garden/remove/all
"
);
}
catch
(
e
)
{
console
.
error
(
"
An error occurred while clearing garden
"
);
console
.
error
(
e
);
result
=
{
err
:
e
};
}
return
result
;
}
async
getGardenEntries
(
sort
?:
string
):
Promise
<
FetchResult
<
Plant
[]
>>
{
let
result
:
FetchResult
<
Plant
[]
>
=
{};
try
{
const
params
=
new
URLSearchParams
();
if
(
sort
)
params
.
set
(
"
sort
"
,
sort
);
const
response
=
await
fetch
(
this
.
baseUrl
+
"
/garden
"
+
params
);
const
json
=
await
response
.
json
();
result
=
this
.
parsePlants
(
json
);
}
catch
(
e
)
{
console
.
error
(
"
An error occurred while getting garden entries
"
)
console
.
error
(
e
);
result
=
{...
result
,
err
:
e
};
}
return
result
;
}
async
getGardenSize
():
Promise
<
FetchResult
<
number
>>
{
let
result
:
FetchResult
<
number
>
=
{};
try
{
const
response
=
await
fetch
(
this
.
baseUrl
+
"
/garden/count
"
);
const
json
=
await
response
.
json
();
const
size
=
Number
.
parseInt
(
json
);
result
=
{
value
:
size
};
}
catch
(
e
)
{
console
.
error
(
"
An error occurred while fetching garden size
"
)
console
.
error
(
e
);
result
=
{...
result
,
err
:
e
};
}
return
result
;
}
async
removeEntryFromGarden
(
entryId
:
number
):
Promise
<
FetchResult
<
void
>>
{
let
result
:
FetchResult
<
void
>
=
{};
try
{
await
fetch
(
this
.
baseUrl
+
"
/garden/remove/
"
+
entryId
);
}
catch
(
e
)
{
console
.
error
(
"
An error occurred while removing garden entry with ID
"
,
entryId
);
console
.
error
(
e
);
result
=
{
err
:
e
};
}
return
result
;
}
parseSinglePlant
(
json
:
any
):
FetchResult
<
Plant
>
{
let
result
:
FetchResult
<
Plant
>
=
{};
try
{
...
...
This diff is collapsed.
Click to expand it.
growbros-frontend/src/utils/IBackendConnector.ts
+
10
−
0
View file @
f26d25d1
...
...
@@ -9,4 +9,14 @@ export interface IBackendConnector {
getRandomPlants
(
amount
:
number
):
Promise
<
FetchResult
<
Plant
[]
>>
;
getSinglePlant
(
id
:
number
):
Promise
<
FetchResult
<
Plant
|
null
>>
;
addToGarden
(
plantId
:
number
):
Promise
<
FetchResult
<
void
>>
;
getGardenEntries
(
sort
?:
string
):
Promise
<
FetchResult
<
Plant
[]
>>
;
getGardenSize
():
Promise
<
FetchResult
<
number
>>
;
removeEntryFromGarden
(
entryId
:
number
):
Promise
<
FetchResult
<
void
>>
;
clearGarden
():
Promise
<
FetchResult
<
void
>>
;
}
\ No newline at end of file
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