Reformatted code
This commit is contained in:
+3
-3
@@ -6,8 +6,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@SpringBootApplication
|
||||
public class UsersServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UsersServiceApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UsersServiceApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -11,6 +11,5 @@
|
||||
|
||||
package com.baeldung.usersservice.adapters.http;
|
||||
|
||||
public record UserResponse(String id,
|
||||
String name) {
|
||||
public record UserResponse(String id, String name) {
|
||||
}
|
||||
|
||||
+7
-6
@@ -11,9 +11,6 @@
|
||||
|
||||
package com.baeldung.usersservice.adapters.http;
|
||||
|
||||
import com.baeldung.usersservice.adapters.repository.UserRecord;
|
||||
import com.baeldung.usersservice.service.UsersService;
|
||||
import com.baeldung.usersservice.service.UnknownUserException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@@ -27,6 +24,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baeldung.usersservice.adapters.repository.UserRecord;
|
||||
import com.baeldung.usersservice.service.UnknownUserException;
|
||||
import com.baeldung.usersservice.service.UsersService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/")
|
||||
class UsersController {
|
||||
@@ -50,14 +51,14 @@ class UsersController {
|
||||
var user = usersService.createUser(body.name());
|
||||
return buildResponse(user);
|
||||
}
|
||||
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
public UserResponse patchUser(@PathVariable("id") String id,
|
||||
@RequestBody PatchUserRequest body) {
|
||||
public UserResponse patchUser(@PathVariable("id") String id, @RequestBody PatchUserRequest body) {
|
||||
var user = usersService.updateUser(id, body.name());
|
||||
|
||||
return buildResponse(user);
|
||||
}
|
||||
|
||||
private UserResponse buildResponse(final UserRecord user) {
|
||||
return new UserResponse(user.getId(), user.getName());
|
||||
}
|
||||
|
||||
+13
-10
@@ -11,18 +11,17 @@
|
||||
|
||||
package com.baeldung.usersservice.service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.usersservice.adapters.jms.JmsSender;
|
||||
import com.baeldung.usersservice.adapters.repository.UserRecord;
|
||||
import com.baeldung.usersservice.adapters.repository.UsersRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UsersService {
|
||||
@@ -33,12 +32,14 @@ public class UsersService {
|
||||
private JmsSender jmsSender;
|
||||
|
||||
public UserRecord getUserById(String id) {
|
||||
return usersRepository.findById(id).orElseThrow(() -> new UnknownUserException(id));
|
||||
return usersRepository.findById(id)
|
||||
.orElseThrow(() -> new UnknownUserException(id));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteUserById(String id) {
|
||||
var user = usersRepository.findById(id).orElseThrow(() -> new UnknownUserException(id));
|
||||
var user = usersRepository.findById(id)
|
||||
.orElseThrow(() -> new UnknownUserException(id));
|
||||
usersRepository.delete(user);
|
||||
|
||||
jmsSender.sendDeleteUserMessage(id);
|
||||
@@ -46,7 +47,8 @@ public class UsersService {
|
||||
|
||||
@Transactional
|
||||
public UserRecord updateUser(String id, Optional<String> newName) {
|
||||
var user = usersRepository.findById(id).orElseThrow(() -> new UnknownUserException(id));
|
||||
var user = usersRepository.findById(id)
|
||||
.orElseThrow(() -> new UnknownUserException(id));
|
||||
|
||||
newName.ifPresent(user::setName);
|
||||
|
||||
@@ -54,7 +56,8 @@ public class UsersService {
|
||||
}
|
||||
|
||||
public UserRecord createUser(String name) {
|
||||
var user = new UserRecord(UUID.randomUUID().toString(), name);
|
||||
var user = new UserRecord(UUID.randomUUID()
|
||||
.toString(), name);
|
||||
usersRepository.save(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
server.port=8081
|
||||
|
||||
spring.artemis.host=localhost
|
||||
spring.artemis.port=61616
|
||||
|
||||
spring.jms.template.default-destination=my-queue-1
|
||||
|
||||
logging.level.org.apache.activemq.audit.base=WARN
|
||||
logging.level.org.apache.activemq.audit.message=WARN
|
||||
|
||||
|
||||
Reference in New Issue
Block a user