-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/1 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/1 #2
Conversation
…ed - OK. User findAll and User Find by ID initially tested - OK. Routing Requires fixing - only works on root path: localhost.
lukaszozim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Poza drobnymi uwagami to bardzo fajny poczatek
| # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" | ||
| # DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4" | ||
| # DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4" | ||
| DATABASE_URL="mysql://root:@127.0.0.1:3306/php_symfony_db?serverVersion=mariadb-10.4.22" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tu był moj błąd ze wrzucilem do repo plik .env, ogólnie podczas git add pomijaj plik .env, ja go wrzuce później do gitignora. bo w ten sposób kazdy przejmuje Twoje ustawienia bazy. To bazy lokalne ale gyby tam były dane dostępowe do prawdziwej bazy, to za to można nawet stracić robote.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
faktycznie, byłem przekonany, że z automatu go ignoruje. Przynajmniej tak było z Laravelem. Nie zwróciłem uwagi kompletnie.
migrations/Version20230908082627.php
Outdated
| public function up(Schema $schema): void | ||
| { | ||
| // this up() migration is auto-generated, please modify it to your needs | ||
| $this->addSql('ALTER TABLE user CHANGE phone_number phone_number INT DEFAULT NULL'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Z migracjami coś jest nie tak. Nie ma skryptu tworzącego tabele user. Wygląda tak jakbyś albo nie załączył pliku z migracją lub utworzył tabele bezpośrednio na bazie dnaych. Migracje nie zadziałają, bo od razu robi altera na tabeli której nie ma. Podpowiedź taka, ze trzeba wyrzucić tą migracje, zrobić doctrine:migration:diff, usunać tabelke z bazy dancyh i przeprowadzić ponowną migracje. z tabelki na bazie danych migrations należy usunac wpis w razie potrzeby
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Poprawiłem to. Mój błąd wynikał z tego, że postawilem te migracje, a potem chcialem dodac emaila i uruchomilem jeszcze raz, zanim skasowalem poprzednią, a tam z automatu wstawiło alter zamiast create.
Nie wiem czy to ma znaczenie, ale wyrzuca mi takie info przy migracjach np.
2023-09-08T15:07:24+02:00 [info] User Deprecated: Method "Symfony\Component\HttpKernel\Bundle\Bundle::build()" might add "void" as a native return type declaration in the future. Do the same in child class "Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle" now to avoid errors or add an explicit @return annotation to suppress this message.
2023-09-08T15:07:24+02:00 [info] User Deprecated: Version detection logic for MySQL will change in DBAL 4. Please specify the version as the server reports it, e.g. "10.9.3-MariaDB" instead of "mariadb-10.9". (AbstractMySQLDriver.php:130 called by AbstractMySQLDriver.php:37, doctrine/dbal#5779, package doctrine/orm)
2023-09-08T15:07:24+02:00 [info] User Deprecated: Context: trying to commit a transaction
Problem: the transaction is already committed, relying on silencing is deprecated.
Solution: override AbstractMigration::isTransactional() so that it returns false.
Automate that by setting transactional to false in the configuration.
More details at https://www.doctrine-project.org/projects/doctrine-migrations/en/stable/explanation/implicit-commits.html (TransactionHelper.php:26 called by
DbalExecutor.php:214, doctrine/migrations#1169, package doctrine/migrations)
|
|
||
| class HelloWorldController extends AbstractController | ||
| { | ||
| #[Route('/hello-world ', name: 'app_hello_world')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to nie było cześćią zadania, rozumiem, ze ocś próbowałeś. Ogólnie byłoby do usunięcia z MR jako kod niemający związku z zadaniem, ale tutaj moze zostać
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tak, chciałem zoabczyc jak cos tam zadziała. Do usunięcia zdecydowanie.
src/Controller/UserController.php
Outdated
| class UserController extends AbstractController | ||
| { | ||
|
|
||
| #[Route(' ', name: 'app_users')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dlatego działa Ci tlko na pierwszej stronie bo tak jest to zmapowane. Tu powinien być url = /users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tutaj zrobilem tak, bo jesli jest users, to właśnie wywala mi 404. zmienilem wiec na pusty, zeby przetestowac na localhost czy w ogole reszta kodu zadziałała.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeszcze raz sprawdziłem i wywala 404.
src/Controller/UserController.php
Outdated
| public function index(UserServices $userServices): JsonResponse | ||
| { | ||
| $users= $userServices->getAllUsers(); | ||
| print_r($users); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
odpowiedzią jest to co w return czyli json. tego print_r już nie stosujemy.
Jak bedziesz chcial się dowiedzieć np co będzie zwrócone lub prontować sobie poszczególne etapy procesu to pokaże Ci przydatne triki. w kazdym razie print_r do usunięcia bo zwraca dwa razy ten sam wynik.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niedopatrzenie. Przyzwyczaiłem się ciągle coś tam drukować. A triki na tego typu debugging jak najbardziej, im wiecej tym lepiej dla mnie.
| public function getUserById(UserServices $userServices): JsonResponse | ||
| { | ||
| $user = $userServices->getUserById(1); | ||
| print_r($user); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do usunięcia
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tutaj też dla testów stworzyłem. Będzie usunięte.
|
|
||
|
|
||
| #[Route('/create-user ', name: 'create_user')] | ||
| public function createUser(EntityManagerInterface $entityManager) : Response { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tu tak jak każe dokumentacja symfony, a to jest to co mówiłem, tak się nie robi. Tutaj możesz poczytać o zasadzie "thin controller" głównie w projektach opartych na MVC. Taka logika powinna zanelźć się w serwisie. A takie na sztywno wpisywane dane to fixtury, je robi się w innym miejscu. Dodawanie usera będzie trzeba mocno przerobić, ale póki co niech to zostanie. Zrobimy zadanie na refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raczej z dodawaniem usera to się spodziewalem, ze nie jest dobrze, bo jedynie chcialem przetestowac czy da rade wbic do bazy w ten sposob jak napisalem. Faktycznie korzystalem z dokumentacji, i nawet nie spodziewalem sie, ze od razu wpadne w pułapkę ;)
| #[ORM\Id] | ||
| #[ORM\GeneratedValue] | ||
| #[ORM\Column] | ||
| private ?int $id = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
od jakiegoś czau m in ze względów bezpieczeństa nie stosuje się już id tylko UUid. To może poruszymy jak się zdzwonimy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tak, jasne, wspomnij na pewno o tym. Ja wiem, ze szybciej sie wyszukuje, i duzo lepiej to chodzi. Wczoraj wieczorem jeszcze myślałęm właśnie, żeby tak zrobic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na razie to zostawiam jak jest, do momentu jak sie spotkamy.
src/Service/UserServices.php
Outdated
|
|
||
| public function getAllUsers() : array | ||
| { | ||
| $users = $this->userRepository->findAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu ten temat o którym mówiłem, czy potrafisz czytać i korzystac z kodu już napisanego. Bardzo dobrze ze wykorzystałeś już dostępne metody a nie pisałeś ich samodzielnie.
| */ | ||
| class UserRepository extends ServiceEntityRepository | ||
| { | ||
| public function __construct(ManagerRegistry $registry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To co tu zrobiłes jest jak najbardziej OK, jest to klasyczne DI, natomiast zgodnie ze sztuką najlepiej jest opierać się o wzorzec IoC (Inversion of controll) ściśle związane z DI ale daje jedną kluczową zalete nie towrzysz zależności do klas rzeczywistych tylko opierasz się na abstrakcji, czyli interfejsach. To niech zostanie póki co , w zadaniu z refaktorem to poprawisz jak doczytasz na czym to polega lub jak sobie o tym opowiemy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to temat grubszy dla mnie i pewnie trzeba będzie to ze mną przeorać porzadniej cos czuję. To zrobiłem tak lekko na czuja prawde mówiąc a wolałbym wiedziec co robie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ogólnie tak jak zrobiłeś to jest akceptowalne, natomiast można to zrobić lepiej
1705933 to
74812d1
Compare
|
Dobra robota! |
first pull request.
ORM installed
migration for User
UserServices
*to verify the expected output form UserController