Skip to content

Commit

Permalink
all files updated
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuazof committed Jul 9, 2024
1 parent 0aa08cf commit c8fcba4
Show file tree
Hide file tree
Showing 88 changed files with 11,563 additions and 2,014 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
19 changes: 19 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip
8,586 changes: 8,586 additions & 0 deletions effective-pom.xml

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0</version>
<relativePath/> <!-- lookup parent from repository -->
<version>3.3.1</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.alkewallet6</groupId>
<artifactId>alkewallet6</artifactId>
Expand All @@ -15,7 +15,7 @@
<name>alkewallet6</name>
<description>Billetera Digital</description>
<properties>
<java.version>21</java.version>
<java.version>22</java.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -25,6 +25,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -42,7 +43,11 @@
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand All @@ -62,7 +67,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -75,12 +80,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>6.3.0</version>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>6.3.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -97,5 +101,4 @@
</plugin>
</plugins>
</build>

</project>
16 changes: 14 additions & 2 deletions src/main/java/com/alkewallet6/Alkewallet6Application.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package com.alkewallet6;

import java.util.Arrays;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Alkewallet6Application {
public class AlkeWallet6Application {

public static void main(String[] args) {
SpringApplication.run(Alkewallet6Application.class, args);

ApplicationContext ctx = SpringApplication.run(AlkeWallet6Application.class, args);

System.out.println("Let's inspect the beans provided by Spring Boot:");

String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
13 changes: 0 additions & 13 deletions src/main/java/com/alkewallet6/ServletInitializer.java

This file was deleted.

64 changes: 0 additions & 64 deletions src/main/java/com/alkewallet6/connection/DBConnection.java

This file was deleted.

48 changes: 48 additions & 0 deletions src/main/java/com/alkewallet6/controller/ContactController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.alkewallet6.controller;

import com.alkewallet6.model.DTO.ContactDTO;
import com.alkewallet6.model.entity.ContactEntity;
import com.alkewallet6.service.interfaces.IContactService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class ContactController {

@Autowired
private IContactService contactService;

@PostMapping("/registerContact")
public String createContact(@ModelAttribute("contactDTO")ContactDTO contactDTO, @RequestParam("userId") Long userId,RedirectAttributes redirectAttributes){
try{
contactService.save(contactDTO, userId);
redirectAttributes.addFlashAttribute("message","Contacto Registrado");
}catch (RuntimeException e){
redirectAttributes.addFlashAttribute("messageContact",e.getMessage());
}
redirectAttributes.addAttribute("id",userId);
return "redirect:/transfer/{id}";
}

@PostMapping("/selectContact/{userId}")
public String manageContact(@PathVariable Long userId, @RequestParam(value = "selectedContactId", required = false) Long selectedContactId, @RequestParam(value = "deleteContact", required = false) String deleteContact, RedirectAttributes redirectAttributes,HttpSession session) {
if ("delete".equals(deleteContact)) {
if (selectedContactId != null) {
contactService.deleteContact(selectedContactId);
redirectAttributes.addFlashAttribute("message", "Contacto eliminado correctamente");
} else {
redirectAttributes.addFlashAttribute("messageContact", "Debe seleccionar un contacto para eliminar");
}
} else {
ContactEntity selectedContact = contactService.getById(selectedContactId);
session.setAttribute("selectedContact", selectedContact);
boolean needsRecharge = !selectedContact.isUser();
redirectAttributes.addFlashAttribute("contactMessage",needsRecharge?"Se hará un recargo de $300 pesos por transferencia a este contacto.":"Pertenece a la familia Alke-Wallet");
}
redirectAttributes.addAttribute("id", userId);
return "redirect:/transfer/{id}";
}
}
104 changes: 104 additions & 0 deletions src/main/java/com/alkewallet6/controller/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.alkewallet6.controller;

import com.alkewallet6.model.DTO.ContactDTO;
import com.alkewallet6.model.entity.ContactEntity;
import com.alkewallet6.model.entity.TransactionEntity;
import com.alkewallet6.model.entity.UserEntity;
import com.alkewallet6.model.enums.TransactionType;
import com.alkewallet6.service.interfaces.IContactService;
import com.alkewallet6.service.interfaces.ITransactionService;
import com.alkewallet6.service.interfaces.IUserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Controller
public class HomeController {

@Autowired
private IUserService userService;
@Autowired
private ITransactionService transactionService;
@Autowired
private IContactService contactService;

@GetMapping("/deposit/{id}")
public String depositView(@PathVariable Long id, Model model) {
UserEntity user = userService.getById(id);

if (user == null){
return "redirect:/?error=true";
}

System.out.println("User ID: " + id);
model.addAttribute("user",user);
model.addAttribute("userId", id);
return "deposit";
}

@GetMapping("/withdraw/{id}")
public String withdrawView(@PathVariable Long id, Model model) {
UserEntity user = userService.getById(id);
if (user == null){
return "redirect:/?error=true";
}

model.addAttribute("user",user);
model.addAttribute("userId", id);
return "withdraw";
}

@GetMapping("/transfer/{id}")
String transferView(@PathVariable Long id, Model model, HttpSession session) {
UserEntity user = userService.getById(id);
if (user == null){
return "redirect:/?error=true";
}

ContactDTO contactDTO = new ContactDTO();
List<ContactEntity> contacts = contactService.getByUserEntityId(id).stream()
.filter(ContactEntity::isActive)
.collect(Collectors.toList());

ContactEntity selectedContact = (ContactEntity) session.getAttribute("selectedContact");

model.addAttribute("user",user);
model.addAttribute("userId", user.getId());
model.addAttribute("contactDTO", contactDTO);
model.addAttribute("contacts", contacts);

if (selectedContact != null) {
model.addAttribute("selectedContact", selectedContact);
}

return "transfer";
}

@GetMapping("/transactionList")
public String transactionView(@RequestParam(value = "transactionType", required = false) TransactionType transactionType, Model model, HttpSession session){
Long userId = (Long) session.getAttribute("userId");
UserEntity user = userService.getById(userId);
if (user == null){
return "redirect:/?error=true";
}

List<TransactionEntity> transactionEntityList = transactionService.getByUserEntityId(userId);
List<TransactionEntity> filteredTransactionList;
if (transactionType == null) {
filteredTransactionList = transactionEntityList;
} else {
filteredTransactionList = transactionEntityList.stream()
.filter(t -> t.getType().equals(transactionType))
.collect(Collectors.toList());
}

model.addAttribute("user", user);
model.addAttribute("filteredTransactionList", filteredTransactionList);
return "transaction";
}
}
Loading

0 comments on commit c8fcba4

Please sign in to comment.