Changeset 5168b2e


Ignore:
Timestamp:
01/09/23 13:35:57 (23 months ago)
Author:
DarkoSasanski <darko.sasanski@…>
Branches:
main
Children:
aad0fb3
Parents:
f7b963f
Message:

Implemented adding new worker at location

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  
    3838            throw new InvalidArgumentsException();
    3939        }
    40         return Optional.of(articlesRepository.save(new Articles(description, articlename, maxquantityperlocation)));
     40        return Optional.of(articlesRepository.saveAndFlush(new Articles(description, articlename, maxquantityperlocation)));
    4141    }
    4242
     
    4848            throw new InvalidArgumentsException();
    4949        }
    50         return Optional.of(articlesRepository.save(new Articles(description, articlename, imageurl, maxquantityperlocation)));
     50        return Optional.of(articlesRepository.saveAndFlush(new Articles(description, articlename, imageurl, maxquantityperlocation)));
    5151    }
    5252
  • FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/WorkersServiceImpl.java

    rf7b963f r5168b2e  
    99import org.springframework.stereotype.Service;
    1010
     11import java.util.List;
    1112import java.util.Optional;
    1213
     
    2627        Locations location=locationsRepository.findById(locationId).orElseThrow(InvalidArgumentsException::new);
    2728        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();
    2935    }
    3036}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Services/WorkersService.java

    rf7b963f r5168b2e  
    66public interface WorkersService {
    77    Optional<Workers> assignLocation(Integer workerId, Integer locationId);
     8    List<Workers> findAllWithNoLocation();
    89}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/ManagerController.java

    rf7b963f r5168b2e  
    11package com.bazi.fullystocked.Web.Controller;
    22
     3import com.bazi.fullystocked.Services.LocationsService;
     4import com.bazi.fullystocked.Services.WorkersService;
    35import org.springframework.stereotype.Controller;
     6import org.springframework.ui.Model;
    47import org.springframework.web.bind.annotation.GetMapping;
     8import org.springframework.web.bind.annotation.PostMapping;
    59import org.springframework.web.bind.annotation.RequestMapping;
     10import org.springframework.web.bind.annotation.RequestParam;
    611
    712@Controller
    813@RequestMapping(value ="/manager")
    914public 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
    1023    @GetMapping
    1124    public String getManagerPage()
     
    1427        return "homeManager";
    1528    }
     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    }
    1649}
Note: See TracChangeset for help on using the changeset viewer.