Code Explainers

Code explainers tagged #annotations

python
from django.db import models
from django.db.models import F, Sum, DecimalField
from django.db.models.functions import Coalesce
 

Recomputing order totals in Django

annotations aggregation custom-manager
Intermediate 9 steps
java
@ControllerAdvice
public class DeprecationHeaderAdvice implements ResponseBodyAdvice<Object> {
 
    private final Clock clock;

Adding deprecation headers in Spring

response interception http headers api deprecation
Intermediate 8 steps
java
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = PasswordsMatchValidator.class)
public @interface PasswordsMatch {

Custom cross-field validation in Spring

bean-validation custom-constraints cross-field-validation
Intermediate 8 steps
java
package com.example.config.condition;
 
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;

A custom @Conditional feature flag in Spring

conditional beans feature flags annotations
Intermediate 7 steps
java
@RestController
@RequestMapping("/api/documents")
@RequiredArgsConstructor
public class DocumentController {

Method-level authorization with @PreAuthorize in Spring

authorization spel rest-api
Intermediate 7 steps
java
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface CurrentUser {
}

Injecting the current user in Spring MVC

annotations dependency-injection security
Intermediate 8 steps
java
public class EventBus {
 
    private final Map<Class<?>, List<Subscriber>> subscribers = new ConcurrentHashMap<>();
    private final Executor executor;

Building an annotation-driven EventBus in Java

publish-subscribe reflection annotations
Intermediate 7 steps
python
from django.db.models import Prefetch, Count
from django.views.generic import ListView
 
from .models import Article, Comment

Building an efficient article list in Django

orm query-optimization prefetching
Intermediate 6 steps
java
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = StrongPasswordValidator.class)
@Documented

Building a custom @StrongPassword validator in Spring

bean-validation annotations regex
Intermediate 7 steps
python
from django.db.models import Sum, Count, F, DecimalField
from django.db.models.functions import TruncMonth, Coalesce
 
from .models import Order

Build a monthly revenue report in Django

aggregation orm group-by
Advanced 7 steps