@@ -0,0 +1,2550 @@
+package de.bahr.pilot;%0A%0Aimport de.bahr.order.Order;%0Aimport de.bahr.order.OrderRepository;%0Aimport de.bahr.user.User;%0Aimport de.bahr.user.UserRepository;%0Aimport org.apache.commons.codec.binary.Base64;%0Aimport org.apache.commons.codec.binary.StringUtils;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity;%0Aimport org.springframework.web.bind.annotation.*;%0A%0Aimport java.util.List;%0A%0A/**%0A * Created by michaelbahr on 11/11/16.%0A */%0A@CrossOrigin%0A@RestController%0A@RequestMapping(value = %22/secured/pilot/selfservice%22)%0Apublic class PilotSelfServiceController %7B%0A%0A    @Autowired%0A    OrderRepository orderRepository;%0A%0A    @Autowired%0A    UserRepository userRepository;%0A%0A%0A    @RequestMapping(value = %22/list/requested%22, method = RequestMethod.GET, produces = %22application/json%22)%0A    public ResponseEntity%3C?%3E listRequested() %7B%0A        List%3COrder%3E result = orderRepository.findByStatus(%22requested%22);%0A        return new ResponseEntity%3C%3E(result, HttpStatus.OK);%0A    %7D%0A%0A    @RequestMapping(value = %22/pick%22, method = RequestMethod.POST, produces = %22application/json%22)%0A    public ResponseEntity%3C?%3E pickOrder(@RequestHeader(%22authorization%22) String auth, String orderId) %7B%0A        User user = getUser(auth);%0A%0A        Order order = orderRepository.findOne(orderId);%0A        if (order.getAssignee() != null) %7B%0A            return new ResponseEntity%3C%3E(HttpStatus.CONFLICT);%0A        %7D%0A%0A        order.setAssignee(user.getName());%0A        orderRepository.save(order);%0A%0A        return new ResponseEntity%3C%3E(order, HttpStatus.OK);%0A    %7D%0A%0A    @RequestMapping(value = %22/flag%22, method = RequestMethod.GET, produces = %22application/json%22)%0A    public ResponseEntity%3C?%3E flagOrder(@RequestHeader(%22authorization%22) String auth, String orderId) %7B%0A        User user = getUser(auth);%0A%0A        Order order = orderRepository.findOne(orderId);%0A        if (!order.getAssignee().equals(user.getName())) %7B%0A            return new ResponseEntity%3C%3E(HttpStatus.CONFLICT);%0A        %7D%0A%0A        order.setAssignee(%22Rihan Shazih%22);%0A        orderRepository.save(order);%0A%0A        return new ResponseEntity%3C%3E(HttpStatus.OK);%0A    %7D%0A%0A%0A    private User getUser(@RequestHeader(%22authorization%22) String auth) %7B%0A        String decoded = decode(auth.replace(%22Basic %22, %22%22));%0A        String characterId = decoded.split(%22:%22)%5B0%5D;%0A        return userRepository.findByCharacterId(Long.valueOf(characterId));%0A    %7D%0A%0A%0A    private String decode(String s) %7B%0A        return StringUtils.newStringUtf8(Base64.decodeBase64(s));%0A    %7D%0A%0A%7D%0A

create pilot self service controller