#16 board : add UserAccount Entity
This commit is contained in:
@@ -3,14 +3,8 @@ package com.example.board.domain;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.time.LocalDateTime;
|
||||
@ToString
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@MappedSuperclass
|
||||
public class AuditingFields {
|
||||
public abstract class AuditingFields {
|
||||
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
@CreatedDate
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.example.board.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Table(indexes = {
|
||||
@Index(columnList = "userId"),
|
||||
@Index(columnList = "email", unique = true),
|
||||
@Index(columnList = "createdAt"),
|
||||
@Index(columnList = "createdBy")
|
||||
})
|
||||
@Entity
|
||||
public class UserAccount extends AuditingFields {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Setter
|
||||
@Column(nullable = false, length = 50)
|
||||
private String userId;
|
||||
@Setter
|
||||
@Column(nullable = false)
|
||||
private String userPassword;
|
||||
|
||||
@Setter
|
||||
@Column(length = 100)
|
||||
private String email;
|
||||
@Setter
|
||||
@Column(length = 100)
|
||||
private String nickname;
|
||||
|
||||
@Setter
|
||||
private String memo;
|
||||
|
||||
protected UserAccount() {}
|
||||
|
||||
private UserAccount(String userId, String userPassword, String email, String nickname, String memo) {
|
||||
this.userId = userId;
|
||||
this.userPassword = userPassword;
|
||||
this.email = email;
|
||||
this.nickname = nickname;
|
||||
this.memo = memo;
|
||||
}
|
||||
|
||||
public static UserAccount of(String userId, String userPassword, String email, String nickname, String memo) {
|
||||
return new UserAccount(userId, userPassword, email, nickname, memo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof UserAccount userAccount)) return false;
|
||||
return id != null && id.equals(userAccount.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.board.repository;
|
||||
|
||||
import com.example.board.domain.UserAccount;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserAccountRepository extends JpaRepository<UserAccount, Long> {
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
-- 테스트 계정
|
||||
-- TODO: 테스트용이지만 비밀번호가 노출된 데이터 세팅. 개선하는 것이 좋을 지 고민해 보자.
|
||||
insert into user_account (user_id, user_password, nickname, email, memo, created_at, created_by, modified_at, modified_by) values
|
||||
('bobby', '1234', 'bobby', 'bobby@mail.com', 'I am Bobby.', now(), 'bobby', now(), 'bobby')
|
||||
;
|
||||
|
||||
-- 123 게시글
|
||||
insert into article (title, content, hashtag, created_by, modified_by, created_at, modified_at) values
|
||||
('Quisque ut erat.', 'Vestibulum quam sapien, varius ut, blandit non, interdum in, ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis faucibus accumsan odio. Curabitur convallis.
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@@ -81,4 +81,18 @@ public class DataRestTest {
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.valueOf("application/hal+json")));
|
||||
}
|
||||
|
||||
@DisplayName("[api] 회원 관련 API 는 일체 제공하지 않는다.")
|
||||
@Test
|
||||
void givenNothing_whenRequestingUserAccounts_thenThrowsException() throws Exception {
|
||||
// Given
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/userAccounts")).andExpect(status().isNotFound());
|
||||
mockMvc.perform(post("/api/userAccounts")).andExpect(status().isNotFound());
|
||||
mockMvc.perform(put("/api/userAccounts")).andExpect(status().isNotFound());
|
||||
mockMvc.perform(patch("/api/userAccounts")).andExpect(status().isNotFound());
|
||||
mockMvc.perform(delete("/api/userAccounts")).andExpect(status().isNotFound());
|
||||
mockMvc.perform(head("/api/userAccounts")).andExpect(status().isNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user