Notice
Recent Posts
Recent Comments
Link
상똥이의 Back-End 공부방
[Board Project] 16. 회원 도메인 추가하기 본문
[1. 도메인 추가]
0. ERD 업데이트
1. 검색 시 필터링 인덱스
- @Table어노테인션
- @Indexes, @Index(columnList = "")
- userId, email, createdAt, createdBy
- JPA 사용 -> @Entity
코드 (접은 글)
더보기
package com.fastcampus.projectboard.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, length = 50)
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);
}
}
2. QUserAccount
- QueryDSL로 generated 디렉토리에 자동 생성
3. UserAccountRepository
코드 (접은 글)
더보기
package com.fastcampus.projectboard.repository;
import com.fastcampus.projectboard.domain.UserAccount;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserAccountRepository extends JpaRepository<UserAccount, Long> {
}
4. data.sql에 사용자 입력
insert into user_account (user_id, user_password, nickname, email, memo, created_at, created_by, modified_at, modified_by) values ('uno', 'asdf1234', 'Uno', 'uno@mail.com', 'I am Uno.', now(), 'uno', now(), 'uno');
[2. UserAccount 관련 테스트 업데이트]
- 회원 관련 모든 정보는 일절 접근하지 못하도록 설정
코드 (접은 글)
더보기
@DisplayName("[api] 회원 관련 API 는 일체 제공하지 않는다.")
@Test
void givenNothing_whenRequestingUserAccounts_thenThrowsException() throws Exception {
// Given
// When & Then
mvc.perform(get("/api/userAccounts")).andExpect(status().isNotFound());
mvc.perform(post("/api/userAccounts")).andExpect(status().isNotFound());
mvc.perform(put("/api/userAccounts")).andExpect(status().isNotFound());
mvc.perform(patch("/api/userAccounts")).andExpect(status().isNotFound());
mvc.perform(delete("/api/userAccounts")).andExpect(status().isNotFound());
mvc.perform(head("/api/userAccounts")).andExpect(status().isNotFound());
}