Skip to content

Commit

Permalink
improvement(issue-23): Audit annotations for the ShoppingList entity
Browse files Browse the repository at this point in the history
  • Loading branch information
JinnJarBurger committed Oct 5, 2024
1 parent be8ba9e commit 1a609c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;
Expand All @@ -19,6 +22,7 @@
@Getter
@Setter
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "shopping_list")
@ToString
public class ShoppingList {
Expand All @@ -44,10 +48,12 @@ public class ShoppingList {
private BigDecimal totalPrice;

@Basic
@Column(name = "created_at")
@CreatedDate
@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;

@Basic
@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public SaveShoppingListRes save(SaveShoppingListReq request, User user) {
shoppingList.setTotalProducts(0);
shoppingList.setTotalCalories(new BigDecimal("0"));
shoppingList.setTotalPrice(new BigDecimal("0"));
shoppingList.setCreatedAt(LocalDateTime.now());
shoppingList.setUpdatedAt(LocalDateTime.now());
shoppingList.setUser(user);

var save = this.shoppingListRepository.save(shoppingList);
Expand All @@ -137,7 +135,6 @@ public UpdateShoppingListRes update(Integer id, UpdateShoppingListReq request, U
var shoppingList = shoppingListOptional.get();

shoppingList.setName(request.getName());
shoppingList.setUpdatedAt(LocalDateTime.now());

var update = this.shoppingListRepository.save(shoppingList);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.nmarulo.depensaapp.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class JpaConfig {
}

0 comments on commit 1a609c9

Please sign in to comment.