Skip to content

Commit

Permalink
submit java-advanced-ru/multithreading-spring
Browse files Browse the repository at this point in the history
  • Loading branch information
hexlet-cli committed Feb 21, 2024
1 parent 59ea97a commit d78fdf3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .current.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"assignment":"java-advanced-ru/asynchrony"}
{"assignment":"java-advanced-ru/multithreading-spring"}
6 changes: 3 additions & 3 deletions java-advanced-ru/multithreading-spring/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.gradle/
build/
caches/
.gradle/
build/
caches/
.idea/
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
package exercise.controller;

import exercise.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import exercise.service.UserService;


@RestController
@RequestMapping("/users")
public class UsersController {

@Autowired
private UserService userService;

@GetMapping(path = "")
public Flux<User> getUsers() {
return userService.findAll();
}

// BEGIN
@GetMapping("/{id}")
public Mono<User> getUser(@PathVariable Long id) {
return userService.findById(id);
}

@PostMapping("")
// @ResponseStatus(HttpStatus.CREATED)
public Mono<User> addUser(@RequestBody User newUser) {
return userService.create(newUser);
}

@PatchMapping("/{id}")
public Mono<User> updateUser(@PathVariable Long id,
@RequestBody User editedUser) {
return userService.update(id, editedUser);
}

@DeleteMapping("/{id}")
public Mono<Void> deleteUser (@PathVariable Long id) {
return userService.delete(id);
}
// END
}
package exercise.controller;

import exercise.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import exercise.service.UserService;


@RestController
@RequestMapping("/users")
public class UsersController {

@Autowired
private UserService userService;

@GetMapping(path = "")
public Flux<User> getUsers() {
return userService.findAll();
}

// BEGIN
@GetMapping("/{id}")
public Mono<User> getUser(@PathVariable Long id) {
return userService.findById(id);
}

@PostMapping("")
// @ResponseStatus(HttpStatus.CREATED)
public Mono<User> addUser(@RequestBody User newUser) {
return userService.create(newUser);
}

@PatchMapping("/{id}")
public Mono<User> updateUser(@PathVariable Long id,
@RequestBody User editedUser) {
return userService.update(id, editedUser);
}

@DeleteMapping("/{id}")
public Mono<Void> deleteUser (@PathVariable Long id) {
return userService.delete(id);
}
// END
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package exercise.repository;

import exercise.model.User;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;


// BEGIN
public interface UserRepository extends ReactiveCrudRepository<User, Long> {
}
// END
package exercise.repository;

import exercise.model.User;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;


// BEGIN
public interface UserRepository extends ReactiveCrudRepository<User, Long> {
}
// END
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
package exercise.service;

import exercise.model.User;
import exercise.repository.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;


import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;

@Service
public class UserService {

@Autowired
UserRepository userRepository;

public Flux<User> findAll() {
return userRepository.findAll();
}

// BEGIN
public Mono<User> findById(Long id) {
return userRepository.findById(id);
}

public Mono<User> create(User newUser) {
return userRepository.save(newUser);
}

public Mono<User> update(Long id, User editedUser) {
return userRepository.findById(id)
.flatMap(user -> {
user.setId(id);
user.setFirstName(editedUser.getFirstName());
user.setLastName(editedUser.getLastName());
user.setEmail(editedUser.getEmail());
return userRepository.save(user);
});
}

public Mono<Void> delete(Long id) {
return userRepository.deleteById(id);
}
// END
}
package exercise.service;

import exercise.model.User;
import exercise.repository.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;


import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;

@Service
public class UserService {

@Autowired
UserRepository userRepository;

public Flux<User> findAll() {
return userRepository.findAll();
}

// BEGIN
public Mono<User> findById(Long id) {
return userRepository.findById(id);
}

public Mono<User> create(User newUser) {
return userRepository.save(newUser);
}

public Mono<User> update(Long id, User editedUser) {
return userRepository.findById(id)
.flatMap(user -> {
user.setId(id);
user.setFirstName(editedUser.getFirstName());
user.setLastName(editedUser.getLastName());
user.setEmail(editedUser.getEmail());
return userRepository.save(user);
});
}

public Mono<Void> delete(Long id) {
return userRepository.deleteById(id);
}
// END
}

0 comments on commit d78fdf3

Please sign in to comment.