Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
loicsantschi01 committed Dec 19, 2023
2 parents 49dd7ac + 0ac8184 commit fbcd94d
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
chmod 600 ~/.ssh/pkey
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/pkey
ssh ${{ secrets.SECRET_USER }}@${{ secrets.SECRET_HOST }} -p ${{ secrets.SECRET_PORT }} "cd ./project/Swissdle && git pull origin main && cd backend-laravel && php artisan db:wipe --force && php artisan migrate --force && php artisan db:seed --force && composer install && php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider" && cd ../frontend-vue && npm install && npm run build && (crontab -l && crontab -r) || echo '* * * * * cd /home/laravel/project/Swissdle/backend-laravel && /usr/local/bin/php artisan schedule:run >> /home/laravel/project/Swissdle/cron.log' | crontab"
ssh ${{ secrets.SECRET_USER }}@${{ secrets.SECRET_HOST }} -p ${{ secrets.SECRET_PORT }} "cd ./project/Swissdle && git pull origin main && cd backend-laravel && php artisan db:wipe --force && php artisan migrate --force && php artisan db:seed --force && composer install && php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider" && php artisan l5-swagger:generate && cd ../frontend-vue && npm install && npm run build && (crontab -l && crontab -r) || echo '*/5 * * * * cd /home/laravel/project/Swissdle/backend-laravel && /usr/local/bin/php artisan schedule:run >> /home/laravel/project/Swissdle/cron.log' | crontab"
64 changes: 64 additions & 0 deletions backend-laravel/app/Http/Controllers/VilleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,77 @@ public function today()
return $ville;
}

/**
* Make a guess
*
* @OA\Get(
* path="/api/ville/guess/{id}",
* summary="Get a guess for a city based on the provided ID.",
* description="Retrieve information about the guessed city.",
* operationId="getGuess",
* tags={"Ville"},
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* description="The ID of the guessed city.",
* @OA\Schema(type="integer")
* ),
*
* @OA\Response(
* response=200,
* description="Successful response",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="ville", ref="#/components/schemas/Ville"),
* @OA\Property(property="canton_diff", type="boolean", description="Whether the guessed city's canton matches the current city's canton"),
* @OA\Property(property="pop_diff", type="integer", description="Population comparison result"),
* @OA\Property(property="lang_diff", type="string", description="Language comparison result"),
* @OA\Property(property="position_diff", type="string", description="Position comparison result"),
* )
* ),
*
* @OA\Response(
* response=404,
* description="Ville not found"
* )
* )
*
* @return App\Utility\CityComparator::compareToToday
*/
public function guess($id)
{
// TODO: clean id
$a = new CityComparator();
return $a->compareToToday($id);
}

