mirror of
https://github.com/Alvin-Zilverstand/pokedex.git
synced 2026-11-22 22:33:00 +01:00
Refactor Pokémon data fetching and validation logic; improve error handling and logging
This commit is contained in:
1 parent
6e06965bc0
commit
5b4fcda9d6
4 files changed
+202
-14
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1,189 @@
|
||||
Executing query: SELECT * FROM pokemon
|
||||
Query result: [{"id":"1","name":"bulbasaur","height":"7","weight":"69","base_experience":"64","species_url":null,"image_url":".\/images\/1.png","image_url_low":".\/small-images\/1.png"},{"id":"2","name":"ivysaur","height":"10","weight":"130","base_experience":"142","species_url":null,"image_url":".\/images\/2.png","image_url_low":".\/small-images\/2.png"},{"id":"3","name":"venusaur","height":"20","weight":"1000","base_experience":"263","species_url":null,"image_url":".\/images\/3.png","image_url_low":".\/small-images\/3.png"},{"id":"4","name":"charmander","height":"6","weight":"85","base_experience":"62","species_url":null,"image_url":".\/images\/4.png","image_url_low":".\/small-images\/4.png"},{"id":"5","name":"charmeleon","height":"11","weight":"190","base_experience":"142","species_url":null,"image_url":".\/images\/5.png","image_url_low":".\/small-images\/5.png"},{"id":"6","name":"charizard","height":"17","weight":"905","base_experience":"267","species_url":null,"image_url":".\/images\/6.png","image_url_low":".\/small-images\/6.png"},{"id":"7","name":"squirtle","height":"5","weight":"90","base_experience":"63","species_url":null,"image_url":".\/images\/7.png","image_url_low":".\/small-images\/7.png"},{"id":"8","name":"wartortle","height":"10","weight":"225","base_experience":"142","species_url":null,"image_url":".\/images\/8.png","image_url_low":".\/small-images\/8.png"},{"id":"9","name":"blastoise","height":"16","weight":"855","base_experience":"265","species_url":null,"image_url":".\/images\/9.png","image_url_low":".\/small-images\/9.png"},{"id":"10","name":"caterpie","height":"3","weight":"29","base_experience":"39","species_url":null,"image_url":".\/images\/10.png","image_url_low":".\/small-images\/10.png"},{"id":"11","name":"metapod","height":"7","weight":"99","base_experience":"72","species_url":null,"image_url":".\/images\/11.png","image_url_low":".\/small-images\/11.png"},{"id":"12","name":"butterfree","height":"11","weight":"320","base_experience":"198","species_url":null,"image_url":".\/images\/12.png","image_url_low":".\/small-images\/12.png"},{"id":"13","name":"weedle","height":"3","weight":"32","base_experience":"39","species_url":null,"image_url":".\/images\/13.png","image_url_low":".\/small-images\/13.png"},{"id":"14","name":"kakuna","height":"6","weight":"100","base_experience":"72","species_url":null,"image_url":".\/images\/14.png","image_url_low":".\/small-images\/14.png"},{"id":"15","name":"beedrill","height":"10","weight":"295","base_experience":"178","species_url":null,"image_url":".\/images\/15.png","image_url_low":".\/small-images\/15.png"},{"id":"16","name":"pidgey","height":"3","weight":"18","base_experience":"50","species_url":null,"image_url":".\/images\/16.png","image_url_low":".\/small-images\/16.png"},{"id":"17","name":"pidgeotto","height":"11","weight":"300","base_experience":"122","species_url":null,"image_url":".\/images\/17.png","image_url_low":".\/small-images\/17.png"},{"id":"18","name":"pidgeot","height":"15","weight":"395","base_experience":"216","species_url":null,"image_url":".\/images\/18.png","image_url_low":".\/small-images\/18.png"},{"id":"19","name":"rattata","height":"3","weight":"35","base_experience":"51","species_url":null,"image_url":".\/images\/19.png","image_url_low":".\/small-images\/19.png"},{"id":"20","name":"raticate","height":"7","weight":"185","base_experience":"145","species_url":null,"image_url":".\/images\/20.png","image_url_low":".\/small-images\/20.png"},{"id":"21","name":"spearow","height":"3","weight":"20","base_experience":"52","species_url":null,"image_url":".\/images\/21.png","image_url_low":".\/small-images\/21.png"},{"id":"22","name":"fearow","height":"12","weight":"380","base_experience":"155","species_url":null,"image_url":".\/images\/22.png","image_url_low":".\/small-images\/22.png"},{"id":"23","name":"ekans","height":"20","weight":"69","base_experience":"58","species_url":null,"image_url":".\/images\/23.png","image_url_low":".\/small-images\/23.png"},{"id":"24","name":"arbok","height":"35","weight":"650","base_experience":"157","species_url":null,"image_url":".\/images\/24.png","image_url_low":".\/small-images\/24.png"},{"id":"25","name":"pikachu","height":"4","weight":"60","base_experience":"112","species_url":null,"image_url":".\/images\/25.png","image_url_low":".\/small-images\/25.png"},{"id":"26","name":"raichu","height":"8","weight":"300","base_experience":"243","species_url":null,"image_url":".\/images\/26.png","image_url_low":".\/small-images\/26.png"},{"id":"27","name":"sandshrew","height":"6","weight":"120","base_experience":"60","species_url":null,"image_url":".\/images\/27.png","image_url_low":".\/small-images\/27.png"},{"id":"28","name":"sandslash","height":"10","weight":"295","base_experience":"158","species_url":null,"image_url":".\/images\/28.png","image_url_low":".\/small-images\/28.png"},{"id":"29","name":"nidoran-f","height":"4","weight":"70","base_experience":"55","species_url":null,"image_url":".\/images\/29.pnLine truncated
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 1
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"1","name":"bulbasaur","height":"7","weight":"69","base_experience":"64","species_url":null,"image_url":".\/images\/1.png","image_url_low":".\/small-images\/1.png","flavor_text":"A strange seed was\nplanted on its\nback at birth. The plant sprouts\nand grows with\nthis POK\u00e9MON.","types":["grass","grass","grass","grass","poison","poison","poison","poison","grass","grass","grass","grass","poison","poison","poison","poison"],"abilities":["overgrow","overgrow","chlorophyll","chlorophyll","overgrow","overgrow","chlorophyll","chlorophyll","overgrow","overgrow","chlorophyll","chlorophyll","overgrow","overgrow","chlorophyll","chlorophyll"],"hp":"45","attack":"49","defense":"49","sp_attack":"65","sp_defense":"65","speed":"45"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 1
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"1","name":"bulbasaur","height":"7","weight":"69","base_experience":"64","species_url":null,"image_url":".\/images\/1.png","image_url_low":".\/small-images\/1.png","flavor_text":"A strange seed was\nplanted on its\nback at birth. The plant sprouts\nand grows with\nthis POK\u00e9MON.","types":["grass","grass","grass","grass","poison","poison","poison","poison","grass","grass","grass","grass","poison","poison","poison","poison"],"abilities":["overgrow","overgrow","chlorophyll","chlorophyll","overgrow","overgrow","chlorophyll","chlorophyll","overgrow","overgrow","chlorophyll","chlorophyll","overgrow","overgrow","chlorophyll","chlorophyll"],"hp":"45","attack":"49","defense":"49","sp_attack":"65","sp_defense":"65","speed":"45"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 2
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"2","name":"ivysaur","height":"10","weight":"130","base_experience":"142","species_url":null,"image_url":".\/images\/2.png","image_url_low":".\/small-images\/2.png","flavor_text":"When the bulb on\nits back grows\nlarge, it appears to lose the\nability to stand\non its hind legs.","types":["grass","grass","poison","poison"],"abilities":["overgrow","chlorophyll","overgrow","chlorophyll"],"hp":"60","attack":"62","defense":"63","sp_attack":"80","sp_defense":"80","speed":"60"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 2
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"2","name":"ivysaur","height":"10","weight":"130","base_experience":"142","species_url":null,"image_url":".\/images\/2.png","image_url_low":".\/small-images\/2.png","flavor_text":"When the bulb on\nits back grows\nlarge, it appears to lose the\nability to stand\non its hind legs.","types":["grass","grass","poison","poison"],"abilities":["overgrow","chlorophyll","overgrow","chlorophyll"],"hp":"60","attack":"62","defense":"63","sp_attack":"80","sp_defense":"80","speed":"60"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 3
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"3","name":"venusaur","height":"20","weight":"1000","base_experience":"263","species_url":null,"image_url":".\/images\/3.png","image_url_low":".\/small-images\/3.png","flavor_text":"The plant blooms\nwhen it is\nabsorbing solar energy. It stays\non the move to\nseek sunlight.","types":["grass","grass","poison","poison"],"abilities":["overgrow","chlorophyll","overgrow","chlorophyll"],"hp":"80","attack":"82","defense":"83","sp_attack":"100","sp_defense":"100","speed":"80"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 3
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"3","name":"venusaur","height":"20","weight":"1000","base_experience":"263","species_url":null,"image_url":".\/images\/3.png","image_url_low":".\/small-images\/3.png","flavor_text":"The plant blooms\nwhen it is\nabsorbing solar energy. It stays\non the move to\nseek sunlight.","types":["grass","grass","poison","poison"],"abilities":["overgrow","chlorophyll","overgrow","chlorophyll"],"hp":"80","attack":"82","defense":"83","sp_attack":"100","sp_defense":"100","speed":"80"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 4
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"4","name":"charmander","height":"6","weight":"85","base_experience":"62","species_url":null,"image_url":".\/images\/4.png","image_url_low":".\/small-images\/4.png","flavor_text":"Obviously prefers\nhot places. When\nit rains, steam is said to spout\nfrom the tip of\nits tail.","types":["fire","fire"],"abilities":["blaze","solar-power"],"hp":"39","attack":"52","defense":"43","sp_attack":"60","sp_defense":"50","speed":"65"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 4
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"4","name":"charmander","height":"6","weight":"85","base_experience":"62","species_url":null,"image_url":".\/images\/4.png","image_url_low":".\/small-images\/4.png","flavor_text":"Obviously prefers\nhot places. When\nit rains, steam is said to spout\nfrom the tip of\nits tail.","types":["fire","fire"],"abilities":["blaze","solar-power"],"hp":"39","attack":"52","defense":"43","sp_attack":"60","sp_defense":"50","speed":"65"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 5
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"5","name":"charmeleon","height":"11","weight":"190","base_experience":"142","species_url":null,"image_url":".\/images\/5.png","image_url_low":".\/small-images\/5.png","flavor_text":"When it swings\nits burning tail,\nit elevates the temperature to\nunbearably high\nlevels.","types":["fire","fire"],"abilities":["blaze","solar-power"],"hp":"58","attack":"64","defense":"58","sp_attack":"80","sp_defense":"65","speed":"80"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 5
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"5","name":"charmeleon","height":"11","weight":"190","base_experience":"142","species_url":null,"image_url":".\/images\/5.png","image_url_low":".\/small-images\/5.png","flavor_text":"When it swings\nits burning tail,\nit elevates the temperature to\nunbearably high\nlevels.","types":["fire","fire"],"abilities":["blaze","solar-power"],"hp":"58","attack":"64","defense":"58","sp_attack":"80","sp_defense":"65","speed":"80"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 681
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"681","name":"aegislash-shield","height":"17","weight":"530","base_experience":"250","species_url":null,"image_url":".\/images\/681.png","image_url_low":".\/small-images\/681.png","flavor_text":"\u308c\u304d\u3060\u3044\u306e\u3000\u304a\u3046\u304c\u3000\u3064\u308c\u3066\u3044\u305f\u3002\n\u308c\u3044\u308a\u3087\u304f\u3067\u3000\u3072\u3068\u3084\u3000\u30dd\u30b1\u30e2\u30f3\u306e\n\u3053\u3053\u308d\u3092\u3000\u3042\u3084\u3064\u308a\u3000\u3057\u305f\u304c\u308f\u305b\u308b\u3002","types":["ghost","steel"],"abilities":["stance-change","stance-change"],"hp":"60","attack":"50","defense":"140","sp_attack":"50","sp_defense":"140","speed":"60"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 402
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"402","name":"kricketune","height":"10","weight":"255","base_experience":"134","species_url":null,"image_url":".\/images\/402.png","image_url_low":".\/small-images\/402.png","flavor_text":"It crosses its knifelike arms in\nfront of its chest when it cries.\nIt can compose melodies ad lib.","types":["bug","bug"],"abilities":["swarm","technician"],"hp":"77","attack":"85","defense":"51","sp_attack":"55","sp_defense":"51","speed":"65"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 133
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"133","name":"eevee","height":"3","weight":"65","base_experience":"65","species_url":null,"image_url":".\/images\/133.png","image_url_low":".\/small-images\/133.png","flavor_text":"Its genetic code\nis irregular.\nIt may mutate if it is exposed to\nradiation from\nelement STONEs.","types":["normal","normal","normal"],"abilities":["run-away","adaptability","anticipation"],"hp":"55","attack":"55","defense":"50","sp_attack":"45","sp_defense":"65","speed":"55"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 133
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"133","name":"eevee","height":"3","weight":"65","base_experience":"65","species_url":null,"image_url":".\/images\/133.png","image_url_low":".\/small-images\/133.png","flavor_text":"Its genetic code\nis irregular.\nIt may mutate if it is exposed to\nradiation from\nelement STONEs.","types":["normal","normal","normal"],"abilities":["run-away","adaptability","anticipation"],"hp":"55","attack":"55","defense":"50","sp_attack":"45","sp_defense":"65","speed":"55"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 223
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"223","name":"remoraid","height":"6","weight":"120","base_experience":"60","species_url":null,"image_url":".\/images\/223.png","image_url_low":".\/small-images\/223.png","flavor_text":"It has superb ac\u00ad\ncuracy. The water\nit shoots out can strike even moving\nprey from more\nthan 300 feet.","types":["water","water","water"],"abilities":["sniper","hustle","moody"],"hp":"35","attack":"65","defense":"35","sp_attack":"65","sp_defense":"35","speed":"65"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 307
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"307","name":"meditite","height":"6","weight":"112","base_experience":"56","species_url":null,"image_url":".\/images\/307.png","image_url_low":".\/small-images\/307.png","flavor_text":"\uff11\u306b\u3061\u3000\uff11\u3053\u3060\u3051\u3000\u304d\u306e\u307f\u3092\u3000\u305f\u3079\u308b\u3002\n\u304f\u3046\u3075\u304f\u306b\u3000\u305f\u3048\u308b\u3053\u3068\u3067\n\u3053\u3053\u308d\u304c\u3000\u3068\u304e\u3059\u307e\u3055\u308c\u3066\u3044\u304f\u3002","types":["fighting","fighting","psychic","psychic"],"abilities":["telepathy","pure-power","telepathy","pure-power"],"hp":"30","attack":"40","defense":"55","sp_attack":"40","sp_defense":"55","speed":"60"}
|
||||
Executing query: SELECT p.*, s.flavor_text, GROUP_CONCAT(t.name) AS types, GROUP_CONCAT(a.name) AS abilities, st.hp, st.attack, st.defense, st.sp_attack, st.sp_defense, st.speed
|
||||
FROM pokemon p
|
||||
LEFT JOIN species s ON p.id = s.pokemon_id
|
||||
LEFT JOIN pokemon_types pt ON p.id = pt.pokemon_id
|
||||
LEFT JOIN types t ON pt.type_id = t.id
|
||||
LEFT JOIN pokemon_abilities pa ON p.id = pa.pokemon_id
|
||||
LEFT JOIN abilities a ON pa.ability_id = a.id
|
||||
LEFT JOIN stats st ON p.id = st.pokemon_id
|
||||
WHERE p.id = 307
|
||||
GROUP BY p.id
|
||||
Query result: {"id":"307","name":"meditite","height":"6","weight":"112","base_experience":"56","species_url":null,"image_url":".\/images\/307.png","image_url_low":".\/small-images\/307.png","flavor_text":"\uff11\u306b\u3061\u3000\uff11\u3053\u3060\u3051\u3000\u304d\u306e\u307f\u3092\u3000\u305f\u3079\u308b\u3002\n\u304f\u3046\u3075\u304f\u306b\u3000\u305f\u3048\u308b\u3053\u3068\u3067\n\u3053\u3053\u308d\u304c\u3000\u3068\u304e\u3059\u307e\u3055\u308c\u3066\u3044\u304f\u3002","types":["fighting","fighting","psychic","psychic"],"abilities":["telepathy","pure-power","telepathy","pure-power"],"hp":"30","attack":"40","defense":"55","sp_attack":"40","sp_defense":"55","speed":"60"}
|
||||
+9
-12
@@ -1,11 +1,11 @@
|
||||
let currentPokemonId = null;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const MAX_POKEMONS = 151;
|
||||
const pokemonID = new URLSearchParams(window.location.search).get("id");
|
||||
const id = parseInt(pokemonID, 10);
|
||||
|
||||
if (id < 1 || id > MAX_POKEMONS) {
|
||||
if (isNaN(id) || id < 1) {
|
||||
console.error(`Invalid Pokémon ID: ${id}`);
|
||||
return (window.location.href = "./index.html");
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
async function loadPokemon(id) {
|
||||
try {
|
||||
console.log(`Loading data for Pokémon ID ${id}...`);
|
||||
const pokemon = await fetch(`./get-pokemon.php?id=${id}`).then((res) =>
|
||||
res.json()
|
||||
);
|
||||
@@ -39,16 +40,12 @@ async function loadPokemon(id) {
|
||||
leftArrow.removeEventListener("click", navigatePokemon);
|
||||
rightArrow.removeEventListener("click", navigatePokemon);
|
||||
|
||||
if (id !== 1) {
|
||||
leftArrow.addEventListener("click", () => {
|
||||
navigatePokemon(id - 1);
|
||||
});
|
||||
}
|
||||
if (id !== 151) {
|
||||
rightArrow.addEventListener("click", () => {
|
||||
navigatePokemon(id + 1);
|
||||
});
|
||||
}
|
||||
leftArrow.addEventListener("click", () => {
|
||||
navigatePokemon(id - 1);
|
||||
});
|
||||
rightArrow.addEventListener("click", () => {
|
||||
navigatePokemon(id + 1);
|
||||
});
|
||||
|
||||
window.history.pushState({}, "", `./detail.html?id=${id}`);
|
||||
}
|
||||
|
||||
+4
-2
@@ -28,8 +28,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
function fetchPokemons() {
|
||||
console.log("Fetching Pokémon data from server...");
|
||||
fetch(`./get-pokemon.php`)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
.then((response) => response.text())
|
||||
.then((text) => {
|
||||
console.log("Server response:", text);
|
||||
const data = JSON.parse(text);
|
||||
if (Array.isArray(data)) {
|
||||
allPokemons = data;
|
||||
localStorage.setItem("pokemons", JSON.stringify(allPokemons));
|
||||
|
||||
Reference in new issue
Block a user