java
@Entity
@Table(name = "invoices")
@FilterDef(
    name = "tenantFilter",
    parameters = @ParamDef(name = "tenantId", type = String.class)
)

Per-Tenant Row Filtering with Hibernate @Filter Enabled Per Request

hibernate jpa multi-tenancy
by codesnips 4 tabs
javascript
const express = require('express');
const controller = require('../controllers/userController');

const router = express.Router();

router.use((req, res, next) => {

Versioning an Express API with Router-per-Version Mounts and a Shared Controller Module

express api-versioning rest
by codesnips 4 tabs
typescript
export interface CartItem {
  id: string;
  name: string;
  price: number;
  quantity: number;
}

Type-Safe Shopping Cart with useReducer, Context, and a useCart Hook

react context usereducer
by codesnips 4 tabs
ruby
module EventBus
  @subscribers = Hash.new { |h, k| h[k] = [] }

  class << self
    def subscribe(event_class, handler = nil, &block)
      callable = handler || block

In-Process Domain Event Bus with Subscribers in Rails

rails domain-events event-bus
by codesnips 4 tabs
python
from decimal import Decimal

from django.db import models
from django.db.models import F, ExpressionWrapper, DecimalField

Annotate Invoice Line Totals in a Django ListView Queryset

django orm queryset
by codesnips 3 tabs
go
package validate

import (
	"regexp"
	"unicode/utf8"
)

Per-Field Signup Validation Errors With a Reusable Validator in Go

go validation http
by codesnips 2 tabs
rust
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Currency {
    pub code: &'static str,
    pub symbol: &'static str,
    pub exponent: u32,
}

Locale-Aware Money Formatting With Minor Units in Rust

rust money currency
by codesnips 3 tabs
java
@RestController
@RequestMapping("/api/orders")
public class OrderController {

    private final OrderService orderService;

Testing a Spring Boot Controller Slice with @WebMvcTest, MockMvc and a Mocked Service

spring-boot testing mockmvc
by codesnips 3 tabs
sql
CREATE TABLE idempotency_keys (
    id              BIGSERIAL PRIMARY KEY,
    idempotency_key TEXT        NOT NULL,
    request_path    TEXT        NOT NULL,
    request_fingerprint TEXT    NOT NULL,
    status          TEXT        NOT NULL DEFAULT 'in_progress',

Idempotent POST Requests with an Idempotency-Key Middleware in Express

express idempotency middleware
by codesnips 3 tabs
typescript
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';

export interface ConfirmDialogData {
  title: string;
  message: string;

Reusable Angular Confirmation Dialog Service Returning an Observable of the User's Choice

angular rxjs observables
by codesnips 3 tabs
java
package com.example.health;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

Custom Spring Boot HealthIndicator for Queue Depth on /actuator/health

spring-boot actuator health-check
by codesnips 4 tabs
rust
use anyhow::{anyhow, Result};
use chrono::{DateTime, Utc};
use cron::Schedule as CronSchedule;
use std::str::FromStr;

pub struct Schedule {

Parse Cron Expressions and Run Due Recurring Jobs in Rust with Tokio

rust tokio cron
by codesnips 3 tabs