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

Java tutorial

Introduction

Here is the source code for org.khmeracademy.btb.auc.pojo.controller.Top_Bidder_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.Top_Bidder;
import org.khmeracademy.btb.auc.pojo.service.Top_Bidder_service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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 KUYLIM
 */
@RestController
@RequestMapping(value = "/api/top-bidder")
public class Top_Bidder_controller {

    @Autowired
    Top_Bidder_service top_bidder_service;

    @RequestMapping(value = "/get-top-bidder", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public ResponseEntity<Map<String, Object>> getTopBidder() {
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            ArrayList<Top_Bidder> top_bidder = top_bidder_service.getTop_Bidder();

            if (!top_bidder.isEmpty()) {
                map.put("DATA", top_bidder);
                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);
    }
}