-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
submit java-advanced-ru/multithreading-spring
- Loading branch information
1 parent
59ea97a
commit d78fdf3
Showing
5 changed files
with
112 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"assignment":"java-advanced-ru/asynchrony"} | ||
{"assignment":"java-advanced-ru/multithreading-spring"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.gradle/ | ||
build/ | ||
caches/ | ||
.gradle/ | ||
build/ | ||
caches/ | ||
.idea/ |
98 changes: 49 additions & 49 deletions
98
...-advanced-ru/multithreading-spring/src/main/java/exercise/controller/UsersController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
22 changes: 11 additions & 11 deletions
22
java-advanced-ru/multithreading-spring/src/main/java/exercise/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
96 changes: 48 additions & 48 deletions
96
java-advanced-ru/multithreading-spring/src/main/java/exercise/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |