<commit_before>package com.wgsistemas.motoboy.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wgsistemas.motoboy.dominio.PageWrapper;
import com.wgsistemas.motoboy.model.Delivery;
import com.wgsistemas.motoboy.service.CustomerService;
import com.wgsistemas.motoboy.service.DeliveryManService;
import com.wgsistemas.motoboy.service.DeliveryService;
import com.wgsistemas.motoboy.service.PaymentMethodService;

@Controller
@RequestMapping(value = "/admin")
public class AdminDeliveryController {
	@Autowired
	private DeliveryService deliveryService;
	@Autowired
	private DeliveryManService deliveryManService;
	@Autowired
	private CustomerService customerService;
	@Autowired
	private PaymentMethodService paymentMethodService;
	
	@GetMapping(value = "/delivery/")
	public String create(Model model) {
		model.addAttribute("deliveryForm", deliveryService.newDelivery());
		model.addAttribute("deliveryManList", deliveryManService.findAll());
		model.addAttribute("customerList", customerService.findAll());
		model.addAttribute("paymentMethodList", paymentMethodService.findAll());
		return "admin/delivery/new";
	}
	
	@PostMapping(path = "/delivery/")
	@Transactional
	public String create(@ModelAttribute("deliveryForm") Delivery deliveryForm, BindingResult bindingResult, Model model) {
		Delivery delivery = deliveryService.create(deliveryForm, SecurityContextHolder.getContext().getAuthentication().getName());		
		return "redirect:/admin/delivery/" + delivery.getId();
	}
	
	@GetMapping(path = "/delivery/{id}")
	public String update(@PathVariable Long id, Model model) {
		Delivery delivery = deliveryService.findOne(id);		
		model.addAttribute("deliveryForm", delivery);
		model.addAttribute("deliveryManList", deliveryManService.findAll());
		model.addAttribute("customerList", customerService.findAll());	
		model.addAttribute("paymentMethodList", paymentMethodService.findAll());
		return "admin/delivery/edit";
	}
	
	@PutMapping(path = "/delivery/{id}")
	@Transactional
	public String update(@PathVariable Integer id, @ModelAttribute("deliveryForm") Delivery deliveryForm, BindingResult bindingResult, Model model) {
		deliveryService.update(deliveryForm, SecurityContextHolder.getContext().getAuthentication().getName());			<commit_msg>Depois de cadastrar corrida direcionar para a insercao.<commit_after>package com.wgsistemas.motoboy.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wgsistemas.motoboy.dominio.PageWrapper;
import com.wgsistemas.motoboy.model.Delivery;
import com.wgsistemas.motoboy.service.CustomerService;
import com.wgsistemas.motoboy.service.DeliveryManService;
import com.wgsistemas.motoboy.service.DeliveryService;
import com.wgsistemas.motoboy.service.PaymentMethodService;

@Controller
@RequestMapping(value = "/admin")
public class AdminDeliveryController {
	@Autowired
	private DeliveryService deliveryService;
	@Autowired
	private DeliveryManService deliveryManService;
	@Autowired
	private CustomerService customerService;
	@Autowired
	private PaymentMethodService paymentMethodService;
	
	@GetMapping(value = "/delivery/")
	public String create(Model model) {
		model.addAttribute("deliveryForm", deliveryService.newDelivery());
		model.addAttribute("deliveryManList", deliveryManService.findAll());
		model.addAttribute("customerList", customerService.findAll());
		model.addAttribute("paymentMethodList", paymentMethodService.findAll());
		return "admin/delivery/new";
	}
	
	@PostMapping(path = "/delivery/")
	@Transactional
	public String create(@ModelAttribute("deliveryForm") Delivery deliveryForm, BindingResult bindingResult, Model model) {
		deliveryService.create(deliveryForm, SecurityContextHolder.getContext().getAuthentication().getName());		
		return "redirect:/admin/delivery/";
	}
	
	@GetMapping(path = "/delivery/{id}")
	public String update(@PathVariable Long id, Model model) {
		Delivery delivery = deliveryService.findOne(id);		
		model.addAttribute("deliveryForm", delivery);
		model.addAttribute("deliveryManList", deliveryManService.findAll());
		model.addAttribute("customerList", customerService.findAll());	
		model.addAttribute("paymentMethodList", paymentMethodService.findAll());
		return "admin/delivery/edit";
	}
	
	@PutMapping(path = "/delivery/{id}")
	@Transactional
	public String update(@PathVariable Integer id, @ModelAttribute("deliveryForm") Delivery deliveryForm, BindingResult bindingResult, Model model) {
		deliveryService.update(deliveryForm, SecurityContextHolder.getContext().getAuthentication().getName());			
{'fraction_non_alphanumeric': 0.10850303124514224, 'fraction_numerical': 0.0, 'mean_word_length': 7.613119143239625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '422764', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1735, 'n_words': 292}