forked from codesquad-members-2023/FoodyMoody-team-06
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
82 additions
and
6 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
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,17 @@ | ||
package com.foodymoody.be.common; | ||
|
||
import java.time.LocalDateTime; | ||
import javax.persistence.EmbeddedId; | ||
import javax.persistence.MappedSuperclass; | ||
import org.springframework.data.annotation.CreatedDate; | ||
|
||
@MappedSuperclass | ||
public class BaseEntity { | ||
|
||
@EmbeddedId | ||
protected WrappedId id; | ||
|
||
@CreatedDate | ||
protected LocalDateTime createdAt; | ||
|
||
} |
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,55 @@ | ||
package com.foodymoody.be.common; | ||
|
||
import io.jsonwebtoken.lang.Assert; | ||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import javax.persistence.Embeddable; | ||
|
||
@Embeddable | ||
public class WrappedId implements Serializable { | ||
|
||
protected String id; | ||
|
||
public WrappedId() { | ||
} | ||
|
||
public WrappedId(String id) { | ||
Assert.notNull(id); | ||
this.id = id; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public boolean equals(String id) { | ||
if (Objects.isNull(id)) { | ||
return false; | ||
} | ||
return this.id.equals(id); | ||
} | ||
|
||
public void assertEquals(String id) { | ||
if (!equals(id)) { | ||
// TODO 적절한 예외 메세지 추가 | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof WrappedId)) { | ||
return false; | ||
} | ||
WrappedId wrappedId = (WrappedId) o; | ||
return Objects.equals(getId(), wrappedId.getId()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getId()); | ||
} | ||
} |
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