Compare commits
41 Commits
dmitrii-cr
...
security_b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a84c498073 | ||
|
|
aaf67ab09b | ||
|
|
0fcacc3e88 | ||
|
|
5a8a8f1197 | ||
|
|
71448a6c21 | ||
|
|
fddd02b9ce | ||
|
|
3bf3f92551 | ||
|
|
ee8a61ba8b | ||
|
|
eb93ca73ce | ||
|
|
fa99d42bee | ||
|
|
c45cd0549f | ||
|
|
a21277bfe7 | ||
| bee800428e | |||
| a6ef16b569 | |||
|
|
444f3a07fa | ||
|
|
a484e8e6d2 | ||
|
|
07c9ed63ee | ||
|
|
d03e256425 | ||
|
|
c13056ae7f | ||
|
|
7481f91b11 | ||
|
|
4410694993 | ||
| 4404eedeec | |||
| 021be06f40 | |||
|
|
fb2695e58a | ||
|
|
ab3641dacb | ||
|
|
2d981c5af8 | ||
|
|
f1c8211f7a | ||
|
|
3ba95647b4 | ||
|
|
acbb6285d9 | ||
|
|
04aa41e354 | ||
| 71ef9aefe1 | |||
|
|
f635ca3cb7 | ||
|
|
ffd0fa36ec | ||
|
|
c0e0c21da7 | ||
|
|
76b515b129 | ||
|
|
9fe17438f7 | ||
|
|
7bc9a460ed | ||
|
|
eca57b111a | ||
|
|
8f934bdf32 | ||
|
|
c399f42e89 | ||
|
|
6a839b7d28 |
6
package-lock.json
generated
Normal file
6
package-lock.json
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "ExpenseTrackerFAF",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
||||
12
pom.xml
12
pom.xml
@@ -69,12 +69,18 @@
|
||||
<version>0.11.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
<version>6.1.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<defaultGoal>package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.faf223.expensetrackerfaf.security.PersonDetails;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
@@ -19,12 +20,11 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
@RequiredArgsConstructor
|
||||
public class ApplicationConfig {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final CredentialRepository credentialRepository;
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() {
|
||||
return username -> new PersonDetails(credentialRepository.findByEmail(username).orElseThrow((() -> new UsernameNotFoundException("User not found"))));
|
||||
return username -> new PersonDetails(credentialRepository.findByEmail(username).orElseThrow(() -> new UsernameNotFoundException("User not found")));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -44,4 +44,10 @@ public class ApplicationConfig {
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
@Bean
|
||||
@Primary
|
||||
public JwtAuthenticationFilter customJwtAuthenticationFilter(JwtService jwtService, UserDetailsService userDetailsService) {
|
||||
return new JwtAuthenticationFilter(jwtService, userDetailsService);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.faf223.expensetrackerfaf.config;
|
||||
|
||||
import com.faf223.expensetrackerfaf.controller.auth.ErrorResponse;
|
||||
import com.faf223.expensetrackerfaf.util.errors.ErrorResponse;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import jakarta.servlet.FilterChain;
|
||||
@@ -61,11 +61,10 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json");
|
||||
|
||||
ErrorResponse errorResponse = new ErrorResponse("TokenExpired", "Your session has expired. Please log in again.");
|
||||
ObjectMapper objectMapper = new ObjectMapper(); // You may need to import ObjectMapper
|
||||
ErrorResponse errorResponse = new ErrorResponse("Your session has expired. Refresh your token.");
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
|
||||
|
||||
|
||||
response.getWriter().flush();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.io.Decoders;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -16,6 +17,7 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class JwtService {
|
||||
|
||||
@Value("${application.security.jwt.secret-key}")
|
||||
@@ -25,6 +27,7 @@ public class JwtService {
|
||||
@Value("${application.security.jwt.refresh-token.expiration}")
|
||||
private long refreshExpiration;
|
||||
|
||||
|
||||
public String extractUsername(String token) {
|
||||
return extractClaim(token, Claims::getSubject);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
package com.faf223.expensetrackerfaf.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import com.faf223.expensetrackerfaf.controller.auth.JwtAuthenticationSuccessHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
||||
import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository;
|
||||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
|
||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
|
||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
@@ -32,12 +24,20 @@ import static org.springframework.security.config.Customizer.withDefaults;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@RequiredArgsConstructor
|
||||
@EnableMethodSecurity
|
||||
public class SecurityConfiguration {
|
||||
|
||||
private final JwtAuthenticationFilter jwtAuthFilter;
|
||||
private final AuthenticationProvider authenticationProvider;
|
||||
private final ClientRegistrationRepository clientRegistrationRepository;
|
||||
|
||||
public SecurityConfiguration(JwtAuthenticationFilter jwtAuthFilter,
|
||||
AuthenticationProvider authenticationProvider,
|
||||
ClientRegistrationRepository clientRegistrationRepository) {
|
||||
this.jwtAuthFilter = jwtAuthFilter;
|
||||
this.authenticationProvider = authenticationProvider;
|
||||
this.clientRegistrationRepository = clientRegistrationRepository;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
@@ -45,15 +45,18 @@ public class SecurityConfiguration {
|
||||
.cors(Customizer.withDefaults())
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/api/v1/auth/**").permitAll()
|
||||
.requestMatchers("/api/v1/auth/*").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authenticationProvider(authenticationProvider)
|
||||
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); // will be executed before UsernamePasswordAuthenticationFilter
|
||||
.oauth2Login(withDefaults());
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtAuthenticationSuccessHandler jwtAuthenticationSuccessHandler() {
|
||||
return new JwtAuthenticationSuccessHandler();
|
||||
}
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
@@ -66,4 +69,8 @@ public class SecurityConfiguration {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthenticationEntryPoint authenticationEntryPoint() {
|
||||
return new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,12 @@ import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.service.ExpenseCategoryService;
|
||||
import com.faf223.expensetrackerfaf.service.ExpenseService;
|
||||
import com.faf223.expensetrackerfaf.service.UserService;
|
||||
import com.faf223.expensetrackerfaf.util.errors.ErrorResponse;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionDoesNotBelongToTheUserException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionNotCreatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionNotUpdatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionsNotFoundException;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -16,10 +22,15 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -37,12 +48,15 @@ public class ExpenseController {
|
||||
public ResponseEntity<List<ExpenseDTO>> getAllExpenses() {
|
||||
List<ExpenseDTO> expenses = expenseService.getTransactions().stream().map(expenseMapper::toDto).collect(Collectors.toList());
|
||||
if (!expenses.isEmpty()) return ResponseEntity.ok(expenses);
|
||||
else return ResponseEntity.notFound().build();
|
||||
else throw new TransactionsNotFoundException("Transactions not found");
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
public ResponseEntity<Void> createNewExpense(@RequestBody ExpenseCreationDTO expenseDTO,
|
||||
public ResponseEntity<Void> createNewExpense(@RequestBody @Valid ExpenseCreationDTO expenseDTO,
|
||||
BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors())
|
||||
throw new TransactionNotCreatedException("Could not create new expense");
|
||||
|
||||
Expense expense = expenseMapper.toExpense(expenseDTO);
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
@@ -57,54 +71,78 @@ public class ExpenseController {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
throw new TransactionNotCreatedException("Could not create new expense");
|
||||
}
|
||||
|
||||
|
||||
// TODO: check if the expense belongs to the user
|
||||
@PatchMapping("/update/{id}")
|
||||
public ResponseEntity<Void> updateExpense(@PathVariable long id, @RequestBody ExpenseCreationDTO expenseDTO,
|
||||
public ResponseEntity<Void> updateExpense(@PathVariable long id, @RequestBody @Valid ExpenseCreationDTO expenseDTO,
|
||||
BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors())
|
||||
throw new TransactionNotUpdatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||
|
||||
Expense expense = expenseService.getTransactionById(id);
|
||||
|
||||
if(expense == null)
|
||||
throw new TransactionsNotFoundException("The expense has not been found");
|
||||
|
||||
if(!expenseService.belongsToUser(expense))
|
||||
throw new TransactionDoesNotBelongToTheUserException("The transaction does not belong to you");
|
||||
|
||||
ExpenseCategory category = expenseCategoryService.getCategoryById(expenseDTO.getExpenseCategory());
|
||||
expense.setCategory(category);
|
||||
expense.setAmount(expenseDTO.getAmount());
|
||||
|
||||
if (!bindingResult.hasErrors()) {
|
||||
expenseService.createOrUpdate(expense);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/personal-expenses")
|
||||
public ResponseEntity<List<ExpenseDTO>> getExpensesByUser() {
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<ExpenseDTO>> getExpensesByUser(@RequestParam Optional<LocalDate> date,
|
||||
@RequestParam Optional<Integer> month,
|
||||
@RequestParam Optional<Integer> startYear,
|
||||
@RequestParam Optional<Integer> endYear,
|
||||
@RequestParam Optional<String> lastUnit) {
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
String email = userDetails.getUsername();
|
||||
List<ExpenseDTO> expenses = expenseService.getTransactionsByEmail(email).stream().map(expenseMapper::toDto).collect(Collectors.toList());
|
||||
List<ExpenseDTO> expenses = Collections.emptyList();
|
||||
|
||||
if(date.isPresent())
|
||||
expenses = expenseService.getTransactionsByDate(date.get(), email).stream().map(expenseMapper::toDto).toList();
|
||||
else if(month.isPresent())
|
||||
expenses = expenseService.getTransactionsByMonth(Month.of(month.get()), email).stream().map(expenseMapper::toDto).toList();
|
||||
else if(startYear.isPresent() && endYear.isPresent())
|
||||
expenses = expenseService.getYearIntervalTransactions(email, startYear.get(), endYear.get()).stream().map(expenseMapper::toDto).toList();
|
||||
else if(lastUnit.isPresent()) {
|
||||
|
||||
if(lastUnit.get().equalsIgnoreCase("week"))
|
||||
expenses = expenseService.getLastWeekTransactions(email).stream().map(expenseMapper::toDto).toList();
|
||||
else if(lastUnit.get().equalsIgnoreCase("month"))
|
||||
expenses = expenseService.getLastMonthTransactions(email).stream().map(expenseMapper::toDto).toList();
|
||||
|
||||
} else {
|
||||
expenses = userService.getUserByEmail(email).getExpenses().stream().map(expenseMapper::toDto).toList();
|
||||
}
|
||||
|
||||
if (!expenses.isEmpty()) {
|
||||
return ResponseEntity.ok(expenses);
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
throw new TransactionsNotFoundException("The expenses have not been found");
|
||||
}
|
||||
|
||||
@GetMapping("/categories")
|
||||
public ResponseEntity<List<ExpenseCategory>> getAllCategories() {
|
||||
List<ExpenseCategory> categories = expenseCategoryService.getAllCategories();
|
||||
if (!categories.isEmpty()) return ResponseEntity.ok(categories);
|
||||
else return ResponseEntity.notFound().build();
|
||||
else throw new TransactionsNotFoundException("The expenses have not been found");
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public void deleteCategory(@PathVariable long id) {
|
||||
expenseService.deleteExpenseById(id);
|
||||
expenseService.deleteTransactionById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.faf223.expensetrackerfaf.controller;
|
||||
|
||||
import com.faf223.expensetrackerfaf.util.errors.ErrorResponse;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.*;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler
|
||||
private ResponseEntity<ErrorResponse> handleDoesNotBelongException(TransactionDoesNotBelongToTheUserException e) {
|
||||
ErrorResponse response = new ErrorResponse(
|
||||
e.getMessage(),
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
private ResponseEntity<ErrorResponse> handleTransactionNotCreatedException(TransactionNotCreatedException e) {
|
||||
ErrorResponse response = new ErrorResponse(
|
||||
e.getMessage(),
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_MODIFIED);
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
private ResponseEntity<ErrorResponse> handleTransactionsNotFoundException(TransactionsNotFoundException e) {
|
||||
ErrorResponse response = new ErrorResponse(
|
||||
e.getMessage(),
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
private ResponseEntity<ErrorResponse> handleUserNotFoundException(UserNotFoundException e) {
|
||||
ErrorResponse response = new ErrorResponse(
|
||||
e.getMessage(),
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
private ResponseEntity<ErrorResponse> handleTransactionNotUpdatedException(TransactionNotUpdatedException e) {
|
||||
ErrorResponse response = new ErrorResponse(
|
||||
e.getMessage(),
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_MODIFIED);
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
private ResponseEntity<ErrorResponse> handleUserNotAuthenticatedException(UserNotAuthenticatedException e) {
|
||||
ErrorResponse response = new ErrorResponse(
|
||||
e.getMessage(),
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
private ResponseEntity<ErrorResponse> handleUserNotCreatedException(UserNotCreatedException e) {
|
||||
ErrorResponse response = new ErrorResponse(
|
||||
e.getMessage(),
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_MODIFIED);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,18 @@ package com.faf223.expensetrackerfaf.controller;
|
||||
import com.faf223.expensetrackerfaf.dto.IncomeCreationDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.IncomeDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.mappers.IncomeMapper;
|
||||
import com.faf223.expensetrackerfaf.model.*;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.service.IncomeCategoryService;
|
||||
import com.faf223.expensetrackerfaf.service.IncomeService;
|
||||
import com.faf223.expensetrackerfaf.service.UserService;
|
||||
import com.faf223.expensetrackerfaf.util.errors.ErrorResponse;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionDoesNotBelongToTheUserException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionNotCreatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionNotUpdatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.TransactionsNotFoundException;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -14,10 +22,15 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -35,13 +48,17 @@ public class IncomeController {
|
||||
public ResponseEntity<List<IncomeDTO>> getAllIncomes() {
|
||||
List<IncomeDTO> incomes = incomeService.getTransactions().stream().map(incomeMapper::toDto).collect(Collectors.toList());
|
||||
if (!incomes.isEmpty()) return ResponseEntity.ok(incomes);
|
||||
else return ResponseEntity.notFound().build();
|
||||
else throw new TransactionsNotFoundException("Transactions not found");
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
public ResponseEntity<Void> createNewIncome(@RequestBody IncomeCreationDTO incomeDTO,
|
||||
public ResponseEntity<Void> createNewIncome(@RequestBody @Valid IncomeCreationDTO incomeDTO,
|
||||
BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors())
|
||||
throw new TransactionNotCreatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||
|
||||
Income income = incomeMapper.toIncome(incomeDTO);
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
@@ -50,58 +67,82 @@ public class IncomeController {
|
||||
User user = userService.getUserByEmail(email);
|
||||
income.setUser(user);
|
||||
|
||||
System.out.println(income);
|
||||
incomeService.createOrUpdate(income);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
throw new TransactionNotCreatedException("Could not create new expense");
|
||||
}
|
||||
|
||||
// TODO: check if the income belongs to the user, extract logic into service
|
||||
@PatchMapping("/update/{id}")
|
||||
public ResponseEntity<Void> updateIncome(@PathVariable long id, @RequestBody IncomeCreationDTO incomeDTO,
|
||||
public ResponseEntity<Void> updateIncome(@PathVariable long id, @RequestBody @Valid IncomeCreationDTO incomeDTO,
|
||||
BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors())
|
||||
throw new TransactionNotUpdatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||
|
||||
Income income = incomeService.getTransactionById(id);
|
||||
|
||||
if(income == null)
|
||||
throw new TransactionsNotFoundException("The income has not been found");
|
||||
|
||||
if(!incomeService.belongsToUser(income))
|
||||
throw new TransactionDoesNotBelongToTheUserException("The transaction does not belong to you");
|
||||
|
||||
IncomeCategory category = incomeCategoryService.getCategoryById(incomeDTO.getIncomeCategory());
|
||||
income.setCategory(category);
|
||||
income.setAmount(incomeDTO.getAmount());
|
||||
|
||||
if (!bindingResult.hasErrors()) {
|
||||
incomeService.createOrUpdate(income);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/personal-incomes")
|
||||
public ResponseEntity<List<IncomeDTO>> getIncomesByUser() {
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<IncomeDTO>> getIncomesByUser(@RequestParam Optional<LocalDate> date,
|
||||
@RequestParam Optional<Integer> month,
|
||||
@RequestParam Optional<Integer> startYear,
|
||||
@RequestParam Optional<Integer> endYear,
|
||||
@RequestParam Optional<String> lastUnit) {
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
String email = userDetails.getUsername();
|
||||
List<IncomeDTO> incomes = incomeService.getTransactionsByEmail(email).stream().map(incomeMapper::toDto).collect(Collectors.toList());
|
||||
List<IncomeDTO> incomes = Collections.emptyList();
|
||||
|
||||
if(date.isPresent())
|
||||
incomes = incomeService.getTransactionsByDate(date.get(), email).stream().map(incomeMapper::toDto).toList();
|
||||
else if(month.isPresent())
|
||||
incomes = incomeService.getTransactionsByMonth(Month.of(month.get()), email).stream().map(incomeMapper::toDto).toList();
|
||||
else if(startYear.isPresent() && endYear.isPresent())
|
||||
incomes = incomeService.getYearIntervalTransactions(email, startYear.get(), endYear.get()).stream().map(incomeMapper::toDto).toList();
|
||||
else if(lastUnit.isPresent()) {
|
||||
|
||||
if(lastUnit.get().equalsIgnoreCase("week"))
|
||||
incomes = incomeService.getLastWeekTransactions(email).stream().map(incomeMapper::toDto).toList();
|
||||
else if(lastUnit.get().equalsIgnoreCase("month"))
|
||||
incomes = incomeService.getLastMonthTransactions(email).stream().map(incomeMapper::toDto).toList();
|
||||
|
||||
} else {
|
||||
incomes = userService.getUserByEmail(email).getIncomes().stream().map(incomeMapper::toDto).toList();
|
||||
}
|
||||
|
||||
if (!incomes.isEmpty()) {
|
||||
return ResponseEntity.ok(incomes);
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
throw new TransactionsNotFoundException("The expenses have not been found");
|
||||
}
|
||||
|
||||
@GetMapping("/categories")
|
||||
public ResponseEntity<List<IncomeCategory>> getAllCategories() {
|
||||
List<IncomeCategory> categories = incomeCategoryService.getAllCategories();
|
||||
if (!categories.isEmpty()) return ResponseEntity.ok(categories);
|
||||
else return ResponseEntity.notFound().build();
|
||||
else throw new TransactionsNotFoundException("The expenses have not been found");
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public void deleteIncome(@PathVariable long id) {
|
||||
incomeService.deleteIncomeById(id);
|
||||
incomeService.deleteTransactionById(id);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@ import com.faf223.expensetrackerfaf.dto.UserDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.mappers.UserMapper;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.service.UserService;
|
||||
import com.faf223.expensetrackerfaf.util.errors.ErrorResponse;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotCreatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -25,27 +29,29 @@ public class UserController {
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@PatchMapping()
|
||||
public ResponseEntity<UserDTO> updateUser(@RequestBody UserCreationDTO userDTO,
|
||||
public ResponseEntity<UserDTO> updateUser(@RequestBody @Valid UserCreationDTO userDTO,
|
||||
BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors())
|
||||
throw new UserNotCreatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||
|
||||
User user = userMapper.toUser(userDTO);
|
||||
if (!bindingResult.hasErrors()) {
|
||||
userService.updateUser(user);
|
||||
return ResponseEntity.ok(userMapper.toDto(user));
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
throw new UserNotFoundException("The user has not been found");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/getUserData")
|
||||
@GetMapping("/get-user-data")
|
||||
public ResponseEntity<UserDTO> getUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
User user = userService.getUserByEmail(userDetails.getUsername());
|
||||
if (user != null) return ResponseEntity.ok(userMapper.toDto(user));
|
||||
else return ResponseEntity.notFound().build();
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
throw new UserNotFoundException("The user has not been found");
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
|
||||
@@ -14,16 +14,19 @@ public class AuthenticationController {
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<AuthenticationResponse> register(@RequestBody RegisterRequest request) {
|
||||
System.out.println("register");
|
||||
return ResponseEntity.ok(service.register(request));
|
||||
}
|
||||
|
||||
@PostMapping("/authenticate")
|
||||
public ResponseEntity<AuthenticationResponse> authenticate(@RequestBody AuthenticationRequest request) {
|
||||
System.out.println("Refresh token!========================");
|
||||
return ResponseEntity.ok(service.authenticate(request));
|
||||
}
|
||||
|
||||
@PostMapping("/refreshtoken")
|
||||
public ResponseEntity<AuthenticationResponse> refreshAccessToken(@RequestBody TokenRefreshRequest request) {
|
||||
System.out.println("Refresh token!========================");
|
||||
return ResponseEntity.ok(service.refreshAccessToken(request));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.faf223.expensetrackerfaf.controller.auth;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ErrorResponse {
|
||||
private String error;
|
||||
private String message;
|
||||
|
||||
public ErrorResponse(String error, String message) {
|
||||
this.error = error;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.faf223.expensetrackerfaf.controller.auth;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class JwtAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
||||
|
||||
super.onAuthenticationSuccess(request, response, authentication);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.faf223.expensetrackerfaf.controller.auth;
|
||||
|
||||
import com.faf223.expensetrackerfaf.service.AuthenticationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class OAuth2SuccessController {
|
||||
|
||||
private final AuthenticationService jwtService;
|
||||
|
||||
@GetMapping()
|
||||
public AuthenticationResponse getUser(@AuthenticationPrincipal OAuth2User oAuth2User) {
|
||||
|
||||
AuthenticationResponse response = jwtService.register(oAuth2User);
|
||||
System.out.println("Response: " + response);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class RegisterRequest {
|
||||
|
||||
private String firstname; // Change field name to match JSON
|
||||
private String lastname; // Change field name to match JSON
|
||||
private String username; // Change field name to match JSON
|
||||
private String email; // Change field name to match JSON
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private String username;
|
||||
private String email;
|
||||
private String password;
|
||||
private Role role;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.faf223.expensetrackerfaf.dto;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.ExpenseCategory;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ExpenseCreationDTO {
|
||||
@NotNull(message = "Category must not be null")
|
||||
private int expenseCategory;
|
||||
|
||||
@NotNull(message = "Amount must not be null")
|
||||
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||
private BigDecimal amount;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.dto;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.ExpenseCategory;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -10,9 +12,19 @@ import java.time.LocalDate;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ExpenseDTO {
|
||||
@NotNull(message = "ID must not be null")
|
||||
private long expenseId;
|
||||
|
||||
@NotNull(message = "User must not be null")
|
||||
private UserDTO userDTO;
|
||||
|
||||
@NotNull(message = "Category must not be null")
|
||||
private ExpenseCategory expenseCategory;
|
||||
|
||||
@NotNull(message = "Date must not be null")
|
||||
private LocalDate date;
|
||||
|
||||
@NotNull(message = "Amount must not be null")
|
||||
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||
private BigDecimal amount;
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.faf223.expensetrackerfaf.dto;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class IncomeCreationDTO {
|
||||
@NotNull(message = "Category must not be null")
|
||||
private int incomeCategory;
|
||||
|
||||
@NotNull(message = "Amount must not be null")
|
||||
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||
private BigDecimal amount;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.dto;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -10,9 +12,19 @@ import java.time.LocalDate;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class IncomeDTO {
|
||||
@NotNull(message = "ID must not be null")
|
||||
private long incomeId;
|
||||
|
||||
@NotNull(message = "User must not be null")
|
||||
private UserDTO userDTO;
|
||||
|
||||
@NotNull(message = "Category must not be null")
|
||||
private IncomeCategory incomeCategory;
|
||||
|
||||
@NotNull(message = "Date must not be null")
|
||||
private LocalDate date;
|
||||
|
||||
@NotNull(message = "Amount must not be null")
|
||||
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||
private BigDecimal amount;
|
||||
}
|
||||
@@ -1,15 +1,28 @@
|
||||
package com.faf223.expensetrackerfaf.dto;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserCreationDTO {
|
||||
|
||||
@NotNull(message = "First name must not be null")
|
||||
@NotEmpty(message = "First name must not be empty")
|
||||
private String firstname;
|
||||
@NotNull(message = "Last name must not be null")
|
||||
@NotEmpty(message = "Last name must not be empty")
|
||||
private String lastname;
|
||||
@NotNull(message = "Username must not be null")
|
||||
@NotEmpty(message = "Username must not be empty")
|
||||
private String username;
|
||||
@NotNull(message = "Email must not be null")
|
||||
@NotEmpty(message = "Email must not be empty")
|
||||
@Email(message = "Email must be valid")
|
||||
private String email;
|
||||
@NotNull(message = "Password must not be null")
|
||||
@NotEmpty(message = "Password must not be empty")
|
||||
private String password;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
package com.faf223.expensetrackerfaf.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserDTO {
|
||||
|
||||
@NotNull(message = "Name must not be null")
|
||||
@NotEmpty(message = "Name must not be empty")
|
||||
private String name;
|
||||
@NotNull(message = "Surname must not be null")
|
||||
@NotEmpty(message = "Surname must not be empty")
|
||||
private String surname;
|
||||
@NotNull(message = "Username must not be null")
|
||||
@NotEmpty(message = "Username must not be empty")
|
||||
private String username;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
@@ -24,9 +30,14 @@ public class Expense implements IMoneyTransaction {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "category_id")
|
||||
@NotNull
|
||||
private ExpenseCategory category;
|
||||
|
||||
@NotNull
|
||||
private LocalDate date;
|
||||
|
||||
@NotNull
|
||||
@DecimalMin(value = "0.0", inclusive = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
public Expense(LocalDate date, BigDecimal amount) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -12,5 +14,7 @@ public class ExpenseCategory implements IMoneyTransactionCategory {
|
||||
private Long id;
|
||||
|
||||
@Column(name = "category_name")
|
||||
@NotNull(message = "Name must not be null")
|
||||
@NotEmpty(message = "Name must not be empty")
|
||||
private String name;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -25,9 +27,14 @@ public class Income implements IMoneyTransaction {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "category_id")
|
||||
@NotNull
|
||||
private IncomeCategory category;
|
||||
|
||||
@NotNull
|
||||
private LocalDate date;
|
||||
|
||||
@NotNull
|
||||
@DecimalMin(value = "0.0", inclusive = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
public Income(IncomeCategory incomeCategory, LocalDate date, BigDecimal amount) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -12,6 +14,8 @@ public class IncomeCategory implements IMoneyTransactionCategory {
|
||||
private Long id;
|
||||
|
||||
@Column(name = "category_name")
|
||||
@NotNull(message = "Name must not be null")
|
||||
@NotEmpty(message = "Name must not be empty")
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,12 +19,18 @@ public class User {
|
||||
private String userUuid;
|
||||
|
||||
@Column(name = "name")
|
||||
@NotNull(message = "First name must not be null")
|
||||
@NotEmpty(message = "First name must not be empty")
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "surname")
|
||||
@NotNull(message = "Last name must not be null")
|
||||
@NotEmpty(message = "Last name must not be empty")
|
||||
private String lastName;
|
||||
|
||||
@Column(name = "username")
|
||||
@NotNull(message = "Username must not be null")
|
||||
@NotEmpty(message = "Username must not be empty")
|
||||
private String username;
|
||||
|
||||
@Transient
|
||||
|
||||
@@ -3,11 +3,28 @@ package com.faf223.expensetrackerfaf.repository;
|
||||
import com.faf223.expensetrackerfaf.model.Expense;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.query.Procedure;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ExpenseRepository extends JpaRepository<Expense, Long> {
|
||||
List<Expense> findByUser(User user);
|
||||
List<Expense> findByDate(LocalDate date);
|
||||
|
||||
List<Expense> findByDateBetween(LocalDate start, LocalDate end);
|
||||
|
||||
@Procedure(procedureName = "get_expenses_by_month")
|
||||
List<Expense> filterByMonth(int month);
|
||||
|
||||
@Procedure(procedureName = "get_last_week_expenses")
|
||||
List<Expense> findLastWeek();
|
||||
|
||||
@Procedure(procedureName = "get_last_month_expenses")
|
||||
List<Expense> findLastMonth();
|
||||
|
||||
@Procedure(procedureName = "get_expenses_by_year_interval")
|
||||
List<Expense> filterByYearInterval(int start, int end);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,33 @@ package com.faf223.expensetrackerfaf.repository;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.query.Procedure;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface IncomeRepository extends JpaRepository<Income, Long> {
|
||||
List<Income> findByUser(User user);
|
||||
List<Income> findByDate(LocalDate date);
|
||||
|
||||
List<Income> findByDateBetween(LocalDate start, LocalDate end);
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Procedure(procedureName = "get_incomes_by_month")
|
||||
List<Income> filterByMonth(int month);
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Procedure(procedureName = "get_last_week_incomes")
|
||||
List<Income> findLastWeek();
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Procedure(procedureName = "get_last_month_incomes")
|
||||
List<Income> findLastMonth();
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Procedure(procedureName = "get_incomes_by_year_interval")
|
||||
List<Income> filterByYearInterval(int start, int end);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,14 @@ import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||
import com.faf223.expensetrackerfaf.security.PersonDetails;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotAuthenticatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -29,6 +31,7 @@ public class AuthenticationService {
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtService jwtService;
|
||||
private final AuthenticationManager authenticationManager;
|
||||
private final PasswordGenerator passwordGenerator;
|
||||
|
||||
public AuthenticationResponse register(RegisterRequest request) {
|
||||
|
||||
@@ -46,20 +49,72 @@ public class AuthenticationService {
|
||||
String jwtToken = jwtService.generateToken(userDetails);
|
||||
String refreshToken = jwtService.generateRefreshToken(userDetails);
|
||||
|
||||
System.out.println(user);
|
||||
return AuthenticationResponse.builder()
|
||||
.accessToken(jwtToken)
|
||||
.refreshToken(refreshToken)
|
||||
.build();
|
||||
}
|
||||
|
||||
public AuthenticationResponse authenticate(AuthenticationRequest request) {
|
||||
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(request.getEmail(), request.getPassword()));
|
||||
public AuthenticationResponse register(OAuth2User oAuth2User) {
|
||||
String userEmail = oAuth2User.getAttribute("email");
|
||||
|
||||
Credential credential = credentialRepository.findByEmail(request.getEmail()).orElseThrow((() -> new UsernameNotFoundException("User not found")));
|
||||
// Check if the user is already registered
|
||||
Optional<Credential> existingCredential = credentialRepository.findByEmail(userEmail);
|
||||
if (existingCredential.isPresent()) {
|
||||
UserDetails userDetails = new PersonDetails(existingCredential.get());
|
||||
String jwtToken = jwtService.generateToken(userDetails);
|
||||
String refreshToken = jwtService.generateRefreshToken(userDetails);
|
||||
|
||||
return AuthenticationResponse.builder()
|
||||
.accessToken(jwtToken)
|
||||
.refreshToken(refreshToken)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
String givenName = oAuth2User.getAttribute("given_name");
|
||||
String familyName = oAuth2User.getAttribute("family_name");
|
||||
String email = oAuth2User.getAttribute("email");
|
||||
|
||||
User user = User.builder()
|
||||
.firstName(givenName)
|
||||
.lastName(familyName)
|
||||
.username(email)
|
||||
.build();
|
||||
|
||||
String randomPassword = passwordGenerator.generateRandomPassword(8);
|
||||
|
||||
user.setPassword(passwordEncoder.encode(randomPassword));
|
||||
|
||||
userRepository.save(user);
|
||||
Credential credential = new Credential(user, email, passwordEncoder.encode(randomPassword));
|
||||
credentialRepository.save(credential);
|
||||
|
||||
UserDetails userDetails = new PersonDetails(credential);
|
||||
String jwtToken = jwtService.generateToken(userDetails);
|
||||
String refreshToken = jwtService.generateRefreshToken(userDetails);
|
||||
|
||||
System.out.println("New user: " + user);
|
||||
System.out.println("New credentials: " + credential);
|
||||
|
||||
return AuthenticationResponse.builder()
|
||||
.accessToken(jwtToken)
|
||||
.refreshToken(refreshToken)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public AuthenticationResponse authenticate(AuthenticationRequest request) {
|
||||
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(request.getEmail(), request.getPassword()));
|
||||
|
||||
Credential credential = credentialRepository.findByEmail(request.getEmail()).orElseThrow((() -> new UserNotFoundException("User not found")));
|
||||
|
||||
UserDetails userDetails = new PersonDetails(credential);
|
||||
String jwtToken = jwtService.generateToken(userDetails);
|
||||
String refreshToken = jwtService.generateRefreshToken(userDetails);
|
||||
System.out.println(jwtToken);
|
||||
return AuthenticationResponse.builder()
|
||||
.accessToken(jwtToken)
|
||||
.refreshToken(refreshToken)
|
||||
@@ -74,12 +129,13 @@ public class AuthenticationService {
|
||||
UserDetails userDetails = new PersonDetails(credential.get());
|
||||
|
||||
String jwtToken = jwtService.generateToken(userDetails);
|
||||
System.out.println(jwtToken);
|
||||
return AuthenticationResponse.builder()
|
||||
.accessToken(jwtToken)
|
||||
.refreshToken(refreshToken)
|
||||
.build();
|
||||
} else {
|
||||
throw new RuntimeException("Invalid or expired refresh token");
|
||||
throw new UserNotAuthenticatedException("Invalid or expired refresh token");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CredentialService {
|
||||
|
||||
private final CredentialRepository credentialRepository;
|
||||
|
||||
public Optional<Credential> findByEmail(String email) {
|
||||
return credentialRepository.findByEmail(email);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,11 +3,21 @@ package com.faf223.expensetrackerfaf.service;
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.model.Expense;
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.ExpenseRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||
import com.faf223.expensetrackerfaf.util.TransactionFilter;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotAuthenticatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -18,6 +28,8 @@ public class ExpenseService implements ITransactionService {
|
||||
|
||||
private final ExpenseRepository expenseRepository;
|
||||
private final CredentialRepository credentialRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final TransactionFilter transactionFilter;
|
||||
|
||||
public void createOrUpdate(IMoneyTransaction expense) {
|
||||
expenseRepository.save((Expense) expense);
|
||||
@@ -33,6 +45,61 @@ public class ExpenseService implements ITransactionService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Expense> getTransactionsByDate(LocalDate date) {
|
||||
return expenseRepository.findByDate(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Expense> getTransactionsByDate(LocalDate date, String email) {
|
||||
return (List<Expense>) transactionFilter.filterByEmail(getTransactionsByDate(date), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Expense> getTransactionsByMonth(Month month) {
|
||||
return expenseRepository.filterByMonth(month.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Expense> getTransactionsByMonth(Month month, String email) {
|
||||
return (List<Expense>) transactionFilter.filterByEmail(getTransactionsByMonth(month), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Expense> getLastWeekTransactions() {
|
||||
return expenseRepository.findLastWeek();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Expense> getLastWeekTransactions(String email) {
|
||||
return (List<Expense>) transactionFilter.filterByEmail(getLastWeekTransactions(), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Expense> getLastMonthTransactions() {
|
||||
return expenseRepository.findLastMonth();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Expense> getLastMonthTransactions(String email) {
|
||||
return (List<Expense>) transactionFilter.filterByEmail(getLastMonthTransactions(), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Expense> getYearIntervalTransactions(int start, int end) {
|
||||
return expenseRepository.filterByYearInterval(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Expense> getYearIntervalTransactions(String email, int start, int end) {
|
||||
return (List<Expense>) transactionFilter.filterByEmail(getYearIntervalTransactions(start, end), email);
|
||||
}
|
||||
|
||||
public List<Expense> getTransactions() {
|
||||
return expenseRepository.findAll();
|
||||
}
|
||||
@@ -41,7 +108,30 @@ public class ExpenseService implements ITransactionService {
|
||||
return expenseRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public void deleteExpenseById(long id) {
|
||||
public void deleteTransactionById(long id) {
|
||||
expenseRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean belongsToUser(IMoneyTransaction transaction) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
if(authentication.getAuthorities().stream().noneMatch(authority -> authority.getAuthority().equals("ADMIN"))) {
|
||||
|
||||
Optional<Credential> credential = credentialRepository.findByEmail(userDetails.getUsername());
|
||||
if(credential.isEmpty()) throw new UserNotFoundException("The user has not been found");
|
||||
Optional<User> user = userRepository.findById(credential.get().getUser().getUserUuid());
|
||||
if(user.isEmpty()) throw new UserNotFoundException("The user has not been found");
|
||||
|
||||
return user.get().getExpenses().contains((Expense) transaction);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw new UserNotAuthenticatedException("You are not authenticated");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.List;
|
||||
|
||||
public interface ITransactionService {
|
||||
@@ -9,6 +13,17 @@ public interface ITransactionService {
|
||||
void createOrUpdate(IMoneyTransaction transaction);
|
||||
List<? extends IMoneyTransaction> getTransactions();
|
||||
List<? extends IMoneyTransaction> getTransactionsByEmail(String email);
|
||||
List<? extends IMoneyTransaction> getTransactionsByDate(LocalDate date);
|
||||
List<? extends IMoneyTransaction> getTransactionsByDate(LocalDate date, String email);
|
||||
List<? extends IMoneyTransaction> getTransactionsByMonth(Month month);
|
||||
List<? extends IMoneyTransaction> getTransactionsByMonth(Month month, String email);
|
||||
List<? extends IMoneyTransaction> getLastWeekTransactions();
|
||||
List<? extends IMoneyTransaction> getLastWeekTransactions(String email);
|
||||
List<? extends IMoneyTransaction> getLastMonthTransactions();
|
||||
List<? extends IMoneyTransaction> getLastMonthTransactions(String email);
|
||||
List<? extends IMoneyTransaction> getYearIntervalTransactions(int start, int end);
|
||||
List<? extends IMoneyTransaction> getYearIntervalTransactions(String email, int start, int end);
|
||||
IMoneyTransaction getTransactionById(long id);
|
||||
|
||||
void deleteTransactionById(long it);
|
||||
boolean belongsToUser(IMoneyTransaction transaction);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,21 @@ package com.faf223.expensetrackerfaf.service;
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.IncomeRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||
import com.faf223.expensetrackerfaf.util.TransactionFilter;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotAuthenticatedException;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -18,6 +28,8 @@ public class IncomeService implements ITransactionService {
|
||||
|
||||
private final IncomeRepository incomeRepository;
|
||||
private final CredentialRepository credentialRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final TransactionFilter transactionFilter;
|
||||
|
||||
public void createOrUpdate(IMoneyTransaction income) {
|
||||
incomeRepository.save((Income) income);
|
||||
@@ -37,11 +49,88 @@ public class IncomeService implements ITransactionService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Income> getTransactionsByDate(LocalDate date) {
|
||||
return incomeRepository.findByDate(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Income> getTransactionsByDate(LocalDate date, String email) {
|
||||
return (List<Income>) transactionFilter.filterByEmail(getTransactionsByDate(date), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Income> getTransactionsByMonth(Month month) {
|
||||
return incomeRepository.filterByMonth(month.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Income> getTransactionsByMonth(Month month, String email) {
|
||||
return (List<Income>) transactionFilter.filterByEmail(getTransactionsByMonth(month), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Income> getLastWeekTransactions() {
|
||||
return incomeRepository.findLastWeek();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Income> getLastWeekTransactions(String email) {
|
||||
return (List<Income>) transactionFilter.filterByEmail(getLastWeekTransactions(), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Income> getLastMonthTransactions() {
|
||||
return incomeRepository.findLastMonth();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Income> getLastMonthTransactions(String email) {
|
||||
return (List<Income>) transactionFilter.filterByEmail(getLastMonthTransactions(), email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Income> getYearIntervalTransactions(int start, int end) {
|
||||
return incomeRepository.filterByYearInterval(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Income> getYearIntervalTransactions(String email, int start, int end) {
|
||||
return (List<Income>) transactionFilter.filterByEmail(getYearIntervalTransactions(start, end), email);
|
||||
}
|
||||
|
||||
public Income getTransactionById(long id) {
|
||||
return incomeRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public void deleteIncomeById(long id) {
|
||||
public void deleteTransactionById(long id) {
|
||||
incomeRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean belongsToUser(IMoneyTransaction transaction) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
if(authentication.getAuthorities().stream().noneMatch(authority -> authority.getAuthority().equals("ADMIN"))) {
|
||||
|
||||
Optional<Credential> credential = credentialRepository.findByEmail(userDetails.getUsername());
|
||||
if(credential.isEmpty()) throw new UserNotFoundException("The user has not been found");
|
||||
Optional<User> user = userRepository.findById(credential.get().getUser().getUserUuid());
|
||||
if(user.isEmpty()) throw new UserNotFoundException("The user has not been found");
|
||||
|
||||
return user.get().getIncomes().contains((Income) transaction);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw new UserNotAuthenticatedException("You are not authenticated");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
@Service
|
||||
public class PasswordGenerator {
|
||||
|
||||
private final SecureRandom secureRandom = new SecureRandom();
|
||||
|
||||
public String generateRandomPassword(int length) {
|
||||
byte[] randomBytes = new byte[length];
|
||||
secureRandom.nextBytes(randomBytes);
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(randomBytes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.faf223.expensetrackerfaf.util;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
import com.faf223.expensetrackerfaf.service.CredentialService;
|
||||
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TransactionFilter {
|
||||
|
||||
private final CredentialService credentialService;
|
||||
|
||||
public List<? extends IMoneyTransaction> filterByEmail(List<? extends IMoneyTransaction> transactions, String email) {
|
||||
Optional<Credential> credential = credentialService.findByEmail(email);
|
||||
if(credential.isEmpty())
|
||||
throw new UserNotFoundException("The user has not been found");
|
||||
|
||||
return transactions
|
||||
.stream()
|
||||
.filter(transaction -> credential.get().getUser().equals(transaction.getUser()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.faf223.expensetrackerfaf.util.errors;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ErrorResponse {
|
||||
private String message;
|
||||
private long timestamp;
|
||||
|
||||
public ErrorResponse(String message, long timestamp) {
|
||||
this.message = message;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public ErrorResponse(String message) {
|
||||
this.message = message;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static ErrorResponse from(BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors()) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
|
||||
List<FieldError> errors = bindingResult.getFieldErrors();
|
||||
for(FieldError fieldError : errors)
|
||||
errorMessage.append(fieldError.getField())
|
||||
.append(" - ")
|
||||
.append(fieldError.getDefaultMessage())
|
||||
.append(";");
|
||||
|
||||
return new ErrorResponse(errorMessage.toString(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
return new ErrorResponse("No error message was provided", System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.util.exceptions;
|
||||
|
||||
public class TransactionDoesNotBelongToTheUserException extends RuntimeException {
|
||||
public TransactionDoesNotBelongToTheUserException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.util.exceptions;
|
||||
|
||||
public class TransactionNotCreatedException extends RuntimeException {
|
||||
public TransactionNotCreatedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.util.exceptions;
|
||||
|
||||
public class TransactionNotUpdatedException extends RuntimeException {
|
||||
public TransactionNotUpdatedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.util.exceptions;
|
||||
|
||||
public class TransactionsNotFoundException extends RuntimeException {
|
||||
public TransactionsNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.util.exceptions;
|
||||
|
||||
public class UserNotAuthenticatedException extends RuntimeException {
|
||||
public UserNotAuthenticatedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.util.exceptions;
|
||||
|
||||
public class UserNotCreatedException extends RuntimeException {
|
||||
public UserNotCreatedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.util.exceptions;
|
||||
|
||||
public class UserNotFoundException extends RuntimeException {
|
||||
public UserNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,9 @@
|
||||
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
||||
"axios": "^1.5.1",
|
||||
"bootstrap": "^5.3.2",
|
||||
"chart.js": "^4.4.0",
|
||||
"email-validator": "^2.0.4",
|
||||
"js-cookie": "^3.0.5",
|
||||
"stores": "^1.0.0",
|
||||
"svelte-cookie": "^1.0.1",
|
||||
"svelte-fa": "^3.0.4",
|
||||
"svelte-simple-modal": "^1.6.1",
|
||||
@@ -579,9 +578,9 @@
|
||||
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg=="
|
||||
},
|
||||
"node_modules/@jridgewell/trace-mapping": {
|
||||
"version": "0.3.19",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz",
|
||||
"integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==",
|
||||
"version": "0.3.20",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz",
|
||||
"integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==",
|
||||
"dependencies": {
|
||||
"@jridgewell/resolve-uri": "^3.1.0",
|
||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
@@ -639,6 +638,16 @@
|
||||
"integrity": "sha512-C16M+IYz0rgRhWZdCmK+h58JMv8vijAA61gmz2rspCSwKwzBebpdcsiUmwrtJRdphuY30i6BSLEOP8ppbNLyLg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@popperjs/core": {
|
||||
"version": "2.11.8",
|
||||
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
|
||||
"integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/popperjs"
|
||||
}
|
||||
},
|
||||
"node_modules/@sveltejs/adapter-auto": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-auto/-/adapter-auto-2.1.0.tgz",
|
||||
@@ -729,9 +738,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.2.tgz",
|
||||
"integrity": "sha512-VeiPZ9MMwXjO32/Xu7+OwflfmeoRwkE/qzndw42gGtgJwZopBnzy2gD//NN1+go1mADzkDcqf/KnFRSjTJ8xJA=="
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
|
||||
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw=="
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.10.0",
|
||||
@@ -836,6 +845,24 @@
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/bootstrap": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.2.tgz",
|
||||
"integrity": "sha512-D32nmNWiQHo94BKHLmOrdjlL05q1c8oxbtBphQFb9Z5to6eGRDCm0QgeaZ4zFBHzfg2++rqa2JkqCcxDy0sH0g==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/twbs"
|
||||
},
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/bootstrap"
|
||||
}
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@popperjs/core": "^2.11.8"
|
||||
}
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
@@ -976,11 +1003,6 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/curry": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/curry/-/curry-1.2.0.tgz",
|
||||
"integrity": "sha512-PAdmqPH2DUYTCc/aknv6RxRxmqdRHclvbz+wP8t1Xpg2Nu13qg+oLb6/5iFoDmf4dbmC9loYoy9PwwGbFt/AqA=="
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
@@ -1491,11 +1513,6 @@
|
||||
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/graceful-fs-stream": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs-stream/-/graceful-fs-stream-0.0.1.tgz",
|
||||
"integrity": "sha512-yZ9Lx4O/LbIQ0prZNtXOt97h8ICA2fwPcmSkrjZcOnXKrMzR8ao+kE78N76su0ffaawHLHyFYt75AkgHdVb41Q=="
|
||||
},
|
||||
"node_modules/graphemer": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
|
||||
@@ -1615,14 +1632,6 @@
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/js-cookie": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
|
||||
"integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
@@ -1796,25 +1805,6 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/minimist": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/mkdirp": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.6"
|
||||
},
|
||||
"bin": {
|
||||
"mkdirp": "bin/cmd.js"
|
||||
}
|
||||
},
|
||||
"node_modules/mri": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||
@@ -1863,14 +1853,6 @@
|
||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/on-headers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
@@ -2319,17 +2301,6 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/stores": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/stores/-/stores-1.0.0.tgz",
|
||||
"integrity": "sha512-aOWM422mpxSj37uo9R1aVKDF2sDRCzjdbn6CYT/H9BECxuuliALmAZcmRVI9/Wq6Pu/HKDY1xZ+ssSuvY6fLlA==",
|
||||
"dependencies": {
|
||||
"curry": "~1.2.0",
|
||||
"graceful-fs-stream": "0.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"on-headers": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||
@@ -2367,9 +2338,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/svelte": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.1.tgz",
|
||||
"integrity": "sha512-LpLqY2Jr7cRxkrTc796/AaaoMLF/1ax7cto8Ot76wrvKQhrPmZ0JgajiWPmg9mTSDqO16SSLiD17r9MsvAPTmw==",
|
||||
"version": "4.2.5",
|
||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.5.tgz",
|
||||
"integrity": "sha512-P9YPKsGkNdw4OJbtpd1uzimQHPj7Ai2sPcOHmmD6VgkFhFDmcYevQi7vE4cQ1g8/Vs64aL2TwMoCNFAzv7TPaQ==",
|
||||
"dependencies": {
|
||||
"@ampproject/remapping": "^2.2.1",
|
||||
"@jridgewell/sourcemap-codec": "^1.4.15",
|
||||
@@ -2382,7 +2353,7 @@
|
||||
"estree-walker": "^3.0.3",
|
||||
"is-reference": "^3.0.1",
|
||||
"locate-character": "^3.0.0",
|
||||
"magic-string": "^0.30.0",
|
||||
"magic-string": "^0.30.4",
|
||||
"periscopic": "^3.1.0"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -26,10 +26,9 @@
|
||||
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
||||
"axios": "^1.5.1",
|
||||
"bootstrap": "^5.3.2",
|
||||
"chart.js": "^4.4.0",
|
||||
"email-validator": "^2.0.4",
|
||||
"js-cookie": "^3.0.5",
|
||||
"stores": "^1.0.0",
|
||||
"svelte-cookie": "^1.0.1",
|
||||
"svelte-fa": "^3.0.4",
|
||||
"svelte-simple-modal": "^1.6.1",
|
||||
|
||||
@@ -1,36 +1,80 @@
|
||||
<script>
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import * as EmailValidator from 'email-validator';
|
||||
import {onMount} from "svelte";
|
||||
import {getCookie, setCookie} from "svelte-cookie";
|
||||
import axios from "axios";
|
||||
|
||||
let isErrorVisible = false;
|
||||
let username, email, password;
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let username, email, password, name, surname;
|
||||
let message = ""
|
||||
|
||||
function submitForm(event) {
|
||||
onMount(async () => {
|
||||
|
||||
const access_token = getCookie('access_token');
|
||||
const refresh_token = getCookie('refresh_token');
|
||||
|
||||
if (access_token && refresh_token) {
|
||||
window.location.href = '/dashboard';
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
async function submitForm(event) {
|
||||
event.preventDefault();
|
||||
console.log("Tried to submit!");
|
||||
console.log("Valid? ", (validateEmail() && validateUsername() && validatePassword() ? "Yes" : "No"));
|
||||
|
||||
try {
|
||||
const data = {
|
||||
firstname: name,
|
||||
lastname: surname,
|
||||
username: username,
|
||||
email: email,
|
||||
password: password,
|
||||
};
|
||||
|
||||
console.log(data)
|
||||
|
||||
const response = await axios.post('http://localhost:8081/api/v1/auth/register', data);
|
||||
|
||||
const { access_token, refresh_token } = response.data;
|
||||
|
||||
setCookie('access_token', access_token);
|
||||
setCookie('refresh_token', refresh_token);
|
||||
|
||||
window.location.href = '/dashboard'
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function validateEmail() {
|
||||
let valid = EmailValidator.validate(username);
|
||||
isErrorVisible = valid ? false : true;
|
||||
message = isErrorVisible ? "Invalid e-mail!" : "";
|
||||
return valid;
|
||||
}
|
||||
// function submitForm(event) {
|
||||
// event.preventDefault();
|
||||
// // console.log("Tried to submit!");
|
||||
// // console.log("Valid? ", (validateEmail() && validateUsername() && validatePassword() ? "Yes" : "No"));
|
||||
// }
|
||||
|
||||
function validatePassword() {
|
||||
let valid = password.value != '';
|
||||
isErrorVisible = valid ? false : true;
|
||||
message = isErrorVisible ? "Invalid password!" : "";
|
||||
return valid;
|
||||
}
|
||||
|
||||
function validateUsername() {
|
||||
let valid = username.value != '';
|
||||
isErrorVisible = valid ? false : true;
|
||||
message = isErrorVisible ? "Invalid password!" : "";
|
||||
return valid;
|
||||
}
|
||||
// function validateEmail() {
|
||||
// let valid = EmailValidator.validate(username);
|
||||
// isErrorVisible = valid ? false : true;
|
||||
// message = isErrorVisible ? "Invalid e-mail!" : "";
|
||||
// return valid;
|
||||
// }
|
||||
//
|
||||
// function validatePassword() {
|
||||
// let valid = password.value != '';
|
||||
// isErrorVisible = valid ? false : true;
|
||||
// message = isErrorVisible ? "Invalid password!" : "";
|
||||
// return valid;
|
||||
// }
|
||||
//
|
||||
// function validateUsername() {
|
||||
// let valid = username.value != '';
|
||||
// isErrorVisible = valid ? false : true;
|
||||
// message = isErrorVisible ? "Invalid password!" : "";
|
||||
// return valid;
|
||||
// }
|
||||
|
||||
</script>
|
||||
|
||||
@@ -45,11 +89,17 @@
|
||||
<input id="usernameInput" type="text" name="username" placeholder="Username" autocomplete="off" on:input={
|
||||
event => {username = event.target.value}
|
||||
}>
|
||||
<input id="nameInput" type="text" name="name" placeholder="Name" autocomplete="off" on:input={
|
||||
event => {name = event.target.value}
|
||||
}>
|
||||
<input id="surnameInput" type="text" name="surname" placeholder="Surname" autocomplete="off" on:input={
|
||||
event => {surname = event.target.value}
|
||||
}>
|
||||
<input id="emailInput" type="text" name="email" placeholder="Email" autocomplete="off" on:input={
|
||||
event => {email = event.target.value}
|
||||
}>
|
||||
<input id="passwordInput" type="password" name="password" placeholder="Password" autocomplete="off" on:input={
|
||||
event => {password = event.target.password}
|
||||
event => {password = event.target.value}
|
||||
}>
|
||||
<a href="/auth/recovery" class="recoveryPass">Forgot your password?</a>
|
||||
<input type="submit" value="Sign up" class="submitButton">
|
||||
@@ -75,7 +125,7 @@
|
||||
border-top: 10px solid #79a6fe;
|
||||
border-bottom: 10px solid #8BD17C;
|
||||
width: 400px;
|
||||
height: 600px;
|
||||
height: 750px;
|
||||
box-shadow: 1px 1px 108.8px 19.2px rgb(25, 31, 53);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
<script>
|
||||
import Dashboard from './board/Dashboard.svelte';
|
||||
import SideMenu from './menu/SideMenu.svelte';
|
||||
import {selectedTab} from "./stores.js";
|
||||
import {globalStyles} from "./styles.js";
|
||||
|
||||
function handleTabClick(tab) {
|
||||
selectedTab.set(tab);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div id="wrapper">
|
||||
<SideMenu />
|
||||
<div id="wrapper" style="background-color: {$globalStyles.mainColor}">
|
||||
<SideMenu onTabClick={handleTabClick} />
|
||||
<Dashboard />
|
||||
</div>
|
||||
|
||||
@@ -12,10 +19,10 @@
|
||||
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400');
|
||||
|
||||
#wrapper {
|
||||
background-color: rgb(23,34,51);
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
min-height: 100vh;
|
||||
max-height: 100%;
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
}
|
||||
</style>
|
||||
@@ -1,15 +1,21 @@
|
||||
<script>
|
||||
import DashHeader from "./other/DashHeader.svelte";
|
||||
import DataMenu from "./other/DataMenu.svelte";
|
||||
import QuickInfobar from "./other/QuickInfobar.svelte";
|
||||
import { getCookie } from "svelte-cookie";
|
||||
import { onMount } from "svelte";
|
||||
import ExpenseDashboard from "./ExpenseDashboard.svelte";
|
||||
import IncomeDashboard from "./IncomeDashboard.svelte";
|
||||
import Settings from "./Settings.svelte";
|
||||
import { incomeData, expenseData, incomeTypes, expenseTypes, selectedTab } from "../stores.js";
|
||||
import {globalStyles} from "../styles.js";
|
||||
|
||||
import {incomeData, expenseData, incomeTypes, expenseTypes} from "../stores.js";
|
||||
let componentStyles;
|
||||
|
||||
$: {
|
||||
console.log("got here")
|
||||
componentStyles = $globalStyles;
|
||||
}
|
||||
|
||||
import axios from "axios";
|
||||
|
||||
|
||||
onMount(async () => {
|
||||
const token = getCookie('access_token');
|
||||
|
||||
@@ -42,23 +48,28 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="dashboard">
|
||||
<DashHeader />
|
||||
<QuickInfobar />
|
||||
<DataMenu />
|
||||
<div id="dashboard" style="background-color: {componentStyles.dashColor}; color: {componentStyles.color}">
|
||||
{#if $selectedTab === 'expenses'}
|
||||
<ExpenseDashboard />
|
||||
{:else if $selectedTab === 'incomes'}
|
||||
<IncomeDashboard />
|
||||
{:else if $selectedTab === 'settings'}
|
||||
<Settings />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#dashboard {
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
background-color: rgb(245,242,243);
|
||||
border-radius: 20px;
|
||||
margin: 20px;
|
||||
padding: 20px 20px 0;
|
||||
min-width: 100px;
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
justify-content: stretch;
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import DashHeader from "./expenses/other/DashHeader.svelte";
|
||||
import DataMenu from "./expenses/other/DataMenu.svelte";
|
||||
import QuickInfobar from "./expenses/other/QuickInfobar.svelte";
|
||||
</script>
|
||||
|
||||
<DashHeader />
|
||||
<QuickInfobar />
|
||||
<DataMenu />
|
||||
@@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import DashHeader from "./incomes/other/DashHeader.svelte";
|
||||
import DataMenu from "./incomes/other/DataMenu.svelte";
|
||||
import QuickInfobar from "./incomes/other/QuickInfobar.svelte";
|
||||
</script>
|
||||
|
||||
<DashHeader />
|
||||
<QuickInfobar />
|
||||
<DataMenu />
|
||||
@@ -0,0 +1,59 @@
|
||||
<script>
|
||||
import {globalStyles} from "../styles.js";
|
||||
import {themeDark} from "../styles.js";
|
||||
import {themeDefault} from "../styles.js";
|
||||
|
||||
function theme_dark() {
|
||||
$globalStyles = themeDark;
|
||||
}
|
||||
|
||||
function theme_default() {
|
||||
$globalStyles = themeDefault;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<h1>Settings</h1>
|
||||
<button class="button-32" on:click={() => theme_default()}>Select</button>
|
||||
|
||||
<button class="button-32" on:click={() => theme_dark()}>Select</button>
|
||||
|
||||
<button class="button-32" on:click={() => theme_dark()}>Select</button>
|
||||
|
||||
<button class="button-32" on:click={() => theme_dark()}>Select</button>
|
||||
|
||||
<button class="button-32" on:click={() => theme_dark()}>Select</button>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.button-32 {
|
||||
background-color: #fff000;
|
||||
border-radius: 12px;
|
||||
color: #000;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
padding: 10px 15px;
|
||||
text-align: center;
|
||||
transition: 200ms;
|
||||
width: 100px;
|
||||
box-sizing: border-box;
|
||||
border: 0;
|
||||
font-size: 16px;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.button-32:not(:disabled):hover,
|
||||
.button-32:not(:disabled):focus {
|
||||
outline: 0;
|
||||
background: #f4e603;
|
||||
box-shadow: 0 0 0 2px rgba(0,0,0,.2), 0 3px 8px 0 rgba(0,0,0,.15);
|
||||
}
|
||||
|
||||
.button-32:disabled {
|
||||
filter: saturate(0.2) opacity(0.5);
|
||||
-webkit-filter: saturate(0.2) opacity(0.5);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
@@ -1,7 +1,8 @@
|
||||
<script>
|
||||
import Chart from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
import { expenseData } from "../../stores.js";
|
||||
import { expenseData } from "../../../stores.js";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
@@ -73,7 +74,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="chart">
|
||||
<div id="chart" style="background-color: {$globalStyles.mainColor}">
|
||||
<canvas bind:this={chartCanvas}></canvas>
|
||||
</div>
|
||||
|
||||
@@ -82,9 +83,10 @@
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
background-color: #d3d3d3;
|
||||
border-radius: 0 0 10px 10px;
|
||||
margin: 0 0 10px 10px;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#chart:hover {
|
||||
@@ -0,0 +1,84 @@
|
||||
<script>
|
||||
import Chart from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
import { incomeData, expenseData } from "../../../stores.js";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
let chart = null;
|
||||
|
||||
function createGraph() {
|
||||
try {
|
||||
const totalIncomes = $incomeData.reduce((total, item) => total + item.amount, 0);
|
||||
const totalExpenses = $expenseData.reduce((total, item) => total + item.amount, 0);
|
||||
|
||||
const chartLabels = ['Incomes', 'Expenses'];
|
||||
const chartValues = [totalIncomes, totalExpenses];
|
||||
|
||||
if (chartCanvas.getContext('2d') !== undefined) {
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
if (!chart) {
|
||||
chart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
data: chartValues,
|
||||
backgroundColor: [
|
||||
'rgb(243, 188, 0)',
|
||||
'rgb(0, 117, 164)'
|
||||
],
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const totalIncomesUpd = $incomeData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
const totalExpensesUpd = $expenseData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
|
||||
const chartLabels = ['Incomes', 'Expenses'];
|
||||
const chartValues = [totalIncomesUpd, totalExpensesUpd];
|
||||
chart.data.labels = chartLabels;
|
||||
chart.data.datasets[0].data = chartValues;
|
||||
chart.update();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if ($incomeData || $expenseData) {
|
||||
createGraph();
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
createGraph();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="chart" style="background-color: {$globalStyles.mainColor}">
|
||||
<canvas bind:this={chartCanvas}></canvas>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#chart {
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
flex: 1;
|
||||
border-radius: 0 0 10px 10px;
|
||||
margin: 0 0 10px 10px;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,10 +1,11 @@
|
||||
<script>
|
||||
import Modal from '../modals/Modal.svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import axios from 'axios';
|
||||
import { getCookie } from "svelte-cookie";
|
||||
import {expenseTypes, expenseData} from "../../../stores.js";
|
||||
|
||||
|
||||
let showModal;
|
||||
let amount = '';
|
||||
let newData;
|
||||
@@ -40,10 +41,10 @@
|
||||
const selectedExpense = $expenseTypes.find(expense => expense.id === $selectedExpenseId);
|
||||
const data = {
|
||||
expenseCategory: selectedExpense.id,
|
||||
amount: amount,
|
||||
amount: parseInt(amount),
|
||||
};
|
||||
|
||||
addNewExpense(selectedExpense.id, amount);
|
||||
addNewExpense(selectedExpense.id, parseInt(amount));
|
||||
|
||||
try {
|
||||
const token = getCookie('access_token');
|
||||
@@ -100,7 +101,7 @@
|
||||
|
||||
<style>
|
||||
#exp {
|
||||
padding: 20px;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<script>
|
||||
import ContentExpense from "./ContentExpense.svelte";
|
||||
import { expenseData } from "../../../stores.js";
|
||||
import { globalStyles } from "../../../styles.js";
|
||||
</script>
|
||||
|
||||
<div id="expenseInfo" style="background-color: {$globalStyles.mainColor}">
|
||||
<ContentExpense />
|
||||
<div id="listContainer" style="color: {$globalStyles.color}">
|
||||
<ul>
|
||||
{#each $expenseData as item}
|
||||
<li style="color: {$globalStyles.color}">
|
||||
{item.incomeCategory ? `${item.incomeCategory.name}: ` : `${item.expenseCategory.name}: `}
|
||||
{item.incomeCategory ? `+${item.amount}$` : `-${item.amount}$`}
|
||||
{`${item.date}`}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
#expenseInfo {
|
||||
min-width: 300px;
|
||||
min-height: 0;
|
||||
background-color: #212942;
|
||||
color: white;
|
||||
border-radius: 0 0 10px 10px;
|
||||
margin: 0 0 10px 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#listContainer {
|
||||
flex: 1 1 auto;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
padding: 0 10px 10px;
|
||||
margin: 0 0 10px;
|
||||
box-sizing: border-box;
|
||||
border-radius: 0 0 10px 10px;
|
||||
}
|
||||
|
||||
#listContainer::-webkit-scrollbar {
|
||||
width: 0;
|
||||
}
|
||||
|
||||
#listContainer::-webkit-scrollbar-thumb {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#listContainer::-webkit-scrollbar-track {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#listContainer ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
border-radius: 0 0 10px 10px;
|
||||
}
|
||||
|
||||
#listContainer li {
|
||||
margin-bottom: 20px;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
|
||||
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
|
||||
}
|
||||
|
||||
#listContainer li:hover {
|
||||
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,168 @@
|
||||
<script>
|
||||
import Graph2 from '../graphs/Graph2.svelte';
|
||||
import Graph3 from '../graphs/Graph3.svelte';
|
||||
import Expenses from "../infolists/Expenses.svelte";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
import { slide } from 'svelte/transition'
|
||||
import {expenseTypes} from "../../../stores.js";
|
||||
|
||||
let isDateDropdownExpanded = false
|
||||
let isCategoryDropdownExpanded = false
|
||||
|
||||
function clickHandlerDate() {
|
||||
isDateDropdownExpanded = !isDateDropdownExpanded
|
||||
}
|
||||
|
||||
function clickHandlerCategory() {
|
||||
isCategoryDropdownExpanded = !isCategoryDropdownExpanded;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div id="main-data" style="background-color: {$globalStyles.dashColor}; color: {$globalStyles.color}">
|
||||
<div id="data-header" style="background-color:{$globalStyles.mainColor}; color: {$globalStyles.altColor}">
|
||||
<span style="color: {$globalStyles.altColor}">Revenue Analysis</span>
|
||||
|
||||
<div id="dropdown-date">
|
||||
<button id="button" on:click={clickHandlerDate}>Filter by Date:</button>
|
||||
{#if isDateDropdownExpanded}
|
||||
<div id="date-list" transition:slide>
|
||||
<div on:click={() => console.log("Today")}>Today</div>
|
||||
<div on:click={() => console.log("Yesterday")}>Yesterday</div>
|
||||
<div on:click={() => console.log("Last week")}>Last week</div>
|
||||
<div on:click={() => console.log("Last month")}>Last month</div>
|
||||
<div on:click={() => console.log("Current quarter")}>Current quarter</div>
|
||||
<div on:click={() => console.log("This year")}>This year</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div id="dropdown-category">
|
||||
<button id="button" on:click={clickHandlerCategory}>Filter by Category:</button>
|
||||
{#if isCategoryDropdownExpanded}
|
||||
<div id="category-list" transition:slide>
|
||||
{#each $expenseTypes as expense (expense.id)}
|
||||
{#if expense.id !== undefined}
|
||||
<option value={expense.id}>{expense.name}</option>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div id="data-menu">
|
||||
<div id="first-graph">
|
||||
<Graph2 />
|
||||
</div>
|
||||
<div id="second-graph">
|
||||
<Graph3 />
|
||||
</div>
|
||||
<Expenses />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#main-data {
|
||||
border-bottom-left-radius: 20px;
|
||||
border-bottom-right-radius: 20px;
|
||||
padding:0;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
height: 0;
|
||||
flex-direction: column;
|
||||
justify-content: stretch;
|
||||
align-items: stretch;
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
#button {
|
||||
background-color: #fff000;
|
||||
border-radius: 12px;
|
||||
color: #000;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
padding: 10px 15px;
|
||||
text-align: center;
|
||||
transition: 200ms;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
border: 0;
|
||||
font-size: 16px;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
#button:not(:disabled):hover,
|
||||
#button:not(:disabled):focus {
|
||||
outline: 0;
|
||||
background: #f4e603;
|
||||
box-shadow: 0 0 0 2px rgba(0,0,0,.2), 0 3px 8px 0 rgba(0,0,0,.15);
|
||||
}
|
||||
|
||||
#button:disabled {
|
||||
filter: saturate(0.2) opacity(0.5);
|
||||
-webkit-filter: saturate(0.2) opacity(0.5);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
|
||||
#date-list {
|
||||
background-color: #8BD17C;
|
||||
position:absolute;
|
||||
z-index:1;
|
||||
}
|
||||
|
||||
#category-list {
|
||||
background-color: #8BD17C;
|
||||
position:absolute;
|
||||
z-index:1;
|
||||
}
|
||||
|
||||
#data-header {
|
||||
background-color: black;
|
||||
min-height: 50px;
|
||||
padding-left: 30px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
border-top-left-radius: 20px;
|
||||
border-top-right-radius: 20px;
|
||||
font-size: larger;
|
||||
border: #8BD17C 2px solid;
|
||||
}
|
||||
|
||||
#data-menu {
|
||||
border-bottom-left-radius: 20px;
|
||||
border-bottom-right-radius: 20px;
|
||||
display:flex;
|
||||
/*padding:10px;*/
|
||||
flex-direction: row-reverse;
|
||||
justify-content: space-between;
|
||||
align-items: stretch;
|
||||
flex: 1;
|
||||
height: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
#first-graph {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#second-graph {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -1,6 +1,7 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { incomeData, expenseData } from "../../stores.js";
|
||||
import { incomeData, expenseData } from "../../../stores.js";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
|
||||
let infobar1, infobar2, infobar3, infobar4;
|
||||
let totalExpenses = 0;
|
||||
@@ -38,10 +39,10 @@
|
||||
</script>
|
||||
|
||||
<div id="quickInfobar">
|
||||
<div class="infobarElement" bind:this={infobar1}></div>
|
||||
<div class="infobarElement" bind:this={infobar2}></div>
|
||||
<div class="infobarElement" bind:this={infobar3}></div>
|
||||
<div class="infobarElement" bind:this={infobar4}></div>
|
||||
<div class="infobarElement" bind:this={infobar1} style="background-color: {$globalStyles.mainColor}"></div>
|
||||
<div class="infobarElement" bind:this={infobar2} style="background-color: {$globalStyles.mainColor}"></div>
|
||||
<div class="infobarElement" bind:this={infobar3} style="background-color: {$globalStyles.mainColor}"></div>
|
||||
<div class="infobarElement" bind:this={infobar4} style="background-color: {$globalStyles.mainColor}"></div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@@ -1,80 +0,0 @@
|
||||
<script>
|
||||
import Chart from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
import { incomeData, expenseData } from "../../stores.js";
|
||||
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
let chart = null;
|
||||
|
||||
function createGraph() {
|
||||
try {
|
||||
const totalIncomes = $incomeData.reduce((total, item) => total + item.amount, 0);
|
||||
const totalExpenses = $expenseData.reduce((total, item) => total + item.amount, 0);
|
||||
|
||||
const chartLabels = ['Incomes', 'Expenses'];
|
||||
const chartValues = [totalIncomes, totalExpenses];
|
||||
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
if (!chart) {
|
||||
chart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
data: chartValues,
|
||||
backgroundColor: [
|
||||
'rgb(243, 188, 0)',
|
||||
'rgb(0, 117, 164)'
|
||||
],
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const totalIncomesUpd = $incomeData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
const totalExpensesUpd = $expenseData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
|
||||
const chartLabels = ['Incomes', 'Expenses'];
|
||||
const chartValues = [totalIncomesUpd, totalExpensesUpd];
|
||||
chart.data.labels = chartLabels;
|
||||
chart.data.datasets[0].data = chartValues;
|
||||
chart.update();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if ($incomeData || $expenseData) {
|
||||
createGraph();
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
createGraph();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="chart">
|
||||
<canvas bind:this={chartCanvas}></canvas>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#chart {
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
background-color: #d3d3d3;
|
||||
}
|
||||
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,7 +1,15 @@
|
||||
<script>
|
||||
import Chart from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
import { incomeData } from "../../stores.js";
|
||||
import { incomeData } from "../../../stores.js";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
|
||||
let componentStyles;
|
||||
|
||||
$: {
|
||||
console.log("got here")
|
||||
componentStyles = $globalStyles;
|
||||
}
|
||||
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
@@ -76,7 +84,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="chart">
|
||||
<div id="chart" style="background-color: {componentStyles.mainColor}">
|
||||
<canvas bind:this={chartCanvas}></canvas>
|
||||
</div>
|
||||
|
||||
@@ -85,9 +93,10 @@
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
background-color: #d3d3d3;
|
||||
border-radius: 0 0 10px 10px;
|
||||
margin: 0 0 10px 10px;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#chart:hover {
|
||||
@@ -0,0 +1,91 @@
|
||||
<script>
|
||||
import Chart from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
import { incomeData, expenseData } from "../../../stores.js";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
|
||||
let componentStyles;
|
||||
|
||||
$: {
|
||||
console.log("got here")
|
||||
componentStyles = $globalStyles;
|
||||
}
|
||||
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
let chart = null;
|
||||
|
||||
function createGraph() {
|
||||
try {
|
||||
const totalIncomes = $incomeData.reduce((total, item) => total + item.amount, 0);
|
||||
const totalExpenses = $expenseData.reduce((total, item) => total + item.amount, 0);
|
||||
|
||||
const chartLabels = ['Incomes', 'Expenses'];
|
||||
const chartValues = [totalIncomes, totalExpenses];
|
||||
|
||||
if (chartCanvas.getContext('2d') !== undefined) {
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
if (!chart) {
|
||||
chart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
data: chartValues,
|
||||
backgroundColor: [
|
||||
'rgb(243, 188, 0)',
|
||||
'rgb(0, 117, 164)'
|
||||
],
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const totalIncomesUpd = $incomeData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
const totalExpensesUpd = $expenseData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
|
||||
const chartLabels = ['Incomes', 'Expenses'];
|
||||
const chartValues = [totalIncomesUpd, totalExpensesUpd];
|
||||
chart.data.labels = chartLabels;
|
||||
chart.data.datasets[0].data = chartValues;
|
||||
chart.update();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if ($incomeData || $expenseData) {
|
||||
createGraph();
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
createGraph();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="chart" style="background-color: {componentStyles.mainColor}">
|
||||
<canvas bind:this={chartCanvas}></canvas>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#chart {
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
flex: 1;
|
||||
border-radius: 0 0 10px 10px;
|
||||
margin: 0 0 10px 10px;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import Modal from '../modals/Modal.svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import axios from 'axios';
|
||||
import { getCookie } from "svelte-cookie";
|
||||
@@ -27,7 +27,7 @@
|
||||
},
|
||||
incomeCategory: incomeCategory,
|
||||
date: today,
|
||||
amount: amount
|
||||
amount: parseInt(amount)
|
||||
};
|
||||
|
||||
newData = $incomeData;
|
||||
@@ -45,7 +45,7 @@
|
||||
amount: parseInt(amount),
|
||||
};
|
||||
|
||||
addNewIncome(selectedIncome.id, amount);
|
||||
addNewIncome(selectedIncome.id, parseInt(amount));
|
||||
|
||||
try {
|
||||
const token = getCookie('access_token');
|
||||
@@ -102,7 +102,7 @@
|
||||
|
||||
<style>
|
||||
#inc {
|
||||
padding: 20px;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<script>
|
||||
import ContentIncome from "./ContentIncome.svelte";
|
||||
import { incomeData } from "../../../stores.js";
|
||||
import { globalStyles } from "../../../styles.js";
|
||||
</script>
|
||||
|
||||
<div id="incomeInfo" style="background-color: {$globalStyles.mainColor}">
|
||||
<ContentIncome />
|
||||
<div id="listContainer" style="color: {$globalStyles.color}">
|
||||
<ul>
|
||||
{#each $incomeData as item}
|
||||
<li>
|
||||
{item.incomeCategory ? `${item.incomeCategory.name}: ` : `${item.incomeCategory.name}: `}
|
||||
{item.incomeCategory ? `+${item.amount}$` : `-${item.amount}$`}
|
||||
{`${item.date}`}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
#incomeInfo {
|
||||
min-width: 300px;
|
||||
min-height: 0;
|
||||
background-color: #212942;
|
||||
color: white;
|
||||
border-radius: 0 0 10px 10px;
|
||||
margin: 0 0 10px 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#listContainer {
|
||||
flex: 1 1 auto;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
padding: 0 10px 10px;
|
||||
margin: 0 0 10px;
|
||||
box-sizing: border-box;
|
||||
border-radius: 0 0 10px 10px;
|
||||
}
|
||||
|
||||
#listContainer::-webkit-scrollbar {
|
||||
width: 0;
|
||||
}
|
||||
|
||||
#listContainer::-webkit-scrollbar-thumb {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#listContainer::-webkit-scrollbar-track {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#listContainer ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
border-radius: 0 0 10px 10px;
|
||||
}
|
||||
|
||||
#listContainer li {
|
||||
margin-bottom: 20px;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
|
||||
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
|
||||
}
|
||||
|
||||
#listContainer li:hover {
|
||||
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,57 @@
|
||||
<script>
|
||||
export let showModal;
|
||||
|
||||
let dialog;
|
||||
|
||||
$: if (dialog && showModal) dialog.showModal();
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-noninteractive-element-interactions -->
|
||||
<dialog
|
||||
bind:this={dialog}
|
||||
on:close={() => (showModal = false)}
|
||||
on:click|self={() => dialog.close()}
|
||||
>
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div on:click|stopPropagation>
|
||||
<slot name="header" />
|
||||
<slot />
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
dialog {
|
||||
max-width: 32em;
|
||||
border-radius: 20px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
}
|
||||
dialog::backdrop {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
dialog > div {
|
||||
padding: 1em;
|
||||
}
|
||||
dialog[open] {
|
||||
animation: zoom 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
|
||||
}
|
||||
@keyframes zoom {
|
||||
from {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
to {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
dialog[open]::backdrop {
|
||||
animation: fade 0.2s ease-out;
|
||||
}
|
||||
@keyframes fade {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,66 @@
|
||||
<script>
|
||||
|
||||
</script>
|
||||
|
||||
<div id="header">
|
||||
<div id="dashboardTitleWrapper">
|
||||
<h5>Hello, welcome to your</h5>
|
||||
<h1 id="dashboardTitle">Dashboard</h1>
|
||||
</div>
|
||||
|
||||
<div id="icons">
|
||||
<div class="headerbtn searchButton">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="1.3em" viewBox="0 0 512 512"><path d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352a144 144 0 1 0 0-288 144 144 0 1 0 0 288z"/></svg>
|
||||
</div>
|
||||
<div class="headerbtn notificationButton">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="1.3em" viewBox="0 0 448 512"><path d="M224 0c-17.7 0-32 14.3-32 32V49.9C119.5 61.4 64 124.2 64 200v33.4c0 45.4-15.5 89.5-43.8 124.9L5.3 377c-5.8 7.2-6.9 17.1-2.9 25.4S14.8 416 24 416H424c9.2 0 17.6-5.3 21.6-13.6s2.9-18.2-2.9-25.4l-14.9-18.6C399.5 322.9 384 278.8 384 233.4V200c0-75.8-55.5-138.6-128-150.1V32c0-17.7-14.3-32-32-32zm0 96h8c57.4 0 104 46.6 104 104v33.4c0 47.9 13.9 94.6 39.7 134.6H72.3C98.1 328 112 281.3 112 233.4V200c0-57.4 46.6-104 104-104h8zm64 352H224 160c0 17 6.7 33.3 18.7 45.3s28.3 18.7 45.3 18.7s33.3-6.7 45.3-18.7s18.7-28.3 18.7-45.3z"/></svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
#header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
#dashboardTitleWrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin:20px;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
#dashboardTitleWrapper h5 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#dashboardTitleWrapper h1 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#icons {
|
||||
display: flex;
|
||||
margin-right:20px;
|
||||
}
|
||||
|
||||
.headerbtn {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.headerbtn:hover::before {
|
||||
content: "";
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background-color: rgb(100, 100, 100, 0.25);
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,168 @@
|
||||
<script>
|
||||
import Graph1 from '../graphs/Graph1.svelte';
|
||||
import Graph3 from '../graphs/Graph3.svelte';
|
||||
import Incomes from "../infolists/Incomes.svelte";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
import { slide } from 'svelte/transition'
|
||||
import {incomeTypes} from "../../../stores.js";
|
||||
|
||||
let isDateDropdownExpanded = false
|
||||
let isCategoryDropdownExpanded = false
|
||||
|
||||
function clickHandlerDate() {
|
||||
isDateDropdownExpanded = !isDateDropdownExpanded
|
||||
}
|
||||
|
||||
function clickHandlerCategory() {
|
||||
isCategoryDropdownExpanded = !isCategoryDropdownExpanded;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div id="main-data" style="background-color: {$globalStyles.dashColor}; color: {$globalStyles.color}">
|
||||
<div id="data-header" style="background-color:{$globalStyles.mainColor}; color: {$globalStyles.altColor}">
|
||||
<span>Revenue Analysis</span>
|
||||
|
||||
<div id="dropdown-date">
|
||||
<button id="button" on:click={clickHandlerDate}>Filter by Date:</button>
|
||||
{#if isDateDropdownExpanded}
|
||||
<div id="date-list" transition:slide>
|
||||
<div on:click={() => console.log("Today")}>Today</div>
|
||||
<div on:click={() => console.log("Yesterday")}>Yesterday</div>
|
||||
<div on:click={() => console.log("Last week")}>Last week</div>
|
||||
<div on:click={() => console.log("Last month")}>Last month</div>
|
||||
<div on:click={() => console.log("Current quarter")}>Current quarter</div>
|
||||
<div on:click={() => console.log("This year")}>This year</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div id="dropdown-category">
|
||||
<button id="button" on:click={clickHandlerCategory}>Filter by Category:</button>
|
||||
{#if isCategoryDropdownExpanded}
|
||||
<div id="category-list" transition:slide>
|
||||
{#each $incomeTypes as income (income.id)}
|
||||
{#if income.id !== undefined}
|
||||
<option value={income.id}>{income.name}</option>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div id="data-menu">
|
||||
<div id="first-graph">
|
||||
<Graph1 />
|
||||
</div>
|
||||
<div id="second-graph">
|
||||
<Graph3 />
|
||||
</div>
|
||||
<Incomes />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#main-data {
|
||||
border-bottom-left-radius: 20px;
|
||||
border-bottom-right-radius: 20px;
|
||||
padding:0;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
height: 0;
|
||||
flex-direction: column;
|
||||
justify-content: stretch;
|
||||
align-items: stretch;
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
#button {
|
||||
background-color: #fff000;
|
||||
border-radius: 12px;
|
||||
color: #000;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
padding: 10px 15px;
|
||||
text-align: center;
|
||||
transition: 200ms;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
border: 0;
|
||||
font-size: 16px;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
#button:not(:disabled):hover,
|
||||
#button:not(:disabled):focus {
|
||||
outline: 0;
|
||||
background: #f4e603;
|
||||
box-shadow: 0 0 0 2px rgba(0,0,0,.2), 0 3px 8px 0 rgba(0,0,0,.15);
|
||||
}
|
||||
|
||||
#button:disabled {
|
||||
filter: saturate(0.2) opacity(0.5);
|
||||
-webkit-filter: saturate(0.2) opacity(0.5);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
|
||||
#date-list {
|
||||
background-color: #8BD17C;
|
||||
position:absolute;
|
||||
z-index:1;
|
||||
}
|
||||
|
||||
#category-list {
|
||||
background-color: #8BD17C;
|
||||
position:absolute;
|
||||
z-index:1;
|
||||
}
|
||||
|
||||
#data-header {
|
||||
background-color: black;
|
||||
min-height: 50px;
|
||||
padding-left: 30px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
border-top-left-radius: 20px;
|
||||
border-top-right-radius: 20px;
|
||||
font-size: larger;
|
||||
border: #8BD17C 2px solid;
|
||||
}
|
||||
|
||||
#data-menu {
|
||||
border-bottom-left-radius: 20px;
|
||||
border-bottom-right-radius: 20px;
|
||||
display:flex;
|
||||
/*padding:10px;*/
|
||||
flex-direction: row-reverse;
|
||||
justify-content: space-between;
|
||||
align-items: stretch;
|
||||
flex: 1;
|
||||
height: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
#first-graph {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#second-graph {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,79 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { incomeData, expenseData } from "../../../stores.js";
|
||||
import {globalStyles} from "../../../styles.js";
|
||||
|
||||
let componentStyles;
|
||||
|
||||
$: {
|
||||
console.log("got here")
|
||||
componentStyles = $globalStyles;
|
||||
}
|
||||
|
||||
let infobar1, infobar2, infobar3, infobar4;
|
||||
let totalExpenses = 0;
|
||||
let totalIncomes = 0;
|
||||
let lastMonthIncome = 800; // Dummy last month's income
|
||||
let lastMonthExpense = 200; // Dummy last month's expense
|
||||
|
||||
function updateInfo() {
|
||||
totalExpenses = $expenseData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
totalIncomes = $incomeData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||
|
||||
const incomeDifference = ((totalIncomes - lastMonthIncome) / lastMonthIncome) * 100;
|
||||
const expenseDifference = ((lastMonthExpense - totalExpenses) / lastMonthExpense) * 100;
|
||||
|
||||
try {
|
||||
infobar1.innerHTML = `<span style="font-size: larger">Total expenses:</span><br><span style="color:red;font-size: 150%">${totalExpenses.toFixed(2)}$</span>`;
|
||||
infobar2.innerHTML = `<span style="font-size: larger">Total incomes:</span><br><span style="color:green;font-size: 150%">${totalIncomes.toFixed(2)}$</span>`;
|
||||
|
||||
infobar3.innerHTML = `<span style="font-size: larger">Income by last month:</span><br><span style="color:blue;font-size: 150%">${incomeDifference.toFixed(2)}%</span>`;
|
||||
infobar4.innerHTML = `<span style="font-size: larger">Expense by last month:</span><br><span style="color:orange;font-size: 150%">${expenseDifference.toFixed(2)}%</span>`;
|
||||
} catch {
|
||||
console.log("not yet loaded");
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if ($incomeData || $expenseData) {
|
||||
updateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
updateInfo();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="quickInfobar">
|
||||
<div class="infobarElement" bind:this={infobar1} style="background-color: {componentStyles.mainColor}"></div>
|
||||
<div class="infobarElement" bind:this={infobar2} style="background-color: {componentStyles.mainColor}"></div>
|
||||
<div class="infobarElement" bind:this={infobar3} style="background-color: {componentStyles.mainColor}"></div>
|
||||
<div class="infobarElement" bind:this={infobar4} style="background-color: {componentStyles.mainColor}"></div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#quickInfobar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
.infobarElement {
|
||||
margin: 10px;
|
||||
width: 200px;
|
||||
min-width: 100px;
|
||||
height: 100px;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
background-color: #212942;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
|
||||
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.infobarElement:hover {
|
||||
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,76 +0,0 @@
|
||||
<script>
|
||||
import { onMount, afterUpdate } from 'svelte';
|
||||
import ContentExpense from "./contents/ContentExpense.svelte";
|
||||
import {expenseData} from "../../stores.js";
|
||||
|
||||
let parentHeight;
|
||||
let listParentHeight;
|
||||
|
||||
async function updateInfo() {
|
||||
parentHeight = document.querySelector('#expenseInfo').offsetHeight;
|
||||
listParentHeight = document.querySelector('#expenseList').offsetHeight;
|
||||
}
|
||||
|
||||
onMount(updateInfo);
|
||||
afterUpdate(updateInfo);
|
||||
</script>
|
||||
|
||||
<div id="expenseInfo" style="max-height: {parentHeight}px;">
|
||||
<ContentExpense />
|
||||
|
||||
<div id="expenseList" style="max-height: {listParentHeight}px;">
|
||||
<ul>
|
||||
{#each $expenseData as item}
|
||||
<li>
|
||||
{item.incomeCategory ? `${item.incomeCategory.name}: ` : `${item.expenseCategory.name}: `}
|
||||
{item.incomeCategory ? `+${item.amount}$` : `-${item.amount}$`}
|
||||
{`${item.date}`}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<style>
|
||||
#expenseInfo {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #212942;
|
||||
color:white;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
#expenseList {
|
||||
scrollbar-width: none;
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
overflow-y: auto;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
#expenseList::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
color:black;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 20px;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
}
|
||||
|
||||
li:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,75 +0,0 @@
|
||||
<script>
|
||||
import { onMount, afterUpdate } from 'svelte';
|
||||
import { incomeData } from "../../stores.js";
|
||||
import ContentIncome from "./contents/ContentIncome.svelte";
|
||||
|
||||
let parentHeight;
|
||||
let listParentHeight;
|
||||
|
||||
async function updateInfo() {
|
||||
parentHeight = document.querySelector('#expenseInfo').offsetHeight;
|
||||
listParentHeight = document.querySelector('#expenseList').offsetHeight;
|
||||
}
|
||||
|
||||
onMount(updateInfo);
|
||||
afterUpdate(updateInfo);
|
||||
</script>
|
||||
|
||||
<div id="incomeInfo" style="max-height: {parentHeight}px;">
|
||||
<ContentIncome />
|
||||
|
||||
<div id="incomeList" style="max-height: {listParentHeight}px;">
|
||||
<ul>
|
||||
{#each $incomeData as item}
|
||||
<li>
|
||||
{item.incomeCategory ? `${item.incomeCategory.name}: ` : `${item.expenseCategory.name}: `}
|
||||
{item.incomeCategory ? `+${item.amount}$` : `-${item.amount}$`}
|
||||
{`${item.date}`}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#incomeInfo {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #212942;
|
||||
color:white;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
#incomeList {
|
||||
scrollbar-width: none;
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
overflow-y: auto;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
color: black;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 20px;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||
}
|
||||
|
||||
li:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
|
||||
#incomeList::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -1,64 +0,0 @@
|
||||
<script>
|
||||
import Graph1 from '../graphs/Graph1.svelte';
|
||||
import Graph2 from '../graphs/Graph2.svelte';
|
||||
import Graph3 from '../graphs/Graph3.svelte';
|
||||
import Expenses from "../infolists/Expenses.svelte";
|
||||
import Incomes from "../infolists/Incomes.svelte";
|
||||
</script>
|
||||
|
||||
<div id="dataMenu">
|
||||
<div id="twoVertical">
|
||||
<Graph1 />
|
||||
<Graph2 />
|
||||
</div>
|
||||
<div id="oneVertical">
|
||||
<Graph3 />
|
||||
</div>
|
||||
<div id="dataPanel">
|
||||
<Incomes />
|
||||
<Expenses />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#dataMenu {
|
||||
border-bottom-left-radius: 20px;
|
||||
border-bottom-right-radius: 20px;
|
||||
background-color: rgb(245,242,243);
|
||||
display:flex;
|
||||
padding:10px;
|
||||
flex-direction: row-reverse;
|
||||
justify-content: stretch;
|
||||
align-items: stretch;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
|
||||
#twoVertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#oneVertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#dataPanel {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -3,6 +3,8 @@
|
||||
import axios from 'axios';
|
||||
import {deleteCookie, getCookie} from "svelte-cookie";
|
||||
|
||||
export let onTabClick;
|
||||
|
||||
let username;
|
||||
|
||||
onMount(async () => {
|
||||
@@ -40,14 +42,14 @@
|
||||
<span class="sideMenuItemText">Profile</span>
|
||||
</div>
|
||||
|
||||
<div class="sideMenuItem">
|
||||
<div on:click={() => onTabClick('expenses')} tabindex="0" role="button" class="sideMenuItem">
|
||||
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M64 64C28.7 64 0 92.7 0 128V384c0 35.3 28.7 64 64 64H512c35.3 0 64-28.7 64-64V128c0-35.3-28.7-64-64-64H64zm64 320H64V320c35.3 0 64 28.7 64 64zM64 192V128h64c0 35.3-28.7 64-64 64zM448 384c0-35.3 28.7-64 64-64v64H448zm64-192c-35.3 0-64-28.7-64-64h64v64zM288 160a96 96 0 1 1 0 192 96 96 0 1 1 0-192z"/></svg>
|
||||
<span class="sideMenuItemText">Expenses</span>
|
||||
<span class="sideMenuItemText">Spendings</span>
|
||||
</div>
|
||||
|
||||
<div class="sideMenuItem">
|
||||
<div on:click={() => onTabClick('incomes')} tabindex="0" role="button" class="sideMenuItem">
|
||||
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M64 64C28.7 64 0 92.7 0 128V384c0 35.3 28.7 64 64 64H512c35.3 0 64-28.7 64-64V128c0-35.3-28.7-64-64-64H64zm64 320H64V320c35.3 0 64 28.7 64 64zM64 192V128h64c0 35.3-28.7 64-64 64zM448 384c0-35.3 28.7-64 64-64v64H448zm64-192c-35.3 0-64-28.7-64-64h64v64zM288 160a96 96 0 1 1 0 192 96 96 0 1 1 0-192z"/></svg>
|
||||
<span class="sideMenuItemText">Incomes</span>
|
||||
<span class="sideMenuItemText">Revenues</span>
|
||||
</div>
|
||||
|
||||
<div class="sideMenuItem">
|
||||
@@ -55,7 +57,7 @@
|
||||
<span class="sideMenuItemText">General</span>
|
||||
</div>
|
||||
|
||||
<div class="sideMenuItem">
|
||||
<div on:click={() => onTabClick('settings')} tabindex="0" role="button" class="sideMenuItem">
|
||||
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M495.9 166.6c3.2 8.7 .5 18.4-6.4 24.6l-43.3 39.4c1.1 8.3 1.7 16.8 1.7 25.4s-.6 17.1-1.7 25.4l43.3 39.4c6.9 6.2 9.6 15.9 6.4 24.6c-4.4 11.9-9.7 23.3-15.8 34.3l-4.7 8.1c-6.6 11-14 21.4-22.1 31.2c-5.9 7.2-15.7 9.6-24.5 6.8l-55.7-17.7c-13.4 10.3-28.2 18.9-44 25.4l-12.5 57.1c-2 9.1-9 16.3-18.2 17.8c-13.8 2.3-28 3.5-42.5 3.5s-28.7-1.2-42.5-3.5c-9.2-1.5-16.2-8.7-18.2-17.8l-12.5-57.1c-15.8-6.5-30.6-15.1-44-25.4L83.1 425.9c-8.8 2.8-18.6 .3-24.5-6.8c-8.1-9.8-15.5-20.2-22.1-31.2l-4.7-8.1c-6.1-11-11.4-22.4-15.8-34.3c-3.2-8.7-.5-18.4 6.4-24.6l43.3-39.4C64.6 273.1 64 264.6 64 256s.6-17.1 1.7-25.4L22.4 191.2c-6.9-6.2-9.6-15.9-6.4-24.6c4.4-11.9 9.7-23.3 15.8-34.3l4.7-8.1c6.6-11 14-21.4 22.1-31.2c5.9-7.2 15.7-9.6 24.5-6.8l55.7 17.7c13.4-10.3 28.2-18.9 44-25.4l12.5-57.1c2-9.1 9-16.3 18.2-17.8C227.3 1.2 241.5 0 256 0s28.7 1.2 42.5 3.5c9.2 1.5 16.2 8.7 18.2 17.8l12.5 57.1c15.8 6.5 30.6 15.1 44 25.4l55.7-17.7c8.8-2.8 18.6-.3 24.5 6.8c8.1 9.8 15.5 20.2 22.1 31.2l4.7 8.1c6.1 11 11.4 22.4 15.8 34.3zM256 336a80 80 0 1 0 0-160 80 80 0 1 0 0 160z"/></svg>
|
||||
<span class="sideMenuItemText">Settings</span>
|
||||
</div>
|
||||
|
||||
@@ -7,3 +7,5 @@ export const expenseData = writable([]);
|
||||
export const incomeTypes = writable([]);
|
||||
|
||||
export const expenseTypes = writable([]);
|
||||
|
||||
export let selectedTab = writable('expenses');
|
||||
@@ -0,0 +1,18 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const themeDefault = {
|
||||
mainColor: '#172233',
|
||||
dashColor: '#F5F2F3',
|
||||
color: 'black',
|
||||
altColor: 'white'
|
||||
}
|
||||
|
||||
export const themeDark = {
|
||||
mainColor: '#000000',
|
||||
dashColor: '#202020',
|
||||
color: 'black',
|
||||
altColor: 'white'
|
||||
}
|
||||
|
||||
export const globalStyles = writable(themeDefault);
|
||||
|
||||
Reference in New Issue
Block a user