diff --git a/src/main/java/com/totopia/server/commons/base/model/Base.java b/src/main/java/com/totopia/server/commons/base/model/Base.java new file mode 100644 index 0000000..536a7d3 --- /dev/null +++ b/src/main/java/com/totopia/server/commons/base/model/Base.java @@ -0,0 +1,28 @@ +package com.totopia.server.commons.base.model; + +import lombok.*; +import org.hibernate.annotations.CreationTimestamp; + +import javax.persistence.*; +import java.util.Date; + +@MappedSuperclass +@Data +@Getter +@Setter +public abstract class Base { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Basic + @CreationTimestamp + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "create_date", nullable = false) + private Date createDate; + + @Basic + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "update_date", nullable = false) + private Date updateDate; +} diff --git a/src/main/java/com/totopia/server/user/model/BankAccount.java b/src/main/java/com/totopia/server/user/model/BankAccount.java new file mode 100644 index 0000000..fe11580 --- /dev/null +++ b/src/main/java/com/totopia/server/user/model/BankAccount.java @@ -0,0 +1,39 @@ +package com.totopia.server.user.model; + +import com.totopia.server.commons.base.model.Base; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Entity +@Table(name = "TBL_BANK_ACCOUNT") +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class BankAccount extends Base { +// @Id +// @GeneratedValue(generator = "bank_account_generator") +// @SequenceGenerator(name = "bank_account_generator", sequenceName = "bank_account_sequence", initialValue = 1, allocationSize = 1) +// private Long id; + + @Basic + @Column(name = "name", nullable = false, length = 100) + private String name; + + @Basic + @Column(name = "number", nullable = false, length = 100) + private String number; + + @Basic + @Column(name = "holder", nullable = false, length = 100) + private String holder; + + @Basic + @Column(name = "user_id", nullable = false) + private Long userId; + +} diff --git a/src/main/java/com/totopia/server/user/model/UserGroup.java b/src/main/java/com/totopia/server/user/model/Role.java similarity index 91% rename from src/main/java/com/totopia/server/user/model/UserGroup.java rename to src/main/java/com/totopia/server/user/model/Role.java index fee6a3c..ad95310 100644 --- a/src/main/java/com/totopia/server/user/model/UserGroup.java +++ b/src/main/java/com/totopia/server/user/model/Role.java @@ -11,18 +11,18 @@ import java.io.Serializable; import java.util.Date; @Entity -@Table(name = "TBL_USER_GROUP") +@Table(name = "TBL_ROLE") @Data @Builder @NoArgsConstructor @AllArgsConstructor -public class UserGroup implements Serializable { +public class Role implements Serializable { private static final long serialVersionUID = 4801565634000630034L; @Id @GeneratedValue(generator = "user_group_generator") @SequenceGenerator(name = "user_group_generator", sequenceName = "user_group_sequence", initialValue = 1, allocationSize = 1) - private Long id; + private Integer id; @Basic @Column(name = "title", nullable = false, length = 100) diff --git a/src/main/java/com/totopia/server/user/model/User.java b/src/main/java/com/totopia/server/user/model/User.java index cd806cd..aaf2712 100644 --- a/src/main/java/com/totopia/server/user/model/User.java +++ b/src/main/java/com/totopia/server/user/model/User.java @@ -7,6 +7,7 @@ import javax.persistence.*; import com.totopia.server.commons.base.gson.annotation.Exclude; +import com.totopia.server.commons.base.model.Base; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -20,13 +21,17 @@ import org.hibernate.annotations.UpdateTimestamp; @Builder @NoArgsConstructor @AllArgsConstructor -public class User implements Serializable { +@AttributeOverrides({ + @AttributeOverride(name = "createDate", column = @Column(name = "registDate")), + @AttributeOverride(name = "updateDate", column = @Column(name = "lastvisitDate")), +}) +public class User extends Base implements Serializable { private static final long serialVersionUID = 2783105197387637187L; - @Id - @GeneratedValue(generator = "user_generator") - @SequenceGenerator(name = "user_generator", sequenceName = "user_sequence", initialValue = 1000) - private Long id; +// @Id +// @GeneratedValue(generator = "user_generator") +// @SequenceGenerator(name = "user_generator", sequenceName = "user_sequence", initialValue = 1000) +// private Long id; @Basic @Column(name = "username", unique = true, nullable = false, length = 150) @@ -37,6 +42,9 @@ public class User implements Serializable { @Exclude private String password; + @Transient + private String passwordConfirm; + @Basic @Column(name = "name", nullable = false, length = 255) private String nickname; @@ -57,24 +65,27 @@ public class User implements Serializable { @Column(name = "send_email", nullable = true, columnDefinition = "bool default false") private Boolean sendEmail; - @Basic - @CreationTimestamp - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "register_date", nullable = false) - private Date registerDate; - - @Basic - @UpdateTimestamp - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "lastvisit_date", nullable = false) - private Date lastvisitDate; +// @AttributeOverride(name = "createDate", column = @Column(name = "regist_date")) +// private Date registerDate; +// +// @AttributeOverride(name = "updateDate", column = @Column(name = "lastvisit_date")) +// private Date lastvisitDate; +// @Basic +// @CreationTimestamp +// @Temporal(TemporalType.TIMESTAMP) +// @Column(name = "register_date", nullable = false) +// private Date registerDate; +// +// @Basic +// @Temporal(TemporalType.TIMESTAMP) +// @Column(name = "lastvisit_date", nullable = false) +// private Date lastvisitDate; @Basic @Column(name = "activation", nullable = false, length = 100) private String activation; @Basic - @UpdateTimestamp @Temporal(TemporalType.TIMESTAMP) @Column(name = "last_reset_time", nullable = false) private Date lastResetTime; diff --git a/src/main/java/com/totopia/server/user/repository/BankAccountRepository.java b/src/main/java/com/totopia/server/user/repository/BankAccountRepository.java new file mode 100644 index 0000000..04c914f --- /dev/null +++ b/src/main/java/com/totopia/server/user/repository/BankAccountRepository.java @@ -0,0 +1,9 @@ +package com.totopia.server.user.repository; + +import com.totopia.server.user.model.BankAccount; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface BankAccountRepository extends JpaRepository { +} diff --git a/src/main/java/com/totopia/server/user/repository/RoleRepository.java b/src/main/java/com/totopia/server/user/repository/RoleRepository.java new file mode 100644 index 0000000..e00ebd3 --- /dev/null +++ b/src/main/java/com/totopia/server/user/repository/RoleRepository.java @@ -0,0 +1,9 @@ +package com.totopia.server.user.repository; + +import com.totopia.server.user.model.Role; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface RoleRepository extends JpaRepository { +} diff --git a/src/main/java/com/totopia/server/user/repository/UserRepository.java b/src/main/java/com/totopia/server/user/repository/UserRepository.java index da8d6a4..cdcc8e9 100644 --- a/src/main/java/com/totopia/server/user/repository/UserRepository.java +++ b/src/main/java/com/totopia/server/user/repository/UserRepository.java @@ -28,12 +28,12 @@ public interface UserRepository extends JpaRepository { // 어드민이 펄스이며, 활동중인 현재 회원 리스트 Page findAllByIsAdminFalseAndActivationEquals(String activation, Pageable pageable) throws Exception; // 날짜 검색 - Page findAllByRegisterDateBetween(Date starDate, Date endDate, Pageable pageable) throws Exception; - Page findAllByLastvisitDateBetween(Date starDate, Date endDate, Pageable pageable) throws Exception; + Page findAllByCreateDateBetween(Date starDate, Date endDate, Pageable pageable) throws Exception; + Page findAllByUpdateDateBetween(Date starDate, Date endDate, Pageable pageable) throws Exception; Page findAllByLastResetTimeBetween(Date starDate, Date endDate, Pageable pageable) throws Exception; // 현재 날짜 이후 가입된 회원의 총 수 리턴 - Long countByRegisterDateGreaterThanEqual(Date date) throws Exception; + Long countByCreateDateGreaterThanEqual(Date date) throws Exception; // 유저 그룹별 회원 리스트 diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index bb6c9bb..548626b 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,14 +1,14 @@ -insert into public.tbl_user_group +insert into public.tbl_role (id ,title, description, is_default, register_date) values (1, '관리자', '관리자 그룹', false, '2019-07-20 12:00:30'); -insert into public.tbl_user_group +insert into public.tbl_role (id ,title, description, is_default, register_date) values (2, '정회원', '정회원 그룹', true, '2019-07-20 12:00:30'); -insert into public.tbl_user_group +insert into public.tbl_role (id ,title, description, is_default, register_date) values (3, '비회원', '비회원 그룹', false, '2019-07-20 12:00:30'); diff --git a/src/test/java/com/totopia/server/user/repository/BankAccountRepositoryTest.java b/src/test/java/com/totopia/server/user/repository/BankAccountRepositoryTest.java new file mode 100644 index 0000000..decbd1b --- /dev/null +++ b/src/test/java/com/totopia/server/user/repository/BankAccountRepositoryTest.java @@ -0,0 +1,105 @@ +package com.totopia.server.user.repository; + +import com.totopia.server.user.model.BankAccount; +import com.totopia.server.user.model.User; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static org.junit.Assert.*; + +@Ignore +@RunWith(SpringRunner.class) +@SpringBootTest +public class BankAccountRepositoryTest { + + @Autowired + private UserRepository userRepository; + + @Autowired + private BankAccountRepository bankAccountRepository; + + List users; + List accounts = new ArrayList<>(); + + @Before + public void setUp() throws Exception { + users = this.userRepository.findAll(); + + if(users == null) { + throw new Exception("user list Null"); + } + } + + @Test + public void testInsert() { + + BankAccount bankAccount = null; + + int idx = 0; + for (User user : users) { + bankAccount = new BankAccount(); + + switch (idx) { + case 0: + bankAccount.setName("국민은행"); + bankAccount.setHolder("예금주1"); + bankAccount.setNumber("123-422-23112"); + break; + case 1: + bankAccount.setName("우리은행"); + bankAccount.setHolder("예금주2"); + bankAccount.setNumber("321-555-3312-21"); + break; + case 2: + bankAccount.setName("기업은행"); + bankAccount.setHolder("예금주3"); + bankAccount.setNumber("832-2392-2392-29829"); + break; + } + idx++; + bankAccount.setUserId(user.getId()); + bankAccount.setUpdateDate(new Date()); + this.bankAccountRepository.save(bankAccount); + } + } + + @Test + public void testUpdate() { + List bankAccounts = this.bankAccountRepository.findAll(); + + int idx = 0; + for (BankAccount account : bankAccounts) { + + switch (idx) { + case 0: + account.setName("국민은행"); + account.setHolder("예금주1"); + account.setNumber("123-422-23112"); + break; + case 1: + account.setName("우리은행"); + account.setHolder("예금주2"); + account.setNumber("321-555-3312-21"); + break; + case 2: + account.setName("기업은행"); + account.setHolder("예금주3"); + account.setNumber("832-2392-2392-29829"); + break; + } + idx++; + account.setUserId(account.getUserId()); + + this.bankAccountRepository.save(account); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/totopia/server/user/repository/UserRepositoryTest.java b/src/test/java/com/totopia/server/user/repository/UserRepositoryTest.java index 691b0d1..b965339 100644 --- a/src/test/java/com/totopia/server/user/repository/UserRepositoryTest.java +++ b/src/test/java/com/totopia/server/user/repository/UserRepositoryTest.java @@ -2,15 +2,21 @@ package com.totopia.server.user.repository; import com.totopia.server.user.model.User; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import static org.junit.Assert.*; +@Ignore @RunWith(SpringRunner.class) @SpringBootTest public class UserRepositoryTest { @@ -18,11 +24,13 @@ public class UserRepositoryTest { @Autowired private UserRepository userRepository; - private User.UserBuilder user; +// private User.UserBuilder user; + + private List userList = new ArrayList<>(); @Before public void setUp() throws Exception { - user = User.builder() + User.UserBuilder user = User.builder() .activation("Y") .block(false) .email("geekdev@naver.com") @@ -33,25 +41,66 @@ public class UserRepositoryTest { .password("qwer5795") .username("admin") .requireReset(false) - .resetCount(Long.valueOf(0)); + .resetCount(Long.valueOf(0)) + .lastResetTime(new Date()); + + User temp = user.build(); + temp.setUpdateDate(new Date()); + userList.add(temp); + + user = User.builder() + .activation("Y") + .block(false) + .email("geektest1@naver.com") + .isAdmin(false) + .nickname("test1") + .otep("") + .otpKey("") + .password("qwer5795") + .username("test1") + .requireReset(false) + .resetCount(Long.valueOf(0)) + .lastResetTime(new Date()); + + temp = user.build(); + temp.setUpdateDate(new Date()); + userList.add(temp); + + user = User.builder() + .activation("Y") + .block(false) + .email("geektest2@naver.com") + .isAdmin(false) + .nickname("test2") + .otep("") + .otpKey("") + .password("qwer5795") + .username("test2") + .requireReset(false) + .resetCount(Long.valueOf(0)) + .lastResetTime(new Date()); + + temp = user.build(); + temp.setUpdateDate(new Date()); + userList.add(temp); } @Test - public void findByUsername() throws Exception { - User admin = this.userRepository.findByUsername("admin"); + public void findByUsername() { + User admin = this.getAdmin(); if (admin == null) { - User tempUser = user.build(); - - this.userRepository.save(tempUser); - - User user1 = this.userRepository.findByUsername(tempUser.getUsername()); - - assertEquals("Equlas", user.build().getUsername(), user1.getUsername()); + this.userRepository.saveAll(userList); + assertEquals("Equlas", userList.get(0).getNickname(), "admin"); } } @Test public void findByEmail() { + User admin = this.getAdmin(); + + if(admin != null) { + + } } @Test @@ -93,4 +142,13 @@ public class UserRepositoryTest { @Test public void countByRegisterDateGreaterThanEqual() { } + + private User getAdmin() { + try { + return this.userRepository.findByUsername("admin"); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } } \ No newline at end of file