Skip to content

Instantly share code, notes, and snippets.

View caiaffa's full-sized avatar
🏠
Working from home

LuΓ­s Felipe caiaffa

🏠
Working from home
View GitHub Profile
@caiaffa
caiaffa / api-filter-query.ts
Created October 23, 2024 21:54 — forked from MarZab/api-filter-query.ts
NestJS Filters with Swagger deepObject (example: `?filters[name]=thing1&filters[description]=thing2`)
import { applyDecorators } from '@nestjs/common';
import { ApiExtraModels, ApiQuery, getSchemaPath } from '@nestjs/swagger';
/**
* Combines Swagger Decorators to create a description for `filters[name]=something`
* - has support for swagger
* - automatic transformation with nestjs
*/
// eslint-disable-next-line @typescript-eslint/ban-types,@typescript-eslint/explicit-module-boundary-types
export function ApiFilterQuery(fieldName: string, filterDto: Function) {
@caiaffa
caiaffa / import.md
Created November 15, 2022 23:51 — forked from iamstoick/import.md
How to import database in MySQL in Docker?

This is a simple way of importing MySQL database in Docker.

  1. In you Dockerfile you must have a shared folder. Shared folder is a directory in your host machine that is mounted to Docker instance.

  2. Put the exported sql file in the shared folder.

  3. Login to your Docker instance via docker exec -it DOCKER_CONTAINER_ID bin/bash.

  4. Login to MySQL via mysql -u USERNAME -p.

@caiaffa
caiaffa / keycloak_db_overview_4.0.0.CR1-SNAPSHOT.svg
Created April 19, 2022 13:18 — forked from thomasdarimont/keycloak_db_overview_4.0.0.CR1-SNAPSHOT.svg
Keycloak Database Overview 4.0.0.CR1-SNAPSHOT (06bb6f00e5)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@caiaffa
caiaffa / 1.srp.py
Created December 2, 2021 12:15 — forked from dmmeteo/1.srp.py
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
β€œβ€¦You had one jobβ€β€Šβ€”β€ŠLoki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
β”œβ”€β”€ src
β”‚ β”œβ”€β”€ Api # API layer
| | β”œβ”€β”€ UseCases # API business rules in use cases
| | | β”œβ”€β”€ GetTodos # Use Case to get all the todo tasks
| | | | β”œβ”€β”€ TodoController.cs # Todo Controller for the Get All
| | | | β”œβ”€β”€ GetTodosPresenter.cs # Presenter
β”‚ β”œβ”€β”€ Application # Application layer
| | β”œβ”€β”€ Boundaries # Input and output ports helping us to cross boundaries
| | β”œβ”€β”€ Services # Application services to handle application business logic
| | β”œβ”€β”€ UseCases # Use cases interactors
@caiaffa
caiaffa / new_task.py
Created September 24, 2020 15:34 — forked from reedsa/new_task.py
RabbitMQ Retry using Dead Letter Exchange in Python/Pika
#!/usr/bin/env python
# http://www.rabbitmq.com/tutorials/tutorial-two-python.html
import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
message = ' '.join(sys.argv[1:]) or "Hello World!"
public function findDataByProductId(int $productId)
{
$qb = $this->createQueryBuilder('p');
$qb
->select('p, pmmp')
->leftJoin('p.contractsRenovation', 'pmmp')
->where('p.id = :productId')
->setParameter('productId', $productId);
$qb = $this->createQueryBuilder('p');
$qb
->select('partial p.{id, name}, partial pmmp.{id}')
->leftJoin('p.contractsRenovation', 'pmmp')
->where('p.id = :productId')
->setParameter('productId', $productId);
return $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
class ProductDto
{
/**
@caiaffa
caiaffa / one-to-many-to-one.php
Created August 6, 2020 20:44 — forked from jaspernbrouwer/one-to-many-to-one.php
Basic Doctrine 2 one-to-many/many-to-one association setup
<?php
/*
* This is a basic setup for Doctrine 2 one-to-many/many-to-one associations.
*
* There are many alternative approaches, additions and optimizations possible,
* but this example is only meant to help people getting started with the concept.
*/
namespace My\Entity;