Skip to content

Instantly share code, notes, and snippets.

View lakshyajit165's full-sized avatar
💭
Busy Coding...

Lakshyajit Laxmikant lakshyajit165

💭
Busy Coding...
View GitHub Profile
@lakshyajit165
lakshyajit165 / RateLimitController.java
Created February 4, 2023 07:04
RedisSpringRateLimiting-RateLimitController.java
package com.example.redisspringratelimiting.controller;
import com.example.redisspringratelimiting.config.RateLimitConfig;
import com.example.redisspringratelimiting.model.ApiResponse;
import io.github.bucket4j.Bucket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@lakshyajit165
lakshyajit165 / RedisspringratelimitingApplicationTests.java
Created February 4, 2023 07:00
RedisspringratelimitingApplication-RedisspringratelimitingApplicationTests.java
package com.example.redisspringratelimiting;
import com.example.redisspringratelimiting.config.RateLimitConfig;
import com.example.redisspringratelimiting.config.RedisConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
@lakshyajit165
lakshyajit165 / RateLimitConfig.java
Created February 4, 2023 06:45
ResispringRatelimiting-RateLimitConfig.java
package com.example.redisspringratelimiting.config;
import io.github.bucket4j.Bandwidth;
import io.github.bucket4j.Bucket;
import io.github.bucket4j.BucketConfiguration;
import io.github.bucket4j.Refill;
import io.github.bucket4j.distributed.proxy.ProxyManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@lakshyajit165
lakshyajit165 / RedisConfig.java
Created February 4, 2023 06:17
Redisspringratelimiting-RedisConfig.java
package com.example.redisspringratelimiting.config;
import com.giffing.bucket4j.spring.boot.starter.config.cache.SyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.jcache.JCacheCacheResolver;
import io.github.bucket4j.distributed.proxy.ProxyManager;
import io.github.bucket4j.grid.jcache.JCacheProxyManager;
import org.redisson.config.Config;
import org.redisson.jcache.configuration.RedissonConfiguration;
import org.redisson.spring.starter.RedissonAutoConfiguration;
import org.springframework.context.annotation.Bean;
@lakshyajit165
lakshyajit165 / build.gradle
Created February 4, 2023 05:53
redisspringrateliminting-gradle-file
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
@lakshyajit165
lakshyajit165 / github-ci.yml
Created May 6, 2022 04:03
github action script for node_postgres_cicd
name: run api testing
on:
push:
branches: [dev, stage, master]
pull_request:
branches: [master]
jobs:
api-test:
runs-on: ubuntu-latest
@lakshyajit165
lakshyajit165 / task_schema_index.js
Created May 6, 2022 03:45
task_schema_index file
const Sequelize = require("sequelize");
const {
DATABASE,
DB_USER,
DB_HMAC,
DB_HOST,
DB_PORT,
DB_DIALECT,
DB_POOL_CONNECTION_LIMIT,
DB_POOL_IDLE_TIMEOUT,
@lakshyajit165
lakshyajit165 / task_schema.js
Created May 6, 2022 03:43
node_postgres_cicd_task_schema
const { DataTypes } = require("sequelize");
module.exports = (sequelizeInstance) => {
const tasks = sequelizeInstance.define("tasks", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
title: {
type: DataTypes.STRING,
describe("/POST task", () => {
it("it SHOULD NOT POST a task without title field", (done) => {
let taskPayload = {
description: "J.R.R. Tolkien",
created_by: "[email protected]",
};
chai.request(app)
.post("/create_task")
.send(taskPayload)
.end((err, res) => {
process.env.NODE_ENV = "test";
const app = require("../src/app.js");
const models = require("../src/models/index");
const { QueryTypes } = require("sequelize");
const sequelizeInstance = models.sequelizeInstance;
//Require the dev-dependencies
let chai = require("chai");
let chaiHttp = require("chai-http");
let should = chai.should();