Skip to content

Instantly share code, notes, and snippets.

View khannedy's full-sized avatar
👀
Orang Ganteng dan Intelek

Eko Kurniawan Khannedy khannedy

👀
Orang Ganteng dan Intelek
View GitHub Profile
package com.idspring.crudreactive.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
@khannedy
khannedy / pom.xml
Last active October 24, 2017 12:18
<dependencies>
...
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
package com.idspring.crudreactive.entity;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Eko Kurniawan Khannedy
* @since 24/10/17
*/
@Document(collection = "products")
package com.idspring.crudreactive.entity;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Eko Kurniawan Khannedy
* @since 24/10/17
*/
@Document(collection = "categories")
curl -v "http://localhost:8080/?secure=true"
* Hostname was NOT found in DNS cache
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /?secure=true HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200
curl -v localhost:8080
* Rebuilt URL to: localhost:8080/
* Hostname was NOT found in DNS cache
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept: */*
>
@Configuration
public class DemoConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
// Add HandlerInterceptor to Registry
registry.addInterceptor(new DemoInterceptor());
}
}
public class DemoInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String secure = request.getParameter("secure");
if ("true".equals(secure)) {
return true;
} else {
response.setStatus(HttpStatus.UNAUTHORIZED.value());
return false;
@khannedy
khannedy / HandlerInterceptor.java
Last active October 15, 2017 01:41
HandlerInterceptor
public interface HandlerInterceptor {
boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception;
void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
throws Exception;
void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception;
package com.idspring.commandpattern.service.command.impl;
import com.idspring.commandpattern.entity.Cart;
import com.idspring.commandpattern.entity.CartItem;
import com.idspring.commandpattern.entity.Product;
import com.idspring.commandpattern.model.service.AddProductToCartRequest;
import com.idspring.commandpattern.repository.CartRepository;
import com.idspring.commandpattern.repository.ProductRepository;
import com.idspring.commandpattern.service.AbstractCommand;
import com.idspring.commandpattern.service.command.AddProductToCartCommand;