-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix removeCategory method in Beer class
Related to #13 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/springframeworkguru/spring-6-rest-mvc/issues/13?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
1 parent
472b325
commit 12a51ed
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/guru/springframework/spring6restmvc/entities/Beer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |