package de.stadtbote.votian; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; import java.util.*; import static de.stadtbote.votian.ApiController.user; @RestController @RequestMapping("/api/crm") class CrmController { private final ContactService contacts;private final SalesAnalytics sales; CrmController(ContactService contacts,SalesAnalytics sales){this.contacts=contacts;this.sales=sales;} @GetMapping("/options") Map options(Authentication a){return sales.options(user(a));} @GetMapping("/contacts/schema") Map schema(Authentication a,@RequestParam long headquarters){return contacts.schema(user(a),headquarters);} @GetMapping("/contacts/draft") Map draft(Authentication a,@RequestParam long headquarters,@RequestParam(required=false) Long customerId){return contacts.draft(user(a),headquarters,customerId);} @PostMapping("/contacts/query") List> contacts(Authentication a,@RequestBody ContactService.Query q){return contacts.list(user(a),q);} @GetMapping("/contacts/{id}") Map contact(Authentication a,@PathVariable long id,@RequestParam long headquarters){return contacts.get(user(a),headquarters,id);} @GetMapping("/contacts/{id}/history") List> history(Authentication a,@PathVariable long id,@RequestParam long headquarters){return contacts.history(user(a),headquarters,id);} @PostMapping("/contacts") Map create(Authentication a,@RequestBody ContactService.Save s){return contacts.save(user(a),null,s);} @PutMapping("/contacts/{id}") Map save(Authentication a,@PathVariable long id,@RequestBody ContactService.Save s){return contacts.save(user(a),id,s);} record Delete(long headquarters,String revision){} @DeleteMapping("/contacts/{id}") @ResponseStatus(org.springframework.http.HttpStatus.NO_CONTENT) void remove(Authentication a,@PathVariable long id,@RequestBody Delete s){contacts.remove(user(a),s.headquarters(),id,s.revision());} @PostMapping("/switches") Map switches(Authentication a,@RequestBody SalesAnalytics.Query q){return sales.switches(user(a),q);} record Motivation(String month,List headquarters){} @PostMapping("/motivation") Map motivation(Authentication a,@RequestBody Motivation q){return sales.motivation(user(a),q.month(),q.headquarters());} @PostMapping("/targets/query") List> targets(Authentication a,@RequestBody SalesAnalytics.TargetAccess s){return sales.targets(user(a),s);} @PostMapping("/targets") Map target(Authentication a,@RequestBody SalesAnalytics.Target s){return sales.target(user(a),s);} }