-
Notifications
You must be signed in to change notification settings - Fork 1.1k
done #1234
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?
done #1234
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,5 @@ | ||
| .idea/* | ||
| *.iml | ||
| target/* | ||
| *.log | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,16 @@ | |
|
|
||
| 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 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); | ||
| if (!user.getPassword().equals(password)) { | ||
|
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 is an improvement, but it's still not quite right. According to checklist item #3, you should use parameterized logging for better performance and readability. Instead of string concatenation, use placeholders like this: |
||
| throw new AuthenticationException("Username or password are incorrect"); | ||
|
|
@@ -20,4 +25,12 @@ private User findByLogin(String login) { | |
| user.setUserId(2L); | ||
| return user; | ||
| } | ||
|
|
||
| public void setLogger(Logger logger) { | ||
| this.logger = logger; | ||
| } | ||
|
|
||
| public Logger getLogger() { | ||
| return logger; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,27 +4,36 @@ | |
| 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 Logger logger = LogManager.getLogger(OrderServiceImpl.class); | ||
|
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. There should be a blank line after this field declaration to improve code readability. This was also mentioned in the previous review feedback. |
||
|
|
||
| @Override | ||
| public Order completeOrder(Long userId) { | ||
| // TODO: add log message about method completeOrder was called | ||
| logger.info("Method completeOrder was called with 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("Successfully fetched data from DB for userId: {}", userId); | ||
| return products; | ||
| } | ||
|
|
||
| public void setLogger(Logger logger) { | ||
| this.logger = logger; | ||
| } | ||
|
|
||
| public Logger getLogger() { | ||
| return logger; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Configuration status="INFO"> | ||
| <!-- Define the appenders --> | ||
| <Appenders> | ||
| <!-- Console Appender --> | ||
| <Console name="ConsoleAppender" target="SYSTEM_OUT"> | ||
| <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" /> | ||
| </Console> | ||
| <!-- File Appender --> | ||
| <File name="FileAppender" fileName="applogs/application_logs.log"> | ||
| <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" /> | ||
| </File> | ||
| </Appenders> | ||
| <!-- Define the loggers --> | ||
| <Loggers> | ||
| <!-- Root Logger --> | ||
| <Root level="info"> | ||
| <AppenderRef ref="ConsoleAppender" /> | ||
| <AppenderRef ref="FileAppender" /> | ||
| </Root> | ||
| <!-- Logger for specific package --> | ||
| <Logger name="com.example.myapp" level="debug"> | ||
| <AppenderRef ref="FileAppender" /> | ||
| </Logger> | ||
| </Loggers> | ||
| </Configuration> |
Uh oh!
There was an error while loading. Please reload this page.