-
Notifications
You must be signed in to change notification settings - Fork 1.2k
for check #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
for check #1261
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .idea/* | ||
| *.iml | ||
| target/* | ||
| /logs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,18 +6,22 @@ | |
| import mate.academy.service.AuthenticationServiceImpl; | ||
| import mate.academy.service.OrderService; | ||
| import mate.academy.service.OrderServiceImpl; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| public class Main { | ||
| private static final Logger logger = LogManager.getLogger(Main.class); | ||
|
|
||
| public static void main(String[] args) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item #1: |
||
| AuthenticationService authenticationService = new AuthenticationServiceImpl(); | ||
| User user; | ||
| try { | ||
| user = authenticationService.login("bob", "1234"); | ||
| OrderService orderService = new OrderServiceImpl(); | ||
| orderService.completeOrder(user.getUserId()); | ||
| } catch (AuthenticationException e) { | ||
| e.printStackTrace(); | ||
| return; | ||
| logger.error("User can`t login", e); | ||
| } | ||
| OrderService orderService = new OrderServiceImpl(); | ||
| orderService.completeOrder(user.getUserId()); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,15 @@ | |
|
|
||
| import mate.academy.exception.AuthenticationException; | ||
| import mate.academy.model.User; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| public class AuthenticationServiceImpl implements AuthenticationService { | ||
| private static final Logger logger = LogManager.getLogger(AuthenticationServiceImpl.class); | ||
|
|
||
| @Override | ||
| public User login(String login, String password) throws AuthenticationException { | ||
| //TODO: add corresponding log message about method login was called | ||
| logger.info("Method login was called. Params: login {}", login); | ||
| User user = findByLogin(login); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: "Let's remove all TODO comments before submitting solution." The logging is already implemented, so this TODO comment should be deleted. |
||
| if (!user.getPassword().equals(password)) { | ||
| throw new AuthenticationException("Username or password are incorrect"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,27 +4,27 @@ | |
| import java.util.List; | ||
| import mate.academy.model.Order; | ||
| import mate.academy.model.Product; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| public class OrderServiceImpl implements OrderService { | ||
| private static final Logger logger = LogManager.getLogger(OrderServiceImpl.class); | ||
|
|
||
| @Override | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item #1: |
||
| public Order completeOrder(Long userId) { | ||
| // TODO: add log message about method completeOrder was called | ||
| logger.info("Method completeOrder was called. Params: userId {}", userId); | ||
| List<Product> products = getAllProductsFromShoppingCart(userId); | ||
| Order order = new Order(products, userId); | ||
| // NOTE: In production ready code this order identifier should be generated by DB | ||
| // For test purpose we simplify this and return dummy data | ||
| order.setOrderId(1L); | ||
| return order; | ||
| } | ||
|
|
||
| private List<Product> getAllProductsFromShoppingCart(Long userId) { | ||
| // NOTE: In production ready code this method should fetch data from DB | ||
| // For test purpose we simplify this method and return dummy data | ||
| Product iphone = new Product("iPhone X", BigDecimal.valueOf(1199)); | ||
| Product macBook = new Product("MacBook Air 2020", BigDecimal.valueOf(1399)); | ||
| Product xiaomi = new Product("Xiaomi 12", BigDecimal.valueOf(499)); | ||
| List<Product> products = List.of(iphone, macBook, xiaomi); | ||
| // TODO: add log message about successful fetched data from DB | ||
| logger.info("Data from DB was successfully fetched"); | ||
| return products; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Configuration status="info"> | ||
| <Appenders> | ||
| <Console name="LogToConsole" target="SYSTEM_OUT"> | ||
| <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n"/> | ||
| </Console> | ||
| <File name="LogToFile" fileName="logs/app.log"> | ||
| <PatternLayout> | ||
| <Pattern>%d %p %c:%L %msg%n</Pattern> | ||
| </PatternLayout> | ||
| </File> | ||
| </Appenders> | ||
| <Loggers> | ||
| <Logger name="mate.academy" level="info" additivity="false"> | ||
| <AppenderRef ref="LogToFile"/> | ||
| <AppenderRef ref="LogToConsole"/> | ||
| </Logger> | ||
| <Root level="error"> | ||
| <AppenderRef ref="LogToFile"/> | ||
| <AppenderRef ref="LogToConsole"/> | ||
| </Root> | ||
| </Loggers> | ||
| </Configuration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates checklist item #1:
Let's remove all TODO comments before submitting solution.You’ve already implemented the logging, so this TODO comment should be deleted.