📍 Implement Schema Versioning NoSQL pattern #5
Merged
alexis.drai
merged 6 commits from feature/implement-nosql-pattern
into main
2 years ago
@ -0,0 +1,384 @@
|
|||||||
|
{
|
||||||
|
"info": {
|
||||||
|
"_postman_id": "11aa7a76-83a4-4b92-940f-528e29b66df8",
|
||||||
|
"name": "PoKeMoNg",
|
||||||
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||||
|
"_exporter_id": "25802734"
|
||||||
|
},
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "move",
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Create 1 move",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\r\n \"name\": \"Bubble beam\",\r\n \"category\": \"PHYSICAL\",\r\n \"power\": 10,\r\n \"accuracy\": 85,\r\n \"type\": \r\n {\r\n \"name\": \"WATER\",\r\n \"weakAgainst\": [\"GRASS\"],\r\n \"effectiveAgainst\": [\"FIRE\", \"GROUND\"]\r\n },\r\n \"schemaVersion\": 2\r\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/move",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"move"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Get all moves",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/move",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"move"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Get 1 move",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/move/60a64f7eae945a6e60b0e917",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"move",
|
||||||
|
"60a64f7eae945a6e60b0e917"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update 1 move",
|
||||||
|
"request": {
|
||||||
|
"method": "PUT",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\r\n \"schemaVersion\": 2,\r\n \"name\": \"Ember UPDATED\",\r\n \"category\": \"SPECIAL\",\r\n \"power\": 40,\r\n \"accuracy\": 100,\r\n \"type\": {\r\n \"name\": \"FIRE\",\r\n \"weakAgainst\": [\r\n \"WATER\",\r\n \"GROUND\"\r\n ],\r\n \"effectiveAgainst\": [\r\n \"GRASS\"\r\n ]\r\n }\r\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/move/60a64f7eae945a6e60b0e917",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"move",
|
||||||
|
"60a64f7eae945a6e60b0e917"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delete 1 move",
|
||||||
|
"request": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/move/60a64f7eae945a6e60b0e913",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"move",
|
||||||
|
"60a64f7eae945a6e60b0e913"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pokemong",
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Create 1 pkmn",
|
||||||
|
"protocolProfileBehavior": {
|
||||||
|
"disabledSystemHeaders": {
|
||||||
|
"content-type": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\r\n \"nickname\": \"Blappity-bloop\",\r\n \"dob\": \"2023-05-07\",\r\n \"level\": 1,\r\n \"pokedexId\": 172,\r\n \"evoStage\": 1,\r\n \"evoTrack\": [\"PICHU\", \"PIKACHU\", \"RAICHU\"],\r\n \"types\": [\r\n {\r\n \"name\": \"ELECTRIC\",\r\n \"weakAgainst\": [\"GROUND\", \"ROCK\"],\r\n \"effectiveAgainst\": [\"WATER\", \"FLYING\"]\r\n }\r\n ],\r\n \"moveSet\": \r\n [\r\n {\r\n \"id\": \"60a64f7eae945a6e60b0e917\",\r\n \"name\": \"Ember\"\r\n }\r\n ],\r\n \"schemaVersion\": 1\r\n}"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/pokemong",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"pokemong"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Get all pkmn",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/pokemong",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"pokemong"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Get 1 pkmn",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/pokemong/60a64f7eae945a6e60b0e911",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"pokemong",
|
||||||
|
"60a64f7eae945a6e60b0e911"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update 1 pkmn",
|
||||||
|
"request": {
|
||||||
|
"method": "PUT",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"schemaVersion\": 1,\n \"nickname\": \"Sparky UPDATED\",\n \"dob\": \"1994-02-18\",\n \"level\": 15,\n \"pokedexId\": 1,\n \"evoStage\": 1,\n \"evoTrack\": [\n \"BULBASAUR\",\n \"IVYSAUR\",\n \"VENUSAUR\"\n ],\n \"trainer\": \"60a64f7eae945a6e60b0e914\",\n \"types\": [\n {\n \"name\": \"GRASS\",\n \"weakAgainst\": [\n \"FIRE\"\n ],\n \"effectiveAgainst\": [\n \"WATER\",\n \"GROUND\"\n ]\n }\n ],\n \"moveSet\": [\n {\n \"id\": \"60a64f7eae945a6e60b0e912\",\n \"name\": \"Vine Whip\"\n }\n ]\n}"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/pokemong/60a64f7eae945a6e60b0e911",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"pokemong",
|
||||||
|
"60a64f7eae945a6e60b0e911"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delete 1 pkmn",
|
||||||
|
"request": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/pokemong/60a64f7eae945a6e60b0e916",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"pokemong",
|
||||||
|
"60a64f7eae945a6e60b0e916"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "trainer",
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Create 1 trainer",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\r\n \"schemaVersion\": 1,\r\n \"name\": \"Bloop\",\r\n \"dob\": \"1997-02-18\",\r\n \"wins\": 1,\r\n \"losses\": 50,\r\n \"pastOpponents\": [\r\n \"60a64f7eae945a6e60b0e915\"\r\n ],\r\n \"pokemongs\": [\r\n {\r\n \"id\": \"60a64f7eae945a6e60b0e911\",\r\n \"nickname\": \"Sparky UPDATED\",\r\n \"species\": \"IVYSAUR\"\r\n }\r\n ]\r\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/trainer",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"trainer"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Get all trainers",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/trainer",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"trainer"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Get 1 trainer",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/trainer/60a64f7eae945a6e60b0e914",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"trainer",
|
||||||
|
"60a64f7eae945a6e60b0e914"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update 1 trainer",
|
||||||
|
"request": {
|
||||||
|
"method": "PUT",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\r\n \"schemaVersion\": 1,\r\n \"name\": \"Brock\",\r\n \"dob\": \"1994-02-18\",\r\n \"wins\": 60,\r\n \"losses\": 60,\r\n \"pastOpponents\": [\r\n \"60a64f7eae945a6e60b0e914\"\r\n ],\r\n \"pokemongs\": [\r\n {\r\n \"id\": \"60a64f7eae945a6e60b0e911\",\r\n \"nickname\": \"Sparky UPDATED\",\r\n \"species\": \"IVYSAUR\"\r\n }\r\n ]\r\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/trainer/60a64f7eae945a6e60b0e915",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"trainer",
|
||||||
|
"60a64f7eae945a6e60b0e915"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delete 1 trainer",
|
||||||
|
"request": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:8080/trainer/60a64f7eae945a6e60b0e914",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "8080",
|
||||||
|
"path": [
|
||||||
|
"trainer",
|
||||||
|
"60a64f7eae945a6e60b0e914"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"_id": { "$oid":"60a64f7eae945a6e60b0e912" },
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"name": "Vine Whip",
|
||||||
|
"power": 45,
|
||||||
|
"pp": 15,
|
||||||
|
"category": "PHYSICAL",
|
||||||
|
"accuracy": 100,
|
||||||
|
"type": {
|
||||||
|
"name": "GRASS",
|
||||||
|
"weakAgainst": ["FIRE"],
|
||||||
|
"effectiveAgainst": ["WATER", "GROUND"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"_id": { "$oid":"60a64f7eae945a6e60b0e913" },
|
||||||
|
"schemaVersion": 2,
|
||||||
|
"name": "Tackle",
|
||||||
|
"power": 40,
|
||||||
|
"category": "PHYSICAL",
|
||||||
|
"accuracy": 100,
|
||||||
|
"type": {
|
||||||
|
"name": "NORMAL",
|
||||||
|
"weakAgainst": ["ROCK"],
|
||||||
|
"effectiveAgainst": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"_id": { "$oid":"60a64f7eae945a6e60b0e917" },
|
||||||
|
"schemaVersion": 2,
|
||||||
|
"name": "Ember",
|
||||||
|
"power": 40,
|
||||||
|
"category": "SPECIAL",
|
||||||
|
"accuracy": 100,
|
||||||
|
"type": {
|
||||||
|
"name": "FIRE",
|
||||||
|
"weakAgainst": ["WATER", "GROUND"],
|
||||||
|
"effectiveAgainst": ["GRASS"]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e911"
|
||||||
|
},
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"nickname": "Sparky",
|
||||||
|
"dob": {
|
||||||
|
"$date": {
|
||||||
|
"$numberLong": "761597551000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"level": 15,
|
||||||
|
"pokedexId": 1,
|
||||||
|
"evoStage": 1,
|
||||||
|
"evoTrack": [
|
||||||
|
"BULBASAUR",
|
||||||
|
"IVYSAUR",
|
||||||
|
"VENUSAUR"
|
||||||
|
],
|
||||||
|
"trainer": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e914"
|
||||||
|
},
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"name": "GRASS",
|
||||||
|
"weakAgainst": [
|
||||||
|
"FIRE"
|
||||||
|
],
|
||||||
|
"effectiveAgainst": [
|
||||||
|
"WATER",
|
||||||
|
"GROUND"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"moveSet": [
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e913"
|
||||||
|
},
|
||||||
|
"name": "Tackle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e912"
|
||||||
|
},
|
||||||
|
"name": "Vine Whip"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e916"
|
||||||
|
},
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"nickname": "Blazey",
|
||||||
|
"dob": {
|
||||||
|
"$date": {
|
||||||
|
"$numberLong": "761597651000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"level": 10,
|
||||||
|
"pokedexId": 4,
|
||||||
|
"evoStage": 0,
|
||||||
|
"evoTrack": [
|
||||||
|
"CHARMANDER",
|
||||||
|
"CHARMELEON",
|
||||||
|
"CHARIZARD"
|
||||||
|
],
|
||||||
|
"trainer": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e915"
|
||||||
|
},
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"name": "FIRE",
|
||||||
|
"weakAgainst": [
|
||||||
|
"WATER",
|
||||||
|
"GROUND"
|
||||||
|
],
|
||||||
|
"effectiveAgainst": [
|
||||||
|
"GRASS"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"moveSet": [
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e913"
|
||||||
|
},
|
||||||
|
"name": "Tackle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e917"
|
||||||
|
},
|
||||||
|
"name": "Ember"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e914"
|
||||||
|
},
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"name": "Ash",
|
||||||
|
"dob": {
|
||||||
|
"$date": {
|
||||||
|
"$numberLong": "761598551000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"wins": 100,
|
||||||
|
"losses": 50,
|
||||||
|
"pastOpponents": [
|
||||||
|
{
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e915"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pokemongs": [
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e911"
|
||||||
|
},
|
||||||
|
"nickname": "Sparky",
|
||||||
|
"species": "IVYSAUR"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e915"
|
||||||
|
},
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"name": "Brock",
|
||||||
|
"dob": {
|
||||||
|
"$date": {
|
||||||
|
"$numberLong": "761596551000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"wins": 70,
|
||||||
|
"losses": 60,
|
||||||
|
"pastOpponents": [
|
||||||
|
{
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e914"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pokemongs": [
|
||||||
|
{
|
||||||
|
"_id": {
|
||||||
|
"$oid": "60a64f7eae945a6e60b0e916"
|
||||||
|
},
|
||||||
|
"nickname": "Blazey",
|
||||||
|
"species": "CHARMANDER"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,78 +1,122 @@
|
|||||||
package fr.uca.iut.codecs.move;
|
package fr.uca.iut.codecs.move;
|
||||||
|
|
||||||
import com.mongodb.MongoClientSettings;
|
import com.mongodb.MongoClientSettings;
|
||||||
import fr.uca.iut.codecs.GenericCodec;
|
import fr.uca.iut.codecs.GenericCodec;
|
||||||
import fr.uca.iut.codecs.type.TypeCodecUtil;
|
import fr.uca.iut.codecs.type.TypeCodecUtil;
|
||||||
import fr.uca.iut.entities.Move;
|
import fr.uca.iut.entities.Move;
|
||||||
import fr.uca.iut.entities.Type;
|
import fr.uca.iut.entities.embedded.Type;
|
||||||
import fr.uca.iut.utils.enums.MoveCategoryName;
|
import fr.uca.iut.utils.enums.MoveCategoryName;
|
||||||
import org.bson.BsonReader;
|
import org.bson.BsonReader;
|
||||||
import org.bson.BsonWriter;
|
import org.bson.BsonWriter;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.codecs.Codec;
|
import org.bson.codecs.Codec;
|
||||||
import org.bson.codecs.DecoderContext;
|
import org.bson.codecs.DecoderContext;
|
||||||
import org.bson.codecs.EncoderContext;
|
import org.bson.codecs.EncoderContext;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
public class MoveCodec extends GenericCodec<Move> {
|
|
||||||
private final Codec<Document> documentCodec;
|
public class MoveCodec extends GenericCodec<Move> {
|
||||||
|
private final Codec<Document> documentCodec;
|
||||||
public MoveCodec() {
|
|
||||||
this.documentCodec = MongoClientSettings.getDefaultCodecRegistry()
|
public MoveCodec() {
|
||||||
.get(Document.class);
|
this.documentCodec = MongoClientSettings.getDefaultCodecRegistry()
|
||||||
}
|
.get(Document.class);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void encode(BsonWriter writer, Move move, EncoderContext encoderContext) {
|
@Override
|
||||||
Document doc = new Document();
|
public void encode(BsonWriter writer, @NotNull Move move, EncoderContext encoderContext) {
|
||||||
|
Document doc = new Document();
|
||||||
doc.put("_id", new ObjectId(move.getId()));
|
|
||||||
|
doc.put("_id", new ObjectId(move.getId()));
|
||||||
doc.put("name", move.getName());
|
|
||||||
|
doc.put("schemaVersion", move.getSchemaVersion());
|
||||||
doc.put("category", move.getCategory());
|
|
||||||
|
doc.put("name", move.getName());
|
||||||
doc.put("power", move.getPower());
|
|
||||||
|
doc.put("category", move.getCategory());
|
||||||
doc.put("accuracy", move.getAccuracy());
|
|
||||||
|
doc.put("power", move.getPower());
|
||||||
Type moveType = move.getType();
|
|
||||||
Document typeDoc = new Document();
|
doc.put("accuracy", move.getAccuracy());
|
||||||
typeDoc.put("name",
|
|
||||||
moveType.getName()
|
Type moveType = move.getType();
|
||||||
.toString());
|
Document typeDoc = new Document();
|
||||||
typeDoc.put("weakAgainst", moveType.getWeakAgainst());
|
typeDoc.put("name",
|
||||||
typeDoc.put("effectiveAgainst", moveType.getEffectiveAgainst());
|
moveType.getName()
|
||||||
doc.put("type", typeDoc);
|
.toString());
|
||||||
|
typeDoc.put("weakAgainst", moveType.getWeakAgainst());
|
||||||
documentCodec.encode(writer, doc, encoderContext);
|
typeDoc.put("effectiveAgainst", moveType.getEffectiveAgainst());
|
||||||
}
|
doc.put("type", typeDoc);
|
||||||
|
|
||||||
@Override
|
documentCodec.encode(writer, doc, encoderContext);
|
||||||
public Class<Move> getEncoderClass() {
|
}
|
||||||
return Move.class;
|
|
||||||
}
|
@Override
|
||||||
|
public Class<Move> getEncoderClass() {
|
||||||
@Override
|
return Move.class;
|
||||||
public Move decode(BsonReader reader, DecoderContext decoderContext) {
|
}
|
||||||
Document document = documentCodec.decode(reader, decoderContext);
|
|
||||||
Move move = new Move();
|
@Override
|
||||||
|
public Move decode(BsonReader reader, DecoderContext decoderContext) {
|
||||||
move.setId(document.getObjectId("_id")
|
|
||||||
.toString());
|
Document document = documentCodec.decode(reader, decoderContext);
|
||||||
|
|
||||||
move.setName(document.getString("name"));
|
Integer schemaVersion = document.getInteger("schemaVersion");
|
||||||
|
|
||||||
move.setCategory(MoveCategoryName.valueOf(document.getString("category")));
|
return switch (schemaVersion) {
|
||||||
|
case 1 -> decodeV1(document);
|
||||||
move.setPower(document.getInteger("power"));
|
case 2 -> decodeV2(document);
|
||||||
|
default -> throw new IllegalArgumentException("Unsupported schema version: " + schemaVersion);
|
||||||
move.setAccuracy(document.getInteger("accuracy"));
|
};
|
||||||
|
}
|
||||||
Document typeDoc = (Document) document.get("type");
|
|
||||||
|
private @NotNull Move decodeV1(@NotNull Document document) {
|
||||||
move.setType(TypeCodecUtil.extractType(typeDoc));
|
Move move = new Move();
|
||||||
|
|
||||||
return move;
|
move.setId(document.getObjectId("_id")
|
||||||
}
|
.toString());
|
||||||
}
|
|
||||||
|
move.setSchemaVersion(document.getInteger("schemaVersion"));
|
||||||
|
|
||||||
|
move.setName(document.getString("name"));
|
||||||
|
|
||||||
|
move.setCategory(MoveCategoryName.valueOf(document.getString("category")));
|
||||||
|
|
||||||
|
move.setPower(document.getInteger("power"));
|
||||||
|
|
||||||
|
move.setAccuracy(document.getInteger("accuracy"));
|
||||||
|
|
||||||
|
Document typeDoc = (Document) document.get("type");
|
||||||
|
|
||||||
|
move.setType(TypeCodecUtil.extractType(typeDoc));
|
||||||
|
|
||||||
|
// Read and discard the old pp field
|
||||||
|
Integer pp = document.getInteger("pp");
|
||||||
|
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull Move decodeV2(@NotNull Document document) {
|
||||||
|
Move move = new Move();
|
||||||
|
|
||||||
|
move.setId(document.getObjectId("_id")
|
||||||
|
.toString());
|
||||||
|
|
||||||
|
move.setSchemaVersion(document.getInteger("schemaVersion"));
|
||||||
|
|
||||||
|
move.setName(document.getString("name"));
|
||||||
|
|
||||||
|
move.setCategory(MoveCategoryName.valueOf(document.getString("category")));
|
||||||
|
|
||||||
|
move.setPower(document.getInteger("power"));
|
||||||
|
|
||||||
|
move.setAccuracy(document.getInteger("accuracy"));
|
||||||
|
|
||||||
|
Document typeDoc = (Document) document.get("type");
|
||||||
|
|
||||||
|
move.setType(TypeCodecUtil.extractType(typeDoc));
|
||||||
|
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package fr.uca.iut.entities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The strategy for incrementing the schema version number is simple.
|
||||||
|
* <br><br>
|
||||||
|
* `schemaVersion` will have to start at 1, and need to be incremented by one at each schema change.
|
||||||
|
* <br><br>
|
||||||
|
* Every change to the schema needs to involve the schema version number being incremented.
|
||||||
|
*/
|
||||||
|
public abstract class GenericVersionedEntity extends GenericEntity {
|
||||||
|
|
||||||
|
private Integer schemaVersion;
|
||||||
|
|
||||||
|
public Integer getSchemaVersion() {
|
||||||
|
return schemaVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchemaVersion(Integer schemaVersion) {
|
||||||
|
this.schemaVersion = schemaVersion;
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +1,58 @@
|
|||||||
package fr.uca.iut.entities;
|
package fr.uca.iut.entities;
|
||||||
|
|
||||||
import fr.uca.iut.utils.enums.MoveCategoryName;
|
import fr.uca.iut.entities.embedded.Type;
|
||||||
|
import fr.uca.iut.utils.enums.MoveCategoryName;
|
||||||
public class Move extends GenericEntity {
|
|
||||||
public static final String COLLECTION_NAME = "moves";
|
public class Move extends GenericVersionedEntity {
|
||||||
|
public static final String COLLECTION_NAME = "moves";
|
||||||
private String name;
|
public static final Integer LATEST_SCHEMA_VERSION = 2;
|
||||||
private MoveCategoryName category;
|
|
||||||
private Integer power;
|
private String name;
|
||||||
private Integer accuracy;
|
private MoveCategoryName category;
|
||||||
private Type type;
|
private Integer power;
|
||||||
|
private Integer accuracy;
|
||||||
public Move() {}
|
private Type type;
|
||||||
|
|
||||||
public String getName() {
|
public Move() {
|
||||||
return name;
|
}
|
||||||
}
|
|
||||||
|
public String getName() {
|
||||||
public void setName(String name) {
|
return name;
|
||||||
this.name = name;
|
}
|
||||||
}
|
|
||||||
|
public void setName(String name) {
|
||||||
public MoveCategoryName getCategory() {
|
this.name = name;
|
||||||
return category;
|
}
|
||||||
}
|
|
||||||
|
public MoveCategoryName getCategory() {
|
||||||
public void setCategory(MoveCategoryName category) {
|
return category;
|
||||||
this.category = category;
|
}
|
||||||
}
|
|
||||||
|
public void setCategory(MoveCategoryName category) {
|
||||||
public Integer getPower() {
|
this.category = category;
|
||||||
return power;
|
}
|
||||||
}
|
|
||||||
|
public Integer getPower() {
|
||||||
public void setPower(Integer power) {
|
return power;
|
||||||
this.power = power;
|
}
|
||||||
}
|
|
||||||
|
public void setPower(Integer power) {
|
||||||
public Integer getAccuracy() {
|
this.power = power;
|
||||||
return accuracy;
|
}
|
||||||
}
|
|
||||||
|
public Integer getAccuracy() {
|
||||||
public void setAccuracy(Integer accuracy) {
|
return accuracy;
|
||||||
this.accuracy = accuracy;
|
}
|
||||||
}
|
|
||||||
|
public void setAccuracy(Integer accuracy) {
|
||||||
public Type getType() {
|
this.accuracy = accuracy;
|
||||||
return type;
|
}
|
||||||
}
|
|
||||||
|
public Type getType() {
|
||||||
public void setType(Type type) {
|
return type;
|
||||||
this.type = type;
|
}
|
||||||
}
|
|
||||||
|
public void setType(Type type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,16 +1,19 @@
|
|||||||
package fr.uca.iut.entities;
|
package fr.uca.iut.entities.denormalized;
|
||||||
|
|
||||||
public class PokemongMove extends GenericEntity {
|
import fr.uca.iut.entities.GenericEntity;
|
||||||
|
|
||||||
private String name;
|
public class PokemongMove extends GenericEntity {
|
||||||
|
|
||||||
public PokemongMove() {}
|
private String name;
|
||||||
|
|
||||||
public String getName() {
|
public PokemongMove() {
|
||||||
return name;
|
}
|
||||||
}
|
|
||||||
|
public String getName() {
|
||||||
public void setName(String name) {
|
return name;
|
||||||
this.name = name;
|
}
|
||||||
}
|
|
||||||
}
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
@ -1,56 +1,56 @@
|
|||||||
package fr.uca.iut.entities;
|
package fr.uca.iut.entities.embedded;
|
||||||
|
|
||||||
import fr.uca.iut.utils.enums.TypeName;
|
import fr.uca.iut.utils.enums.TypeName;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.List;
|
||||||
import java.util.List;
|
import java.util.Objects;
|
||||||
import java.util.Objects;
|
|
||||||
|
public class Type {
|
||||||
public class Type {
|
|
||||||
|
private TypeName name;
|
||||||
private TypeName name;
|
private List<TypeName> weakAgainst;
|
||||||
private List<TypeName> weakAgainst;
|
private List<TypeName> effectiveAgainst;
|
||||||
private List<TypeName> effectiveAgainst;
|
|
||||||
|
public Type() {
|
||||||
public Type() {}
|
}
|
||||||
|
|
||||||
public TypeName getName() {
|
public TypeName getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(TypeName name) {
|
public void setName(TypeName name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TypeName> getWeakAgainst() {
|
public List<TypeName> getWeakAgainst() {
|
||||||
return Collections.unmodifiableList(weakAgainst);
|
return weakAgainst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWeakAgainst(List<TypeName> weakAgainst) {
|
public void setWeakAgainst(List<TypeName> weakAgainst) {
|
||||||
this.weakAgainst = weakAgainst;
|
this.weakAgainst = weakAgainst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TypeName> getEffectiveAgainst() {
|
public List<TypeName> getEffectiveAgainst() {
|
||||||
return Collections.unmodifiableList(effectiveAgainst);
|
return effectiveAgainst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEffectiveAgainst(List<TypeName> effectiveAgainst) {
|
public void setEffectiveAgainst(List<TypeName> effectiveAgainst) {
|
||||||
this.effectiveAgainst = effectiveAgainst;
|
this.effectiveAgainst = effectiveAgainst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(name, weakAgainst, effectiveAgainst);
|
return Objects.hash(name, weakAgainst, effectiveAgainst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
Type type = (Type) o;
|
Type type = (Type) o;
|
||||||
return Objects.equals(name, type.name) &&
|
return Objects.equals(name, type.name) &&
|
||||||
Objects.equals(weakAgainst, type.weakAgainst) &&
|
Objects.equals(weakAgainst, type.weakAgainst) &&
|
||||||
Objects.equals(effectiveAgainst, type.effectiveAgainst);
|
Objects.equals(effectiveAgainst, type.effectiveAgainst);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in new issue