package com.rizki.mufrizal.belajar.oauth2.controller;

import com.rizki.mufrizal.belajar.oauth2.domain.Barang;
import com.rizki.mufrizal.belajar.oauth2.service.BarangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api")
public class BarangController {

    @Autowired
    private BarangService barangService;

    @Secured({"ROLE_ADMIN", "ROLE_USER"})
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    @RequestMapping(value = "/barang", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    public List<Barang> getBarang() {
        return barangService.getBarangList();
    }

}

@@ -449,20 +449,68 @@
 va.util.
-List
+HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A@Rest
@@ -548,14 +548,28 @@
 e = 
-%22/api%22
+BarangController.API
 )%0Apu
@@ -664,136 +664,746 @@
     
-@Secured(%7B%22ROLE_ADMIN%22, %22ROLE_USER%22%7D)%0A    @ResponseBody%0A    @ResponseStatus(HttpStatus.OK)%0A    @RequestMapping(value = %22/barang%22
+public static final String API = %22/api%22;%0A    public static final String LIST_BARANG = %22/Barang%22;%0A    public static final String SAVE_BARANG = %22/SaveBarang%22;%0A    public static final String UPDATE_BARANG = %22/UpdateBarang%22;%0A    public static final String DELETE_BARANG = %22/DeleteBarang/%7BidBarang%7D%22;%0A%0A    @Secured(%7B%22ROLE_ADMIN%22, %22ROLE_USER%22%7D)%0A    @ResponseBody%0A    @ResponseStatus(HttpStatus.OK)%0A    @RequestMapping(value = LIST_BARANG, method = RequestMethod.GET, produces = %7BMediaType.APPLICATION_JSON_VALUE%7D)%0A    public List%3CBarang%3E getBarang() %7B%0A        return barangService.getBarangList();%0A    %7D%0A%0A    @Secured(%7B%22ROLE_ADMIN%22, %22ROLE_USER%22%7D)%0A    @ResponseBody%0A    @ResponseStatus(HttpStatus.CREATED)%0A    @RequestMapping(value = SAVE_BARANG
 , me
@@ -1415,34 +1415,35 @@
 = RequestMethod.
-GE
+POS
 T, produces = %7BM
@@ -1478,92 +1478,1492 @@
 LUE%7D
-)%0A    public List%3CBarang%3E getBarang() %7B%0A        return barangService.getBarangList()
+, consumes = %7BMediaType.APPLICATION_JSON_VALUE%7D)%0A    public Map%3CString, Object%3E saveBarang(@RequestBody Barang barang) %7B%0A%0A        barangService.save(barang);%0A%0A        Map%3CString, Object%3E message = new HashMap%3C%3E();%0A        message.put(%22Success%22, Boolean.TRUE);%0A        message.put(%22Info%22, %22Save Data Berhasil%22);%0A%0A        return message;%0A    %7D%0A%0A    @Secured(%7B%22ROLE_ADMIN%22, %22ROLE_USER%22%7D)%0A    @ResponseBody%0A    @ResponseStatus(HttpStatus.OK)%0A    @RequestMapping(value = UPDATE_BARANG, method = RequestMethod.PUT, produces = %7BMediaType.APPLICATION_JSON_VALUE%7D, consumes = %7BMediaType.APPLICATION_JSON_VALUE%7D)%0A    public Map%3CString, Object%3E updateBarang(@RequestBody Barang barang) %7B%0A%0A        barangService.update(barang);%0A%0A        Map%3CString, Object%3E message = new HashMap%3C%3E();%0A        message.put(%22Success%22, Boolean.TRUE);%0A        message.put(%22Info%22, %22Update Data Berhasil%22);%0A%0A        return message;%0A    %7D%0A%0A    @Secured(%7B%22ROLE_ADMIN%22, %22ROLE_USER%22%7D)%0A    @ResponseBody%0A    @ResponseStatus(HttpStatus.OK)%0A    @RequestMapping(value = DELETE_BARANG, method = RequestMethod.DELETE, produces = %7BMediaType.APPLICATION_JSON_VALUE%7D)%0A    public Map%3CString, Object%3E deleteBarang(@PathVariable(%22idBarang%22)String idBarang) %7B%0A%0A        Barang barang = barangService.getBarang(idBarang);%0A        barangService.delete(barang);%0A%0A        Map%3CString, Object%3E message = new HashMap%3C%3E();%0A        message.put(%22Success%22, Boolean.TRUE);%0A        message.put(%22Info%22, %22Data Berhasil Dihapus%22);%0A%0A        return message
 ;%0A  

Add CRUD Barang With Annotation Secure