org.khmeracademy.btb.auc.pojo.controller.Bid_log_controller.java Source code

Java tutorial

Introduction

Here is the source code for org.khmeracademy.btb.auc.pojo.controller.Bid_log_controller.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.khmeracademy.btb.auc.pojo.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.khmeracademy.btb.auc.pojo.entity.Bid_log;
import org.khmeracademy.btb.auc.pojo.service.Bid_log_service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author User
 */
@RestController
@RequestMapping(value = "/api/bid-log")
public class Bid_log_controller {
    @Autowired
    private Bid_log_service bid_log_service;

    @RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public ResponseEntity<Map<String, Object>> getNumberOfBid() {
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            ArrayList<Bid_log> bids = bid_log_service.getNumberOfBid();
            if (!bids.isEmpty()) {
                map.put("DATA", bids);
                map.put("STATUS", true);
                map.put("MESSAGE", "DATA FOUND!");
            } else {
                map.put("STATUS", true);
                map.put("MESSAGE", "DATA NOT FOUND");
            }
        } catch (Exception e) {
            map.put("STATUS", false);
            map.put("MESSAGE", "Error!");
            e.printStackTrace();
        }
        return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json")
    public ResponseEntity<Map<String, Object>> add(@RequestBody Bid_log bids) {
        Map<String, Object> map = new HashMap<String, Object>();
        try {

            if (bid_log_service.save(bids)) {
                map.put("MESSAGE", "Bid Log has been inserted.");
                map.put("STATUS", true);
            } else {
                map.put("MESSAGE", "Bid Log has not been inserted.");
                map.put("STATUS", false);
            }
        } catch (Exception e) {
            map.put("MESSAGE", "Error!");
            map.put("STATUS", false);
            e.printStackTrace();
        }
        return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
    }
}