From a3bddd299ea891b1a1bc67ea951f635ce1d83a2e Mon Sep 17 00:00:00 2001 From: sehajyang Date: Fri, 9 Oct 2020 20:03:16 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat=20:=20#4=20category=20penalty,=20role?= =?UTF-8?q?=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resumers/server/oauth/enums/RoleType.java | 10 ++++++ .../server/oauth/model/entity/Category.java | 19 +++++++++++ .../server/oauth/model/entity/Penalty.java | 24 +++++++++++++ .../server/oauth/model/entity/Role.java | 28 +++++++++++++++ .../server/oauth/model/entity/User.java | 8 +++++ .../oauth/model/entity/UserCaterory.java | 9 +++++ .../oauth/model/entity/UserPenalty.java | 34 +++++++++++++++++++ .../server/oauth/model/entity/UserTag.java | 26 ++++++++++++++ 8 files changed, 158 insertions(+) create mode 100644 src/main/java/com/resumers/server/oauth/enums/RoleType.java create mode 100644 src/main/java/com/resumers/server/oauth/model/entity/Category.java create mode 100644 src/main/java/com/resumers/server/oauth/model/entity/Penalty.java create mode 100644 src/main/java/com/resumers/server/oauth/model/entity/Role.java create mode 100644 src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java create mode 100644 src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java create mode 100644 src/main/java/com/resumers/server/oauth/model/entity/UserTag.java diff --git a/src/main/java/com/resumers/server/oauth/enums/RoleType.java b/src/main/java/com/resumers/server/oauth/enums/RoleType.java new file mode 100644 index 0000000..980e338 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/enums/RoleType.java @@ -0,0 +1,10 @@ +package com.resumers.server.oauth.enums; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + * Descrpition : + */ +public enum RoleType { + USER, ADMIN +} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Category.java b/src/main/java/com/resumers/server/oauth/model/entity/Category.java new file mode 100644 index 0000000..d68a282 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/entity/Category.java @@ -0,0 +1,19 @@ +package com.resumers.server.oauth.model.entity; + +import javax.persistence.*; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + * Descrpition : + */ + +@Entity +@Table(name="category") +public class Category extends BaseEntity{ + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name ="category_id") + public Long categoryId; +} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Penalty.java b/src/main/java/com/resumers/server/oauth/model/entity/Penalty.java new file mode 100644 index 0000000..1ff45c8 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/entity/Penalty.java @@ -0,0 +1,24 @@ +package com.resumers.server.oauth.model.entity; + +import javax.persistence.*; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + * Descrpition : + */ + +@Entity +@Table(name="penalty") +public class Penalty { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long penaltyId; + + @Column(length = 100) + private String title; + + @Column(length = 2000) + private String description; +} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Role.java b/src/main/java/com/resumers/server/oauth/model/entity/Role.java new file mode 100644 index 0000000..9e0b4e5 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/entity/Role.java @@ -0,0 +1,28 @@ +package com.resumers.server.oauth.model.entity; + +import com.resumers.server.oauth.enums.RoleType; + +import javax.persistence.*; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + * Descrpition : + */ + +@Entity +@Table(name="role") +public class Role { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="role_id") + private Long roleId; + + @Enumerated(EnumType.STRING) + @Column(name = "name") + private RoleType roleType; + + @Column(name = "description") + private String description; +} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/User.java b/src/main/java/com/resumers/server/oauth/model/entity/User.java index 925ece7..67a8a48 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/User.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/User.java @@ -50,4 +50,12 @@ public class User extends BaseEntity { @OneToOne @JoinColumn(name="user_id") private UserDetail userDetail; + + @OneToMany(mappedBy = "user") + private Set userTags = new LinkedHashSet<>(); + + @ManyToMany + @JoinTable(name = "user_role", + joinColumns = @JoinColumn(name ="user_id"), inverseJoinColumns= @JoinColumn(name="role_id")) + private Set roles = new LinkedHashSet<>(); } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java b/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java new file mode 100644 index 0000000..d53d880 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java @@ -0,0 +1,9 @@ +package com.resumers.server.oauth.model.entity; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + * Descrpition : + */ +public class UserCaterory { +} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java b/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java new file mode 100644 index 0000000..8e52fce --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java @@ -0,0 +1,34 @@ +package com.resumers.server.oauth.model.entity; + +import javax.persistence.*; +import java.time.LocalDateTime; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + * Descrpition : + */ + +@Entity +@Table(name = "user_penalty") +public class UserPenalty extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_penalty_id") + private Long userPenaltyId; + + @ManyToOne + @JoinColumn(name="user_id") + private User user; + + @OneToOne + @JoinColumn(name="penalty_id") + private Penalty penalty; + + @Column(length = 2000) + private String description; + + private LocalDateTime startAt; + private LocalDateTime endAt; +} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java b/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java new file mode 100644 index 0000000..e2dbd52 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java @@ -0,0 +1,26 @@ +package com.resumers.server.oauth.model.entity; + +import javax.persistence.*; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + * Description : 유저 관심사 태그 엔티티 + */ +@Entity +@Table(name = "user_tag") +public class UserTag { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="user_tag_id") + private Long userTagId; + + @ManyToOne + @JoinColumn(name="user_id") + private User user; + + @OneToOne + @JoinColumn(name="tag_id") + private Tag tag; +} From 080646a96759e1c5ab37cc0ad4c970cd922d2f28 Mon Sep 17 00:00:00 2001 From: sehajyang Date: Fri, 9 Oct 2020 20:33:55 +0900 Subject: [PATCH 2/8] =?UTF-8?q?fix=20:=20#4=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=A1=B0=ED=9A=8C=20=EC=A0=84?= =?UTF-8?q?=EB=9E=B5=20lazy=20=EB=A1=9C=20=EC=9D=BC=EA=B4=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/oauth/ResumersOauthApplication.java | 13 ------------- .../server/oauth/model/entity/Category.java | 2 ++ .../resumers/server/oauth/model/entity/Certify.java | 4 ++-- .../resumers/server/oauth/model/entity/Company.java | 2 +- .../server/oauth/model/entity/CompanyTag.java | 4 ++-- .../com/resumers/server/oauth/model/entity/Tag.java | 3 +++ .../resumers/server/oauth/model/entity/User.java | 6 +++--- .../entity/{UserCaterory.java => UserCategory.java} | 2 +- .../server/oauth/model/entity/UserCompany.java | 6 +++--- .../server/oauth/model/entity/UserDetail.java | 2 +- .../server/oauth/model/entity/UserPenalty.java | 4 ++-- .../server/oauth/model/entity/UserResumeLike.java | 2 +- .../server/oauth/model/entity/UserResumeView.java | 2 +- .../server/oauth/model/entity/UserSocial.java | 2 +- .../resumers/server/oauth/model/entity/UserTag.java | 4 ++-- 15 files changed, 25 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java rename src/main/java/com/resumers/server/oauth/model/entity/{UserCaterory.java => UserCategory.java} (81%) diff --git a/src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java b/src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java deleted file mode 100644 index 4c06762..0000000 --- a/src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.resumers.server.oauth; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class ResumersOauthApplication { - - public static void main(String[] args) { - SpringApplication.run(ResumersOauthApplication.class, args); - } - -} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Category.java b/src/main/java/com/resumers/server/oauth/model/entity/Category.java index d68a282..64f9a7b 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Category.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Category.java @@ -16,4 +16,6 @@ public class Category extends BaseEntity{ @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name ="category_id") public Long categoryId; + + public String title; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Certify.java b/src/main/java/com/resumers/server/oauth/model/entity/Certify.java index d0fd7cc..34ef4ff 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Certify.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Certify.java @@ -16,7 +16,7 @@ public class Certify extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name="certify_id") + @Column(name = "certify_id") private Long certifyId; @Enumerated(EnumType.STRING) @@ -28,7 +28,7 @@ public class Certify extends BaseEntity { @Enumerated(EnumType.STRING) private CertifiedStatus certifiedStatus; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = true) private User user; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Company.java b/src/main/java/com/resumers/server/oauth/model/entity/Company.java index 59d7421..228fbff 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Company.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Company.java @@ -21,6 +21,6 @@ public class Company extends BaseEntity{ private String name; private String description; - @OneToMany(mappedBy = "company") + @OneToMany(mappedBy = "company", fetch = FetchType.LAZY) private Set companyTags = new LinkedHashSet<>(); } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java b/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java index c9e3716..b4dc3c1 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java @@ -17,11 +17,11 @@ public class CompanyTag extends BaseEntity { @Column(name = "companyTagId") private Long companyTagId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "tag_id") private Tag tag; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "company_id") private Company company; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Tag.java b/src/main/java/com/resumers/server/oauth/model/entity/Tag.java index 23959bf..e0a110d 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Tag.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Tag.java @@ -19,6 +19,9 @@ public class Tag { private Long TagId; private String title; + + @Enumerated(EnumType.STRING) private TagType tagType; + private String description; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/User.java b/src/main/java/com/resumers/server/oauth/model/entity/User.java index 67a8a48..87b88e8 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/User.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/User.java @@ -44,17 +44,17 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user") private Set userResumeViews = new LinkedHashSet<>(); - @OneToMany(mappedBy = "user", orphanRemoval = true, fetch = FetchType.EAGER) + @OneToMany(mappedBy = "user", orphanRemoval = true) private Set userSocials = new LinkedHashSet<>(); - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name="user_id") private UserDetail userDetail; @OneToMany(mappedBy = "user") private Set userTags = new LinkedHashSet<>(); - @ManyToMany + @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "user_role", joinColumns = @JoinColumn(name ="user_id"), inverseJoinColumns= @JoinColumn(name="role_id")) private Set roles = new LinkedHashSet<>(); diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java b/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java similarity index 81% rename from src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java rename to src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java index d53d880..1a6eb2e 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java @@ -5,5 +5,5 @@ * DateTime : 2020/10/09 * Descrpition : */ -public class UserCaterory { +public class UserCategory { } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java b/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java index 9cd9106..30eaaa9 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java @@ -17,18 +17,18 @@ public class UserCompany extends BaseEntity { @Column(name = "user_company_id") private Long userCompanyId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "company_id") private Company company; @Enumerated(EnumType.STRING) private UserCompanyCertifyStatus userCompanyCertifyStatus; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "certify_id") private Certify certify; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java b/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java index 60b7be0..5163e45 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java @@ -7,8 +7,8 @@ * DateTime : 2020/10/09 */ -@Table @Entity +@Table(name="user_detail") public class UserDetail extends BaseEntity{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java b/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java index 8e52fce..0676529 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java @@ -18,11 +18,11 @@ public class UserPenalty extends BaseEntity { @Column(name = "user_penalty_id") private Long userPenaltyId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="user_id") private User user; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name="penalty_id") private Penalty penalty; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java index e511c80..16de450 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java @@ -15,7 +15,7 @@ public class UserResumeLike { @Column(name = "user_resume_like_id") private Long userResumeLikeId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java index 1044578..621b35e 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java @@ -15,7 +15,7 @@ public class UserResumeView { @Column(name = "user_resume_view_id") private Long userResumeViewId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java b/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java index 5b1367e..365c8fb 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java @@ -23,7 +23,7 @@ public class UserSocial extends BaseEntity{ private String socialToken; private String email; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java b/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java index e2dbd52..29b7364 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java @@ -16,11 +16,11 @@ public class UserTag { @Column(name="user_tag_id") private Long userTagId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="user_id") private User user; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name="tag_id") private Tag tag; } From 46bf371c54beaf9d51da6d4a015d5daf6342774d Mon Sep 17 00:00:00 2001 From: sehajyang Date: Fri, 9 Oct 2020 20:54:56 +0900 Subject: [PATCH 3/8] =?UTF-8?q?fix=20:=20#4=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=A0=84=EB=9E=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/oauth/model/entity/Company.java | 2 +- .../server/oauth/model/entity/User.java | 9 ++++++++- .../oauth/model/entity/UserCategory.java | 20 +++++++++++++++++-- .../oauth/model/entity/UserResumeLike.java | 1 + .../oauth/model/entity/UserResumeView.java | 3 +++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Company.java b/src/main/java/com/resumers/server/oauth/model/entity/Company.java index 228fbff..59d7421 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Company.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Company.java @@ -21,6 +21,6 @@ public class Company extends BaseEntity{ private String name; private String description; - @OneToMany(mappedBy = "company", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "company") private Set companyTags = new LinkedHashSet<>(); } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/User.java b/src/main/java/com/resumers/server/oauth/model/entity/User.java index 87b88e8..fbdf59f 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/User.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/User.java @@ -54,8 +54,15 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user") private Set userTags = new LinkedHashSet<>(); - @ManyToMany(fetch = FetchType.LAZY) + @OneToMany(mappedBy = "user") + private Set userCategories = new LinkedHashSet<>(); + + @OneToMany(mappedBy = "user") + private Set userPenalties = new LinkedHashSet<>(); + + @ManyToMany @JoinTable(name = "user_role", joinColumns = @JoinColumn(name ="user_id"), inverseJoinColumns= @JoinColumn(name="role_id")) private Set roles = new LinkedHashSet<>(); + } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java b/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java index 1a6eb2e..b8f0185 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java @@ -1,9 +1,25 @@ package com.resumers.server.oauth.model.entity; +import javax.persistence.*; + /** * Created by sehajyang * DateTime : 2020/10/09 - * Descrpition : */ -public class UserCategory { + +@Entity +@Table(name = "user_category") +public class UserCategory extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="user_category_id") + private Long userCategoryId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="user_id") + private User user; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name="category_id") + private Category category; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java index 16de450..1f48eb5 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java @@ -7,6 +7,7 @@ * DateTime : 2020/10/09 */ +// FIXME : 상속관계로 수정 필요 @Entity @Table(name = "user_resume_like") public class UserResumeLike { diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java index 621b35e..6cde91e 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java @@ -1,5 +1,7 @@ package com.resumers.server.oauth.model.entity; +import com.fasterxml.jackson.databind.ser.Serializers; + import javax.persistence.*; /** @@ -7,6 +9,7 @@ * DateTime : 2020/10/09 */ +// FIXME : 상속관계로 수정 필요 @Entity @Table(name = "user_resume_view") public class UserResumeView { From 797855d3b9321255eae9b7aa06e5061a2df19809 Mon Sep 17 00:00:00 2001 From: sehajyang Date: Thu, 15 Oct 2020 14:00:17 +0900 Subject: [PATCH 4/8] =?UTF-8?q?fix=20:=20#4=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=A1=B0=ED=9A=8C=20=EC=A0=84?= =?UTF-8?q?=EB=9E=B5=20lazy=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/ResumersOauthApplication.java | 13 ---------- .../server/oauth/model/entity/Category.java | 2 ++ .../server/oauth/model/entity/Certify.java | 4 +-- .../server/oauth/model/entity/CompanyTag.java | 4 +-- .../server/oauth/model/entity/Tag.java | 3 +++ .../server/oauth/model/entity/User.java | 11 ++++++-- .../oauth/model/entity/UserCategory.java | 25 +++++++++++++++++++ .../oauth/model/entity/UserCaterory.java | 9 ------- .../oauth/model/entity/UserCompany.java | 6 ++--- .../server/oauth/model/entity/UserDetail.java | 2 +- .../oauth/model/entity/UserPenalty.java | 4 +-- .../oauth/model/entity/UserResumeLike.java | 3 ++- .../oauth/model/entity/UserResumeView.java | 5 +++- .../server/oauth/model/entity/UserSocial.java | 2 +- .../server/oauth/model/entity/UserTag.java | 4 +-- 15 files changed, 58 insertions(+), 39 deletions(-) delete mode 100644 src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java create mode 100644 src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java delete mode 100644 src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java diff --git a/src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java b/src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java deleted file mode 100644 index 4c06762..0000000 --- a/src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.resumers.server.oauth; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class ResumersOauthApplication { - - public static void main(String[] args) { - SpringApplication.run(ResumersOauthApplication.class, args); - } - -} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Category.java b/src/main/java/com/resumers/server/oauth/model/entity/Category.java index d68a282..64f9a7b 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Category.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Category.java @@ -16,4 +16,6 @@ public class Category extends BaseEntity{ @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name ="category_id") public Long categoryId; + + public String title; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Certify.java b/src/main/java/com/resumers/server/oauth/model/entity/Certify.java index d0fd7cc..34ef4ff 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Certify.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Certify.java @@ -16,7 +16,7 @@ public class Certify extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name="certify_id") + @Column(name = "certify_id") private Long certifyId; @Enumerated(EnumType.STRING) @@ -28,7 +28,7 @@ public class Certify extends BaseEntity { @Enumerated(EnumType.STRING) private CertifiedStatus certifiedStatus; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = true) private User user; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java b/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java index c9e3716..b4dc3c1 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/CompanyTag.java @@ -17,11 +17,11 @@ public class CompanyTag extends BaseEntity { @Column(name = "companyTagId") private Long companyTagId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "tag_id") private Tag tag; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "company_id") private Company company; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Tag.java b/src/main/java/com/resumers/server/oauth/model/entity/Tag.java index 23959bf..e0a110d 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Tag.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Tag.java @@ -19,6 +19,9 @@ public class Tag { private Long TagId; private String title; + + @Enumerated(EnumType.STRING) private TagType tagType; + private String description; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/User.java b/src/main/java/com/resumers/server/oauth/model/entity/User.java index 67a8a48..fbdf59f 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/User.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/User.java @@ -44,18 +44,25 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user") private Set userResumeViews = new LinkedHashSet<>(); - @OneToMany(mappedBy = "user", orphanRemoval = true, fetch = FetchType.EAGER) + @OneToMany(mappedBy = "user", orphanRemoval = true) private Set userSocials = new LinkedHashSet<>(); - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name="user_id") private UserDetail userDetail; @OneToMany(mappedBy = "user") private Set userTags = new LinkedHashSet<>(); + @OneToMany(mappedBy = "user") + private Set userCategories = new LinkedHashSet<>(); + + @OneToMany(mappedBy = "user") + private Set userPenalties = new LinkedHashSet<>(); + @ManyToMany @JoinTable(name = "user_role", joinColumns = @JoinColumn(name ="user_id"), inverseJoinColumns= @JoinColumn(name="role_id")) private Set roles = new LinkedHashSet<>(); + } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java b/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java new file mode 100644 index 0000000..b8f0185 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserCategory.java @@ -0,0 +1,25 @@ +package com.resumers.server.oauth.model.entity; + +import javax.persistence.*; + +/** + * Created by sehajyang + * DateTime : 2020/10/09 + */ + +@Entity +@Table(name = "user_category") +public class UserCategory extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="user_category_id") + private Long userCategoryId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="user_id") + private User user; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name="category_id") + private Category category; +} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java b/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java deleted file mode 100644 index d53d880..0000000 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserCaterory.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.resumers.server.oauth.model.entity; - -/** - * Created by sehajyang - * DateTime : 2020/10/09 - * Descrpition : - */ -public class UserCaterory { -} diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java b/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java index 9cd9106..30eaaa9 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserCompany.java @@ -17,18 +17,18 @@ public class UserCompany extends BaseEntity { @Column(name = "user_company_id") private Long userCompanyId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "company_id") private Company company; @Enumerated(EnumType.STRING) private UserCompanyCertifyStatus userCompanyCertifyStatus; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "certify_id") private Certify certify; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java b/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java index 60b7be0..5163e45 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserDetail.java @@ -7,8 +7,8 @@ * DateTime : 2020/10/09 */ -@Table @Entity +@Table(name="user_detail") public class UserDetail extends BaseEntity{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java b/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java index 8e52fce..0676529 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserPenalty.java @@ -18,11 +18,11 @@ public class UserPenalty extends BaseEntity { @Column(name = "user_penalty_id") private Long userPenaltyId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="user_id") private User user; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name="penalty_id") private Penalty penalty; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java index e511c80..1f48eb5 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeLike.java @@ -7,6 +7,7 @@ * DateTime : 2020/10/09 */ +// FIXME : 상속관계로 수정 필요 @Entity @Table(name = "user_resume_like") public class UserResumeLike { @@ -15,7 +16,7 @@ public class UserResumeLike { @Column(name = "user_resume_like_id") private Long userResumeLikeId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java index 1044578..6cde91e 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserResumeView.java @@ -1,5 +1,7 @@ package com.resumers.server.oauth.model.entity; +import com.fasterxml.jackson.databind.ser.Serializers; + import javax.persistence.*; /** @@ -7,6 +9,7 @@ * DateTime : 2020/10/09 */ +// FIXME : 상속관계로 수정 필요 @Entity @Table(name = "user_resume_view") public class UserResumeView { @@ -15,7 +18,7 @@ public class UserResumeView { @Column(name = "user_resume_view_id") private Long userResumeViewId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java b/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java index 5b1367e..365c8fb 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserSocial.java @@ -23,7 +23,7 @@ public class UserSocial extends BaseEntity{ private String socialToken; private String email; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java b/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java index e2dbd52..29b7364 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/UserTag.java @@ -16,11 +16,11 @@ public class UserTag { @Column(name="user_tag_id") private Long userTagId; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="user_id") private User user; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name="tag_id") private Tag tag; } From 9bbbf9660b0e2026d61ba1e7c44e17c1b1f28147 Mon Sep 17 00:00:00 2001 From: sehajyang Date: Mon, 19 Oct 2020 19:46:19 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feat=20:=20#4=20User=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20API=20=EC=9E=91=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?H2=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * findAll, create, validation 작성 * H2 config 작성 * UserDTO 작성 --- gradle/wrapper/gradle-wrapper.properties | 5 ++- .../oauth/controller/SocialController.java | 4 +- .../oauth/controller/UserController.java | 37 ++++++++++++++++++ .../resumers/server/oauth/enums/RoleType.java | 1 - .../server/oauth/model/dto/UserDto.java | 30 ++++++++++++++ .../server/oauth/model/entity/Penalty.java | 1 - .../server/oauth/model/entity/User.java | 13 ++++++- .../oauth/repository/UserRepository.java | 5 +++ .../server/oauth/service/UserService.java | 39 +++++++++++++++++++ 9 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/resumers/server/oauth/controller/UserController.java diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 12d38de..2630c7e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Oct 15 19:57:46 KST 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/com/resumers/server/oauth/controller/SocialController.java b/src/main/java/com/resumers/server/oauth/controller/SocialController.java index 16e4cf3..59730f2 100644 --- a/src/main/java/com/resumers/server/oauth/controller/SocialController.java +++ b/src/main/java/com/resumers/server/oauth/controller/SocialController.java @@ -1,7 +1,7 @@ package com.resumers.server.oauth.controller; -import com.resumers.oauth.service.SocialService; -import com.resumers.oauth.service.UserService; +import com.resumers.server.oauth.service.SocialService; +import com.resumers.server.oauth.service.UserService; import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/com/resumers/server/oauth/controller/UserController.java b/src/main/java/com/resumers/server/oauth/controller/UserController.java new file mode 100644 index 0000000..fa79736 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/controller/UserController.java @@ -0,0 +1,37 @@ +package com.resumers.server.oauth.controller; + +import com.resumers.server.oauth.model.dto.UserDto; +import com.resumers.server.oauth.model.entity.User; +import com.resumers.server.oauth.service.UserService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * Created by sehajyang + * DateTime : 2020/10/19 + * Descrpition : + */ + +@Slf4j +@Controller +@RestController +@RequiredArgsConstructor +@RequestMapping("/users") +public class UserController { + private final UserService userService; + + // TODO : Response 객체 작성 + @GetMapping + public List findAll(UserDto.SearchQuery userDto){ + return userService.findAll(); + } + + @PostMapping + public void save(UserDto.InsertUser user) { + userService.create(user); + } +} diff --git a/src/main/java/com/resumers/server/oauth/enums/RoleType.java b/src/main/java/com/resumers/server/oauth/enums/RoleType.java index 980e338..1c0245d 100644 --- a/src/main/java/com/resumers/server/oauth/enums/RoleType.java +++ b/src/main/java/com/resumers/server/oauth/enums/RoleType.java @@ -3,7 +3,6 @@ /** * Created by sehajyang * DateTime : 2020/10/09 - * Descrpition : */ public enum RoleType { USER, ADMIN diff --git a/src/main/java/com/resumers/server/oauth/model/dto/UserDto.java b/src/main/java/com/resumers/server/oauth/model/dto/UserDto.java index 357ec73..fb1d44b 100644 --- a/src/main/java/com/resumers/server/oauth/model/dto/UserDto.java +++ b/src/main/java/com/resumers/server/oauth/model/dto/UserDto.java @@ -1,8 +1,38 @@ package com.resumers.server.oauth.model.dto; +import com.resumers.server.oauth.model.entity.User; +import lombok.Getter; +import lombok.NoArgsConstructor; + /** * Created by sehajyang * DateTime : 2020/10/03 */ + +@Getter +@NoArgsConstructor public class UserDto { + private Long userId; + private String email; + private String nickname; + private String description; + + public UserDto(User user) { + this.userId = user.getUserId(); + this.email = user.getEmail(); + this.nickname = user.getNickname(); + this.description = user.getDescription(); + } + + @Getter + public class SearchQuery extends UserDto{ + public SearchQuery(){ + super(); + } + } + + @Getter + @NoArgsConstructor + public class InsertUser extends UserDto { + } } diff --git a/src/main/java/com/resumers/server/oauth/model/entity/Penalty.java b/src/main/java/com/resumers/server/oauth/model/entity/Penalty.java index 1ff45c8..4c36008 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/Penalty.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/Penalty.java @@ -5,7 +5,6 @@ /** * Created by sehajyang * DateTime : 2020/10/09 - * Descrpition : */ @Entity diff --git a/src/main/java/com/resumers/server/oauth/model/entity/User.java b/src/main/java/com/resumers/server/oauth/model/entity/User.java index fbdf59f..8441ddd 100644 --- a/src/main/java/com/resumers/server/oauth/model/entity/User.java +++ b/src/main/java/com/resumers/server/oauth/model/entity/User.java @@ -1,6 +1,9 @@ package com.resumers.server.oauth.model.entity; import com.resumers.server.oauth.enums.UserStatusType; +import com.resumers.server.oauth.model.dto.UserDto; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.persistence.*; import java.util.LinkedHashSet; @@ -11,6 +14,8 @@ * DateTime : 2020/10/03 */ +@Getter +@NoArgsConstructor @Entity @Table(name = "user") public class User extends BaseEntity { @@ -24,7 +29,8 @@ public class User extends BaseEntity { private String password; private String nickname; - @OneToOne(mappedBy = "user") + @OneToOne + @JoinColumn(name = "file_id") private File file; @Column(length = 1000) @@ -65,4 +71,9 @@ public class User extends BaseEntity { joinColumns = @JoinColumn(name ="user_id"), inverseJoinColumns= @JoinColumn(name="role_id")) private Set roles = new LinkedHashSet<>(); + public User(UserDto userDto) { + this.email = userDto.getEmail(); + this.nickname = userDto.getNickname(); + this.description = userDto.getDescription(); + } } diff --git a/src/main/java/com/resumers/server/oauth/repository/UserRepository.java b/src/main/java/com/resumers/server/oauth/repository/UserRepository.java index 05b0a08..bb5a3c3 100644 --- a/src/main/java/com/resumers/server/oauth/repository/UserRepository.java +++ b/src/main/java/com/resumers/server/oauth/repository/UserRepository.java @@ -3,9 +3,14 @@ import com.resumers.server.oauth.model.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; + /** * Created by sehajyang * DateTime : 2020/10/03 */ public interface UserRepository extends JpaRepository { + List findAll(); + Optional findAllByEmailOrNickname(String email, String nickname); } diff --git a/src/main/java/com/resumers/server/oauth/service/UserService.java b/src/main/java/com/resumers/server/oauth/service/UserService.java index eaed7c2..6006eb3 100644 --- a/src/main/java/com/resumers/server/oauth/service/UserService.java +++ b/src/main/java/com/resumers/server/oauth/service/UserService.java @@ -1,12 +1,51 @@ package com.resumers.server.oauth.service; +import com.common.Utils; +import com.resumers.server.oauth.model.dto.UserDto; +import com.resumers.server.oauth.model.entity.User; +import com.resumers.server.oauth.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityExistsException; +import java.util.List; +import java.util.stream.Collectors; /** * Created by sehajyang * DateTime : 2020/10/03 */ +@Slf4j @Service +@RequiredArgsConstructor public class UserService { + private final UserRepository userRepository; + + public List findAll() { + List users = userRepository.findAll(); + return users.stream() + .map(UserDto::new) + .collect(Collectors.toList()); + } + + @Transactional + public void create(UserDto userDto) { + if (Utils.isNotEmpty(userDto)) { + validation(userDto.getEmail(), userDto.getNickname()); + User user = new User(userDto); + userRepository.save(user); + } + } + + // TODO : CustomException 만들어서 log error 라인 수정 + private void validation(String email, String nickname) { + if (Utils.isEmpty(email) || Utils.isEmpty(nickname)) { + log.error("BAD REQUEST EXCEPTION"); + } + userRepository.findAllByEmailOrNickname(email, nickname) + .ifPresent(user -> log.error("DUPLICATION ERROR")); + } } From cbecfbd8aea53c520e3600ddf7723a59e4063ac3 Mon Sep 17 00:00:00 2001 From: sehajyang Date: Sat, 31 Oct 2020 15:54:38 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feat=20:=20#5=20api=20response=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/controller/UserController.java | 9 +-- .../server/oauth/model/dto/ApiResponse.java | 71 +++++++++++++++++++ .../server/oauth/model/dto/EmptyObject.java | 16 +++++ .../server/oauth/model/dto/ErrorResponse.java | 8 +++ .../server/oauth/model/dto/MetaResponse.java | 17 +++++ 5 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/resumers/server/oauth/model/dto/ApiResponse.java create mode 100644 src/main/java/com/resumers/server/oauth/model/dto/EmptyObject.java create mode 100644 src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java create mode 100644 src/main/java/com/resumers/server/oauth/model/dto/MetaResponse.java diff --git a/src/main/java/com/resumers/server/oauth/controller/UserController.java b/src/main/java/com/resumers/server/oauth/controller/UserController.java index fa79736..ef9a840 100644 --- a/src/main/java/com/resumers/server/oauth/controller/UserController.java +++ b/src/main/java/com/resumers/server/oauth/controller/UserController.java @@ -1,19 +1,17 @@ package com.resumers.server.oauth.controller; +import com.resumers.server.oauth.model.dto.ApiResponse; import com.resumers.server.oauth.model.dto.UserDto; -import com.resumers.server.oauth.model.entity.User; import com.resumers.server.oauth.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; - import java.util.List; /** * Created by sehajyang * DateTime : 2020/10/19 - * Descrpition : */ @Slf4j @@ -24,10 +22,9 @@ public class UserController { private final UserService userService; - // TODO : Response 객체 작성 @GetMapping - public List findAll(UserDto.SearchQuery userDto){ - return userService.findAll(); + public ApiResponse> findAll(UserDto.SearchQuery userDto){ + return new ApiResponse<>(userService.findAll()); } @PostMapping diff --git a/src/main/java/com/resumers/server/oauth/model/dto/ApiResponse.java b/src/main/java/com/resumers/server/oauth/model/dto/ApiResponse.java new file mode 100644 index 0000000..017e0b2 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/dto/ApiResponse.java @@ -0,0 +1,71 @@ +package com.resumers.server.oauth.model.dto; + +import lombok.Data; +import org.slf4j.MDC; +/** + * Created by sehajyang + * DateTime : 2020/10/31 + */ + +@Data +public class ApiResponse { + private MetaResponse meta; + private T data; + private ErrorResponse error; + private String traceId; + + public ApiResponse() { + this.meta = new MetaResponse(); + this.data = (T) EmptyObject.OBJECT; + this.error = new ErrorResponse(); + setTraceId(); + } + + public ApiResponse(MetaResponse meta) { + this.meta = meta; + this.data = (T) EmptyObject.LIST; + this.error = new ErrorResponse(); + setTraceId(); + } + + public ApiResponse(T data) { + if (data == null) { + this.data = (T) EmptyObject.OBJECT; + this.meta = new MetaResponse(); + } else { + this.data = data; + this.meta = new MetaResponse(1L); + } + this.error = new ErrorResponse(); + setTraceId(); + } + + public ApiResponse(ErrorResponse error) { + this.meta = new MetaResponse(); + this.data = (T) EmptyObject.OBJECT; + this.error = error; + setTraceId(); + } + + public ApiResponse(Long totalCount, T data) { + this.meta = new MetaResponse(totalCount); + + if (data == null) { + this.data = (T) EmptyObject.LIST; + } else { + this.data = data; + } + + this.error = new ErrorResponse(); + setTraceId(); + } + + private void setTraceId() { + try { + this.traceId = MDC.get("TRACE_ID"); + } catch (NullPointerException e) { + this.traceId = ""; + } + } +} + diff --git a/src/main/java/com/resumers/server/oauth/model/dto/EmptyObject.java b/src/main/java/com/resumers/server/oauth/model/dto/EmptyObject.java new file mode 100644 index 0000000..9bee782 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/dto/EmptyObject.java @@ -0,0 +1,16 @@ +package com.resumers.server.oauth.model.dto; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import java.util.ArrayList; +import java.util.List; +/** + * Created by sehajyang + * DateTime : 2020/10/31 + */ + +@JsonSerialize +public class EmptyObject { + public static EmptyObject OBJECT = new EmptyObject(); + public static List LIST = new ArrayList(); +} + diff --git a/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java b/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java new file mode 100644 index 0000000..02eec67 --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java @@ -0,0 +1,8 @@ +package com.resumers.server.oauth.model.dto; + +/** + * Created by sehajyang + * DateTime : 2020/10/31 + */ +public class ErrorResponse { +} diff --git a/src/main/java/com/resumers/server/oauth/model/dto/MetaResponse.java b/src/main/java/com/resumers/server/oauth/model/dto/MetaResponse.java new file mode 100644 index 0000000..642cf9c --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/model/dto/MetaResponse.java @@ -0,0 +1,17 @@ +package com.resumers.server.oauth.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Created by sehajyang + * DateTime : 2020/10/31 + */ + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class MetaResponse { + private Long total; +} From 30386d57c70c25e16ca4ab4ba641ed8cda6312ee Mon Sep 17 00:00:00 2001 From: sehajyang Date: Sat, 31 Oct 2020 17:01:13 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat=20:=20#5=20ExceptionHandler=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ExceptionHandler * ErrorResponse * CustomException * ExceptionType * Message Component --- .../java/com/component/MessageComponent.java | 28 +++++++++++++ .../server/oauth/enums/ExceptionType.java | 31 +++++++++++++++ .../oauth/exception/CustomException.java | 28 +++++++++++++ .../oauth/exception/ExceptionHandler.java | 39 ++++++++++++++++++- .../server/oauth/model/dto/ErrorResponse.java | 26 +++++++++++++ 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/component/MessageComponent.java create mode 100644 src/main/java/com/resumers/server/oauth/enums/ExceptionType.java create mode 100644 src/main/java/com/resumers/server/oauth/exception/CustomException.java diff --git a/src/main/java/com/component/MessageComponent.java b/src/main/java/com/component/MessageComponent.java new file mode 100644 index 0000000..496fa3f --- /dev/null +++ b/src/main/java/com/component/MessageComponent.java @@ -0,0 +1,28 @@ +package com.component; + +import com.common.Utils; +import lombok.RequiredArgsConstructor; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.stereotype.Component; + +/** + * Created by sehajyang + * DateTime : 2020/10/31 + */ + +@Component +@RequiredArgsConstructor +public class MessageComponent { + private final ResourceBundleMessageSource messageSource; + + public String getMessage(String code) { + String message; + try { + message = messageSource.getMessage(code, null, LocaleContextHolder.getLocale()); + } catch (Exception e){ + message = "UNDEFINED ERROR"; + } + return Utils.isEmpty(message) ? "UNDEFINED ERROR" : message; + } +} diff --git a/src/main/java/com/resumers/server/oauth/enums/ExceptionType.java b/src/main/java/com/resumers/server/oauth/enums/ExceptionType.java new file mode 100644 index 0000000..b856f0b --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/enums/ExceptionType.java @@ -0,0 +1,31 @@ +package com.resumers.server.oauth.enums; + +import lombok.Getter; + +/** + * Created by sehajyang + * DateTime : 2020/10/31 + */ + +@Getter +public enum ExceptionType { + /* + * BadRequest 400 + * Unauthorized 401 + * Forbidden 403 + * Not Found 404 + * Server 500 + */ + + USER_NOT_FOUND(400, 1000, "존재하지 않는 유저입니다"); + + private Integer httpStatusCode; + private Integer code; + private String value; + + ExceptionType(Integer httpStatusCode, Integer code, String value) { + this.httpStatusCode = httpStatusCode; + this.code = code; + this.value = value; + } +} diff --git a/src/main/java/com/resumers/server/oauth/exception/CustomException.java b/src/main/java/com/resumers/server/oauth/exception/CustomException.java new file mode 100644 index 0000000..3b70b1f --- /dev/null +++ b/src/main/java/com/resumers/server/oauth/exception/CustomException.java @@ -0,0 +1,28 @@ +package com.resumers.server.oauth.exception; + +import com.resumers.server.oauth.enums.ExceptionType; +import lombok.Getter; +import lombok.NoArgsConstructor; + +/** + * Created by sehajyang + * DateTime : 2020/10/31 + */ + +@Getter +@NoArgsConstructor +public class CustomException extends RuntimeException{ + private ExceptionType type; + private String message; + + public CustomException(ExceptionType type) { + super(type.getValue()); + this.type = type; + } + + public CustomException(ExceptionType type, String message) { + super(type.getValue()); + this.type = type; + this.message = message; + } +} diff --git a/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java b/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java index d2422d9..45f47ad 100644 --- a/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java +++ b/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java @@ -1,8 +1,45 @@ package com.resumers.server.oauth.exception; +import com.component.MessageComponent; +import com.resumers.server.oauth.model.dto.ApiResponse; +import com.resumers.server.oauth.model.dto.EmptyObject; +import com.resumers.server.oauth.model.dto.ErrorResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.web.servlet.error.ErrorAttributes; +import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.context.request.WebRequest; + +import java.util.Map; + /** * Created by sehajyang * DateTime : 2020/10/03 */ -public class ExceptionHandler { + +@Slf4j +@RestController +@RestControllerAdvice +@RequiredArgsConstructor +public class ExceptionHandler implements ErrorController { + + private final ErrorAttributes errorAttributes; + private final MessageComponent message; + + @Override + public String getErrorPath() { + return "/error"; + } + + private Map getErrorAttribute(WebRequest webRequest) { + return errorAttributes.getErrorAttributes(webRequest, true); + } + + @org.springframework.web.bind.annotation.ExceptionHandler(value = CustomException.class) + public ResponseEntity> customException(WebRequest webRequest, CustomException e) { + return ResponseEntity.status(e.getType().getHttpStatusCode()).body(new ApiResponse<>(new ErrorResponse(e.getType().getCode(), getErrorAttribute(webRequest), message.getMessage()))); + } } diff --git a/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java b/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java index 02eec67..8c9c7bd 100644 --- a/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java +++ b/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java @@ -1,8 +1,34 @@ package com.resumers.server.oauth.model.dto; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.Map; + /** * Created by sehajyang * DateTime : 2020/10/31 */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) public class ErrorResponse { + private Integer status; + private String error; + private String message; + private LocalDateTime timeStamp; + + public ErrorResponse(Integer statusCode, Map errorAttribute, String message) { + this.status = statusCode; + this.message = message; + this.error = (String) errorAttribute.get("error"); + this.timeStamp = new Timestamp(((Date) errorAttribute.get("timestamp")).getTime()).toLocalDateTime(); + } } From edc7f01b6734d9d74354181c4ee88a9947f16fc7 Mon Sep 17 00:00:00 2001 From: sehajyang Date: Sat, 31 Oct 2020 17:16:07 +0900 Subject: [PATCH 8/8] =?UTF-8?q?fix=20:=20CustomException=20handling=20retu?= =?UTF-8?q?rn=20=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * messageComponent return StringUtil로 isEmpty 체크하도록 수정 * Error Response 생성자 파라미터 타입 변경 --- src/main/java/com/component/MessageComponent.java | 4 ++-- .../resumers/server/oauth/exception/ExceptionHandler.java | 3 ++- .../com/resumers/server/oauth/model/dto/ErrorResponse.java | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/component/MessageComponent.java b/src/main/java/com/component/MessageComponent.java index 496fa3f..d19289c 100644 --- a/src/main/java/com/component/MessageComponent.java +++ b/src/main/java/com/component/MessageComponent.java @@ -1,10 +1,10 @@ package com.component; -import com.common.Utils; import lombok.RequiredArgsConstructor; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; /** * Created by sehajyang @@ -23,6 +23,6 @@ public String getMessage(String code) { } catch (Exception e){ message = "UNDEFINED ERROR"; } - return Utils.isEmpty(message) ? "UNDEFINED ERROR" : message; + return StringUtils.isEmpty(message) ? "UNDEFINED ERROR" : message; } } diff --git a/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java b/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java index 45f47ad..62b775e 100644 --- a/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java +++ b/src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.java @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.boot.web.servlet.error.ErrorAttributes; import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -40,6 +41,6 @@ private Map getErrorAttribute(WebRequest webRequest) { @org.springframework.web.bind.annotation.ExceptionHandler(value = CustomException.class) public ResponseEntity> customException(WebRequest webRequest, CustomException e) { - return ResponseEntity.status(e.getType().getHttpStatusCode()).body(new ApiResponse<>(new ErrorResponse(e.getType().getCode(), getErrorAttribute(webRequest), message.getMessage()))); + return ResponseEntity.status(e.getType().getHttpStatusCode()).body(new ApiResponse<>(new ErrorResponse(e.getType().getCode(), getErrorAttribute(webRequest), e.getMessage()))); } } diff --git a/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java b/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java index 8c9c7bd..35b0386 100644 --- a/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java +++ b/src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.ToString; import java.sql.Timestamp; import java.time.LocalDateTime; @@ -25,8 +26,8 @@ public class ErrorResponse { private String message; private LocalDateTime timeStamp; - public ErrorResponse(Integer statusCode, Map errorAttribute, String message) { - this.status = statusCode; + public ErrorResponse(int status, Map errorAttribute, String message) { + this.status = status; this.message = message; this.error = (String) errorAttribute.get("error"); this.timeStamp = new Timestamp(((Date) errorAttribute.get("timestamp")).getTime()).toLocalDateTime();