Skip to content

Commit 505cf80

Browse files
LP-ReactGabriel
andauthored
feat: add dependencies and test with table product (#3)
Co-authored-by: Gabriel <i202332157@cibertec.edu.pe>
1 parent 32b3a21 commit 505cf80

7 files changed

Lines changed: 189 additions & 16 deletions

File tree

pom.xml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,38 @@
4242
<scope>test</scope>
4343
</dependency>
4444

45-
<dependency>
46-
<groupId>com.azure.spring</groupId>
47-
<artifactId>spring-cloud-azure-starter-keyvault-secrets</artifactId>
48-
<version>5.21.0</version>
49-
</dependency>
45+
<dependency>
46+
<groupId>org.postgresql</groupId>
47+
<artifactId>postgresql</artifactId>
48+
<scope>runtime</scope>
49+
</dependency>
5050

51-
<dependency>
52-
<groupId>org.postgresql</groupId>
53-
<artifactId>postgresql</artifactId>
54-
<scope>runtime</scope>
55-
</dependency>
51+
<dependency>
52+
<groupId>com.azure.spring</groupId>
53+
<artifactId>spring-cloud-azure-starter-keyvault-secrets</artifactId>
54+
<version>5.21.0</version>
55+
</dependency>
5656

57-
<dependency>
58-
<groupId>org.springframework.boot</groupId>
59-
<artifactId>spring-boot-starter-data-jpa</artifactId>
60-
</dependency>
57+
<dependency>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-starter-data-jpa</artifactId>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-starter-web</artifactId>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.projectlombok</groupId>
69+
<artifactId>lombok</artifactId>
70+
<optional>true</optional>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-validation</artifactId>
76+
</dependency>
6177
</dependencies>
6278

6379

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.meevent.webapi.Controller;
2+
3+
import com.meevent.webapi.model.Product;
4+
import com.meevent.webapi.service.ProductService;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.*;
8+
9+
import java.util.List;
10+
11+
@RestController
12+
@RequestMapping("/api/v1/products")
13+
public class ProductController {
14+
15+
@Autowired
16+
private ProductService productService;
17+
18+
@GetMapping
19+
public ResponseEntity<List<Product>> obtenerTodos() {
20+
return ResponseEntity.ok(productService.listarProductos());
21+
}
22+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.meevent.webapi.model;
2+
3+
import jakarta.persistence.*;
4+
5+
import java.math.BigDecimal;
6+
import java.time.OffsetDateTime;
7+
8+
@Entity
9+
@Table(name = "products")
10+
public class Product {
11+
12+
@Id
13+
@GeneratedValue(strategy = GenerationType.IDENTITY)
14+
private Integer id;
15+
16+
@Column(unique = true, nullable = false)
17+
private String sku;
18+
19+
@Column(nullable = false)
20+
private String name;
21+
22+
private String category;
23+
24+
private BigDecimal price;
25+
26+
private Integer stock;
27+
28+
@Column(name = "is_active")
29+
private Boolean isActive;
30+
31+
@Column(name = "tags", columnDefinition = "text[]")
32+
private String[] tags; // Mapeo simple de array de Postgres
33+
34+
@Column(name = "created_at", insertable = false, updatable = false)
35+
private OffsetDateTime createdAt;
36+
37+
public Integer getId() {
38+
return id;
39+
}
40+
41+
public void setId(Integer id) {
42+
this.id = id;
43+
}
44+
45+
public String getSku() {
46+
return sku;
47+
}
48+
49+
public void setSku(String sku) {
50+
this.sku = sku;
51+
}
52+
53+
public String getName() {
54+
return name;
55+
}
56+
57+
public void setName(String name) {
58+
this.name = name;
59+
}
60+
61+
public String getCategory() {
62+
return category;
63+
}
64+
65+
public void setCategory(String category) {
66+
this.category = category;
67+
}
68+
69+
public Integer getStock() {
70+
return stock;
71+
}
72+
73+
public void setStock(Integer stock) {
74+
this.stock = stock;
75+
}
76+
77+
public BigDecimal getPrice() {
78+
return price;
79+
}
80+
81+
public void setPrice(BigDecimal price) {
82+
this.price = price;
83+
}
84+
85+
public Boolean getActive() {
86+
return isActive;
87+
}
88+
89+
public void setActive(Boolean active) {
90+
isActive = active;
91+
}
92+
93+
public String[] getTags() {
94+
return tags;
95+
}
96+
97+
public void setTags(String[] tags) {
98+
this.tags = tags;
99+
}
100+
101+
public OffsetDateTime getCreatedAt() {
102+
return createdAt;
103+
}
104+
105+
public void setCreatedAt(OffsetDateTime createdAt) {
106+
this.createdAt = createdAt;
107+
}
108+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.meevent.webapi.repository;
2+
3+
import com.meevent.webapi.model.Product;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.stereotype.Repository;
6+
7+
@Repository
8+
public interface IProductRepository extends JpaRepository<Product,Integer> {
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.meevent.webapi.service;
2+
3+
import com.meevent.webapi.model.Product;
4+
import com.meevent.webapi.repository.IProductRepository;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Service;
7+
8+
import java.util.List;
9+
10+
@Service
11+
public class ProductService {
12+
@Autowired
13+
private IProductRepository productRepository;
14+
15+
public List<Product> listarProductos() {
16+
return productRepository.findAll();
17+
}
18+
}

src/main/resources/application-dev.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ spring.datasource.password=${DB-PASSWORD-DEV}
77
spring.datasource.driver-class-name=org.postgresql.Driver
88

99
#Opciones JPA
10-
spring.jpa.hibernate.ddl-auto=validate
10+
spring.jpa.hibernate.ddl-auto=none
1111
spring.jpa.show-sql=true
1212
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
spring.profiles.active=prod
1+
spring.profiles.active=stage

0 commit comments

Comments
 (0)