Skip to content

Commit

Permalink
Add CreatedBy and UpdatedBy Info Into Response (#404)
Browse files Browse the repository at this point in the history
Per discussion, this will include the user and org info in the responses
for templates if it is set.
  • Loading branch information
schreiaj authored Nov 19, 2024
1 parent 68743bf commit 92e6c61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
25 changes: 13 additions & 12 deletions backend/src/main/java/gov/cdc/ReportVision/models/ApiUser.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package gov.cdc.ReportVision.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import lombok.Getter;

import java.util.UUID;
import lombok.Getter;

@Getter
@Entity
public class ApiUser extends BaseEntity {

@Id
@GeneratedValue(generator = "UUID4")
@Column(updatable = false, nullable = false)
private UUID id;
@Id
@GeneratedValue(generator = "UUID4")
@Column(updatable = false, nullable = false)
private UUID id;

@JsonProperty private String name;
@JsonProperty private String email;

private String name;
private String email;
private String password; // Should be hashed and salted
@JsonIgnore private String password; // Should be hashed and salted

@ManyToOne
private Organization organization;
}
@ManyToOne private Organization organization;
}
12 changes: 10 additions & 2 deletions backend/src/main/java/gov/cdc/ReportVision/models/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import java.util.Date;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

Expand All @@ -24,7 +26,13 @@ public abstract class BaseEntity {
@LastModifiedDate
private Date updatedAt;

@ManyToOne private ApiUser createdBy;
@JsonProperty
@Fetch(FetchMode.JOIN)
@ManyToOne
private ApiUser createdBy;

@ManyToOne private ApiUser updatedBy;
@JsonProperty
@Fetch(FetchMode.JOIN)
@ManyToOne
private ApiUser updatedBy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.UUID;
import lombok.Builder;
import lombok.Getter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Getter
Expand All @@ -32,13 +34,16 @@ public class Template extends BaseEntity {
private String labName;

@OneToMany(mappedBy = "template")
@Fetch(FetchMode.JOIN)
private List<Page> pages;

@Enumerated(EnumType.STRING)
@Builder.Default
private TemplateStatus status = TemplateStatus.IN_PROGRESS;

@ManyToOne private Organization organization;
@Fetch(FetchMode.JOIN)
@ManyToOne
private Organization organization;

public Template(
UUID id,
Expand Down

0 comments on commit 92e6c61

Please sign in to comment.