Skip to content

Commit

Permalink
Fix removeCategory method in Beer class
Browse files Browse the repository at this point in the history
  • Loading branch information
springframeworkguru committed Dec 15, 2024
1 parent 472b325 commit 12a51ed
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tasks": {
"test": "./mvnw test",
"build": "./mvnw clean verify",
"launch": "mvn spring-boot:run"
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 12a51ed

Please sign in to comment.