/**
* Get all Villes.
*
* @OA\Get(
* path="/api/villes",
* summary="Get all cities",
* description="Retrieve information about all cities.",
* operationId="getAll",
* tags={"Ville"},
* @OA\Response(
* response=200,
* description="Successful response",
* @OA\JsonContent(
* type="array",
* @OA\Items(ref="#/components/schemas/Ville")
* )
* ),
*
* @OA\Response(
* response=404,
* description="Ville not found"
* )
* )
*
* @return \Illuminate\Http\JsonResponse
*/
public function all()
{
$villes = Ville::all();
Expand Down
85 changes: 85 additions & 0 deletions backend-laravel/storage/api-docs/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,91 @@
}
}
}
},
"/api/ville/guess/{id}": {
"get": {
"tags": [
"Ville"
],
"summary": "Get a guess for a city based on the provided ID.",
"description": "Retrieve information about the guessed city.",
"operationId": "getGuess",
"parameters": [
{
"name": "id",
"in": "path",
"description": "The ID of the guessed city.",
"required": true,
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"properties": {
"ville": {
"$ref": "#/components/schemas/Ville"
},
"canton_diff": {
"description": "Whether the guessed city's canton matches the current city's canton",
"type": "boolean"
},
"pop_diff": {
"description": "Population comparison result",
"type": "integer"
},
"lang_diff": {
"description": "Language comparison result",
"type": "string"
},
"position_diff": {
"description": "Position comparison result",
"type": "string"
}
},
"type": "object"
}
}
}
},
"404": {
"description": "Ville not found"
}
}
}
},
"/api/villes": {
"get": {
"tags": [
"Ville"
],
"summary": "Get all cities",
"description": "Retrieve information about all cities.",
"operationId": "getAll",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Ville"
}
}
}
}
},
"404": {
"description": "Ville not found"
}
}
}
}
},
"components": {
Expand Down
4 changes: 2 additions & 2 deletions frontend-vue/src/components/DailyCity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default {
</script>
<style scoped>
img {
width: 70%;
height: 50vh;
width: 55%;
height: 55vh;
object-fit: cover;
border-radius: 5px;
}
Expand Down
43 changes: 31 additions & 12 deletions frontend-vue/src/components/HintsDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,28 @@
</div>
</div>
<template v-for="guess in guesses.slice().reverse()" :key="guess.city.id">
<div class="hint" :class="(guess.city.name == nameDailyCity ?'good-guess' : 'bad-guess')">
<div class="hint" :class="(guess.city.name == nameDailyCity ? 'good-guess' : 'bad-guess')">
<div class="city">
<p class="montserrat">{{ guess.city.name }}</p>
</div>
<div class="lang" :class="'hint-' + (guess.lang_diff == 0 ? '0' : '1')">
<p class="montserrat">{{ guess.city.langues }}</p>
<p class="montserrat">{{ formatLanguages(guess.city.langues) }}</p>
</div>
<div class="canton" :class="'hint-' + (guess.canton_diff ? '0' : '1')">
<p class="montserrat">{{ guess.city.canton.name }}</p>
</div>
<div class="population">
<div class="population" :class="{
'hint-1': Math.abs(guess.city.population - populationDailyCity) > 50000,
'hint-orange': Math.abs(guess.city.population - populationDailyCity) > 25000 && Math.abs(guess.city.population - populationDailyCity) <= 50000,
'hint-yellow': Math.abs(guess.city.population - populationDailyCity) <= 25000
}">
<p class="montserrat"> {{ guess.city.population }}</p>
<DirectionalArrow :populationDiff="guess.pop_diff" v-if="guess.pop_diff != 0"/>
<DirectionalArrow :populationDiff="guess.pop_diff" v-if="guess.pop_diff != 0" />
</div>
<div class="distance hint-grey">
<p class="montserrat">~{{ Math.round(guess.position_diff.distance) }}km</p>
<DirectionalArrow :angleToDailyCity="guess.position_diff.direction" v-if="guess.position_diff.distance != 0" />
<DirectionalArrow :angleToDailyCity="guess.position_diff.direction"
v-if="guess.position_diff.distance != 0" />
</div>
</div>
</template>
Expand All @@ -57,6 +62,15 @@ export default {
DirectionalArrow,
},
methods: {
formatLanguages(langues) {
if (Array.isArray(langues) && langues.length > 0) {
const languageNames = langues.map(langue => langue.name);
return languageNames.join('/');
}
return '';
}
},
computed: {
guesses() {
Expand All @@ -65,34 +79,37 @@ export default {
nameDailyCity() {
return CityService.getDailyCity() ? CityService.getDailyCity().name : "";
},
populationDailyCity() {
return CityService.getDailyCity() ? CityService.getDailyCity().population : "";
}
},
mounted() { }
}
</script>
<style scoped>
#hints-display-component {
padding-top: 30px;
margin-bottom: 30px;
}
.hint,
.hint-titles {
display: flex;
}
.hint > div {
.hint>div {
flex: 1;
border: 1px solid black;
padding: 10px 5px;
margin: 10px 5px;
margin: 5px 5px;
}
.hint-titles > div {
.hint-titles>div {
flex: 1;
padding: 10px 5px;
}
.hint-titles p {
font-size: 20px;
display: inline-block;
border-bottom: 2px solid black;
}
Expand All @@ -101,16 +118,18 @@ export default {
background-color: #FD9696;
}
.hint.good-guess > div {
.hint.good-guess>div {
background-color: #83D881;
}
.hint div p,
.hint-titles div p {
font-size: 15px;
margin: 0;
}
.distance, .population {
.distance,
.population {
display: flex;
justify-content: center;
}
Expand All @@ -131,7 +150,7 @@ export default {
background-color: #FAE46E;
}
.hint-grey{
.hint-grey {
background-color: #D9D9D9;
}
</style>

0 comments on commit fbcd94d

Please sign in to comment.