Changeset 5168b2e
- Timestamp:
- 01/09/23 13:35:57 (2 years ago)
- Branches:
- main
- Children:
- aad0fb3
- Parents:
- f7b963f
- Location:
- FullyStocked/src/main
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/ArticlesServiceImpl.java
rf7b963f r5168b2e 38 38 throw new InvalidArgumentsException(); 39 39 } 40 return Optional.of(articlesRepository.save (new Articles(description, articlename, maxquantityperlocation)));40 return Optional.of(articlesRepository.saveAndFlush(new Articles(description, articlename, maxquantityperlocation))); 41 41 } 42 42 … … 48 48 throw new InvalidArgumentsException(); 49 49 } 50 return Optional.of(articlesRepository.save (new Articles(description, articlename, imageurl, maxquantityperlocation)));50 return Optional.of(articlesRepository.saveAndFlush(new Articles(description, articlename, imageurl, maxquantityperlocation))); 51 51 } 52 52 -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/WorkersServiceImpl.java
rf7b963f r5168b2e 9 9 import org.springframework.stereotype.Service; 10 10 11 import java.util.List; 11 12 import java.util.Optional; 12 13 … … 26 27 Locations location=locationsRepository.findById(locationId).orElseThrow(InvalidArgumentsException::new); 27 28 worker.setLocation(location); 28 return Optional.of(worker); 29 return Optional.of(workersRepository.save(worker)); 30 } 31 32 @Override 33 public List<Workers> findAllWithNoLocation() { 34 return workersRepository.findAllByLocationIsNull(); 29 35 } 30 36 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/WorkersService.java
rf7b963f r5168b2e 6 6 public interface WorkersService { 7 7 Optional<Workers> assignLocation(Integer workerId, Integer locationId); 8 List<Workers> findAllWithNoLocation(); 8 9 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/ManagerController.java
rf7b963f r5168b2e 1 1 package com.bazi.fullystocked.Web.Controller; 2 2 3 import com.bazi.fullystocked.Services.LocationsService; 4 import com.bazi.fullystocked.Services.WorkersService; 3 5 import org.springframework.stereotype.Controller; 6 import org.springframework.ui.Model; 4 7 import org.springframework.web.bind.annotation.GetMapping; 8 import org.springframework.web.bind.annotation.PostMapping; 5 9 import org.springframework.web.bind.annotation.RequestMapping; 10 import org.springframework.web.bind.annotation.RequestParam; 6 11 7 12 @Controller 8 13 @RequestMapping(value ="/manager") 9 14 public class ManagerController { 15 private final WorkersService workersService; 16 private final LocationsService locationsService; 17 18 public ManagerController(WorkersService workersService, LocationsService locationsService) { 19 this.workersService = workersService; 20 this.locationsService = locationsService; 21 } 22 10 23 @GetMapping 11 24 public String getManagerPage() … … 14 27 return "homeManager"; 15 28 } 29 30 @GetMapping("/noLocWorkers") 31 public String listWorkersWithNullLocation(Model model) 32 { 33 model.addAttribute("workers", workersService.findAllWithNoLocation()); 34 model.addAttribute("locations", locationsService.findAll()); 35 return "noLocWorkers"; 36 } 37 @PostMapping("/noLocWorkers/add") 38 public String addWorkerToLocation(@RequestParam Integer workerId, @RequestParam Integer locationId) 39 { 40 try{ 41 workersService.assignLocation(workerId, locationId); 42 return "redirect:/manager/noLocWorkers"; 43 } 44 catch (Exception e) 45 { 46 return "redirect:/manager/noLocWorkers?error="+e.getMessage(); 47 } 48 } 16 49 }
Note:
See TracChangeset
for help on using the changeset viewer.