Skip to content

Commit

Permalink
Route to post songs (#21)
Browse files Browse the repository at this point in the history
* #5 moved Album-Query to it's own class

* #10 added code sniffer

* #10 more styling fixes

* #10 updated the CLI variable in the Makefile

* #10 added lyrics to the songs

* #10 added words to the lyrics

* #10 code style fix

* #10 added qaqaz_latin library
- library is now resposible for latin
- started adding post route

* #10 added song specific cover-art for song

* #10
* made APIResponse static
* fixed response types in the mysql classes
* added param to former badData response

* #20 responseData is now optional

* #20 POST /song now writes to Album, Artist, Lyrics, Song, SongArtists

* #20 added method to write to AlbumArtists

* #20 fixed exception on unused id

* #20 added media to post route

* #20 added media to get route

* #20 renamed SongDataMapper back
  • Loading branch information
tolik518 authored Jun 21, 2023
1 parent d4c7932 commit b96256d
Show file tree
Hide file tree
Showing 23 changed files with 724 additions and 146 deletions.
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

CLI = docker-compose -f docker/compose/docker-compose-cli.yml
CLI = docker-compose -f docker/compose/docker-compose-cli.yml run --rm --no-deps php_cli
PHPUNIT = /var/www/html/vendor/bin/phpunit

.PHONY: build_dev
build_dev:
@echo "\n+++++ BUILD +++++"
docker build -f docker/php/Dockerfile . \
-t qazaq_genius/lyrics_api/php:dev
docker build -f docker/nginx/Dockerfile . \
Expand All @@ -23,24 +24,39 @@ stop:

.PHONY: install
install:
$(CLI) run --rm --no-deps php_cli php -d memory_limit=-1 /usr/local/bin/composer install
$(CLI) php -d memory_limit=-1 /usr/local/bin/composer install

.PHONY: autoload
autoload:
$(CLI) run --rm --no-deps php_cli php -d memory_limit=-1 /usr/local/bin/composer dumpautoload
$(CLI) php -d memory_limit=-1 /usr/local/bin/composer dumpautoload

.PHONY: update
update:
$(CLI) run --rm --no-deps php_cli php -d memory_limit=-1 /usr/local/bin/composer update
$(CLI) php -d memory_limit=-1 /usr/local/bin/composer update

.PHONY: logs
logs:
docker-compose -f docker/compose/docker-compose-dev.yml logs

.PHONY: tests
tests:
$(CLI) run php_cli php -dxdebug.coverage_enable=1 -dxdebug.mode=coverage $(PHPUNIT) \
@echo "\n+++++ TESTS +++++"
$(CLI) php -dxdebug.coverage_enable=1 -dxdebug.mode=coverage $(PHPUNIT) \
--coverage-clover tests/reports/coverage/phpunit.coverage.xml \
--configuration tests/phpunit.xml
sed -i "s|/var/www/html|$$(pwd)/code|g" code/tests/reports/coverage/phpunit.coverage.xml #replace docker folder path with out
git update-index --assume-unchanged code/tests/reports/coverage/phpunit.coverage.xml #ignore changes in the coverage file, but keep in version control
git update-index --assume-unchanged code/tests/reports/coverage/phpunit.coverage.xml #ignore changes in the coverage file, but keep in version control

.PHONY: sniff
sniff: install
@echo "\n+++++ SNIFFER +++++"
set -e
$(CLI) /bin/sh -c "vendor/bin/phpcs -w -p -s --standard=vendor/flyeralarm/php-code-validator/ruleset.xml src/ tests/"

.PHONY: sniffer_fix
sniffer_fix: install
@echo "+++++ SNIFFER FIXER+++++"
set -e
$(CLI) /bin/sh -c "vendor/bin/phpcbf --standard=vendor/flyeralarm/php-code-validator/ruleset.xml src/ tests/"
docker-compose down -v --remove-orphans

5 changes: 3 additions & 2 deletions code/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"php": "8.2.*",
"ext-pdo": "*",
"slim/slim": "4.*",
"slim/psr7": "^1.3"
"slim/psr7": "^1.3",
"qazaq_genius/qazaq_cyrillic_to_latin": "dev-master"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"flyeralarm/php-code-validator": "3.*",
"flyeralarm/php-code-validator": "^3.0.0",
"phpunit/phpunit": "9.5.*"
}
}
93 changes: 78 additions & 15 deletions code/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion code/public/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
declare(strict_types=1);
namespace Qazaq_Genius\Lyrics_Api;
namespace QazaqGenius\LyricsApi;

use Slim\Factory\AppFactory;

Expand Down
37 changes: 33 additions & 4 deletions code/src/ApiResponse.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Qazaq_Genius\Lyrics_Api;
namespace QazaqGenius\LyricsApi;

use Slim\Psr7\Response;

class ApiResponse
{
public function sucessful($response, $responseData, $statusCode = 200)
public static function sucessful(Response $response, array $responseData = [], int $statusCode = 200): Response
{
$response->getBody()->write(
json_encode(
Expand All @@ -17,9 +17,38 @@ public function sucessful($response, $responseData, $statusCode = 200)
return $response->withStatus($statusCode)->withHeader('Content-Type', 'application/json');
}

public function noData()
public static function noData(): Response
{
$response = new Response();
return $response->withStatus(204)->withHeader('Content-Type', 'application/json');
}
}

public static function errorMissingData(Response $response, array $missingFields = []): Response
{
if (empty($missingFields))
{
$response->getBody()->write(
json_encode(
[
"code" => "ERROR_MISSING_DATA",
"message" => "Some data is missing in the JSON data"
],
JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR
)
);
} else {
$missingFieldsString = implode(", ", $missingFields);
$response->getBody()->write(
json_encode(
[
"code" => "ERROR_MISSING_DATA",
"message" => "$missingFieldsString is missing in the JSON data"
],
JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR
)
);
}

return $response->withStatus(400)->withHeader('Content-Type', 'application/json');
}
}
Loading

0 comments on commit b96256d

Please sign in to comment.