diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..28e850793 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,7 @@ +{ + "tasks": { + "test": "./mvnw test", + "build": "./mvnw clean verify", + "launch": "mvn spring-boot:run" + } +} \ No newline at end of file diff --git a/src/main/java/guru/springframework/spring6restmvc/entities/Beer.java b/src/main/java/guru/springframework/spring6restmvc/entities/Beer.java new file mode 100644 index 000000000..e38491ec3 --- /dev/null +++ b/src/main/java/guru/springframework/spring6restmvc/entities/Beer.java @@ -0,0 +1,53 @@ +package guru.springframework.spring6restmvc.entities; + +import lombok.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import jakarta.persistence.*; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Entity +public class Beer { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private UUID id; + + private String name; + private String style; + private String upc; + private Integer quantityOnHand; + private BigDecimal price; + + @CreationTimestamp + private LocalDateTime createdDate; + + @UpdateTimestamp + private LocalDateTime lastModifiedDate; + + @ManyToMany + @JoinTable(name = "beer_category", + joinColumns = @JoinColumn(name = "beer_id"), + inverseJoinColumns = @JoinColumn(name = "category_id")) + private Set<Category> categories = new HashSet<>(); + + public void addCategory(Category category){ + this.categories.add(category); + category.getBeers().add(this); + } + + public void removeCategory(Category category){ + this.categories.remove(category); + category.getBeers().remove(this); + } +}