Точечные правки. Всё работает.
This commit is contained in:
parent
a0ff253478
commit
01470af3bb
@ -12,6 +12,10 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
jar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
|
||||
|
@ -2,8 +2,8 @@ package premium_store.controller.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import premium_store.controller.DTO.ClientDTO;
|
||||
import premium_store.model.Tank;
|
||||
import premium_store.service.GameClientService;
|
||||
import premium_store.service.TankService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -11,9 +11,11 @@ import java.util.List;
|
||||
@RequestMapping("/client")
|
||||
public class GameClientController {
|
||||
private final GameClientService gameClientService;
|
||||
private final TankService tankService;
|
||||
|
||||
public GameClientController(GameClientService gameClientService){
|
||||
public GameClientController(GameClientService gameClientService, TankService tankService){
|
||||
this.gameClientService = gameClientService;
|
||||
this.tankService = tankService;
|
||||
}
|
||||
|
||||
//аннотация PathVariable связывает значения id из URL и Long id
|
||||
@ -42,8 +44,8 @@ public class GameClientController {
|
||||
@RequestParam("nickName") String nickName,
|
||||
@RequestParam("email") String email,
|
||||
@RequestParam("balance") Integer balance,
|
||||
@RequestParam("tanks") List<Tank> tanks) {
|
||||
return new ClientDTO(gameClientService.updateClient(id, nickName, email, balance, tanks));
|
||||
@RequestParam("tankId") Long tankId) {
|
||||
return new ClientDTO(gameClientService.updateClient(id, nickName, email, balance, tankService.findTank(tankId)));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -1,8 +1,9 @@
|
||||
package premium_store.controller.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import premium_store.model.Nation;
|
||||
import premium_store.controller.DTO.FullNationDTO;
|
||||
import premium_store.service.NationService;
|
||||
import premium_store.service.TankService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -10,41 +11,46 @@ import java.util.List;
|
||||
//здесь происходит внедрение зависимости нашего сервиса
|
||||
//так же здесь прописываем вызовы методов CRUD в привязке к URL
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/nation")
|
||||
public class NationController {
|
||||
private final NationService nationService;
|
||||
private final TankService tankService;
|
||||
|
||||
public NationController(NationService nationService){
|
||||
public NationController(NationService nationService, TankService tankService){
|
||||
this.nationService = nationService;
|
||||
this.tankService = tankService;
|
||||
}
|
||||
|
||||
//аннотация PathVariable связывает значения id из URL и Long id
|
||||
@GetMapping("/{id}")
|
||||
public Nation getNation(@PathVariable Long id) {
|
||||
return nationService.findNation(id);
|
||||
public FullNationDTO getNation(@PathVariable Long id) {
|
||||
return new FullNationDTO(nationService.findNation(id));
|
||||
}
|
||||
|
||||
//с помощью Java Stream преобразуем набор пришедших данных в объекты StudentDto
|
||||
@GetMapping("/")
|
||||
public List<Nation> getNations() {
|
||||
public List<FullNationDTO> getNations() {
|
||||
return nationService.findAllNations().stream()
|
||||
.map(FullNationDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public Nation createNation(@RequestParam("nation") String nation) {
|
||||
return nationService.addNation(nation);
|
||||
public FullNationDTO createNation(@RequestParam("nation") String nation) {
|
||||
return new FullNationDTO(nationService.addNation(nation));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public Nation updateNation(@PathVariable Long id,
|
||||
@RequestParam("nation") String nation) {
|
||||
return nationService.updateNation(id, nation);
|
||||
public FullNationDTO updateNation(@PathVariable Long id,
|
||||
@RequestParam("nation") String nation,
|
||||
@RequestParam(value = "tankId", required = false) Long tankId ) {
|
||||
return new FullNationDTO(nationService.updateNation(id, nation, (tankId > 0) ? tankService.findTank(tankId) : null));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Nation deleteNation(@PathVariable Long id) {
|
||||
return nationService.deleteNation(id);
|
||||
public FullNationDTO deleteNation(@PathVariable Long id) {
|
||||
return new FullNationDTO(nationService.deleteNation(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,20 +2,24 @@ package premium_store.controller.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import premium_store.controller.DTO.TankDTO;
|
||||
import premium_store.model.GameClient;
|
||||
import premium_store.model.TankLevel;
|
||||
import premium_store.model.Nation;
|
||||
import premium_store.service.NationService;
|
||||
import premium_store.service.TankLevelService;
|
||||
import premium_store.service.TankService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/tank")
|
||||
public class TankController {
|
||||
private final TankService tankService;
|
||||
private final TankLevelService tankLevelService;
|
||||
private final NationService nationService;
|
||||
|
||||
public TankController(TankService tankService){
|
||||
public TankController(TankService tankService, TankLevelService tankLevelService, NationService nationService){
|
||||
this.tankService = tankService;
|
||||
this.tankLevelService = tankLevelService;
|
||||
this.nationService = nationService;
|
||||
}
|
||||
|
||||
//аннотация PathVariable связывает значения id из URL и Long id
|
||||
@ -32,22 +36,32 @@ public class TankController {
|
||||
.toList();
|
||||
}
|
||||
|
||||
@GetMapping("/filteredList/")
|
||||
public List<TankDTO> getFilteredTanks(@RequestParam("nation") String nation,
|
||||
@RequestParam("firstLevel") int firstLevel,
|
||||
@RequestParam("secondLevel") int secondLevel) {
|
||||
return tankService.findListTank(nation, firstLevel, secondLevel).stream()
|
||||
.map(TankDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public TankDTO createTank(@RequestParam("firstName") String name,
|
||||
@RequestParam("nation") Nation nation,
|
||||
@RequestParam("level") TankLevel tankLevel,
|
||||
@RequestParam("cost") int cost) {
|
||||
return new TankDTO(tankService.addTank(name, nation, tankLevel, cost));
|
||||
@RequestParam("nationId") Long nationId,
|
||||
@RequestParam("levelId") Long tankLevelId,
|
||||
@RequestParam("cost") int cost
|
||||
) {
|
||||
return new TankDTO(tankService.addTank(name, nationService.findNation(nationId), tankLevelService.findLevel(tankLevelId), cost));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public TankDTO updateTank(@PathVariable Long id,
|
||||
@RequestParam("firstName") String name,
|
||||
@RequestParam("nation") Nation nation,
|
||||
@RequestParam("level") TankLevel tankLevel,
|
||||
@RequestParam("cost") int cost,
|
||||
@RequestParam("clients")List<GameClient> gameClients) {
|
||||
return new TankDTO(tankService.updateTank(id, name, nation, tankLevel, cost, gameClients));
|
||||
@RequestParam("nationId") Long nationId,
|
||||
@RequestParam("levelId") Long tankLevelId,
|
||||
@RequestParam("cost") int cost
|
||||
) {
|
||||
return new TankDTO(tankService.updateTank(id, name, nationService.findNation(nationId), tankLevelService.findLevel(tankLevelId), cost));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -1,7 +1,7 @@
|
||||
package premium_store.controller.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import premium_store.model.TankLevel;
|
||||
import premium_store.controller.DTO.LevelDTO;
|
||||
import premium_store.service.TankLevelService;
|
||||
|
||||
import java.util.List;
|
||||
@ -20,30 +20,31 @@ public class TankLevelController {
|
||||
|
||||
//аннотация PathVariable связывает значения id из URL и Long id
|
||||
@GetMapping("/{id}")
|
||||
public TankLevel getLevel(@PathVariable Long id) {
|
||||
return tankLevelService.findLevel(id);
|
||||
public LevelDTO getLevel(@PathVariable Long id) {
|
||||
return new LevelDTO(tankLevelService.findLevel(id));
|
||||
}
|
||||
|
||||
//с помощью Java Stream преобразуем набор пришедших данных в объекты StudentDto
|
||||
@GetMapping("/")
|
||||
public List<TankLevel> getLevels() {
|
||||
public List<LevelDTO> getLevels() {
|
||||
return tankLevelService.findAllLevels().stream()
|
||||
.map(LevelDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public TankLevel createLevel(@RequestParam("Level") int level) {
|
||||
return tankLevelService.addLevel(level);
|
||||
public LevelDTO createLevel(@RequestParam("Level") int level) {
|
||||
return new LevelDTO(tankLevelService.addLevel(level));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public TankLevel updateLevel(@PathVariable Long id,
|
||||
public LevelDTO updateLevel(@PathVariable Long id,
|
||||
@RequestParam("Level") int level) {
|
||||
return tankLevelService.updateLevel(id, level);
|
||||
return new LevelDTO(tankLevelService.updateLevel(id, level));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public TankLevel deleteLevel(@PathVariable Long id) {
|
||||
return tankLevelService.deleteLevel(id);
|
||||
public LevelDTO deleteLevel(@PathVariable Long id) {
|
||||
return new LevelDTO(tankLevelService.deleteLevel(id));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
spring.main.banner-mode=off
|
||||
server.port=8080
|
||||
server.tomcat.relaxed-query-chars=|,{,},[,]
|
||||
spring.datasource.url=jdbc:h2:file:./data
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
|
@ -39,20 +39,33 @@ class PremiumStoreApplicationTests {
|
||||
void testClientRead() {
|
||||
gameClientService.deleteAllClients();
|
||||
|
||||
GameClient gameClient = gameClientService.addClient("3tankista73", "fff@mail.ru", 3400);
|
||||
log.info(gameClient.toString());
|
||||
GameClient client = gameClientService.addClient("3tankista73", "fff@mail.ru", 3400);
|
||||
log.info(client.toString());
|
||||
|
||||
GameClient findGameClient = gameClientService.findClient(gameClient.getId());
|
||||
log.info(findGameClient.toString());
|
||||
GameClient findClient = gameClientService.findClient(client.getId());
|
||||
log.info(findClient.toString());
|
||||
|
||||
Assertions.assertEquals(gameClient, findGameClient);
|
||||
Assertions.assertEquals(client, findClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNationRead() {
|
||||
nationService.deleteAllNations();
|
||||
tankService.deleteAllTanks();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
Nation nation = nationService.addNation("Германия");
|
||||
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
Tank firstTank = tankService.addTank("ИС-3", nation, firstLevel, 3700000);
|
||||
Tank secondTank = tankService.addTank("E-75", nation, secondLevel, 5600000);
|
||||
|
||||
List<Tank> tanks = new ArrayList<>(Arrays.asList(firstTank, secondTank));
|
||||
|
||||
nation = nationService.updateNation(nation.getId(), "СССР", null);
|
||||
|
||||
Nation nation = nationService.addNation("СССР");
|
||||
log.info(nation.toString());
|
||||
|
||||
Nation findNation = nationService.findNation(nation.getId());
|
||||
@ -72,11 +85,11 @@ class PremiumStoreApplicationTests {
|
||||
tankService.deleteAllTanks();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
TankLevel tankLevel = tankLevelService.addLevel(8);
|
||||
log.info(tankLevel.toString());
|
||||
TankLevel level = tankLevelService.addLevel(8);
|
||||
log.info(level.toString());
|
||||
|
||||
TankLevel secondTankLevel = tankLevelService.addLevel(9);
|
||||
log.info(secondTankLevel.toString());
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
log.info(secondLevel.toString());
|
||||
|
||||
Assertions.assertEquals(tankLevelService.findAllLevels().size(), 2);
|
||||
}
|
||||
@ -86,10 +99,10 @@ class PremiumStoreApplicationTests {
|
||||
tankService.deleteAllTanks();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
List<TankLevel> tankLevels = tankLevelService.findAllLevels();
|
||||
log.info(tankLevels.toString());
|
||||
List<TankLevel> levels = tankLevelService.findAllLevels();
|
||||
log.info(levels.toString());
|
||||
|
||||
Assertions.assertEquals(tankLevels.size(), 0);
|
||||
Assertions.assertEquals(levels.size(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -97,11 +110,11 @@ class PremiumStoreApplicationTests {
|
||||
tankService.deleteAllTanks();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
TankLevel firstTankLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondTankLevel = tankLevelService.addLevel(9);
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
tankService.addTank("ИС-3", nationService.addNation("СССР"), firstTankLevel, 3700000);
|
||||
tankService.addTank("E-75", nationService.addNation("Германия"), secondTankLevel, 5600000);
|
||||
tankService.addTank("ИС-3", nationService.addNation("СССР"), firstLevel, 3700000);
|
||||
tankService.addTank("E-75", nationService.addNation("Германия"), secondLevel, 5600000);
|
||||
|
||||
List<Tank> tanks = tankService.findAllTanks();
|
||||
log.info(tanks.toString());
|
||||
@ -113,11 +126,11 @@ class PremiumStoreApplicationTests {
|
||||
void testClientCreate() {
|
||||
gameClientService.deleteAllClients();
|
||||
|
||||
GameClient firstGameClient = gameClientService.addClient("Barbarian", "dsfg@gmail.com", 56000);
|
||||
log.info(firstGameClient.toString());
|
||||
GameClient firstClient = gameClientService.addClient("Barbarian", "dsfg@gmail.com", 56000);
|
||||
log.info(firstClient.toString());
|
||||
|
||||
GameClient secondGameClient = gameClientService.addClient("KorbenDallas", "tankoviyGeniy@mail.ru", 37000);
|
||||
log.info(secondGameClient.toString());
|
||||
GameClient secondClient = gameClientService.addClient("KorbenDallas", "tankoviyGeniy@mail.ru", 37000);
|
||||
log.info(secondClient.toString());
|
||||
|
||||
Assertions.assertEquals(gameClientService.findAllClients().size(), 2);
|
||||
}
|
||||
@ -128,26 +141,43 @@ class PremiumStoreApplicationTests {
|
||||
tankLevelService.deleteAllLevels();
|
||||
gameClientService.deleteAllClients();
|
||||
|
||||
GameClient firstGameClient = gameClientService.addClient("Barbarian", "dsfg@gmail.com", 56000);
|
||||
GameClient secondGameClient = gameClientService.addClient("KorbenDallas", "tankoviyGeniy@mail.ru", 37000);
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
TankLevel firstTankLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondTankLevel = tankLevelService.addLevel(9);
|
||||
|
||||
Tank firstTank = tankService.addTank("ИС-3", nationService.addNation("СССР"), firstTankLevel, 3700000);
|
||||
Tank secondTank = tankService.addTank("E-75", nationService.addNation("Германия"), secondTankLevel, 5600000);
|
||||
Tank firstTank = tankService.addTank("ИС-3", nationService.addNation("СССР"), firstLevel, 3700000);
|
||||
Tank secondTank = tankService.addTank("E-75", nationService.addNation("Германия"), secondLevel, 5600000);
|
||||
|
||||
Tank tank = tankService.findTank(firstTank.getId());
|
||||
log.info(tank.toString());
|
||||
|
||||
List<GameClient> newGameClient = new ArrayList<>();
|
||||
Collections.addAll(newGameClient, firstGameClient, secondGameClient);
|
||||
|
||||
tank.setName("ИСУ-152");
|
||||
tank.setLevel(secondTankLevel);
|
||||
tank.setLevel(secondLevel);
|
||||
tank.setCost(4100000);
|
||||
tank.setClients(newGameClient);
|
||||
|
||||
log.info(tank.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNewTest() {
|
||||
nationService.deleteAllNations();
|
||||
tankService.deleteAllTanks();
|
||||
tankLevelService.deleteAllLevels();
|
||||
|
||||
Nation nation = nationService.addNation("Германия");
|
||||
Nation newNation = nationService.addNation("CCCР");
|
||||
|
||||
TankLevel firstLevel = tankLevelService.addLevel(8);
|
||||
TankLevel secondLevel = tankLevelService.addLevel(9);
|
||||
|
||||
Tank firstTank = tankService.addTank("ИС-3", nation, firstLevel, 3700000);
|
||||
Tank secondTank = tankService.addTank("E-75", nation, secondLevel, 5600000);
|
||||
|
||||
List<Tank> tanks = new ArrayList<>(Arrays.asList(firstTank, secondTank));
|
||||
|
||||
nation = nationService.updateNation(nation.getId(), "СССР", null);
|
||||
|
||||
//tanks = tankService.findListTank(firstLevel, nation);
|
||||
|
||||
log.info("AAAAA" + tanks.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user