0

Model: This is the model entity class that have the three members which is id ,skucoden quantity

package com.Inventory_microservice.Inventory_microservice.model;

import lombok.*;

import javax.persistence.*;


@AllArgsConstructor
@NoArgsConstructor
@Entity
@Getter
@Setter
@Table(name="t_inventory")
public class Inventory {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long Id;
    private  String skucode;
    private  Integer quantity;

}

Controller:

this is controller class that will take the skucode as input from rest api

package com.Inventory_microservice.Inventory_microservice.Controller;

import com.Inventory_microservice.Inventory_microservice.Service.InventoryService;
import com.Inventory_microservice.Inventory_microservice.model.Inventory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;
    @PostMapping("/{sku-code}")
    public boolean isInStock(@PathVariable("Sku-code") String skucode ) {
        return inventoryService.isInStock(skucode);

    }
}

Service

package com.Inventory_microservice.Inventory_microservice.Service;

import com.Inventory_microservice.Inventory_microservice.Repository.InventoryRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;

@Service

public class InventoryService {

@Autowired
private InventoryRepository inventoryRepository;

public boolean isInStock(String Skucode)
{
       return inventoryRepository.findBySkucode(Skucode).isPresent();
}

}

apllicatin.class

package com.Inventory_microservice.Inventory_microservice;

import com.Inventory_microservice.Inventory_microservice.Repository.InventoryRepository;
import com.Inventory_microservice.Inventory_microservice.model.Inventory;
import java.lang.*;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class InventoryMicroserviceApplication {



    public static void main(String[] args) {
        SpringApplication.run(InventoryMicroserviceApplication.class, args);
    }

    @Bean
    public  CommandLineRunner intotheinventory(InventoryRepository inventoryRepository){
        return args -> {
            Inventory inventory=new Inventory();
            Inventory.setSkucode("order_10");
            Inventory.setQuantity(10);

            Inventory inventory1 = new Inventory();
            Inventory1.setSkucode("order_20");
            Inventory1.setQuantity(10);

            Inventory inventory2=new Inventory();

            Inventory2.setSkucode("order_30");
            Inventory2.setQuantity(10);
            inventoryRepository.save(inventory1);
            inventoryRepository.save(inventory2);
            inventoryRepository.save(inventory);

        };
    }
}

In the above class am getting error when calling the set methods .please help me

0 Answers0