Merge branch 'master' into security_branch
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -22,6 +22,7 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>3.1.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.faf223.expensetrackerfaf.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.faf223.expensetrackerfaf.config;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class CorsFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
|
||||
response.setHeader("Access-Control-Allow-Origin", "http://localhost:5173");
|
||||
response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
response.setHeader("Access-Control-Allow-Headers", "X-Requested-With, X-Auth-Token");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
if (!"OPTIONS".equalsIgnoreCase(request.getMethod())) {
|
||||
chain.doFilter(req, res);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig config) {
|
||||
}
|
||||
}
|
||||
@@ -43,34 +43,7 @@ public class SecurityConfiguration {
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authenticationProvider(authenticationProvider)
|
||||
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); // will be executed before UsernamePasswordAuthenticationFilter
|
||||
// .oauth2Login(Customizer.withDefaults());
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientRegistrationRepository clientRegistrationRepository(
|
||||
@Value("${spring.security.oauth2.client.registration.google.client-id}") String clientId,
|
||||
@Value("${spring.security.oauth2.client.registration.google.client-secret}") String clientSecret) {
|
||||
|
||||
ClientRegistration registration = ClientRegistration.withRegistrationId("google")
|
||||
.clientId(clientId)
|
||||
.clientSecret(clientSecret)
|
||||
.clientName("Google")
|
||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
||||
.redirectUri("http://localhost:8081/login/oauth2/code/{registrationId}")
|
||||
.scope("openid", "profile", "email")
|
||||
.authorizationUri("https://accounts.google.com/o/oauth2/auth")
|
||||
.tokenUri("https://accounts.google.com/o/oauth2/token")
|
||||
.userInfoUri("https://www.googleapis.com/oauth2/v3/userinfo")
|
||||
.userNameAttributeName(IdTokenClaimNames.SUB)
|
||||
.build();
|
||||
|
||||
return new InMemoryClientRegistrationRepository(registration);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService() {
|
||||
return new DefaultOAuth2UserService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,18 @@ import com.faf223.expensetrackerfaf.dto.ExpenseCreationDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.ExpenseDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.mappers.ExpenseMapper;
|
||||
import com.faf223.expensetrackerfaf.model.Expense;
|
||||
import com.faf223.expensetrackerfaf.model.ExpenseCategory;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.service.ExpenseCategoryService;
|
||||
import com.faf223.expensetrackerfaf.service.ExpenseService;
|
||||
import com.faf223.expensetrackerfaf.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -20,12 +28,14 @@ import java.util.stream.Collectors;
|
||||
public class ExpenseController {
|
||||
|
||||
private final ExpenseService expenseService;
|
||||
private final UserService userService;
|
||||
private final ExpenseMapper expenseMapper;
|
||||
private final ExpenseCategoryService expenseCategoryService;
|
||||
|
||||
@GetMapping()
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public ResponseEntity<List<ExpenseDTO>> getAllExpenses() {
|
||||
List<ExpenseDTO> expenses = expenseService.getExpenses().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);
|
||||
else return ResponseEntity.notFound().build();
|
||||
}
|
||||
@@ -34,31 +44,58 @@ public class ExpenseController {
|
||||
public ResponseEntity<ExpenseDTO> createNewExpense(@RequestBody ExpenseCreationDTO expenseDTO,
|
||||
BindingResult bindingResult) {
|
||||
Expense expense = expenseMapper.toExpense(expenseDTO);
|
||||
if (!bindingResult.hasErrors()) {
|
||||
expenseService.createOrUpdateExpense(expense);
|
||||
return ResponseEntity.ok(expenseMapper.toDto(expense));
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
String email = userDetails.getUsername();
|
||||
User user = userService.getUserByEmail(email);
|
||||
expense.setUser(user);
|
||||
|
||||
expenseService.createOrUpdate(expense);
|
||||
ExpenseDTO createdExpenseDTO = expenseMapper.toDto(expense);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(createdExpenseDTO);
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
// TODO: has to be checked on auto extracting Uuid
|
||||
@PatchMapping()
|
||||
public ResponseEntity<ExpenseDTO> updateExpense(@RequestBody ExpenseCreationDTO expenseDTO,
|
||||
BindingResult bindingResult) {
|
||||
Expense expense = expenseMapper.toExpense(expenseDTO);
|
||||
if (!bindingResult.hasErrors()) {
|
||||
expenseService.createOrUpdateExpense(expense);
|
||||
expenseService.createOrUpdate(expense);
|
||||
return ResponseEntity.ok(expenseMapper.toDto(expense));
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{userUuid}")
|
||||
public ResponseEntity<List<ExpenseDTO>> getExpensesByUser(@PathVariable String userUuid) {
|
||||
List<ExpenseDTO> expenses = expenseService.getExpensesByUserId(userUuid).stream().map(expenseMapper::toDto).collect(Collectors.toList());
|
||||
if (!expenses.isEmpty()) return ResponseEntity.ok(expenses);
|
||||
@GetMapping("/personal-expenses")
|
||||
public ResponseEntity<List<ExpenseDTO>> getExpensesByUser() {
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
String email = userDetails.getUsername();
|
||||
List<ExpenseDTO> expenses = expenseService.getTransactionsByEmail(email).stream().map(expenseMapper::toDto).collect(Collectors.toList());
|
||||
|
||||
if (!expenses.isEmpty()) {
|
||||
return ResponseEntity.ok(expenses);
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@GetMapping("/categories")
|
||||
public ResponseEntity<List<ExpenseCategory>> getAllCategories() {
|
||||
List<ExpenseCategory> categories = expenseCategoryService.getAllCategories();
|
||||
if (!categories.isEmpty()) return ResponseEntity.ok(categories);
|
||||
else return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,18 @@ import com.faf223.expensetrackerfaf.dto.IncomeCreationDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.IncomeDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.mappers.IncomeMapper;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.service.IncomeCategoryService;
|
||||
import com.faf223.expensetrackerfaf.service.IncomeService;
|
||||
import com.faf223.expensetrackerfaf.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -20,12 +28,14 @@ import java.util.stream.Collectors;
|
||||
public class IncomeController {
|
||||
|
||||
private final IncomeService incomeService;
|
||||
private final UserService userService;
|
||||
private final IncomeMapper incomeMapper;
|
||||
private final IncomeCategoryService incomeCategoryService;
|
||||
|
||||
@GetMapping()
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public ResponseEntity<List<IncomeDTO>> getAllIncomes() {
|
||||
List<IncomeDTO> incomes = incomeService.getIncomes().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);
|
||||
else return ResponseEntity.notFound().build();
|
||||
}
|
||||
@@ -34,12 +44,21 @@ public class IncomeController {
|
||||
public ResponseEntity<IncomeDTO> createNewIncome(@RequestBody IncomeCreationDTO incomeDTO,
|
||||
BindingResult bindingResult) {
|
||||
Income income = incomeMapper.toIncome(incomeDTO);
|
||||
if (!bindingResult.hasErrors()) {
|
||||
incomeService.createOrUpdateIncome(income);
|
||||
return ResponseEntity.ok(incomeMapper.toDto(income));
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
String email = userDetails.getUsername();
|
||||
User user = userService.getUserByEmail(email);
|
||||
income.setUser(user);
|
||||
|
||||
System.out.println(income);
|
||||
incomeService.createOrUpdate(income);
|
||||
IncomeDTO createdIncomeDTO = incomeMapper.toDto(income);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(createdIncomeDTO);
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@PatchMapping()
|
||||
@@ -47,18 +66,35 @@ public class IncomeController {
|
||||
BindingResult bindingResult) {
|
||||
Income income = incomeMapper.toIncome(incomeDTO);
|
||||
if (!bindingResult.hasErrors()) {
|
||||
incomeService.createOrUpdateIncome(income);
|
||||
incomeService.createOrUpdate(income);
|
||||
return ResponseEntity.ok(incomeMapper.toDto(income));
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{userUuid}")
|
||||
public ResponseEntity<List<IncomeDTO>> getIncomesByUser(@PathVariable String userUuid) {
|
||||
List<IncomeDTO> incomes = incomeService.getIncomesByUserId(userUuid).stream().map(incomeMapper::toDto).collect(Collectors.toList());
|
||||
if (!incomes.isEmpty()) return ResponseEntity.ok(incomes);
|
||||
@GetMapping("/personal-incomes")
|
||||
public ResponseEntity<List<IncomeDTO>> getIncomesByUser() {
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
|
||||
String email = userDetails.getUsername();
|
||||
List<IncomeDTO> incomes = incomeService.getTransactionsByEmail(email).stream().map(incomeMapper::toDto).collect(Collectors.toList());
|
||||
|
||||
if (!incomes.isEmpty()) {
|
||||
return ResponseEntity.ok(incomes);
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@GetMapping("/categories")
|
||||
public ResponseEntity<List<IncomeCategory>> getAllCategories() {
|
||||
List<IncomeCategory> categories = incomeCategoryService.getAllCategories();
|
||||
if (!categories.isEmpty()) return ResponseEntity.ok(categories);
|
||||
else return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,9 @@ import com.faf223.expensetrackerfaf.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -33,11 +36,16 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{userUuid}")
|
||||
public ResponseEntity<UserDTO> getUser(@PathVariable String userUuid) {
|
||||
User user = userService.getUserById(userUuid);
|
||||
if (user != null) return ResponseEntity.ok(userMapper.toDto(user));
|
||||
else return ResponseEntity.notFound().build();
|
||||
@GetMapping("/getUserData")
|
||||
public ResponseEntity<UserDTO> getUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication != null && authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
User user = userService.getUserByEmail(userDetails.getUsername());
|
||||
if (user != null) return ResponseEntity.ok(userMapper.toDto(user));
|
||||
else return ResponseEntity.notFound().build();
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
|
||||
@@ -11,9 +11,6 @@ import java.time.LocalDate;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ExpenseCreationDTO {
|
||||
private long expenseId;
|
||||
private User user;
|
||||
private ExpenseCategory expenseCategory;
|
||||
private LocalDate date;
|
||||
private int expenseCategory;
|
||||
private BigDecimal amount;
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,4 @@ public class ExpenseDTO {
|
||||
private ExpenseCategory expenseCategory;
|
||||
private LocalDate date;
|
||||
private BigDecimal amount;
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,6 @@ import java.time.LocalDate;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class IncomeCreationDTO {
|
||||
private long incomeId;
|
||||
private User user;
|
||||
private IncomeCategory category;
|
||||
private LocalDate date;
|
||||
private int incomeCategory;
|
||||
private BigDecimal amount;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.time.LocalDate;
|
||||
public class IncomeDTO {
|
||||
private long incomeId;
|
||||
private UserDTO userDTO;
|
||||
private IncomeCategory category;
|
||||
private IncomeCategory incomeCategory;
|
||||
private LocalDate date;
|
||||
private BigDecimal amount;
|
||||
}
|
||||
}
|
||||
@@ -3,32 +3,35 @@ package com.faf223.expensetrackerfaf.dto.mappers;
|
||||
import com.faf223.expensetrackerfaf.dto.ExpenseCreationDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.ExpenseDTO;
|
||||
import com.faf223.expensetrackerfaf.model.Expense;
|
||||
import com.faf223.expensetrackerfaf.service.ExpenseCategoryService;
|
||||
import com.faf223.expensetrackerfaf.service.ExpenseService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Component
|
||||
public class ExpenseMapper {
|
||||
|
||||
private final ExpenseService expenseService;
|
||||
private final ExpenseCategoryService expenseCategoryService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
public ExpenseMapper(ExpenseService expenseService, UserMapper userMapper) {
|
||||
public ExpenseMapper(ExpenseService expenseService, ExpenseCategoryService expenseCategoryService, UserMapper userMapper) {
|
||||
this.expenseService = expenseService;
|
||||
this.expenseCategoryService = expenseCategoryService;
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
public ExpenseDTO toDto(Expense expense) {
|
||||
return new ExpenseDTO(expense.getExpenseId(), userMapper.toDto(expense.getUser()),
|
||||
return new ExpenseDTO(expense.getId(), userMapper.toDto(expense.getUser()),
|
||||
expense.getCategory(), expense.getDate(), expense.getAmount());
|
||||
}
|
||||
|
||||
public Expense toExpense(ExpenseCreationDTO expenseDTO) {
|
||||
Expense expense = expenseService.getExpenseById(expenseDTO.getExpenseId());
|
||||
if(expense == null) return new Expense(expenseDTO.getExpenseId(), expenseDTO.getUser(),
|
||||
expenseDTO.getExpenseCategory(), expenseDTO.getDate(), expenseDTO.getAmount());
|
||||
return expense;
|
||||
|
||||
return new Expense(expenseCategoryService.getCategoryById(expenseDTO.getExpenseCategory()), LocalDate.now(), expenseDTO.getAmount());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,32 +4,34 @@ import com.faf223.expensetrackerfaf.dto.IncomeCreationDTO;
|
||||
import com.faf223.expensetrackerfaf.dto.IncomeDTO;
|
||||
import com.faf223.expensetrackerfaf.model.Expense;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.service.IncomeCategoryService;
|
||||
import com.faf223.expensetrackerfaf.service.IncomeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Component
|
||||
public class IncomeMapper {
|
||||
|
||||
private final IncomeService incomeService;
|
||||
private final IncomeCategoryService incomeCategoryService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
public IncomeMapper(IncomeService incomeService, UserMapper userMapper) {
|
||||
public IncomeMapper(IncomeService incomeService, IncomeCategoryService incomeCategoryService, UserMapper userMapper) {
|
||||
this.incomeService = incomeService;
|
||||
this.incomeCategoryService = incomeCategoryService;
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
public IncomeDTO toDto(Income income) {
|
||||
return new IncomeDTO(income.getIncomeId(), userMapper.toDto(income.getUser()),
|
||||
return new IncomeDTO(income.getId(), userMapper.toDto(income.getUser()),
|
||||
income.getCategory(), income.getDate(), income.getAmount());
|
||||
}
|
||||
|
||||
public Income toIncome(IncomeCreationDTO incomeDTO) {
|
||||
Income income = incomeService.getIncomeById(incomeDTO.getIncomeId());
|
||||
if(income == null) return new Income(incomeDTO.getIncomeId(), incomeDTO.getUser(),
|
||||
incomeDTO.getCategory(), incomeDTO.getDate(), incomeDTO.getAmount());
|
||||
return income;
|
||||
return new Income(incomeCategoryService.getCategoryById(incomeDTO.getIncomeCategory()), LocalDate.now(), incomeDTO.getAmount());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,35 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Entity(name = "credentials")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Credential {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long credentialId;
|
||||
@Data
|
||||
@Entity(name = "credentials")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Credential {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long credentialId;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_uuid")
|
||||
private User user;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_uuid")
|
||||
private User user;
|
||||
|
||||
private String email;
|
||||
private String password;
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Role role;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Role role;
|
||||
|
||||
public Credential(User user, String email, String password) {
|
||||
this.user = user;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
public Credential(User user, String email, String password) {
|
||||
this.user = user;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
|
||||
this.role = Role.ROLE_USER;
|
||||
}
|
||||
this.role = Role.ROLE_USER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
@@ -13,10 +10,11 @@ import java.time.LocalDate;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity(name = "expenses")
|
||||
public class Expense {
|
||||
public class Expense implements IMoneyTransaction {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long expenseId;
|
||||
@Column(name = "expense_id")
|
||||
private Long id;
|
||||
|
||||
@ManyToOne()
|
||||
@JoinColumn(name = "user_uuid")
|
||||
@@ -30,5 +28,13 @@ public class Expense {
|
||||
|
||||
private LocalDate date;
|
||||
private BigDecimal amount;
|
||||
}
|
||||
|
||||
public Expense(LocalDate date, BigDecimal amount) {
|
||||
}
|
||||
|
||||
public Expense(ExpenseCategory expenseCategory, LocalDate date, BigDecimal amount) {
|
||||
this.category = expenseCategory;
|
||||
this.date = date;
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity(name = "expense_categories")
|
||||
public class ExpenseCategory {
|
||||
public class ExpenseCategory implements IMoneyTransactionCategory {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long categoryId;
|
||||
@Column(name = "category_id")
|
||||
private Long id;
|
||||
|
||||
private String categoryName;
|
||||
@Column(name = "category_name")
|
||||
private String name;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public interface IMoneyTransaction {
|
||||
|
||||
Long getId();
|
||||
LocalDate getDate();
|
||||
User getUser();
|
||||
BigDecimal getAmount();
|
||||
IMoneyTransactionCategory getCategory();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
public interface IMoneyTransactionCategory {
|
||||
Long getId();
|
||||
String getName();
|
||||
}
|
||||
@@ -2,10 +2,8 @@ package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -13,10 +11,11 @@ import java.time.LocalDate;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity(name = "incomes")
|
||||
public class Income {
|
||||
public class Income implements IMoneyTransaction {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long incomeId;
|
||||
@Column(name = "income_id")
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_uuid")
|
||||
@@ -30,4 +29,10 @@ public class Income {
|
||||
|
||||
private LocalDate date;
|
||||
private BigDecimal amount;
|
||||
|
||||
public Income(IncomeCategory incomeCategory, LocalDate date, BigDecimal amount) {
|
||||
this.category = incomeCategory;
|
||||
this.date = date;
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity(name = "income_categories")
|
||||
public class IncomeCategory {
|
||||
public class IncomeCategory implements IMoneyTransactionCategory {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long categoryId;
|
||||
@Column(name = "category_id")
|
||||
private Long id;
|
||||
|
||||
private String categoryName;
|
||||
@Column(name = "category_name")
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
public enum Role {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.ExpenseCategory;
|
||||
import com.faf223.expensetrackerfaf.repository.ExpenseCategoryRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ExpenseCategoryService implements ICategoryService {
|
||||
|
||||
private final ExpenseCategoryRepository expenseCategoryRepository;
|
||||
|
||||
@Override
|
||||
public List<ExpenseCategory> getAllCategories() {
|
||||
return expenseCategoryRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpenseCategory getCategoryById(long id) {
|
||||
return expenseCategoryRepository.getReferenceById(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.model.Expense;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.ExpenseRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -14,30 +14,30 @@ import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ExpenseService {
|
||||
public class ExpenseService implements ITransactionService {
|
||||
|
||||
private final ExpenseRepository expenseRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final CredentialRepository credentialRepository;
|
||||
|
||||
public void createOrUpdateExpense(Expense expense) {
|
||||
expenseRepository.save(expense);
|
||||
public void createOrUpdate(IMoneyTransaction expense) {
|
||||
expenseRepository.save((Expense) expense);
|
||||
}
|
||||
|
||||
public List<Expense> getExpensesByUserId(String userUuid) {
|
||||
public List<Expense> getTransactionsByEmail(String email) {
|
||||
|
||||
Optional<User> user = userRepository.getUserByUserUuid(userUuid);
|
||||
if (user.isPresent()) {
|
||||
return expenseRepository.findByUser(user.get());
|
||||
Optional<Credential> credential = credentialRepository.findByEmail(email);
|
||||
if (credential.isPresent()) {
|
||||
return expenseRepository.findByUser(credential.get().getUser());
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<Expense> getExpenses() {
|
||||
public List<Expense> getTransactions() {
|
||||
return expenseRepository.findAll();
|
||||
}
|
||||
|
||||
public Expense getExpenseById(long id) {
|
||||
public Expense getTransactionById(long id) {
|
||||
return expenseRepository.findById(id).orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransactionCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ICategoryService {
|
||||
|
||||
List<? extends IMoneyTransactionCategory> getAllCategories();
|
||||
IMoneyTransactionCategory getCategoryById(long id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ITransactionService {
|
||||
|
||||
void createOrUpdate(IMoneyTransaction transaction);
|
||||
List<? extends IMoneyTransaction> getTransactions();
|
||||
List<? extends IMoneyTransaction> getTransactionsByEmail(String email);
|
||||
IMoneyTransaction getTransactionById(long id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.IncomeCategory;
|
||||
import com.faf223.expensetrackerfaf.repository.IncomeCategoryRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class IncomeCategoryService implements ICategoryService {
|
||||
|
||||
private final IncomeCategoryRepository incomeCategoryRepository;
|
||||
|
||||
@Override
|
||||
public List<IncomeCategory> getAllCategories() {
|
||||
return incomeCategoryRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomeCategory getCategoryById(long id) {
|
||||
return incomeCategoryRepository.getReferenceById(id);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.IncomeRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -14,30 +14,30 @@ import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class IncomeService {
|
||||
public class IncomeService implements ITransactionService {
|
||||
|
||||
private final IncomeRepository incomeRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final CredentialRepository credentialRepository;
|
||||
|
||||
public void createOrUpdateIncome(Income income) {
|
||||
incomeRepository.save(income);
|
||||
public void createOrUpdate(IMoneyTransaction income) {
|
||||
incomeRepository.save((Income) income);
|
||||
}
|
||||
|
||||
public List<Income> getIncomes() {
|
||||
public List<Income> getTransactions() {
|
||||
return incomeRepository.findAll();
|
||||
}
|
||||
|
||||
public List<Income> getIncomesByUserId(String userUuid) {
|
||||
public List<Income> getTransactionsByEmail(String email) {
|
||||
|
||||
Optional<User> user = userRepository.getUserByUserUuid(userUuid);
|
||||
if (user.isPresent()) {
|
||||
return incomeRepository.findByUser(user.get());
|
||||
Optional<Credential> credential = credentialRepository.findByEmail(email);
|
||||
if (credential.isPresent()) {
|
||||
return incomeRepository.findByUser(credential.get().getUser());
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public Income getIncomeById(long id) {
|
||||
public Income getTransactionById(long id) {
|
||||
return incomeRepository.findById(id).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
import com.faf223.expensetrackerfaf.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final CredentialRepository credentialRepository;
|
||||
|
||||
public void updateUser(User user) {
|
||||
userRepository.save(user);
|
||||
@@ -24,4 +28,12 @@ public class UserService {
|
||||
public User getUserById(String userUuid) {
|
||||
return userRepository.findById(userUuid).orElse(null);
|
||||
}
|
||||
public User getUserByEmail(String email) {
|
||||
Optional<Credential> credential = credentialRepository.findByEmail(email);
|
||||
if (credential.isPresent()) {
|
||||
Optional<User> user = userRepository.findById(credential.get().getUser().getUserUuid());
|
||||
return user.orElse(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.faf223.expensetrackerfaf.util;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
|
||||
public interface IMoneyTransaction {
|
||||
|
||||
User getUser();
|
||||
int getAmount();
|
||||
String getCategory();
|
||||
|
||||
}
|
||||
@@ -10,9 +10,13 @@
|
||||
"dependencies": {
|
||||
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
||||
"axios": "^1.5.1",
|
||||
"chart.js": "^4.4.0",
|
||||
"email-validator": "^2.0.4",
|
||||
"svelte-fa": "^3.0.4"
|
||||
"js-cookie": "^3.0.5",
|
||||
"svelte-cookie": "^1.0.1",
|
||||
"svelte-fa": "^3.0.4",
|
||||
"svelte-spa-router": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fontsource/fira-mono": "^4.5.10",
|
||||
@@ -810,6 +814,21 @@
|
||||
"dequal": "^2.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz",
|
||||
"integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/axobject-query": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz",
|
||||
@@ -902,6 +921,17 @@
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@@ -988,6 +1018,14 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dequal": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz",
|
||||
@@ -1349,6 +1387,38 @@
|
||||
"integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.3",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz",
|
||||
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
@@ -1548,6 +1618,14 @@
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/js-cookie": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
|
||||
"integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
@@ -1693,6 +1771,25 @@
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/minimatch": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
|
||||
@@ -2011,6 +2108,11 @@
|
||||
"svelte": "^3.2.0 || ^4.0.0-next.0"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"node_modules/punycode": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz",
|
||||
@@ -2040,6 +2142,14 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/regexparam": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/regexparam/-/regexparam-2.0.1.tgz",
|
||||
"integrity": "sha512-zRgSaYemnNYxUv+/5SeoHI0eJIgTL/A2pUtXUPLHQxUldagouJ9p+K6IbIZ/JiQuCEv2E2B1O11SjVQy3aMCkw==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/resolve-from": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
||||
@@ -2250,6 +2360,11 @@
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/svelte-cookie": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/svelte-cookie/-/svelte-cookie-1.0.1.tgz",
|
||||
"integrity": "sha512-c4cXLMeG7vlAk3Q5axjxlppMJgeLLWd/6cCvo1wEL6ZwEueVHAP71SBRi9r5XmLYnCYr7eAqlK6NrYT/29KuKQ=="
|
||||
},
|
||||
"node_modules/svelte-eslint-parser": {
|
||||
"version": "0.33.1",
|
||||
"resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.33.1.tgz",
|
||||
@@ -2294,6 +2409,17 @@
|
||||
"svelte": "^3.19.0 || ^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/svelte-spa-router": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/svelte-spa-router/-/svelte-spa-router-3.3.0.tgz",
|
||||
"integrity": "sha512-cwRNe7cxD43sCvSfEeaKiNZg3FCizGxeMcf7CPiWRP3jKXjEma3vxyyuDtPOam6nWbVxl9TNM3hlE/i87ZlqcQ==",
|
||||
"dependencies": {
|
||||
"regexparam": "2.0.1"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ItalyPaleAle"
|
||||
}
|
||||
},
|
||||
"node_modules/text-table": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
|
||||
|
||||
@@ -26,8 +26,12 @@
|
||||
"dependencies": {
|
||||
"@fortawesome/free-brands-svg-icons": "^6.4.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
||||
"axios": "^1.5.1",
|
||||
"chart.js": "^4.4.0",
|
||||
"email-validator": "^2.0.4",
|
||||
"svelte-fa": "^3.0.4"
|
||||
"js-cookie": "^3.0.5",
|
||||
"svelte-cookie": "^1.0.1",
|
||||
"svelte-fa": "^3.0.4",
|
||||
"svelte-spa-router": "^3.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 28 KiB |
@@ -1,29 +1,58 @@
|
||||
<script>
|
||||
import * as EmailValidator from 'email-validator';
|
||||
import axios from "axios";
|
||||
import {onMount} from "svelte";
|
||||
import { getCookie, setCookie } from 'svelte-cookie';
|
||||
|
||||
let isErrorVisible = false;
|
||||
let username, password;
|
||||
let message = ""
|
||||
|
||||
function submitForm(event) {
|
||||
onMount(async () => {
|
||||
console.log("Mounted");
|
||||
const access_token = getCookie('access_token');
|
||||
const refresh_token = getCookie('refresh_token');
|
||||
if (access_token && refresh_token) {
|
||||
window.location.href = '/dashboard';
|
||||
}
|
||||
});
|
||||
|
||||
async function submitForm(event) {
|
||||
event.preventDefault();
|
||||
console.log("Tried to submit!");
|
||||
console.log("Valid? ", (validateEmail() && validatePassword() ? "Yes" : "No"));
|
||||
console.log(username);
|
||||
console.log(password);
|
||||
try {
|
||||
const response = await axios.post('http://localhost:8081/api/v1/auth/authenticate', {
|
||||
email: username,
|
||||
password: password,
|
||||
});
|
||||
|
||||
const { access_token, refresh_token } = response.data;
|
||||
|
||||
// Save the tokens in cookies
|
||||
setCookie('access_token', access_token);
|
||||
setCookie('refresh_token', refresh_token);
|
||||
console.log(access_token, refresh_token);
|
||||
window.location.href = '/dashboard'
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function validateEmail() {
|
||||
let valid = EmailValidator.validate(username);
|
||||
isErrorVisible = valid ? false : true;
|
||||
message = isErrorVisible ? "Invalid e-mail!" : "";
|
||||
return valid;
|
||||
}
|
||||
|
||||
function validatePassword() {
|
||||
let valid = password.value != '';
|
||||
isErrorVisible = valid ? false : true;
|
||||
message = isErrorVisible ? "Invalid password!" : "";
|
||||
return valid;
|
||||
}
|
||||
// function validateEmail() {
|
||||
// let valid = EmailValidator.validate(username);
|
||||
// isErrorVisible = !valid;
|
||||
// message = isErrorVisible ? "Invalid e-mail!" : "";
|
||||
// return valid;
|
||||
// }
|
||||
//
|
||||
// function validatePassword() {
|
||||
// let valid = password.value !== '';
|
||||
// isErrorVisible = !valid;
|
||||
// message = isErrorVisible ? "Invalid password!" : "";
|
||||
// return valid;
|
||||
// }
|
||||
|
||||
</script>
|
||||
|
||||
@@ -39,7 +68,7 @@
|
||||
event => {username = event.target.value}
|
||||
}>
|
||||
<input id="passwordInput" type="password" name="password" placeholder="Password" autocomplete="off" on:input={
|
||||
event => {password = event.target.password}
|
||||
event => {password = event.target.value}
|
||||
}>
|
||||
<a href="/auth/recovery" class="recoveryPass">Forgot your password?</a>
|
||||
<input type="submit" value="Sign in" class="submitButton">
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
function submitForm(event) {
|
||||
event.preventDefault();
|
||||
console.log("Tried to submit!");
|
||||
console.log("Valid? ", (validateEmail() && validateUsername() && va && validatePassword() ? "Yes" : "No"));
|
||||
console.log("Valid? ", (validateEmail() && validateUsername() && validatePassword() ? "Yes" : "No"));
|
||||
}
|
||||
|
||||
function validateEmail() {
|
||||
|
||||
@@ -16,5 +16,6 @@
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
min-height: 100vh;
|
||||
max-height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -2,7 +2,14 @@
|
||||
import DashHeader from "./DashHeader.svelte";
|
||||
import DataMenu from "./DataMenu.svelte";
|
||||
import QuickInfobar from "./QuickInfobar.svelte";
|
||||
import NotificationBoard from "./NotificationBoard.svelte";
|
||||
import { getCookie } from "svelte-cookie";
|
||||
import {onMount} from "svelte";
|
||||
|
||||
onMount(() => {
|
||||
if (getCookie('access_token') === null ) {
|
||||
window.location.href = '/auth/login';
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<div id="dashboard">
|
||||
@@ -17,7 +24,7 @@
|
||||
background-color: rgb(245,242,243);
|
||||
border-radius: 20px;
|
||||
margin: 20px;
|
||||
min-width: 100px;
|
||||
min-width: 100px;
|
||||
display: flex;
|
||||
flex:1 1 auto;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
import Graph1 from './graphs/Graph1.svelte';
|
||||
import Graph2 from './graphs/Graph2.svelte';
|
||||
import Graph3 from './graphs/Graph3.svelte';
|
||||
import Graph4 from './graphs/Graph4.svelte';
|
||||
import Graph5 from './graphs/Graph5.svelte';
|
||||
import Expenses from "./Expenses.svelte";
|
||||
import Incomes from "./Incomes.svelte";
|
||||
</script>
|
||||
|
||||
<div id="dataMenu">
|
||||
@@ -14,9 +14,9 @@
|
||||
<div id="oneVertical">
|
||||
<Graph3 />
|
||||
</div>
|
||||
<div id="twoHorizontal">
|
||||
<Graph4 />
|
||||
<Graph5 />
|
||||
<div id="dataPanel">
|
||||
<Incomes />
|
||||
<Expenses />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
#twoVertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -53,9 +52,9 @@
|
||||
min-height:0;
|
||||
}
|
||||
|
||||
#twoHorizontal {
|
||||
#dataPanel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-direction: row;
|
||||
align-self: stretch;
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<script>
|
||||
import { onMount, afterUpdate } from 'svelte';
|
||||
import axios from 'axios';
|
||||
import { getCookie } from "svelte-cookie";
|
||||
|
||||
let data = [];
|
||||
let parentHeight;
|
||||
|
||||
onMount(async () => {
|
||||
const token = getCookie('access_token');
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8081/expenses/personal-expenses', config);
|
||||
data = response.data;
|
||||
parentHeight = document.querySelector('#expenseInfo').offsetHeight;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
afterUpdate(() => {
|
||||
parentHeight = document.querySelector('#expenseInfo').offsetHeight;
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="expenseInfo" style="max-height: {parentHeight}px;">
|
||||
<h2 id="text">Expenses</h2>
|
||||
<div id="expenseList">
|
||||
<ul>
|
||||
{#each data 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>
|
||||
#text {
|
||||
padding: 0 0 10px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#expenseInfo {
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
overflow-y: auto;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
h2 {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
#expenseList {
|
||||
margin-top: 10px;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
#expenseList::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
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>
|
||||
@@ -0,0 +1,92 @@
|
||||
<script>
|
||||
import { onMount, afterUpdate } from 'svelte';
|
||||
import axios from 'axios';
|
||||
import { getCookie } from "svelte-cookie";
|
||||
|
||||
let data = [];
|
||||
let parentHeight;
|
||||
|
||||
onMount(async () => {
|
||||
const token = getCookie('access_token');
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8081/incomes/personal-incomes', config);
|
||||
data = response.data;
|
||||
parentHeight = document.querySelector('#incomeInfo').offsetHeight;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
|
||||
afterUpdate(() => {
|
||||
parentHeight = document.querySelector('#incomeInfo').offsetHeight;
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="incomeInfo" style="max-height: {parentHeight}px;">
|
||||
<h2 id="text">Incomes</h2>
|
||||
<div id="incomeList">
|
||||
<ul>
|
||||
{#each data 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>
|
||||
#text {
|
||||
padding: 0 0 10px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#incomeInfo {
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
margin: 10px;
|
||||
overflow-y: auto;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
h2 {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
#incomeList {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
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,15 +0,0 @@
|
||||
<script>
|
||||
|
||||
</script>
|
||||
|
||||
<div id="notificationBoard">
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#notificationBoard {
|
||||
display: none;
|
||||
width:0;
|
||||
height:0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,12 +1,46 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import axios from 'axios';
|
||||
import { getCookie } from "svelte-cookie";
|
||||
|
||||
let infobar1, infobar2, infobar3, infobar4;
|
||||
let totalExpenses = 0;
|
||||
let totalIncomes = 0;
|
||||
|
||||
onMount(async () => {
|
||||
const token = getCookie('access_token');
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const [incomesResponse, expensesResponse] = await Promise.all([
|
||||
axios.get('http://localhost:8081/incomes/personal-incomes', config),
|
||||
axios.get('http://localhost:8081/expenses/personal-expenses', config)
|
||||
]);
|
||||
|
||||
const incomesData = incomesResponse.data;
|
||||
const expensesData = expensesResponse.data;
|
||||
|
||||
totalExpenses = expensesData.reduce((total, item) => total + item.amount, 0);
|
||||
totalIncomes = incomesData.reduce((total, item) => total + item.amount, 0);
|
||||
|
||||
infobar1.innerHTML = `<span style="font-size: larger">Total expenses:</span><br><span style="color:red;font-size: xxx-large">${totalExpenses}$`;
|
||||
infobar2.innerHTML = `<span style="font-size: larger">Total incomes:</span><br><span style="color:green;font-size: xxx-large">${totalIncomes}$</span>`;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="quickInfobar">
|
||||
<div class="infobarElement">Income for this month 50$</div>
|
||||
<div class="infobarElement">Expense for this month 40$</div>
|
||||
<div class="infobarElement">Income for this month 50$</div>
|
||||
<div class="infobarElement">Expense for this month 40$</div>
|
||||
<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>
|
||||
@@ -21,17 +55,15 @@
|
||||
width: 200px;
|
||||
min-width: 100px;
|
||||
height: 100px;
|
||||
color:white;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
background-color: #ffdde2;
|
||||
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);
|
||||
/* border: 1px solid black; */
|
||||
}
|
||||
|
||||
.infobarElement:hover {
|
||||
/* color:white; */
|
||||
/* background-color: black; */
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,30 +1,49 @@
|
||||
<script>
|
||||
import Chart from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
import axios from 'axios';
|
||||
import {getCookie} from "svelte-cookie";
|
||||
|
||||
let chartValues = [20, 10, 5, 2, 20, 30, 45];
|
||||
let chartLabels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
|
||||
onMount(async () => {
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
|
||||
const token = getCookie('access_token');
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8081/incomes/personal-incomes', config);
|
||||
console.log(response.data);
|
||||
const incomeData = response.data;
|
||||
|
||||
const chartLabels = incomeData.map(item => item.incomeCategory.name);
|
||||
const chartValues = incomeData.map(item => item.amount);
|
||||
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
label: 'Revenue',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: chartValues
|
||||
}]
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
label: 'Revenue',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
data: chartValues
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -34,15 +53,15 @@
|
||||
|
||||
<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);
|
||||
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: #ffdde2;
|
||||
}
|
||||
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>
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,48 +1,70 @@
|
||||
<script>
|
||||
import chartjs from 'chart.js/auto';
|
||||
import Chart from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
import axios from 'axios';
|
||||
import {getCookie} from "svelte-cookie";
|
||||
|
||||
var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
||||
var config = {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
||||
datasets: [{
|
||||
fill: false,
|
||||
data: [
|
||||
5,
|
||||
6,
|
||||
3,
|
||||
4
|
||||
]
|
||||
}, {
|
||||
label: "My Second dataset ",
|
||||
fill: false,
|
||||
data: [
|
||||
5,
|
||||
6,
|
||||
3,
|
||||
4
|
||||
]
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
title:{
|
||||
display:true,
|
||||
text: "Chart.js Line Chart - Animation Progress Bar"
|
||||
},
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
};
|
||||
|
||||
let chartValues = [20, 10, 5, 2, 20, 30, 45];
|
||||
let chartLabels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
|
||||
onMount(async (promise) => {
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
var chart = new chartjs(ctx, config);
|
||||
onMount(async () => {
|
||||
|
||||
const token = getCookie('access_token');
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8081/expenses/personal-expenses', config);
|
||||
|
||||
const aggregatedData = {};
|
||||
|
||||
response.data.forEach(item => {
|
||||
const category = item.expenseCategory.name;
|
||||
const amount = item.amount;
|
||||
|
||||
if (aggregatedData[category]) {
|
||||
aggregatedData[category] += amount;
|
||||
} else {
|
||||
aggregatedData[category] = amount;
|
||||
}
|
||||
});
|
||||
|
||||
const chartLabels = Object.keys(aggregatedData);
|
||||
const chartValues = Object.values(aggregatedData);
|
||||
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
label: 'Revenue',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
data: chartValues
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
legend: {
|
||||
display: false
|
||||
},
|
||||
tooltips: {
|
||||
callbacks: {
|
||||
label: (tooltipItem) => {
|
||||
return tooltipItem.yLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -52,15 +74,15 @@
|
||||
|
||||
<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: #ffdde2;
|
||||
}
|
||||
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>
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,45 +1,55 @@
|
||||
<script>
|
||||
import chartjs from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
|
||||
var randomScalingFactor = function() {
|
||||
return Math.round(Math.random() * 100);
|
||||
};
|
||||
|
||||
var config = {
|
||||
type: 'pie',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: [
|
||||
randomScalingFactor(),
|
||||
randomScalingFactor(),
|
||||
randomScalingFactor(),
|
||||
randomScalingFactor(),
|
||||
randomScalingFactor(),
|
||||
],
|
||||
label: 'Dataset 1'
|
||||
}],
|
||||
labels: [
|
||||
"Red",
|
||||
"Orange",
|
||||
"Yellow",
|
||||
"Green",
|
||||
"Blue"
|
||||
]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
};
|
||||
import axios from 'axios';
|
||||
import { getCookie } from "svelte-cookie";
|
||||
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
|
||||
onMount(async (promise) => {
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
var chart = new chartjs(ctx, config);
|
||||
onMount(async () => {
|
||||
const token = getCookie('access_token');
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const [incomesResponse, expensesResponse] = await Promise.all([
|
||||
axios.get('http://localhost:8081/incomes/personal-incomes', config),
|
||||
axios.get('http://localhost:8081/expenses/personal-expenses', config)
|
||||
]);
|
||||
|
||||
const incomesData = incomesResponse.data;
|
||||
const expensesData = expensesResponse.data;
|
||||
|
||||
const totalIncomes = incomesData.reduce((total, item) => total + item.amount, 0);
|
||||
|
||||
const totalExpenses = expensesData.reduce((total, item) => total + item.amount, 0);
|
||||
|
||||
const chartLabels = ['Incomes', 'Expenses'];
|
||||
const chartValues = [totalIncomes, totalExpenses];
|
||||
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
new chartjs(ctx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
data: chartValues,
|
||||
backgroundColor: ['green', 'red'],
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -49,15 +59,15 @@
|
||||
|
||||
<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: #ffdde2;
|
||||
}
|
||||
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>
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<script>
|
||||
import chartjs from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let chartValues = [20, 10, 5, 2, 20, 30, 45];
|
||||
let chartLabels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
|
||||
onMount(async (promise) => {
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
var chart = new chartjs(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
label: 'Revenue',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: chartValues
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
});
|
||||
</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: #ffdde2;
|
||||
}
|
||||
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,48 +0,0 @@
|
||||
<script>
|
||||
import chartjs from 'chart.js/auto';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let chartValues = [20, 10, 5, 2, 20, 30, 45];
|
||||
let chartLabels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
||||
let ctx;
|
||||
let chartCanvas;
|
||||
|
||||
onMount(async (promise) => {
|
||||
ctx = chartCanvas.getContext('2d');
|
||||
var chart = new chartjs(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
label: 'Revenue',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: chartValues
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
});
|
||||
</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: #ffdde2;
|
||||
}
|
||||
|
||||
#chart:hover {
|
||||
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||
}
|
||||
</style>
|
||||
@@ -1,4 +1,29 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import axios from 'axios';
|
||||
import {deleteCookie, getCookie} from "svelte-cookie";
|
||||
|
||||
let username;
|
||||
|
||||
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>
|
||||
|
||||
@@ -37,7 +62,24 @@
|
||||
</div>
|
||||
|
||||
<div id="profileSpace">
|
||||
<div id="profileInfo">Profile Info</div>
|
||||
<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>
|
||||
|
||||
@@ -81,15 +123,28 @@
|
||||
}
|
||||
|
||||
#iconImg {
|
||||
max-width: 100px;
|
||||
max-width: 150px;
|
||||
}
|
||||
|
||||
#profileSpace {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
color:white;
|
||||
flex-direction: column;
|
||||
align-items: 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>
|
||||
Reference in New Issue
Block a user