Newer
Older
package apiservice.service;
import apiservice.model.Asset;
import apiservice.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/assets/")
public class ApiController {
private final ApiService service;
@Autowired
public ApiController(ApiService service) {
this.service = service;
}
@GetMapping(produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<Asset>> getAssets(@RequestParam(name ="uid") String uid) {
List<Asset> assets = service.getAssets(uid);
return new ResponseEntity<>(assets, HttpStatus.OK);
}
@PostMapping(produces = {MediaType.APPLICATION_JSON_VALUE})
public void postAsset(@RequestBody() Asset asset, @RequestParam(name = "uid") String uid) {
service.saveAsset(asset,uid);
}
}