4 lab кто придумал спикера соболезную
This commit is contained in:
parent
0c1764ab47
commit
08dad1b6a4
@ -12,11 +12,15 @@ sourceCompatibility = '17'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
jar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
|
@ -0,0 +1,5 @@
|
||||
package ru.ulstu.is.sbapp.Comment.controller;
|
||||
|
||||
public class CommentController {
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package ru.ulstu.is.sbapp.Post.controller;
|
||||
|
||||
public class PostController {
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package ru.ulstu.is.sbapp.User.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.User.service.UserService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
private final UserService userService;
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
@GetMapping("/{id}")
|
||||
public UserDto getUser(@PathVariable Long id) {
|
||||
return new UserDto(userService.findUser(id));
|
||||
}
|
||||
@GetMapping
|
||||
public List<UserDto> getUsers() {
|
||||
return userService.findAllUsers().stream()
|
||||
.map(UserDto::new)
|
||||
.toList();
|
||||
}
|
||||
@PostMapping
|
||||
public UserDto createUser(@RequestParam("firstName") String firstName,
|
||||
@RequestParam("lastName") String lastname,
|
||||
@RequestParam("email") String email) {
|
||||
return new UserDto(userService.addUser(firstName, lastname,email));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public UserDto updateClient(@PathVariable Long id,
|
||||
@RequestParam("firstName") String firstName,
|
||||
@RequestParam("lastName") String lastname,
|
||||
@RequestParam("email") String email){
|
||||
return new UserDto(userService.updateUser(id, firstName, lastname,email));
|
||||
}
|
||||
@PostMapping("/{id}/Post")
|
||||
public void addPost(@PathVariable Long id,
|
||||
@RequestParam("Heading") String Heading,
|
||||
@RequestParam("Content") String Content) {
|
||||
userService.addNewPost(id, Heading,Content);
|
||||
}
|
||||
@DeleteMapping("/{id}/Post/{postId}")
|
||||
public void removePost(@PathVariable Long id,
|
||||
@PathVariable Long postId)
|
||||
{
|
||||
userService.deletePost(id,postId);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public UserDto deleteUser(@PathVariable Long id) {
|
||||
return new UserDto(userService.deleteUser(id));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package ru.ulstu.is.sbapp.User.controller;
|
||||
|
||||
import ru.ulstu.is.sbapp.Comment.model.Comment;
|
||||
import ru.ulstu.is.sbapp.Post.model.Post;
|
||||
import ru.ulstu.is.sbapp.User.model.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -19,10 +20,11 @@ public class UserDto {
|
||||
|
||||
private List<Comment> comments = new ArrayList<>();
|
||||
|
||||
public UserDto(String firstName, String lastName, String email) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.email=email;
|
||||
public UserDto(User user) {
|
||||
this.id=user.getId();
|
||||
this.firstName = user.getFirstName();
|
||||
this.lastName = user.getLastName();
|
||||
this.email= user.getEmail();
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
@ -1,52 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.speaker.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.is.sbapp.speaker.service.MethodService;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
private final MethodService methodService;
|
||||
public UserController(MethodService methodService)
|
||||
{
|
||||
this.methodService=methodService;
|
||||
}
|
||||
|
||||
@GetMapping("/sum")
|
||||
public String sum(@RequestParam(value = "firstObj",defaultValue = "0") String firstObj,
|
||||
@RequestParam(value = "secondObj",defaultValue = "0") String secondObj,
|
||||
@RequestParam(value = "type",defaultValue = "int")String type)
|
||||
{
|
||||
Object a = firstObj;
|
||||
Object b = secondObj;
|
||||
return methodService.Sum(a,b,type);
|
||||
}
|
||||
@GetMapping("/dif")
|
||||
public String dif(@RequestParam(value = "firstObj",defaultValue = "0") String firstObj,
|
||||
@RequestParam(value = "secondObj",defaultValue = "0") String secondObj,
|
||||
@RequestParam(value = "type",defaultValue = "int")String type)
|
||||
{
|
||||
Object a = firstObj;
|
||||
Object b = secondObj;
|
||||
return methodService.Dif(a,b,type);
|
||||
}
|
||||
@GetMapping("/com")
|
||||
public String com(@RequestParam(value = "firstObj",defaultValue = "0") String firstObj,
|
||||
@RequestParam(value = "secondObj",defaultValue = "0") String secondObj,
|
||||
@RequestParam(value = "type",defaultValue = "int")String type)
|
||||
{
|
||||
Object a = firstObj;
|
||||
Object b = secondObj;
|
||||
return methodService.Com(a,b,type);
|
||||
}
|
||||
@GetMapping("/div")
|
||||
public String div(@RequestParam(value = "firstObj",defaultValue = "0") String firstObj,
|
||||
@RequestParam(value = "secondObj",defaultValue = "0") String secondObj,
|
||||
@RequestParam(value = "type",defaultValue = "int")String type)
|
||||
{
|
||||
Object a = firstObj;
|
||||
Object b = secondObj;
|
||||
return methodService.Div(a,b,type);
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.speaker.domain;
|
||||
|
||||
public interface IMethods<T> {
|
||||
T Sum(T firstObj,T secondObj);
|
||||
T Dif (T firstObj, T secondObj);
|
||||
T Com(T firstObj,T secondObj);
|
||||
T Div (T firstObj, T secondObj);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.speaker.domain;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component(value = "int")
|
||||
public class MethodInteger implements IMethods<Integer> {
|
||||
@Override
|
||||
public Integer Sum(Integer firstObj, Integer secondObj) {
|
||||
return firstObj + secondObj;
|
||||
}
|
||||
@Override
|
||||
public Integer Dif(Integer firstObj, Integer secondObj) {
|
||||
return firstObj -secondObj;
|
||||
}
|
||||
@Override
|
||||
public Integer Com(Integer firstObj, Integer secondObj) {
|
||||
return firstObj * secondObj;
|
||||
}
|
||||
@Override
|
||||
public Integer Div(Integer firstObj, Integer secondObj) {
|
||||
int num = secondObj;
|
||||
if (num == 0){
|
||||
return null;
|
||||
}else{
|
||||
return firstObj / num;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.speaker.domain;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component(value = "string")
|
||||
public class MethodString implements IMethods<String> {
|
||||
@Override
|
||||
public String Sum(String firstObj,String secondObj)
|
||||
{
|
||||
return firstObj.concat(secondObj);
|
||||
}
|
||||
@Override
|
||||
public String Dif(String firstObj,String secondObj)
|
||||
{
|
||||
if(firstObj.contains(secondObj))
|
||||
{
|
||||
return firstObj.replace(secondObj,"");
|
||||
}
|
||||
return (firstObj);
|
||||
}
|
||||
@Override
|
||||
public String Com(String firstObj,String secondObj)
|
||||
{
|
||||
String res = (firstObj);
|
||||
for (int i = 0; i < (secondObj).length(); i++) {
|
||||
res = Sum(res, firstObj);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@Override
|
||||
public String Div(String firstObj,String secondObj)
|
||||
{
|
||||
if (firstObj.contains(secondObj)){
|
||||
return "true";
|
||||
}else{
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.speaker.service;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.is.sbapp.speaker.domain.IMethods;
|
||||
import ru.ulstu.is.sbapp.speaker.domain.MethodInteger;
|
||||
import ru.ulstu.is.sbapp.speaker.domain.MethodString;
|
||||
|
||||
@Service
|
||||
public class MethodService {
|
||||
private final ApplicationContext applicationContext;
|
||||
public MethodService(ApplicationContext applicationContext)
|
||||
{
|
||||
this.applicationContext=applicationContext;
|
||||
}
|
||||
public String Sum(Object firstObj,Object secondObj,String type)
|
||||
{
|
||||
final IMethods method=(IMethods) applicationContext.getBean(type);
|
||||
if (method instanceof MethodString){
|
||||
return String.format("%s", method.Sum(firstObj,secondObj));
|
||||
}else{
|
||||
return String.format("%s", method.Sum(Integer.parseInt(firstObj.toString()),Integer.parseInt(secondObj.toString())));
|
||||
}
|
||||
}
|
||||
public String Com(Object firstObj,Object secondObj,String type)
|
||||
{
|
||||
final IMethods method=(IMethods) applicationContext.getBean(type);
|
||||
if (method instanceof MethodString){
|
||||
return String.format("%s", method.Com(firstObj,secondObj));
|
||||
}else{
|
||||
return String.format("%s", method.Com(Integer.parseInt(firstObj.toString()),Integer.parseInt(secondObj.toString())));
|
||||
}
|
||||
}
|
||||
public String Dif(Object firstObj,Object secondObj,String type)
|
||||
{
|
||||
final IMethods method=(IMethods) applicationContext.getBean(type);
|
||||
if (method instanceof MethodString){
|
||||
return String.format("%s", method.Dif(firstObj,secondObj));
|
||||
}else{
|
||||
return String.format("%s", method.Dif(Integer.parseInt(firstObj.toString()),Integer.parseInt(secondObj.toString())));
|
||||
}
|
||||
}
|
||||
public String Div(Object firstObj,Object secondObj,String type)
|
||||
{
|
||||
final IMethods method=(IMethods) applicationContext.getBean(type);
|
||||
if (method instanceof MethodString){
|
||||
return String.format("%s", method.Div(firstObj,secondObj));
|
||||
}else{
|
||||
return String.format("%s", method.Div(Integer.parseInt(firstObj.toString()),Integer.parseInt(secondObj.toString())));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import ru.ulstu.is.sbapp.speaker.service.MethodService;
|
||||
|
||||
@SpringBootTest
|
||||
class SbappApplicationTests {
|
||||
@Autowired
|
||||
MethodService methodService;
|
||||
@Test
|
||||
void testSumInt() {
|
||||
final String res=methodService.Sum(1,1,"int");
|
||||
Assertions.assertEquals(2,Integer.parseInt(res));
|
||||
}
|
||||
@Test
|
||||
void testDifInt() {
|
||||
final String res=methodService.Dif(1,1,"int");
|
||||
Assertions.assertEquals(0,Integer.parseInt(res));
|
||||
}
|
||||
@Test
|
||||
void testComInt() {
|
||||
final String res=methodService.Com(3,2,"int");
|
||||
Assertions.assertEquals(6,Integer.parseInt(res));
|
||||
}
|
||||
@Test
|
||||
void testDivInt() {
|
||||
final String res=methodService.Div(6,2,"int");
|
||||
Assertions.assertEquals(3,Integer.parseInt(res));
|
||||
}
|
||||
@Test
|
||||
void testSumStr() {
|
||||
final String res=methodService.Sum("1","1","string");
|
||||
Assertions.assertEquals("11",res);
|
||||
}
|
||||
@Test
|
||||
void testDifStr() {
|
||||
final String res=methodService.Dif("2133","2","string");
|
||||
Assertions.assertEquals("133",res);
|
||||
}
|
||||
@Test
|
||||
void testComStr() {
|
||||
final String res=methodService.Com("abc","ba","string");
|
||||
Assertions.assertEquals("abcabcabc",res);
|
||||
}
|
||||
@Test
|
||||
void testDivStr() {
|
||||
final String res=methodService.Div("1010","2","string");
|
||||
Assertions.assertEquals("false",res);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user