Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Meissshu committed Feb 2, 2018
1 parent e170edf commit edfff7f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
12 changes: 12 additions & 0 deletions application.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[2018-02-02 10:47:05] ERROR There is an error: java.lang.NullPointerException Default message: null
[2018-02-02 10:55:32] ERROR [THYMELEAF][http-nio-80-exec-6] Exception processing template "service/service_user_list": An error happened during template parsing (template: "class path resource [templates/service/service_user_list.html]" - line 122, col 37)
[2018-02-02 10:55:32] ERROR Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/service/service_user_list.html]" - line 122, col 37)] with root cause
[2018-02-02 10:55:32] ERROR [THYMELEAF][http-nio-80-exec-6] Exception processing template "error": Error resolving template "error", template might not exist or might not be accessible by any of the configured Template Resolvers
[2018-02-02 10:55:32] ERROR Servlet.service() for servlet [dispatcherServlet] threw exception
[2018-02-02 10:55:32] ERROR Exception Processing ErrorPage[errorCode=0, location=/error]
[2018-02-02 10:59:24] ERROR An internal error occurred while trying to authenticate the user.
[2018-02-02 12:21:57] ERROR An internal error occurred while trying to authenticate the user.
[2018-02-02 12:37:13] ERROR There is an error: java.lang.NullPointerException Default message: null
[2018-02-02 12:37:30] ERROR [THYMELEAF][http-nio-80-exec-2] Exception processing template "error": Error resolving template "error", template might not exist or might not be accessible by any of the configured Template Resolvers
[2018-02-02 12:37:30] ERROR Servlet.service() for servlet [dispatcherServlet] threw exception
[2018-02-02 12:37:30] ERROR Exception Processing ErrorPage[errorCode=0, location=/error]
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.Locale;

@SpringBootApplication
public class MobilePaymentSystemApplication extends WebMvcConfigurerAdapter{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ public long numberOfUnpaidBillsOfUserByUserId(long userId) {
return billsRepository.countAllByPaidForAndUser_Id(UNPAID, userId);
}

// payment for EXPIRED PAID BILL
/**
* Withdraw cash to pay for all services of User with ID userId
* Find expired active services and try to renew subscription
* @param userId id of User
*/
public void withdrawCashToPayForServicesByUserId(long userId) {
List<ServiceUnit> serviceUnits = userService.getActiveServicesByUserId(userId);
User user = userService.getUserById(userId);
Expand All @@ -108,7 +112,7 @@ public void withdrawCashToPayForServicesByUserId(long userId) {
}
}

userService.updateUser(user); // todo: maybe it's not needed
userService.updateUser(user);
}

public void withdrawCashToPayForOneBill(Bill bill, User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ public long numberOfAllPaidActiveUserServicesByUserId(long userId) {
+ billService.getAllExpiredActiveServicesOfUserByUserId(userId).size();
}

/**
* Subscribe User with ID userId to Service with ID serviceID
* Withdraw cash at the moment of subscribing
* Create paid bill if payment is successful
* Create unpaid bill if payment is unsuccessful
* Already existing Service cannot be subscribed to User
* @param userId ID of User
* @param serviceId ID of Service
*/
public void subscribeUserToServiceByUserAndServiceId(long userId, long serviceId) {
// if we chose actual existing service
if (serviceId != -1) {
User user = userService.getUserById(userId);
ServiceUnit service = getServiceById(serviceId);

// we create bill only if the service is new
if (user.addService(service)) {
Bill bill = billService.createAndSaveBill(user, service);
billService.withdrawCashToPayForOneBill(bill, user);
Expand All @@ -75,11 +82,17 @@ public void subscribeUserToServiceByUserAndServiceId(long userId, long serviceId
}
}

/**
* Unsubscribe User from Service
* Delete unpaid Bill of this Service from User in process
* Service cannot be unsubscribed if User doesn't have it
* @param bill Bill that contains information about User subscribed to Service
* @param userId ID of User
*/
public void unsubscribeUserFromServiceByBillAndUserId(Bill bill, long userId) {
User user = userService.getUserById(userId);
ServiceUnit service = getServiceById(bill.getId());
ServiceUnit service = getServiceById(bill.getServiceUnit().getId());

// if service exists and it is unpaid - remove also unpaid bill
if (user.removeService(service)) {
userService.updateUser(user);
billService.deleteUnpaidBillByUserIdAndServiceId(userId, service.getId());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data-h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ VALUES
('admin', 'Vladimir Kostin', 99999, '$2a$10$hW7TdoUPWhEdprtj0XjCJ.iDopWV2UUaHWp2l7FoK3mRbLTX7W81q', 'ROLE_ADMIN'),
('mikey', 'Marsel Allaiarov', 435, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_SUBSCRIBER'),
('stranger', 'Bill Gates', 107, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_LOCKED'),
('exceptional', 'Gryu Felonius', 0, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_DELETED');
('exceptional', 'Gryu Felonius', 0, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_LOCKED');

--
INSERT INTO SERVICES (cost, duration, name, description)
Expand Down

0 comments on commit edfff7f

Please sign in to comment.