diff options
| author | realtradam <[email protected]> | 2024-07-28 20:00:49 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2024-07-28 20:00:49 -0400 |
| commit | fc34d9853386b6dbf270a10862a47a052f1fb151 (patch) | |
| tree | 20ebca59324d88eab8b867306dd251a27cd91699 /backend/src/main/java/com/blog/web/models/Article.java | |
| parent | c24839e8f8b4b6868f8ee383b589ce01dcdc81e1 (diff) | |
| download | spring-blog-dev.tar.gz spring-blog-dev.zip | |
code cleanupdev
Diffstat (limited to 'backend/src/main/java/com/blog/web/models/Article.java')
| -rw-r--r-- | backend/src/main/java/com/blog/web/models/Article.java | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/backend/src/main/java/com/blog/web/models/Article.java b/backend/src/main/java/com/blog/web/models/Article.java index ed4ac1c..58fcca3 100644 --- a/backend/src/main/java/com/blog/web/models/Article.java +++ b/backend/src/main/java/com/blog/web/models/Article.java @@ -6,12 +6,13 @@ import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; import java.time.LocalDateTime; +import java.util.Optional; @Entity public class Article { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private final long id; private String title; private String photoUrl; private String content; @@ -23,7 +24,7 @@ public class Article { @JoinColumn(name = "created_by", nullable = false) private UserEntity createdBy; - public Article(Long id, String title, String photoUrl, String content, UserEntity createdBy, LocalDateTime createdOn, LocalDateTime updatedOn) { + public Article(long id, String title, String photoUrl, String content, UserEntity createdBy, LocalDateTime createdOn, LocalDateTime updatedOn) { this.id = id; this.title = title; this.photoUrl = photoUrl; @@ -33,11 +34,8 @@ public class Article { this.updatedOn = updatedOn; } - public Article() { - } - public Article(ArticleDto articleDto) { - this.id = articleDto.getId(); + this.id = Optional.ofNullable(articleDto.getId()).orElse(0L); this.title = articleDto.getTitle(); this.photoUrl = articleDto.getPhotoUrl(); this.content = articleDto.getContent(); @@ -46,12 +44,12 @@ public class Article { this.updatedOn = articleDto.getUpdatedOn(); } - public Long getId() { - return id; + public Article() { + this.id = 0; } - public void setId(Long id) { - this.id = id; + public long getId() { + return id; } public String getTitle() { |
