// Path: demo-service-interface/src/main/java/app/demo/api/product/CreateProductRequest.java
// public class CreateProductRequest {
//     @NotNull(message = "id is required")
//     @Property(name = "id")
//     public String id;
// 
//     @NotNull(message = "name is required")
//     @Property(name = "name")
//     public String name;
// 
//     @Property(name = "desc")
//     public String description;
// }
// 
// Path: demo-service-interface/src/main/java/app/demo/api/product/ProductView.java
// public class ProductView {
//     @Property(name = "id")
//     public String id;
// 
//     @NotNull(message = "name is required")
//     @Property(name = "name")
//     public String name;
// 
//     @Property(name = "desc")
//     public String description;
// 
//     @Property(name = "created_time")
//     public LocalDateTime createdTime;
// }
// 
// Path: demo-service-interface/src/main/java/app/demo/api/product/UpdateProductRequest.java
// public class UpdateProductRequest {
//     @Property(name = "name")
//     public String name;
// 
//     @Property(name = "desc")
//     public String description;
// }


import app.demo.api.product.CreateProductRequest;
import app.demo.api.product.ProductView;
import app.demo.api.product.UpdateProductRequest;
import core.framework.cache.Cache;
import core.framework.inject.Inject;
import core.framework.util.Maps;
import core.framework.web.exception.NotFoundException;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.Optional;
package app.demo.product.service;



/**
 * @author neo
 */
public class ProductService {
    private final Map<String, ProductView> products = Maps.newConcurrentHashMap();
    @Inject
    Cache<ProductView> cache;

    public Optional<ProductView> get(String id) {
        ProductView view = cache.get(id, products::get);
        return Optional.ofNullable(view);
    }

    public void create(CreateProductRequest request) {
        ProductView product = new ProductView();
        product.id = request.id;
        product.name = request.name;
        product.description = request.description;
        product.createdTime = LocalDateTime.now();
        products.put(product.id, product);
    }

// Path: demo-service-interface/src/main/java/app/demo/api/product/CreateProductRequest.java
// public class CreateProductRequest {
//     @NotNull(message = "id is required")
//     @Property(name = "id")
//     public String id;
// 
//     @NotNull(message = "name is required")
//     @Property(name = "name")
//     public String name;
// 
//     @Property(name = "desc")
//     public String description;
// }
// 
// Path: demo-service-interface/src/main/java/app/demo/api/product/ProductView.java
// public class ProductView {
//     @Property(name = "id")
//     public String id;
// 
//     @NotNull(message = "name is required")
//     @Property(name = "name")
//     public String name;
// 
//     @Property(name = "desc")
//     public String description;
// 
//     @Property(name = "created_time")
//     public LocalDateTime createdTime;
// }
// 
// Path: demo-service-interface/src/main/java/app/demo/api/product/UpdateProductRequest.java
// public class UpdateProductRequest {
//     @Property(name = "name")
//     public String name;
// 
//     @Property(name = "desc")
//     public String description;
// }


// Path: demo-service/src/main/java/app/demo/product/service/ProductService.java
import app.demo.api.product.CreateProductRequest;
import app.demo.api.product.ProductView;
import app.demo.api.product.UpdateProductRequest;
import core.framework.cache.Cache;
import core.framework.inject.Inject;
import core.framework.util.Maps;
import core.framework.web.exception.NotFoundException;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.Optional;

package app.demo.product.service;



/**
 * @author neo
 */
public class ProductService {
    private final Map<String, ProductView> products = Maps.newConcurrentHashMap();
    @Inject
    Cache<ProductView> cache;

    public Optional<ProductView> get(String id) {
        ProductView view = cache.get(id, products::get);
        return Optional.ofNullable(view);
    }

    public void create(CreateProductRequest request) {
        ProductView product = new ProductView();
        product.id = request.id;
        product.name = request.name;
        product.description = request.description;
        product.createdTime = LocalDateTime.now();
        products.put(product.id, product);
    }

    public void update(String id, UpdateProductRequest request) {