Skip to content
Snippets Groups Projects
Commit 9a41c428 authored by Diana Gulčíková's avatar Diana Gulčíková
Browse files

checkstyle fix

parent 8be7264a
No related branches found
No related tags found
2 merge requests!60Docker,!41Race extended functionality
Pipeline #
......@@ -3,8 +3,6 @@ package cz.muni.pa165.race.rest;
import cz.muni.pa165.common_library.dtos.Location;
import cz.muni.pa165.common_library.dtos.RaceDto;
import cz.muni.pa165.race.data.model.Race;
import cz.muni.pa165.race.service.RaceService;
import cz.muni.pa165.race.service.RaceServiceI;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
......@@ -68,8 +66,8 @@ public class RaceController {
@PatchMapping(path = "/assignDriverOne",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RaceDto> assignDriverOne(@RequestParam Long driverOneId,
@RequestParam Long raceId,
@RequestParam Long carId) {
@RequestParam Long raceId,
@RequestParam Long carId) {
return ResponseEntity.ok(raceService.assignDriverOne(driverOneId, raceId, carId));
}
......@@ -77,8 +75,8 @@ public class RaceController {
@PatchMapping(path = "/assignDriverTwo",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RaceDto> assignDriverTwo(@RequestParam Long driverTwoId,
@RequestParam Long raceId,
@RequestParam Long carId) {
@RequestParam Long raceId,
@RequestParam Long carId) {
return ResponseEntity.ok(raceService.assignDriverTwo(driverTwoId, raceId, carId));
}
......@@ -86,7 +84,7 @@ public class RaceController {
@PatchMapping(path = "/assignPointsDriverTwo",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RaceDto> assignPositionDriverTwo(@RequestParam Long raceId,
@RequestParam Integer position) {
@RequestParam Integer position) {
return ResponseEntity.ok(raceService.assignPositionForDriverTwo(raceId, position));
}
......@@ -100,7 +98,8 @@ public class RaceController {
@Operation(summary = "get races")
@GetMapping(path = "/findMostSuitableDriversForLocation")
public ResponseEntity<Set<Long>> getMostSuitableDriversForLocation(@RequestParam Location location) {
public ResponseEntity<Set<Long>> getMostSuitableDriversForLocation(
@RequestParam Location location) {
return ResponseEntity.ok(raceService.findMostSuitableDriver(location));
}
}
......@@ -2,12 +2,20 @@ package cz.muni.pa165.race.service;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Utility for points per position.
*/
public class PointsUtil {
/**
* Map with position and corresponding points.
*/
public Map<Integer, Integer> points;
/**
* Constructor.
*/
public PointsUtil() {
points = new HashMap<>();
points.put(1, 25);
......
......@@ -123,6 +123,13 @@ public class RaceService implements RaceServiceI {
return raceRepository.findAll().stream().map(this::convertRace).toList();
}
/**
* Assigns positions for driver number two.
*
* @param raceId race id.
* @param position position of driver two.
* @return updated race.
*/
public RaceDto assignPositionForDriverTwo(Long raceId, Integer position) {
var race =
raceRepository.findById(raceId).orElseThrow(() -> new DatabaseException("Race not found"));
......@@ -130,6 +137,13 @@ public class RaceService implements RaceServiceI {
return convertRace(raceRepository.save(race));
}
/**
* Assigns positions for driver number one.
*
* @param raceId race id.
* @param position position of driver one.
* @return updated race.
*/
public RaceDto assignPositionForDriverOne(Long raceId, Integer position) {
var race =
raceRepository.findById(raceId).orElseThrow(() -> new DatabaseException("Race not found"));
......@@ -137,6 +151,12 @@ public class RaceService implements RaceServiceI {
return convertRace(raceRepository.save(race));
}
/**
* Finds most suitable drivers for given location.
*
* @param location location of the race.
* @return set if ids of most suitable drivers for given location.
*/
public Set<Long> findMostSuitableDriver(Location location) {
var races = raceRepository.findRacesByLocation(location);
Map<Long, Integer> driverWithPoints = new HashMap<>();
......
......@@ -2,10 +2,12 @@ package cz.muni.pa165.race.service;
import cz.muni.pa165.common_library.dtos.Location;
import cz.muni.pa165.common_library.dtos.RaceDto;
import cz.muni.pa165.race.data.model.Race;
import java.util.List;
import java.util.Set;
/**
* Race service interface.
*/
public interface RaceServiceI {
RaceDto postRace(RaceDto raceDto);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment