3 Komitmen 68d9a23ada ... 1ab7809b1d

Pembuat SHA1 Pesan Tanggal
  Adrien Carteron 1ab7809b1d [FEAT] add readme 2 tahun lalu
  Adrien Carteron f5c782b392 [FEAT] add docker stuff to embed the service and the db 2 tahun lalu
  Adrien Carteron c956e6a653 [FIX] add check if player exists 2 tahun lalu

+ 20 - 0
Docker/Dockerfile

@@ -0,0 +1,20 @@
+FROM gradle:8.0.2-jdk19-alpine
+
+MAINTAINER Adrien Carteron <acarteron@cha-sam.re>
+
+ENV SCHEME=''
+ENV HOST=''
+ENV PORT=''
+ENV NAME=''
+ENV COLLECTION=''
+
+RUN apk update && apk add g++ &&\
+cd /opt &&\
+git clone -b master https://git.cha-sam.re/acarteron/Tournament.git &&\
+cd Tournament &&\
+    gradle build &&\
+    unzip build/distributions/playerRank-0.0.1.zip -d /opt &&\
+apk del unzip
+
+EXPOSE 8080
+ENTRYPOINT /opt/playerRank-0.0.1/bin/playerRank

+ 29 - 0
Docker/docker-compose.yaml

@@ -0,0 +1,29 @@
+version: '3'
+services:
+  tournament:
+    build:
+      dockerfile: Dockerfile
+    ports:
+      - 8080:8080
+    depends_on:
+      - mongodb
+    networks:
+      - my-network
+    environment:
+      - SCHEME=mongodb
+      - HOST=mongodb
+      - PORT=27017
+      - NAME=tournament
+      - COLLECTION=users
+    links:
+      - mongodb
+  mongodb:
+    image: mongodb/mongodb-community-server:6.0-ubi8
+    networks:
+      - my-network
+    expose:
+      - 27017
+
+networks:
+  my-network:
+    driver: bridge

+ 58 - 0
README.md

@@ -0,0 +1,58 @@
+# Implementation
+
+## Requirements
+* Gradle
+* Mongodb
+
+## Compile
+```
+gradle build
+```
+## Run
+```
+unzip build/distributions/playerRank-0.0.1.zip -d <location>
+/<location>/playerRank-0.0.1/bin/playerRank
+```
+starts web server with api: http://localhost:8080/
+
+## Run test
+```
+gradle test --tests "re.chasam.models.impl.TournamentImplTest"
+gradle test --tests "re.chasam.models.impl.PlayerTest"
+```
+
+## Mongo connexion
+Its access follows the format:
+```
+scheme://host:port
+```
+to access to a db and use collection.
+Defaults parameters can be overriden using environments variables:
+```
+SCHEME
+HOST
+PORT
+NAME
+COLLECTION
+```
+
+## Docker
+
+```
+cd Docker
+docker compose up
+```
+
+## API
+### GET /players  
+lists all players with name score and rank
+### GET /player/{id}
+get a player score and its rank
+### POST /players {"name":"a name"}
+add a new player, its score and rank are set to 0
+### PATCH /players/{id} {"score":42}
+set the score of a player
+### DELETE /players
+remove all players
+
+

+ 2 - 1
src/main/kotlin/re/chasam/routes/PlayersRoutes.kt

@@ -33,11 +33,12 @@ fun Route.playersRouting() {
         post {
             val player = call.receive<Player>()
             println("post $player")
-            tournamentImpl.addOrUpdate(player)
+            tournamentImpl.addOrUpdate(Player(player.name))
             call.respondText("player stored correctly", status = HttpStatusCode.Created)
         }
         patch("{id?}") {
             val id = call.parameters["id"] ?: return@patch call.respondText("Bad Request", status = HttpStatusCode.BadRequest)
+            tournamentImpl.getPlayer(id) ?: return@patch call.respondText("No player found", status = HttpStatusCode.NotFound)
             val player = call.receive<Player>()
             println("post $id $player")
             tournamentImpl.addOrUpdate(id, player.score)