Skip to content

Fix removeCategory method in Beer class #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}