Лабораторная 3 (Backend)
This commit is contained in:
parent
3b4940ddf8
commit
b224f1b8a1
@ -1,90 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
// import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
// import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
// import org.slf4j.Logger;
|
||||
// import org.slf4j.LoggerFactory;
|
||||
// import org.springframework.boot.autoconfigure.security.SecurityProperties.User;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
// import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class ApiController {
|
||||
// private final Logger log = LoggerFactory.getLogger(ApiController.class);
|
||||
|
||||
// @GetMapping
|
||||
// public String get(@RequestParam(name = "name", defaultValue = "World") String name) {
|
||||
// return String.format("Hello, %s!", name);
|
||||
// }
|
||||
|
||||
// @GetMapping("/test")
|
||||
// public String getTest() {
|
||||
// return new Date().toString();
|
||||
// }
|
||||
|
||||
// @GetMapping("/num")
|
||||
// public Integer getNum() {
|
||||
// return 10;
|
||||
// }
|
||||
|
||||
// @GetMapping("/list")
|
||||
// public List<Integer> getList() {
|
||||
// return List.of(10, 20, 30, 40, 50);
|
||||
// }
|
||||
|
||||
// @PutMapping("/{name}")
|
||||
// public String putMethodName(@PathVariable(name = "name") String name, @RequestBody String entity) {
|
||||
// log.info("The body value is {}", entity);
|
||||
// return get(name);
|
||||
// }
|
||||
|
||||
// @PutMapping("user/{idUser}")
|
||||
// public UserDto postUser(@PathVariable(name = "idUser") String idUser) {
|
||||
// // Играем с айдишниками
|
||||
// return new UserDto();
|
||||
// }
|
||||
|
||||
|
||||
Map<Integer, UserDto> users = new HashMap<>();
|
||||
|
||||
@GetMapping
|
||||
public Map<Integer, UserDto> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public UserDto getUser(@PathVariable(name = "id") int id) {
|
||||
return users.get(id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public UserDto delete(@PathVariable(name = "id") int id) {
|
||||
UserDto usr = users.get(id);
|
||||
users.remove(id);
|
||||
return usr;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public UserDto postMap(@RequestBody UserDto userDto) {
|
||||
users.put(users.size(), userDto);
|
||||
return userDto;
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public UserDto putMap(@RequestBody UserDto UserDto, @PathVariable(name = "id") int id) {
|
||||
// users.put(id, UserDto);
|
||||
users.replace(id, UserDto);
|
||||
return UserDto;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/line")
|
||||
public class LinesController {
|
||||
List<LinesDTO> lines = new ArrayList<>();
|
||||
|
||||
@GetMapping
|
||||
public List<LinesDTO> getLines() {
|
||||
return lines.stream().toList();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public LinesDTO getLine(@PathVariable(name = "id") int id) {
|
||||
return lines.get(id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public LinesDTO deleteLine(@PathVariable(name = "id") int id) {
|
||||
LinesDTO lin = lines.get(id);
|
||||
lines.remove(id);
|
||||
return lin;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public LinesDTO postMap(@RequestBody LinesDTO linesDto) {
|
||||
lines.add(lines.size(), linesDto);
|
||||
return linesDto;
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public LinesDTO putMap(@RequestBody LinesDTO LinesDto, @PathVariable(name = "id") int id) {
|
||||
// lines.put(id, LinesDto);
|
||||
lines.add(id, LinesDto);
|
||||
return LinesDto;
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class LinesDTO {
|
||||
private String id;
|
||||
private String title;
|
||||
private String description;
|
||||
private String count;
|
||||
private String price;
|
||||
|
||||
public LinesDTO() {
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public LinesDTO (
|
||||
@JsonProperty(value = "id") String id,
|
||||
@JsonProperty(value = "title") String title,
|
||||
@JsonProperty(value = "description") String description,
|
||||
@JsonProperty(value = "count") String count,
|
||||
@JsonProperty(value = "price") String price) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.count = count;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class UserDto {
|
||||
private String email;
|
||||
private String name;
|
||||
private String age;
|
||||
private String password;
|
||||
|
||||
public UserDto() {
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public UserDto (
|
||||
@JsonProperty(value = "email") String email,
|
||||
@JsonProperty(value = "name") String name,
|
||||
@JsonProperty(value = "age") String age,
|
||||
@JsonProperty(value = "password") String password) {
|
||||
this.email = email;
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class DemoApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user