Skip to content

Instantly share code, notes, and snippets.

View vladdedita's full-sized avatar

Vlad Dedita vladdedita

  • Suceava
View GitHub Profile
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authz) -> authz
.requestMatchers("/login", "/register")
.permitAll() // Login and register endpoints are accessible to allf
.anyRequest()
.authenticated() // Any other requests require authentication
)
.httpBasic(withDefaults()); // Enables basic authentication with default settings
@RestController
@RequestMapping("/coffees")
public class CoffeeController {
@GetMapping("/{criteria}/details/{details}/reviews")
public String getCoffeeDetailsAndReviews(@MatrixVariable(pathVar = "criteria") Map<String, String> criteriaMatrixVars,
@MatrixVariable(pathVar = "details") Map<String, String> detailsMatrixVars) {
String roast = criteriaMatrixVars.get("roast");
String origin = criteriaMatrixVars.get("origin");
String flavor = criteriaMatrixVars.get("flavor");
@Service
public class MyService {
public void methodA() {
// This method calls methodB internally
this.methodB();
}
@Cacheable("myCache")
public String methodB() {
@Service
public class MessageProcessingService {
private final MessageProcessor<TextMessage> textMessageProcessor;
private final MessageProcessor<ImageMessage> imageMessageProcessor;
@Autowired
public MessageProcessingService(MessageProcessor<TextMessage> textMessageProcessor,
MessageProcessor<ImageMessage> imageMessageProcessor) {
this.textMessageProcessor = textMessageProcessor;
public interface MessageProcessor<T> {
void process(T message);
}
@Component
public class TextMessageProcessor implements MessageProcessor<TextMessage> {
@Override
public void process(TextMessage message) {
// Processing logic for text messages
}
@Service
public class NotificationManager {
@Autowired
private List<NotificationService> notificationServices;
public void sendNotifications(String message, String recipient) {
for (NotificationService service : notificationServices) {
service.sendNotification(message, recipient);
}
}
public interface NotificationService {
void sendNotification(String message, String recipient);
String getServiceName();
}
@Component
public class EmailNotificationService implements NotificationService {
public void sendNotification(String message, String recipient) { /* Email sending logic */ }
public String getServiceName() { return "Email"; }
}
@Component
public abstract class SingletonService {
public void usePrototype() {
PrototypeService prototypeService = createPrototypeService();
prototypeService.doSomething();
}
@Lookup
public PrototypeService createPrototypeService() {
@Component
public abstract class SingletonService {
public void usePrototype() {
PrototypeService prototypeService = createPrototypeService();
prototypeService.doSomething();
}
@Lookup
protected abstract PrototypeService createPrototypeService();
@vladdedita
vladdedita / CheckoutForm.js
Created March 3, 2021 18:54
Full Scope of Checkout Form
const CheckoutFormComponent = (props) => {
const stripe = useStripe();
const elements = useElements();
const { fullName, email } = props;
const [cardType, setCardType] = useState("");
useEffect(() => {}, []);
const handleSubmit = async (event) => {
// Block native form submission.