Compare commits
94 Commits
dmitrii-cr
...
front-v3
| Author | SHA1 | Date | |
|---|---|---|---|
| fd5718ec8f | |||
|
|
ff61849321 | ||
|
|
f2b6178f11 | ||
| de86a9d474 | |||
| 31087f82dd | |||
|
|
f9ccaca90d | ||
|
|
8ef00d83ef | ||
|
|
2e403e57b6 | ||
|
|
9faf6e00bc | ||
|
|
3fbd7a1440 | ||
|
|
67f2180f49 | ||
|
|
7f0a173685 | ||
|
|
da1076042e | ||
|
|
d03f3bd552 | ||
|
|
3a79741101 | ||
|
|
5809cf0284 | ||
| 75d081fd88 | |||
|
|
8420f15732 | ||
|
|
ca1c1473a4 | ||
|
|
81fe558dbb | ||
| ee4c885ae6 | |||
|
|
dc0252333e | ||
|
|
a373daa58c | ||
|
|
f98b9ac3e7 | ||
| 3335b1edc4 | |||
| cda5913aa9 | |||
| 9483b7a233 | |||
| 1cc271d590 | |||
| 8103a36394 | |||
| b22f3c32d0 | |||
| d70fd2975b | |||
| 420f9010e4 | |||
| 2e41979897 | |||
| 45b40c8987 | |||
| d750593d24 | |||
| b74cb462cd | |||
| 09fd20d071 | |||
|
|
f4a03e438b | ||
| 1696965557 | |||
|
|
f6fa5542f7 | ||
|
|
5cbee61f71 | ||
|
|
cf9a18cd33 | ||
| 3c724a395b | |||
|
|
2a83718dd6 | ||
|
|
40f7db9dc7 | ||
| 4a25e8fc66 | |||
|
|
673dfa374e | ||
|
|
4fac06b680 | ||
|
|
ee39ac605f | ||
|
|
f70fb1f0a2 | ||
|
|
0eecbd5907 | ||
| 20a2799869 | |||
|
|
48281b46a4 | ||
| b5742b9761 | |||
|
|
0fcacc3e88 | ||
|
|
5a8a8f1197 | ||
| cb6c03fe76 | |||
|
|
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>
|
<version>0.11.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.validation</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>jakarta.validation-api</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
<version>2.0.2</version>
|
</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>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
<defaultGoal>package</defaultGoal>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.faf223.expensetrackerfaf.security.PersonDetails;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.AuthenticationProvider;
|
import org.springframework.security.authentication.AuthenticationProvider;
|
||||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||||
@@ -19,12 +20,11 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ApplicationConfig {
|
public class ApplicationConfig {
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
private final CredentialRepository credentialRepository;
|
private final CredentialRepository credentialRepository;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public UserDetailsService userDetailsService() {
|
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
|
@Bean
|
||||||
@@ -44,4 +44,10 @@ public class ApplicationConfig {
|
|||||||
public PasswordEncoder passwordEncoder() {
|
public PasswordEncoder passwordEncoder() {
|
||||||
return new BCryptPasswordEncoder();
|
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;
|
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 com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.jsonwebtoken.ExpiredJwtException;
|
import io.jsonwebtoken.ExpiredJwtException;
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
@@ -61,8 +61,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
response.setContentType("application/json");
|
response.setContentType("application/json");
|
||||||
|
|
||||||
ErrorResponse errorResponse = new ErrorResponse("TokenExpired", "Your session has expired. Please log in again.");
|
ErrorResponse errorResponse = new ErrorResponse("Your session has expired. Refresh your token.");
|
||||||
ObjectMapper objectMapper = new ObjectMapper(); // You may need to import ObjectMapper
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
|
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import io.jsonwebtoken.Jwts;
|
|||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
import io.jsonwebtoken.io.Decoders;
|
import io.jsonwebtoken.io.Decoders;
|
||||||
import io.jsonwebtoken.security.Keys;
|
import io.jsonwebtoken.security.Keys;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -16,6 +17,7 @@ import java.util.Map;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class JwtService {
|
public class JwtService {
|
||||||
|
|
||||||
@Value("${application.security.jwt.secret-key}")
|
@Value("${application.security.jwt.secret-key}")
|
||||||
@@ -25,6 +27,7 @@ public class JwtService {
|
|||||||
@Value("${application.security.jwt.refresh-token.expiration}")
|
@Value("${application.security.jwt.refresh-token.expiration}")
|
||||||
private long refreshExpiration;
|
private long refreshExpiration;
|
||||||
|
|
||||||
|
|
||||||
public String extractUsername(String token) {
|
public String extractUsername(String token) {
|
||||||
return extractClaim(token, Claims::getSubject);
|
return extractClaim(token, Claims::getSubject);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,19 @@
|
|||||||
package com.faf223.expensetrackerfaf.config;
|
package com.faf223.expensetrackerfaf.config;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import com.faf223.expensetrackerfaf.controller.auth.JwtAuthenticationSuccessHandler;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.authentication.AuthenticationProvider;
|
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.method.configuration.EnableMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
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.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
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.ClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository;
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
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.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.cors.CorsConfigurationSource;
|
import org.springframework.web.cors.CorsConfigurationSource;
|
||||||
@@ -32,28 +25,39 @@ import static org.springframework.security.config.Customizer.withDefaults;
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@RequiredArgsConstructor
|
|
||||||
@EnableMethodSecurity
|
@EnableMethodSecurity
|
||||||
public class SecurityConfiguration {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
private final JwtAuthenticationFilter jwtAuthFilter;
|
private final JwtAuthenticationFilter jwtAuthFilter;
|
||||||
private final AuthenticationProvider authenticationProvider;
|
private final AuthenticationProvider authenticationProvider;
|
||||||
|
|
||||||
|
public SecurityConfiguration(JwtAuthenticationFilter jwtAuthFilter,
|
||||||
|
AuthenticationProvider authenticationProvider) {
|
||||||
|
this.jwtAuthFilter = jwtAuthFilter;
|
||||||
|
this.authenticationProvider = authenticationProvider;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http
|
http
|
||||||
.cors(Customizer.withDefaults())
|
.cors(withDefaults())
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/api/v1/auth/**").permitAll()
|
.requestMatchers("/api/v1/auth/*").permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
|
//.oauth2Login(withDefaults())
|
||||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.authenticationProvider(authenticationProvider)
|
.authenticationProvider(authenticationProvider)
|
||||||
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); // will be executed before UsernamePasswordAuthenticationFilter
|
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JwtAuthenticationSuccessHandler jwtAuthenticationSuccessHandler() {
|
||||||
|
return new JwtAuthenticationSuccessHandler();
|
||||||
|
}
|
||||||
@Bean
|
@Bean
|
||||||
public CorsConfigurationSource corsConfigurationSource() {
|
public CorsConfigurationSource corsConfigurationSource() {
|
||||||
CorsConfiguration configuration = new CorsConfiguration();
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
@@ -66,4 +70,8 @@ public class SecurityConfiguration {
|
|||||||
return source;
|
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.ExpenseCategoryService;
|
||||||
import com.faf223.expensetrackerfaf.service.ExpenseService;
|
import com.faf223.expensetrackerfaf.service.ExpenseService;
|
||||||
import com.faf223.expensetrackerfaf.service.UserService;
|
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 lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -16,10 +22,13 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.time.LocalDate;
|
||||||
|
import java.time.Month;
|
||||||
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -37,12 +46,15 @@ public class ExpenseController {
|
|||||||
public ResponseEntity<List<ExpenseDTO>> getAllExpenses() {
|
public ResponseEntity<List<ExpenseDTO>> getAllExpenses() {
|
||||||
List<ExpenseDTO> expenses = expenseService.getTransactions().stream().map(expenseMapper::toDto).collect(Collectors.toList());
|
List<ExpenseDTO> expenses = expenseService.getTransactions().stream().map(expenseMapper::toDto).collect(Collectors.toList());
|
||||||
if (!expenses.isEmpty()) return ResponseEntity.ok(expenses);
|
if (!expenses.isEmpty()) return ResponseEntity.ok(expenses);
|
||||||
else return ResponseEntity.notFound().build();
|
else throw new TransactionsNotFoundException("Transactions not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public ResponseEntity<Void> createNewExpense(@RequestBody ExpenseCreationDTO expenseDTO,
|
public ResponseEntity<Map<String, Long>> createNewExpense(@RequestBody @Valid ExpenseCreationDTO expenseDTO,
|
||||||
BindingResult bindingResult) {
|
BindingResult bindingResult) {
|
||||||
|
if(bindingResult.hasErrors())
|
||||||
|
throw new TransactionNotCreatedException("Could not create new expense");
|
||||||
|
|
||||||
Expense expense = expenseMapper.toExpense(expenseDTO);
|
Expense expense = expenseMapper.toExpense(expenseDTO);
|
||||||
|
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
@@ -54,57 +66,83 @@ public class ExpenseController {
|
|||||||
expense.setUser(user);
|
expense.setUser(user);
|
||||||
|
|
||||||
expenseService.createOrUpdate(expense);
|
expenseService.createOrUpdate(expense);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
Map<String, Long> response = new HashMap<>();
|
||||||
|
response.put("expenseId", expense.getId());
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.notFound().build();
|
throw new TransactionNotCreatedException("Could not create new expense");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: check if the expense belongs to the user
|
|
||||||
@PatchMapping("/update/{id}")
|
@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) {
|
BindingResult bindingResult) {
|
||||||
|
if(bindingResult.hasErrors())
|
||||||
|
throw new TransactionNotUpdatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||||
|
|
||||||
Expense expense = expenseService.getTransactionById(id);
|
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());
|
ExpenseCategory category = expenseCategoryService.getCategoryById(expenseDTO.getExpenseCategory());
|
||||||
expense.setCategory(category);
|
expense.setCategory(category);
|
||||||
expense.setAmount(expenseDTO.getAmount());
|
expense.setAmount(expenseDTO.getAmount());
|
||||||
|
|
||||||
if (!bindingResult.hasErrors()) {
|
|
||||||
expenseService.createOrUpdate(expense);
|
expenseService.createOrUpdate(expense);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
} else {
|
|
||||||
return ResponseEntity.notFound().build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/personal-expenses")
|
@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();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||||
|
|
||||||
String email = userDetails.getUsername();
|
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.ok(expenses);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseEntity.notFound().build();
|
throw new TransactionsNotFoundException("The expenses have not been found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/categories")
|
@GetMapping("/categories")
|
||||||
public ResponseEntity<List<ExpenseCategory>> getAllCategories() {
|
public ResponseEntity<List<ExpenseCategory>> getAllCategories() {
|
||||||
List<ExpenseCategory> categories = expenseCategoryService.getAllCategories();
|
List<ExpenseCategory> categories = expenseCategoryService.getAllCategories();
|
||||||
if (!categories.isEmpty()) return ResponseEntity.ok(categories);
|
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}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public void deleteCategory(@PathVariable long 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.IncomeCreationDTO;
|
||||||
import com.faf223.expensetrackerfaf.dto.IncomeDTO;
|
import com.faf223.expensetrackerfaf.dto.IncomeDTO;
|
||||||
import com.faf223.expensetrackerfaf.dto.mappers.IncomeMapper;
|
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.IncomeCategoryService;
|
||||||
import com.faf223.expensetrackerfaf.service.IncomeService;
|
import com.faf223.expensetrackerfaf.service.IncomeService;
|
||||||
import com.faf223.expensetrackerfaf.service.UserService;
|
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 lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -14,10 +22,13 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.time.LocalDate;
|
||||||
|
import java.time.Month;
|
||||||
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -35,13 +46,17 @@ public class IncomeController {
|
|||||||
public ResponseEntity<List<IncomeDTO>> getAllIncomes() {
|
public ResponseEntity<List<IncomeDTO>> getAllIncomes() {
|
||||||
List<IncomeDTO> incomes = incomeService.getTransactions().stream().map(incomeMapper::toDto).collect(Collectors.toList());
|
List<IncomeDTO> incomes = incomeService.getTransactions().stream().map(incomeMapper::toDto).collect(Collectors.toList());
|
||||||
if (!incomes.isEmpty()) return ResponseEntity.ok(incomes);
|
if (!incomes.isEmpty()) return ResponseEntity.ok(incomes);
|
||||||
else return ResponseEntity.notFound().build();
|
else throw new TransactionsNotFoundException("Transactions not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public ResponseEntity<Void> createNewIncome(@RequestBody IncomeCreationDTO incomeDTO,
|
public ResponseEntity<Map<String, Long>> createNewIncome(@RequestBody @Valid IncomeCreationDTO incomeDTO,
|
||||||
BindingResult bindingResult) {
|
BindingResult bindingResult) {
|
||||||
|
if(bindingResult.hasErrors())
|
||||||
|
throw new TransactionNotCreatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||||
|
|
||||||
Income income = incomeMapper.toIncome(incomeDTO);
|
Income income = incomeMapper.toIncome(incomeDTO);
|
||||||
|
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||||
@@ -50,58 +65,84 @@ public class IncomeController {
|
|||||||
User user = userService.getUserByEmail(email);
|
User user = userService.getUserByEmail(email);
|
||||||
income.setUser(user);
|
income.setUser(user);
|
||||||
|
|
||||||
System.out.println(income);
|
|
||||||
incomeService.createOrUpdate(income);
|
incomeService.createOrUpdate(income);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
Map<String, Long> response = new HashMap<>();
|
||||||
|
response.put("incomeId", income.getId());
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.notFound().build();
|
throw new TransactionNotCreatedException("Could not create new income");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check if the income belongs to the user, extract logic into service
|
|
||||||
@PatchMapping("/update/{id}")
|
@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) {
|
BindingResult bindingResult) {
|
||||||
|
if(bindingResult.hasErrors())
|
||||||
|
throw new TransactionNotUpdatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||||
|
|
||||||
Income income = incomeService.getTransactionById(id);
|
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());
|
IncomeCategory category = incomeCategoryService.getCategoryById(incomeDTO.getIncomeCategory());
|
||||||
income.setCategory(category);
|
income.setCategory(category);
|
||||||
income.setAmount(incomeDTO.getAmount());
|
income.setAmount(incomeDTO.getAmount());
|
||||||
|
|
||||||
if (!bindingResult.hasErrors()) {
|
|
||||||
incomeService.createOrUpdate(income);
|
incomeService.createOrUpdate(income);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
} else {
|
|
||||||
return ResponseEntity.notFound().build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/personal-incomes")
|
@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();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||||
|
|
||||||
String email = userDetails.getUsername();
|
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.ok(incomes);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseEntity.notFound().build();
|
throw new TransactionsNotFoundException("The expenses have not been found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/categories")
|
@GetMapping("/categories")
|
||||||
public ResponseEntity<List<IncomeCategory>> getAllCategories() {
|
public ResponseEntity<List<IncomeCategory>> getAllCategories() {
|
||||||
List<IncomeCategory> categories = incomeCategoryService.getAllCategories();
|
List<IncomeCategory> categories = incomeCategoryService.getAllCategories();
|
||||||
if (!categories.isEmpty()) return ResponseEntity.ok(categories);
|
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}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public void deleteIncome(@PathVariable long id) {
|
public void deleteIncome(@PathVariable long id) {
|
||||||
incomeService.deleteIncomeById(id);
|
incomeService.deleteTransactionById(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,22 @@
|
|||||||
package com.faf223.expensetrackerfaf.controller;
|
package com.faf223.expensetrackerfaf.controller;
|
||||||
|
|
||||||
|
import com.faf223.expensetrackerfaf.controller.auth.AuthenticationResponse;
|
||||||
|
import com.faf223.expensetrackerfaf.controller.auth.ChangePasswordRequest;
|
||||||
import com.faf223.expensetrackerfaf.dto.UserCreationDTO;
|
import com.faf223.expensetrackerfaf.dto.UserCreationDTO;
|
||||||
import com.faf223.expensetrackerfaf.dto.UserDTO;
|
import com.faf223.expensetrackerfaf.dto.UserDTO;
|
||||||
|
import com.faf223.expensetrackerfaf.dto.UserUpdateDTO;
|
||||||
import com.faf223.expensetrackerfaf.dto.mappers.UserMapper;
|
import com.faf223.expensetrackerfaf.dto.mappers.UserMapper;
|
||||||
|
import com.faf223.expensetrackerfaf.model.Credential;
|
||||||
import com.faf223.expensetrackerfaf.model.User;
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
|
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||||
|
import com.faf223.expensetrackerfaf.service.AuthenticationService;
|
||||||
import com.faf223.expensetrackerfaf.service.UserService;
|
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 lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
@@ -15,6 +26,9 @@ import org.springframework.validation.BindingResult;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/users")
|
@RequestMapping("/users")
|
||||||
@@ -23,37 +37,109 @@ public class UserController {
|
|||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
|
private final CredentialRepository credentialRepository;
|
||||||
|
private final AuthenticationService authenticationService;
|
||||||
|
|
||||||
@PatchMapping()
|
@PatchMapping()
|
||||||
public ResponseEntity<UserDTO> updateUser(@RequestBody UserCreationDTO userDTO,
|
public ResponseEntity<UserDTO> updateUser(@RequestBody @Valid UserCreationDTO userDTO,
|
||||||
BindingResult bindingResult) {
|
BindingResult bindingResult) {
|
||||||
|
if (bindingResult.hasErrors())
|
||||||
|
throw new UserNotCreatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||||
|
|
||||||
User user = userMapper.toUser(userDTO);
|
User user = userMapper.toUser(userDTO);
|
||||||
|
|
||||||
if (!bindingResult.hasErrors()) {
|
if (!bindingResult.hasErrors()) {
|
||||||
|
|
||||||
userService.updateUser(user);
|
userService.updateUser(user);
|
||||||
return ResponseEntity.ok(userMapper.toDto(user));
|
return ResponseEntity.ok(userMapper.toDto(user));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return ResponseEntity.notFound().build();
|
throw new UserNotFoundException("The user has not been found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getUserData")
|
@PatchMapping("/update-password")
|
||||||
public ResponseEntity<UserDTO> getUser() {
|
public ResponseEntity<Void> updateUserPassword(@RequestBody ChangePasswordRequest password) {
|
||||||
|
|
||||||
|
authenticationService.updatePassword(password.getPassword());
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/update-user-data")
|
||||||
|
public ResponseEntity<AuthenticationResponse> updateUserData(@RequestBody UserUpdateDTO userUpdateDTO) {
|
||||||
|
|
||||||
|
return ResponseEntity.ok(userService.updateUser(userUpdateDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-user-data")
|
||||||
|
public ResponseEntity<Map<String, String>> getUser() {
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||||
User user = userService.getUserByEmail(userDetails.getUsername());
|
User user = userService.getUserByEmail(userDetails.getUsername());
|
||||||
if (user != null) return ResponseEntity.ok(userMapper.toDto(user));
|
Optional<Credential> credential = credentialRepository.findByUser(user);
|
||||||
else return ResponseEntity.notFound().build();
|
|
||||||
|
if (credential.isPresent()) {
|
||||||
|
Map<String, String> userData = new HashMap<>();
|
||||||
|
userData.put("firstname", user.getFirstName());
|
||||||
|
userData.put("lastname", user.getLastName());
|
||||||
|
userData.put("username", user.getUsername());
|
||||||
|
userData.put("email", credential.get().getEmail());
|
||||||
|
userData.put("userrole", credential.get().getRole().toString());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(userData);
|
||||||
}
|
}
|
||||||
return ResponseEntity.notFound().build();
|
}
|
||||||
|
throw new UserNotFoundException("The user has not been found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
public ResponseEntity<ArrayList<UserDTO>> getAllUsers() {
|
public ResponseEntity<ArrayList<Map<String, String>>> getAllUsers() {
|
||||||
ArrayList<User> users = new ArrayList<>(userService.getUsers());
|
ArrayList<User> users = new ArrayList<>(userService.getUsers());
|
||||||
|
|
||||||
return ResponseEntity.ok(userMapper.toDto(users));
|
ArrayList<Map<String, String>> mappedUsers = new ArrayList<>();
|
||||||
|
|
||||||
|
for (User u: users) {
|
||||||
|
Map<String, String> userData = new HashMap<>();
|
||||||
|
userData.put("firstname", u.getFirstName());
|
||||||
|
userData.put("lastname", u.getLastName());
|
||||||
|
userData.put("username", u.getUsername());
|
||||||
|
Optional<Credential> credential = credentialRepository.findByUser(u);
|
||||||
|
if (credential.isEmpty()) continue;
|
||||||
|
userData.put("email", credential.get().getEmail());
|
||||||
|
userData.put("userrole", credential.get().getRole().toString());
|
||||||
|
mappedUsers.add(userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return ResponseEntity.ok(mappedUsers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/delete/{username}")
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
|
public ResponseEntity<Void> deleteUserByUsername(@PathVariable String username) {
|
||||||
|
|
||||||
|
userService.deleteByUsername(username);
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/promote/{email}")
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
|
public ResponseEntity<Void> promoteUser(@PathVariable String email) {
|
||||||
|
|
||||||
|
userService.promoteUser(email);
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/demote/{email}")
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
|
public ResponseEntity<Void> demoteUser(@PathVariable String email) {
|
||||||
|
|
||||||
|
userService.demoteUser(email);
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.faf223.expensetrackerfaf.controller.auth;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ChangePasswordRequest {
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
@@ -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
|
@NoArgsConstructor
|
||||||
public class RegisterRequest {
|
public class RegisterRequest {
|
||||||
|
|
||||||
private String firstname; // Change field name to match JSON
|
private String firstname;
|
||||||
private String lastname; // Change field name to match JSON
|
private String lastname;
|
||||||
private String username; // Change field name to match JSON
|
private String username;
|
||||||
private String email; // Change field name to match JSON
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
private Role role;
|
private Role role;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
package com.faf223.expensetrackerfaf.dto;
|
package com.faf223.expensetrackerfaf.dto;
|
||||||
|
|
||||||
import com.faf223.expensetrackerfaf.model.ExpenseCategory;
|
import jakarta.validation.constraints.DecimalMin;
|
||||||
import com.faf223.expensetrackerfaf.model.User;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ExpenseCreationDTO {
|
public class ExpenseCreationDTO {
|
||||||
|
@NotNull(message = "Category must not be null")
|
||||||
private int expenseCategory;
|
private int expenseCategory;
|
||||||
|
|
||||||
|
@NotNull(message = "Amount must not be null")
|
||||||
|
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.faf223.expensetrackerfaf.dto;
|
package com.faf223.expensetrackerfaf.dto;
|
||||||
|
|
||||||
import com.faf223.expensetrackerfaf.model.ExpenseCategory;
|
import com.faf223.expensetrackerfaf.model.ExpenseCategory;
|
||||||
|
import jakarta.validation.constraints.DecimalMin;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -10,9 +12,19 @@ import java.time.LocalDate;
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ExpenseDTO {
|
public class ExpenseDTO {
|
||||||
|
@NotNull(message = "ID must not be null")
|
||||||
private long expenseId;
|
private long expenseId;
|
||||||
|
|
||||||
|
@NotNull(message = "User must not be null")
|
||||||
private UserDTO userDTO;
|
private UserDTO userDTO;
|
||||||
|
|
||||||
|
@NotNull(message = "Category must not be null")
|
||||||
private ExpenseCategory expenseCategory;
|
private ExpenseCategory expenseCategory;
|
||||||
|
|
||||||
|
@NotNull(message = "Date must not be null")
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
|
|
||||||
|
@NotNull(message = "Amount must not be null")
|
||||||
|
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
package com.faf223.expensetrackerfaf.dto;
|
package com.faf223.expensetrackerfaf.dto;
|
||||||
|
|
||||||
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
import jakarta.validation.constraints.DecimalMin;
|
||||||
import com.faf223.expensetrackerfaf.model.User;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class IncomeCreationDTO {
|
public class IncomeCreationDTO {
|
||||||
|
@NotNull(message = "Category must not be null")
|
||||||
private int incomeCategory;
|
private int incomeCategory;
|
||||||
|
|
||||||
|
@NotNull(message = "Amount must not be null")
|
||||||
|
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.faf223.expensetrackerfaf.dto;
|
package com.faf223.expensetrackerfaf.dto;
|
||||||
|
|
||||||
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
||||||
|
import jakarta.validation.constraints.DecimalMin;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -10,9 +12,19 @@ import java.time.LocalDate;
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class IncomeDTO {
|
public class IncomeDTO {
|
||||||
|
@NotNull(message = "ID must not be null")
|
||||||
private long incomeId;
|
private long incomeId;
|
||||||
|
|
||||||
|
@NotNull(message = "User must not be null")
|
||||||
private UserDTO userDTO;
|
private UserDTO userDTO;
|
||||||
|
|
||||||
|
@NotNull(message = "Category must not be null")
|
||||||
private IncomeCategory incomeCategory;
|
private IncomeCategory incomeCategory;
|
||||||
|
|
||||||
|
@NotNull(message = "Date must not be null")
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
|
|
||||||
|
@NotNull(message = "Amount must not be null")
|
||||||
|
@DecimalMin(value = "0.0", inclusive = false, message = "Amount must be positive")
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,28 @@
|
|||||||
package com.faf223.expensetrackerfaf.dto;
|
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.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class UserCreationDTO {
|
public class UserCreationDTO {
|
||||||
|
@NotNull(message = "First name must not be null")
|
||||||
|
@NotEmpty(message = "First name must not be empty")
|
||||||
private String firstname;
|
private String firstname;
|
||||||
|
@NotNull(message = "Last name must not be null")
|
||||||
|
@NotEmpty(message = "Last name must not be empty")
|
||||||
private String lastname;
|
private String lastname;
|
||||||
|
@NotNull(message = "Username must not be null")
|
||||||
|
@NotEmpty(message = "Username must not be empty")
|
||||||
private String username;
|
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;
|
private String email;
|
||||||
|
@NotNull(message = "Password must not be null")
|
||||||
|
@NotEmpty(message = "Password must not be empty")
|
||||||
private String password;
|
private String password;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
package com.faf223.expensetrackerfaf.dto;
|
package com.faf223.expensetrackerfaf.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class UserDTO {
|
public class UserDTO {
|
||||||
|
@NotNull(message = "Name must not be null")
|
||||||
|
@NotEmpty(message = "Name must not be empty")
|
||||||
private String name;
|
private String name;
|
||||||
|
@NotNull(message = "Surname must not be null")
|
||||||
|
@NotEmpty(message = "Surname must not be empty")
|
||||||
private String surname;
|
private String surname;
|
||||||
|
@NotNull(message = "Username must not be null")
|
||||||
|
@NotEmpty(message = "Username must not be empty")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.faf223.expensetrackerfaf.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UserUpdateDTO {
|
||||||
|
|
||||||
|
private String firstname;
|
||||||
|
private String lastname;
|
||||||
|
private String username;
|
||||||
|
private String email;
|
||||||
|
}
|
||||||
@@ -5,25 +5,19 @@ import com.faf223.expensetrackerfaf.dto.ExpenseDTO;
|
|||||||
import com.faf223.expensetrackerfaf.model.Expense;
|
import com.faf223.expensetrackerfaf.model.Expense;
|
||||||
import com.faf223.expensetrackerfaf.service.ExpenseCategoryService;
|
import com.faf223.expensetrackerfaf.service.ExpenseCategoryService;
|
||||||
import com.faf223.expensetrackerfaf.service.ExpenseService;
|
import com.faf223.expensetrackerfaf.service.ExpenseService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class ExpenseMapper {
|
public class ExpenseMapper {
|
||||||
|
|
||||||
private final ExpenseService expenseService;
|
|
||||||
private final ExpenseCategoryService expenseCategoryService;
|
private final ExpenseCategoryService expenseCategoryService;
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ExpenseMapper(ExpenseService expenseService, ExpenseCategoryService expenseCategoryService, UserMapper userMapper) {
|
|
||||||
this.expenseService = expenseService;
|
|
||||||
this.expenseCategoryService = expenseCategoryService;
|
|
||||||
this.userMapper = userMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExpenseDTO toDto(Expense expense) {
|
public ExpenseDTO toDto(Expense expense) {
|
||||||
return new ExpenseDTO(expense.getId(), userMapper.toDto(expense.getUser()),
|
return new ExpenseDTO(expense.getId(), userMapper.toDto(expense.getUser()),
|
||||||
expense.getCategory(), expense.getDate(), expense.getAmount());
|
expense.getCategory(), expense.getDate(), expense.getAmount());
|
||||||
|
|||||||
@@ -6,25 +6,19 @@ import com.faf223.expensetrackerfaf.model.Expense;
|
|||||||
import com.faf223.expensetrackerfaf.model.Income;
|
import com.faf223.expensetrackerfaf.model.Income;
|
||||||
import com.faf223.expensetrackerfaf.service.IncomeCategoryService;
|
import com.faf223.expensetrackerfaf.service.IncomeCategoryService;
|
||||||
import com.faf223.expensetrackerfaf.service.IncomeService;
|
import com.faf223.expensetrackerfaf.service.IncomeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class IncomeMapper {
|
public class IncomeMapper {
|
||||||
|
|
||||||
private final IncomeService incomeService;
|
|
||||||
private final IncomeCategoryService incomeCategoryService;
|
private final IncomeCategoryService incomeCategoryService;
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public IncomeMapper(IncomeService incomeService, IncomeCategoryService incomeCategoryService, UserMapper userMapper) {
|
|
||||||
this.incomeService = incomeService;
|
|
||||||
this.incomeCategoryService = incomeCategoryService;
|
|
||||||
this.userMapper = userMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IncomeDTO toDto(Income income) {
|
public IncomeDTO toDto(Income income) {
|
||||||
return new IncomeDTO(income.getId(), userMapper.toDto(income.getUser()),
|
return new IncomeDTO(income.getId(), userMapper.toDto(income.getUser()),
|
||||||
income.getCategory(), income.getDate(), income.getAmount());
|
income.getCategory(), income.getDate(), income.getAmount());
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.faf223.expensetrackerfaf.model;
|
|||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Entity(name = "credentials")
|
@Entity(name = "credentials")
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
public class Credential {
|
public class Credential {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.faf223.expensetrackerfaf.model;
|
package com.faf223.expensetrackerfaf.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.DecimalMin;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -10,6 +13,7 @@ import java.time.LocalDate;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Entity(name = "expenses")
|
@Entity(name = "expenses")
|
||||||
|
@Builder
|
||||||
public class Expense implements IMoneyTransaction {
|
public class Expense implements IMoneyTransaction {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@@ -24,9 +28,14 @@ public class Expense implements IMoneyTransaction {
|
|||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "category_id")
|
@JoinColumn(name = "category_id")
|
||||||
|
@NotNull
|
||||||
private ExpenseCategory category;
|
private ExpenseCategory category;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@DecimalMin(value = "0.0", inclusive = false)
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
|
|
||||||
public Expense(LocalDate date, BigDecimal amount) {
|
public Expense(LocalDate date, BigDecimal amount) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.faf223.expensetrackerfaf.model;
|
package com.faf223.expensetrackerfaf.model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -12,5 +14,7 @@ public class ExpenseCategory implements IMoneyTransactionCategory {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "category_name")
|
@Column(name = "category_name")
|
||||||
|
@NotNull(message = "Name must not be null")
|
||||||
|
@NotEmpty(message = "Name must not be empty")
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.faf223.expensetrackerfaf.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.DecimalMin;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -11,6 +13,7 @@ import java.time.LocalDate;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Entity(name = "incomes")
|
@Entity(name = "incomes")
|
||||||
|
@Builder
|
||||||
public class Income implements IMoneyTransaction {
|
public class Income implements IMoneyTransaction {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@@ -25,9 +28,14 @@ public class Income implements IMoneyTransaction {
|
|||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "category_id")
|
@JoinColumn(name = "category_id")
|
||||||
|
@NotNull
|
||||||
private IncomeCategory category;
|
private IncomeCategory category;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@DecimalMin(value = "0.0", inclusive = false)
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
|
|
||||||
public Income(IncomeCategory incomeCategory, LocalDate date, BigDecimal amount) {
|
public Income(IncomeCategory incomeCategory, LocalDate date, BigDecimal amount) {
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package com.faf223.expensetrackerfaf.model;
|
package com.faf223.expensetrackerfaf.model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Entity(name = "income_categories")
|
@Entity(name = "income_categories")
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class IncomeCategory implements IMoneyTransactionCategory {
|
public class IncomeCategory implements IMoneyTransactionCategory {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@@ -12,6 +20,8 @@ public class IncomeCategory implements IMoneyTransactionCategory {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "category_name")
|
@Column(name = "category_name")
|
||||||
|
@NotNull(message = "Name must not be null")
|
||||||
|
@NotEmpty(message = "Name must not be empty")
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,46 @@
|
|||||||
package com.faf223.expensetrackerfaf.model;
|
package com.faf223.expensetrackerfaf.model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity(name = "users")
|
@Entity(name = "users")
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class User {
|
public class User {
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "user_uuid")
|
@Column(name = "user_uuid")
|
||||||
@GeneratedValue(strategy = GenerationType.UUID)
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
private String userUuid;
|
private String userUuid;
|
||||||
|
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
|
@NotNull(message = "First name must not be null")
|
||||||
|
@NotEmpty(message = "First name must not be empty")
|
||||||
private String firstName;
|
private String firstName;
|
||||||
|
|
||||||
@Column(name = "surname")
|
@Column(name = "surname")
|
||||||
|
@NotNull(message = "Last name must not be null")
|
||||||
|
@NotEmpty(message = "Last name must not be empty")
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
|
||||||
@Column(name = "username")
|
@Column(name = "username")
|
||||||
|
@NotNull(message = "Username must not be null")
|
||||||
|
@NotEmpty(message = "Username must not be empty")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
private List<Expense> expenses;
|
private List<Expense> expenses;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
private List<Income> incomes;
|
private List<Income> incomes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.faf223.expensetrackerfaf.repository;
|
package com.faf223.expensetrackerfaf.repository;
|
||||||
|
|
||||||
import com.faf223.expensetrackerfaf.model.Credential;
|
import com.faf223.expensetrackerfaf.model.Credential;
|
||||||
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@@ -9,4 +10,8 @@ import java.util.Optional;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface CredentialRepository extends JpaRepository<Credential, Long> {
|
public interface CredentialRepository extends JpaRepository<Credential, Long> {
|
||||||
Optional<Credential> findByEmail(String email);
|
Optional<Credential> findByEmail(String email);
|
||||||
|
|
||||||
|
Optional<Credential> findByUser(User user);
|
||||||
|
|
||||||
|
void deleteByEmail(String email);
|
||||||
}
|
}
|
||||||
@@ -3,11 +3,28 @@ package com.faf223.expensetrackerfaf.repository;
|
|||||||
import com.faf223.expensetrackerfaf.model.Expense;
|
import com.faf223.expensetrackerfaf.model.Expense;
|
||||||
import com.faf223.expensetrackerfaf.model.User;
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.query.Procedure;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ExpenseRepository extends JpaRepository<Expense, Long> {
|
public interface ExpenseRepository extends JpaRepository<Expense, Long> {
|
||||||
List<Expense> findByUser(User user);
|
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.Income;
|
||||||
import com.faf223.expensetrackerfaf.model.User;
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.query.Procedure;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface IncomeRepository extends JpaRepository<Income, Long> {
|
public interface IncomeRepository extends JpaRepository<Income, Long> {
|
||||||
List<Income> findByUser(User user);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ public interface UserRepository extends JpaRepository<User, String> {
|
|||||||
Optional<User> getUserByUserUuid(String userUuid);
|
Optional<User> getUserByUserUuid(String userUuid);
|
||||||
|
|
||||||
Optional<User> findByUsername(String username);
|
Optional<User> findByUsername(String username);
|
||||||
|
|
||||||
|
void deleteByUsername(String username);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,16 @@ import com.faf223.expensetrackerfaf.model.User;
|
|||||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||||
import com.faf223.expensetrackerfaf.security.PersonDetails;
|
import com.faf223.expensetrackerfaf.security.PersonDetails;
|
||||||
|
import com.faf223.expensetrackerfaf.util.exceptions.UserNotAuthenticatedException;
|
||||||
|
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
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.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -25,10 +29,12 @@ import java.util.Optional;
|
|||||||
public class AuthenticationService {
|
public class AuthenticationService {
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
private final UserService userService;
|
||||||
private final CredentialRepository credentialRepository;
|
private final CredentialRepository credentialRepository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final JwtService jwtService;
|
private final JwtService jwtService;
|
||||||
private final AuthenticationManager authenticationManager;
|
private final AuthenticationManager authenticationManager;
|
||||||
|
private final PasswordGenerator passwordGenerator;
|
||||||
|
|
||||||
public AuthenticationResponse register(RegisterRequest request) {
|
public AuthenticationResponse register(RegisterRequest request) {
|
||||||
|
|
||||||
@@ -52,10 +58,58 @@ public class AuthenticationService {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthenticationResponse register(OAuth2User oAuth2User) {
|
||||||
|
String userEmail = oAuth2User.getAttribute("email");
|
||||||
|
|
||||||
|
// 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) {
|
public AuthenticationResponse authenticate(AuthenticationRequest request) {
|
||||||
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(request.getEmail(), request.getPassword()));
|
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(request.getEmail(), request.getPassword()));
|
||||||
|
|
||||||
Credential credential = credentialRepository.findByEmail(request.getEmail()).orElseThrow((() -> new UsernameNotFoundException("User not found")));
|
Credential credential = credentialRepository.findByEmail(request.getEmail()).orElseThrow((() -> new UserNotFoundException("User not found")));
|
||||||
|
|
||||||
UserDetails userDetails = new PersonDetails(credential);
|
UserDetails userDetails = new PersonDetails(credential);
|
||||||
String jwtToken = jwtService.generateToken(userDetails);
|
String jwtToken = jwtService.generateToken(userDetails);
|
||||||
@@ -79,8 +133,25 @@ public class AuthenticationService {
|
|||||||
.refreshToken(refreshToken)
|
.refreshToken(refreshToken)
|
||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Invalid or expired refresh token");
|
throw new UserNotAuthenticatedException("Invalid or expired refresh token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updatePassword(String newPassword) {
|
||||||
|
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
|
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||||
|
User user = userService.getUserByEmail(userDetails.getUsername());
|
||||||
|
Optional<Credential> credential = credentialRepository.findByUser(user);
|
||||||
|
|
||||||
|
if (credential.isPresent()) {
|
||||||
|
|
||||||
|
Credential updatedCredential = credential.get();
|
||||||
|
updatedCredential.setPassword(passwordEncoder.encode(newPassword));
|
||||||
|
credentialRepository.save(updatedCredential);
|
||||||
|
}
|
||||||
|
} else throw new UserNotFoundException("User not found!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.Credential;
|
||||||
import com.faf223.expensetrackerfaf.model.Expense;
|
import com.faf223.expensetrackerfaf.model.Expense;
|
||||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||||
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||||
import com.faf223.expensetrackerfaf.repository.ExpenseRepository;
|
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 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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.Month;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -18,6 +28,8 @@ public class ExpenseService implements ITransactionService {
|
|||||||
|
|
||||||
private final ExpenseRepository expenseRepository;
|
private final ExpenseRepository expenseRepository;
|
||||||
private final CredentialRepository credentialRepository;
|
private final CredentialRepository credentialRepository;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final TransactionFilter transactionFilter;
|
||||||
|
|
||||||
public void createOrUpdate(IMoneyTransaction expense) {
|
public void createOrUpdate(IMoneyTransaction expense) {
|
||||||
expenseRepository.save((Expense) expense);
|
expenseRepository.save((Expense) expense);
|
||||||
@@ -33,6 +45,62 @@ public class ExpenseService implements ITransactionService {
|
|||||||
return new ArrayList<>();
|
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) {
|
||||||
|
System.out.println(expenseRepository.filterByMonth(month.getValue()));
|
||||||
|
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() {
|
public List<Expense> getTransactions() {
|
||||||
return expenseRepository.findAll();
|
return expenseRepository.findAll();
|
||||||
}
|
}
|
||||||
@@ -41,7 +109,30 @@ public class ExpenseService implements ITransactionService {
|
|||||||
return expenseRepository.findById(id).orElse(null);
|
return expenseRepository.findById(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteExpenseById(long id) {
|
public void deleteTransactionById(long id) {
|
||||||
expenseRepository.deleteById(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;
|
package com.faf223.expensetrackerfaf.service;
|
||||||
|
|
||||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ITransactionService {
|
public interface ITransactionService {
|
||||||
@@ -9,6 +13,17 @@ public interface ITransactionService {
|
|||||||
void createOrUpdate(IMoneyTransaction transaction);
|
void createOrUpdate(IMoneyTransaction transaction);
|
||||||
List<? extends IMoneyTransaction> getTransactions();
|
List<? extends IMoneyTransaction> getTransactions();
|
||||||
List<? extends IMoneyTransaction> getTransactionsByEmail(String email);
|
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);
|
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.Credential;
|
||||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||||
import com.faf223.expensetrackerfaf.model.Income;
|
import com.faf223.expensetrackerfaf.model.Income;
|
||||||
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||||
import com.faf223.expensetrackerfaf.repository.IncomeRepository;
|
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 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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.Month;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -18,6 +28,8 @@ public class IncomeService implements ITransactionService {
|
|||||||
|
|
||||||
private final IncomeRepository incomeRepository;
|
private final IncomeRepository incomeRepository;
|
||||||
private final CredentialRepository credentialRepository;
|
private final CredentialRepository credentialRepository;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final TransactionFilter transactionFilter;
|
||||||
|
|
||||||
public void createOrUpdate(IMoneyTransaction income) {
|
public void createOrUpdate(IMoneyTransaction income) {
|
||||||
incomeRepository.save((Income) income);
|
incomeRepository.save((Income) income);
|
||||||
@@ -37,11 +49,88 @@ public class IncomeService implements ITransactionService {
|
|||||||
return new ArrayList<>();
|
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) {
|
public Income getTransactionById(long id) {
|
||||||
return incomeRepository.findById(id).orElse(null);
|
return incomeRepository.findById(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteIncomeById(long id) {
|
public void deleteTransactionById(long id) {
|
||||||
incomeRepository.deleteById(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
package com.faf223.expensetrackerfaf.service;
|
package com.faf223.expensetrackerfaf.service;
|
||||||
|
|
||||||
|
import com.faf223.expensetrackerfaf.config.JwtService;
|
||||||
|
import com.faf223.expensetrackerfaf.controller.auth.AuthenticationResponse;
|
||||||
|
import com.faf223.expensetrackerfaf.dto.UserUpdateDTO;
|
||||||
import com.faf223.expensetrackerfaf.model.Credential;
|
import com.faf223.expensetrackerfaf.model.Credential;
|
||||||
|
import com.faf223.expensetrackerfaf.model.Role;
|
||||||
import com.faf223.expensetrackerfaf.model.User;
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||||
|
import com.faf223.expensetrackerfaf.security.PersonDetails;
|
||||||
|
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import lombok.RequiredArgsConstructor;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,11 +26,48 @@ public class UserService {
|
|||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final CredentialRepository credentialRepository;
|
private final CredentialRepository credentialRepository;
|
||||||
|
private final JwtService jwtService;
|
||||||
|
|
||||||
public void updateUser(User user) {
|
public void updateUser(User user) {
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthenticationResponse updateUser(UserUpdateDTO userUpdate) {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
|
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||||
|
User user = getUserByEmail(userDetails.getUsername());
|
||||||
|
Optional<Credential> credential = credentialRepository.findByUser(user);
|
||||||
|
|
||||||
|
if (credential.isPresent()) {
|
||||||
|
|
||||||
|
Credential credentialToUpdate = credential.get();
|
||||||
|
|
||||||
|
if (userUpdate.getUsername() != null)
|
||||||
|
user.setUsername(userUpdate.getUsername());
|
||||||
|
if (userUpdate.getFirstname() != null)
|
||||||
|
user.setFirstName(userUpdate.getFirstname());
|
||||||
|
if (userUpdate.getLastname() != null)
|
||||||
|
user.setLastName(userUpdate.getLastname());
|
||||||
|
if (userUpdate.getEmail() != null)
|
||||||
|
credentialToUpdate.setEmail(userUpdate.getEmail());
|
||||||
|
|
||||||
|
userRepository.save(user);
|
||||||
|
credentialRepository.save(credentialToUpdate);
|
||||||
|
|
||||||
|
UserDetails details = new PersonDetails(credentialToUpdate);
|
||||||
|
String jwtToken = jwtService.generateToken(details);
|
||||||
|
String refreshToken = jwtService.generateRefreshToken(details);
|
||||||
|
|
||||||
|
return AuthenticationResponse.builder()
|
||||||
|
.accessToken(jwtToken)
|
||||||
|
.refreshToken(refreshToken)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new UserNotFoundException("User not found!");
|
||||||
|
}
|
||||||
|
|
||||||
public List<User> getUsers() {
|
public List<User> getUsers() {
|
||||||
return userRepository.findAll();
|
return userRepository.findAll();
|
||||||
}
|
}
|
||||||
@@ -28,6 +75,7 @@ public class UserService {
|
|||||||
public User getUserById(String userUuid) {
|
public User getUserById(String userUuid) {
|
||||||
return userRepository.findById(userUuid).orElse(null);
|
return userRepository.findById(userUuid).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUserByEmail(String email) {
|
public User getUserByEmail(String email) {
|
||||||
Optional<Credential> credential = credentialRepository.findByEmail(email);
|
Optional<Credential> credential = credentialRepository.findByEmail(email);
|
||||||
if (credential.isPresent()) {
|
if (credential.isPresent()) {
|
||||||
@@ -36,4 +84,42 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteByUsername(String username) {
|
||||||
|
|
||||||
|
Optional<User> user = userRepository.findByUsername(username);
|
||||||
|
if (user.isPresent()) {
|
||||||
|
|
||||||
|
Optional<Credential> credential = credentialRepository.findByUser(user.get());
|
||||||
|
|
||||||
|
if (credential.isPresent()) {
|
||||||
|
|
||||||
|
credentialRepository.deleteByEmail(credential.get().getEmail());
|
||||||
|
userRepository.deleteByUsername(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void promoteUser(String email) {
|
||||||
|
Optional<Credential> credential = credentialRepository.findByEmail(email);
|
||||||
|
if (credential.isPresent()) {
|
||||||
|
|
||||||
|
System.out.println(email);
|
||||||
|
Credential updatedCredential = credential.get();
|
||||||
|
updatedCredential.setRole(Role.ROLE_ADMIN);
|
||||||
|
credentialRepository.save(updatedCredential);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void demoteUser(String email) {
|
||||||
|
Optional<Credential> credential = credentialRepository.findByEmail(email);
|
||||||
|
if (credential.isPresent()) {
|
||||||
|
|
||||||
|
System.out.println(email);
|
||||||
|
Credential updatedCredential = credential.get();
|
||||||
|
updatedCredential.setRole(Role.ROLE_USER);
|
||||||
|
credentialRepository.save(updatedCredential);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
86
src/main/java/com/faf223/expensetrackerfaf/web/fullchain.pem
Normal file
86
src/main/java/com/faf223/expensetrackerfaf/web/fullchain.pem
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEHTCCAwWgAwIBAgISBGYC3YGfvdZxQg6y2YUSjvzLMA0GCSqGSIb3DQEBCwUA
|
||||||
|
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
|
||||||
|
EwJSMzAeFw0yMzEyMTIxOTAxNTVaFw0yNDAzMTExOTAxNTRaMBkxFzAVBgNVBAMT
|
||||||
|
DnRyYWNraW8ub25saW5lMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEirToCuVv
|
||||||
|
qNiT3Rxqsyu2+OmD7TYBW+CV9639OW4FhwHaFxyzoCWI3/w3gZNVE/5Y1CvwHAsw
|
||||||
|
qfuam0LjfbnKOKOCAg8wggILMA4GA1UdDwEB/wQEAwIHgDAdBgNVHSUEFjAUBggr
|
||||||
|
BgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUmUFyQf+b
|
||||||
|
b16jD80QRaO9ipw7h9kwHwYDVR0jBBgwFoAUFC6zF7dYVsuuUAlA5h+vnYsUwsYw
|
||||||
|
VQYIKwYBBQUHAQEESTBHMCEGCCsGAQUFBzABhhVodHRwOi8vcjMuby5sZW5jci5v
|
||||||
|
cmcwIgYIKwYBBQUHMAKGFmh0dHA6Ly9yMy5pLmxlbmNyLm9yZy8wGQYDVR0RBBIw
|
||||||
|
EIIOdHJhY2tpby5vbmxpbmUwEwYDVR0gBAwwCjAIBgZngQwBAgEwggEDBgorBgEE
|
||||||
|
AdZ5AgQCBIH0BIHxAO8AdQA7U3d1Pi25gE6LMFsG/kA7Z9hPw/THvQANLXJv4frU
|
||||||
|
FwAAAYxfnyo6AAAEAwBGMEQCIBqYq5pa2GE7UNJHzN+1AAbw///s8PtWNkauU9UO
|
||||||
|
igWZAiAktf1uf/O90k1l/+ihkPxJXToxcH5yeOiqATqDMol5PwB2AHb/iD8KtvuV
|
||||||
|
UcJhzPWHujS0pM27KdxoQgqf5mdMWjp0AAABjF+fKoMAAAQDAEcwRQIgfNyTycHQ
|
||||||
|
D1OMAOBA8vHAyu//5SjnY0BtCxOITyY/W1oCIQCCHFH+VKTFCglsqcp2hwQJHGq/
|
||||||
|
jiSj4tR0jYIm5xMlaTANBgkqhkiG9w0BAQsFAAOCAQEAqu7cvsrkAnyrBgQHovQ4
|
||||||
|
r+F1S/H6vu/Bvt9x+d125uDa/pT55JO/wG1IvdT9fxws2oYcc/nc8DjvW9U7+peu
|
||||||
|
5K675kH09QTi+GhBAU4gZBhx3PohA6qG0Wm/6gC4lOq+S7o32x6RpoptcSvB3UXQ
|
||||||
|
9BkgbO6LgDu99jPm6Acv4wre6trXAbPOpSlruSKSENnda7l/CamfiOX0cRKHjZdX
|
||||||
|
PNpIfqWXokXNNYDAdrcXbOm7mFVMo1WcjBQM6E++IXfDRqHQ82Y94YVhEdH/hCo6
|
||||||
|
3ce9uSrgL9+HcwhHzlZj20rTHFJ6iX/+Ffk8wbYfR4Eu7MXDg8ULT0z93yIvDxgy
|
||||||
|
uw==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw
|
||||||
|
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||||
|
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjAwOTA0MDAwMDAw
|
||||||
|
WhcNMjUwOTE1MTYwMDAwWjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg
|
||||||
|
RW5jcnlwdDELMAkGA1UEAxMCUjMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
|
||||||
|
AoIBAQC7AhUozPaglNMPEuyNVZLD+ILxmaZ6QoinXSaqtSu5xUyxr45r+XXIo9cP
|
||||||
|
R5QUVTVXjJ6oojkZ9YI8QqlObvU7wy7bjcCwXPNZOOftz2nwWgsbvsCUJCWH+jdx
|
||||||
|
sxPnHKzhm+/b5DtFUkWWqcFTzjTIUu61ru2P3mBw4qVUq7ZtDpelQDRrK9O8Zutm
|
||||||
|
NHz6a4uPVymZ+DAXXbpyb/uBxa3Shlg9F8fnCbvxK/eG3MHacV3URuPMrSXBiLxg
|
||||||
|
Z3Vms/EY96Jc5lP/Ooi2R6X/ExjqmAl3P51T+c8B5fWmcBcUr2Ok/5mzk53cU6cG
|
||||||
|
/kiFHaFpriV1uxPMUgP17VGhi9sVAgMBAAGjggEIMIIBBDAOBgNVHQ8BAf8EBAMC
|
||||||
|
AYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIGA1UdEwEB/wQIMAYB
|
||||||
|
Af8CAQAwHQYDVR0OBBYEFBQusxe3WFbLrlAJQOYfr52LFMLGMB8GA1UdIwQYMBaA
|
||||||
|
FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw
|
||||||
|
AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw
|
||||||
|
Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB
|
||||||
|
gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W
|
||||||
|
PTNlclQtgaDqw+34IL9fzLdwALduO/ZelN7kIJ+m74uyA+eitRY8kc607TkC53wl
|
||||||
|
ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz
|
||||||
|
CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm
|
||||||
|
lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4
|
||||||
|
avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2
|
||||||
|
yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O
|
||||||
|
yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids
|
||||||
|
hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+
|
||||||
|
HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv
|
||||||
|
MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX
|
||||||
|
nLRbwHOoq7hHwg==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFYDCCBEigAwIBAgIQQAF3ITfU6UK47naqPGQKtzANBgkqhkiG9w0BAQsFADA/
|
||||||
|
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
|
||||||
|
DkRTVCBSb290IENBIFgzMB4XDTIxMDEyMDE5MTQwM1oXDTI0MDkzMDE4MTQwM1ow
|
||||||
|
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||||
|
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwggIiMA0GCSqGSIb3DQEB
|
||||||
|
AQUAA4ICDwAwggIKAoICAQCt6CRz9BQ385ueK1coHIe+3LffOJCMbjzmV6B493XC
|
||||||
|
ov71am72AE8o295ohmxEk7axY/0UEmu/H9LqMZshftEzPLpI9d1537O4/xLxIZpL
|
||||||
|
wYqGcWlKZmZsj348cL+tKSIG8+TA5oCu4kuPt5l+lAOf00eXfJlII1PoOK5PCm+D
|
||||||
|
LtFJV4yAdLbaL9A4jXsDcCEbdfIwPPqPrt3aY6vrFk/CjhFLfs8L6P+1dy70sntK
|
||||||
|
4EwSJQxwjQMpoOFTJOwT2e4ZvxCzSow/iaNhUd6shweU9GNx7C7ib1uYgeGJXDR5
|
||||||
|
bHbvO5BieebbpJovJsXQEOEO3tkQjhb7t/eo98flAgeYjzYIlefiN5YNNnWe+w5y
|
||||||
|
sR2bvAP5SQXYgd0FtCrWQemsAXaVCg/Y39W9Eh81LygXbNKYwagJZHduRze6zqxZ
|
||||||
|
Xmidf3LWicUGQSk+WT7dJvUkyRGnWqNMQB9GoZm1pzpRboY7nn1ypxIFeFntPlF4
|
||||||
|
FQsDj43QLwWyPntKHEtzBRL8xurgUBN8Q5N0s8p0544fAQjQMNRbcTa0B7rBMDBc
|
||||||
|
SLeCO5imfWCKoqMpgsy6vYMEG6KDA0Gh1gXxG8K28Kh8hjtGqEgqiNx2mna/H2ql
|
||||||
|
PRmP6zjzZN7IKw0KKP/32+IVQtQi0Cdd4Xn+GOdwiK1O5tmLOsbdJ1Fu/7xk9TND
|
||||||
|
TwIDAQABo4IBRjCCAUIwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYw
|
||||||
|
SwYIKwYBBQUHAQEEPzA9MDsGCCsGAQUFBzAChi9odHRwOi8vYXBwcy5pZGVudHJ1
|
||||||
|
c3QuY29tL3Jvb3RzL2RzdHJvb3RjYXgzLnA3YzAfBgNVHSMEGDAWgBTEp7Gkeyxx
|
||||||
|
+tvhS5B1/8QVYIWJEDBUBgNVHSAETTBLMAgGBmeBDAECATA/BgsrBgEEAYLfEwEB
|
||||||
|
ATAwMC4GCCsGAQUFBwIBFiJodHRwOi8vY3BzLnJvb3QteDEubGV0c2VuY3J5cHQu
|
||||||
|
b3JnMDwGA1UdHwQ1MDMwMaAvoC2GK2h0dHA6Ly9jcmwuaWRlbnRydXN0LmNvbS9E
|
||||||
|
U1RST09UQ0FYM0NSTC5jcmwwHQYDVR0OBBYEFHm0WeZ7tuXkAXOACIjIGlj26Ztu
|
||||||
|
MA0GCSqGSIb3DQEBCwUAA4IBAQAKcwBslm7/DlLQrt2M51oGrS+o44+/yQoDFVDC
|
||||||
|
5WxCu2+b9LRPwkSICHXM6webFGJueN7sJ7o5XPWioW5WlHAQU7G75K/QosMrAdSW
|
||||||
|
9MUgNTP52GE24HGNtLi1qoJFlcDyqSMo59ahy2cI2qBDLKobkx/J3vWraV0T9VuG
|
||||||
|
WCLKTVXkcGdtwlfFRjlBz4pYg1htmf5X6DYO8A4jqv2Il9DjXA6USbW1FzXSLr9O
|
||||||
|
he8Y4IWS6wY7bCkjCWDcRQJMEhg76fsO3txE+FiYruq9RUWhiF1myv4Q6W+CyBFC
|
||||||
|
Dfvp7OOGAN6dEOM4+qR9sdjoSYKEBpsr6GtPAQw4dy753ec5
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -11,10 +11,9 @@
|
|||||||
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
||||||
"axios": "^1.5.1",
|
"axios": "^1.5.1",
|
||||||
|
"bootstrap": "^5.3.2",
|
||||||
"chart.js": "^4.4.0",
|
"chart.js": "^4.4.0",
|
||||||
"email-validator": "^2.0.4",
|
"email-validator": "^2.0.4",
|
||||||
"js-cookie": "^3.0.5",
|
|
||||||
"stores": "^1.0.0",
|
|
||||||
"svelte-cookie": "^1.0.1",
|
"svelte-cookie": "^1.0.1",
|
||||||
"svelte-fa": "^3.0.4",
|
"svelte-fa": "^3.0.4",
|
||||||
"svelte-simple-modal": "^1.6.1",
|
"svelte-simple-modal": "^1.6.1",
|
||||||
@@ -579,9 +578,9 @@
|
|||||||
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg=="
|
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg=="
|
||||||
},
|
},
|
||||||
"node_modules/@jridgewell/trace-mapping": {
|
"node_modules/@jridgewell/trace-mapping": {
|
||||||
"version": "0.3.19",
|
"version": "0.3.20",
|
||||||
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz",
|
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz",
|
||||||
"integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==",
|
"integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jridgewell/resolve-uri": "^3.1.0",
|
"@jridgewell/resolve-uri": "^3.1.0",
|
||||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
@@ -639,6 +638,16 @@
|
|||||||
"integrity": "sha512-C16M+IYz0rgRhWZdCmK+h58JMv8vijAA61gmz2rspCSwKwzBebpdcsiUmwrtJRdphuY30i6BSLEOP8ppbNLyLg==",
|
"integrity": "sha512-C16M+IYz0rgRhWZdCmK+h58JMv8vijAA61gmz2rspCSwKwzBebpdcsiUmwrtJRdphuY30i6BSLEOP8ppbNLyLg==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/@sveltejs/adapter-auto": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-auto/-/adapter-auto-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-auto/-/adapter-auto-2.1.0.tgz",
|
||||||
@@ -729,9 +738,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/estree": {
|
"node_modules/@types/estree": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
|
||||||
"integrity": "sha512-VeiPZ9MMwXjO32/Xu7+OwflfmeoRwkE/qzndw42gGtgJwZopBnzy2gD//NN1+go1mADzkDcqf/KnFRSjTJ8xJA=="
|
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw=="
|
||||||
},
|
},
|
||||||
"node_modules/acorn": {
|
"node_modules/acorn": {
|
||||||
"version": "8.10.0",
|
"version": "8.10.0",
|
||||||
@@ -813,9 +822,9 @@
|
|||||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.5.1",
|
"version": "1.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz",
|
||||||
"integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==",
|
"integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.0",
|
"follow-redirects": "^1.15.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
@@ -836,6 +845,24 @@
|
|||||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
@@ -976,11 +1003,6 @@
|
|||||||
"node": ">=4"
|
"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": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
@@ -1491,11 +1513,6 @@
|
|||||||
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==",
|
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/graphemer": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
|
||||||
@@ -1615,14 +1632,6 @@
|
|||||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/js-yaml": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||||
@@ -1796,25 +1805,6 @@
|
|||||||
"node": "*"
|
"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": {
|
"node_modules/mri": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||||
@@ -1863,14 +1853,6 @@
|
|||||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
@@ -2319,17 +2301,6 @@
|
|||||||
"node": ">=0.10.0"
|
"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": {
|
"node_modules/strip-ansi": {
|
||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||||
@@ -2367,9 +2338,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/svelte": {
|
"node_modules/svelte": {
|
||||||
"version": "4.2.1",
|
"version": "4.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.5.tgz",
|
||||||
"integrity": "sha512-LpLqY2Jr7cRxkrTc796/AaaoMLF/1ax7cto8Ot76wrvKQhrPmZ0JgajiWPmg9mTSDqO16SSLiD17r9MsvAPTmw==",
|
"integrity": "sha512-P9YPKsGkNdw4OJbtpd1uzimQHPj7Ai2sPcOHmmD6VgkFhFDmcYevQi7vE4cQ1g8/Vs64aL2TwMoCNFAzv7TPaQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ampproject/remapping": "^2.2.1",
|
"@ampproject/remapping": "^2.2.1",
|
||||||
"@jridgewell/sourcemap-codec": "^1.4.15",
|
"@jridgewell/sourcemap-codec": "^1.4.15",
|
||||||
@@ -2382,7 +2353,7 @@
|
|||||||
"estree-walker": "^3.0.3",
|
"estree-walker": "^3.0.3",
|
||||||
"is-reference": "^3.0.1",
|
"is-reference": "^3.0.1",
|
||||||
"locate-character": "^3.0.0",
|
"locate-character": "^3.0.0",
|
||||||
"magic-string": "^0.30.0",
|
"magic-string": "^0.30.4",
|
||||||
"periscopic": "^3.1.0"
|
"periscopic": "^3.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"name": "expensetracker",
|
"name": "expensetracker",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev --host",
|
||||||
|
"devs": "vite dev --host --https",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
||||||
@@ -26,10 +27,9 @@
|
|||||||
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
||||||
"axios": "^1.5.1",
|
"axios": "^1.5.1",
|
||||||
|
"bootstrap": "^5.3.2",
|
||||||
"chart.js": "^4.4.0",
|
"chart.js": "^4.4.0",
|
||||||
"email-validator": "^2.0.4",
|
"email-validator": "^2.0.4",
|
||||||
"js-cookie": "^3.0.5",
|
|
||||||
"stores": "^1.0.0",
|
|
||||||
"svelte-cookie": "^1.0.1",
|
"svelte-cookie": "^1.0.1",
|
||||||
"svelte-fa": "^3.0.4",
|
"svelte-fa": "^3.0.4",
|
||||||
"svelte-simple-modal": "^1.6.1",
|
"svelte-simple-modal": "^1.6.1",
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg9kCIfgqNqFYgYU0Q
|
||||||
|
HGi/jc5nLxhZxoXST5qeXBGtOAehRANCAASKtOgK5W+o2JPdHGqzK7b46YPtNgFb
|
||||||
|
4JX3rf05bgWHAdoXHLOgJYjf/DeBk1UT/ljUK/AcCzCp+5qbQuN9uco4
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
<link rel="icon" href="/favicon.png" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
BIN
src/main/java/com/faf223/expensetrackerfaf/web/src/favicon.png
Normal file
BIN
src/main/java/com/faf223/expensetrackerfaf/web/src/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
@@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
@@ -22,11 +22,13 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('http://localhost:8081/api/v1/auth/authenticate', {
|
const response = await axios.post('https://trackio.online:8081/api/v1/auth/authenticate', {
|
||||||
email: username,
|
email: username,
|
||||||
password: password,
|
password: password,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(response.data)
|
||||||
|
|
||||||
const { access_token, refresh_token } = response.data;
|
const { access_token, refresh_token } = response.data;
|
||||||
|
|
||||||
setCookie('access_token', access_token);
|
setCookie('access_token', access_token);
|
||||||
@@ -60,6 +62,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<link rel="icon" type="image/x-icon" href="../favicon.png" />
|
||||||
|
<title>Login into Track.IO</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400');
|
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400');
|
||||||
|
|||||||
@@ -1,39 +1,89 @@
|
|||||||
<script>
|
<script>
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
import * as EmailValidator from 'email-validator';
|
import * as EmailValidator from 'email-validator';
|
||||||
|
import {onMount} from "svelte";
|
||||||
|
import {getCookie, setCookie} from "svelte-cookie";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
let isErrorVisible = false;
|
let isErrorVisible = false;
|
||||||
let username, email, password;
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
let username, email, password, name, surname;
|
||||||
let message = ""
|
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();
|
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('https://trackio.online: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() {
|
// function submitForm(event) {
|
||||||
let valid = EmailValidator.validate(username);
|
// event.preventDefault();
|
||||||
isErrorVisible = valid ? false : true;
|
// // console.log("Tried to submit!");
|
||||||
message = isErrorVisible ? "Invalid e-mail!" : "";
|
// // console.log("Valid? ", (validateEmail() && validateUsername() && validatePassword() ? "Yes" : "No"));
|
||||||
return valid;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
function validatePassword() {
|
// function validateEmail() {
|
||||||
let valid = password.value != '';
|
// let valid = EmailValidator.validate(username);
|
||||||
isErrorVisible = valid ? false : true;
|
// isErrorVisible = valid ? false : true;
|
||||||
message = isErrorVisible ? "Invalid password!" : "";
|
// message = isErrorVisible ? "Invalid e-mail!" : "";
|
||||||
return valid;
|
// return valid;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
function validateUsername() {
|
// function validatePassword() {
|
||||||
let valid = username.value != '';
|
// let valid = password.value != '';
|
||||||
isErrorVisible = valid ? false : true;
|
// isErrorVisible = valid ? false : true;
|
||||||
message = isErrorVisible ? "Invalid password!" : "";
|
// message = isErrorVisible ? "Invalid password!" : "";
|
||||||
return valid;
|
// return valid;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// function validateUsername() {
|
||||||
|
// let valid = username.value != '';
|
||||||
|
// isErrorVisible = valid ? false : true;
|
||||||
|
// message = isErrorVisible ? "Invalid password!" : "";
|
||||||
|
// return valid;
|
||||||
|
// }
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<link rel="icon" type="image/x-icon" href="../favicon.png" />
|
||||||
|
<title>Register into Track.IO</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
|
||||||
<div class="animated bounceInDown">
|
<div class="animated bounceInDown">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{#if isErrorVisible}
|
{#if isErrorVisible}
|
||||||
@@ -45,11 +95,17 @@
|
|||||||
<input id="usernameInput" type="text" name="username" placeholder="Username" autocomplete="off" on:input={
|
<input id="usernameInput" type="text" name="username" placeholder="Username" autocomplete="off" on:input={
|
||||||
event => {username = event.target.value}
|
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={
|
<input id="emailInput" type="text" name="email" placeholder="Email" autocomplete="off" on:input={
|
||||||
event => {email = event.target.value}
|
event => {email = event.target.value}
|
||||||
}>
|
}>
|
||||||
<input id="passwordInput" type="password" name="password" placeholder="Password" autocomplete="off" on:input={
|
<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>
|
<a href="/auth/recovery" class="recoveryPass">Forgot your password?</a>
|
||||||
<input type="submit" value="Sign up" class="submitButton">
|
<input type="submit" value="Sign up" class="submitButton">
|
||||||
@@ -75,7 +131,7 @@
|
|||||||
border-top: 10px solid #79a6fe;
|
border-top: 10px solid #79a6fe;
|
||||||
border-bottom: 10px solid #8BD17C;
|
border-bottom: 10px solid #8BD17C;
|
||||||
width: 400px;
|
width: 400px;
|
||||||
height: 600px;
|
height: 750px;
|
||||||
box-shadow: 1px 1px 108.8px 19.2px rgb(25, 31, 53);
|
box-shadow: 1px 1px 108.8px 19.2px rgb(25, 31, 53);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,62 @@
|
|||||||
<script>
|
<script>
|
||||||
import Dashboard from './board/Dashboard.svelte';
|
import Dashboard from './board/Dashboard.svelte';
|
||||||
import SideMenu from './menu/SideMenu.svelte';
|
import SideMenu from './menu/SideMenu.svelte';
|
||||||
|
import {selectedTab} from "./stores.js";
|
||||||
|
import {globalStyles} from "./styles.js";
|
||||||
|
import StickyMenu from "./menu/StickyMenu.svelte";
|
||||||
|
import {onMount} from "svelte";
|
||||||
|
|
||||||
|
function handleTabClick(tab) {
|
||||||
|
selectedTab.set(tab);
|
||||||
|
// $isCategorizedIncome = false;
|
||||||
|
// $isCategorizedExpense = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let screenWidth;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
screenWidth = window.innerWidth;
|
||||||
|
const handleResize = () => {
|
||||||
|
console.log(screenWidth);
|
||||||
|
screenWidth = window.innerWidth;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('resize', handleResize);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('resize', handleResize);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="wrapper">
|
<div id="wrapper" style="background-color: {$globalStyles.mainColor}">
|
||||||
<SideMenu />
|
{#if screenWidth < 900}
|
||||||
|
<StickyMenu onTabClick={handleTabClick} />
|
||||||
|
{:else}
|
||||||
|
<SideMenu onTabClick={handleTabClick} />
|
||||||
|
{/if}
|
||||||
<Dashboard />
|
<Dashboard />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400');
|
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400');
|
||||||
|
@import url('https://fonts.googleapis.com/css?family=Inconsolata');
|
||||||
|
|
||||||
#wrapper {
|
#wrapper {
|
||||||
background-color: rgb(23,34,51);
|
padding: 0;
|
||||||
|
font-family: Inconsolata,"Source Sans Pro",sans-serif;
|
||||||
|
margin: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
|
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#wrapper {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import axios from "axios";
|
||||||
|
import { getCookie } from "svelte-cookie";
|
||||||
|
|
||||||
|
let isLoaded = false;
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
isLoaded = false;
|
||||||
|
isLoaded = true;
|
||||||
|
const token = getCookie('access_token');
|
||||||
|
|
||||||
|
if (token === '') {
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get('https://trackio.online:8081/users', config);
|
||||||
|
const userResponse = response.data;
|
||||||
|
userData = userResponse;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="adminContainer">
|
||||||
|
{#if !isLoaded}
|
||||||
|
<div class="loading-container">
|
||||||
|
<div class="loading-spinner"></div>
|
||||||
|
<div class="loading-text">Loading...</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
LOL
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
.adminContainer {
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-container {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
border: 8px solid rgba(0, 0, 0, 0.1);
|
||||||
|
border-top: 8px solid #3498db;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% { transform: rotate(0deg); }
|
||||||
|
100% { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-text {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,14 +1,34 @@
|
|||||||
<script>
|
<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 { getCookie } from "svelte-cookie";
|
||||||
import {onMount} from "svelte";
|
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,
|
||||||
|
monthIncome,
|
||||||
|
monthExpense,
|
||||||
|
tempExpense,
|
||||||
|
tempIncome, copyExpenseData, copyIncomeData,
|
||||||
|
isAdmin, username
|
||||||
|
} 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";
|
import axios from "axios";
|
||||||
|
import Statistics from "./Statistics.svelte";
|
||||||
|
import AdminPanel from "./AdminPanel.svelte";
|
||||||
|
import Profile from "./Profile.svelte";
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const token = getCookie('access_token');
|
const token = getCookie('access_token');
|
||||||
@@ -25,40 +45,89 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get('https://trackio.online:8081/users/get-user-data', config);
|
||||||
|
const data = response.data;
|
||||||
|
$username = data.username;
|
||||||
|
$isAdmin = data.userrole === 'ROLE_ADMIN';
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentDate = new Date();
|
||||||
|
const currentMonth = currentDate.getMonth() + 1;
|
||||||
const [incomeResponse, expenseResponse, incomeTypesResponse, expenseTypesResponse] = await Promise.all([
|
const [incomeResponse, expenseResponse, incomeTypesResponse, expenseTypesResponse] = await Promise.all([
|
||||||
axios.get('http://localhost:8081/incomes/personal-incomes', config),
|
axios.get('https://trackio.online:8081/incomes/personal-incomes?month=' + currentMonth , config),
|
||||||
axios.get('http://localhost:8081/expenses/personal-expenses', config),
|
axios.get('https://trackio.online:8081/expenses/personal-expenses?month=' + currentMonth, config),
|
||||||
axios.get('http://localhost:8081/incomes/categories', config),
|
axios.get('https://trackio.online:8081/incomes/categories', config),
|
||||||
axios.get('http://localhost:8081/expenses/categories', config)
|
axios.get('https://trackio.online:8081/expenses/categories', config)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
console.log("Data", incomeResponse.data);
|
||||||
|
|
||||||
incomeData.set(incomeResponse.data);
|
incomeData.set(incomeResponse.data);
|
||||||
expenseData.set(expenseResponse.data);
|
expenseData.set(expenseResponse.data);
|
||||||
|
|
||||||
|
copyExpenseData.set(expenseResponse.data);
|
||||||
|
copyIncomeData.set(incomeResponse.data);
|
||||||
|
|
||||||
incomeTypes.set(incomeTypesResponse.data);
|
incomeTypes.set(incomeTypesResponse.data);
|
||||||
expenseTypes.set(expenseTypesResponse.data);
|
expenseTypes.set(expenseTypesResponse.data);
|
||||||
|
|
||||||
|
tempExpense.set(expenseResponse.data);
|
||||||
|
tempIncome.set(incomeResponse.data);
|
||||||
|
|
||||||
|
monthIncome.set(incomeResponse.data);
|
||||||
|
monthExpense.set(expenseResponse.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="dashboard">
|
<svelte:head>
|
||||||
<DashHeader />
|
<link rel="icon" type="image/x-icon" href="../favicon.png" />
|
||||||
<QuickInfobar />
|
<title>Track.IO</title>
|
||||||
<DataMenu />
|
</svelte:head>
|
||||||
|
|
||||||
|
<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 />
|
||||||
|
{:else if $selectedTab === 'statistics'}
|
||||||
|
<Statistics />
|
||||||
|
{:else if $selectedTab === 'admin'}
|
||||||
|
<AdminPanel />
|
||||||
|
{:else if $selectedTab === 'profile'}
|
||||||
|
<Profile />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
#dashboard {
|
#dashboard {
|
||||||
font-family: 'Source Sans Pro', sans-serif;
|
font-family: 'Source Sans Pro', sans-serif;
|
||||||
background-color: rgb(245,242,243);
|
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex:1 1 auto;
|
flex: 1 1 auto;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
justify-content: stretch;
|
justify-content: stretch;
|
||||||
|
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#dashboard {
|
||||||
|
margin: 0;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<script>
|
||||||
|
import DashHeader from "./expenses/other/DashHeader.svelte";
|
||||||
|
import QuickInfobar from "./expenses/other/QuickInfobar.svelte";
|
||||||
|
import Expenses from "./expenses/infolists/Expenses.svelte";
|
||||||
|
import Graph3 from "./expenses/graphs/Graph3.svelte";
|
||||||
|
import Graph2 from "./expenses/graphs/Graph2.svelte";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="expenseContainer">
|
||||||
|
<div class="dataHalf">
|
||||||
|
<div>
|
||||||
|
<DashHeader />
|
||||||
|
<QuickInfobar />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="graphs">
|
||||||
|
<Graph3 />
|
||||||
|
<Graph2 />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Expenses />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
.expenseContainer {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graphs {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.graphs {
|
||||||
|
display:flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: stretch;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
height: 100% !important;
|
||||||
|
width: 100% !important;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
.expenseContainer {
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
background-color: #172233;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataHalf {
|
||||||
|
display:flex;
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
background-color: #212942;
|
||||||
|
border-radius: 20px;
|
||||||
|
/*padding: 10px;*/
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<script>
|
||||||
|
import DashHeader from "./incomes/other/DashHeader.svelte";
|
||||||
|
import QuickInfobar from "./incomes/other/QuickInfobar.svelte";
|
||||||
|
import Incomes from "./incomes/infolists/Incomes.svelte";
|
||||||
|
import Graph3 from "./incomes/graphs/Graph3.svelte";
|
||||||
|
import Graph2 from "./incomes/graphs/Graph2.svelte";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="incomeContainer">
|
||||||
|
<div class="dataHalf">
|
||||||
|
<div>
|
||||||
|
<DashHeader />
|
||||||
|
<QuickInfobar />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="graphs">
|
||||||
|
<Graph3 />
|
||||||
|
<Graph2 />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Incomes />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
.incomeContainer {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graphs {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.graphs {
|
||||||
|
display:flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: stretch;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
height: 100% !important;
|
||||||
|
width: 100% !important;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
.incomeContainer {
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
background-color: #172233;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataHalf {
|
||||||
|
display:flex;
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
background-color: #212942;
|
||||||
|
border-radius: 20px;
|
||||||
|
/*padding: 10px;*/
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<h1>PROFILE</h1>
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<script>
|
||||||
|
import {globalStyles} from "../styles.js";
|
||||||
|
import {themeDark} from "../styles.js";
|
||||||
|
import {themeDefault} from "../styles.js";
|
||||||
|
import {themeColorful} from "../styles.js";
|
||||||
|
|
||||||
|
function theme_dark() {
|
||||||
|
$globalStyles = themeDark;
|
||||||
|
}
|
||||||
|
|
||||||
|
function theme_default() {
|
||||||
|
$globalStyles = themeDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
function theme_colorful() {
|
||||||
|
$globalStyles = themeColorful;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div style="color: {$globalStyles.dashTextColor}">
|
||||||
|
<h1>Settings</h1>
|
||||||
|
<div id="buttonContainer">
|
||||||
|
<div class="settingEntry">
|
||||||
|
<span><svg style="fill: yellow" xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M361.5 1.2c5 2.1 8.6 6.6 9.6 11.9L391 121l107.9 19.8c5.3 1 9.8 4.6 11.9 9.6s1.5 10.7-1.6 15.2L446.9 256l62.3 90.3c3.1 4.5 3.7 10.2 1.6 15.2s-6.6 8.6-11.9 9.6L391 391 371.1 498.9c-1 5.3-4.6 9.8-9.6 11.9s-10.7 1.5-15.2-1.6L256 446.9l-90.3 62.3c-4.5 3.1-10.2 3.7-15.2 1.6s-8.6-6.6-9.6-11.9L121 391 13.1 371.1c-5.3-1-9.8-4.6-11.9-9.6s-1.5-10.7 1.6-15.2L65.1 256 2.8 165.7c-3.1-4.5-3.7-10.2-1.6-15.2s6.6-8.6 11.9-9.6L121 121 140.9 13.1c1-5.3 4.6-9.8 9.6-11.9s10.7-1.5 15.2 1.6L256 65.1 346.3 2.8c4.5-3.1 10.2-3.7 15.2-1.6zM160 256a96 96 0 1 1 192 0 96 96 0 1 1 -192 0zm224 0a128 128 0 1 0 -256 0 128 128 0 1 0 256 0z"/></svg></span>
|
||||||
|
<h3 class="settingName">Light Mode</h3>
|
||||||
|
<button class="button-32" on:click={() => theme_default()}>Select</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="settingEntry">
|
||||||
|
<span><svg style="fill:darkblue" xmlns="http://www.w3.org/2000/svg" height="16" width="12" viewBox="0 0 384 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M223.5 32C100 32 0 132.3 0 256S100 480 223.5 480c60.6 0 115.5-24.2 155.8-63.4c5-4.9 6.3-12.5 3.1-18.7s-10.1-9.7-17-8.5c-9.8 1.7-19.8 2.6-30.1 2.6c-96.9 0-175.5-78.8-175.5-176c0-65.8 36-123.1 89.3-153.3c6.1-3.5 9.2-10.5 7.7-17.3s-7.3-11.9-14.3-12.5c-6.3-.5-12.6-.8-19-.8z"/></svg></span>
|
||||||
|
<h3 class="settingName">Dark Mode</h3>
|
||||||
|
<button class="button-32" on:click={() => theme_dark()}>Select</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="settingEntry">
|
||||||
|
<span><svg style="fill:pink" xmlns="http://www.w3.org/2000/svg" height="16" width="10" viewBox="0 0 320 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M160 0a48 48 0 1 1 0 96 48 48 0 1 1 0-96zM88 384H70.2c-10.9 0-18.6-10.7-15.2-21.1L93.3 248.1 59.4 304.5c-9.1 15.1-28.8 20-43.9 10.9s-20-28.8-10.9-43.9l53.6-89.2c20.3-33.7 56.7-54.3 96-54.3h11.6c39.3 0 75.7 20.6 96 54.3l53.6 89.2c9.1 15.1 4.2 34.8-10.9 43.9s-34.8 4.2-43.9-10.9l-33.9-56.3L265 362.9c3.5 10.4-4.3 21.1-15.2 21.1H232v96c0 17.7-14.3 32-32 32s-32-14.3-32-32V384H152v96c0 17.7-14.3 32-32 32s-32-14.3-32-32V384z"/></svg></span>
|
||||||
|
<h3 class="settingName">Pinky Theme</h3>
|
||||||
|
<button class="button-32" on:click={() => theme_colorful()}>Select</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</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;
|
||||||
|
}
|
||||||
|
|
||||||
|
#buttonContainer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settingEntry {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settingName {
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<h1>ACT LIKE THERE'S A NEURAL NETWORK HERE</h1>
|
||||||
|
<h1>IT'S REALLY IN THE WORKS THOUGH</h1>
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto';
|
||||||
|
import {onMount} from 'svelte';
|
||||||
|
import {monthExpense} from "../../../stores.js";
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
|
||||||
|
let ctx;
|
||||||
|
let chartCanvas;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
function groupAndSumByCategory() {
|
||||||
|
const groupedData = new Map();
|
||||||
|
$monthExpense.forEach(expense => {
|
||||||
|
const category = expense.expenseCategory.name;
|
||||||
|
if (groupedData.has(category)) {
|
||||||
|
groupedData.set(category, groupedData.get(category) + parseInt(expense.amount));
|
||||||
|
} else {
|
||||||
|
groupedData.set(category, parseInt(expense.amount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Map([...groupedData.entries()].sort());
|
||||||
|
}
|
||||||
|
|
||||||
|
function createGraph() {
|
||||||
|
try {
|
||||||
|
const groupedExpenseData = groupAndSumByCategory();
|
||||||
|
|
||||||
|
const chartLabels = [];
|
||||||
|
const chartValues = [];
|
||||||
|
|
||||||
|
for (const [label, value] of groupedExpenseData.entries()) {
|
||||||
|
chartLabels.push(label);
|
||||||
|
chartValues.push(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = chartCanvas.getContext('2d');
|
||||||
|
|
||||||
|
if (!chart) {
|
||||||
|
chart = new Chart(ctx, {
|
||||||
|
type: 'doughnut',
|
||||||
|
data: {
|
||||||
|
labels: chartLabels,
|
||||||
|
datasets: [{
|
||||||
|
label: 'Spendings',
|
||||||
|
data: chartValues
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
backgroundColor: [
|
||||||
|
'rgb(255, 140, 140)',
|
||||||
|
'rgb(140, 180, 255)',
|
||||||
|
'rgb(255, 200, 140)',
|
||||||
|
'rgb(160, 200, 160)',
|
||||||
|
'rgb(160, 130, 200)',
|
||||||
|
'rgb(255, 160, 140)',
|
||||||
|
'rgb(140, 180, 255)',
|
||||||
|
'rgb(160, 255, 160)',
|
||||||
|
'rgb(255, 140, 120)',
|
||||||
|
'rgb(160, 140, 200)',
|
||||||
|
'rgb(255, 220, 140)',
|
||||||
|
'rgb(140, 255, 255)',
|
||||||
|
'rgb(255, 160, 140)',
|
||||||
|
'rgb(160, 255, 160)',
|
||||||
|
'rgb(160, 160, 255)'
|
||||||
|
],
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
position: 'bottom',
|
||||||
|
align: 'start',
|
||||||
|
fullWidth: false,
|
||||||
|
labels: {
|
||||||
|
font: {
|
||||||
|
weight: 'bold'
|
||||||
|
},
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
chart.data.labels = chartLabels;
|
||||||
|
chart.data.datasets[0].data = chartValues;
|
||||||
|
chart.update();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($monthExpense) {
|
||||||
|
createGraph();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
createGraph();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="chart" style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<canvas bind:this={chartCanvas}></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#chart {
|
||||||
|
min-width: 0;
|
||||||
|
min-height:0;
|
||||||
|
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);
|
||||||
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
flex-grow: 1;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin: 0 10px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chart:hover {
|
||||||
|
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#chart {
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import {monthIncome, monthExpense, isCategorizedExpense, categorizedExpense, expenseCategoryLabel} from "../../../stores.js";
|
||||||
|
import { globalStyles } from "../../../styles.js";
|
||||||
|
|
||||||
|
let ctx;
|
||||||
|
let chartCanvas;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
let generatedData;
|
||||||
|
|
||||||
|
function createGraph() {
|
||||||
|
try {
|
||||||
|
if (chartCanvas.getContext('2d') !== undefined) {
|
||||||
|
ctx = chartCanvas.getContext('2d');
|
||||||
|
if (!chart) {
|
||||||
|
console.log(generatedData);
|
||||||
|
chart = new Chart(ctx, {
|
||||||
|
type: 'line',
|
||||||
|
data: generatedData,
|
||||||
|
options: {
|
||||||
|
scales: {
|
||||||
|
y: {
|
||||||
|
ticks: {
|
||||||
|
color: 'rgb(255,255,255)'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: {
|
||||||
|
ticks: {
|
||||||
|
color: 'rgb(255,255,255)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if ($isCategorizedExpense === true) {
|
||||||
|
chart.data.labels = generatedData.labels;
|
||||||
|
chart.data.datasets = generatedData.datasets;
|
||||||
|
} else {
|
||||||
|
generatedData.datasets = generatedData.datasets.filter(dataset => dataset.label !== $expenseCategoryLabel);
|
||||||
|
chart.data.labels = generatedData.labels;
|
||||||
|
chart.data.datasets = generatedData.datasets;
|
||||||
|
}
|
||||||
|
chart.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (isCategorizedExpense) {
|
||||||
|
const allDates = [...new Set([...$monthExpense, ...$categorizedExpense].map(item => item.date))];
|
||||||
|
const uniqueDates = allDates.sort((a, b) => new Date(a) - new Date(b));
|
||||||
|
|
||||||
|
const categorizedValues = uniqueDates.map(date => $categorizedExpense.filter(item => item.date === date).reduce((total, item) => total + item.amount, 0));
|
||||||
|
const expenseValues = uniqueDates.map(date => $monthExpense.filter(item => item.date === date).reduce((total, item) => total + item.amount, 0));
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: uniqueDates,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: $expenseCategoryLabel,
|
||||||
|
backgroundColor: "rgba(21, 194, 58, 0.4)",
|
||||||
|
borderColor: "rgba(21, 194, 58, 1)",
|
||||||
|
data: categorizedValues,
|
||||||
|
tension: 0.2,
|
||||||
|
fill: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Expense",
|
||||||
|
backgroundColor: "rgba(194, 21, 96, 0.4)",
|
||||||
|
borderColor: "rgba(194, 21, 96, 1)",
|
||||||
|
data: expenseValues,
|
||||||
|
tension: 0.4,
|
||||||
|
fill: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const tempData = generatedData.datasets.filter(dataset => dataset.label !== undefined);
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: generatedData.labels || [],
|
||||||
|
datasets: tempData
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const allDates = [...new Set([...$monthExpense].map(item => item.date))];
|
||||||
|
const uniqueDates = allDates.sort((a, b) => new Date(a) - new Date(b));
|
||||||
|
|
||||||
|
const expenseValues = uniqueDates.map(date => $monthExpense.filter(item => item.date === date).reduce((total, item) => total + item.amount, 0));
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: uniqueDates,
|
||||||
|
datasets:
|
||||||
|
{
|
||||||
|
label: "Expense",
|
||||||
|
backgroundColor: "rgba(194, 21, 96, 0.4)",
|
||||||
|
borderColor: "rgba(194, 21, 96, 1)",
|
||||||
|
data: expenseValues,
|
||||||
|
tension: 0.4,
|
||||||
|
fill: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const tempData = generatedData.datasets.filter(dataset => dataset.label !== undefined);
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: generatedData.labels || [],
|
||||||
|
datasets: tempData
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($monthIncome || $monthExpense || $isCategorizedExpense || $categorizedExpense) {
|
||||||
|
createGraph();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
createGraph();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="chart" style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<canvas id="canvas" bind:this={chartCanvas}></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#chart {
|
||||||
|
min-width: 0;
|
||||||
|
min-height:0;
|
||||||
|
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);
|
||||||
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
flex-grow: 2;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin: 0 10px 10px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chart:hover {
|
||||||
|
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#chart {
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,35 +1,30 @@
|
|||||||
<script>
|
<script>
|
||||||
import Modal from '../modals/Modal.svelte';
|
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { getCookie } from "svelte-cookie";
|
import { getCookie } from "svelte-cookie";
|
||||||
import {expenseTypes, expenseData} from "../../../stores.js";
|
import {expenseTypes, expenseData, dateText} from "../../../stores.js";
|
||||||
|
import { slide } from 'svelte/transition';
|
||||||
|
|
||||||
let showModal;
|
let showModal = false;
|
||||||
let amount = '';
|
let amount = '';
|
||||||
let newData;
|
let newData;
|
||||||
|
|
||||||
const selectedExpenseId = writable('');
|
const selectedExpenseId = writable('');
|
||||||
|
|
||||||
function addNewExpense(id, amount) {
|
function addNewExpense(expid, id, amount) {
|
||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date().toISOString().split('T')[0];
|
||||||
const expenseCategory = $expenseTypes.find(incomeType => incomeType.id === id);
|
const expenseCategory = $expenseTypes.find(incomeType => incomeType.id === id);
|
||||||
|
|
||||||
if (expenseCategory) {
|
if (expenseCategory) {
|
||||||
const newIncome = {
|
const newExpense = {
|
||||||
incomeId: 0,
|
expenseId: expid,
|
||||||
userDTO: {
|
|
||||||
name: "Dummy",
|
|
||||||
surname: "User",
|
|
||||||
username: "dummyuser"
|
|
||||||
},
|
|
||||||
expenseCategory: expenseCategory,
|
expenseCategory: expenseCategory,
|
||||||
date: today,
|
date: today,
|
||||||
amount: parseInt(amount)
|
amount: parseInt(amount)
|
||||||
};
|
};
|
||||||
|
|
||||||
newData = $expenseData;
|
newData = $expenseData;
|
||||||
newData.push(newIncome);
|
newData.push(newExpense);
|
||||||
$expenseData = newData;
|
$expenseData = newData;
|
||||||
} else {
|
} else {
|
||||||
console.error('Expense category not found for id:', id);
|
console.error('Expense category not found for id:', id);
|
||||||
@@ -37,18 +32,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createExpense = async () => {
|
const createExpense = async () => {
|
||||||
|
showModal = false;
|
||||||
const selectedExpense = $expenseTypes.find(expense => expense.id === $selectedExpenseId);
|
const selectedExpense = $expenseTypes.find(expense => expense.id === $selectedExpenseId);
|
||||||
const data = {
|
const data = {
|
||||||
expenseCategory: selectedExpense.id,
|
expenseCategory: selectedExpense.id,
|
||||||
amount: amount,
|
amount: parseInt(amount),
|
||||||
};
|
};
|
||||||
|
|
||||||
addNewExpense(selectedExpense.id, amount);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token = getCookie('access_token');
|
const token = getCookie('access_token');
|
||||||
|
|
||||||
const response = await axios.post('http://localhost:8081/expenses', data, {
|
const response = await axios.post('https://trackio.online:8081/expenses', data, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -56,7 +50,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.status === 201) {
|
if (response.status === 201) {
|
||||||
//console.log("cool");
|
addNewExpense(response.data.expenseId, selectedExpense.id, parseInt(amount));
|
||||||
} else {
|
} else {
|
||||||
console.error('Error:', response.status);
|
console.error('Error:', response.status);
|
||||||
}
|
}
|
||||||
@@ -64,17 +58,21 @@
|
|||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function toggleModal() {
|
||||||
|
showModal = !showModal;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="exp">
|
<div id="exp">
|
||||||
<div id="optionField">
|
<div id="optionField">
|
||||||
<h2>Expenses</h2>
|
<h2>Expenses: {$dateText}</h2>
|
||||||
<div id="openModal" class="plus-button" role="button" tabindex="0" on:click={() => (showModal = true)} on:keydown={() => console.log("keydown")}>
|
<div id="openModal" class="plus-button" role="button" tabindex="0" on:click={toggleModal} on:keydown={() => console.log("keydown")}>
|
||||||
+
|
+
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Modal bind:showModal>
|
{#if showModal}
|
||||||
<div class="expense-form">
|
<div class="expense-form" transition:slide>
|
||||||
<h3>Expense Details</h3>
|
<h3>Expense Details</h3>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="amount">Amount:</label>
|
<label for="amount">Amount:</label>
|
||||||
@@ -92,18 +90,48 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn btn-primary" on:click={createExpense}>Submit</button>
|
<div style="display: flex; justify-content: space-around">
|
||||||
|
<button class="btn btn-primary" on:click={createExpense}>SUBMIT</button>
|
||||||
|
<button class="btn btn-primary" on:click={() => showModal = false}>CANCEL</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#exp {
|
#exp {
|
||||||
padding: 20px;
|
padding: 10px 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
#optionField {
|
#optionField {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -131,7 +159,26 @@
|
|||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
margin: 0 auto;
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=text] {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
@@ -0,0 +1,712 @@
|
|||||||
|
<script>
|
||||||
|
import ContentExpense from "./ContentExpense.svelte";
|
||||||
|
import {
|
||||||
|
dateText,
|
||||||
|
expenseData,
|
||||||
|
expenseTypes,
|
||||||
|
incomeData,
|
||||||
|
tempExpense,
|
||||||
|
tempIncome,
|
||||||
|
monthIncome,
|
||||||
|
monthExpense,
|
||||||
|
isCategorizedExpense,
|
||||||
|
categorizedExpense,
|
||||||
|
expenseCategoryLabel,
|
||||||
|
currencyLabel, copyExpenseData, copyIncomeData, isCategorizedIncome
|
||||||
|
} from "../../../stores.js";
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
import {onMount} from "svelte";
|
||||||
|
import axios from "axios";
|
||||||
|
import {getCookie} from "svelte-cookie";
|
||||||
|
import {slide} from 'svelte/transition'
|
||||||
|
import EditEntry from "../util/EditEntry.svelte";
|
||||||
|
|
||||||
|
const textToIcon = {
|
||||||
|
'Groceries': "<svg fill=\"#299146\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M0 24C0 10.7 10.7 0 24 0H69.5c22 0 41.5 12.8 50.6 32h411c26.3 0 45.5 25 38.6 50.4l-41 152.3c-8.5 31.4-37 53.3-69.5 53.3H170.7l5.4 28.5c2.2 11.3 12.1 19.5 23.6 19.5H488c13.3 0 24 10.7 24 24s-10.7 24-24 24H199.7c-34.6 0-64.3-24.6-70.7-58.5L77.4 54.5c-.7-3.8-4-6.5-7.9-6.5H24C10.7 48 0 37.3 0 24zM128 464a48 48 0 1 1 96 0 48 48 0 1 1 -96 0zm336-48a48 48 0 1 1 0 96 48 48 0 1 1 0-96z\"/></svg>",
|
||||||
|
'Utilities': "<svg fill=\"#8f0611\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M176 88v40H336V88c0-4.4-3.6-8-8-8H184c-4.4 0-8 3.6-8 8zm-48 40V88c0-30.9 25.1-56 56-56H328c30.9 0 56 25.1 56 56v40h28.1c12.7 0 24.9 5.1 33.9 14.1l51.9 51.9c9 9 14.1 21.2 14.1 33.9V304H384V288c0-17.7-14.3-32-32-32s-32 14.3-32 32v16H192V288c0-17.7-14.3-32-32-32s-32 14.3-32 32v16H0V227.9c0-12.7 5.1-24.9 14.1-33.9l51.9-51.9c9-9 21.2-14.1 33.9-14.1H128zM0 416V336H128v16c0 17.7 14.3 32 32 32s32-14.3 32-32V336H320v16c0 17.7 14.3 32 32 32s32-14.3 32-32V336H512v80c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64z\"/></svg>",
|
||||||
|
'Rent': "<svg fill=\"#386907\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M575.8 255.5c0 18-15 32.1-32 32.1h-32l.7 160.2c0 2.7-.2 5.4-.5 8.1V472c0 22.1-17.9 40-40 40H456c-1.1 0-2.2 0-3.3-.1c-1.4 .1-2.8 .1-4.2 .1H416 392c-22.1 0-40-17.9-40-40V448 384c0-17.7-14.3-32-32-32H256c-17.7 0-32 14.3-32 32v64 24c0 22.1-17.9 40-40 40H160 128.1c-1.5 0-3-.1-4.5-.2c-1.2 .1-2.4 .2-3.6 .2H104c-22.1 0-40-17.9-40-40V360c0-.9 0-1.9 .1-2.8V287.6H32c-18 0-32-14-32-32.1c0-9 3-17 10-24L266.4 8c7-7 15-8 22-8s15 2 21 7L564.8 231.5c8 7 12 15 11 24z\"/></svg>",
|
||||||
|
'Transportation': "<svg fill=\"#027874\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M135.2 117.4L109.1 192H402.9l-26.1-74.6C372.3 104.6 360.2 96 346.6 96H165.4c-13.6 0-25.7 8.6-30.2 21.4zM39.6 196.8L74.8 96.3C88.3 57.8 124.6 32 165.4 32H346.6c40.8 0 77.1 25.8 90.6 64.3l35.2 100.5c23.2 9.6 39.6 32.5 39.6 59.2V400v48c0 17.7-14.3 32-32 32H448c-17.7 0-32-14.3-32-32V400H96v48c0 17.7-14.3 32-32 32H32c-17.7 0-32-14.3-32-32V400 256c0-26.7 16.4-49.6 39.6-59.2zM128 288a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zm288 32a32 32 0 1 0 0-64 32 32 0 1 0 0 64z\"/></svg>",
|
||||||
|
'Education': "<svg fill=\"#091094\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"20\" viewBox=\"0 0 640 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M337.8 5.4C327-1.8 313-1.8 302.2 5.4L166.3 96H48C21.5 96 0 117.5 0 144V464c0 26.5 21.5 48 48 48H256V416c0-35.3 28.7-64 64-64s64 28.7 64 64v96H592c26.5 0 48-21.5 48-48V144c0-26.5-21.5-48-48-48H473.7L337.8 5.4zM96 192h32c8.8 0 16 7.2 16 16v64c0 8.8-7.2 16-16 16H96c-8.8 0-16-7.2-16-16V208c0-8.8 7.2-16 16-16zm400 16c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v64c0 8.8-7.2 16-16 16H512c-8.8 0-16-7.2-16-16V208zM96 320h32c8.8 0 16 7.2 16 16v64c0 8.8-7.2 16-16 16H96c-8.8 0-16-7.2-16-16V336c0-8.8 7.2-16 16-16zm400 16c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v64c0 8.8-7.2 16-16 16H512c-8.8 0-16-7.2-16-16V336zM232 176a88 88 0 1 1 176 0 88 88 0 1 1 -176 0zm88-48c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16s-7.2-16-16-16H336V144c0-8.8-7.2-16-16-16z\"/></svg>",
|
||||||
|
'Restaurants & Cafes': "<svg fill=\"#961115\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M0 192c0-35.3 28.7-64 64-64c.5 0 1.1 0 1.6 0C73 91.5 105.3 64 144 64c15 0 29 4.1 40.9 11.2C198.2 49.6 225.1 32 256 32s57.8 17.6 71.1 43.2C339 68.1 353 64 368 64c38.7 0 71 27.5 78.4 64c.5 0 1.1 0 1.6 0c35.3 0 64 28.7 64 64c0 11.7-3.1 22.6-8.6 32H8.6C3.1 214.6 0 203.7 0 192zm0 91.4C0 268.3 12.3 256 27.4 256H484.6c15.1 0 27.4 12.3 27.4 27.4c0 70.5-44.4 130.7-106.7 154.1L403.5 452c-2 16-15.6 28-31.8 28H140.2c-16.1 0-29.8-12-31.8-28l-1.8-14.4C44.4 414.1 0 353.9 0 283.4z\"/></svg>",
|
||||||
|
'Home Maintenance': "<svg fill=\"#386907\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M575.8 255.5c0 18-15 32.1-32 32.1h-32l.7 160.2c0 2.7-.2 5.4-.5 8.1V472c0 22.1-17.9 40-40 40H456c-1.1 0-2.2 0-3.3-.1c-1.4 .1-2.8 .1-4.2 .1H416 392c-22.1 0-40-17.9-40-40V448 384c0-17.7-14.3-32-32-32H256c-17.7 0-32 14.3-32 32v64 24c0 22.1-17.9 40-40 40H160 128.1c-1.5 0-3-.1-4.5-.2c-1.2 .1-2.4 .2-3.6 .2H104c-22.1 0-40-17.9-40-40V360c0-.9 0-1.9 .1-2.8V287.6H32c-18 0-32-14-32-32.1c0-9 3-17 10-24L266.4 8c7-7 15-8 22-8s15 2 21 7L564.8 231.5c8 7 12 15 11 24z\"/></svg>",
|
||||||
|
'Transport': "<svg fill=\"#027874\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M135.2 117.4L109.1 192H402.9l-26.1-74.6C372.3 104.6 360.2 96 346.6 96H165.4c-13.6 0-25.7 8.6-30.2 21.4zM39.6 196.8L74.8 96.3C88.3 57.8 124.6 32 165.4 32H346.6c40.8 0 77.1 25.8 90.6 64.3l35.2 100.5c23.2 9.6 39.6 32.5 39.6 59.2V400v48c0 17.7-14.3 32-32 32H448c-17.7 0-32-14.3-32-32V400H96v48c0 17.7-14.3 32-32 32H32c-17.7 0-32-14.3-32-32V400 256c0-26.7 16.4-49.6 39.6-59.2zM128 288a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zm288 32a32 32 0 1 0 0-64 32 32 0 1 0 0 64z\"/></svg>",
|
||||||
|
'Shopping': "<svg fill=\"#2b26ad\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M0 24C0 10.7 10.7 0 24 0H69.5c22 0 41.5 12.8 50.6 32h411c26.3 0 45.5 25 38.6 50.4l-41 152.3c-8.5 31.4-37 53.3-69.5 53.3H170.7l5.4 28.5c2.2 11.3 12.1 19.5 23.6 19.5H488c13.3 0 24 10.7 24 24s-10.7 24-24 24H199.7c-34.6 0-64.3-24.6-70.7-58.5L77.4 54.5c-.7-3.8-4-6.5-7.9-6.5H24C10.7 48 0 37.3 0 24zM128 464a48 48 0 1 1 96 0 48 48 0 1 1 -96 0zm336-48a48 48 0 1 1 0 96 48 48 0 1 1 0-96z\"/></svg>",
|
||||||
|
'Miscellaneous': "<svg fill=\"#299146\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M403.8 34.4c12-5 25.7-2.2 34.9 6.9l64 64c6 6 9.4 14.1 9.4 22.6s-3.4 16.6-9.4 22.6l-64 64c-9.2 9.2-22.9 11.9-34.9 6.9s-19.8-16.6-19.8-29.6V160H352c-10.1 0-19.6 4.7-25.6 12.8L284 229.3 244 176l31.2-41.6C293.3 110.2 321.8 96 352 96h32V64c0-12.9 7.8-24.6 19.8-29.6zM164 282.7L204 336l-31.2 41.6C154.7 401.8 126.2 416 96 416H32c-17.7 0-32-14.3-32-32s14.3-32 32-32H96c10.1 0 19.6-4.7 25.6-12.8L164 282.7zm274.6 188c-9.2 9.2-22.9 11.9-34.9 6.9s-19.8-16.6-19.8-29.6V416H352c-30.2 0-58.7-14.2-76.8-38.4L121.6 172.8c-6-8.1-15.5-12.8-25.6-12.8H32c-17.7 0-32-14.3-32-32s14.3-32 32-32H96c30.2 0 58.7 14.2 76.8 38.4L326.4 339.2c6 8.1 15.5 12.8 25.6 12.8h32V320c0-12.9 7.8-24.6 19.8-29.6s25.7-2.2 34.9 6.9l64 64c6 6 9.4 14.1 9.4 22.6s-3.4 16.6-9.4 22.6l-64 64z\"/></svg>",
|
||||||
|
'Charity': "<svg fill=\"#961189\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M163.9 136.9c-29.4-29.8-29.4-78.2 0-108s77-29.8 106.4 0l17.7 18 17.7-18c29.4-29.8 77-29.8 106.4 0s29.4 78.2 0 108L310.5 240.1c-6.2 6.3-14.3 9.4-22.5 9.4s-16.3-3.1-22.5-9.4L163.9 136.9zM568.2 336.3c13.1 17.8 9.3 42.8-8.5 55.9L433.1 485.5c-23.4 17.2-51.6 26.5-80.7 26.5H192 32c-17.7 0-32-14.3-32-32V416c0-17.7 14.3-32 32-32H68.8l44.9-36c22.7-18.2 50.9-28 80-28H272h16 64c17.7 0 32 14.3 32 32s-14.3 32-32 32H288 272c-8.8 0-16 7.2-16 16s7.2 16 16 16H392.6l119.7-88.2c17.8-13.1 42.8-9.3 55.9 8.5zM193.6 384l0 0-.9 0c.3 0 .6 0 .9 0z\"/></svg>",
|
||||||
|
'Legal Services': "<svg fill=\"#916129\" xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M318.6 9.4c-12.5-12.5-32.8-12.5-45.3 0l-120 120c-12.5 12.5-12.5 32.8 0 45.3l16 16c12.5 12.5 32.8 12.5 45.3 0l4-4L325.4 293.4l-4 4c-12.5 12.5-12.5 32.8 0 45.3l16 16c12.5 12.5 32.8 12.5 45.3 0l120-120c12.5-12.5 12.5-32.8 0-45.3l-16-16c-12.5-12.5-32.8-12.5-45.3 0l-4 4L330.6 74.6l4-4c12.5-12.5 12.5-32.8 0-45.3l-16-16zm-152 288c-12.5-12.5-32.8-12.5-45.3 0l-112 112c-12.5 12.5-12.5 32.8 0 45.3l48 48c12.5 12.5 32.8 12.5 45.3 0l112-112c12.5-12.5 12.5-32.8 0-45.3l-1.4-1.4L272 285.3 226.7 240 168 298.7l-1.4-1.4z\"/></svg>"
|
||||||
|
};
|
||||||
|
|
||||||
|
let isDateDropdownExpanded = false
|
||||||
|
let isCategoryDropdownExpanded = false
|
||||||
|
let isCurrencyDropdownExpanded = false
|
||||||
|
let isFilterDown = false;
|
||||||
|
|
||||||
|
let dropdownStates = {};
|
||||||
|
let deleteDropdownStates = {}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
dropdownStates = {};
|
||||||
|
deleteDropdownStates = {};
|
||||||
|
$expenseData.toReversed().forEach(data => {
|
||||||
|
dropdownStates[data.expenseId] = false;
|
||||||
|
deleteDropdownStates[data.expenseId] = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickFilter() {
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
isFilterDown = !isFilterDown;
|
||||||
|
isCurrencyDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
function clickHandlerDate() {
|
||||||
|
isDateDropdownExpanded = !isDateDropdownExpanded
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickHandlerCategory() {
|
||||||
|
isCategoryDropdownExpanded = !isCategoryDropdownExpanded;
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickHandlerCurrency() {
|
||||||
|
isCurrencyDropdownExpanded = !isCurrencyDropdownExpanded;
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
isFilterDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickItemHandler(id) {
|
||||||
|
dropdownStates[id] = !dropdownStates[id];
|
||||||
|
if (deleteDropdownStates[id] === true) deleteDropdownStates[id] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickDeleteHandler(id) {
|
||||||
|
deleteDropdownStates[id] = !deleteDropdownStates[id];
|
||||||
|
if (dropdownStates[id] === true) dropdownStates[id] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickOutsideHandler(event) {
|
||||||
|
const isDateButton = event.target.closest("#expenseInfo");
|
||||||
|
|
||||||
|
if (!isDateButton) {
|
||||||
|
isFilterDown = false;
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
isCurrencyDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
document.body.addEventListener("click", clickOutsideHandler);
|
||||||
|
return () => {
|
||||||
|
document.body.removeEventListener("click", clickOutsideHandler);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getToday() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const currentDay = currentDate.toISOString().split('T')[0];
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?date=' + currentDay, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?date=' + currentDay, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response1.data);
|
||||||
|
$dateText = "Today"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getYesterday() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
|
||||||
|
const yesterday = new Date(currentDate);
|
||||||
|
yesterday.setDate(currentDate.getDate() - 1);
|
||||||
|
|
||||||
|
const yesterdayString = yesterday.toISOString().split('T')[0];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?date=' + yesterdayString, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?date=' + yesterdayString, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "Yesterday"
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getMonth() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const year = currentDate.getMonth() + 1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
monthExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
monthIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "This Month"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLastMonth() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const year = currentDate.getMonth();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data)
|
||||||
|
monthExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
monthIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "Last Month"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLastYear() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const year = currentDate.getFullYear();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?year=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
monthExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?year=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
monthIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "This Year"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterByCategory(category) {
|
||||||
|
$isCategorizedExpense = true;
|
||||||
|
$expenseCategoryLabel = category;
|
||||||
|
console.log($isCategorizedExpense);
|
||||||
|
let tempArr = $tempExpense.filter(expense => expense.expenseCategory.name === category);
|
||||||
|
categorizedExpense.set(tempArr);
|
||||||
|
expenseData.set(tempArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAll() {
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
$expenseCategoryLabel = "Category";
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
console.log($isCategorizedExpense);
|
||||||
|
expenseData.set($tempExpense);
|
||||||
|
}
|
||||||
|
|
||||||
|
function doNothing() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeCurrency(currency) {
|
||||||
|
if (currency === 'USD') {
|
||||||
|
expenseData.set($copyExpenseData);
|
||||||
|
incomeData.set($copyIncomeData);
|
||||||
|
$currencyLabel = "USD";
|
||||||
|
}
|
||||||
|
if (currency === 'MDL') {
|
||||||
|
const tempData1 = $copyExpenseData.map(expense => ({
|
||||||
|
...expense,
|
||||||
|
amount: expense.amount / 0.056
|
||||||
|
}));
|
||||||
|
expenseData.set(tempData1);
|
||||||
|
|
||||||
|
const tempData2 = $copyIncomeData.map(income => ({
|
||||||
|
...income,
|
||||||
|
amount: income.amount / 0.056
|
||||||
|
}));
|
||||||
|
incomeData.set(tempData2);
|
||||||
|
$currencyLabel = "MDL";
|
||||||
|
}
|
||||||
|
if (currency === 'EUR') {
|
||||||
|
const tempData1 = $copyExpenseData.map(expense => ({
|
||||||
|
...expense,
|
||||||
|
amount: expense.amount / 1.08
|
||||||
|
}));
|
||||||
|
expenseData.set(tempData1);
|
||||||
|
|
||||||
|
const tempData2 = $copyIncomeData.map(income => ({
|
||||||
|
...income,
|
||||||
|
amount: income.amount / 1.08
|
||||||
|
}));
|
||||||
|
incomeData.set(tempData2);
|
||||||
|
$currencyLabel = "EUR";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currency === 'GBP') {
|
||||||
|
const tempData1 = $copyExpenseData.map(expense => ({
|
||||||
|
...expense,
|
||||||
|
amount: expense.amount / 1.26
|
||||||
|
}));
|
||||||
|
expenseData.set(tempData1);
|
||||||
|
|
||||||
|
const tempData2 = $copyIncomeData.map(income => ({
|
||||||
|
...income,
|
||||||
|
amount: income.amount / 1.26
|
||||||
|
}));
|
||||||
|
incomeData.set(tempData2);
|
||||||
|
$currencyLabel = "GBP";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="expenseInfo" style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<ContentExpense />
|
||||||
|
<div style="display: flex; justify-content: space-around">
|
||||||
|
|
||||||
|
<div id="dropdown" style="margin: 10px; display: flex; justify-content: space-between">
|
||||||
|
<button id="btn1" class="button" on:click={clickFilter}>Filter ▼</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="dropdown-currency" style="margin: 10px;">
|
||||||
|
<button id="btn2" class="button" on:click={clickHandlerCurrency}>Currency ▼</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#if isFilterDown}
|
||||||
|
<div style="margin: 10px; display: flex; justify-content: space-between" transition:slide>
|
||||||
|
<div id="dropdown-date" style="margin: 10px;">
|
||||||
|
<button id="btn3" class="button" on:click={clickHandlerDate}>Filter by Date ▼</button></div>
|
||||||
|
|
||||||
|
<div id="dropdown-category" style="margin: 10px;">
|
||||||
|
<button id="btn4" class="button" on:click={clickHandlerCategory}>Filter by Category ▼</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if isDateDropdownExpanded}
|
||||||
|
<div id="date-list" transition:slide>
|
||||||
|
<div class="date-entry" on:click={() => getToday()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>Today
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getYesterday()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>Yesterday
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getMonth()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>This month
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getLastMonth()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>Last month
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getLastYear()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>This year
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if isCategoryDropdownExpanded}
|
||||||
|
<div id="date-list" transition:slide>
|
||||||
|
<div class="date-entry" on:click={() => getAll()} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>All</div>
|
||||||
|
{#each $expenseTypes as expense (expense.id)}
|
||||||
|
{#if expense.id !== undefined}
|
||||||
|
<div class="date-entry" on:click={() => filterByCategory(expense.name)} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>{expense.name}</div>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if isCurrencyDropdownExpanded}
|
||||||
|
<div id="date-list" transition:slide>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("MDL")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>MDL Leu</div>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("GBP")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>GBP Pound</div>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("USD")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>USD Dollar</div>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("EUR")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>EUR Euro</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div id="listContainer" style="color: {$globalStyles.color}">
|
||||||
|
<ul>
|
||||||
|
{#each $expenseData.toReversed() as item (item.expenseId)}
|
||||||
|
<li style="display:flex; flex-direction: column; justify-content: space-between; color: {$globalStyles.color}">
|
||||||
|
<div style="display:flex; flex-direction: row; justify-content: space-between; align-items: center;">
|
||||||
|
<div>
|
||||||
|
{#if textToIcon[item.expenseCategory.name]}
|
||||||
|
{@html textToIcon[item.expenseCategory.name]}
|
||||||
|
{/if}
|
||||||
|
<span style="font-weight: bold">{item.incomeCategory ? `${item.incomeCategory.name}: ` : `${item.expenseCategory.name}: `}</span>
|
||||||
|
<span style="font-weight:bold; margin-right: 10px; color: red; font-size: larger">{item.incomeCategory ? `+${item.amount.toFixed(2)} ${$currencyLabel}` : `-${item.amount.toFixed(2)} ${$currencyLabel}`}</span>
|
||||||
|
</div>
|
||||||
|
<div style="margin-right: 5px; display: flex; flex-direction: row">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{`${item.date}`}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="editBtnDiv" role="button" tabindex="0" on:keydown={doNothing}
|
||||||
|
on:click={() => clickItemHandler(item.expenseId)}>
|
||||||
|
<span id="editBtn"><svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512"><path
|
||||||
|
d="M471.6 21.7c-21.9-21.9-57.3-21.9-79.2 0L362.3 51.7l97.9 97.9 30.1-30.1c21.9-21.9 21.9-57.3 0-79.2L471.6 21.7zm-299.2 220c-6.1 6.1-10.8 13.6-13.5 21.9l-29.6 88.8c-2.9 8.6-.6 18.1 5.8 24.6s15.9 8.7 24.6 5.8l88.8-29.6c8.2-2.7 15.7-7.4 21.9-13.5L437.7 172.3 339.7 74.3 172.4 241.7zM96 64C43 64 0 107 0 160V416c0 53 43 96 96 96H352c53 0 96-43 96-96V320c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7-14.3 32-32 32H96c-17.7 0-32-14.3-32-32V160c0-17.7 14.3-32 32-32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H96z"/></svg></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="deleteBtnDiv" role="button" tabindex="0" on:keydown={doNothing}
|
||||||
|
on:click={() => clickDeleteHandler(item.expenseId)}>
|
||||||
|
<span id="deleteBtn"><svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><path
|
||||||
|
d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if dropdownStates[item.expenseId]}
|
||||||
|
<EditEntry {item} bind:isOn={dropdownStates[item.expenseId]}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if deleteDropdownStates[item.expenseId]}
|
||||||
|
<div style="padding: 5px; margin-top: 5px; display:flex; flex-direction: column; justify-content: space-evenly"
|
||||||
|
class="inputForm" transition:slide>
|
||||||
|
<span id="textf" style="text-align: center; margin-bottom: 10px">Confirm deletion?</span>
|
||||||
|
<div style="display:flex; flex-direction: row; justify-content: space-evenly">
|
||||||
|
<button id="confirmBtn">CONFIRM</button>
|
||||||
|
<button id="cancelBtn">CANCEL</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- <button style="background-color: #8BD17C" on:click={() => console.log("LOL")}>Delete</button>-->
|
||||||
|
<!-- <button style="background-color: palevioletred" on:click={clickItemHandler(item.expenseId)}>Cancel</button>-->
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#textf {
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
#confirmBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#confirmBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#listContainer {
|
||||||
|
max-height: 50vh;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#expenseInfo {
|
||||||
|
margin: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#editBtn {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 5px;
|
||||||
|
fill: darkblue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inputForm {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editBtn:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
fill: lightseagreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
#deleteBtn {
|
||||||
|
fill: red;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#deleteBtn:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
fill: palevioletred;
|
||||||
|
}
|
||||||
|
|
||||||
|
#expenseInfo {
|
||||||
|
min-width: 350px;
|
||||||
|
min-height: 0;
|
||||||
|
background-color: #212942;
|
||||||
|
color: white;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: #f1f1f1;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: #888;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
align-items: center;
|
||||||
|
background-color: #0A66C2;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 100px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #ffffff;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-flex;
|
||||||
|
font-family: -apple-system, system-ui, system-ui, "Segoe UI", Roboto, "Helvetica Neue", "Fira Sans", Ubuntu, Oxygen, "Oxygen Sans", Cantarell, "Droid Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Lucida Grande", Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
justify-content: center;
|
||||||
|
line-height: 20px;
|
||||||
|
max-width: 480px;
|
||||||
|
min-height: 40px;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 0 20px;
|
||||||
|
text-align: center;
|
||||||
|
touch-action: manipulation;
|
||||||
|
transition: background-color 0.167s cubic-bezier(0.4, 0, 0.2, 1) 0s, box-shadow 0.167s cubic-bezier(0.4, 0, 0.2, 1) 0s, color 0.167s cubic-bezier(0.4, 0, 0.2, 1) 0s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover,
|
||||||
|
.button:focus {
|
||||||
|
background-color: #16437E;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:active {
|
||||||
|
background: #09223b;
|
||||||
|
color: rgb(255, 255, 255, .7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
background: rgba(0, 0, 0, .08);
|
||||||
|
color: rgba(0, 0, 0, .3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#date-list {
|
||||||
|
background-color: black;
|
||||||
|
margin: 0 20px 20px;
|
||||||
|
max-height: 400px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-entry {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .3s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-entry:hover {
|
||||||
|
box-shadow: rgba(255, 255, 255, 0.8) 0 0 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<script>
|
||||||
|
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="header">
|
||||||
|
<div id="dashboardTitleWrapper" style="color: white">
|
||||||
|
<h1 id="dashboardTitle">Dashboard - Expenses</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="icons">
|
||||||
|
<div class="headerbtn searchButton">
|
||||||
|
<svg style="fill: white" 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 style="fill: white" 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 20px 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,140 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { incomeData, expenseData, currencyLabel } from "../../../stores.js";
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
|
||||||
|
let infobar1, infobar2, infobar3, infobar4;
|
||||||
|
let totalExpenses = 0;
|
||||||
|
let totalIncomes = 0;
|
||||||
|
let lastMonthIncome = 800;
|
||||||
|
let lastMonthExpense = 200;
|
||||||
|
let incomeDifference;
|
||||||
|
let expenseDifference;
|
||||||
|
|
||||||
|
function updateInfo() {
|
||||||
|
totalExpenses = $expenseData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||||
|
totalIncomes = $incomeData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||||
|
|
||||||
|
incomeDifference = ((totalIncomes - lastMonthIncome) / lastMonthIncome) * 100;
|
||||||
|
expenseDifference = ((lastMonthExpense - totalExpenses) / lastMonthExpense) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($currencyLabel) {
|
||||||
|
if ($currencyLabel === 'USD') {
|
||||||
|
lastMonthIncome = 800;
|
||||||
|
lastMonthExpense = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currencyLabel === 'MDL') {
|
||||||
|
lastMonthIncome = 800 / 0.056;
|
||||||
|
lastMonthExpense = 200 / 0.056;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currencyLabel === 'EUR') {
|
||||||
|
lastMonthIncome = 800 / 1.08;
|
||||||
|
lastMonthExpense = 200 / 1.08;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currencyLabel === 'GBP') {
|
||||||
|
lastMonthIncome = 800 / 1.26;
|
||||||
|
lastMonthExpense = 200 / 1.26;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($incomeData || $expenseData) {
|
||||||
|
updateInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
updateInfo();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="quickInfobar">
|
||||||
|
<div class="firstTwo">
|
||||||
|
<div class="infobarElement" bind:this={infobar1} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Total expenses:</span><br><span class="dataSpan" style="color:#ab1a3c">{totalExpenses.toFixed(2)} {$currencyLabel}</span>
|
||||||
|
</div>
|
||||||
|
<div class="infobarElement" bind:this={infobar2} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Total incomes:</span><br><span class="dataSpan" style="color:#38cc1b">{totalIncomes.toFixed(2)} {$currencyLabel}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="secondTwo">
|
||||||
|
<div class="infobarElement" bind:this={infobar3} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Income by last month:</span><br><span class="dataSpan" style="color:#2763db">{incomeDifference.toFixed(2)}%</span>
|
||||||
|
</div>
|
||||||
|
<div class="infobarElement" bind:this={infobar4} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Expense by last month:</span><br><span class="dataSpan" style="color:#dba527">{expenseDifference.toFixed(2)}%</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
.firstTwo {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondTwo {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.infobarSpan {
|
||||||
|
font-size: larger;
|
||||||
|
color: #00FEFC
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataSpan {
|
||||||
|
color:#ab1a3c;
|
||||||
|
font-size: xxx-large;
|
||||||
|
}
|
||||||
|
|
||||||
|
#quickInfobar {
|
||||||
|
/*display: flex;*/
|
||||||
|
/*justify-content: space-between;*/
|
||||||
|
/*flex-wrap: wrap;*/
|
||||||
|
min-height: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (min-width: 768px) and (max-width: 1200px) {
|
||||||
|
.infobarSpan {
|
||||||
|
font-size: medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataSpan {
|
||||||
|
font-size: large;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.infobarElement {
|
||||||
|
font-family: Inconsolata,"Source Sans Pro",sans-serif;
|
||||||
|
font-size: larger;
|
||||||
|
margin: 10px;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
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>
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<script>
|
||||||
|
import {expenseTypes} from "../../../stores.js";
|
||||||
|
import { slide } from 'svelte/transition'
|
||||||
|
export let item;
|
||||||
|
export let isOn;
|
||||||
|
|
||||||
|
function handleSave() {
|
||||||
|
const amount = document.getElementById('amountInput').value;
|
||||||
|
const expenseCategory = document.getElementById('expenseCategory').value;
|
||||||
|
|
||||||
|
console.log("tryna save: " + item.expenseId + " " + amount + " " + expenseCategory)
|
||||||
|
// saveFunction(item.expenseId, amount, expenseCategory);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div style="display: flex; flex-direction: column" transition:slide>
|
||||||
|
<span id="textf" style="margin-top: 10px; text-align: center">Edit Entry</span>
|
||||||
|
<input type="text" id="amountInput" bind:value={item.amount}>
|
||||||
|
<select id="expenseCategory" class="form-control">
|
||||||
|
{#each $expenseTypes as expense (expense.id)}
|
||||||
|
{#if expense.id !== undefined}
|
||||||
|
{#if expense.id === item.expenseCategory.id}
|
||||||
|
<option value={expense.id} selected>{expense.name}</option>
|
||||||
|
{:else}
|
||||||
|
<option value={expense.id}>{expense.name}</option>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
<div style="margin: 10px; display:flex; flex-direction: row; justify-content: space-evenly">
|
||||||
|
<button class="buttonCL" id="saveBtn" on:click={handleSave}>SAVE</button>
|
||||||
|
<button class="buttonCL" id="cancelBtn" on:click={() => isOn = false}>CANCEL</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#textf {
|
||||||
|
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=text] {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#saveBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#saveBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
<script>
|
|
||||||
import Chart from 'chart.js/auto';
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import { incomeData } from "../../stores.js";
|
|
||||||
|
|
||||||
let ctx;
|
|
||||||
let chartCanvas;
|
|
||||||
let chart = null;
|
|
||||||
|
|
||||||
function groupAndSumByCategory() {
|
|
||||||
const groupedData = new Map();
|
|
||||||
$incomeData.forEach(income => {
|
|
||||||
const category = income.incomeCategory.name;
|
|
||||||
if (groupedData.has(category)) {
|
|
||||||
groupedData.set(category, groupedData.get(category) + parseInt(income.amount));
|
|
||||||
} else {
|
|
||||||
groupedData.set(category, income.amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return groupedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createGraph() {
|
|
||||||
try {
|
|
||||||
const groupedIncomeData = groupAndSumByCategory();
|
|
||||||
|
|
||||||
const chartLabels = Array.from(groupedIncomeData.keys());
|
|
||||||
const chartValues = Array.from(groupedIncomeData.values());
|
|
||||||
|
|
||||||
ctx = chartCanvas.getContext('2d');
|
|
||||||
|
|
||||||
if (!chart) {
|
|
||||||
chart = new Chart(ctx, {
|
|
||||||
type: 'bar',
|
|
||||||
data: {
|
|
||||||
labels: chartLabels,
|
|
||||||
datasets: [{
|
|
||||||
label: 'Revenue',
|
|
||||||
backgroundColor:
|
|
||||||
['rgb(0, 0, 179)',
|
|
||||||
'rgb(0, 16, 217)',
|
|
||||||
'rgb(0, 32, 255)',
|
|
||||||
'rgb(0, 64, 255)',
|
|
||||||
'rgb(0, 96, 255)',
|
|
||||||
'rgb(0, 128, 255)',
|
|
||||||
'rgb(0, 159, 255)',
|
|
||||||
'rgb(0, 191, 255)',
|
|
||||||
'rgb(0, 255, 255)'],
|
|
||||||
data: chartValues
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
maintainAspectRatio: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
chart.data.labels = chartLabels;
|
|
||||||
chart.data.datasets[0].data = chartValues;
|
|
||||||
chart.update();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$: {
|
|
||||||
if ($incomeData) {
|
|
||||||
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,93 +0,0 @@
|
|||||||
<script>
|
|
||||||
import Chart from 'chart.js/auto';
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import { expenseData } from "../../stores.js";
|
|
||||||
|
|
||||||
let ctx;
|
|
||||||
let chartCanvas;
|
|
||||||
let chart = null;
|
|
||||||
|
|
||||||
function groupAndSumByCategory() {
|
|
||||||
const groupedData = new Map();
|
|
||||||
console.log($expenseData)
|
|
||||||
$expenseData.forEach(expense => {
|
|
||||||
const category = expense.expenseCategory.name;
|
|
||||||
if (groupedData.has(category)) {
|
|
||||||
groupedData.set(category, groupedData.get(category) + parseInt(expense.amount));
|
|
||||||
} else {
|
|
||||||
groupedData.set(category, expense.amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return groupedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createGraph() {
|
|
||||||
try {
|
|
||||||
const groupedExpenseData = groupAndSumByCategory();
|
|
||||||
|
|
||||||
const chartLabels = Array.from(groupedExpenseData.keys());
|
|
||||||
const chartValues = Array.from(groupedExpenseData.values());
|
|
||||||
|
|
||||||
ctx = chartCanvas.getContext('2d');
|
|
||||||
|
|
||||||
if (!chart) {
|
|
||||||
chart = new Chart(ctx, {
|
|
||||||
type: 'bar',
|
|
||||||
data: {
|
|
||||||
labels: chartLabels,
|
|
||||||
datasets: [{
|
|
||||||
label: 'Spendings',
|
|
||||||
backgroundColor: [
|
|
||||||
'rgb(107, 80, 107)',
|
|
||||||
'rgb(171, 61, 169)',
|
|
||||||
'rgb(222, 37, 218)',
|
|
||||||
'rgb(235, 68, 232)',
|
|
||||||
'rgb(255, 128, 255)'],
|
|
||||||
data: chartValues
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
maintainAspectRatio: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
chart.data.labels = chartLabels;
|
|
||||||
chart.data.datasets[0].data = chartValues;
|
|
||||||
chart.update();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$: {
|
|
||||||
if ($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,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>
|
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto';
|
||||||
|
import {onMount} from 'svelte';
|
||||||
|
import {monthIncome} from "../../../stores.js";
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
|
||||||
|
let ctx;
|
||||||
|
let chartCanvas;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
function groupAndSumByCategory() {
|
||||||
|
const groupedData = new Map();
|
||||||
|
$monthIncome.forEach(income => {
|
||||||
|
const category = income.incomeCategory.name;
|
||||||
|
if (groupedData.has(category)) {
|
||||||
|
groupedData.set(category, groupedData.get(category) + parseInt(income.amount));
|
||||||
|
} else {
|
||||||
|
groupedData.set(category, parseInt(income.amount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Map([...groupedData.entries()].sort());
|
||||||
|
}
|
||||||
|
|
||||||
|
function createGraph() {
|
||||||
|
try {
|
||||||
|
const groupedIncomeData = groupAndSumByCategory();
|
||||||
|
|
||||||
|
const chartLabels = [];
|
||||||
|
const chartValues = [];
|
||||||
|
|
||||||
|
for (const [label, value] of groupedIncomeData.entries()) {
|
||||||
|
chartLabels.push(label);
|
||||||
|
chartValues.push(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = chartCanvas.getContext('2d');
|
||||||
|
|
||||||
|
if (!chart) {
|
||||||
|
chart = new Chart(ctx, {
|
||||||
|
type: 'doughnut',
|
||||||
|
data: {
|
||||||
|
labels: chartLabels,
|
||||||
|
datasets: [{
|
||||||
|
label: 'Incomes',
|
||||||
|
data: chartValues
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
backgroundColor: [
|
||||||
|
'rgb(255, 140, 140)',
|
||||||
|
'rgb(140, 180, 255)',
|
||||||
|
'rgb(255, 200, 140)',
|
||||||
|
'rgb(160, 200, 160)',
|
||||||
|
'rgb(160, 130, 200)',
|
||||||
|
'rgb(255, 160, 140)',
|
||||||
|
'rgb(140, 180, 255)',
|
||||||
|
'rgb(160, 255, 160)',
|
||||||
|
'rgb(255, 140, 120)',
|
||||||
|
'rgb(160, 140, 200)',
|
||||||
|
'rgb(255, 220, 140)',
|
||||||
|
'rgb(140, 255, 255)',
|
||||||
|
'rgb(255, 160, 140)',
|
||||||
|
'rgb(160, 255, 160)',
|
||||||
|
'rgb(160, 160, 255)'
|
||||||
|
],
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
position: 'bottom',
|
||||||
|
align: 'start',
|
||||||
|
fullWidth: false,
|
||||||
|
labels: {
|
||||||
|
font: {
|
||||||
|
weight: 'bold'
|
||||||
|
},
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
chart.data.labels = chartLabels;
|
||||||
|
chart.data.datasets[0].data = chartValues;
|
||||||
|
chart.update();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($monthIncome) {
|
||||||
|
createGraph();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
createGraph();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="chart" style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<canvas bind:this={chartCanvas}></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#chart {
|
||||||
|
min-width: 0;
|
||||||
|
min-height:0;
|
||||||
|
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);
|
||||||
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
flex-grow: 1;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin: 0 10px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chart:hover {
|
||||||
|
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#chart {
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
<script>
|
||||||
|
import Chart from 'chart.js/auto';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import {monthIncome, monthExpense, isCategorizedIncome, categorizedIncome, incomeCategoryLabel} from "../../../stores.js";
|
||||||
|
import { globalStyles } from "../../../styles.js";
|
||||||
|
|
||||||
|
let ctx;
|
||||||
|
let chartCanvas;
|
||||||
|
let chart = null;
|
||||||
|
|
||||||
|
let generatedData;
|
||||||
|
|
||||||
|
function createGraph() {
|
||||||
|
try {
|
||||||
|
if (chartCanvas.getContext('2d') !== undefined) {
|
||||||
|
ctx = chartCanvas.getContext('2d');
|
||||||
|
if (!chart) {
|
||||||
|
chart = new Chart(ctx, {
|
||||||
|
type: 'line',
|
||||||
|
data: generatedData,
|
||||||
|
options: {
|
||||||
|
scales: {
|
||||||
|
y: {
|
||||||
|
ticks: {
|
||||||
|
color: 'rgb(255,255,255)'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: {
|
||||||
|
ticks: {
|
||||||
|
color: 'rgb(255,255,255)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if ($isCategorizedIncome === true) {
|
||||||
|
chart.data.labels = generatedData.labels;
|
||||||
|
chart.data.datasets = generatedData.datasets;
|
||||||
|
} else {
|
||||||
|
generatedData.datasets = generatedData.datasets.filter(dataset => dataset.label !== $incomeCategoryLabel);
|
||||||
|
chart.data.labels = generatedData.labels;
|
||||||
|
chart.data.datasets = generatedData.datasets;
|
||||||
|
}
|
||||||
|
chart.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (isCategorizedIncome) {
|
||||||
|
const allDates = [...new Set([...$monthIncome, ...$categorizedIncome].map(item => item.date))];
|
||||||
|
const uniqueDates = allDates.sort((a, b) => new Date(a) - new Date(b));
|
||||||
|
|
||||||
|
const categorizedValues = uniqueDates.map(date => $categorizedIncome.filter(item => item.date === date).reduce((total, item) => total + item.amount, 0));
|
||||||
|
const incomeValues = uniqueDates.map(date => $monthIncome.filter(item => item.date === date).reduce((total, item) => total + item.amount, 0));
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: uniqueDates,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: $incomeCategoryLabel,
|
||||||
|
backgroundColor: "rgba(21, 194, 58, 0.4)",
|
||||||
|
borderColor: "rgba(21, 194, 58, 1)",
|
||||||
|
data: categorizedValues,
|
||||||
|
tension: 0.2,
|
||||||
|
fill: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Revenue",
|
||||||
|
backgroundColor: "rgba(194, 21, 96, 0.4)",
|
||||||
|
borderColor: "rgba(194, 21, 96, 1)",
|
||||||
|
data: incomeValues,
|
||||||
|
tension: 0.4,
|
||||||
|
fill: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
const tempData = generatedData.datasets.filter(dataset => dataset.label !== undefined);
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: generatedData.labels || [],
|
||||||
|
datasets: tempData
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const allDates = [...new Set([...$monthIncome].map(item => item.date))];
|
||||||
|
const uniqueDates = allDates.sort((a, b) => new Date(a) - new Date(b));
|
||||||
|
|
||||||
|
const incomeValues = uniqueDates.map(date => $monthIncome.filter(item => item.date === date).reduce((total, item) => total + item.amount, 0));
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: uniqueDates,
|
||||||
|
datasets:
|
||||||
|
{
|
||||||
|
label: "Income",
|
||||||
|
backgroundColor: "rgba(194, 21, 96, 0.4)",
|
||||||
|
borderColor: "rgba(194, 21, 96, 1)",
|
||||||
|
data: incomeValues,
|
||||||
|
tension: 0.4,
|
||||||
|
fill: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const tempData = generatedData.datasets.filter(dataset => dataset.label !== undefined);
|
||||||
|
|
||||||
|
generatedData = {
|
||||||
|
labels: generatedData.labels || [],
|
||||||
|
datasets: tempData
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($monthIncome || $monthExpense || $isCategorizedIncome || $categorizedIncome) {
|
||||||
|
createGraph();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
createGraph();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="chart" style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<canvas id="canvas" bind:this={chartCanvas}></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#chart {
|
||||||
|
min-width: 0;
|
||||||
|
min-height:0;
|
||||||
|
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);
|
||||||
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
flex-grow: 2;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin: 0 10px 10px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chart:hover {
|
||||||
|
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#chart {
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,56 +1,48 @@
|
|||||||
<script>
|
<script>
|
||||||
import Modal from '../modals/Modal.svelte';
|
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { getCookie } from "svelte-cookie";
|
import { getCookie } from "svelte-cookie";
|
||||||
import {incomeData, incomeTypes} from "../../../stores.js";
|
import {incomeTypes, incomeData, dateText} from "../../../stores.js";
|
||||||
|
import { slide } from 'svelte/transition';
|
||||||
|
|
||||||
let showModal;
|
let showModal = false;
|
||||||
let amount = '';
|
let amount = '';
|
||||||
let newData;
|
let newData;
|
||||||
|
|
||||||
const selectedIncomeId = writable('');
|
const selectedIncomeId = writable('');
|
||||||
|
|
||||||
function addNewIncome(id, amount) {
|
function addNewIncome(expid, id, amount) {
|
||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date().toISOString().split('T')[0];
|
||||||
const incomeCategory = $incomeTypes.find(incomeType => incomeType.id === id);
|
const incomeCategory = $incomeTypes.find(incomeType => incomeType.id === id);
|
||||||
|
|
||||||
console.log(amount);
|
|
||||||
|
|
||||||
if (incomeCategory) {
|
if (incomeCategory) {
|
||||||
const newIncome = {
|
const newIncome = {
|
||||||
incomeId: 0,
|
incomeId: expid,
|
||||||
userDTO: {
|
|
||||||
name: "Dummy",
|
|
||||||
surname: "User",
|
|
||||||
username: "dummyuser"
|
|
||||||
},
|
|
||||||
incomeCategory: incomeCategory,
|
incomeCategory: incomeCategory,
|
||||||
date: today,
|
date: today,
|
||||||
amount: amount
|
amount: parseInt(amount)
|
||||||
};
|
};
|
||||||
|
|
||||||
newData = $incomeData;
|
newData = $incomeData;
|
||||||
newData.push(newIncome);
|
newData.push(newIncome);
|
||||||
$incomeData = newData;
|
$incomeData = newData;
|
||||||
} else {
|
} else {
|
||||||
console.error('Income category not found for id:', id);
|
console.error('Expense category not found for id:', id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const createIncome = async () => {
|
const createIncome = async () => {
|
||||||
|
showModal = false;
|
||||||
const selectedIncome = $incomeTypes.find(income => income.id === $selectedIncomeId);
|
const selectedIncome = $incomeTypes.find(income => income.id === $selectedIncomeId);
|
||||||
const data = {
|
const data = {
|
||||||
incomeCategory: selectedIncome.id,
|
incomeCategory: selectedIncome.id,
|
||||||
amount: parseInt(amount),
|
amount: parseInt(amount),
|
||||||
};
|
};
|
||||||
|
|
||||||
addNewIncome(selectedIncome.id, amount);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token = getCookie('access_token');
|
const token = getCookie('access_token');
|
||||||
|
|
||||||
const response = await axios.post('http://localhost:8081/incomes', data, {
|
const response = await axios.post('https://trackio.online:8081/incomes', data, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -58,7 +50,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.status === 201) {
|
if (response.status === 201) {
|
||||||
//console.log("cool");
|
addNewIncome(response.data.incomeId, selectedIncome.id, parseInt(amount));
|
||||||
} else {
|
} else {
|
||||||
console.error('Error:', response.status);
|
console.error('Error:', response.status);
|
||||||
}
|
}
|
||||||
@@ -66,17 +58,21 @@
|
|||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function toggleModal() {
|
||||||
|
showModal = !showModal;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="inc">
|
<div id="exp">
|
||||||
<div id="optionField">
|
<div id="optionField">
|
||||||
<h2>Incomes</h2>
|
<h2>Incomes: {$dateText}</h2>
|
||||||
<div id="openModal" class="plus-button" role="button" tabindex="0" on:click={() => (showModal = true)} on:keydown={() => console.log("keydown")}>
|
<div id="openModal" class="plus-button" role="button" tabindex="0" on:click={toggleModal} on:keydown={() => console.log("keydown")}>
|
||||||
+
|
+
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Modal bind:showModal>
|
{#if showModal}
|
||||||
<div class="income-form">
|
<div class="income-form" transition:slide>
|
||||||
<h3>Income Details</h3>
|
<h3>Income Details</h3>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="amount">Amount:</label>
|
<label for="amount">Amount:</label>
|
||||||
@@ -94,18 +90,48 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn btn-primary" on:click={createIncome}>Submit</button>
|
<div style="display: flex; justify-content: space-around">
|
||||||
|
<button class="btn btn-primary" on:click={createIncome}>SUBMIT</button>
|
||||||
|
<button class="btn btn-primary" on:click={() => showModal = false}>CANCEL</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#inc {
|
#exp {
|
||||||
padding: 20px;
|
padding: 10px 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
#optionField {
|
#optionField {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -130,10 +156,29 @@
|
|||||||
|
|
||||||
.income-form {
|
.income-form {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-radius: 5px;
|
border-radius: 20px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
margin: 0 auto;
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=text] {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
@@ -0,0 +1,710 @@
|
|||||||
|
<script>
|
||||||
|
import ContentIncome from "./ContentIncome.svelte";
|
||||||
|
import {
|
||||||
|
dateText,
|
||||||
|
expenseData,
|
||||||
|
incomeData,
|
||||||
|
tempExpense,
|
||||||
|
tempIncome,
|
||||||
|
monthIncome,
|
||||||
|
monthExpense,
|
||||||
|
isCategorizedExpense,
|
||||||
|
categorizedExpense,
|
||||||
|
currencyLabel, copyExpenseData, copyIncomeData, incomeCategoryLabel, categorizedIncome, isCategorizedIncome, incomeTypes
|
||||||
|
} from "../../../stores.js";
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
import {onMount} from "svelte";
|
||||||
|
import axios from "axios";
|
||||||
|
import {getCookie} from "svelte-cookie";
|
||||||
|
import {slide} from 'svelte/transition'
|
||||||
|
import EditEntry from "../util/EditEntry.svelte";
|
||||||
|
|
||||||
|
const textToIcon = {
|
||||||
|
'Interest': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"20\" viewBox=\"0 0 640 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M539.7 237.3c3.1-12.3 4.3-24.8 4.3-37.4C544 107.4 468.6 32 376.1 32c-77.2 0-144.6 53-163 127.8-15.3-13.2-34.9-20.5-55.2-20.5-46.3 0-84 37.7-84 84 0 7.4 .9 15 3.1 22.4-42.9 20.2-70.8 63.7-70.8 111.2C6.2 424.8 61.7 480 129.4 480h381.2c67.7 0 123.2-55.2 123.2-123.2 0-56.4-38.9-106-94.1-119.5zM199.9 401.6c0 8.3-7 15.3-15.3 15.3H153.6c-8.3 0-15.3-7-15.3-15.3V290.6c0-8.3 7-15.3 15.3-15.3h30.9c8.3 0 15.3 7 15.3 15.3v110.9zm89.5 0c0 8.3-7 15.3-15.3 15.3h-30.9c-8.3 0-15.3-7-15.3-15.3V270.1c0-8.3 7-15.3 15.3-15.3h30.9c8.3 0 15.3 7 15.3 15.3v131.5zm89.5 0c0 8.3-7 15.3-15.3 15.3h-30.9c-8.3 0-15.3-7-15.3-15.3V238.8c0-8.3 7-15.3 15.3-15.3h30.9c8.3 0 15.3 7 15.3 15.3v162.7zm87 0c0 8.3-7 15.3-15.3 15.3h-28.5c-8.3 0-15.3-7-15.3-15.3V176.9c0-8.6 7-15.6 15.3-15.6h28.5c8.3 0 15.3 7 15.3 15.6v224.6z\"/></svg>",
|
||||||
|
'Salary': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free 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>",
|
||||||
|
'Freelance Income': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free 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>",
|
||||||
|
'Investment Income': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"20\" viewBox=\"0 0 640 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M539.7 237.3c3.1-12.3 4.3-24.8 4.3-37.4C544 107.4 468.6 32 376.1 32c-77.2 0-144.6 53-163 127.8-15.3-13.2-34.9-20.5-55.2-20.5-46.3 0-84 37.7-84 84 0 7.4 .9 15 3.1 22.4-42.9 20.2-70.8 63.7-70.8 111.2C6.2 424.8 61.7 480 129.4 480h381.2c67.7 0 123.2-55.2 123.2-123.2 0-56.4-38.9-106-94.1-119.5zM199.9 401.6c0 8.3-7 15.3-15.3 15.3H153.6c-8.3 0-15.3-7-15.3-15.3V290.6c0-8.3 7-15.3 15.3-15.3h30.9c8.3 0 15.3 7 15.3 15.3v110.9zm89.5 0c0 8.3-7 15.3-15.3 15.3h-30.9c-8.3 0-15.3-7-15.3-15.3V270.1c0-8.3 7-15.3 15.3-15.3h30.9c8.3 0 15.3 7 15.3 15.3v131.5zm89.5 0c0 8.3-7 15.3-15.3 15.3h-30.9c-8.3 0-15.3-7-15.3-15.3V238.8c0-8.3 7-15.3 15.3-15.3h30.9c8.3 0 15.3 7 15.3 15.3v162.7zm87 0c0 8.3-7 15.3-15.3 15.3h-28.5c-8.3 0-15.3-7-15.3-15.3V176.9c0-8.6 7-15.6 15.3-15.6h28.5c8.3 0 15.3 7 15.3 15.6v224.6z\"/></svg>",
|
||||||
|
'Comission': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M64 64C28.7 64 0 92.7 0 128v64c0 8.8 7.4 15.7 15.7 18.6C34.5 217.1 48 235 48 256s-13.5 38.9-32.3 45.4C7.4 304.3 0 311.2 0 320v64c0 35.3 28.7 64 64 64H512c35.3 0 64-28.7 64-64V320c0-8.8-7.4-15.7-15.7-18.6C541.5 294.9 528 277 528 256s13.5-38.9 32.3-45.4c8.3-2.9 15.7-9.8 15.7-18.6V128c0-35.3-28.7-64-64-64H64zm64 112l0 160c0 8.8 7.2 16 16 16H432c8.8 0 16-7.2 16-16V176c0-8.8-7.2-16-16-16H144c-8.8 0-16 7.2-16 16zM96 160c0-17.7 14.3-32 32-32H448c17.7 0 32 14.3 32 32V352c0 17.7-14.3 32-32 32H128c-17.7 0-32-14.3-32-32V160z\"/></svg>",
|
||||||
|
'Sold Products': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free 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>",
|
||||||
|
'Gifts': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"16\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d=\"M190.5 68.8L225.3 128H224 152c-22.1 0-40-17.9-40-40s17.9-40 40-40h2.2c14.9 0 28.8 7.9 36.3 20.8zM64 88c0 14.4 3.5 28 9.6 40H32c-17.7 0-32 14.3-32 32v64c0 17.7 14.3 32 32 32H480c17.7 0 32-14.3 32-32V160c0-17.7-14.3-32-32-32H438.4c6.1-12 9.6-25.6 9.6-40c0-48.6-39.4-88-88-88h-2.2c-31.9 0-61.5 16.9-77.7 44.4L256 85.5l-24.1-41C215.7 16.9 186.1 0 154.2 0H152C103.4 0 64 39.4 64 88zm336 0c0 22.1-17.9 40-40 40H288h-1.3l34.8-59.2C329.1 55.9 342.9 48 357.8 48H360c22.1 0 40 17.9 40 40zM32 288V464c0 26.5 21.5 48 48 48H224V288H32zM288 512H432c26.5 0 48-21.5 48-48V288H288V512z\"/></svg>",
|
||||||
|
'Government Payments': "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"16\" width=\"18\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free 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>"
|
||||||
|
};
|
||||||
|
|
||||||
|
let isDateDropdownExpanded = false
|
||||||
|
let isCategoryDropdownExpanded = false
|
||||||
|
let isCurrencyDropdownExpanded = false
|
||||||
|
let isFilterDown = false;
|
||||||
|
|
||||||
|
let dropdownStates = {};
|
||||||
|
let deleteDropdownStates = {}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
dropdownStates = {};
|
||||||
|
deleteDropdownStates = {};
|
||||||
|
$incomeData.toReversed().forEach(data => {
|
||||||
|
dropdownStates[data.incomeId] = false;
|
||||||
|
deleteDropdownStates[data.incomeId] = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickFilter() {
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
isFilterDown = !isFilterDown;
|
||||||
|
isCurrencyDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
function clickHandlerDate() {
|
||||||
|
isDateDropdownExpanded = !isDateDropdownExpanded
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickHandlerCategory() {
|
||||||
|
isCategoryDropdownExpanded = !isCategoryDropdownExpanded;
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickHandlerCurrency() {
|
||||||
|
isCurrencyDropdownExpanded = !isCurrencyDropdownExpanded;
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
isFilterDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickItemHandler(id) {
|
||||||
|
dropdownStates[id] = !dropdownStates[id];
|
||||||
|
if (deleteDropdownStates[id] === true) deleteDropdownStates[id] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickDeleteHandler(id) {
|
||||||
|
deleteDropdownStates[id] = !deleteDropdownStates[id];
|
||||||
|
if (dropdownStates[id] === true) dropdownStates[id] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clickOutsideHandler(event) {
|
||||||
|
const isDateButton = event.target.closest("#incomeInfo");
|
||||||
|
|
||||||
|
if (!isDateButton) {
|
||||||
|
isFilterDown = false;
|
||||||
|
isCategoryDropdownExpanded = false;
|
||||||
|
isDateDropdownExpanded = false;
|
||||||
|
isCurrencyDropdownExpanded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
$isCategorizedIncome = false;
|
||||||
|
|
||||||
|
document.body.addEventListener("click", clickOutsideHandler);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.body.removeEventListener("click", clickOutsideHandler);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getToday() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const currentDay = currentDate.toISOString().split('T')[0];
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?date=' + currentDay, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?date=' + currentDay, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response1.data);
|
||||||
|
$dateText = "Today"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getYesterday() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
|
||||||
|
const yesterday = new Date(currentDate);
|
||||||
|
yesterday.setDate(currentDate.getDate() - 1);
|
||||||
|
|
||||||
|
const yesterdayString = yesterday.toISOString().split('T')[0];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?date=' + yesterdayString, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?date=' + yesterdayString, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "Yesterday"
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getMonth() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const year = currentDate.getMonth() + 1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
monthExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
monthIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "This Month"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLastMonth() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const year = currentDate.getMonth();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data)
|
||||||
|
monthExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?month=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
monthIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "Last Month"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLastYear() {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const year = currentDate.getFullYear();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response1 = await axios.get('https://trackio.online:8081/expenses/personal-expenses?year=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expenseData.set(response1.data);
|
||||||
|
tempExpense.set(response1.data);
|
||||||
|
monthExpense.set(response1.data);
|
||||||
|
copyExpenseData.set(response1.data);
|
||||||
|
const response2 = await axios.get('https://trackio.online:8081/incomes/personal-incomes?year=' + year, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${getCookie('access_token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
incomeData.set(response2.data);
|
||||||
|
tempIncome.set(response2.data);
|
||||||
|
monthIncome.set(response2.data);
|
||||||
|
copyIncomeData.set(response2.data);
|
||||||
|
$dateText = "This Year"
|
||||||
|
|
||||||
|
$isCategorizedExpense = false;
|
||||||
|
categorizedExpense.set([]);
|
||||||
|
changeCurrency($currencyLabel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching expenses:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterByCategory(category) {
|
||||||
|
$isCategorizedIncome = true;
|
||||||
|
$incomeCategoryLabel = category;
|
||||||
|
console.log($isCategorizedIncome);
|
||||||
|
let tempArr = $tempIncome.filter(income => income.incomeCategory.name === category);
|
||||||
|
categorizedIncome.set(tempArr);
|
||||||
|
incomeData.set(tempArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAll() {
|
||||||
|
categorizedIncome.set([]);
|
||||||
|
$incomeCategoryLabel = "Category";
|
||||||
|
$isCategorizedIncome = false;
|
||||||
|
console.log($isCategorizedIncome);
|
||||||
|
incomeData.set($tempIncome);
|
||||||
|
}
|
||||||
|
|
||||||
|
function doNothing() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeCurrency(currency) {
|
||||||
|
if (currency === 'USD') {
|
||||||
|
expenseData.set($copyExpenseData);
|
||||||
|
incomeData.set($copyIncomeData);
|
||||||
|
$currencyLabel = "USD";
|
||||||
|
}
|
||||||
|
if (currency === 'MDL') {
|
||||||
|
const tempData1 = $copyExpenseData.map(expense => ({
|
||||||
|
...expense,
|
||||||
|
amount: expense.amount / 0.056
|
||||||
|
}));
|
||||||
|
expenseData.set(tempData1);
|
||||||
|
|
||||||
|
const tempData2 = $copyIncomeData.map(income => ({
|
||||||
|
...income,
|
||||||
|
amount: income.amount / 0.056
|
||||||
|
}));
|
||||||
|
incomeData.set(tempData2);
|
||||||
|
$currencyLabel = "MDL";
|
||||||
|
}
|
||||||
|
if (currency === 'EUR') {
|
||||||
|
const tempData1 = $copyExpenseData.map(expense => ({
|
||||||
|
...expense,
|
||||||
|
amount: expense.amount / 1.08
|
||||||
|
}));
|
||||||
|
expenseData.set(tempData1);
|
||||||
|
|
||||||
|
const tempData2 = $copyIncomeData.map(income => ({
|
||||||
|
...income,
|
||||||
|
amount: income.amount / 1.08
|
||||||
|
}));
|
||||||
|
incomeData.set(tempData2);
|
||||||
|
$currencyLabel = "EUR";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currency === 'GBP') {
|
||||||
|
const tempData1 = $copyExpenseData.map(expense => ({
|
||||||
|
...expense,
|
||||||
|
amount: expense.amount / 1.26
|
||||||
|
}));
|
||||||
|
expenseData.set(tempData1);
|
||||||
|
|
||||||
|
const tempData2 = $copyIncomeData.map(income => ({
|
||||||
|
...income,
|
||||||
|
amount: income.amount / 1.26
|
||||||
|
}));
|
||||||
|
incomeData.set(tempData2);
|
||||||
|
$currencyLabel = "GBP";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="incomeInfo" style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<ContentIncome />
|
||||||
|
<div style="display: flex; justify-content: space-around">
|
||||||
|
|
||||||
|
<div id="dropdown" style="margin: 10px; display: flex; justify-content: space-between">
|
||||||
|
<button id="btn1" class="button" on:click={clickFilter}>Filter ▼</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="dropdown-currency" style="margin: 10px;">
|
||||||
|
<button id="btn2" class="button" on:click={clickHandlerCurrency}>Currency ▼</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#if isFilterDown}
|
||||||
|
<div style="margin: 10px; display: flex; justify-content: space-between" transition:slide>
|
||||||
|
<div id="dropdown-date" style="margin: 10px;">
|
||||||
|
<button id="btn3" class="button" on:click={clickHandlerDate}>Filter by Date ▼</button></div>
|
||||||
|
|
||||||
|
<div id="dropdown-category" style="margin: 10px;">
|
||||||
|
<button id="btn4" class="button" on:click={clickHandlerCategory}>Filter by Category ▼</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if isDateDropdownExpanded}
|
||||||
|
<div id="date-list" transition:slide>
|
||||||
|
<div class="date-entry" on:click={() => getToday()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>Today
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getYesterday()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>Yesterday
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getMonth()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>This month
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getLastMonth()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>Last month
|
||||||
|
</div>
|
||||||
|
<div class="date-entry" on:click={() => getLastYear()} role="button" tabindex="0"
|
||||||
|
on:keydown={doNothing}>This year
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if isCategoryDropdownExpanded}
|
||||||
|
<div id="date-list" transition:slide>
|
||||||
|
<div class="date-entry" on:click={() => getAll()} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>All</div>
|
||||||
|
{#each $incomeTypes as income (income.id)}
|
||||||
|
{#if income.id !== undefined}
|
||||||
|
<div class="date-entry" on:click={() => filterByCategory(income.name)} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>{income.name}</div>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if isCurrencyDropdownExpanded}
|
||||||
|
<div id="date-list" transition:slide>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("MDL")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>MDL Leu</div>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("GBP")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>GBP Pound</div>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("USD")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>USD Dollar</div>
|
||||||
|
<div class="date-entry" on:click={() => changeCurrency("EUR")} role="button"
|
||||||
|
tabindex="0" on:keydown={doNothing}>EUR Euro</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div id="listContainer" style="color: {$globalStyles.color}">
|
||||||
|
<ul>
|
||||||
|
{#each $incomeData.toReversed() as item (item.incomeId)}
|
||||||
|
<li style="display:flex; flex-direction: column; justify-content: space-between; color: {$globalStyles.color}">
|
||||||
|
<div style="display:flex; flex-direction: row; justify-content: space-between; align-items: center;">
|
||||||
|
<div>
|
||||||
|
{#if textToIcon[item.incomeCategory.name]}
|
||||||
|
{@html textToIcon[item.incomeCategory.name]}
|
||||||
|
{/if}
|
||||||
|
<span style="font-weight: bold">{item.incomeCategory ? `${item.incomeCategory.name}: ` : `${item.expenseCategory.name}: `}</span>
|
||||||
|
<span style="font-weight:bold; margin-right: 10px; color: limegreen; font-size: larger">{item.incomeCategory ? `+${item.amount.toFixed(2)} ${$currencyLabel}` : `-${item.amount.toFixed(2)} ${$currencyLabel}`}</span>
|
||||||
|
</div>
|
||||||
|
<div style="margin-right: 5px; display: flex; flex-direction: row">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{`${item.date}`}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="editBtnDiv" role="button" tabindex="0" on:keydown={doNothing}
|
||||||
|
on:click={() => clickItemHandler(item.incomeId)}>
|
||||||
|
<span id="editBtn"><svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512"><path
|
||||||
|
d="M471.6 21.7c-21.9-21.9-57.3-21.9-79.2 0L362.3 51.7l97.9 97.9 30.1-30.1c21.9-21.9 21.9-57.3 0-79.2L471.6 21.7zm-299.2 220c-6.1 6.1-10.8 13.6-13.5 21.9l-29.6 88.8c-2.9 8.6-.6 18.1 5.8 24.6s15.9 8.7 24.6 5.8l88.8-29.6c8.2-2.7 15.7-7.4 21.9-13.5L437.7 172.3 339.7 74.3 172.4 241.7zM96 64C43 64 0 107 0 160V416c0 53 43 96 96 96H352c53 0 96-43 96-96V320c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7-14.3 32-32 32H96c-17.7 0-32-14.3-32-32V160c0-17.7 14.3-32 32-32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H96z"/></svg></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="deleteBtnDiv" role="button" tabindex="0" on:keydown={doNothing}
|
||||||
|
on:click={() => clickDeleteHandler(item.incomeId)}>
|
||||||
|
<span id="deleteBtn"><svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><path
|
||||||
|
d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if dropdownStates[item.incomeId]}
|
||||||
|
<EditEntry {item} bind:isOn={dropdownStates[item.incomeId]}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if deleteDropdownStates[item.incomeId]}
|
||||||
|
<div style="padding: 5px; margin-top: 5px; display:flex; flex-direction: column; justify-content: space-evenly"
|
||||||
|
class="inputForm" transition:slide>
|
||||||
|
<span id="textf" style="text-align: center; margin-bottom: 10px">Confirm deletion?</span>
|
||||||
|
<div style="display:flex; flex-direction: row; justify-content: space-evenly">
|
||||||
|
<button id="confirmBtn">CONFIRM</button>
|
||||||
|
<button id="cancelBtn">CANCEL</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- <button style="background-color: #8BD17C" on:click={() => console.log("LOL")}>Delete</button>-->
|
||||||
|
<!-- <button style="background-color: palevioletred" on:click={clickItemHandler(item.expenseId)}>Cancel</button>-->
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#textf {
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
#confirmBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#confirmBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#listContainer {
|
||||||
|
max-height: 50vh;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#incomeInfo {
|
||||||
|
margin: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#editBtn {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 5px;
|
||||||
|
fill: darkblue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inputForm {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editBtn:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
fill: lightseagreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
#deleteBtn {
|
||||||
|
fill: red;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#deleteBtn:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
fill: palevioletred;
|
||||||
|
}
|
||||||
|
|
||||||
|
#incomeInfo {
|
||||||
|
min-width: 350px;
|
||||||
|
min-height: 0;
|
||||||
|
background-color: #212942;
|
||||||
|
color: white;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: #f1f1f1;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: #888;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
align-items: center;
|
||||||
|
background-color: #0A66C2;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 100px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #ffffff;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-flex;
|
||||||
|
font-family: -apple-system, system-ui, system-ui, "Segoe UI", Roboto, "Helvetica Neue", "Fira Sans", Ubuntu, Oxygen, "Oxygen Sans", Cantarell, "Droid Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Lucida Grande", Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
justify-content: center;
|
||||||
|
line-height: 20px;
|
||||||
|
max-width: 480px;
|
||||||
|
min-height: 40px;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 0 20px;
|
||||||
|
text-align: center;
|
||||||
|
touch-action: manipulation;
|
||||||
|
transition: background-color 0.167s cubic-bezier(0.4, 0, 0.2, 1) 0s, box-shadow 0.167s cubic-bezier(0.4, 0, 0.2, 1) 0s, color 0.167s cubic-bezier(0.4, 0, 0.2, 1) 0s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover,
|
||||||
|
.button:focus {
|
||||||
|
background-color: #16437E;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:active {
|
||||||
|
background: #09223b;
|
||||||
|
color: rgb(255, 255, 255, .7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
background: rgba(0, 0, 0, .08);
|
||||||
|
color: rgba(0, 0, 0, .3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#date-list {
|
||||||
|
background-color: black;
|
||||||
|
margin: 0 20px 20px;
|
||||||
|
max-height: 400px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-entry {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .3s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-entry:hover {
|
||||||
|
box-shadow: rgba(255, 255, 255, 0.8) 0 0 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<script>
|
||||||
|
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="header">
|
||||||
|
<div id="dashboardTitleWrapper" style="color: white">
|
||||||
|
<h1 id="dashboardTitle">Dashboard - Incomes</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="icons">
|
||||||
|
<div class="headerbtn searchButton">
|
||||||
|
<svg style="fill: white" 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 style="fill: white" 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 20px 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,140 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { incomeData, expenseData, currencyLabel } from "../../../stores.js";
|
||||||
|
import {globalStyles} from "../../../styles.js";
|
||||||
|
|
||||||
|
let infobar1, infobar2, infobar3, infobar4;
|
||||||
|
let totalExpenses = 0;
|
||||||
|
let totalIncomes = 0;
|
||||||
|
let lastMonthIncome = 800;
|
||||||
|
let lastMonthExpense = 200;
|
||||||
|
let incomeDifference;
|
||||||
|
let expenseDifference;
|
||||||
|
|
||||||
|
function updateInfo() {
|
||||||
|
totalExpenses = $expenseData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||||
|
totalIncomes = $incomeData.reduce((total, item) => total + parseInt(item.amount), 0);
|
||||||
|
|
||||||
|
incomeDifference = ((totalIncomes - lastMonthIncome) / lastMonthIncome) * 100;
|
||||||
|
expenseDifference = ((lastMonthExpense - totalExpenses) / lastMonthExpense) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($currencyLabel) {
|
||||||
|
if ($currencyLabel === 'USD') {
|
||||||
|
lastMonthIncome = 800;
|
||||||
|
lastMonthExpense = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currencyLabel === 'MDL') {
|
||||||
|
lastMonthIncome = 800 / 0.056;
|
||||||
|
lastMonthExpense = 200 / 0.056;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currencyLabel === 'EUR') {
|
||||||
|
lastMonthIncome = 800 / 1.08;
|
||||||
|
lastMonthExpense = 200 / 1.08;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currencyLabel === 'GBP') {
|
||||||
|
lastMonthIncome = 800 / 1.26;
|
||||||
|
lastMonthExpense = 200 / 1.26;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($incomeData || $expenseData) {
|
||||||
|
updateInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
updateInfo();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="quickInfobar">
|
||||||
|
<div class="firstTwo">
|
||||||
|
<div class="infobarElement" bind:this={infobar1} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Total expenses:</span><br><span class="dataSpan" style="color:#ab1a3c">{totalExpenses.toFixed(2)} {$currencyLabel}</span>
|
||||||
|
</div>
|
||||||
|
<div class="infobarElement" bind:this={infobar2} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Total incomes:</span><br><span class="dataSpan" style="color:#38cc1b">{totalIncomes.toFixed(2)} {$currencyLabel}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="secondTwo">
|
||||||
|
<div class="infobarElement" bind:this={infobar3} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Income by last month:</span><br><span class="dataSpan" style="color:#2763db">{incomeDifference.toFixed(2)}%</span>
|
||||||
|
</div>
|
||||||
|
<div class="infobarElement" bind:this={infobar4} style="background-color: {$globalStyles.mainColor}">
|
||||||
|
<span class="infobarSpan">Expense by last month:</span><br><span class="dataSpan" style="color:#dba527">{expenseDifference.toFixed(2)}%</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
.firstTwo {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondTwo {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.infobarSpan {
|
||||||
|
font-size: larger;
|
||||||
|
color: #00FEFC
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataSpan {
|
||||||
|
color:#ab1a3c;
|
||||||
|
font-size: xxx-large;
|
||||||
|
}
|
||||||
|
|
||||||
|
#quickInfobar {
|
||||||
|
/*display: flex;*/
|
||||||
|
/*justify-content: space-between;*/
|
||||||
|
/*flex-wrap: wrap;*/
|
||||||
|
min-height: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (min-width: 768px) and (max-width: 1200px) {
|
||||||
|
.infobarSpan {
|
||||||
|
font-size: medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataSpan {
|
||||||
|
font-size: large;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.infobarElement {
|
||||||
|
font-family: Inconsolata,"Source Sans Pro",sans-serif;
|
||||||
|
font-size: larger;
|
||||||
|
margin: 10px;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
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>
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<script>
|
||||||
|
import {incomeTypes} from "../../../stores.js";
|
||||||
|
import { slide } from 'svelte/transition'
|
||||||
|
export let item;
|
||||||
|
export let isOn;
|
||||||
|
|
||||||
|
function handleSave() {
|
||||||
|
const amount = document.getElementById('amountInput').value;
|
||||||
|
const expenseCategory = document.getElementById('incomeCategory').value;
|
||||||
|
|
||||||
|
console.log("tryna save: " + item.incomeId + " " + amount + " " + expenseCategory)
|
||||||
|
// saveFunction(item.expenseId, amount, expenseCategory);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div style="display: flex; flex-direction: column" transition:slide>
|
||||||
|
<span id="textf" style="margin-top: 10px; text-align: center">Edit Entry</span>
|
||||||
|
<input type="text" id="amountInput" bind:value={item.amount}>
|
||||||
|
<select id="incomeCategory" class="form-control">
|
||||||
|
{#each $incomeTypes as income (income.id)}
|
||||||
|
{#if income.id !== undefined}
|
||||||
|
{#if income.id === item.incomeCategory.id}
|
||||||
|
<option value={income.id} selected>{income.name}</option>
|
||||||
|
{:else}
|
||||||
|
<option value={income.id}>{income.name}</option>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
<div style="margin: 10px; display:flex; flex-direction: row; justify-content: space-evenly">
|
||||||
|
<button class="buttonCL" id="saveBtn" on:click={handleSave}>SAVE</button>
|
||||||
|
<button class="buttonCL" id="cancelBtn" on:click={() => isOn = false}>CANCEL</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#textf {
|
||||||
|
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=text] {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
padding: 12px 20px;
|
||||||
|
margin: 8px 0;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#saveBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#saveBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn {
|
||||||
|
background-image: linear-gradient(92.88deg, #455EB5 9.16%, #5643CC 43.89%, #673FD7 64.72%);
|
||||||
|
border-radius: 8px;
|
||||||
|
border-style: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: "Inter UI","SF Pro Display",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue",sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 3rem;
|
||||||
|
padding: 0 1.6rem;
|
||||||
|
text-align: center;
|
||||||
|
text-shadow: rgba(0, 0, 0, 0.25) 0 3px 8px;
|
||||||
|
transition: all .5s;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelBtn:hover {
|
||||||
|
box-shadow: rgba(80, 63, 205, 0.5) 0 1px 30px;
|
||||||
|
transition-duration: .1s;
|
||||||
|
}
|
||||||
|
</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,57 +0,0 @@
|
|||||||
<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>
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<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>
|
|
||||||
@@ -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>
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<script>
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
import { incomeData, expenseData } from "../../stores.js";
|
|
||||||
|
|
||||||
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}></div>
|
|
||||||
<div class="infobarElement" bind:this={infobar2}></div>
|
|
||||||
<div class="infobarElement" bind:this={infobar3}></div>
|
|
||||||
<div class="infobarElement" bind:this={infobar4}></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,29 +1,10 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import {deleteCookie} from "svelte-cookie";
|
||||||
import axios from 'axios';
|
import {isAdmin, username} from "../stores.js";
|
||||||
import {deleteCookie, getCookie} from "svelte-cookie";
|
export let onTabClick;
|
||||||
|
|
||||||
let username;
|
function doNothing() {
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
const token = getCookie('access_token');
|
|
||||||
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
'Authorization': `Bearer ${token}`
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await axios.get('http://localhost:8081/users/getUserData', config);
|
|
||||||
const data = response.data;
|
|
||||||
username = data.username;
|
|
||||||
console.log(username)
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error:', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -35,34 +16,41 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="menuSpace">
|
<div id="menuSpace">
|
||||||
<div class="sideMenuItem">
|
<div on:click={() => onTabClick('profile')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 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="M224 256A128 128 0 1 0 224 0a128 128 0 1 0 0 256zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512H418.3c16.4 0 29.7-13.3 29.7-29.7C448 383.8 368.2 304 269.7 304H178.3z"/></svg>
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><path d="M224 256A128 128 0 1 0 224 0a128 128 0 1 0 0 256zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512H418.3c16.4 0 29.7-13.3 29.7-29.7C448 383.8 368.2 304 269.7 304H178.3z"/></svg>
|
||||||
<span class="sideMenuItemText">Profile</span>
|
<span class="sideMenuItemText">Profile</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="sideMenuItem">
|
<div on:click={() => onTabClick('expenses')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
<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>
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512"><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>
|
||||||
|
|
||||||
<div class="sideMenuItem">
|
<div on:click={() => onTabClick('incomes')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
<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>
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512"><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>
|
||||||
|
|
||||||
<div class="sideMenuItem">
|
<div on:click={() => onTabClick('statistics')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
<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>
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><path d="M160 80c0-26.5 21.5-48 48-48h32c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H208c-26.5 0-48-21.5-48-48V80zM0 272c0-26.5 21.5-48 48-48H80c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V272zM368 96h32c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H368c-26.5 0-48-21.5-48-48V144c0-26.5 21.5-48 48-48z"/></svg>
|
||||||
<span class="sideMenuItemText">General</span>
|
<span class="sideMenuItemText">Statistics</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="sideMenuItem">
|
{#if isAdmin}
|
||||||
<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>
|
<div on:click={() => onTabClick('admin')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><path d="M96 128a128 128 0 1 0 256 0A128 128 0 1 0 96 128zm94.5 200.2l18.6 31L175.8 483.1l-36-146.9c-2-8.1-9.8-13.4-17.9-11.3C51.9 342.4 0 405.8 0 481.3c0 17 13.8 30.7 30.7 30.7H162.5c0 0 0 0 .1 0H168 280h5.5c0 0 0 0 .1 0H417.3c17 0 30.7-13.8 30.7-30.7c0-75.5-51.9-138.9-121.9-156.4c-8.1-2-15.9 3.3-17.9 11.3l-36 146.9L238.9 359.2l18.6-31c6.4-10.7-1.3-24.2-13.7-24.2H224 204.3c-12.4 0-20.1 13.6-13.7 24.2z"/></svg>
|
||||||
|
<span class="sideMenuItemText">Admin Panel</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div on:click={() => onTabClick('settings')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><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>
|
<span class="sideMenuItemText">Settings</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="profileSpace">
|
<div id="profileSpace">
|
||||||
<div id="profileInfo">Hello, {username}</div>
|
<div id="profileInfo">Hello, {$username}</div>
|
||||||
<div id="logout" role="button"
|
<div id="logout" role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
@@ -84,6 +72,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
#sideMenu {
|
#sideMenu {
|
||||||
font-family: 'Source Sans Pro', sans-serif;
|
font-family: 'Source Sans Pro', sans-serif;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -94,6 +83,12 @@
|
|||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 900px) {
|
||||||
|
#sideMenu {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#iconSpace {
|
#iconSpace {
|
||||||
margin-top:20px;
|
margin-top:20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -105,9 +100,11 @@
|
|||||||
min-height: 50px;
|
min-height: 50px;
|
||||||
color:white;
|
color:white;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: left;
|
||||||
|
padding-left: 20px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sideMenuItem:hover {
|
.sideMenuItem:hover {
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import axios from 'axios';
|
||||||
|
import {deleteCookie, getCookie} from "svelte-cookie";
|
||||||
|
import { slide } from 'svelte/transition'
|
||||||
|
import {isAdmin, username} from "../stores.js";
|
||||||
|
|
||||||
|
export let onTabClick;
|
||||||
|
|
||||||
|
let isMenuDown = false;
|
||||||
|
|
||||||
|
function toggleMenu() {
|
||||||
|
isMenuDown = !isMenuDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
function doNothing() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="stickyMenu">
|
||||||
|
<div id="stickyButton" tabindex="0" role="button" style="background-color: #191f35; color:white; padding: 10px; display: flex; align-items: center; justify-content: space-around" on:click={toggleMenu} on:keydown={doNothing}>
|
||||||
|
<img id="iconImg" src='./../../../src/lib/images/adidas.png' width="90px" alt="icon"/>
|
||||||
|
<h3>Menu ▼</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if isMenuDown}
|
||||||
|
<div id="sideMenu" transition:slide>
|
||||||
|
<div on:click={() => onTabClick('profile')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 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="M224 256A128 128 0 1 0 224 0a128 128 0 1 0 0 256zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512H418.3c16.4 0 29.7-13.3 29.7-29.7C448 383.8 368.2 304 269.7 304H178.3z"/></svg>
|
||||||
|
<span class="sideMenuItemText">Profile</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div on:click={() => onTabClick('expenses')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<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">Spendings</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div on:click={() => onTabClick('incomes')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<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">Revenues</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div on:click={() => onTabClick('statistics')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M160 80c0-26.5 21.5-48 48-48h32c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H208c-26.5 0-48-21.5-48-48V80zM0 272c0-26.5 21.5-48 48-48H80c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V272zM368 96h32c26.5 0 48 21.5 48 48V432c0 26.5-21.5 48-48 48H368c-26.5 0-48-21.5-48-48V144c0-26.5 21.5-48 48-48z"/></svg>
|
||||||
|
<span class="sideMenuItemText">Statistics</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div on:click={() => onTabClick('settings')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
{#if isAdmin}
|
||||||
|
<div on:click={() => onTabClick('admin')} tabindex="0" role="button" class="sideMenuItem" on:keydown={doNothing}>
|
||||||
|
<svg class="svgimg" xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M96 128a128 128 0 1 0 256 0A128 128 0 1 0 96 128zm94.5 200.2l18.6 31L175.8 483.1l-36-146.9c-2-8.1-9.8-13.4-17.9-11.3C51.9 342.4 0 405.8 0 481.3c0 17 13.8 30.7 30.7 30.7H162.5c0 0 0 0 .1 0H168 280h5.5c0 0 0 0 .1 0H417.3c17 0 30.7-13.8 30.7-30.7c0-75.5-51.9-138.9-121.9-156.4c-8.1-2-15.9 3.3-17.9 11.3l-36 146.9L238.9 359.2l18.6-31c6.4-10.7-1.3-24.2-13.7-24.2H224 204.3c-12.4 0-20.1 13.6-13.7 24.2z"/></svg>
|
||||||
|
<span class="sideMenuItemText">Admin Panel</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div id="profileSpace">
|
||||||
|
<div id="profileInfo">Hello, {$username}</div>
|
||||||
|
<div id="logout" role="button"
|
||||||
|
tabindex="0"
|
||||||
|
on:click={() => {
|
||||||
|
deleteCookie('access_token');
|
||||||
|
deleteCookie('refresh_token');
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
}}
|
||||||
|
on:keydown={e => {
|
||||||
|
if (e.key === 'Enter' || e.key === ' ') {
|
||||||
|
deleteCookie('access_token');
|
||||||
|
deleteCookie('refresh_token');
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
Log out
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#stickyMenu {
|
||||||
|
position:sticky;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sideMenu {
|
||||||
|
font-family: 'Source Sans Pro', sans-serif;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
margin:0;
|
||||||
|
justify-content: center;
|
||||||
|
min-width: 150px;
|
||||||
|
background-color: #191f35;
|
||||||
|
position:absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sideMenuItem {
|
||||||
|
min-height: 50px;
|
||||||
|
color:white;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sideMenuItem:hover {
|
||||||
|
background-color: rgb(45, 60, 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sideMenuItemText {
|
||||||
|
padding:10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.svgimg {
|
||||||
|
fill:white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#iconImg {
|
||||||
|
max-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#profileSpace {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: white;
|
||||||
|
font-weight: 900;
|
||||||
|
font-size: larger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#logout {
|
||||||
|
background: none;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 10px;
|
||||||
|
transition: background 0.3s ease;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#logout:hover {
|
||||||
|
background: rgba(128, 128, 128, 0.5);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,9 +1,42 @@
|
|||||||
import {writable} from "svelte/store";
|
import {writable} from "svelte/store";
|
||||||
|
|
||||||
|
export const isAdmin = writable(false);
|
||||||
|
|
||||||
|
export const username = writable("");
|
||||||
export const incomeData = writable([]);
|
export const incomeData = writable([]);
|
||||||
|
|
||||||
export const expenseData = writable([]);
|
export const expenseData = writable([]);
|
||||||
|
|
||||||
|
export const copyExpenseData = writable([]);
|
||||||
|
|
||||||
|
export const copyIncomeData = writable([]);
|
||||||
|
|
||||||
export const incomeTypes = writable([]);
|
export const incomeTypes = writable([]);
|
||||||
|
|
||||||
export const expenseTypes = writable([]);
|
export const expenseTypes = writable([]);
|
||||||
|
|
||||||
|
export const tempExpense = writable([])
|
||||||
|
|
||||||
|
export const tempIncome = writable([]);
|
||||||
|
|
||||||
|
export const monthIncome = writable([]);
|
||||||
|
|
||||||
|
export const monthExpense = writable([]);
|
||||||
|
|
||||||
|
export const categorizedExpense = writable([]);
|
||||||
|
|
||||||
|
export const categorizedIncome = writable([]);
|
||||||
|
|
||||||
|
export let isCategorizedExpense = writable(false);
|
||||||
|
|
||||||
|
export let isCategorizedIncome = writable(false);
|
||||||
|
|
||||||
|
export let expenseCategoryLabel = writable();
|
||||||
|
|
||||||
|
export let incomeCategoryLabel = writable();
|
||||||
|
|
||||||
|
export let selectedTab = writable('expenses');
|
||||||
|
|
||||||
|
export let dateText = writable("This Month");
|
||||||
|
|
||||||
|
export let currencyLabel = writable('USD');
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export const themeDefault = {
|
||||||
|
mainColor: '#172233',
|
||||||
|
dashColor: '#F5F2F3',
|
||||||
|
color: 'black',
|
||||||
|
altColor: 'white',
|
||||||
|
dashTextColor: 'black',
|
||||||
|
mainDataColor: '#F5F2F3'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const themeDark = {
|
||||||
|
mainColor: '#000000',
|
||||||
|
dashColor: '#202020',
|
||||||
|
color: 'black',
|
||||||
|
altColor: 'white',
|
||||||
|
dashTextColor: 'white',
|
||||||
|
mainDataColor: 'black'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const themeColorful = {
|
||||||
|
mainColor: '#F75590',
|
||||||
|
dashColor: '#FCE4D8',
|
||||||
|
color: 'black',
|
||||||
|
altColor: 'white',
|
||||||
|
dashTextColor: 'black',
|
||||||
|
mainDataColor: '#FCE4D8'
|
||||||
|
}
|
||||||
|
export const globalStyles = writable(themeDefault);
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
window.location.href = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
|
||||||
|
});
|
||||||
|
</script>
|
||||||
BIN
src/main/java/com/faf223/expensetrackerfaf/web/static/img.jpg
Normal file
BIN
src/main/java/com/faf223/expensetrackerfaf/web/static/img.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 MiB |
@@ -1,6 +1,15 @@
|
|||||||
import { sveltekit } from '@sveltejs/kit/vite';
|
import fs from 'fs'
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit()]
|
plugins: [sveltekit()],
|
||||||
});
|
server: {
|
||||||
|
port: 443,
|
||||||
|
https: {
|
||||||
|
key: fs.readFileSync('D:\\Source\\JavaProjects\\ExpenseTrackerFAF\\src\\main\\java\\com\\faf223\\expensetrackerfaf\\web\\privkey.pem'),
|
||||||
|
cert: fs.readFileSync('D:\\Source\\JavaProjects\\ExpenseTrackerFAF\\src\\main\\java\\com\\faf223\\expensetrackerfaf\\web\\fullchain.pem'),
|
||||||
|
proxy: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
86
src/main/resources/fullchain.pem
Normal file
86
src/main/resources/fullchain.pem
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEHTCCAwWgAwIBAgISBGYC3YGfvdZxQg6y2YUSjvzLMA0GCSqGSIb3DQEBCwUA
|
||||||
|
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
|
||||||
|
EwJSMzAeFw0yMzEyMTIxOTAxNTVaFw0yNDAzMTExOTAxNTRaMBkxFzAVBgNVBAMT
|
||||||
|
DnRyYWNraW8ub25saW5lMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEirToCuVv
|
||||||
|
qNiT3Rxqsyu2+OmD7TYBW+CV9639OW4FhwHaFxyzoCWI3/w3gZNVE/5Y1CvwHAsw
|
||||||
|
qfuam0LjfbnKOKOCAg8wggILMA4GA1UdDwEB/wQEAwIHgDAdBgNVHSUEFjAUBggr
|
||||||
|
BgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUmUFyQf+b
|
||||||
|
b16jD80QRaO9ipw7h9kwHwYDVR0jBBgwFoAUFC6zF7dYVsuuUAlA5h+vnYsUwsYw
|
||||||
|
VQYIKwYBBQUHAQEESTBHMCEGCCsGAQUFBzABhhVodHRwOi8vcjMuby5sZW5jci5v
|
||||||
|
cmcwIgYIKwYBBQUHMAKGFmh0dHA6Ly9yMy5pLmxlbmNyLm9yZy8wGQYDVR0RBBIw
|
||||||
|
EIIOdHJhY2tpby5vbmxpbmUwEwYDVR0gBAwwCjAIBgZngQwBAgEwggEDBgorBgEE
|
||||||
|
AdZ5AgQCBIH0BIHxAO8AdQA7U3d1Pi25gE6LMFsG/kA7Z9hPw/THvQANLXJv4frU
|
||||||
|
FwAAAYxfnyo6AAAEAwBGMEQCIBqYq5pa2GE7UNJHzN+1AAbw///s8PtWNkauU9UO
|
||||||
|
igWZAiAktf1uf/O90k1l/+ihkPxJXToxcH5yeOiqATqDMol5PwB2AHb/iD8KtvuV
|
||||||
|
UcJhzPWHujS0pM27KdxoQgqf5mdMWjp0AAABjF+fKoMAAAQDAEcwRQIgfNyTycHQ
|
||||||
|
D1OMAOBA8vHAyu//5SjnY0BtCxOITyY/W1oCIQCCHFH+VKTFCglsqcp2hwQJHGq/
|
||||||
|
jiSj4tR0jYIm5xMlaTANBgkqhkiG9w0BAQsFAAOCAQEAqu7cvsrkAnyrBgQHovQ4
|
||||||
|
r+F1S/H6vu/Bvt9x+d125uDa/pT55JO/wG1IvdT9fxws2oYcc/nc8DjvW9U7+peu
|
||||||
|
5K675kH09QTi+GhBAU4gZBhx3PohA6qG0Wm/6gC4lOq+S7o32x6RpoptcSvB3UXQ
|
||||||
|
9BkgbO6LgDu99jPm6Acv4wre6trXAbPOpSlruSKSENnda7l/CamfiOX0cRKHjZdX
|
||||||
|
PNpIfqWXokXNNYDAdrcXbOm7mFVMo1WcjBQM6E++IXfDRqHQ82Y94YVhEdH/hCo6
|
||||||
|
3ce9uSrgL9+HcwhHzlZj20rTHFJ6iX/+Ffk8wbYfR4Eu7MXDg8ULT0z93yIvDxgy
|
||||||
|
uw==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw
|
||||||
|
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||||
|
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjAwOTA0MDAwMDAw
|
||||||
|
WhcNMjUwOTE1MTYwMDAwWjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg
|
||||||
|
RW5jcnlwdDELMAkGA1UEAxMCUjMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
|
||||||
|
AoIBAQC7AhUozPaglNMPEuyNVZLD+ILxmaZ6QoinXSaqtSu5xUyxr45r+XXIo9cP
|
||||||
|
R5QUVTVXjJ6oojkZ9YI8QqlObvU7wy7bjcCwXPNZOOftz2nwWgsbvsCUJCWH+jdx
|
||||||
|
sxPnHKzhm+/b5DtFUkWWqcFTzjTIUu61ru2P3mBw4qVUq7ZtDpelQDRrK9O8Zutm
|
||||||
|
NHz6a4uPVymZ+DAXXbpyb/uBxa3Shlg9F8fnCbvxK/eG3MHacV3URuPMrSXBiLxg
|
||||||
|
Z3Vms/EY96Jc5lP/Ooi2R6X/ExjqmAl3P51T+c8B5fWmcBcUr2Ok/5mzk53cU6cG
|
||||||
|
/kiFHaFpriV1uxPMUgP17VGhi9sVAgMBAAGjggEIMIIBBDAOBgNVHQ8BAf8EBAMC
|
||||||
|
AYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIGA1UdEwEB/wQIMAYB
|
||||||
|
Af8CAQAwHQYDVR0OBBYEFBQusxe3WFbLrlAJQOYfr52LFMLGMB8GA1UdIwQYMBaA
|
||||||
|
FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw
|
||||||
|
AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw
|
||||||
|
Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB
|
||||||
|
gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W
|
||||||
|
PTNlclQtgaDqw+34IL9fzLdwALduO/ZelN7kIJ+m74uyA+eitRY8kc607TkC53wl
|
||||||
|
ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz
|
||||||
|
CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm
|
||||||
|
lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4
|
||||||
|
avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2
|
||||||
|
yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O
|
||||||
|
yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids
|
||||||
|
hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+
|
||||||
|
HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv
|
||||||
|
MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX
|
||||||
|
nLRbwHOoq7hHwg==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFYDCCBEigAwIBAgIQQAF3ITfU6UK47naqPGQKtzANBgkqhkiG9w0BAQsFADA/
|
||||||
|
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
|
||||||
|
DkRTVCBSb290IENBIFgzMB4XDTIxMDEyMDE5MTQwM1oXDTI0MDkzMDE4MTQwM1ow
|
||||||
|
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||||
|
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwggIiMA0GCSqGSIb3DQEB
|
||||||
|
AQUAA4ICDwAwggIKAoICAQCt6CRz9BQ385ueK1coHIe+3LffOJCMbjzmV6B493XC
|
||||||
|
ov71am72AE8o295ohmxEk7axY/0UEmu/H9LqMZshftEzPLpI9d1537O4/xLxIZpL
|
||||||
|
wYqGcWlKZmZsj348cL+tKSIG8+TA5oCu4kuPt5l+lAOf00eXfJlII1PoOK5PCm+D
|
||||||
|
LtFJV4yAdLbaL9A4jXsDcCEbdfIwPPqPrt3aY6vrFk/CjhFLfs8L6P+1dy70sntK
|
||||||
|
4EwSJQxwjQMpoOFTJOwT2e4ZvxCzSow/iaNhUd6shweU9GNx7C7ib1uYgeGJXDR5
|
||||||
|
bHbvO5BieebbpJovJsXQEOEO3tkQjhb7t/eo98flAgeYjzYIlefiN5YNNnWe+w5y
|
||||||
|
sR2bvAP5SQXYgd0FtCrWQemsAXaVCg/Y39W9Eh81LygXbNKYwagJZHduRze6zqxZ
|
||||||
|
Xmidf3LWicUGQSk+WT7dJvUkyRGnWqNMQB9GoZm1pzpRboY7nn1ypxIFeFntPlF4
|
||||||
|
FQsDj43QLwWyPntKHEtzBRL8xurgUBN8Q5N0s8p0544fAQjQMNRbcTa0B7rBMDBc
|
||||||
|
SLeCO5imfWCKoqMpgsy6vYMEG6KDA0Gh1gXxG8K28Kh8hjtGqEgqiNx2mna/H2ql
|
||||||
|
PRmP6zjzZN7IKw0KKP/32+IVQtQi0Cdd4Xn+GOdwiK1O5tmLOsbdJ1Fu/7xk9TND
|
||||||
|
TwIDAQABo4IBRjCCAUIwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYw
|
||||||
|
SwYIKwYBBQUHAQEEPzA9MDsGCCsGAQUFBzAChi9odHRwOi8vYXBwcy5pZGVudHJ1
|
||||||
|
c3QuY29tL3Jvb3RzL2RzdHJvb3RjYXgzLnA3YzAfBgNVHSMEGDAWgBTEp7Gkeyxx
|
||||||
|
+tvhS5B1/8QVYIWJEDBUBgNVHSAETTBLMAgGBmeBDAECATA/BgsrBgEEAYLfEwEB
|
||||||
|
ATAwMC4GCCsGAQUFBwIBFiJodHRwOi8vY3BzLnJvb3QteDEubGV0c2VuY3J5cHQu
|
||||||
|
b3JnMDwGA1UdHwQ1MDMwMaAvoC2GK2h0dHA6Ly9jcmwuaWRlbnRydXN0LmNvbS9E
|
||||||
|
U1RST09UQ0FYM0NSTC5jcmwwHQYDVR0OBBYEFHm0WeZ7tuXkAXOACIjIGlj26Ztu
|
||||||
|
MA0GCSqGSIb3DQEBCwUAA4IBAQAKcwBslm7/DlLQrt2M51oGrS+o44+/yQoDFVDC
|
||||||
|
5WxCu2+b9LRPwkSICHXM6webFGJueN7sJ7o5XPWioW5WlHAQU7G75K/QosMrAdSW
|
||||||
|
9MUgNTP52GE24HGNtLi1qoJFlcDyqSMo59ahy2cI2qBDLKobkx/J3vWraV0T9VuG
|
||||||
|
WCLKTVXkcGdtwlfFRjlBz4pYg1htmf5X6DYO8A4jqv2Il9DjXA6USbW1FzXSLr9O
|
||||||
|
he8Y4IWS6wY7bCkjCWDcRQJMEhg76fsO3txE+FiYruq9RUWhiF1myv4Q6W+CyBFC
|
||||||
|
Dfvp7OOGAN6dEOM4+qR9sdjoSYKEBpsr6GtPAQw4dy753ec5
|
||||||
|
-----END CERTIFICATE-----
|
||||||
5
src/main/resources/privkey.pem
Normal file
5
src/main/resources/privkey.pem
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg9kCIfgqNqFYgYU0Q
|
||||||
|
HGi/jc5nLxhZxoXST5qeXBGtOAehRANCAASKtOgK5W+o2JPdHGqzK7b46YPtNgFb
|
||||||
|
4JX3rf05bgWHAdoXHLOgJYjf/DeBk1UT/ljUK/AcCzCp+5qbQuN9uco4
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.faf223.expensetrackerfaf.repository;
|
||||||
|
|
||||||
|
import com.faf223.expensetrackerfaf.model.Credential;
|
||||||
|
import com.faf223.expensetrackerfaf.model.User;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@DataJpaTest
|
||||||
|
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
||||||
|
class CredentialRepositoryTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CredentialRepository credentialRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
private User user;
|
||||||
|
private Credential credential;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
user = new User();
|
||||||
|
user.setFirstName("Hamon");
|
||||||
|
user.setLastName("User");
|
||||||
|
user.setUsername("UserHamon");
|
||||||
|
|
||||||
|
credential = Credential.builder()
|
||||||
|
.email("NewEmail@gmail.com")
|
||||||
|
.password("12345")
|
||||||
|
.user(user)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
userRepository.save(user);
|
||||||
|
credentialRepository.save(credential);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void findByEmail() {
|
||||||
|
// when
|
||||||
|
boolean exists = credentialRepository.findByUser(user).isPresent();
|
||||||
|
// then
|
||||||
|
assertThat(exists).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void itShouldCheckIfCredentialExistsByUser() {
|
||||||
|
// when
|
||||||
|
boolean exists = credentialRepository.findByUser(user).isPresent();
|
||||||
|
// then
|
||||||
|
assertThat(exists).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteByEmail() {
|
||||||
|
// when
|
||||||
|
credentialRepository.deleteByEmail(credential.getEmail());
|
||||||
|
boolean exists = credentialRepository.findByUser(user).isPresent();
|
||||||
|
// then
|
||||||
|
assertThat(exists).isFalse();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user