Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mod4-wp-2023-2024-pokemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Popa, C. (Carim, Student B-TCS)
mod4-wp-2023-2024-pokemon
Commits
72426d0d
Commit
72426d0d
authored
9 months ago
by
CarimPopa
Browse files
Options
Downloads
Patches
Plain Diff
Method for handling DELETE request is implemented.
Added a helper static class to store data about pokemons.
parent
19a9211f
Branches
newFeature1
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/nl/utwente/mod4/pokemon/routes/Pokemon.java
+17
-8
17 additions, 8 deletions
src/main/java/nl/utwente/mod4/pokemon/routes/Pokemon.java
src/main/java/nl/utwente/mod4/pokemon/routes/PokemonHelperClass.java
+24
-0
24 additions, 0 deletions
...va/nl/utwente/mod4/pokemon/routes/PokemonHelperClass.java
with
41 additions
and
8 deletions
src/main/java/nl/utwente/mod4/pokemon/routes/Pokemon.java
+
17
−
8
View file @
72426d0d
...
...
@@ -11,6 +11,8 @@ import nl.utwente.mod4.pokemon.model.ResourceCollection;
@Path
(
"/pokemon"
)
public
class
Pokemon
{
public
int
counter
=
0
;
@GET
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
ResourceCollection
<
PokemonEntity
>
getAllPokemon
()
{
...
...
@@ -23,17 +25,24 @@ public class Pokemon {
@Path
(
"/{id}"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
ResourceCollection
<
PokemonEntity
>
getPokemonById
(
@PathParam
(
"id"
)
int
id
)
{
HashMap
<
Integer
,
PokemonEntity
>
map
=
new
HashMap
<>();
map
.
put
(
1
,
new
PokemonEntity
(
"Pikachu"
,
513
,
1
));
map
.
put
(
2
,
new
PokemonEntity
(
"Pikipek"
,
514
,
2
));
PokemonEntity
requestedPokemon
=
map
.
get
(
id
);
if
(
requestedPokemon
==
null
)
{
throw
new
WebApplicationException
(
Response
.
Status
.
NOT_FOUND
);
}
return
new
ResourceCollection
<>(
new
PokemonEntity
[]{
requestedPokemon
},
1
,
1
,
1
);
PokemonEntity
requestedPokemon
=
PokemonHelperClass
.
getPokemon
(
id
);
if
(
requestedPokemon
==
null
)
{
throw
new
NotFoundException
(
);
}
return
new
ResourceCollection
<>(
new
PokemonEntity
[]{
requestedPokemon
},
1
,
1
,
1
);
}
@DELETE
@Path
(
"/{id}"
)
public
void
deletePokemonById
(
@PathParam
(
"id"
)
int
id
)
{
PokemonEntity
pokemonToDelete
=
PokemonHelperClass
.
getPokemon
(
id
);
if
(
pokemonToDelete
==
null
)
{
throw
new
WebApplicationException
(
Response
.
Status
.
BAD_REQUEST
);
}
else
{
PokemonHelperClass
.
deletePokemon
(
id
);
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/nl/utwente/mod4/pokemon/routes/PokemonHelperClass.java
0 → 100644
+
24
−
0
View file @
72426d0d
package
nl.utwente.mod4.pokemon.routes
;
import
nl.utwente.mod4.pokemon.model.PokemonEntity
;
import
java.util.*
;
public
class
PokemonHelperClass
{
public
static
Map
<
Integer
,
PokemonEntity
>
pokemonMap
=
new
HashMap
<
Integer
,
PokemonEntity
>();
static
{
pokemonMap
.
put
(
1
,
new
PokemonEntity
(
"Pikachu"
,
513
,
1
));
pokemonMap
.
put
(
2
,
new
PokemonEntity
(
"Pikipek"
,
514
,
2
));
}
public
static
PokemonEntity
getPokemon
(
int
id
)
{
return
pokemonMap
.
get
(
id
);
}
public
static
void
deletePokemon
(
int
id
)
{
pokemonMap
.
remove
(
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