Skip to content

Instantly share code, notes, and snippets.

@arijit83sarkar
arijit83sarkar / Product.java
Last active October 19, 2024 20:22
A simple Product class with its various properties.
public class Product {
private String title;
private String description;
private double price;
private double discountPercentage;
private double rating;
private int stock;
private String brand;
private String category;
public class OAuthService {
public void signIn(String medium, String userName, String password) {
if (medium.equals("google")) {
System.out.println("Sign in with your Google account!");
}
if (medium.equals("facebook")) {
System.out.println("Sign in with your Facebook account!");
}
if (medium.equals("github")) {
System.out.println("Sign in with your Github account!");
@arijit83sarkar
arijit83sarkar / UserService.java
Last active February 18, 2024 18:29
Single Responsibility Principle - UserService.java
import java.util.ArrayList;
import java.util.List;
public class UserService {
public List<String> cart = new ArrayList<>();
public void registerNewUser(String mailID) {
System.out.println("Register a new user .....");
}
@arijit83sarkar
arijit83sarkar / StreamForEach.java
Created August 12, 2023 15:46
Java Stream API - Terminal Operation - forEach
import java.util.List;
import java.util.function.Consumer;
public class StreamForEach {
public static void main(String[] args) {
List<Product> productList = ProductList.getProductList();
// get all product details
productList.stream().forEach(System.out::println);
System.out.println("--------------------------------------------------------------------");
@arijit83sarkar
arijit83sarkar / ProductList.java
Last active October 10, 2024 14:49
Product List - dummy
// imports are removed
public class ProductList {
public static List<Product> getProductList() {
List<Product> products = new ArrayList<>();
products.add(new Product("iPhone 9", "An apple mobile", 549, 12.96, 4.69, 94, "Apple", "smartphones"));
products.add(new Product("iPhone X", "An apple mobile", 899, 17.94, 4.44, 34, "Apple", "smartphones"));
products.add(new Product("Samsung Universe 9", "Samsung's new variant", 1249, 15.46, 4.09, 36, "Samsung", "smartphones"));
products.add(new Product("MacBook Pro", "MacBook Pro 2021 with mini-LED display", 1749, 11.02, 4.57, 83, "Samsung", "laptops"));
products.add(new Product("perfume Oil", "Mega Discount", 13, 8.4, 4.26, 65, "Impression of Acqua Di Gio", "fragrances"));
products.add(new Product("Pubg Printed Graphic T-Shirt", "Vibrant & colorful printing on front", 46, 16.44, 4.62, 136, "The Warehouse", "mens-shirts"));
@arijit83sarkar
arijit83sarkar / CustomerController.java
Created May 21, 2023 19:05
How To Use JDBCTemplate In Spring Boot With Swagger OpenAPI
package com.raven.jdbctemplate.controller;
import com.raven.jdbctemplate.model.CustomerModel;
import com.raven.jdbctemplate.repository.CustomerJDBCRepository;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
@arijit83sarkar
arijit83sarkar / CustomerJDBCRepository.java
Created May 21, 2023 19:03
How To Use JDBCTemplate In Spring Boot With Swagger OpenAPI
package com.raven.jdbctemplate.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
import com.raven.jdbctemplate.model.CustomerModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
@arijit83sarkar
arijit83sarkar / CustomerRepository.java
Created May 21, 2023 19:01
How To Use JDBCTemplate In Spring Boot With Swagger OpenAPI
package com.raven.jdbctemplate.repository;
import java.util.List;
import java.util.Optional;
import com.raven.jdbctemplate.model.CustomerModel;
public interface CustomerRepository {
// gets the total record count
int count();
@arijit83sarkar
arijit83sarkar / CustomerModel.java
Created May 21, 2023 18:58
How To Use JDBCTemplate In Spring Boot With Swagger OpenAPI
package com.raven.jdbctemplate.model;
public class CustomerModel {
private int customerNumber = 0;
private String customerName = "";
private String phone = "";
private String address1 = "";
private String city = "";
private String country = "";
@arijit83sarkar
arijit83sarkar / ApplicationConfiguration.java
Last active May 21, 2023 18:56
How To Use JDBCTemplate In Spring Boot With Swagger OpenAPI
package com.raven.jdbctemplate.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;