| 1 | package edu.ucsb.cs156.frontiers.entities; | |
| 2 | ||
| 3 | import jakarta.persistence.*; | |
| 4 | import java.time.ZonedDateTime; | |
| 5 | import lombok.*; | |
| 6 | ||
| 7 | @Data | |
| 8 | @AllArgsConstructor | |
| 9 | @NoArgsConstructor(access = AccessLevel.PROTECTED) | |
| 10 | @Builder | |
| 11 | @Entity | |
| 12 | @Table(name = "api_course_key") | |
| 13 | public class ApiCourseKey { | |
| 14 | @Id | |
| 15 | @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 16 | private Long id; | |
| 17 | ||
| 18 | @ManyToOne(fetch = FetchType.LAZY) | |
| 19 | @JoinColumn(name = "course_id", nullable = false) | |
| 20 | @ToString.Exclude | |
| 21 | private Course course; | |
| 22 | ||
| 23 | @ManyToOne(fetch = FetchType.LAZY) | |
| 24 | @JoinColumn(name = "created_by_id", nullable = false) | |
| 25 | @ToString.Exclude | |
| 26 | private User createdBy; | |
| 27 | ||
| 28 | @Column(nullable = false) | |
| 29 | private String keyHash; | |
| 30 | ||
| 31 | @Column(nullable = false) | |
| 32 | private String salt; | |
| 33 | ||
| 34 | @Column(nullable = false) | |
| 35 | private String keySuffix; | |
| 36 | ||
| 37 | @Column(nullable = false) | |
| 38 | private ZonedDateTime createdAt; | |
| 39 | ||
| 40 | @Column(nullable = false) | |
| 41 | private ZonedDateTime expiresAt; | |
| 42 | ||
| 43 | @Builder.Default | |
| 44 | @Column(nullable = false) | |
| 45 | private boolean revoked = false; | |
| 46 | ||
| 47 | private ZonedDateTime lastUsedAt; | |
| 48 | ||
| 49 | @Builder.Default | |
| 50 | @Column(nullable = false) | |
| 51 | private long usageCount = 0; | |
| 52 | ||
| 53 | public boolean isActive(ZonedDateTime now) { | |
| 54 |
3
1. isActive : replaced boolean return with true for edu/ucsb/cs156/frontiers/entities/ApiCourseKey::isActive → KILLED 2. isActive : negated conditional → KILLED 3. isActive : negated conditional → KILLED |
return !revoked && now.isBefore(expiresAt); |
| 55 | } | |
| 56 | } | |
Mutations | ||
| 54 |
1.1 2.2 3.3 |