From 89efa1cc1a1b631d0cac75331e47982ca35c5f94 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 15:34:33 +0900 Subject: [PATCH 001/301] =?UTF-8?q?#1=20[fix]=20=EC=86=8C=EC=85=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=8B=9C=20fcmToken=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/auth/dto/request/LoginRequestDto.java | 6 +++++- src/main/java/hous/server/domain/user/SocialInfo.java | 2 +- src/main/java/hous/server/domain/user/User.java | 11 +++++++---- .../server/service/auth/dto/request/LoginDto.java | 8 +++++--- .../java/hous/server/service/user/UserService.java | 2 +- .../service/user/dto/request/CreateUserDto.java | 6 ++++-- src/main/resources/messages/validation.properties | 1 + 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/controller/auth/dto/request/LoginRequestDto.java b/src/main/java/hous/server/controller/auth/dto/request/LoginRequestDto.java index 3056d65e..c7685463 100644 --- a/src/main/java/hous/server/controller/auth/dto/request/LoginRequestDto.java +++ b/src/main/java/hous/server/controller/auth/dto/request/LoginRequestDto.java @@ -22,7 +22,11 @@ public class LoginRequestDto { @NotBlank(message = "{auth.token.notBlank}") private String token; + @ApiModelProperty(value = "토큰 - fcmToken", example = "dfdafjdslkfjslfjslifsjvmdsklvdosijiofjamvsdlkvmiodsjfdiosmvsdjvosadjvosd") + @NotBlank(message = "{auth.fcmToken.notBlank}") + private String fcmToken; + public LoginDto toServiceDto() { - return LoginDto.of(socialType, token); + return LoginDto.of(socialType, token, fcmToken); } } diff --git a/src/main/java/hous/server/domain/user/SocialInfo.java b/src/main/java/hous/server/domain/user/SocialInfo.java index c862ea08..47eea94f 100644 --- a/src/main/java/hous/server/domain/user/SocialInfo.java +++ b/src/main/java/hous/server/domain/user/SocialInfo.java @@ -16,7 +16,7 @@ @Embeddable public class SocialInfo { - @Column(nullable = false, length = 200) + @Column(nullable = false, length = 300) private String socialId; @Column(nullable = false, length = 30) diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index 5513ba87..f816ea37 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -7,7 +7,6 @@ import javax.persistence.*; -@Table(name = "users") @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -20,16 +19,20 @@ public class User extends AuditingTimeEntity { @Embedded private SocialInfo socialInfo; + @Column(nullable = false, length = 300) + private String fcmToken; + @Column(nullable = false, length = 30) @Enumerated(EnumType.STRING) private UserStatus status; - private User(String socialId, UserSocialType socialType) { + private User(String socialId, UserSocialType socialType, String fcmToken) { this.socialInfo = SocialInfo.of(socialId, socialType); + this.fcmToken = fcmToken; this.status = UserStatus.ACTIVE; } - public static User newInstance(String socialId, UserSocialType socialType) { - return new User(socialId, socialType); + public static User newInstance(String socialId, UserSocialType socialType, String fcmToken) { + return new User(socialId, socialType, fcmToken); } } diff --git a/src/main/java/hous/server/service/auth/dto/request/LoginDto.java b/src/main/java/hous/server/service/auth/dto/request/LoginDto.java index 2b183b26..6d318a55 100644 --- a/src/main/java/hous/server/service/auth/dto/request/LoginDto.java +++ b/src/main/java/hous/server/service/auth/dto/request/LoginDto.java @@ -14,11 +14,13 @@ public class LoginDto { private String token; - public static LoginDto of(UserSocialType socialType, String token) { - return new LoginDto(socialType, token); + private String fcmToken; + + public static LoginDto of(UserSocialType socialType, String token, String fcmToken) { + return new LoginDto(socialType, token, fcmToken); } public CreateUserDto toCreateUserDto(String socialId) { - return CreateUserDto.of(socialId, socialType); + return CreateUserDto.of(socialId, socialType, fcmToken); } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index e51ece6b..86a40cb9 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -17,7 +17,7 @@ public class UserService { @Transactional public Long registerUser(CreateUserDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); - User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType())); + User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken())); return user.getId(); } } diff --git a/src/main/java/hous/server/service/user/dto/request/CreateUserDto.java b/src/main/java/hous/server/service/user/dto/request/CreateUserDto.java index a3435c07..d872f371 100644 --- a/src/main/java/hous/server/service/user/dto/request/CreateUserDto.java +++ b/src/main/java/hous/server/service/user/dto/request/CreateUserDto.java @@ -13,7 +13,9 @@ public class CreateUserDto { private UserSocialType socialType; - public static CreateUserDto of(String socialId, UserSocialType socialType) { - return new CreateUserDto(socialId, socialType); + private String fcmToken; + + public static CreateUserDto of(String socialId, UserSocialType socialType, String fcmToken) { + return new CreateUserDto(socialId, socialType, fcmToken); } } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 3ea60203..3ac1fe14 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -1,6 +1,7 @@ common.size.min=\uC870\uD68C\uD560 \uAC1C\uC218\uB97C {value} \uC774\uC0C1 \uC785\uB825\uD574\uC8FC\uC138\uC694. common.size.max=\uC870\uD68C\uD560 \uAC1C\uC218\uB97C {value} \uC774\uD558 \uC785\uB825\uD574\uC8FC\uC138\uC694. auth.token.notBlank=access token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +auth.fcmToken.notBlank=fcm token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. auth.accessToken.notBlank=access token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. auth.refreshToken.notBlank=refresh token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 142cc1d0f645a89177d224d3d91816e2c96e3378 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:41:57 +0900 Subject: [PATCH 002/301] =?UTF-8?q?#3=20[feat]=20User=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/user/Onboarding.java | 58 +++++++++++++++++++ .../java/hous/server/domain/user/Setting.java | 21 +++++++ .../java/hous/server/domain/user/Tag.java | 25 ++++++++ .../hous/server/domain/user/TestScore.java | 33 +++++++++++ .../java/hous/server/domain/user/User.java | 8 +++ 5 files changed, 145 insertions(+) create mode 100644 src/main/java/hous/server/domain/user/Onboarding.java create mode 100644 src/main/java/hous/server/domain/user/Setting.java create mode 100644 src/main/java/hous/server/domain/user/Tag.java create mode 100644 src/main/java/hous/server/domain/user/TestScore.java diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java new file mode 100644 index 00000000..62f0f488 --- /dev/null +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -0,0 +1,58 @@ +package hous.server.domain.user; + +import hous.server.domain.badge.Badge; +import hous.server.domain.badge.Represent; +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.personality.Personality; +import hous.server.domain.room.Participate; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Onboarding extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(length = 30) + private String nickname; + + @Column + private LocalDateTime birthday; + + @Column(length = 30) + private String introduction; + + @Column(nullable = false) + private boolean isChecked; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "personality_id") + private Personality personality; + + @OneToOne(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private Represent represent; + + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "test_score_id") + private TestScore testScore; + + @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List participates = new ArrayList<>(); + + @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List tags = new ArrayList<>(); + + @OneToMany(fetch = FetchType.LAZY) + @JoinColumn(name = "badge_id") + private final List badges = new ArrayList<>(); +} diff --git a/src/main/java/hous/server/domain/user/Setting.java b/src/main/java/hous/server/domain/user/Setting.java new file mode 100644 index 00000000..798ddfd3 --- /dev/null +++ b/src/main/java/hous/server/domain/user/Setting.java @@ -0,0 +1,21 @@ +package hous.server.domain.user; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Setting extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private boolean isPushNotification; +} diff --git a/src/main/java/hous/server/domain/user/Tag.java b/src/main/java/hous/server/domain/user/Tag.java new file mode 100644 index 00000000..76c4fcc9 --- /dev/null +++ b/src/main/java/hous/server/domain/user/Tag.java @@ -0,0 +1,25 @@ +package hous.server.domain.user; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Tag extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "onboarding_id", nullable = false) + private Onboarding onboarding; + + @Column(nullable = false, length = 30) + private String name; +} diff --git a/src/main/java/hous/server/domain/user/TestScore.java b/src/main/java/hous/server/domain/user/TestScore.java new file mode 100644 index 00000000..57076874 --- /dev/null +++ b/src/main/java/hous/server/domain/user/TestScore.java @@ -0,0 +1,33 @@ +package hous.server.domain.user; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class TestScore extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private int light; + + @Column(nullable = false) + private int noise; + + @Column(nullable = false) + private int clean; + + @Column(nullable = false) + private int smell; + + @Column(nullable = false) + private int introversion; +} diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index f816ea37..e45751c7 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -26,6 +26,14 @@ public class User extends AuditingTimeEntity { @Enumerated(EnumType.STRING) private UserStatus status; + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "onboarding_id", nullable = false) + private Onboarding onboarding; + + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "setting_id", nullable = false) + private Setting setting; + private User(String socialId, UserSocialType socialType, String fcmToken) { this.socialInfo = SocialInfo.of(socialId, socialType); this.fcmToken = fcmToken; From 62450b2e480ed1d3f0400cf4112dd9d566a71f03 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:42:52 +0900 Subject: [PATCH 003/301] =?UTF-8?q?#3=20[feat]=20Room=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/room/Participate.java | 27 +++++++++++ .../java/hous/server/domain/room/Room.java | 46 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/main/java/hous/server/domain/room/Participate.java create mode 100644 src/main/java/hous/server/domain/room/Room.java diff --git a/src/main/java/hous/server/domain/room/Participate.java b/src/main/java/hous/server/domain/room/Participate.java new file mode 100644 index 00000000..15f91b5f --- /dev/null +++ b/src/main/java/hous/server/domain/room/Participate.java @@ -0,0 +1,27 @@ +package hous.server.domain.room; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Participate extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "onboarding_id") + private Onboarding onboarding; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "room_id") + private Room room; +} diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java new file mode 100644 index 00000000..6fd679f8 --- /dev/null +++ b/src/main/java/hous/server/domain/room/Room.java @@ -0,0 +1,46 @@ +package hous.server.domain.room; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.rule.Rule; +import hous.server.domain.todo.Todo; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Room extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, length = 30) + private String name; + + @Column(nullable = false, length = 30) + private String code; + + @Column(nullable = false) + private int participantsCnt; + + @Column(nullable = false) + private int rulesCnt; + + @Column(nullable = false) + private int todosCnt; + + @OneToMany(mappedBy = "room", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List participates = new ArrayList<>(); + + @OneToMany(mappedBy = "room", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List rules = new ArrayList<>(); + + @OneToMany(mappedBy = "room", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List todos = new ArrayList<>(); +} From c55664263d0c70ac9f0ec813710cd99689b79849 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:43:20 +0900 Subject: [PATCH 004/301] =?UTF-8?q?#3=20[feat]=20Rule=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/domain/rule/Rule.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/hous/server/domain/rule/Rule.java diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java new file mode 100644 index 00000000..ace7acda --- /dev/null +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -0,0 +1,29 @@ +package hous.server.domain.rule; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.room.Room; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Rule extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "room_id") + private Room room; + + @Column(nullable = false, length = 100) + private String name; + + @Column(nullable = false) + private int idx; +} From 0ade8486ac6c767ca9274e12b66790ba41a0cdb0 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:44:08 +0900 Subject: [PATCH 005/301] =?UTF-8?q?#3=20[feat]=20Todo=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/todo/DayOfWeek.java | 11 ++++++ .../java/hous/server/domain/todo/Done.java | 27 +++++++++++++++ .../java/hous/server/domain/todo/Redo.java | 31 +++++++++++++++++ .../java/hous/server/domain/todo/Take.java | 32 +++++++++++++++++ .../java/hous/server/domain/todo/Todo.java | 34 +++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 src/main/java/hous/server/domain/todo/DayOfWeek.java create mode 100644 src/main/java/hous/server/domain/todo/Done.java create mode 100644 src/main/java/hous/server/domain/todo/Redo.java create mode 100644 src/main/java/hous/server/domain/todo/Take.java create mode 100644 src/main/java/hous/server/domain/todo/Todo.java diff --git a/src/main/java/hous/server/domain/todo/DayOfWeek.java b/src/main/java/hous/server/domain/todo/DayOfWeek.java new file mode 100644 index 00000000..3736af50 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/DayOfWeek.java @@ -0,0 +1,11 @@ +package hous.server.domain.todo; + +public enum DayOfWeek { + MONDAY, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY, + SUNDAY; +} diff --git a/src/main/java/hous/server/domain/todo/Done.java b/src/main/java/hous/server/domain/todo/Done.java new file mode 100644 index 00000000..9088757e --- /dev/null +++ b/src/main/java/hous/server/domain/todo/Done.java @@ -0,0 +1,27 @@ +package hous.server.domain.todo; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Done extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "onboarding_id") + private Onboarding onboarding; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "redo_id") + private Redo redo; +} diff --git a/src/main/java/hous/server/domain/todo/Redo.java b/src/main/java/hous/server/domain/todo/Redo.java new file mode 100644 index 00000000..5adcfc11 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/Redo.java @@ -0,0 +1,31 @@ +package hous.server.domain.todo; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Redo extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "take_id") + private Take take; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private DayOfWeek dayOfWeek; + + @OneToMany(mappedBy = "redo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List dones = new ArrayList<>(); +} diff --git a/src/main/java/hous/server/domain/todo/Take.java b/src/main/java/hous/server/domain/todo/Take.java new file mode 100644 index 00000000..518ef3ee --- /dev/null +++ b/src/main/java/hous/server/domain/todo/Take.java @@ -0,0 +1,32 @@ +package hous.server.domain.todo; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Take extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "todo_id", nullable = false) + private Todo todo; + + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "onboarding_id") + private Onboarding onboarding; + + @OneToMany(mappedBy = "take", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List redos = new ArrayList<>(); +} diff --git a/src/main/java/hous/server/domain/todo/Todo.java b/src/main/java/hous/server/domain/todo/Todo.java new file mode 100644 index 00000000..c9cc5748 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/Todo.java @@ -0,0 +1,34 @@ +package hous.server.domain.todo; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.room.Room; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Todo extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "room_id") + private Room room; + + @Column(nullable = false, length = 100) + private String name; + + @Column(nullable = false) + private boolean isPushNotification; + + @OneToMany(mappedBy = "todo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List takes = new ArrayList<>(); +} From b8c5e830838f55c8859e99733e6edbb22f8c7c31 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:44:28 +0900 Subject: [PATCH 006/301] =?UTF-8?q?#3=20[feat]=20Badge=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/domain/badge/Badge.java | 27 +++++++++++++++++++ .../hous/server/domain/badge/Represent.java | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/java/hous/server/domain/badge/Badge.java create mode 100644 src/main/java/hous/server/domain/badge/Represent.java diff --git a/src/main/java/hous/server/domain/badge/Badge.java b/src/main/java/hous/server/domain/badge/Badge.java new file mode 100644 index 00000000..903748e8 --- /dev/null +++ b/src/main/java/hous/server/domain/badge/Badge.java @@ -0,0 +1,27 @@ +package hous.server.domain.badge; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Badge extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, length = 30) + private String name; + + @Column(nullable = false, length = 100) + private String description; + + @Column(nullable = false, length = 300) + private String imageUrl; +} diff --git a/src/main/java/hous/server/domain/badge/Represent.java b/src/main/java/hous/server/domain/badge/Represent.java new file mode 100644 index 00000000..5f17c007 --- /dev/null +++ b/src/main/java/hous/server/domain/badge/Represent.java @@ -0,0 +1,27 @@ +package hous.server.domain.badge; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Represent extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "onboarding_id") + private Onboarding onboarding; + + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "badge_id") + private Badge badge; +} From 8e456775e62bbf0d8a7ee7782843be1c199d7d2d Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:44:43 +0900 Subject: [PATCH 007/301] =?UTF-8?q?#3=20[feat]=20Personality=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/personality/Personality.java | 52 +++++++++++++++++++ .../domain/personality/PersonalityColor.java | 10 ++++ .../domain/personality/PersonalityTest.java | 34 ++++++++++++ .../domain/personality/QuestionType.java | 9 ++++ 4 files changed, 105 insertions(+) create mode 100644 src/main/java/hous/server/domain/personality/Personality.java create mode 100644 src/main/java/hous/server/domain/personality/PersonalityColor.java create mode 100644 src/main/java/hous/server/domain/personality/PersonalityTest.java create mode 100644 src/main/java/hous/server/domain/personality/QuestionType.java diff --git a/src/main/java/hous/server/domain/personality/Personality.java b/src/main/java/hous/server/domain/personality/Personality.java new file mode 100644 index 00000000..ccb74598 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/Personality.java @@ -0,0 +1,52 @@ +package hous.server.domain.personality; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Personality extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, length = 30) + private String name; + + @Column(nullable = false, length = 300) + private String imageUrl; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private PersonalityColor color; + + @Column(nullable = false, length = 300) + private String title; + + @Column(nullable = false, length = 300) + private String description; + + @Column(nullable = false, length = 300) + private String recommendTitle; + + @Column(nullable = false, length = 300) + private String recommendTodo; + + @Column(nullable = false, length = 300) + private String goodPersonalityName; + + @Column(nullable = false, length = 300) + private String goodPersonalityImageUrl; + + @Column(nullable = false, length = 300) + private String badPersonalityName; + + @Column(nullable = false, length = 300) + private String badPersonalityImageUrl; +} diff --git a/src/main/java/hous/server/domain/personality/PersonalityColor.java b/src/main/java/hous/server/domain/personality/PersonalityColor.java new file mode 100644 index 00000000..6607179a --- /dev/null +++ b/src/main/java/hous/server/domain/personality/PersonalityColor.java @@ -0,0 +1,10 @@ +package hous.server.domain.personality; + +public enum PersonalityColor { + YELLOW, + RED, + BLUE, + PURPLE, + GREEN, + GRAY; +} diff --git a/src/main/java/hous/server/domain/personality/PersonalityTest.java b/src/main/java/hous/server/domain/personality/PersonalityTest.java new file mode 100644 index 00000000..e07ac723 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/PersonalityTest.java @@ -0,0 +1,34 @@ +package hous.server.domain.personality; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class PersonalityTest extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private int idx; + + @Column(nullable = false, length = 300) + private String question; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private QuestionType questionType; + + @Column(nullable = false, length = 300) + private String answers; + + @Column(nullable = false, length = 300) + private String imageUrl; +} diff --git a/src/main/java/hous/server/domain/personality/QuestionType.java b/src/main/java/hous/server/domain/personality/QuestionType.java new file mode 100644 index 00000000..300426fc --- /dev/null +++ b/src/main/java/hous/server/domain/personality/QuestionType.java @@ -0,0 +1,9 @@ +package hous.server.domain.personality; + +public enum QuestionType { + LIGHT, + NOISE, + CLEAN, + SMELL, + INTROVERSION; +} From b6b9a2c0d9dd11d42f5b0c6bfac04cb6353be522 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:46:27 +0900 Subject: [PATCH 008/301] =?UTF-8?q?#3=20[docs]=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/auth/AuthController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 4005ed22..de1b0595 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -41,7 +41,8 @@ public class AuthController { @ApiResponse( code = 400, message = "1. 유저의 socialType 를 입력해주세요.\n" - + "2. access token 을 입력해주세요.", + + "2. access token 을 입력해주세요.\n" + + "3. fcm token 을 입력해주세요.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요.", response = ErrorResponse.class), From 88a5e1a88e5130ac9eda4f35ad86dfdfef2e789e Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 23 Aug 2022 19:55:24 +0900 Subject: [PATCH 009/301] =?UTF-8?q?#3=20[fix]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=EC=8B=9C=20Onboarding,=20Setting=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/user/Onboarding.java | 18 ++++++++++++++++++ .../java/hous/server/domain/user/Setting.java | 12 ++++++++++++ .../java/hous/server/domain/user/User.java | 8 +++++--- .../hous/server/service/user/UserService.java | 4 +++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 62f0f488..17a65b7e 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -6,6 +6,7 @@ import hous.server.domain.personality.Personality; import hous.server.domain.room.Participate; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -55,4 +56,21 @@ public class Onboarding extends AuditingTimeEntity { @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "badge_id") private final List badges = new ArrayList<>(); + + @Builder(access = AccessLevel.PRIVATE) + public Onboarding(String nickname, LocalDateTime birthday, String introduction, boolean isChecked, Personality personality, Represent represent, TestScore testScore) { + this.nickname = nickname; + this.birthday = birthday; + this.introduction = introduction; + this.isChecked = isChecked; + this.personality = personality; + this.represent = represent; + this.testScore = testScore; + } + + public static Onboarding newInstance() { + return Onboarding.builder() + .isChecked(false) + .build(); + } } diff --git a/src/main/java/hous/server/domain/user/Setting.java b/src/main/java/hous/server/domain/user/Setting.java index 798ddfd3..eb17dd57 100644 --- a/src/main/java/hous/server/domain/user/Setting.java +++ b/src/main/java/hous/server/domain/user/Setting.java @@ -2,6 +2,7 @@ import hous.server.domain.common.AuditingTimeEntity; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -18,4 +19,15 @@ public class Setting extends AuditingTimeEntity { @Column(nullable = false) private boolean isPushNotification; + + @Builder(access = AccessLevel.PRIVATE) + public Setting(boolean isPushNotification) { + this.isPushNotification = isPushNotification; + } + + public static Setting newInstance() { + return Setting.builder() + .isPushNotification(true) + .build(); + } } diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index e45751c7..719a403f 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -34,13 +34,15 @@ public class User extends AuditingTimeEntity { @JoinColumn(name = "setting_id", nullable = false) private Setting setting; - private User(String socialId, UserSocialType socialType, String fcmToken) { + private User(String socialId, UserSocialType socialType, String fcmToken, Onboarding onboarding, Setting setting) { this.socialInfo = SocialInfo.of(socialId, socialType); this.fcmToken = fcmToken; this.status = UserStatus.ACTIVE; + this.onboarding = onboarding; + this.setting = setting; } - public static User newInstance(String socialId, UserSocialType socialType, String fcmToken) { - return new User(socialId, socialType, fcmToken); + public static User newInstance(String socialId, UserSocialType socialType, String fcmToken, Onboarding onboarding, Setting setting) { + return new User(socialId, socialType, fcmToken, onboarding, setting); } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 86a40cb9..437eaeee 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,5 +1,7 @@ package hous.server.service.user; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.Setting; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.user.dto.request.CreateUserDto; @@ -17,7 +19,7 @@ public class UserService { @Transactional public Long registerUser(CreateUserDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); - User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken())); + User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), Onboarding.newInstance(), Setting.newInstance())); return user.getId(); } } From 35830c9adbf8a8ae6ce4ce943b7794f50e8d7b01 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 23 Aug 2022 22:44:13 +0900 Subject: [PATCH 010/301] =?UTF-8?q?#6=20[feat]=20=EC=98=A8=EB=B3=B4?= =?UTF-8?q?=EB=94=A9=20=EC=A0=95=EB=B3=B4=20=EB=93=B1=EB=A1=9D=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 ++ .../user/UserRetrieveController.java | 42 +++++++++++++++++++ .../service/user/UserRetrieveService.java | 25 +++++++++++ .../response/CheckOnboardingInfoResponse.java | 24 +++++++++++ 4 files changed, 94 insertions(+) create mode 100644 src/main/java/hous/server/controller/user/UserRetrieveController.java create mode 100644 src/main/java/hous/server/service/user/UserRetrieveService.java create mode 100644 src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index ed3b81cc..8ae033e0 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -19,6 +19,9 @@ public enum SuccessCode { LOGIN_SUCCESS(OK, "로그인 성공입니다."), REISSUE_TOKEN_SUCCESS(OK, "토큰 갱신 성공입니다."), + // 온보딩 + CHECK_ONBOARDING_SUCCESS(OK, "온보딩 등록여부 조회 성공입니다."); + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java new file mode 100644 index 00000000..df24467b --- /dev/null +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -0,0 +1,42 @@ +package hous.server.controller.user; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.user.UserRetrieveService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +@Api(tags = "User") +@RequiredArgsConstructor +@RestController +@RequestMapping("/v1/user") +public class UserRetrieveController { + + private final UserRetrieveService userRetrieveService; + + @ApiOperation( + value = "[인증] 온보딩 페이지 - 나의 온보딩 정보 등록여부를 확인합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "온보딩 등록여부 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/onboarding/check") + public ResponseEntity checkMyOnboardingInfo(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.CHECK_ONBOARDING_SUCCESS, userRetrieveService.checkMyOnboardingInfo(userId)); + } +} diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java new file mode 100644 index 00000000..968b731a --- /dev/null +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -0,0 +1,25 @@ +package hous.server.service.user; + +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class UserRetrieveService { + + private final UserRepository userRepository; + + public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); + return !onboarding.isChecked() ? CheckOnboardingInfoResponse.of(false) : CheckOnboardingInfoResponse.of(true); + } + + +} diff --git a/src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java new file mode 100644 index 00000000..138648a2 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java @@ -0,0 +1,24 @@ +package hous.server.service.user.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@ToString +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class CheckOnboardingInfoResponse { + + private boolean isChecked; + + @JsonProperty("isChecked") + public boolean isChecked() { + return isChecked; + } + + public static CheckOnboardingInfoResponse of(boolean isChecked) { + return CheckOnboardingInfoResponse.builder() + .isChecked(isChecked) + .build(); + } +} From 804f129e4242999b3c08ff17ed7464feaf4b54ff Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 24 Aug 2022 00:04:27 +0900 Subject: [PATCH 011/301] =?UTF-8?q?#6=20[feat]=20=EC=98=A8=EB=B3=B4?= =?UTF-8?q?=EB=94=A9=20=EC=A0=95=EB=B3=B4=20=EB=93=B1=EB=A1=9D=20api=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 4 +- .../controller/user/UserController.java | 55 +++++++++++++++++++ .../hous/server/domain/user/Onboarding.java | 14 ++++- .../user/repository/OnboardingRepository.java | 7 +++ .../hous/server/service/user/UserService.java | 11 ++++ .../request/SetOnboardingInfoRequestDto.java | 29 ++++++++++ .../resources/messages/validation.properties | 12 ++-- 7 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 src/main/java/hous/server/controller/user/UserController.java create mode 100644 src/main/java/hous/server/domain/user/repository/OnboardingRepository.java create mode 100644 src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 8ae033e0..0080fb0f 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import static hous.server.common.success.SuccessStatusCode.CREATED; import static hous.server.common.success.SuccessStatusCode.OK; @Getter @@ -20,11 +21,12 @@ public enum SuccessCode { REISSUE_TOKEN_SUCCESS(OK, "토큰 갱신 성공입니다."), // 온보딩 - CHECK_ONBOARDING_SUCCESS(OK, "온보딩 등록여부 조회 성공입니다."); + CHECK_ONBOARDING_SUCCESS(OK, "온보딩 등록여부 조회 성공입니다."), /** * 201 CREATED */ + SET_ONBOARDING_SUCCESS(CREATED, "온보딩 정보 등록 성공입니다.") /** * 202 ACCEPTED diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java new file mode 100644 index 00000000..8acc18ed --- /dev/null +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -0,0 +1,55 @@ +package hous.server.controller.user; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.user.UserService; +import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; + +@Api(tags = "User") +@RequiredArgsConstructor +@RestController +@RequestMapping("/v1/user") +public class UserController { + + private final UserService userService; + + @ApiOperation( + value = "[인증] 온보딩 페이지 - 나의 온보딩 정보를 설정합니다.", + notes = "닉네임, 생년월일을 설정합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "온보딩 정보 등록 성공입니다."), + @ApiResponse( + code = 400, + message = "1. 닉네임을 입력해주세요. (nickname)\n" + + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)" + + "3. 생년월일을 입력해주세요. (birthday)\"\n", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @PostMapping("/onboarding") + public ResponseEntity setOnboardingInfo(@Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { + userService.setOnboardingInfo(request, userId); + return SuccessResponse.success(SuccessCode.SET_ONBOARDING_SUCCESS, null); + } + +} diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 17a65b7e..f14dfa05 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -1,5 +1,6 @@ package hous.server.domain.user; +import com.fasterxml.jackson.annotation.JsonFormat; import hous.server.domain.badge.Badge; import hous.server.domain.badge.Represent; import hous.server.domain.common.AuditingTimeEntity; @@ -11,7 +12,7 @@ import lombok.NoArgsConstructor; import javax.persistence.*; -import java.time.LocalDateTime; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -28,7 +29,8 @@ public class Onboarding extends AuditingTimeEntity { private String nickname; @Column - private LocalDateTime birthday; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") + private LocalDate birthday; @Column(length = 30) private String introduction; @@ -58,7 +60,7 @@ public class Onboarding extends AuditingTimeEntity { private final List badges = new ArrayList<>(); @Builder(access = AccessLevel.PRIVATE) - public Onboarding(String nickname, LocalDateTime birthday, String introduction, boolean isChecked, Personality personality, Represent represent, TestScore testScore) { + public Onboarding(String nickname, LocalDate birthday, String introduction, boolean isChecked, Personality personality, Represent represent, TestScore testScore) { this.nickname = nickname; this.birthday = birthday; this.introduction = introduction; @@ -73,4 +75,10 @@ public static Onboarding newInstance() { .isChecked(false) .build(); } + + public void setOnboarding(String nickname, LocalDate birthday) { + this.nickname = nickname; + this.birthday = birthday; + this.isChecked = true; + } } diff --git a/src/main/java/hous/server/domain/user/repository/OnboardingRepository.java b/src/main/java/hous/server/domain/user/repository/OnboardingRepository.java new file mode 100644 index 00000000..23dce44f --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/OnboardingRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.user.repository; + +import hous.server.domain.user.Onboarding; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OnboardingRepository extends JpaRepository { +} diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 437eaeee..3f30bc6b 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -3,8 +3,10 @@ import hous.server.domain.user.Onboarding; import hous.server.domain.user.Setting; import hous.server.domain.user.User; +import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.user.dto.request.CreateUserDto; +import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +17,7 @@ public class UserService { private final UserRepository userRepository; + private final OnboardingRepository onboardingRepository; @Transactional public Long registerUser(CreateUserDto request) { @@ -22,4 +25,12 @@ public Long registerUser(CreateUserDto request) { User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), Onboarding.newInstance(), Setting.newInstance())); return user.getId(); } + + @Transactional + public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); + onboarding.setOnboarding(request.getNickname(), request.getBirthday()); + onboardingRepository.save(onboarding); + } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java new file mode 100644 index 00000000..2dc92a43 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -0,0 +1,29 @@ +package hous.server.service.user.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.time.LocalDate; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetOnboardingInfoRequestDto { + + @ApiModelProperty(value = "닉네임", example = "혜조니") + @NotBlank(message = "{onboarding.nickname.notBlank}") + @Length(min = 1, max = 5, message = "{onboarding.nickname.legnth}") + private String nickname; + + @ApiModelProperty(value = "생년월일", example = "1999-03-04") + @NotNull(message = "{onboarding.birthday.notNull}") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") + private LocalDate birthday; +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 3ac1fe14..79732f46 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -6,11 +6,7 @@ auth.accessToken.notBlank=access token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC6 auth.refreshToken.notBlank=refresh token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.socialType.notNull=\uC720\uC800\uC758 socialType \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.name.notBlank=\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.phoneNumber.notBlank=\uC804\uD654\uBC88\uD638\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.phoneNumber.pattern=\uC804\uD654\uBC88\uD638 \uD615\uC2DD\uC73C\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.gender.notNull=\uC131\uBCC4\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.cleanAbility.notNull=\uBD80\uC9C0\uB7F0\uD55C \uC815\uB3C4\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.address.notBlank=\uC8FC\uC18C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.detailAddress.notBlank=\uC0C1\uC138\uC8FC\uC18C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.gatePassword.notBlank=\uACF5\uB3D9\uD604\uAD00 \uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.nickname.legnth=\uB2C9\uB124\uC784\uC740 \uCD5C\uB300 5\uAE00\uC790\uAE4C\uC9C0 \uAC00\uB2A5\uD569\uB2C8\uB2E4. +onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +\u00AE From caa927e3796b4f87b709dc03850b40a4581092d0 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 24 Aug 2022 01:21:08 +0900 Subject: [PATCH 012/301] =?UTF-8?q?#5=20[feat]=20=EB=B0=A9=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../server/common/success/SuccessCode.java | 2 + .../controller/room/RoomController.java | 54 +++++++++++++++++++ .../hous/server/domain/room/Participate.java | 14 +++++ .../java/hous/server/domain/room/Room.java | 25 +++++++++ .../repository/ParticipateRepository.java | 8 +++ .../ParticipateRepositoryCustom.java | 8 +++ .../repository/ParticipateRepositoryImpl.java | 21 ++++++++ .../room/repository/RoomRepository.java | 8 +++ .../room/repository/RoomRepositoryCustom.java | 6 +++ .../room/repository/RoomRepositoryImpl.java | 20 +++++++ .../hous/server/domain/user/Onboarding.java | 4 ++ .../hous/server/service/room/RoomService.java | 37 +++++++++++++ .../server/service/room/RoomServiceUtils.java | 38 +++++++++++++ .../dto/request/CreateRoomRequestDto.java | 21 ++++++++ .../room/dto/response/CreateRoomResponse.java | 23 ++++++++ .../resources/messages/validation.properties | 9 +--- 17 files changed, 292 insertions(+), 7 deletions(-) create mode 100644 src/main/java/hous/server/controller/room/RoomController.java create mode 100644 src/main/java/hous/server/domain/room/repository/ParticipateRepository.java create mode 100644 src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java create mode 100644 src/main/java/hous/server/domain/room/repository/RoomRepository.java create mode 100644 src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/room/RoomService.java create mode 100644 src/main/java/hous/server/service/room/RoomServiceUtils.java create mode 100644 src/main/java/hous/server/service/room/dto/request/CreateRoomRequestDto.java create mode 100644 src/main/java/hous/server/service/room/dto/response/CreateRoomResponse.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 1176eee0..7e06d7fe 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -56,6 +56,7 @@ public enum ErrorCode { */ CONFLICT_EXCEPTION(CONFLICT, "이미 존재합니다."), CONFLICT_USER_EXCEPTION(CONFLICT, "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), + CONFLICT_JOINED_ROOM_EXCEPTION(CONFLICT, "이미 참가중인 방이 있습니다."), /** * 415 Unsupported Media Type diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index ed3b81cc..7531aef7 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import static hous.server.common.success.SuccessStatusCode.CREATED; import static hous.server.common.success.SuccessStatusCode.OK; @Getter @@ -22,6 +23,7 @@ public enum SuccessCode { /** * 201 CREATED */ + CREATE_ROOM_SUCCESS(CREATED, "방 생성 성공입니다."), /** * 202 ACCEPTED diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java new file mode 100644 index 00000000..8b12babd --- /dev/null +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -0,0 +1,54 @@ +package hous.server.controller.room; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.room.RoomService; +import hous.server.service.room.dto.request.CreateRoomRequestDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; + +@Api(tags = "Room") +@RestController +@RequiredArgsConstructor +public class RoomController { + + private final RoomService roomService; + + @ApiOperation( + value = "방 만들기/입장 페이지 - 방을 만듭니다.", + notes = "방 이름을 8글자 이내로 설정하고 방 생성을 요청합니다.\n" + + "방이 생성되면 방의 id 와 초대코드를 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "방 생성 성공입니다."), + @ApiResponse( + code = 400, + message = "1. 방 이름을 입력해주세요.\n" + + "2. 방 이름을 8 글자 이내로 입력해주세요.", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "이미 참가중인 방이 있습니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.CREATED) + @PostMapping("/v1/room") + public ResponseEntity createRoom(@Valid @RequestBody CreateRoomRequestDto request, @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.CREATE_ROOM_SUCCESS, roomService.createRoom(request, userId)); + } +} diff --git a/src/main/java/hous/server/domain/room/Participate.java b/src/main/java/hous/server/domain/room/Participate.java index 15f91b5f..240199a8 100644 --- a/src/main/java/hous/server/domain/room/Participate.java +++ b/src/main/java/hous/server/domain/room/Participate.java @@ -3,6 +3,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,4 +25,17 @@ public class Participate extends AuditingTimeEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "room_id") private Room room; + + @Builder(access = AccessLevel.PRIVATE) + public Participate(Onboarding onboarding, Room room) { + this.onboarding = onboarding; + this.room = room; + } + + public static Participate newInstance(Onboarding onboarding, Room room) { + return Participate.builder() + .onboarding(onboarding) + .room(room) + .build(); + } } diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index 6fd679f8..f304aaa0 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -4,6 +4,7 @@ import hous.server.domain.rule.Rule; import hous.server.domain.todo.Todo; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -43,4 +44,28 @@ public class Room extends AuditingTimeEntity { @OneToMany(mappedBy = "room", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List todos = new ArrayList<>(); + + @Builder(access = AccessLevel.PRIVATE) + public Room(String name, String code, int participantsCnt, int rulesCnt, int todosCnt) { + this.name = name; + this.code = code; + this.participantsCnt = participantsCnt; + this.rulesCnt = rulesCnt; + this.todosCnt = todosCnt; + } + + public static Room newInstance(String name, String code) { + return Room.builder() + .name(name) + .code(code) + .participantsCnt(0) + .rulesCnt(0) + .todosCnt(0) + .build(); + } + + public void addParticipate(Participate participate) { + this.participates.add(participate); + this.participantsCnt += 1; + } } diff --git a/src/main/java/hous/server/domain/room/repository/ParticipateRepository.java b/src/main/java/hous/server/domain/room/repository/ParticipateRepository.java new file mode 100644 index 00000000..81f41ff4 --- /dev/null +++ b/src/main/java/hous/server/domain/room/repository/ParticipateRepository.java @@ -0,0 +1,8 @@ +package hous.server.domain.room.repository; + +import hous.server.domain.room.Participate; +import hous.server.domain.user.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ParticipateRepository extends JpaRepository, ParticipateRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java new file mode 100644 index 00000000..46134d70 --- /dev/null +++ b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java @@ -0,0 +1,8 @@ +package hous.server.domain.room.repository; + +import hous.server.domain.user.Onboarding; + +public interface ParticipateRepositoryCustom { + + boolean existsByOnboarding(Onboarding onboarding); +} diff --git a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java new file mode 100644 index 00000000..bca61de9 --- /dev/null +++ b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java @@ -0,0 +1,21 @@ +package hous.server.domain.room.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.user.Onboarding; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.room.QParticipate.participate; + +@RequiredArgsConstructor +public class ParticipateRepositoryImpl implements ParticipateRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public boolean existsByOnboarding(Onboarding onboarding) { + return queryFactory.selectOne() + .from(participate) + .where(participate.onboarding.eq(onboarding)) + .fetchFirst() != null; + } +} diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepository.java b/src/main/java/hous/server/domain/room/repository/RoomRepository.java new file mode 100644 index 00000000..557dcbd6 --- /dev/null +++ b/src/main/java/hous/server/domain/room/repository/RoomRepository.java @@ -0,0 +1,8 @@ +package hous.server.domain.room.repository; + +import hous.server.domain.room.Room; +import hous.server.domain.user.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RoomRepository extends JpaRepository, RoomRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java new file mode 100644 index 00000000..3159c976 --- /dev/null +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java @@ -0,0 +1,6 @@ +package hous.server.domain.room.repository; + +public interface RoomRepositoryCustom { + + boolean existsByRoomCode(String code); +} diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java new file mode 100644 index 00000000..2743940a --- /dev/null +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java @@ -0,0 +1,20 @@ +package hous.server.domain.room.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.room.QRoom.room; + +@RequiredArgsConstructor +public class RoomRepositoryImpl implements RoomRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public boolean existsByRoomCode(String code) { + return queryFactory.selectOne() + .from(room) + .where(room.code.eq(code)) + .fetchFirst() != null; + } +} diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 17a65b7e..45149bf3 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -73,4 +73,8 @@ public static Onboarding newInstance() { .isChecked(false) .build(); } + + public void addParticipate(Participate participate) { + this.participates.add(participate); + } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java new file mode 100644 index 00000000..c93e6a6a --- /dev/null +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -0,0 +1,37 @@ +package hous.server.service.room; + +import hous.server.domain.room.Participate; +import hous.server.domain.room.Room; +import hous.server.domain.room.repository.ParticipateRepository; +import hous.server.domain.room.repository.RoomRepository; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.dto.request.CreateRoomRequestDto; +import hous.server.service.room.dto.response.CreateRoomResponse; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class RoomService { + + private final UserRepository userRepository; + private final RoomRepository roomRepository; + private final ParticipateRepository participateRepository; + + @Transactional + public CreateRoomResponse createRoom(CreateRoomRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); + RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); + Room room = roomRepository.save(Room.newInstance(request.getName(), RoomServiceUtils.createUniqueRoomCode(roomRepository))); + Participate participate = participateRepository.save(Participate.newInstance(onboarding, room)); + onboarding.addParticipate(participate); + room.addParticipate(participate); + return CreateRoomResponse.of(room); + } +} diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java new file mode 100644 index 00000000..86648829 --- /dev/null +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -0,0 +1,38 @@ +package hous.server.service.room; + +import hous.server.common.exception.ConflictException; +import hous.server.common.exception.ErrorCode; +import hous.server.domain.room.repository.ParticipateRepository; +import hous.server.domain.room.repository.RoomRepository; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Random; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class RoomServiceUtils { + + public static void validateNotExistsParticipate(ParticipateRepository participateRepository, Onboarding onboarding) { + if (participateRepository.existsByOnboarding(onboarding)) { + throw new ConflictException(String.format("이미 참가중인 방이 있는 유저 (%s) 입니다.", onboarding.getId()), ErrorCode.CONFLICT_JOINED_ROOM_EXCEPTION); + } + } + + private static boolean isNotUniqueRoomCode(RoomRepository roomRepository, String code) { + return roomRepository.existsByRoomCode(code); + } + + static String createUniqueRoomCode(RoomRepository roomRepository) { + String code; + do { + Random random = new Random(); + code = random.ints(48, 91) + .filter(i -> (i <= 57 || i >= 65) && (i <= 90)) + .limit(8) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString(); + } while (isNotUniqueRoomCode(roomRepository, code)); + return code; + } +} diff --git a/src/main/java/hous/server/service/room/dto/request/CreateRoomRequestDto.java b/src/main/java/hous/server/service/room/dto/request/CreateRoomRequestDto.java new file mode 100644 index 00000000..34c8a37b --- /dev/null +++ b/src/main/java/hous/server/service/room/dto/request/CreateRoomRequestDto.java @@ -0,0 +1,21 @@ +package hous.server.service.room.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CreateRoomRequestDto { + + @ApiModelProperty(value = "방 이름", example = "러블리더블리") + @NotBlank(message = "{room.name.notBlank}") + @Size(max = 8, message = "{room.name.max}") + private String name; +} diff --git a/src/main/java/hous/server/service/room/dto/response/CreateRoomResponse.java b/src/main/java/hous/server/service/room/dto/response/CreateRoomResponse.java new file mode 100644 index 00000000..e8797158 --- /dev/null +++ b/src/main/java/hous/server/service/room/dto/response/CreateRoomResponse.java @@ -0,0 +1,23 @@ +package hous.server.service.room.dto.response; + +import hous.server.domain.room.Room; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class CreateRoomResponse { + + private Long roomId; + + private String roomCode; + + public static CreateRoomResponse of(Room room) { + return CreateRoomResponse.builder() + .roomId(room.getId()) + .roomCode(room.getCode()) + .build(); + } +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 3ac1fe14..eb8d4990 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -7,10 +7,5 @@ auth.refreshToken.notBlank=refresh token \uC744 \uC785\uB825\uD574\uC8FC\uC138\u user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.socialType.notNull=\uC720\uC800\uC758 socialType \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.name.notBlank=\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.phoneNumber.notBlank=\uC804\uD654\uBC88\uD638\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.phoneNumber.pattern=\uC804\uD654\uBC88\uD638 \uD615\uC2DD\uC73C\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.gender.notNull=\uC131\uBCC4\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.cleanAbility.notNull=\uBD80\uC9C0\uB7F0\uD55C \uC815\uB3C4\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.address.notBlank=\uC8FC\uC18C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.detailAddress.notBlank=\uC0C1\uC138\uC8FC\uC18C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.gatePassword.notBlank=\uACF5\uB3D9\uD604\uAD00 \uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 9221599cb324fdbf7c4cd753a4d6784f7164bb1f Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 24 Aug 2022 10:12:17 +0900 Subject: [PATCH 013/301] =?UTF-8?q?#5=20[feat]=20=EC=B0=B8=EA=B0=80?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EB=B0=A9=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 2 + .../room/RoomRetrieveController.java | 42 +++++++++++++++++++ .../service/room/RoomRetrieveService.java | 28 +++++++++++++ .../room/dto/response/GetRoomResponse.java | 35 ++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/main/java/hous/server/controller/room/RoomRetrieveController.java create mode 100644 src/main/java/hous/server/service/room/RoomRetrieveService.java create mode 100644 src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 7531aef7..cc648346 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -20,6 +20,8 @@ public enum SuccessCode { LOGIN_SUCCESS(OK, "로그인 성공입니다."), REISSUE_TOKEN_SUCCESS(OK, "토큰 갱신 성공입니다."), + GET_ROOM_SUCCESS(OK, "참가중인 방 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java new file mode 100644 index 00000000..aa83ad58 --- /dev/null +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -0,0 +1,42 @@ +package hous.server.controller.room; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.room.RoomRetrieveService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +@Api(tags = "Room") +@RequiredArgsConstructor +@RestController +public class RoomRetrieveController { + + private final RoomRetrieveService roomRetrieveService; + + @ApiOperation( + value = "방 만들기/입장 페이지 - 참가중인 방을 조회합니다.", + notes = "참가중인 방이 있다면 방의 id 를 전달합니다.\n" + + "참가중인 방이 없다면 null 을 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "참가중인 방 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/v1/room") + public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_ROOM_SUCCESS, roomRetrieveService.getRoom(userId)); + } +} diff --git a/src/main/java/hous/server/service/room/RoomRetrieveService.java b/src/main/java/hous/server/service/room/RoomRetrieveService.java new file mode 100644 index 00000000..b1e83f02 --- /dev/null +++ b/src/main/java/hous/server/service/room/RoomRetrieveService.java @@ -0,0 +1,28 @@ +package hous.server.service.room; + +import hous.server.domain.room.Participate; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.dto.response.GetRoomResponse; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class RoomRetrieveService { + + private final UserRepository userRepository; + + public GetRoomResponse getRoom(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + if (user.getOnboarding().getParticipates().size() == 0) { + return GetRoomResponse.of(null); + } else { + Participate participate = user.getOnboarding().getParticipates().get(0); + return GetRoomResponse.of(participate.getRoom()); + } + } +} diff --git a/src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java b/src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java new file mode 100644 index 00000000..a04d61b5 --- /dev/null +++ b/src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java @@ -0,0 +1,35 @@ +package hous.server.service.room.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.room.Room; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class GetRoomResponse { + + private boolean isJoiningRoom; + private Long roomId; + + @JsonProperty("isJoiningRoom") + public boolean isJoiningRoom() { + return isJoiningRoom; + } + + public static GetRoomResponse of(Room room) { + if (room == null) { + return GetRoomResponse.builder() + .isJoiningRoom(false) + .roomId(null) + .build(); + } else { + return GetRoomResponse.builder() + .isJoiningRoom(true) + .roomId(room.getId()) + .build(); + } + } +} From 544f251c869f4a5982ccdbce907a65285ab3ee42 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 24 Aug 2022 10:13:11 +0900 Subject: [PATCH 014/301] =?UTF-8?q?#5=20[docs]=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/room/RoomController.java | 3 ++- .../hous/server/controller/room/RoomRetrieveController.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 8b12babd..b76ee5ea 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -30,7 +30,7 @@ public class RoomController { private final RoomService roomService; @ApiOperation( - value = "방 만들기/입장 페이지 - 방을 만듭니다.", + value = "[인증] 방 만들기/입장 페이지 - 방을 만듭니다.", notes = "방 이름을 8글자 이내로 설정하고 방 생성을 요청합니다.\n" + "방이 생성되면 방의 id 와 초대코드를 전달합니다." ) @@ -42,6 +42,7 @@ public class RoomController { + "2. 방 이름을 8 글자 이내로 입력해주세요.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "이미 참가중인 방이 있습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index aa83ad58..e77bf657 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -24,7 +24,7 @@ public class RoomRetrieveController { private final RoomRetrieveService roomRetrieveService; @ApiOperation( - value = "방 만들기/입장 페이지 - 참가중인 방을 조회합니다.", + value = "[인증] 방 만들기/입장 페이지 - 참가중인 방을 조회합니다.", notes = "참가중인 방이 있다면 방의 id 를 전달합니다.\n" + "참가중인 방이 없다면 null 을 전달합니다." ) From 58902cd1684ab7851e0175f9059e007c983b3e24 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 24 Aug 2022 10:53:05 +0900 Subject: [PATCH 015/301] =?UTF-8?q?#5=20[feat]=20=EB=B0=A9=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../server/common/success/SuccessCode.java | 1 + .../controller/room/RoomController.java | 34 ++++++++++++++----- .../room/repository/RoomRepositoryCustom.java | 4 +++ .../room/repository/RoomRepositoryImpl.java | 9 +++++ .../hous/server/service/room/RoomService.java | 18 ++++++++-- .../server/service/room/RoomServiceUtils.java | 16 +++++++-- ...oomResponse.java => RoomInfoResponse.java} | 6 ++-- 8 files changed, 73 insertions(+), 16 deletions(-) rename src/main/java/hous/server/service/room/dto/response/{CreateRoomResponse.java => RoomInfoResponse.java} (76%) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 7e06d7fe..f7bebef8 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -40,6 +40,7 @@ public enum ErrorCode { NOT_FOUND_USER_EXCEPTION(NOT_FOUND, "탈퇴했거나 존재하지 않는 유저입니다."), NOT_FOUND_REFRESH_TOKEN_EXCEPTION(NOT_FOUND, "만료된 리프레시 토큰입니다."), NOT_FOUND_ONBOARDING_EXCEPTION(NOT_FOUND, "유저의 온보딩 정보가 존재하지 않습니다."), + NOT_FOUND_ROOM_EXCEPTION(NOT_FOUND, "존재하지 않는 방입니다."), /** * 405 Method Not Allowed diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index cc648346..7e2657ac 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -21,6 +21,7 @@ public enum SuccessCode { REISSUE_TOKEN_SUCCESS(OK, "토큰 갱신 성공입니다."), GET_ROOM_SUCCESS(OK, "참가중인 방 조회 성공입니다."), + JOIN_ROOM_SUCCESS(OK, "방 참여 성공입니다."), /** * 201 CREATED diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index b76ee5ea..1f326493 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -7,17 +7,11 @@ import hous.server.config.resolver.UserId; import hous.server.service.room.RoomService; import hous.server.service.room.dto.request.CreateRoomRequestDto; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -52,4 +46,28 @@ public class RoomController { public ResponseEntity createRoom(@Valid @RequestBody CreateRoomRequestDto request, @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CREATE_ROOM_SUCCESS, roomService.createRoom(request, userId)); } + + @ApiOperation( + value = "[인증] 방 만들기/입장 페이지 - 방에 참여합니다.", + notes = "방 코드 입력 후 페이지에서 참여하기 버튼을 누를 때 요청합니다.\n" + + "방 초대코드로 조회한 방의 id 로 입장을 요청합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "방 참여 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 방입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 409, message = "이미 참가중인 방이 있습니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @PostMapping("/v1/room/{roomId}/join") + public ResponseEntity joinRoom(@ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") + @PathVariable Long roomId, + @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.JOIN_ROOM_SUCCESS, roomService.joinRoom(roomId, userId)); + } } diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java index 3159c976..2e0ffcf7 100644 --- a/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java @@ -1,6 +1,10 @@ package hous.server.domain.room.repository; +import hous.server.domain.room.Room; + public interface RoomRepositoryCustom { boolean existsByRoomCode(String code); + + Room findRoomById(Long id); } diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java index 2743940a..cca0bccc 100644 --- a/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java @@ -1,6 +1,7 @@ package hous.server.domain.room.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.room.Room; import lombok.RequiredArgsConstructor; import static hous.server.domain.room.QRoom.room; @@ -17,4 +18,12 @@ public boolean existsByRoomCode(String code) { .where(room.code.eq(code)) .fetchFirst() != null; } + + @Override + public Room findRoomById(Long id) { + return queryFactory + .selectFrom(room) + .where(room.id.eq(id)) + .fetchOne(); + } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index c93e6a6a..a2bf4c08 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -8,7 +8,7 @@ import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.dto.request.CreateRoomRequestDto; -import hous.server.service.room.dto.response.CreateRoomResponse; +import hous.server.service.room.dto.response.RoomInfoResponse; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -24,7 +24,7 @@ public class RoomService { private final ParticipateRepository participateRepository; @Transactional - public CreateRoomResponse createRoom(CreateRoomRequestDto request, Long userId) { + public RoomInfoResponse createRoom(CreateRoomRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); @@ -32,6 +32,18 @@ public CreateRoomResponse createRoom(CreateRoomRequestDto request, Long userId) Participate participate = participateRepository.save(Participate.newInstance(onboarding, room)); onboarding.addParticipate(participate); room.addParticipate(participate); - return CreateRoomResponse.of(room); + return RoomInfoResponse.of(room); + } + + @Transactional + public RoomInfoResponse joinRoom(Long roomId, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); + RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); + Room room = RoomServiceUtils.findRoomById(roomRepository, roomId); + Participate participate = participateRepository.save(Participate.newInstance(onboarding, room)); + onboarding.addParticipate(participate); + room.addParticipate(participate); + return RoomInfoResponse.of(room); } } diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 86648829..1d878980 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -1,7 +1,8 @@ package hous.server.service.room; import hous.server.common.exception.ConflictException; -import hous.server.common.exception.ErrorCode; +import hous.server.common.exception.NotFoundException; +import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.user.Onboarding; @@ -10,13 +11,24 @@ import java.util.Random; +import static hous.server.common.exception.ErrorCode.CONFLICT_JOINED_ROOM_EXCEPTION; +import static hous.server.common.exception.ErrorCode.NOT_FOUND_ROOM_EXCEPTION; + @NoArgsConstructor(access = AccessLevel.PRIVATE) public class RoomServiceUtils { public static void validateNotExistsParticipate(ParticipateRepository participateRepository, Onboarding onboarding) { if (participateRepository.existsByOnboarding(onboarding)) { - throw new ConflictException(String.format("이미 참가중인 방이 있는 유저 (%s) 입니다.", onboarding.getId()), ErrorCode.CONFLICT_JOINED_ROOM_EXCEPTION); + throw new ConflictException(String.format("이미 참가중인 방이 있는 유저 (%s) 입니다.", onboarding.getId()), CONFLICT_JOINED_ROOM_EXCEPTION); + } + } + + public static Room findRoomById(RoomRepository roomRepository, Long roomId) { + Room room = roomRepository.findRoomById(roomId); + if (room == null) { + throw new NotFoundException(String.format("존재하지 않는 방 (%s) 입니다", roomId), NOT_FOUND_ROOM_EXCEPTION); } + return room; } private static boolean isNotUniqueRoomCode(RoomRepository roomRepository, String code) { diff --git a/src/main/java/hous/server/service/room/dto/response/CreateRoomResponse.java b/src/main/java/hous/server/service/room/dto/response/RoomInfoResponse.java similarity index 76% rename from src/main/java/hous/server/service/room/dto/response/CreateRoomResponse.java rename to src/main/java/hous/server/service/room/dto/response/RoomInfoResponse.java index e8797158..55e61c9f 100644 --- a/src/main/java/hous/server/service/room/dto/response/CreateRoomResponse.java +++ b/src/main/java/hous/server/service/room/dto/response/RoomInfoResponse.java @@ -8,14 +8,14 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) -public class CreateRoomResponse { +public class RoomInfoResponse { private Long roomId; private String roomCode; - public static CreateRoomResponse of(Room room) { - return CreateRoomResponse.builder() + public static RoomInfoResponse of(Room room) { + return RoomInfoResponse.builder() .roomId(room.getId()) .roomCode(room.getCode()) .build(); From a89c4c9d9878e1254e9a47e3e82d491232ab114c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 24 Aug 2022 11:13:57 +0900 Subject: [PATCH 016/301] =?UTF-8?q?#5=20[docs]=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/room/RoomController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 1f326493..a2af8f38 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -32,8 +32,8 @@ public class RoomController { @ApiResponse(code = 201, message = "방 생성 성공입니다."), @ApiResponse( code = 400, - message = "1. 방 이름을 입력해주세요.\n" - + "2. 방 이름을 8 글자 이내로 입력해주세요.", + message = "1. 방 이름을 입력해주세요. (name)\n" + + "2. 방 이름을 8 글자 이내로 입력해주세요. (name)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), From 37ae520b481bff605dffeda39afab1a228885a38 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 25 Aug 2022 13:29:59 +0900 Subject: [PATCH 017/301] =?UTF-8?q?#6=20[fix]=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20201=20->=20200=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/success/SuccessCode.java | 3 +-- .../java/hous/server/controller/user/UserController.java | 8 ++++---- src/main/java/hous/server/service/user/UserService.java | 1 - .../user/dto/request/SetOnboardingInfoRequestDto.java | 2 +- src/main/resources/messages/validation.properties | 4 ++-- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 0080fb0f..089616cc 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -4,7 +4,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import static hous.server.common.success.SuccessStatusCode.CREATED; import static hous.server.common.success.SuccessStatusCode.OK; @Getter @@ -22,11 +21,11 @@ public enum SuccessCode { // 온보딩 CHECK_ONBOARDING_SUCCESS(OK, "온보딩 등록여부 조회 성공입니다."), + SET_ONBOARDING_SUCCESS(OK, "온보딩 정보 등록 성공입니다.") /** * 201 CREATED */ - SET_ONBOARDING_SUCCESS(CREATED, "온보딩 정보 등록 성공입니다.") /** * 202 ACCEPTED diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 8acc18ed..f689b303 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -31,15 +31,15 @@ public class UserController { @ApiOperation( value = "[인증] 온보딩 페이지 - 나의 온보딩 정보를 설정합니다.", - notes = "닉네임, 생년월일을 설정합니다." + notes = "닉네임, 생년월일을 설정합니다. 성공시 data로 null을 보냅니다." ) @ApiResponses(value = { - @ApiResponse(code = 201, message = "온보딩 정보 등록 성공입니다."), + @ApiResponse(code = 200, message = "온보딩 정보 등록 성공입니다."), @ApiResponse( code = 400, message = "1. 닉네임을 입력해주세요. (nickname)\n" - + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)" - + "3. 생년월일을 입력해주세요. (birthday)\"\n", + + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" + + "3. 생년월일을 입력해주세요. (birthday)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 3f30bc6b..85de6b47 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -31,6 +31,5 @@ public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); onboarding.setOnboarding(request.getNickname(), request.getBirthday()); - onboardingRepository.save(onboarding); } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index 2dc92a43..4afd24f6 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -19,7 +19,7 @@ public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") @NotBlank(message = "{onboarding.nickname.notBlank}") - @Length(min = 1, max = 5, message = "{onboarding.nickname.legnth}") + @Length(min = 1, max = 5, message = "{onboarding.nickname.length}") private String nickname; @ApiModelProperty(value = "생년월일", example = "1999-03-04") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 79732f46..c4a28b6f 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -7,6 +7,6 @@ auth.refreshToken.notBlank=refresh token \uC744 \uC785\uB825\uD574\uC8FC\uC138\u user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.socialType.notNull=\uC720\uC800\uC758 socialType \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.nickname.legnth=\uB2C9\uB124\uC784\uC740 \uCD5C\uB300 5\uAE00\uC790\uAE4C\uC9C0 \uAC00\uB2A5\uD569\uB2C8\uB2E4. +onboarding.nickname.length=\uB2C9\uB124\uC784\uC740 \uCD5C\uB300 5\uAE00\uC790\uAE4C\uC9C0 \uAC00\uB2A5\uD569\uB2C8\uB2E4. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -\u00AE + From f4c5162af4ca869df87133f1380a187277c71882 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 25 Aug 2022 22:35:09 +0900 Subject: [PATCH 018/301] =?UTF-8?q?#9=20[fix]=20dto=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/JwtUtils.java | 6 +++--- .../java/hous/server/service/auth/CreateTokenService.java | 6 +++--- .../response/{TokenResponseDto.java => TokenResponse.java} | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) rename src/main/java/hous/server/service/auth/dto/response/{TokenResponseDto.java => TokenResponse.java} (72%) diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index f0bfbefb..f5968c74 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -1,7 +1,7 @@ package hous.server.common.util; import hous.server.config.security.JwtConstants; -import hous.server.service.auth.dto.response.TokenResponseDto; +import hous.server.service.auth.dto.response.TokenResponse; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.security.Keys; @@ -35,7 +35,7 @@ public JwtUtils(@Value("${jwt.secret}") String secretKey, RedisTemplate redisTem this.secretKey = Keys.hmacShaKeyFor(keyBytes); } - public TokenResponseDto createTokenInfo(Long userId) { + public TokenResponse createTokenInfo(Long userId) { long now = (new Date()).getTime(); Date accessTokenExpiresIn = new Date(now + ACCESS_TOKEN_EXPIRE_TIME); @@ -57,7 +57,7 @@ public TokenResponseDto createTokenInfo(Long userId) { redisTemplate.opsForValue() .set("RT:" + userId, refreshToken, REFRESH_TOKEN_EXPIRE_TIME, TimeUnit.MILLISECONDS); - return TokenResponseDto.of(accessToken, refreshToken); + return TokenResponse.of(accessToken, refreshToken); } public boolean validateToken(String token) { diff --git a/src/main/java/hous/server/service/auth/CreateTokenService.java b/src/main/java/hous/server/service/auth/CreateTokenService.java index c7fa5a03..bb764647 100644 --- a/src/main/java/hous/server/service/auth/CreateTokenService.java +++ b/src/main/java/hous/server/service/auth/CreateTokenService.java @@ -3,7 +3,7 @@ import hous.server.common.exception.UnAuthorizedException; import hous.server.common.util.JwtUtils; import hous.server.service.auth.dto.request.TokenRequestDto; -import hous.server.service.auth.dto.response.TokenResponseDto; +import hous.server.service.auth.dto.response.TokenResponse; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -20,12 +20,12 @@ public class CreateTokenService { private final RedisTemplate redisTemplate; @Transactional - public TokenResponseDto createTokenInfo(Long userId) { + public TokenResponse createTokenInfo(Long userId) { return jwtProvider.createTokenInfo(userId); } @Transactional - public TokenResponseDto reissueToken(TokenRequestDto request) { + public TokenResponse reissueToken(TokenRequestDto request) { if (!jwtProvider.validateToken(request.getRefreshToken())) { throw new UnAuthorizedException(String.format("주어진 리프레시 토큰 (%s) 이 유효하지 않습니다.", request.getRefreshToken())); } diff --git a/src/main/java/hous/server/service/auth/dto/response/TokenResponseDto.java b/src/main/java/hous/server/service/auth/dto/response/TokenResponse.java similarity index 72% rename from src/main/java/hous/server/service/auth/dto/response/TokenResponseDto.java rename to src/main/java/hous/server/service/auth/dto/response/TokenResponse.java index 18054b77..28802662 100644 --- a/src/main/java/hous/server/service/auth/dto/response/TokenResponseDto.java +++ b/src/main/java/hous/server/service/auth/dto/response/TokenResponse.java @@ -7,13 +7,13 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) -public class TokenResponseDto { +public class TokenResponse { private String accessToken; private String refreshToken; - public static TokenResponseDto of(String accessToken, String refreshToken) { - return TokenResponseDto.builder() + public static TokenResponse of(String accessToken, String refreshToken) { + return TokenResponse.builder() .accessToken(accessToken) .refreshToken(refreshToken) .build(); From 55770deb79c711aff40ee08e7c624bf4d3e972ea Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 25 Aug 2022 22:36:34 +0900 Subject: [PATCH 019/301] =?UTF-8?q?#9=20[fix]=20SuccessResponse=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=9D=BC=20controller?= =?UTF-8?q?=20=EB=8B=A8=20return=20value=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/common/dto/SuccessResponse.java | 9 ++++----- .../server/controller/auth/AuthController.java | 14 ++++++++------ .../auth/dto/response/LoginResponse.java | 6 +++--- .../server/controller/room/RoomController.java | 14 ++++++++------ .../controller/room/RoomRetrieveController.java | 3 ++- .../controller/user/UserRetrieveController.java | 3 ++- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/hous/server/common/dto/SuccessResponse.java b/src/main/java/hous/server/common/dto/SuccessResponse.java index 1a514ea6..8d95a287 100644 --- a/src/main/java/hous/server/common/dto/SuccessResponse.java +++ b/src/main/java/hous/server/common/dto/SuccessResponse.java @@ -1,6 +1,5 @@ package hous.server.common.dto; -import feign.Response; import hous.server.common.success.SuccessCode; import lombok.*; import org.springframework.http.ResponseEntity; @@ -9,15 +8,15 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class SuccessResponse { +public class SuccessResponse { private int status; private boolean success; private String message; - private Object data; + private T data; - public static ResponseEntity success(SuccessCode successCode, Object data) { - return ResponseEntity.status(successCode.getStatus()) + public static ResponseEntity success(SuccessCode successCode, T data) { + return (ResponseEntity) ResponseEntity.status(successCode.getStatus()) .body(new SuccessResponse(successCode.getStatus(), true, successCode.getMessage(), data)); } } diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index de1b0595..d11fad3d 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -9,7 +9,7 @@ import hous.server.service.auth.AuthServiceProvider; import hous.server.service.auth.CreateTokenService; import hous.server.service.auth.dto.request.TokenRequestDto; -import hous.server.service.auth.dto.response.TokenResponseDto; +import hous.server.service.auth.dto.response.TokenResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -18,12 +18,14 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; @Api(tags = "Auth") @RestController +@RequestMapping("/v1/auth") @RequiredArgsConstructor public class AuthController { @@ -48,12 +50,12 @@ public class AuthController { @ApiResponse(code = 409, message = "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) - @PostMapping("/v1/auth/login") - public ResponseEntity login(@Valid @RequestBody LoginRequestDto request) { + @PostMapping("/login") + public ResponseEntity login(@Valid @RequestBody LoginRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); Long userId = authService.login(request.toServiceDto()); - TokenResponseDto tokenInfo = createTokenService.createTokenInfo(userId); + TokenResponse tokenInfo = createTokenService.createTokenInfo(userId); return SuccessResponse.success(SuccessCode.LOGIN_SUCCESS, LoginResponse.of(userId, tokenInfo)); } @@ -72,8 +74,8 @@ public ResponseEntity login(@Valid @RequestBody LoginRequestDto @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) - @PostMapping("/v1/auth/refresh") - public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto request) { + @PostMapping("/refresh") + public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto request) { return SuccessResponse.success(SuccessCode.REISSUE_TOKEN_SUCCESS, createTokenService.reissueToken(request)); } } diff --git a/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java b/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java index ba852bb2..f0123ba1 100644 --- a/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java +++ b/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java @@ -1,6 +1,6 @@ package hous.server.controller.auth.dto.response; -import hous.server.service.auth.dto.response.TokenResponseDto; +import hous.server.service.auth.dto.response.TokenResponse; import lombok.*; @ToString @@ -11,9 +11,9 @@ public class LoginResponse { private Long userId; - private TokenResponseDto token; + private TokenResponse token; - public static LoginResponse of(Long userId, TokenResponseDto token) { + public static LoginResponse of(Long userId, TokenResponse token) { return LoginResponse.builder() .userId(userId) .token(token) diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index a2af8f38..6c58b2ef 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -7,6 +7,7 @@ import hous.server.config.resolver.UserId; import hous.server.service.room.RoomService; import hous.server.service.room.dto.request.CreateRoomRequestDto; +import hous.server.service.room.dto.response.RoomInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -18,6 +19,7 @@ @Api(tags = "Room") @RestController +@RequestMapping("/v1/room") @RequiredArgsConstructor public class RoomController { @@ -42,8 +44,8 @@ public class RoomController { }) @Auth @ResponseStatus(HttpStatus.CREATED) - @PostMapping("/v1/room") - public ResponseEntity createRoom(@Valid @RequestBody CreateRoomRequestDto request, @ApiIgnore @UserId Long userId) { + @PostMapping("") + public ResponseEntity createRoom(@Valid @RequestBody CreateRoomRequestDto request, @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CREATE_ROOM_SUCCESS, roomService.createRoom(request, userId)); } @@ -64,10 +66,10 @@ public ResponseEntity createRoom(@Valid @RequestBody CreateRoom @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @PostMapping("/v1/room/{roomId}/join") - public ResponseEntity joinRoom(@ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") - @PathVariable Long roomId, - @ApiIgnore @UserId Long userId) { + @PostMapping("/{roomId}/join") + public ResponseEntity joinRoom(@ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") + @PathVariable Long roomId, + @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.JOIN_ROOM_SUCCESS, roomService.joinRoom(roomId, userId)); } } diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index e77bf657..fdabb158 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -6,6 +6,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.room.RoomRetrieveService; +import hous.server.service.room.dto.response.GetRoomResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -36,7 +37,7 @@ public class RoomRetrieveController { }) @Auth @GetMapping("/v1/room") - public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { + public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_ROOM_SUCCESS, roomRetrieveService.getRoom(userId)); } } diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index df24467b..7601402a 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -6,6 +6,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.user.UserRetrieveService; +import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -36,7 +37,7 @@ public class UserRetrieveController { }) @Auth @GetMapping("/onboarding/check") - public ResponseEntity checkMyOnboardingInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity checkMyOnboardingInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CHECK_ONBOARDING_SUCCESS, userRetrieveService.checkMyOnboardingInfo(userId)); } } From 6385d3487778cd5c8a3bc155031038da32b1bf62 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 25 Aug 2022 22:49:51 +0900 Subject: [PATCH 020/301] =?UTF-8?q?#9=20[fix]=20=ED=8A=B8=EB=9E=9C?= =?UTF-8?q?=EC=9E=AD=EC=85=98=20=EC=A0=81=EC=9A=A9=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/room/RoomService.java | 4 +--- src/main/java/hous/server/service/user/UserService.java | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index a2bf4c08..54ff6f72 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -16,14 +16,13 @@ @RequiredArgsConstructor @Service -@Transactional(readOnly = true) +@Transactional public class RoomService { private final UserRepository userRepository; private final RoomRepository roomRepository; private final ParticipateRepository participateRepository; - @Transactional public RoomInfoResponse createRoom(CreateRoomRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); @@ -35,7 +34,6 @@ public RoomInfoResponse createRoom(CreateRoomRequestDto request, Long userId) { return RoomInfoResponse.of(room); } - @Transactional public RoomInfoResponse joinRoom(Long roomId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 85de6b47..03772be9 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -13,20 +13,18 @@ @RequiredArgsConstructor @Service -@Transactional(readOnly = true) +@Transactional public class UserService { private final UserRepository userRepository; private final OnboardingRepository onboardingRepository; - @Transactional public Long registerUser(CreateUserDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), Onboarding.newInstance(), Setting.newInstance())); return user.getId(); } - @Transactional public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); From 9683412284a56d8a4daf59f2ff7392b48b31ad0e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 25 Aug 2022 22:55:55 +0900 Subject: [PATCH 021/301] =?UTF-8?q?#9=20[fix]=20=EC=98=A8=EB=B3=B4?= =?UTF-8?q?=EB=94=A9=20=EC=A0=95=EB=B3=B4=20=EB=93=B1=EB=A1=9D=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EC=A1=B0=ED=9A=8C=20api=20return=20200=20->=20204?= =?UTF-8?q?=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 --- .../server/common/success/SuccessCode.java | 16 ++++----- .../controller/user/UserController.java | 35 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index bb437368..bbc759f2 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -1,12 +1,13 @@ package hous.server.common.success; +import static hous.server.common.success.SuccessStatusCode.CREATED; +import static hous.server.common.success.SuccessStatusCode.NO_CONTENT; +import static hous.server.common.success.SuccessStatusCode.OK; + import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; -import static hous.server.common.success.SuccessStatusCode.CREATED; -import static hous.server.common.success.SuccessStatusCode.OK; - @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum SuccessCode { @@ -14,16 +15,13 @@ public enum SuccessCode { /** * 200 OK */ - SUCCESS(OK, "성공입니다."), - // 인증 LOGIN_SUCCESS(OK, "로그인 성공입니다."), REISSUE_TOKEN_SUCCESS(OK, "토큰 갱신 성공입니다."), // 온보딩 CHECK_ONBOARDING_SUCCESS(OK, "온보딩 등록여부 조회 성공입니다."), - SET_ONBOARDING_SUCCESS(OK, "온보딩 정보 등록 성공입니다."), - + // 방 GET_ROOM_SUCCESS(OK, "참가중인 방 조회 성공입니다."), JOIN_ROOM_SUCCESS(OK, "방 참여 성공입니다."), @@ -31,7 +29,7 @@ public enum SuccessCode { /** * 201 CREATED */ - + // 방 CREATE_ROOM_SUCCESS(CREATED, "방 생성 성공입니다."), @@ -42,7 +40,7 @@ public enum SuccessCode { /** * 204 NO_CONTENT */ - ; + NO_CONTENT_SUCCESS(NO_CONTENT, ""); private final SuccessStatusCode statusCode; private final String message; diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index f689b303..54fffa8e 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -11,16 +11,17 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import javax.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; -import javax.validation.Valid; - @Api(tags = "User") @RequiredArgsConstructor @RestController @@ -30,26 +31,28 @@ public class UserController { private final UserService userService; @ApiOperation( - value = "[인증] 온보딩 페이지 - 나의 온보딩 정보를 설정합니다.", - notes = "닉네임, 생년월일을 설정합니다. 성공시 data로 null을 보냅니다." + value = "[인증] 온보딩 페이지 - 나의 온보딩 정보를 설정합니다.", + notes = "닉네임, 생년월일을 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "온보딩 정보 등록 성공입니다."), - @ApiResponse( - code = 400, - message = "1. 닉네임을 입력해주세요. (nickname)\n" - + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" - + "3. 생년월일을 입력해주세요. (birthday)", - response = ErrorResponse.class), - @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), - @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. 닉네임을 입력해주세요. (nickname)\n" + + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" + + "3. 생년월일을 입력해주세요. (birthday)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @ResponseStatus(HttpStatus.NO_CONTENT) @Auth @PostMapping("/onboarding") - public ResponseEntity setOnboardingInfo(@Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity setOnboardingInfo( + @Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { userService.setOnboardingInfo(request, userId); - return SuccessResponse.success(SuccessCode.SET_ONBOARDING_SUCCESS, null); + return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); } } From 59ef57a40c38b99989190ce2f09d38a8bfdba1e0 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 16:22:34 +0900 Subject: [PATCH 022/301] =?UTF-8?q?#11=20[fix]=20Room=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=EC=97=90=20owner=20=EC=B9=BC=EB=9F=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/room/Room.java | 11 +++++++++-- .../java/hous/server/service/room/RoomService.java | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index f304aaa0..d4f1aeea 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -3,6 +3,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.rule.Rule; import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -21,6 +22,10 @@ public class Room extends AuditingTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "onboarding_id", nullable = false) + private Onboarding owner; + @Column(nullable = false, length = 30) private String name; @@ -46,7 +51,8 @@ public class Room extends AuditingTimeEntity { private final List todos = new ArrayList<>(); @Builder(access = AccessLevel.PRIVATE) - public Room(String name, String code, int participantsCnt, int rulesCnt, int todosCnt) { + public Room(Onboarding owner, String name, String code, int participantsCnt, int rulesCnt, int todosCnt) { + this.owner = owner; this.name = name; this.code = code; this.participantsCnt = participantsCnt; @@ -54,8 +60,9 @@ public Room(String name, String code, int participantsCnt, int rulesCnt, int tod this.todosCnt = todosCnt; } - public static Room newInstance(String name, String code) { + public static Room newInstance(Onboarding owner, String name, String code) { return Room.builder() + .owner(owner) .name(name) .code(code) .participantsCnt(0) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 54ff6f72..3e9a27cd 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -27,7 +27,7 @@ public RoomInfoResponse createRoom(CreateRoomRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); - Room room = roomRepository.save(Room.newInstance(request.getName(), RoomServiceUtils.createUniqueRoomCode(roomRepository))); + Room room = roomRepository.save(Room.newInstance(onboarding, request.getName(), RoomServiceUtils.createUniqueRoomCode(roomRepository))); Participate participate = participateRepository.save(Participate.newInstance(onboarding, room)); onboarding.addParticipate(participate); room.addParticipate(participate); From 1ad723e9faa81507c1171963f79fe6af4b127645 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 16:24:07 +0900 Subject: [PATCH 023/301] =?UTF-8?q?#11=20[docs]=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 54fffa8e..8a1edf6c 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -11,17 +11,14 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import javax.validation.Valid; + @Api(tags = "User") @RequiredArgsConstructor @RestController @@ -31,26 +28,26 @@ public class UserController { private final UserService userService; @ApiOperation( - value = "[인증] 온보딩 페이지 - 나의 온보딩 정보를 설정합니다.", - notes = "닉네임, 생년월일을 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + value = "[인증] 온보딩 페이지 - 나의 온보딩 정보를 설정합니다.", + notes = "닉네임, 생년월일을 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), - @ApiResponse( - code = 400, - message = "1. 닉네임을 입력해주세요. (nickname)\n" - + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" - + "3. 생년월일을 입력해주세요. (birthday)", - response = ErrorResponse.class), - @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), - @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. 닉네임을 입력해주세요. (nickname)\n" + + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" + + "3. 생년월일을 입력해주세요. (birthday)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) - @ResponseStatus(HttpStatus.NO_CONTENT) @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/onboarding") public ResponseEntity setOnboardingInfo( - @Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { + @Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { userService.setOnboardingInfo(request, userId); return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); } From 21c77597f85a4c9abef7830397909a32d0c7e96d Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 16:53:52 +0900 Subject: [PATCH 024/301] =?UTF-8?q?#11=20[feat]=20=EB=B0=A9=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 7 ++--- .../room/RoomRetrieveController.java | 24 ++++++++++++--- .../room/repository/RoomRepositoryCustom.java | 2 ++ .../room/repository/RoomRepositoryImpl.java | 8 +++++ .../service/room/RoomRetrieveService.java | 9 ++++++ .../dto/response/GetRoomInfoResponse.java | 29 +++++++++++++++++++ 6 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/main/java/hous/server/service/room/dto/response/GetRoomInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index bbc759f2..84c748b9 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -1,13 +1,11 @@ package hous.server.common.success; -import static hous.server.common.success.SuccessStatusCode.CREATED; -import static hous.server.common.success.SuccessStatusCode.NO_CONTENT; -import static hous.server.common.success.SuccessStatusCode.OK; - import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; +import static hous.server.common.success.SuccessStatusCode.*; + @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum SuccessCode { @@ -24,6 +22,7 @@ public enum SuccessCode { // 방 GET_ROOM_SUCCESS(OK, "참가중인 방 조회 성공입니다."), + GET_ROOM_INFO_SUCCESS(OK, "참가하려는 방 정보 조회 성공입니다."), JOIN_ROOM_SUCCESS(OK, "방 참여 성공입니다."), /** diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index fdabb158..1a475043 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -6,14 +6,13 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.room.RoomRetrieveService; +import hous.server.service.room.dto.response.GetRoomInfoResponse; import hous.server.service.room.dto.response.GetRoomResponse; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; @@ -40,4 +39,21 @@ public class RoomRetrieveController { public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_ROOM_SUCCESS, roomRetrieveService.getRoom(userId)); } + + @ApiOperation( + value = "[인증] 방 만들기/입장 페이지 - 참가하려는 방 정보를 조회합니다.", + notes = "방 코드와 일치하는 방이 존재한다면 방의 id 와 방장의 닉네임을 전달합니다.\n" + + "방 코드와 일치하는 방이 없다면 null 을 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "참가하려는 방 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/v1/room/info") + public ResponseEntity getRoomInfo(@ApiParam(name = "code", value = "참가하려는 방 코드", required = true, example = "PNO6VN6A") + @RequestParam String code) { + return SuccessResponse.success(SuccessCode.GET_ROOM_INFO_SUCCESS, roomRetrieveService.getRoomInfo(code)); + } } diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java index 2e0ffcf7..f0d3701f 100644 --- a/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java @@ -7,4 +7,6 @@ public interface RoomRepositoryCustom { boolean existsByRoomCode(String code); Room findRoomById(Long id); + + Room findRoomByCode(String code); } diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java index cca0bccc..6159d211 100644 --- a/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java @@ -26,4 +26,12 @@ public Room findRoomById(Long id) { .where(room.id.eq(id)) .fetchOne(); } + + @Override + public Room findRoomByCode(String code) { + return queryFactory + .selectFrom(room) + .where(room.code.eq(code)) + .fetchOne(); + } } diff --git a/src/main/java/hous/server/service/room/RoomRetrieveService.java b/src/main/java/hous/server/service/room/RoomRetrieveService.java index b1e83f02..cdba94c3 100644 --- a/src/main/java/hous/server/service/room/RoomRetrieveService.java +++ b/src/main/java/hous/server/service/room/RoomRetrieveService.java @@ -1,8 +1,11 @@ package hous.server.service.room; import hous.server.domain.room.Participate; +import hous.server.domain.room.Room; +import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.dto.response.GetRoomInfoResponse; import hous.server.service.room.dto.response.GetRoomResponse; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -15,6 +18,7 @@ public class RoomRetrieveService { private final UserRepository userRepository; + private final RoomRepository roomRepository; public GetRoomResponse getRoom(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -25,4 +29,9 @@ public GetRoomResponse getRoom(Long userId) { return GetRoomResponse.of(participate.getRoom()); } } + + public GetRoomInfoResponse getRoomInfo(String code) { + Room room = roomRepository.findRoomByCode(code); + return GetRoomInfoResponse.of(room); + } } diff --git a/src/main/java/hous/server/service/room/dto/response/GetRoomInfoResponse.java b/src/main/java/hous/server/service/room/dto/response/GetRoomInfoResponse.java new file mode 100644 index 00000000..3184be26 --- /dev/null +++ b/src/main/java/hous/server/service/room/dto/response/GetRoomInfoResponse.java @@ -0,0 +1,29 @@ +package hous.server.service.room.dto.response; + +import hous.server.domain.room.Room; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class GetRoomInfoResponse { + + private Long roomId; + private String nickname; + + public static GetRoomInfoResponse of(Room room) { + if (room == null) { + return GetRoomInfoResponse.builder() + .roomId(null) + .nickname(null) + .build(); + } else { + return GetRoomInfoResponse.builder() + .roomId(room.getId()) + .nickname(room.getOwner().getNickname()) + .build(); + } + } +} From 255792c8e036b7cf3eeb54f2359569fb8a447de5 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 17:19:51 +0900 Subject: [PATCH 025/301] =?UTF-8?q?#11=20[refactor]=20endpoint=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/controller/room/RoomRetrieveController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index 1a475043..23b7cb48 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -12,13 +12,15 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; @Api(tags = "Room") -@RequiredArgsConstructor @RestController +@RequestMapping("/v1/room") +@RequiredArgsConstructor public class RoomRetrieveController { private final RoomRetrieveService roomRetrieveService; @@ -35,7 +37,7 @@ public class RoomRetrieveController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping("/v1/room") + @GetMapping public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_ROOM_SUCCESS, roomRetrieveService.getRoom(userId)); } @@ -51,7 +53,7 @@ public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping("/v1/room/info") + @GetMapping("/info") public ResponseEntity getRoomInfo(@ApiParam(name = "code", value = "참가하려는 방 코드", required = true, example = "PNO6VN6A") @RequestParam String code) { return SuccessResponse.success(SuccessCode.GET_ROOM_INFO_SUCCESS, roomRetrieveService.getRoomInfo(code)); From bc1cdd37134fe4e06147a268138932e6809e6e8f Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 18:42:01 +0900 Subject: [PATCH 026/301] =?UTF-8?q?#13=20[fix]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=EC=8B=9C=20=EA=B8=B0=EB=B3=B8=20=EC=84=B1?= =?UTF-8?q?=ED=96=A5=EC=9C=BC=EB=A1=9C=20=EC=84=A4=EC=A0=95=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PersonalityRepository.java | 7 ++++++ .../PersonalityRepositoryCustom.java | 9 ++++++++ .../repository/PersonalityRepositoryImpl.java | 22 +++++++++++++++++++ .../hous/server/domain/user/Onboarding.java | 7 +++--- .../hous/server/service/user/UserService.java | 9 +++++--- 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/main/java/hous/server/domain/personality/repository/PersonalityRepository.java create mode 100644 src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryImpl.java diff --git a/src/main/java/hous/server/domain/personality/repository/PersonalityRepository.java b/src/main/java/hous/server/domain/personality/repository/PersonalityRepository.java new file mode 100644 index 00000000..a16e8e68 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/repository/PersonalityRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.personality.repository; + +import hous.server.domain.personality.Personality; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PersonalityRepository extends JpaRepository, PersonalityRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryCustom.java b/src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryCustom.java new file mode 100644 index 00000000..2caed312 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryCustom.java @@ -0,0 +1,9 @@ +package hous.server.domain.personality.repository; + +import hous.server.domain.personality.Personality; +import hous.server.domain.personality.PersonalityColor; + +public interface PersonalityRepositoryCustom { + + Personality findPersonalityByColor(PersonalityColor color); +} diff --git a/src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryImpl.java b/src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryImpl.java new file mode 100644 index 00000000..0d08f3e4 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/repository/PersonalityRepositoryImpl.java @@ -0,0 +1,22 @@ +package hous.server.domain.personality.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.personality.Personality; +import hous.server.domain.personality.PersonalityColor; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.personality.QPersonality.personality; + +@RequiredArgsConstructor +public class PersonalityRepositoryImpl implements PersonalityRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Personality findPersonalityByColor(PersonalityColor color) { + return queryFactory + .selectFrom(personality) + .where(personality.color.eq(color)) + .fetchOne(); + } +} diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 2e969417..e5bdaed2 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -39,7 +39,7 @@ public class Onboarding extends AuditingTimeEntity { private boolean isChecked; @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "personality_id") + @JoinColumn(name = "personality_id", nullable = false) private Personality personality; @OneToOne(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @@ -70,12 +70,13 @@ public Onboarding(String nickname, LocalDate birthday, String introduction, bool this.testScore = testScore; } - public static Onboarding newInstance() { + public static Onboarding newInstance(Personality personality) { return Onboarding.builder() .isChecked(false) + .personality(personality) .build(); } - + public void setOnboarding(String nickname, LocalDate birthday) { this.nickname = nickname; this.birthday = birthday; diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 03772be9..65ffde4f 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,9 +1,10 @@ package hous.server.service.user; +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.Setting; import hous.server.domain.user.User; -import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.user.dto.request.CreateUserDto; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; @@ -17,11 +18,13 @@ public class UserService { private final UserRepository userRepository; - private final OnboardingRepository onboardingRepository; + private final PersonalityRepository personalityRepository; public Long registerUser(CreateUserDto request) { + System.out.println(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY)); UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); - User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), Onboarding.newInstance(), Setting.newInstance())); + User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), + Onboarding.newInstance(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY)), Setting.newInstance())); return user.getId(); } From 6de67332043164fe27231cb011c204e2bd72cd46 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 18:42:28 +0900 Subject: [PATCH 027/301] =?UTF-8?q?#13=20[feat]=20=EB=B0=A9=20=EC=B0=B8?= =?UTF-8?q?=EA=B0=80=EC=9E=90=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 ++ .../todo/TodoRetrieveController.java | 43 +++++++++++++++++++ .../service/todo/TodoRetrieveService.java | 34 +++++++++++++++ .../dto/response/GetUsersInfoResponse.java | 40 +++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 src/main/java/hous/server/controller/todo/TodoRetrieveController.java create mode 100644 src/main/java/hous/server/service/todo/TodoRetrieveService.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 84c748b9..c91316e1 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -25,6 +25,9 @@ public enum SuccessCode { GET_ROOM_INFO_SUCCESS(OK, "참가하려는 방 정보 조회 성공입니다."), JOIN_ROOM_SUCCESS(OK, "방 참여 성공입니다."), + // to-do + GET_USERS_INFO_SUCCESS(OK, "담당자 목록 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java new file mode 100644 index 00000000..3da0372b --- /dev/null +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -0,0 +1,43 @@ +package hous.server.controller.todo; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.todo.TodoRetrieveService; +import hous.server.service.todo.dto.response.GetUsersInfoResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +@Api(tags = "Todo") +@RestController +@RequestMapping("/v1/todo") +@RequiredArgsConstructor +public class TodoRetrieveController { + + private final TodoRetrieveService todoRetrieveService; + + @ApiOperation( + value = "[인증] todo 추가 페이지 - 담당자 목록을 조회합니다.", + notes = "방에 참가중인 사용자들의 id, 성향 색, 닉네임을 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "담당자 목록 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping + public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_USERS_INFO_SUCCESS, todoRetrieveService.getUsersInfo(userId)); + } +} diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java new file mode 100644 index 00000000..f2d0728a --- /dev/null +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -0,0 +1,34 @@ +package hous.server.service.todo; + +import hous.server.domain.room.Participate; +import hous.server.domain.room.Room; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.todo.dto.response.GetUsersInfoResponse; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class TodoRetrieveService { + + private final UserRepository userRepository; + + public GetUsersInfoResponse getUsersInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Participate participate = user.getOnboarding().getParticipates().get(0); + Room room = participate.getRoom(); + List participates = room.getParticipates(); + List onboardings = participates.stream() + .map(Participate::getOnboarding) + .collect(Collectors.toList()); + return GetUsersInfoResponse.of(onboardings); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java new file mode 100644 index 00000000..7571a5a2 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java @@ -0,0 +1,40 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.user.Onboarding; +import lombok.*; + +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class GetUsersInfoResponse { + + private List users; + + @ToString + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + private static class UserInfo { + private Long onboardingId; + private String color; + private String nickname; + } + + public static GetUsersInfoResponse of(List onboardings) { + return GetUsersInfoResponse.builder() + .users(onboardings.stream() + .map(onboarding -> UserInfo.builder() + .onboardingId(onboarding.getId()) + .color(onboarding.getPersonality().getColor().toString()) + .nickname(onboarding.getNickname()) + .build()) + .collect(Collectors.toList())) + .build(); + } +} From 218a810a49eb2ee97213e48d23b09d0730458ae8 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 19:44:40 +0900 Subject: [PATCH 028/301] =?UTF-8?q?#13=20[refactor]=20=EC=B0=B8=EA=B0=80?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EB=B0=A9=20=EC=A1=B0=ED=9A=8C=20=EC=9C=A0?= =?UTF-8?q?=ED=8B=B8=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/common/exception/ErrorCode.java | 1 + .../hous/server/service/room/RoomServiceUtils.java | 14 ++++++++++++-- .../server/service/todo/TodoRetrieveService.java | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index f7bebef8..5c5191b1 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -41,6 +41,7 @@ public enum ErrorCode { NOT_FOUND_REFRESH_TOKEN_EXCEPTION(NOT_FOUND, "만료된 리프레시 토큰입니다."), NOT_FOUND_ONBOARDING_EXCEPTION(NOT_FOUND, "유저의 온보딩 정보가 존재하지 않습니다."), NOT_FOUND_ROOM_EXCEPTION(NOT_FOUND, "존재하지 않는 방입니다."), + NOT_FOUND_PARTICIPATE_EXCEPTION(NOT_FOUND, "참가중인 방이 존재하지 않습니다."), /** * 405 Method Not Allowed diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 1d878980..9dc06962 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -2,17 +2,19 @@ import hous.server.common.exception.ConflictException; import hous.server.common.exception.NotFoundException; +import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.List; import java.util.Random; -import static hous.server.common.exception.ErrorCode.CONFLICT_JOINED_ROOM_EXCEPTION; -import static hous.server.common.exception.ErrorCode.NOT_FOUND_ROOM_EXCEPTION; +import static hous.server.common.exception.ErrorCode.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class RoomServiceUtils { @@ -31,6 +33,14 @@ public static Room findRoomById(RoomRepository roomRepository, Long roomId) { return room; } + public static Room findParticipatingRoom(User user) { + List participates = user.getOnboarding().getParticipates(); + if (participates.isEmpty()) { + throw new NotFoundException(String.format("유저 (%s) 는 참가중인 방이 존재하지 않습니다.", user.getId()), NOT_FOUND_PARTICIPATE_EXCEPTION); + } + return participates.get(0).getRoom(); + } + private static boolean isNotUniqueRoomCode(RoomRepository roomRepository, String code) { return roomRepository.existsByRoomCode(code); } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index f2d0728a..8191f320 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -5,6 +5,7 @@ import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.dto.response.GetUsersInfoResponse; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -23,8 +24,7 @@ public class TodoRetrieveService { public GetUsersInfoResponse getUsersInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - Participate participate = user.getOnboarding().getParticipates().get(0); - Room room = participate.getRoom(); + Room room = RoomServiceUtils.findParticipatingRoom(user); List participates = room.getParticipates(); List onboardings = participates.stream() .map(Participate::getOnboarding) From f9e98dedbc3946665ba3d2856062d54141f84201 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 19:46:00 +0900 Subject: [PATCH 029/301] =?UTF-8?q?#13=20[docs]=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/controller/todo/TodoRetrieveController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 3da0372b..65fd29e6 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -33,6 +33,11 @@ public class TodoRetrieveController { @ApiResponses(value = { @ApiResponse(code = 200, message = "담당자 목록 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth From 01a40fc775b1a307e9afff20227a3b5b7b742c18 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 29 Aug 2022 20:18:11 +0900 Subject: [PATCH 030/301] =?UTF-8?q?#13=20[feat]=20todo=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/todo/TodoController.java | 59 +++++++++++++++++++ .../java/hous/server/domain/todo/Redo.java | 14 +++++ .../java/hous/server/domain/todo/Take.java | 18 ++++++ .../java/hous/server/domain/todo/Todo.java | 20 +++++++ .../todo/repository/RedoRepository.java | 7 +++ .../todo/repository/RedoRepositoryCustom.java | 4 ++ .../todo/repository/RedoRepositoryImpl.java | 10 ++++ .../todo/repository/TakeRepository.java | 7 +++ .../todo/repository/TakeRepositoryCustom.java | 4 ++ .../todo/repository/TakeRepositoryImpl.java | 10 ++++ .../todo/repository/TodoRepository.java | 7 +++ .../todo/repository/TodoRepositoryCustom.java | 4 ++ .../todo/repository/TodoRepositoryImpl.java | 10 ++++ .../user/repository/OnboardingRepository.java | 2 +- .../OnboardingRepositoryCustom.java | 8 +++ .../repository/OnboardingRepositoryImpl.java | 21 +++++++ .../hous/server/service/todo/TodoService.java | 46 +++++++++++++++ .../dto/request/CreateTodoRequestDto.java | 51 ++++++++++++++++ .../resources/messages/validation.properties | 4 ++ 19 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 src/main/java/hous/server/controller/todo/TodoController.java create mode 100644 src/main/java/hous/server/domain/todo/repository/RedoRepository.java create mode 100644 src/main/java/hous/server/domain/todo/repository/RedoRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/todo/repository/RedoRepositoryImpl.java create mode 100644 src/main/java/hous/server/domain/todo/repository/TakeRepository.java create mode 100644 src/main/java/hous/server/domain/todo/repository/TakeRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/todo/repository/TakeRepositoryImpl.java create mode 100644 src/main/java/hous/server/domain/todo/repository/TodoRepository.java create mode 100644 src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java create mode 100644 src/main/java/hous/server/domain/user/repository/OnboardingRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/user/repository/OnboardingRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/todo/TodoService.java create mode 100644 src/main/java/hous/server/service/todo/dto/request/CreateTodoRequestDto.java diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java new file mode 100644 index 00000000..ec5644fc --- /dev/null +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -0,0 +1,59 @@ +package hous.server.controller.todo; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.todo.TodoService; +import hous.server.service.todo.dto.request.CreateTodoRequestDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; + +@Api(tags = "Todo") +@RestController +@RequestMapping("/v1/todo") +@RequiredArgsConstructor +public class TodoController { + + private final TodoService todoService; + + @ApiOperation( + value = "[인증] todo 추가 페이지 - 새로운 todo 를 생성합니다.", + notes = "todo 이름을 15글자 이내로 설정하고 알림 여부, 담당자, 담당 요일을 설정하여 새로운 todo 생성을 요청합니다.\n" + + "성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. todo 이름을 입력해주세요. (name)\n" + + "2. todo 이름을 15 글자 이내로 입력해주세요. (name)\n" + + "3. 담당자 목록은 빈 배열일 수 없습니다. (todoUsers)\n" + + "4. 담당 요일 목록은 빈 배열일 수 없습니다. (todoUsers[0].dayOfWeeks)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping + public ResponseEntity createTodo(@Valid @RequestBody CreateTodoRequestDto request, @ApiIgnore @UserId Long userId) { + todoService.createTodo(request, userId); + return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); + } +} diff --git a/src/main/java/hous/server/domain/todo/Redo.java b/src/main/java/hous/server/domain/todo/Redo.java index 5adcfc11..5b20775f 100644 --- a/src/main/java/hous/server/domain/todo/Redo.java +++ b/src/main/java/hous/server/domain/todo/Redo.java @@ -2,6 +2,7 @@ import hous.server.domain.common.AuditingTimeEntity; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -28,4 +29,17 @@ public class Redo extends AuditingTimeEntity { @OneToMany(mappedBy = "redo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List dones = new ArrayList<>(); + + @Builder(access = AccessLevel.PRIVATE) + public Redo(Take take, DayOfWeek dayOfWeek) { + this.take = take; + this.dayOfWeek = dayOfWeek; + } + + public static Redo newInstance(Take take, DayOfWeek dayOfWeek) { + return Redo.builder() + .take(take) + .dayOfWeek(dayOfWeek) + .build(); + } } diff --git a/src/main/java/hous/server/domain/todo/Take.java b/src/main/java/hous/server/domain/todo/Take.java index 518ef3ee..53ba3063 100644 --- a/src/main/java/hous/server/domain/todo/Take.java +++ b/src/main/java/hous/server/domain/todo/Take.java @@ -3,6 +3,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -29,4 +30,21 @@ public class Take extends AuditingTimeEntity { @OneToMany(mappedBy = "take", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List redos = new ArrayList<>(); + + @Builder(access = AccessLevel.PRIVATE) + public Take(Todo todo, Onboarding onboarding) { + this.todo = todo; + this.onboarding = onboarding; + } + + public static Take newInstance(Todo todo, Onboarding onboarding) { + return Take.builder() + .todo(todo) + .onboarding(onboarding) + .build(); + } + + public void addRedo(Redo redo) { + this.redos.add(redo); + } } diff --git a/src/main/java/hous/server/domain/todo/Todo.java b/src/main/java/hous/server/domain/todo/Todo.java index c9cc5748..9db52ae8 100644 --- a/src/main/java/hous/server/domain/todo/Todo.java +++ b/src/main/java/hous/server/domain/todo/Todo.java @@ -3,6 +3,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Room; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -31,4 +32,23 @@ public class Todo extends AuditingTimeEntity { @OneToMany(mappedBy = "todo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List takes = new ArrayList<>(); + + @Builder(access = AccessLevel.PRIVATE) + public Todo(Room room, String name, boolean isPushNotification) { + this.room = room; + this.name = name; + this.isPushNotification = isPushNotification; + } + + public static Todo newInstance(Room room, String name, boolean isPushNotification) { + return Todo.builder() + .room(room) + .name(name) + .isPushNotification(isPushNotification) + .build(); + } + + public void addTake(Take take) { + this.takes.add(take); + } } diff --git a/src/main/java/hous/server/domain/todo/repository/RedoRepository.java b/src/main/java/hous/server/domain/todo/repository/RedoRepository.java new file mode 100644 index 00000000..b95d2c0b --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/RedoRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.todo.repository; + +import hous.server.domain.todo.Redo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RedoRepository extends JpaRepository, RedoRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/todo/repository/RedoRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/RedoRepositoryCustom.java new file mode 100644 index 00000000..71228e73 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/RedoRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.todo.repository; + +public interface RedoRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/todo/repository/RedoRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/RedoRepositoryImpl.java new file mode 100644 index 00000000..41e63ff0 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/RedoRepositoryImpl.java @@ -0,0 +1,10 @@ +package hous.server.domain.todo.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class RedoRepositoryImpl implements RedoRepositoryCustom { + + private final JPAQueryFactory queryFactory; +} diff --git a/src/main/java/hous/server/domain/todo/repository/TakeRepository.java b/src/main/java/hous/server/domain/todo/repository/TakeRepository.java new file mode 100644 index 00000000..bca9d809 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/TakeRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.todo.repository; + +import hous.server.domain.todo.Take; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TakeRepository extends JpaRepository, TakeRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/todo/repository/TakeRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/TakeRepositoryCustom.java new file mode 100644 index 00000000..812a772e --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/TakeRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.todo.repository; + +public interface TakeRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/todo/repository/TakeRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/TakeRepositoryImpl.java new file mode 100644 index 00000000..984c6fe1 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/TakeRepositoryImpl.java @@ -0,0 +1,10 @@ +package hous.server.domain.todo.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class TakeRepositoryImpl implements TakeRepositoryCustom { + + private final JPAQueryFactory queryFactory; +} diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepository.java b/src/main/java/hous/server/domain/todo/repository/TodoRepository.java new file mode 100644 index 00000000..2695ecf9 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.todo.repository; + +import hous.server.domain.todo.Todo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TodoRepository extends JpaRepository, TodoRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java new file mode 100644 index 00000000..0771ecb4 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.todo.repository; + +public interface TodoRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java new file mode 100644 index 00000000..a14f1f7b --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java @@ -0,0 +1,10 @@ +package hous.server.domain.todo.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class TodoRepositoryImpl implements TodoRepositoryCustom { + + private final JPAQueryFactory queryFactory; +} diff --git a/src/main/java/hous/server/domain/user/repository/OnboardingRepository.java b/src/main/java/hous/server/domain/user/repository/OnboardingRepository.java index 23dce44f..729d604a 100644 --- a/src/main/java/hous/server/domain/user/repository/OnboardingRepository.java +++ b/src/main/java/hous/server/domain/user/repository/OnboardingRepository.java @@ -3,5 +3,5 @@ import hous.server.domain.user.Onboarding; import org.springframework.data.jpa.repository.JpaRepository; -public interface OnboardingRepository extends JpaRepository { +public interface OnboardingRepository extends JpaRepository, OnboardingRepositoryCustom { } diff --git a/src/main/java/hous/server/domain/user/repository/OnboardingRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/OnboardingRepositoryCustom.java new file mode 100644 index 00000000..1e94ea2d --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/OnboardingRepositoryCustom.java @@ -0,0 +1,8 @@ +package hous.server.domain.user.repository; + +import hous.server.domain.user.Onboarding; + +public interface OnboardingRepositoryCustom { + + Onboarding findOnboardingById(Long id); +} diff --git a/src/main/java/hous/server/domain/user/repository/OnboardingRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/OnboardingRepositoryImpl.java new file mode 100644 index 00000000..e51f420a --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/OnboardingRepositoryImpl.java @@ -0,0 +1,21 @@ +package hous.server.domain.user.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.user.Onboarding; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.user.QOnboarding.onboarding; + +@RequiredArgsConstructor +public class OnboardingRepositoryImpl implements OnboardingRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Onboarding findOnboardingById(Long id) { + return queryFactory + .selectFrom(onboarding) + .where(onboarding.id.eq(id)) + .fetchOne(); + } +} diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java new file mode 100644 index 00000000..439d60c6 --- /dev/null +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -0,0 +1,46 @@ +package hous.server.service.todo; + +import hous.server.domain.room.Room; +import hous.server.domain.todo.Redo; +import hous.server.domain.todo.Take; +import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.RedoRepository; +import hous.server.domain.todo.repository.TakeRepository; +import hous.server.domain.todo.repository.TodoRepository; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.OnboardingRepository; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; +import hous.server.service.todo.dto.request.CreateTodoRequestDto; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class TodoService { + + private final UserRepository userRepository; + private final OnboardingRepository onboardingRepository; + private final TodoRepository todoRepository; + private final TakeRepository takeRepository; + private final RedoRepository redoRepository; + + public void createTodo(CreateTodoRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); + request.getTodoUsers().forEach(todoUser -> { + Onboarding onboarding = onboardingRepository.findOnboardingById(todoUser.getOnboardingId()); + Take take = takeRepository.save(Take.newInstance(todo, onboarding)); + todoUser.getDayOfWeeks().forEach(dayOfWeek -> { + Redo redo = redoRepository.save(Redo.newInstance(take, dayOfWeek)); + take.addRedo(redo); + }); + todo.addTake(take); + }); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/request/CreateTodoRequestDto.java b/src/main/java/hous/server/service/todo/dto/request/CreateTodoRequestDto.java new file mode 100644 index 00000000..517eaa3e --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/request/CreateTodoRequestDto.java @@ -0,0 +1,51 @@ +package hous.server.service.todo.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.todo.DayOfWeek; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import javax.validation.Valid; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CreateTodoRequestDto { + + @ApiModelProperty(value = "todo 이름", example = "청소기 돌리기") + @NotBlank(message = "{todo.name.notBlank}") + @Size(max = 15, message = "{todo.name.max}") + private String name; + + @ApiModelProperty(value = "알림 여부") + private boolean isPushNotification; + + @ApiModelProperty(value = "담당자 목록") + @NotEmpty(message = "{todo.todoUsers.notEmpty}") + private List<@Valid TodoUser> todoUsers; + + @ToString + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + public static class TodoUser { + + @ApiModelProperty(value = "담당자 id", example = "1") + private Long onboardingId; + + @ApiModelProperty(value = "담당 요일") + @NotEmpty(message = "{todo.dayOfWeeks.notEmpty}") + private List dayOfWeeks; + } + + @JsonProperty("isPushNotification") + public boolean isPushNotification() { + return isPushNotification; + } +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index bf2ce7a2..3f545520 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -12,3 +12,7 @@ onboarding.nickname.length=\uB2C9\uB124\uC784\uC740 \uCD5C\uB300 5\uAE00\uC790\u onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +todo.name.notBlank=todo \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +todo.name.max=todo \uC774\uB984\uC744 15 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. From 666fa80790828dd83e359b5bf124e3da546daff2 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 13:01:25 +0900 Subject: [PATCH 031/301] =?UTF-8?q?#16=20[fix]=20todo=20=EA=B0=9C=EC=88=98?= =?UTF-8?q?=20=EC=A0=9C=ED=95=9C=2060=EA=B0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../common/exception/ForbiddenException.java | 12 ++++++++++++ .../controller/todo/TodoController.java | 1 + .../todo/repository/TodoRepositoryCustom.java | 4 ++++ .../todo/repository/TodoRepositoryImpl.java | 10 ++++++++++ .../hous/server/service/todo/TodoService.java | 1 + .../server/service/todo/TodoServiceUtils.java | 19 +++++++++++++++++++ 7 files changed, 48 insertions(+) create mode 100644 src/main/java/hous/server/common/exception/ForbiddenException.java create mode 100644 src/main/java/hous/server/service/todo/TodoServiceUtils.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 5c5191b1..56b280ef 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -32,6 +32,7 @@ public enum ErrorCode { FORBIDDEN_EXCEPTION(FORBIDDEN, "허용하지 않는 요청입니다."), FORBIDDEN_FILE_TYPE_EXCEPTION(BAD_REQUEST, "허용되지 않은 파일 형식입니다."), FORBIDDEN_FILE_NAME_EXCEPTION(BAD_REQUEST, "허용되지 않은 파일 이름입니다."), + FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/common/exception/ForbiddenException.java b/src/main/java/hous/server/common/exception/ForbiddenException.java new file mode 100644 index 00000000..f4635fb8 --- /dev/null +++ b/src/main/java/hous/server/common/exception/ForbiddenException.java @@ -0,0 +1,12 @@ +package hous.server.common.exception; + +public class ForbiddenException extends HousException { + + public ForbiddenException(String message, ErrorCode errorCode) { + super(message, errorCode); + } + + public ForbiddenException(String message) { + super(message, ErrorCode.FORBIDDEN_EXCEPTION); + } +} diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index ec5644fc..6ab8a88b 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -42,6 +42,7 @@ public class TodoController { + "4. 담당 요일 목록은 빈 배열일 수 없습니다. (todoUsers[0].dayOfWeeks)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "todo 는 60개를 초과할 수 없습니다.", response = ErrorResponse.class), @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java index 0771ecb4..040a4705 100644 --- a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java @@ -1,4 +1,8 @@ package hous.server.domain.todo.repository; +import hous.server.domain.room.Room; + public interface TodoRepositoryCustom { + + int findCountsByRoom(Room room); } diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java index a14f1f7b..38b7c0d3 100644 --- a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java @@ -1,10 +1,20 @@ package hous.server.domain.todo.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.room.Room; import lombok.RequiredArgsConstructor; +import static hous.server.domain.todo.QTodo.todo; + @RequiredArgsConstructor public class TodoRepositoryImpl implements TodoRepositoryCustom { private final JPAQueryFactory queryFactory; + + @Override + public int findCountsByRoom(Room room) { + return queryFactory.selectFrom(todo) + .where(todo.room.eq(room)) + .fetch().size(); + } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 439d60c6..a437b3c9 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -32,6 +32,7 @@ public class TodoService { public void createTodo(CreateTodoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); + TodoServiceUtils.validateTodoCounts(todoRepository, room); Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); request.getTodoUsers().forEach(todoUser -> { Onboarding onboarding = onboardingRepository.findOnboardingById(todoUser.getOnboardingId()); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java new file mode 100644 index 00000000..00253021 --- /dev/null +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -0,0 +1,19 @@ +package hous.server.service.todo; + +import hous.server.common.exception.ForbiddenException; +import hous.server.domain.room.Room; +import hous.server.domain.todo.repository.TodoRepository; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static hous.server.common.exception.ErrorCode.FORBIDDEN_TODO_COUNT_EXCEPTION; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TodoServiceUtils { + + public static void validateTodoCounts(TodoRepository todoRepository, Room room) { + if (todoRepository.findCountsByRoom(room) >= 60) { + throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_TODO_COUNT_EXCEPTION); + } + } +} From 1a852535d7b4f052f517071638c5b60572c846c9 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 13:15:53 +0900 Subject: [PATCH 032/301] =?UTF-8?q?#16=20[fix]=20todo=20=EB=8B=B4=EB=8B=B9?= =?UTF-8?q?=EC=9E=90=20=EB=AA=A9=EB=A1=9D=20=EC=84=B1=ED=96=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=98=A4=EB=A6=84=EC=B0=A8=EC=88=9C=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/todo/TodoRetrieveService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 8191f320..55fe2782 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -28,6 +29,7 @@ public GetUsersInfoResponse getUsersInfo(Long userId) { List participates = room.getParticipates(); List onboardings = participates.stream() .map(Participate::getOnboarding) + .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) .collect(Collectors.toList()); return GetUsersInfoResponse.of(onboardings); } From 87acc2ad6a9f3f8c5d788271db126117c3c3340c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 13:56:49 +0900 Subject: [PATCH 033/301] =?UTF-8?q?#16=20[fix]=20=EB=B0=A9=20=EC=B5=9C?= =?UTF-8?q?=EB=8C=80=EC=9D=B8=EC=9B=90=2016=EB=AA=85=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/exception/ErrorCode.java | 1 + .../java/hous/server/controller/room/RoomController.java | 1 + .../room/repository/ParticipateRepositoryCustom.java | 3 +++ .../domain/room/repository/ParticipateRepositoryImpl.java | 8 ++++++++ src/main/java/hous/server/service/room/RoomService.java | 1 + .../java/hous/server/service/room/RoomServiceUtils.java | 7 +++++++ 6 files changed, 21 insertions(+) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 56b280ef..e1a2c0a9 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -32,6 +32,7 @@ public enum ErrorCode { FORBIDDEN_EXCEPTION(FORBIDDEN, "허용하지 않는 요청입니다."), FORBIDDEN_FILE_TYPE_EXCEPTION(BAD_REQUEST, "허용되지 않은 파일 형식입니다."), FORBIDDEN_FILE_NAME_EXCEPTION(BAD_REQUEST, "허용되지 않은 파일 이름입니다."), + FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), /** diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 6c58b2ef..d81e51f0 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -57,6 +57,7 @@ public ResponseEntity createRoom(@Valid @RequestBody CreateRoo @ApiResponses(value = { @ApiResponse(code = 200, message = "방 참여 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "방 참가자는 16명을 초과할 수 없습니다.", response = ErrorResponse.class), @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" diff --git a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java index 46134d70..7a1a183b 100644 --- a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java +++ b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java @@ -1,8 +1,11 @@ package hous.server.domain.room.repository; +import hous.server.domain.room.Room; import hous.server.domain.user.Onboarding; public interface ParticipateRepositoryCustom { boolean existsByOnboarding(Onboarding onboarding); + + int findCountsByRoom(Room room); } diff --git a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java index bca61de9..24e24a0a 100644 --- a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java +++ b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java @@ -1,6 +1,7 @@ package hous.server.domain.room.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.room.Room; import hous.server.domain.user.Onboarding; import lombok.RequiredArgsConstructor; @@ -18,4 +19,11 @@ public boolean existsByOnboarding(Onboarding onboarding) { .where(participate.onboarding.eq(onboarding)) .fetchFirst() != null; } + + @Override + public int findCountsByRoom(Room room) { + return queryFactory.selectFrom(participate) + .where(participate.room.eq(room)) + .fetch().size(); + } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 3e9a27cd..a67fd94d 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -39,6 +39,7 @@ public RoomInfoResponse joinRoom(Long roomId, Long userId) { Onboarding onboarding = user.getOnboarding(); RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); Room room = RoomServiceUtils.findRoomById(roomRepository, roomId); + RoomServiceUtils.validateParticipateCounts(participateRepository, room); Participate participate = participateRepository.save(Participate.newInstance(onboarding, room)); onboarding.addParticipate(participate); room.addParticipate(participate); diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 9dc06962..db5c9ddb 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -1,6 +1,7 @@ package hous.server.service.room; import hous.server.common.exception.ConflictException; +import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; @@ -25,6 +26,12 @@ public static void validateNotExistsParticipate(ParticipateRepository participat } } + public static void validateParticipateCounts(ParticipateRepository participateRepository, Room room) { + if (participateRepository.findCountsByRoom(room) >= 16) { + throw new ForbiddenException(String.format("방 (%s) 의 참가자 는 16명을 초과할 수 없습니다.", room.getId()), FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION); + } + } + public static Room findRoomById(RoomRepository roomRepository, Long roomId) { Room room = roomRepository.findRoomById(roomId); if (room == null) { From 9849cf4260cffb88b8b318cfb5bcb305c3697577 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 14:13:01 +0900 Subject: [PATCH 034/301] =?UTF-8?q?#16=20[fix]=20endpoint=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 --- .../java/hous/server/controller/auth/AuthController.java | 6 +++--- .../java/hous/server/controller/room/RoomController.java | 6 +++--- .../hous/server/controller/room/RoomRetrieveController.java | 6 +++--- .../java/hous/server/controller/todo/TodoController.java | 4 ++-- .../hous/server/controller/todo/TodoRetrieveController.java | 4 ++-- .../java/hous/server/controller/user/UserController.java | 4 ++-- .../hous/server/controller/user/UserRetrieveController.java | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index d11fad3d..3b4d1d2b 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -25,7 +25,7 @@ @Api(tags = "Auth") @RestController -@RequestMapping("/v1/auth") +@RequestMapping("/v1") @RequiredArgsConstructor public class AuthController { @@ -50,7 +50,7 @@ public class AuthController { @ApiResponse(code = 409, message = "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) - @PostMapping("/login") + @PostMapping("/auth/login") public ResponseEntity login(@Valid @RequestBody LoginRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); Long userId = authService.login(request.toServiceDto()); @@ -74,7 +74,7 @@ public ResponseEntity login(@Valid @RequestBody LoginRequestDto r @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) - @PostMapping("/refresh") + @PostMapping("/auth/refresh") public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto request) { return SuccessResponse.success(SuccessCode.REISSUE_TOKEN_SUCCESS, createTokenService.reissueToken(request)); } diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index d81e51f0..ccb485a5 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -19,7 +19,7 @@ @Api(tags = "Room") @RestController -@RequestMapping("/v1/room") +@RequestMapping("/v1") @RequiredArgsConstructor public class RoomController { @@ -44,7 +44,7 @@ public class RoomController { }) @Auth @ResponseStatus(HttpStatus.CREATED) - @PostMapping("") + @PostMapping("/room") public ResponseEntity createRoom(@Valid @RequestBody CreateRoomRequestDto request, @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CREATE_ROOM_SUCCESS, roomService.createRoom(request, userId)); } @@ -67,7 +67,7 @@ public ResponseEntity createRoom(@Valid @RequestBody CreateRoo @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @PostMapping("/{roomId}/join") + @PostMapping("/room/{roomId}/join") public ResponseEntity joinRoom(@ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") @PathVariable Long roomId, @ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index 23b7cb48..100026a2 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -19,7 +19,7 @@ @Api(tags = "Room") @RestController -@RequestMapping("/v1/room") +@RequestMapping("/v1") @RequiredArgsConstructor public class RoomRetrieveController { @@ -37,7 +37,7 @@ public class RoomRetrieveController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping + @GetMapping("/room") public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_ROOM_SUCCESS, roomRetrieveService.getRoom(userId)); } @@ -53,7 +53,7 @@ public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping("/info") + @GetMapping("/room/info") public ResponseEntity getRoomInfo(@ApiParam(name = "code", value = "참가하려는 방 코드", required = true, example = "PNO6VN6A") @RequestParam String code) { return SuccessResponse.success(SuccessCode.GET_ROOM_INFO_SUCCESS, roomRetrieveService.getRoomInfo(code)); diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 6ab8a88b..938f5072 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -21,7 +21,7 @@ @Api(tags = "Todo") @RestController -@RequestMapping("/v1/todo") +@RequestMapping("/v1") @RequiredArgsConstructor public class TodoController { @@ -52,7 +52,7 @@ public class TodoController { }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) - @PostMapping + @PostMapping("/todo") public ResponseEntity createTodo(@Valid @RequestBody CreateTodoRequestDto request, @ApiIgnore @UserId Long userId) { todoService.createTodo(request, userId); return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 65fd29e6..23d8f33c 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -20,7 +20,7 @@ @Api(tags = "Todo") @RestController -@RequestMapping("/v1/todo") +@RequestMapping("/v1") @RequiredArgsConstructor public class TodoRetrieveController { @@ -41,7 +41,7 @@ public class TodoRetrieveController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping + @GetMapping("/todo") public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_USERS_INFO_SUCCESS, todoRetrieveService.getUsersInfo(userId)); } diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 8a1edf6c..abf5ce81 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -22,7 +22,7 @@ @Api(tags = "User") @RequiredArgsConstructor @RestController -@RequestMapping("/v1/user") +@RequestMapping("/v1") public class UserController { private final UserService userService; @@ -45,7 +45,7 @@ public class UserController { }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) - @PostMapping("/onboarding") + @PostMapping("/user/onboarding") public ResponseEntity setOnboardingInfo( @Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { userService.setOnboardingInfo(request, userId); diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 7601402a..e1fdc370 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -21,7 +21,7 @@ @Api(tags = "User") @RequiredArgsConstructor @RestController -@RequestMapping("/v1/user") +@RequestMapping("/v1") public class UserRetrieveController { private final UserRetrieveService userRetrieveService; @@ -36,7 +36,7 @@ public class UserRetrieveController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping("/onboarding/check") + @GetMapping("/user/onboarding/check") public ResponseEntity checkMyOnboardingInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CHECK_ONBOARDING_SUCCESS, userRetrieveService.checkMyOnboardingInfo(userId)); } From 7f93b8cb7c1923ba3bc07b21a40581ca29c9a91f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 14:29:33 +0900 Subject: [PATCH 035/301] =?UTF-8?q?#15=20[fix]=20=ED=98=95=ED=83=9C=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/dto/request/SetOnboardingInfoRequestDto.java | 11 +++++------ src/main/resources/messages/validation.properties | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index 4afd24f6..aee73e8a 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -2,15 +2,14 @@ import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; +import java.time.LocalDate; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.time.LocalDate; @ToString @Getter @@ -19,7 +18,7 @@ public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") @NotBlank(message = "{onboarding.nickname.notBlank}") - @Length(min = 1, max = 5, message = "{onboarding.nickname.length}") + @Size(min = 1, max = 5, message = "{onboarding.nickname.length}") private String nickname; @ApiModelProperty(value = "생년월일", example = "1999-03-04") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 3f545520..e63abb4c 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -8,7 +8,7 @@ user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8 user.socialType.notNull=\uC720\uC800\uC758 socialType \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.name.notBlank=\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.nickname.length=\uB2C9\uB124\uC784\uC740 \uCD5C\uB300 5\uAE00\uC790\uAE4C\uC9C0 \uAC00\uB2A5\uD569\uB2C8\uB2E4. +onboarding.nickname.length=\uB2C9\uB124\uC784\uC740 5 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From b58fb1646c7f6a742d2cc68b4f8832f6ef40174d Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 14:29:47 +0900 Subject: [PATCH 036/301] =?UTF-8?q?#15=20[feat]=20rule=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../server/common/success/SuccessCode.java | 3 + .../controller/rule/RuleController.java | 58 +++++++++++++++++++ .../java/hous/server/domain/rule/Rule.java | 14 ++++- .../rule/repository/RuleRepository.java | 7 +++ .../rule/repository/RuleRepositoryCustom.java | 10 ++++ .../rule/repository/RuleRepositoryImpl.java | 32 ++++++++++ .../hous/server/service/rule/RuleService.java | 32 ++++++++++ .../server/service/rule/RuleServiceUtils.java | 31 ++++++++++ .../dto/request/CreateRuleRequestDto.java | 20 +++++++ .../rule/dto/response/RuleInfoResponse.java | 23 ++++++++ .../resources/messages/validation.properties | 2 + 12 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 src/main/java/hous/server/controller/rule/RuleController.java create mode 100644 src/main/java/hous/server/domain/rule/repository/RuleRepository.java create mode 100644 src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/rule/RuleService.java create mode 100644 src/main/java/hous/server/service/rule/RuleServiceUtils.java create mode 100644 src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java create mode 100644 src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index e1a2c0a9..df155485 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -34,6 +34,7 @@ public enum ErrorCode { FORBIDDEN_FILE_NAME_EXCEPTION(BAD_REQUEST, "허용되지 않은 파일 이름입니다."), FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), + FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index c91316e1..42f16ff8 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -35,6 +35,9 @@ public enum SuccessCode { // 방 CREATE_ROOM_SUCCESS(CREATED, "방 생성 성공입니다."), + // 규칙 + CREATE_RULE_SUCCESS(CREATED, "규칙 생성 성공입니다."), + /** * 202 ACCEPTED */ diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java new file mode 100644 index 00000000..0fc7f81a --- /dev/null +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -0,0 +1,58 @@ +package hous.server.controller.rule; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.rule.RuleService; +import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.response.RuleInfoResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; + +@Api(tags = "Rule") +@RequiredArgsConstructor +@RestController +@RequestMapping("/v1") +public class RuleController { + + private final RuleService ruleService; + + @ApiOperation( + value = "[인증] 규칙 페이지 - 방의 규칙을 생성합니다.", + notes = "성공시 status code = 201, response body로 해당 규칙의 idx와 규칙 내용을 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "규칙 생성을 성공입니다."), + @ApiResponse( + code = 400, + message = "1. 규칙 내용을 입력해주세요. (name)\n" + + "2. 규칙은 20 글자 이내로 입력해주세요. (name)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 방입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping("/rule") + public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.CREATE_RULE_SUCCESS, ruleService.createRule(request, userId)); + } + +} diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index ace7acda..8f227b06 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -2,15 +2,15 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Room; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder(access = AccessLevel.PRIVATE) public class Rule extends AuditingTimeEntity { @Id @@ -26,4 +26,12 @@ public class Rule extends AuditingTimeEntity { @Column(nullable = false) private int idx; + + public static Rule newInstance(Room room, String name, int idx) { + return Rule.builder() + .room(room) + .name(name) + .idx(idx) + .build(); + } } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepository.java b/src/main/java/hous/server/domain/rule/repository/RuleRepository.java new file mode 100644 index 00000000..b74c4488 --- /dev/null +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.rule.repository; + +import hous.server.domain.rule.Rule; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RuleRepository extends JpaRepository, RuleRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java new file mode 100644 index 00000000..fd502faf --- /dev/null +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java @@ -0,0 +1,10 @@ +package hous.server.domain.rule.repository; + +import hous.server.domain.rule.Rule; + +public interface RuleRepositoryCustom { + + Rule findRuleIdxByRoomId(Long id); + + int validateRuleCountsByRoomId(Long id); +} diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java new file mode 100644 index 00000000..36e72b76 --- /dev/null +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java @@ -0,0 +1,32 @@ +package hous.server.domain.rule.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.rule.Rule; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.room.QRoom.room; +import static hous.server.domain.rule.QRule.rule; + + +@RequiredArgsConstructor +public class RuleRepositoryImpl implements RuleRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Rule findRuleIdxByRoomId(Long id) { + return queryFactory + .selectFrom(rule) + .where(room.id.eq(id)) + .orderBy(rule.idx.desc()) + .fetchFirst(); + } + + @Override + public int validateRuleCountsByRoomId(Long id) { + return queryFactory + .selectFrom(rule) + .where(room.id.eq(id)) + .fetch().size(); + } +} diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java new file mode 100644 index 00000000..c9221eaa --- /dev/null +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -0,0 +1,32 @@ +package hous.server.service.rule; + +import hous.server.domain.room.Room; +import hous.server.domain.rule.Rule; +import hous.server.domain.rule.repository.RuleRepository; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; +import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.response.RuleInfoResponse; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class RuleService { + + private final UserRepository userRepository; + private final RuleRepository ruleRepository; + + public RuleInfoResponse createRule(CreateRuleRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + RuleServiceUtils.validateRuleCounts(ruleRepository, room.getId()); + int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room.getId()); + Rule rule = ruleRepository.save(Rule.newInstance(room, request.getName(), ruleIdx + 1)); + return RuleInfoResponse.of(rule); + } +} diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java new file mode 100644 index 00000000..c66c7110 --- /dev/null +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -0,0 +1,31 @@ +package hous.server.service.rule; + +import hous.server.common.exception.ForbiddenException; +import hous.server.domain.rule.Rule; +import hous.server.domain.rule.repository.RuleRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static hous.server.common.exception.ErrorCode.FORBIDDEN_RULE_COUNT_EXCEPTION; + +@RequiredArgsConstructor +@Service +@Transactional +public class RuleServiceUtils { + + public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Long roomId) { + Rule rule = ruleRepository.findRuleIdxByRoomId(roomId); + if (rule == null) { + return 0; + } + return rule.getIdx(); + } + + public static boolean validateRuleCounts(RuleRepository ruleRepository, Long roomId) { + if (ruleRepository.validateRuleCountsByRoomId(roomId) >= 30) { + throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", roomId), FORBIDDEN_RULE_COUNT_EXCEPTION); + } + return true; + } +} diff --git a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java new file mode 100644 index 00000000..a1a90983 --- /dev/null +++ b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java @@ -0,0 +1,20 @@ +package hous.server.service.rule.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CreateRuleRequestDto { + + @ApiModelProperty(value = "규칙 내용", example = "우리집 대장은 김또순") + @NotBlank(message = "{rule.name.notBlank") + @Size(max = 20, message = "{rule.name.max}") + private String name; +} diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java new file mode 100644 index 00000000..6d6c126e --- /dev/null +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java @@ -0,0 +1,23 @@ +package hous.server.service.rule.dto.response; + +import hous.server.domain.rule.Rule; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class RuleInfoResponse { + + private int index; + + private String name; + + public static RuleInfoResponse of(Rule rule) { + return RuleInfoResponse.builder() + .index(rule.getIdx()) + .name(rule.getName()) + .build(); + } +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index e63abb4c..3e7c9c44 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -16,3 +16,5 @@ todo.name.notBlank=todo \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.name.max=todo \uC774\uB984\uC744 15 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 30dfbcc6215e669f416292c8f0d662b205b63855 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 14:49:07 +0900 Subject: [PATCH 037/301] =?UTF-8?q?#20=20[feat]=20rule=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 ++ .../rule/RuleRetrieveController.java | 45 +++++++++++++++++++ .../rule/repository/RuleRepositoryCustom.java | 4 ++ .../rule/repository/RuleRepositoryImpl.java | 13 ++++++ .../service/rule/RuleRetrieveService.java | 31 +++++++++++++ .../rule/dto/response/RuleInfoResponse.java | 10 +++++ 6 files changed, 106 insertions(+) create mode 100644 src/main/java/hous/server/controller/rule/RuleRetrieveController.java create mode 100644 src/main/java/hous/server/service/rule/RuleRetrieveService.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 42f16ff8..1b418762 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -28,6 +28,9 @@ public enum SuccessCode { // to-do GET_USERS_INFO_SUCCESS(OK, "담당자 목록 조회 성공입니다."), + // rule + GET_RULE_INFO_SUCCESS(OK, "규칙 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java new file mode 100644 index 00000000..9d72f75b --- /dev/null +++ b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java @@ -0,0 +1,45 @@ +package hous.server.controller.rule; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.rule.RuleRetrieveService; +import hous.server.service.rule.dto.response.RuleInfoResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.List; + +@Api(tags = "Rule") +@RequiredArgsConstructor +@RestController +@RequestMapping("/v1") +public class RuleRetrieveController { + + private final RuleRetrieveService ruleRetrieveService; + + @ApiOperation( + value = "[인증] 규칙 페이지 - 방의 규칙을 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "규칙 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/rules") + public ResponseEntity> getRulesInfo(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_RULE_INFO_SUCCESS, ruleRetrieveService.getRulesInfo(userId)); + } +} diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java index fd502faf..27e14ad3 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java @@ -2,9 +2,13 @@ import hous.server.domain.rule.Rule; +import java.util.List; + public interface RuleRepositoryCustom { Rule findRuleIdxByRoomId(Long id); int validateRuleCountsByRoomId(Long id); + + List findRulesByRoomId(Long id); } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java index 36e72b76..bc053dbd 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java @@ -4,6 +4,8 @@ import hous.server.domain.rule.Rule; import lombok.RequiredArgsConstructor; +import java.util.List; + import static hous.server.domain.room.QRoom.room; import static hous.server.domain.rule.QRule.rule; @@ -29,4 +31,15 @@ public int validateRuleCountsByRoomId(Long id) { .where(room.id.eq(id)) .fetch().size(); } + + @Override + public List findRulesByRoomId(Long id) { + return queryFactory + .selectFrom(rule) + .where(room.id.eq(id)) + .orderBy(rule.idx.asc()) + .fetch(); + } + + } diff --git a/src/main/java/hous/server/service/rule/RuleRetrieveService.java b/src/main/java/hous/server/service/rule/RuleRetrieveService.java new file mode 100644 index 00000000..9d180e09 --- /dev/null +++ b/src/main/java/hous/server/service/rule/RuleRetrieveService.java @@ -0,0 +1,31 @@ +package hous.server.service.rule; + +import hous.server.domain.room.Room; +import hous.server.domain.rule.Rule; +import hous.server.domain.rule.repository.RuleRepository; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; +import hous.server.service.rule.dto.response.RuleInfoResponse; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class RuleRetrieveService { + + private final UserRepository userRepository; + private final RuleRepository ruleRepository; + + public List getRulesInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + List rules = ruleRepository.findRulesByRoomId(room.getId()); + return RuleInfoResponse.of(rules); + } +} diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java index 6d6c126e..bb3be1ce 100644 --- a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java @@ -3,6 +3,9 @@ import hous.server.domain.rule.Rule; import lombok.*; +import java.util.List; +import java.util.stream.Collectors; + @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -10,14 +13,21 @@ @Builder(access = AccessLevel.PRIVATE) public class RuleInfoResponse { + private Long id; + private int index; private String name; public static RuleInfoResponse of(Rule rule) { return RuleInfoResponse.builder() + .id(rule.getId()) .index(rule.getIdx()) .name(rule.getName()) .build(); } + + public static List of(List rules) { + return rules.stream().map(RuleInfoResponse::of).collect(Collectors.toList()); + } } From a18dbf5588c4f354df6a8e1389714e6621070ea8 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 14:29:47 +0900 Subject: [PATCH 038/301] =?UTF-8?q?#15=20[feat]=20rule=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../server/common/success/SuccessCode.java | 3 + .../controller/rule/RuleController.java | 58 +++++++++++++++++++ .../java/hous/server/domain/rule/Rule.java | 14 ++++- .../rule/repository/RuleRepository.java | 7 +++ .../rule/repository/RuleRepositoryCustom.java | 10 ++++ .../rule/repository/RuleRepositoryImpl.java | 32 ++++++++++ .../hous/server/service/rule/RuleService.java | 32 ++++++++++ .../server/service/rule/RuleServiceUtils.java | 31 ++++++++++ .../dto/request/CreateRuleRequestDto.java | 20 +++++++ .../rule/dto/response/RuleInfoResponse.java | 23 ++++++++ .../resources/messages/validation.properties | 2 + 12 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 src/main/java/hous/server/controller/rule/RuleController.java create mode 100644 src/main/java/hous/server/domain/rule/repository/RuleRepository.java create mode 100644 src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/rule/RuleService.java create mode 100644 src/main/java/hous/server/service/rule/RuleServiceUtils.java create mode 100644 src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java create mode 100644 src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index e1a2c0a9..df155485 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -34,6 +34,7 @@ public enum ErrorCode { FORBIDDEN_FILE_NAME_EXCEPTION(BAD_REQUEST, "허용되지 않은 파일 이름입니다."), FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), + FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index c91316e1..42f16ff8 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -35,6 +35,9 @@ public enum SuccessCode { // 방 CREATE_ROOM_SUCCESS(CREATED, "방 생성 성공입니다."), + // 규칙 + CREATE_RULE_SUCCESS(CREATED, "규칙 생성 성공입니다."), + /** * 202 ACCEPTED */ diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java new file mode 100644 index 00000000..786e5f6f --- /dev/null +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -0,0 +1,58 @@ +package hous.server.controller.rule; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.rule.RuleService; +import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.response.RuleInfoResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; + +@Api(tags = "Rule") +@RequiredArgsConstructor +@RestController +@RequestMapping("/v1") +public class RuleController { + + private final RuleService ruleService; + + @ApiOperation( + value = "[인증] 규칙 페이지 - 방의 규칙을 생성합니다.", + notes = "성공시 status code = 201, response body로 해당 규칙의 idx와 규칙 내용을 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 201, message = "규칙 생성을 성공입니다."), + @ApiResponse( + code = 400, + message = "1. 규칙 내용을 입력해주세요. (name)\n" + + "2. 규칙은 20 글자 이내로 입력해주세요. (name)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 방입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.CREATED) + @PostMapping("/rule") + public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.CREATE_RULE_SUCCESS, ruleService.createRule(request, userId)); + } + +} diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index ace7acda..8f227b06 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -2,15 +2,15 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Room; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder(access = AccessLevel.PRIVATE) public class Rule extends AuditingTimeEntity { @Id @@ -26,4 +26,12 @@ public class Rule extends AuditingTimeEntity { @Column(nullable = false) private int idx; + + public static Rule newInstance(Room room, String name, int idx) { + return Rule.builder() + .room(room) + .name(name) + .idx(idx) + .build(); + } } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepository.java b/src/main/java/hous/server/domain/rule/repository/RuleRepository.java new file mode 100644 index 00000000..b74c4488 --- /dev/null +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.rule.repository; + +import hous.server.domain.rule.Rule; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RuleRepository extends JpaRepository, RuleRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java new file mode 100644 index 00000000..fd502faf --- /dev/null +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java @@ -0,0 +1,10 @@ +package hous.server.domain.rule.repository; + +import hous.server.domain.rule.Rule; + +public interface RuleRepositoryCustom { + + Rule findRuleIdxByRoomId(Long id); + + int validateRuleCountsByRoomId(Long id); +} diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java new file mode 100644 index 00000000..36e72b76 --- /dev/null +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java @@ -0,0 +1,32 @@ +package hous.server.domain.rule.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.rule.Rule; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.room.QRoom.room; +import static hous.server.domain.rule.QRule.rule; + + +@RequiredArgsConstructor +public class RuleRepositoryImpl implements RuleRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Rule findRuleIdxByRoomId(Long id) { + return queryFactory + .selectFrom(rule) + .where(room.id.eq(id)) + .orderBy(rule.idx.desc()) + .fetchFirst(); + } + + @Override + public int validateRuleCountsByRoomId(Long id) { + return queryFactory + .selectFrom(rule) + .where(room.id.eq(id)) + .fetch().size(); + } +} diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java new file mode 100644 index 00000000..c9221eaa --- /dev/null +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -0,0 +1,32 @@ +package hous.server.service.rule; + +import hous.server.domain.room.Room; +import hous.server.domain.rule.Rule; +import hous.server.domain.rule.repository.RuleRepository; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; +import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.response.RuleInfoResponse; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class RuleService { + + private final UserRepository userRepository; + private final RuleRepository ruleRepository; + + public RuleInfoResponse createRule(CreateRuleRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + RuleServiceUtils.validateRuleCounts(ruleRepository, room.getId()); + int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room.getId()); + Rule rule = ruleRepository.save(Rule.newInstance(room, request.getName(), ruleIdx + 1)); + return RuleInfoResponse.of(rule); + } +} diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java new file mode 100644 index 00000000..c66c7110 --- /dev/null +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -0,0 +1,31 @@ +package hous.server.service.rule; + +import hous.server.common.exception.ForbiddenException; +import hous.server.domain.rule.Rule; +import hous.server.domain.rule.repository.RuleRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static hous.server.common.exception.ErrorCode.FORBIDDEN_RULE_COUNT_EXCEPTION; + +@RequiredArgsConstructor +@Service +@Transactional +public class RuleServiceUtils { + + public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Long roomId) { + Rule rule = ruleRepository.findRuleIdxByRoomId(roomId); + if (rule == null) { + return 0; + } + return rule.getIdx(); + } + + public static boolean validateRuleCounts(RuleRepository ruleRepository, Long roomId) { + if (ruleRepository.validateRuleCountsByRoomId(roomId) >= 30) { + throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", roomId), FORBIDDEN_RULE_COUNT_EXCEPTION); + } + return true; + } +} diff --git a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java new file mode 100644 index 00000000..a1a90983 --- /dev/null +++ b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java @@ -0,0 +1,20 @@ +package hous.server.service.rule.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CreateRuleRequestDto { + + @ApiModelProperty(value = "규칙 내용", example = "우리집 대장은 김또순") + @NotBlank(message = "{rule.name.notBlank") + @Size(max = 20, message = "{rule.name.max}") + private String name; +} diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java new file mode 100644 index 00000000..6d6c126e --- /dev/null +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java @@ -0,0 +1,23 @@ +package hous.server.service.rule.dto.response; + +import hous.server.domain.rule.Rule; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class RuleInfoResponse { + + private int index; + + private String name; + + public static RuleInfoResponse of(Rule rule) { + return RuleInfoResponse.builder() + .index(rule.getIdx()) + .name(rule.getName()) + .build(); + } +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index e63abb4c..3e7c9c44 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -16,3 +16,5 @@ todo.name.notBlank=todo \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.name.max=todo \uC774\uB984\uC744 15 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 21c3be983ec3e548c1114a5659e104b479907ee0 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 15:58:28 +0900 Subject: [PATCH 039/301] =?UTF-8?q?#18=20[fix]=20Room=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=EC=9D=98=20todos,=20todosCnt=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/room/Room.java | 5 +++++ .../domain/todo/repository/TodoRepositoryCustom.java | 4 ---- .../domain/todo/repository/TodoRepositoryImpl.java | 10 ---------- .../java/hous/server/service/todo/TodoService.java | 3 ++- .../hous/server/service/todo/TodoServiceUtils.java | 5 ++--- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index d4f1aeea..d499dc4f 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -75,4 +75,9 @@ public void addParticipate(Participate participate) { this.participates.add(participate); this.participantsCnt += 1; } + + public void addTodo(Todo todo) { + this.todos.add(todo); + this.todosCnt += 1; + } } diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java index 040a4705..0771ecb4 100644 --- a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java @@ -1,8 +1,4 @@ package hous.server.domain.todo.repository; -import hous.server.domain.room.Room; - public interface TodoRepositoryCustom { - - int findCountsByRoom(Room room); } diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java index 38b7c0d3..a14f1f7b 100644 --- a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java @@ -1,20 +1,10 @@ package hous.server.domain.todo.repository; import com.querydsl.jpa.impl.JPAQueryFactory; -import hous.server.domain.room.Room; import lombok.RequiredArgsConstructor; -import static hous.server.domain.todo.QTodo.todo; - @RequiredArgsConstructor public class TodoRepositoryImpl implements TodoRepositoryCustom { private final JPAQueryFactory queryFactory; - - @Override - public int findCountsByRoom(Room room) { - return queryFactory.selectFrom(todo) - .where(todo.room.eq(room)) - .fetch().size(); - } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index a437b3c9..245cfe58 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -32,7 +32,7 @@ public class TodoService { public void createTodo(CreateTodoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - TodoServiceUtils.validateTodoCounts(todoRepository, room); + TodoServiceUtils.validateTodoCounts(room); Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); request.getTodoUsers().forEach(todoUser -> { Onboarding onboarding = onboardingRepository.findOnboardingById(todoUser.getOnboardingId()); @@ -43,5 +43,6 @@ public void createTodo(CreateTodoRequestDto request, Long userId) { }); todo.addTake(take); }); + room.addTodo(todo); } } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 00253021..fd386b41 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -2,7 +2,6 @@ import hous.server.common.exception.ForbiddenException; import hous.server.domain.room.Room; -import hous.server.domain.todo.repository.TodoRepository; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -11,8 +10,8 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class TodoServiceUtils { - public static void validateTodoCounts(TodoRepository todoRepository, Room room) { - if (todoRepository.findCountsByRoom(room) >= 60) { + public static void validateTodoCounts(Room room) { + if (room.getTodosCnt() >= 60) { throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_TODO_COUNT_EXCEPTION); } } From 8d9d4282dee27ca5affdb57ec302af3f2c71dd97 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 15:38:11 +0900 Subject: [PATCH 040/301] =?UTF-8?q?#15=20[fix]=20room=EC=97=90=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20ruleCnt=20=EC=B9=B4=EC=9A=B4=ED=8C=85=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=EC=A0=84=EC=B2=B4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/rule/RuleController.java | 9 +++++---- src/main/java/hous/server/domain/room/Room.java | 5 +++++ .../room/repository/RoomRepositoryCustom.java | 1 + .../domain/room/repository/RoomRepositoryImpl.java | 1 + .../rule/repository/RuleRepositoryCustom.java | 6 +++--- .../domain/rule/repository/RuleRepositoryImpl.java | 14 +++----------- .../java/hous/server/service/rule/RuleService.java | 7 +++++-- .../hous/server/service/rule/RuleServiceUtils.java | 12 ++++++------ .../dto/request/SetOnboardingInfoRequestDto.java | 11 ++++++----- src/main/resources/messages/validation.properties | 2 +- 10 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 786e5f6f..5185726d 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -30,10 +30,10 @@ public class RuleController { @ApiOperation( value = "[인증] 규칙 페이지 - 방의 규칙을 생성합니다.", - notes = "성공시 status code = 201, response body로 해당 규칙의 idx와 규칙 내용을 보냅니다." + notes = "성공시 status code = 204, 빈 response body로 보냅니다." ) @ApiResponses(value = { - @ApiResponse(code = 201, message = "규칙 생성을 성공입니다."), + @ApiResponse(code = 204, message = ""), @ApiResponse( code = 400, message = "1. 규칙 내용을 입력해주세요. (name)\n" @@ -48,11 +48,12 @@ public class RuleController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.CREATED) + @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/rule") public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, @ApiIgnore @UserId Long userId) { - return SuccessResponse.success(SuccessCode.CREATE_RULE_SUCCESS, ruleService.createRule(request, userId)); + ruleService.createRule(request, userId); + return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); } } diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index d4f1aeea..7e8d117c 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -75,4 +75,9 @@ public void addParticipate(Participate participate) { this.participates.add(participate); this.participantsCnt += 1; } + + public void addRule(Rule rule) { + this.rules.add(rule); + this.rulesCnt += 1; + } } diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java index f0d3701f..b7fc6797 100644 --- a/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryCustom.java @@ -9,4 +9,5 @@ public interface RoomRepositoryCustom { Room findRoomById(Long id); Room findRoomByCode(String code); + } diff --git a/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java index 6159d211..10f128b5 100644 --- a/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java +++ b/src/main/java/hous/server/domain/room/repository/RoomRepositoryImpl.java @@ -34,4 +34,5 @@ public Room findRoomByCode(String code) { .where(room.code.eq(code)) .fetchOne(); } + } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java index fd502faf..85019468 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java @@ -1,10 +1,10 @@ package hous.server.domain.rule.repository; +import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; public interface RuleRepositoryCustom { - Rule findRuleIdxByRoomId(Long id); - - int validateRuleCountsByRoomId(Long id); + Rule findLastRuleByRoomId(Room room); } + diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java index 36e72b76..caaedf09 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java @@ -1,10 +1,10 @@ package hous.server.domain.rule.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import lombok.RequiredArgsConstructor; -import static hous.server.domain.room.QRoom.room; import static hous.server.domain.rule.QRule.rule; @@ -14,19 +14,11 @@ public class RuleRepositoryImpl implements RuleRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public Rule findRuleIdxByRoomId(Long id) { + public Rule findLastRuleByRoomId(Room room) { return queryFactory .selectFrom(rule) - .where(room.id.eq(id)) + .where(rule.room.eq(room)) .orderBy(rule.idx.desc()) .fetchFirst(); } - - @Override - public int validateRuleCountsByRoomId(Long id) { - return queryFactory - .selectFrom(rule) - .where(room.id.eq(id)) - .fetch().size(); - } } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index c9221eaa..03d866e1 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -1,6 +1,7 @@ package hous.server.service.rule; import hous.server.domain.room.Room; +import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; import hous.server.domain.user.User; @@ -20,13 +21,15 @@ public class RuleService { private final UserRepository userRepository; private final RuleRepository ruleRepository; + private final RoomRepository roomRepository; public RuleInfoResponse createRule(CreateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - RuleServiceUtils.validateRuleCounts(ruleRepository, room.getId()); - int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room.getId()); + RuleServiceUtils.validateRuleCounts(room); + int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room); Rule rule = ruleRepository.save(Rule.newInstance(room, request.getName(), ruleIdx + 1)); + room.addRule(rule); return RuleInfoResponse.of(rule); } } diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index c66c7110..f8e30d63 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -1,6 +1,7 @@ package hous.server.service.rule; import hous.server.common.exception.ForbiddenException; +import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; import lombok.RequiredArgsConstructor; @@ -14,18 +15,17 @@ @Transactional public class RuleServiceUtils { - public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Long roomId) { - Rule rule = ruleRepository.findRuleIdxByRoomId(roomId); + public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Room room) { + Rule rule = ruleRepository.findLastRuleByRoomId(room); if (rule == null) { return 0; } return rule.getIdx(); } - public static boolean validateRuleCounts(RuleRepository ruleRepository, Long roomId) { - if (ruleRepository.validateRuleCountsByRoomId(roomId) >= 30) { - throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", roomId), FORBIDDEN_RULE_COUNT_EXCEPTION); + public static void validateRuleCounts(Room room) { + if (room.getRulesCnt() >= 30) { + throw new ForbiddenException(String.format("방 (%s) 의 rule 는 30개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_RULE_COUNT_EXCEPTION); } - return true; } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index aee73e8a..9cbb687a 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -2,15 +2,16 @@ import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; -import java.time.LocalDate; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.time.LocalDate; + @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -18,7 +19,7 @@ public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") @NotBlank(message = "{onboarding.nickname.notBlank}") - @Size(min = 1, max = 5, message = "{onboarding.nickname.length}") + @Size(min = 1, max = 5, message = "{onboarding.nickname.size}") private String nickname; @ApiModelProperty(value = "생년월일", example = "1999-03-04") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 3e7c9c44..2d118143 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -8,7 +8,7 @@ user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8 user.socialType.notNull=\uC720\uC800\uC758 socialType \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.name.notBlank=\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.nickname.length=\uB2C9\uB124\uC784\uC740 5 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.nickname.size=\uB2C9\uB124\uC784\uC740 5 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 632ecdd17a9bc0466c78f26aa5743609dfd3ea4e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 16:41:25 +0900 Subject: [PATCH 041/301] =?UTF-8?q?#20=20[fix]=20room=EC=97=90=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20rules=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/rule/RuleRetrieveService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/rule/RuleRetrieveService.java b/src/main/java/hous/server/service/rule/RuleRetrieveService.java index 9d180e09..9f5eb32f 100644 --- a/src/main/java/hous/server/service/rule/RuleRetrieveService.java +++ b/src/main/java/hous/server/service/rule/RuleRetrieveService.java @@ -25,7 +25,7 @@ public class RuleRetrieveService { public List getRulesInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - List rules = ruleRepository.findRulesByRoomId(room.getId()); + List rules = room.getRules(); return RuleInfoResponse.of(rules); } } From 479e06c2ace1876eeef18c97a222473bad9138af Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 16:53:32 +0900 Subject: [PATCH 042/301] =?UTF-8?q?#15=20[fix]=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/rule/repository/RuleRepositoryCustom.java | 2 +- .../hous/server/domain/rule/repository/RuleRepositoryImpl.java | 2 +- src/main/java/hous/server/service/rule/RuleRetrieveService.java | 1 - src/main/java/hous/server/service/rule/RuleServiceUtils.java | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java index a9b02017..8a87ebde 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java @@ -5,5 +5,5 @@ public interface RuleRepositoryCustom { - Rule findLastRuleByRoomId(Room room); + Rule findLastRuleByRoom(Room room); } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java index caaedf09..f491ce0f 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java @@ -14,7 +14,7 @@ public class RuleRepositoryImpl implements RuleRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public Rule findLastRuleByRoomId(Room room) { + public Rule findLastRuleByRoom(Room room) { return queryFactory .selectFrom(rule) .where(rule.room.eq(room)) diff --git a/src/main/java/hous/server/service/rule/RuleRetrieveService.java b/src/main/java/hous/server/service/rule/RuleRetrieveService.java index 9f5eb32f..97a0ee23 100644 --- a/src/main/java/hous/server/service/rule/RuleRetrieveService.java +++ b/src/main/java/hous/server/service/rule/RuleRetrieveService.java @@ -20,7 +20,6 @@ public class RuleRetrieveService { private final UserRepository userRepository; - private final RuleRepository ruleRepository; public List getRulesInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index 5a850356..c6fee30f 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -15,7 +15,7 @@ @Transactional public class RuleServiceUtils { public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Room room) { - Rule rule = ruleRepository.findLastRuleByRoomId(room); + Rule rule = ruleRepository.findLastRuleByRoom(room); if (rule == null) { return 0; } From b6b4f1e7cc403708df8b56c4036400cbfd35b128 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 17:00:13 +0900 Subject: [PATCH 043/301] =?UTF-8?q?#20=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20idx=20=EA=B0=92=EC=9D=84=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/rule/dto/response/RuleInfoResponse.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java index bb3be1ce..ff35cd8c 100644 --- a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java @@ -3,6 +3,7 @@ import hous.server.domain.rule.Rule; import lombok.*; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -28,6 +29,8 @@ public static RuleInfoResponse of(Rule rule) { } public static List of(List rules) { - return rules.stream().map(RuleInfoResponse::of).collect(Collectors.toList()); + return rules.stream() + .sorted(Comparator.comparing(Rule::getIdx)) + .map(RuleInfoResponse::of).collect(Collectors.toList()); } } From 377c71a4a6c0c363dbefcc9817092c1faef0d0c9 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 17:00:16 +0900 Subject: [PATCH 044/301] =?UTF-8?q?#22=20[feat]=20rule=201=EA=B0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../controller/rule/RuleController.java | 37 +++++++++++++++++-- .../java/hous/server/domain/rule/Rule.java | 5 +++ .../rule/repository/RuleRepositoryCustom.java | 2 + .../rule/repository/RuleRepositoryImpl.java | 8 ++++ .../service/rule/RuleRetrieveService.java | 1 - .../hous/server/service/rule/RuleService.java | 10 ++++- .../server/service/rule/RuleServiceUtils.java | 10 +++++ .../dto/request/UpdateRuleRequestDto.java | 21 +++++++++++ .../resources/messages/validation.properties | 2 + 10 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index df155485..6867ff14 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -45,6 +45,7 @@ public enum ErrorCode { NOT_FOUND_ONBOARDING_EXCEPTION(NOT_FOUND, "유저의 온보딩 정보가 존재하지 않습니다."), NOT_FOUND_ROOM_EXCEPTION(NOT_FOUND, "존재하지 않는 방입니다."), NOT_FOUND_PARTICIPATE_EXCEPTION(NOT_FOUND, "참가중인 방이 존재하지 않습니다."), + NOT_FOUND_RULE_EXCEPTION(NOT_FOUND, "존재하지 않는 규칙입니다."), /** * 405 Method Not Allowed diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 5185726d..4c13ff8b 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -7,11 +7,9 @@ import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleService; import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.request.UpdateRuleRequestDto; import hous.server.service.rule.dto.response.RuleInfoResponse; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -56,4 +54,35 @@ public ResponseEntity createRule(@Valid @RequestBody CreateRul return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); } + @ApiOperation( + value = "[인증] 규칙 페이지 - 규칙 1개를 수정합니다.", + notes = "성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = "규칙 생성을 성공입니다."), + @ApiResponse( + code = 400, + message = "1. 규칙 내용을 입력해주세요. (name)\n" + + "2. 규칙은 20 글자 이내로 입력해주세요. (name)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 방입니다.\n" + + "3. 존재하지 않는 규칙입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping("/rule/{ruleId}") + public ResponseEntity UpdateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") + @PathVariable Long ruleId, + @Valid @RequestBody UpdateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { + ruleService.updateRule(request, ruleId, userId); + return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); + } + } diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index 8f227b06..f7ac63e2 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -2,6 +2,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Room; +import hous.server.service.rule.dto.request.UpdateRuleRequestDto; import lombok.*; import javax.persistence.*; @@ -34,4 +35,8 @@ public static Rule newInstance(Room room, String name, int idx) { .idx(idx) .build(); } + + public void updateRule(UpdateRuleRequestDto request) { + this.name = request.getName(); + } } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java index 8a87ebde..4834d494 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java @@ -6,4 +6,6 @@ public interface RuleRepositoryCustom { Rule findLastRuleByRoom(Room room); + + Rule findRoomById(Long ruleId, Room room); } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java index f491ce0f..ea8b12b2 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java @@ -21,4 +21,12 @@ public Rule findLastRuleByRoom(Room room) { .orderBy(rule.idx.desc()) .fetchFirst(); } + + @Override + public Rule findRoomById(Long ruleId, Room room) { + return queryFactory + .selectFrom(rule) + .where(rule.id.eq(ruleId).and(rule.room.eq(room))) + .fetchOne(); + } } diff --git a/src/main/java/hous/server/service/rule/RuleRetrieveService.java b/src/main/java/hous/server/service/rule/RuleRetrieveService.java index 97a0ee23..237663cb 100644 --- a/src/main/java/hous/server/service/rule/RuleRetrieveService.java +++ b/src/main/java/hous/server/service/rule/RuleRetrieveService.java @@ -2,7 +2,6 @@ import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; -import hous.server.domain.rule.repository.RuleRepository; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 3b03fc32..27bc586a 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -1,13 +1,13 @@ package hous.server.service.rule; import hous.server.domain.room.Room; -import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.request.UpdateRuleRequestDto; import hous.server.service.rule.dto.response.RuleInfoResponse; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -31,4 +31,12 @@ public RuleInfoResponse createRule(CreateRuleRequestDto request, Long userId) { room.addRule(rule); return RuleInfoResponse.of(rule); } + + public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + Rule rule = RuleServiceUtils.findRuleById(ruleRepository, ruleId, room); + rule.updateRule(request); + } + } diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index c6fee30f..f05c9a2d 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -1,6 +1,7 @@ package hous.server.service.rule; import hous.server.common.exception.ForbiddenException; +import hous.server.common.exception.NotFoundException; import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; @@ -9,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional; import static hous.server.common.exception.ErrorCode.FORBIDDEN_RULE_COUNT_EXCEPTION; +import static hous.server.common.exception.ErrorCode.NOT_FOUND_RULE_EXCEPTION; @RequiredArgsConstructor @Service @@ -27,4 +29,12 @@ public static void validateRuleCounts(Room room) { throw new ForbiddenException(String.format("방 (%s) 의 rule 는 30개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_RULE_COUNT_EXCEPTION); } } + + public static Rule findRuleById(RuleRepository ruleRepository, Long ruleId, Room room) { + Rule rule = ruleRepository.findRoomById(ruleId, room); + if (rule == null) { + throw new NotFoundException(String.format("존재하지 않는 규칙 (%s) 입니다", ruleId), NOT_FOUND_RULE_EXCEPTION); + } + return rule; + } } diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java new file mode 100644 index 00000000..df754c12 --- /dev/null +++ b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java @@ -0,0 +1,21 @@ +package hous.server.service.rule.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateRuleRequestDto { + + @ApiModelProperty(value = "규칙 내용", example = "우리집 대장은 김또순") + @NotBlank(message = "{rule.name.notBlank") + @Size(max = 20, message = "{rule.name.max}") + private String name; +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 2d118143..4827de24 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -18,3 +18,5 @@ todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +#rule.id.notBlank=\uADDC\uCE59 id\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +#rule.idx.notBlank=\uADDC\uCE59 index\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 413da2007f6301a4ed7e760df2c958446f8c03cc Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 17:05:49 +0900 Subject: [PATCH 045/301] =?UTF-8?q?#18=20[fix]=20Todo,=20Redo,=20Done=20?= =?UTF-8?q?=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/todo/Done.java | 4 ++-- src/main/java/hous/server/domain/todo/Redo.java | 5 ----- src/main/java/hous/server/domain/todo/Todo.java | 3 +++ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/domain/todo/Done.java b/src/main/java/hous/server/domain/todo/Done.java index 9088757e..48893d3d 100644 --- a/src/main/java/hous/server/domain/todo/Done.java +++ b/src/main/java/hous/server/domain/todo/Done.java @@ -22,6 +22,6 @@ public class Done extends AuditingTimeEntity { private Onboarding onboarding; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "redo_id") - private Redo redo; + @JoinColumn(name = "todo_id") + private Todo todo; } diff --git a/src/main/java/hous/server/domain/todo/Redo.java b/src/main/java/hous/server/domain/todo/Redo.java index 5b20775f..568ec4ff 100644 --- a/src/main/java/hous/server/domain/todo/Redo.java +++ b/src/main/java/hous/server/domain/todo/Redo.java @@ -7,8 +7,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; -import java.util.ArrayList; -import java.util.List; @Getter @Entity @@ -27,9 +25,6 @@ public class Redo extends AuditingTimeEntity { @Enumerated(EnumType.STRING) private DayOfWeek dayOfWeek; - @OneToMany(mappedBy = "redo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - private final List dones = new ArrayList<>(); - @Builder(access = AccessLevel.PRIVATE) public Redo(Take take, DayOfWeek dayOfWeek) { this.take = take; diff --git a/src/main/java/hous/server/domain/todo/Todo.java b/src/main/java/hous/server/domain/todo/Todo.java index 9db52ae8..76559281 100644 --- a/src/main/java/hous/server/domain/todo/Todo.java +++ b/src/main/java/hous/server/domain/todo/Todo.java @@ -33,6 +33,9 @@ public class Todo extends AuditingTimeEntity { @OneToMany(mappedBy = "todo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List takes = new ArrayList<>(); + @OneToMany(mappedBy = "todo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List dones = new ArrayList<>(); + @Builder(access = AccessLevel.PRIVATE) public Todo(Room room, String name, boolean isPushNotification) { this.room = room; From 0fb67aa5906c0db6b61d9186e2221c680dac68c7 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 18:42:20 +0900 Subject: [PATCH 046/301] =?UTF-8?q?#18=20[feat]=20todo=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../hous/server/common/util/DateUtils.java | 26 +++++ .../hous/server/common/util/MathUtils.java | 12 +++ .../todo/TodoRetrieveController.java | 21 +++++ .../server/domain/todo/OurTodoStatus.java | 7 ++ .../todo/repository/DoneRepository.java | 7 ++ .../todo/repository/DoneRepositoryCustom.java | 14 +++ .../todo/repository/DoneRepositoryImpl.java | 46 +++++++++ .../service/todo/TodoRetrieveService.java | 11 +++ .../server/service/todo/TodoServiceUtils.java | 34 +++++++ .../dto/response/GetTodoMainResponse.java | 94 +++++++++++++++++++ 11 files changed, 273 insertions(+) create mode 100644 src/main/java/hous/server/common/util/DateUtils.java create mode 100644 src/main/java/hous/server/common/util/MathUtils.java create mode 100644 src/main/java/hous/server/domain/todo/OurTodoStatus.java create mode 100644 src/main/java/hous/server/domain/todo/repository/DoneRepository.java create mode 100644 src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index c91316e1..c0e663d8 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -27,6 +27,7 @@ public enum SuccessCode { // to-do GET_USERS_INFO_SUCCESS(OK, "담당자 목록 조회 성공입니다."), + GET_TODO_MAIN_SUCCESS(OK, "todo 메인 페이지 조회 성공입니다."), /** * 201 CREATED diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java new file mode 100644 index 00000000..2ff53afa --- /dev/null +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -0,0 +1,26 @@ +package hous.server.common.util; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class DateUtils { + + public static String nowMonthAndDay(LocalDate now) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd"); + return now.format(formatter); + } + + public static String nowDayOfWeek(LocalDate now) { + return now.getDayOfWeek().toString(); + } + + public static boolean isSameDate(LocalDateTime localDateTime, LocalDate localDate) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + return localDateTime.format(formatter).equals(localDate.format(formatter)); + } +} diff --git a/src/main/java/hous/server/common/util/MathUtils.java b/src/main/java/hous/server/common/util/MathUtils.java new file mode 100644 index 00000000..09246b29 --- /dev/null +++ b/src/main/java/hous/server/common/util/MathUtils.java @@ -0,0 +1,12 @@ +package hous.server.common.util; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MathUtils { + + public static int percent(int part, int total) { + return (int) ((double) part / (double) total * 100); + } +} diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 23d8f33c..0d36e7c2 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -6,6 +6,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoRetrieveService; +import hous.server.service.todo.dto.response.GetTodoMainResponse; import hous.server.service.todo.dto.response.GetUsersInfoResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -45,4 +46,24 @@ public class TodoRetrieveController { public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_USERS_INFO_SUCCESS, todoRetrieveService.getUsersInfo(userId)); } + + @ApiOperation( + value = "[인증] todo 메인 페이지 - todo 메인 페이지에 필요한 정보를 조회합니다.", + notes = "오늘 날짜, todo 진행률, my todo, our todo 를 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "todo 메인 페이지 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/todos") + public ResponseEntity getTodoMain(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_TODO_MAIN_SUCCESS, todoRetrieveService.getTodoMain(userId)); + } } diff --git a/src/main/java/hous/server/domain/todo/OurTodoStatus.java b/src/main/java/hous/server/domain/todo/OurTodoStatus.java new file mode 100644 index 00000000..e9377ced --- /dev/null +++ b/src/main/java/hous/server/domain/todo/OurTodoStatus.java @@ -0,0 +1,7 @@ +package hous.server.domain.todo; + +public enum OurTodoStatus { + EMPTY, + FULL, + CHECK; +} diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepository.java b/src/main/java/hous/server/domain/todo/repository/DoneRepository.java new file mode 100644 index 00000000..cef9226f --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.todo.repository; + +import hous.server.domain.todo.Done; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DoneRepository extends JpaRepository, DoneRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java new file mode 100644 index 00000000..c7bf26b7 --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java @@ -0,0 +1,14 @@ +package hous.server.domain.todo.repository; + +import hous.server.domain.todo.OurTodoStatus; +import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; + +import java.time.LocalDate; + +public interface DoneRepositoryCustom { + + boolean findTodayMyTodoCheckStatus(LocalDate now, Onboarding me, Todo todo); + + OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo); +} diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java new file mode 100644 index 00000000..32d6c78c --- /dev/null +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -0,0 +1,46 @@ +package hous.server.domain.todo.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.common.util.DateUtils; +import hous.server.domain.todo.Done; +import hous.server.domain.todo.OurTodoStatus; +import hous.server.domain.todo.Take; +import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; +import lombok.RequiredArgsConstructor; + +import java.time.LocalDate; +import java.util.List; + +import static hous.server.domain.todo.QDone.done; + +@RequiredArgsConstructor +public class DoneRepositoryImpl implements DoneRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public boolean findTodayMyTodoCheckStatus(LocalDate now, Onboarding me, Todo todo) { + Done lastDone = queryFactory.selectFrom(done) + .where(done.onboarding.eq(me)) + .orderBy(done.createdAt.desc()) + .fetchFirst(); + if (lastDone == null) return false; + return DateUtils.isSameDate(lastDone.getCreatedAt(), now); + } + + @Override + public OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo) { + List takes = todo.getTakes(); + int doneCnt = (int) takes.stream() + .map(take -> queryFactory.selectFrom(done) + .where(done.onboarding.eq(take.getOnboarding())) + .orderBy(done.createdAt.desc()) + .fetchFirst()) + .filter(lastDone -> lastDone != null && DateUtils.isSameDate(lastDone.getCreatedAt(), now)) + .count(); + if (doneCnt == 0) return OurTodoStatus.EMPTY; + else if (doneCnt == takes.size()) return OurTodoStatus.CHECK; + else return OurTodoStatus.FULL; + } +} diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 55fe2782..88e7b261 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -2,16 +2,20 @@ import hous.server.domain.room.Participate; import hous.server.domain.room.Room; +import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; +import hous.server.service.todo.dto.response.GetTodoMainResponse; import hous.server.service.todo.dto.response.GetUsersInfoResponse; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -22,6 +26,7 @@ public class TodoRetrieveService { private final UserRepository userRepository; + private final DoneRepository doneRepository; public GetUsersInfoResponse getUsersInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -33,4 +38,10 @@ public GetUsersInfoResponse getUsersInfo(Long userId) { .collect(Collectors.toList()); return GetUsersInfoResponse.of(onboardings); } + + public GetTodoMainResponse getTodoMain(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + return GetTodoMainResponse.of(user.getOnboarding(), LocalDate.now(ZoneId.of("Asia/Seoul")), room.getTodos(), doneRepository); + } } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index fd386b41..857f827a 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -1,10 +1,17 @@ package hous.server.service.todo; import hous.server.common.exception.ForbiddenException; +import hous.server.common.util.DateUtils; import hous.server.domain.room.Room; +import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + import static hous.server.common.exception.ErrorCode.FORBIDDEN_TODO_COUNT_EXCEPTION; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -15,4 +22,31 @@ public static void validateTodoCounts(Room room) { throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_TODO_COUNT_EXCEPTION); } } + + public static List filterTodayOurTodos(LocalDate now, List todos) { + List todayOurTodosList = new ArrayList<>(); + todos.forEach(todo -> { + todo.getTakes().forEach(take -> { + take.getRedos().forEach(redo -> { + if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(now))) { + todayOurTodosList.add(todo); + } + }); + }); + }); + return todayOurTodosList; + } + + public static List filterTodayMyTodos(LocalDate now, Onboarding me, List todos) { + List todayMyTodosList = new ArrayList<>(); + List todayOurTodosList = filterTodayOurTodos(now, todos); + todayOurTodosList.forEach(todo -> { + todo.getTakes().forEach(take -> { + if (take.getOnboarding().getId().equals(me.getId())) { + todayMyTodosList.add(todo); + } + }); + }); + return todayMyTodosList; + } } diff --git a/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java b/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java new file mode 100644 index 00000000..d2687ec5 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java @@ -0,0 +1,94 @@ +package hous.server.service.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.common.util.DateUtils; +import hous.server.common.util.MathUtils; +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.todo.OurTodoStatus; +import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; +import hous.server.domain.user.Onboarding; +import hous.server.service.todo.TodoServiceUtils; +import lombok.*; + +import java.time.LocalDate; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class GetTodoMainResponse { + + private String date; + private String dayOfWeek; + private int progress; + private int myTodosCnt; + private int ourTodosCnt; + private List myTodos; + private List ourTodos; + + @ToString + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + private static class MyTodo { + private Long todoId; + private String todoName; + private boolean isChecked; + + @JsonProperty("isChecked") + public boolean isChecked() { + return isChecked; + } + } + + @ToString + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + private static class OurTodo { + private String todoName; + private OurTodoStatus status; + private List nicknames; + } + + public static GetTodoMainResponse of(Onboarding me, LocalDate now, List todos, DoneRepository doneRepository) { + List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(now, todos); + List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(now, me, todos); + List todayMyTodos = todayMyTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> MyTodo.builder() + .todoId(todo.getId()) + .todoName(todo.getName()) + .isChecked(doneRepository.findTodayMyTodoCheckStatus(now, me, todo)) + .build()) + .collect(Collectors.toList()); + List todayOurTodos = todayOurTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> OurTodo.builder() + .todoName(todo.getName()) + .status(doneRepository.findTodayOurTodoStatus(now, todo)) + .nicknames(todo.getTakes().stream() + .map(take -> take.getOnboarding().getNickname()) + .collect(Collectors.toList())) + .build()) + .collect(Collectors.toList()); + int doneOurTodosCnt = (int) todayOurTodos.stream() + .filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.CHECK).count(); + return GetTodoMainResponse.builder() + .date(DateUtils.nowMonthAndDay(now)) + .dayOfWeek(DateUtils.nowDayOfWeek(now)) + .progress(MathUtils.percent(doneOurTodosCnt, todayOurTodos.size())) + .myTodosCnt(todayMyTodos.size()) + .ourTodosCnt(todayOurTodos.size()) + .myTodos(todayMyTodos) + .ourTodos(todayOurTodos) + .build(); + } +} From 78c12e9975e231bf996b1c6a7371da617697314e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 30 Aug 2022 19:27:06 +0900 Subject: [PATCH 047/301] =?UTF-8?q?#22=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/rule/Rule.java | 2 +- .../server/domain/rule/repository/RuleRepositoryCustom.java | 2 +- .../server/domain/rule/repository/RuleRepositoryImpl.java | 4 ++-- src/main/java/hous/server/service/rule/RuleService.java | 4 ++-- src/main/java/hous/server/service/rule/RuleServiceUtils.java | 4 ++-- .../service/user/dto/request/SetOnboardingInfoRequestDto.java | 2 +- src/main/resources/messages/validation.properties | 4 +--- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index f7ac63e2..d5fd4bbe 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -36,7 +36,7 @@ public static Rule newInstance(Room room, String name, int idx) { .build(); } - public void updateRule(UpdateRuleRequestDto request) { + public void updateRuleName(UpdateRuleRequestDto request) { this.name = request.getName(); } } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java index 4834d494..22238e3b 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryCustom.java @@ -7,5 +7,5 @@ public interface RuleRepositoryCustom { Rule findLastRuleByRoom(Room room); - Rule findRoomById(Long ruleId, Room room); + Rule findRuleByIdAndRoom(Long ruleId, Room room); } diff --git a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java index ea8b12b2..79933add 100644 --- a/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java +++ b/src/main/java/hous/server/domain/rule/repository/RuleRepositoryImpl.java @@ -23,10 +23,10 @@ public Rule findLastRuleByRoom(Room room) { } @Override - public Rule findRoomById(Long ruleId, Room room) { + public Rule findRuleByIdAndRoom(Long ruleId, Room room) { return queryFactory .selectFrom(rule) - .where(rule.id.eq(ruleId).and(rule.room.eq(room))) + .where(rule.id.eq(ruleId), rule.room.eq(room)) .fetchOne(); } } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 27bc586a..6820e5ee 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -35,8 +35,8 @@ public RuleInfoResponse createRule(CreateRuleRequestDto request, Long userId) { public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - Rule rule = RuleServiceUtils.findRuleById(ruleRepository, ruleId, room); - rule.updateRule(request); + Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, ruleId, room); + rule.updateRuleName(request); } } diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index f05c9a2d..f2c72f4b 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -30,8 +30,8 @@ public static void validateRuleCounts(Room room) { } } - public static Rule findRuleById(RuleRepository ruleRepository, Long ruleId, Room room) { - Rule rule = ruleRepository.findRoomById(ruleId, room); + public static Rule findRuleByIdAndRoom(RuleRepository ruleRepository, Long ruleId, Room room) { + Rule rule = ruleRepository.findRuleByIdAndRoom(ruleId, room); if (rule == null) { throw new NotFoundException(String.format("존재하지 않는 규칙 (%s) 입니다", ruleId), NOT_FOUND_RULE_EXCEPTION); } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index 9cbb687a..f8003801 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -19,7 +19,7 @@ public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") @NotBlank(message = "{onboarding.nickname.notBlank}") - @Size(min = 1, max = 5, message = "{onboarding.nickname.size}") + @Size(min = 1, max = 5, message = "{onboarding.nickname.max}") private String nickname; @ApiModelProperty(value = "생년월일", example = "1999-03-04") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 4827de24..797c85b1 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -8,7 +8,7 @@ user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8 user.socialType.notNull=\uC720\uC800\uC758 socialType \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.name.notBlank=\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.nickname.size=\uB2C9\uB124\uC784\uC740 5 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.nickname.max=\uB2C9\uB124\uC784\uC740 5 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. @@ -18,5 +18,3 @@ todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -#rule.id.notBlank=\uADDC\uCE59 id\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -#rule.idx.notBlank=\uADDC\uCE59 index\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. From e1e7a0b17e6c8f5f9343b6761b964cbcc2292f61 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 30 Aug 2022 21:55:34 +0900 Subject: [PATCH 048/301] =?UTF-8?q?#18=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/todo/OurTodoStatus.java | 2 +- .../todo/repository/DoneRepositoryImpl.java | 2 +- .../service/todo/TodoRetrieveService.java | 26 ++++++- .../dto/response/GetTodoMainResponse.java | 74 +++---------------- .../service/todo/dto/response/MyTodoInfo.java | 29 ++++++++ .../todo/dto/response/OurTodoInfo.java | 26 +++++++ 6 files changed, 91 insertions(+), 68 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java diff --git a/src/main/java/hous/server/domain/todo/OurTodoStatus.java b/src/main/java/hous/server/domain/todo/OurTodoStatus.java index e9377ced..adecadfa 100644 --- a/src/main/java/hous/server/domain/todo/OurTodoStatus.java +++ b/src/main/java/hous/server/domain/todo/OurTodoStatus.java @@ -3,5 +3,5 @@ public enum OurTodoStatus { EMPTY, FULL, - CHECK; + FULL_CHECK; } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index 32d6c78c..08a71865 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -40,7 +40,7 @@ public OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo) { .filter(lastDone -> lastDone != null && DateUtils.isSameDate(lastDone.getCreatedAt(), now)) .count(); if (doneCnt == 0) return OurTodoStatus.EMPTY; - else if (doneCnt == takes.size()) return OurTodoStatus.CHECK; + else if (doneCnt == takes.size()) return OurTodoStatus.FULL_CHECK; else return OurTodoStatus.FULL; } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 88e7b261..7cff3d9f 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -1,7 +1,9 @@ package hous.server.service.todo; +import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; +import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; @@ -9,6 +11,8 @@ import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.dto.response.GetTodoMainResponse; import hous.server.service.todo.dto.response.GetUsersInfoResponse; +import hous.server.service.todo.dto.response.MyTodoInfo; +import hous.server.service.todo.dto.response.OurTodoInfo; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -42,6 +46,26 @@ public GetUsersInfoResponse getUsersInfo(Long userId) { public GetTodoMainResponse getTodoMain(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - return GetTodoMainResponse.of(user.getOnboarding(), LocalDate.now(ZoneId.of("Asia/Seoul")), room.getTodos(), doneRepository); + LocalDate now = LocalDate.now(ZoneId.of("Asia/Seoul")); + List todos = room.getTodos(); + List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(now, todos); + List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(now, user.getOnboarding(), todos); + List todayMyTodos = todayMyTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> MyTodoInfo.of( + todo.getId(), + todo.getName(), + doneRepository.findTodayMyTodoCheckStatus(now, user.getOnboarding(), todo))) + .collect(Collectors.toList()); + List todayOurTodos = todayOurTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> OurTodoInfo.of( + todo.getName(), + doneRepository.findTodayOurTodoStatus(now, todo), + todo.getTakes().stream() + .map(take -> take.getOnboarding().getNickname()) + .collect(Collectors.toList()))) + .collect(Collectors.toList()); + return GetTodoMainResponse.of(now, todayMyTodos, todayOurTodos); } } diff --git a/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java b/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java index d2687ec5..21dbf696 100644 --- a/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java @@ -1,20 +1,12 @@ package hous.server.service.todo.dto.response; -import com.fasterxml.jackson.annotation.JsonProperty; import hous.server.common.util.DateUtils; import hous.server.common.util.MathUtils; -import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.todo.OurTodoStatus; -import hous.server.domain.todo.Todo; -import hous.server.domain.todo.repository.DoneRepository; -import hous.server.domain.user.Onboarding; -import hous.server.service.todo.TodoServiceUtils; import lombok.*; import java.time.LocalDate; -import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; @ToString @Getter @@ -28,67 +20,19 @@ public class GetTodoMainResponse { private int progress; private int myTodosCnt; private int ourTodosCnt; - private List myTodos; - private List ourTodos; + private List myTodos; + private List ourTodos; - @ToString - @Getter - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Builder(access = AccessLevel.PRIVATE) - private static class MyTodo { - private Long todoId; - private String todoName; - private boolean isChecked; - - @JsonProperty("isChecked") - public boolean isChecked() { - return isChecked; - } - } - - @ToString - @Getter - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Builder(access = AccessLevel.PRIVATE) - private static class OurTodo { - private String todoName; - private OurTodoStatus status; - private List nicknames; - } - - public static GetTodoMainResponse of(Onboarding me, LocalDate now, List todos, DoneRepository doneRepository) { - List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(now, todos); - List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(now, me, todos); - List todayMyTodos = todayMyTodosList.stream() - .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> MyTodo.builder() - .todoId(todo.getId()) - .todoName(todo.getName()) - .isChecked(doneRepository.findTodayMyTodoCheckStatus(now, me, todo)) - .build()) - .collect(Collectors.toList()); - List todayOurTodos = todayOurTodosList.stream() - .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> OurTodo.builder() - .todoName(todo.getName()) - .status(doneRepository.findTodayOurTodoStatus(now, todo)) - .nicknames(todo.getTakes().stream() - .map(take -> take.getOnboarding().getNickname()) - .collect(Collectors.toList())) - .build()) - .collect(Collectors.toList()); - int doneOurTodosCnt = (int) todayOurTodos.stream() - .filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.CHECK).count(); + public static GetTodoMainResponse of(LocalDate now, List myTodos, List ourTodos) { + int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); return GetTodoMainResponse.builder() .date(DateUtils.nowMonthAndDay(now)) .dayOfWeek(DateUtils.nowDayOfWeek(now)) - .progress(MathUtils.percent(doneOurTodosCnt, todayOurTodos.size())) - .myTodosCnt(todayMyTodos.size()) - .ourTodosCnt(todayOurTodos.size()) - .myTodos(todayMyTodos) - .ourTodos(todayOurTodos) + .progress(MathUtils.percent(doneOurTodosCnt, ourTodos.size())) + .myTodosCnt(myTodos.size()) + .ourTodosCnt(ourTodos.size()) + .myTodos(myTodos) + .ourTodos(ourTodos) .build(); } } diff --git a/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java new file mode 100644 index 00000000..cf56ef94 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java @@ -0,0 +1,29 @@ +package hous.server.service.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class MyTodoInfo { + + private Long todoId; + private String todoName; + private boolean isChecked; + + @JsonProperty("isChecked") + public boolean isChecked() { + return isChecked; + } + + public static MyTodoInfo of(Long todoId, String todoName, boolean isChecked) { + return MyTodoInfo.builder() + .todoId(todoId) + .todoName(todoName) + .isChecked(isChecked) + .build(); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java new file mode 100644 index 00000000..c3ca183e --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java @@ -0,0 +1,26 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.todo.OurTodoStatus; +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class OurTodoInfo { + + private String todoName; + private OurTodoStatus status; + private List nicknames; + + public static OurTodoInfo of(String todoName, OurTodoStatus status, List nicknames) { + return OurTodoInfo.builder() + .todoName(todoName) + .status(status) + .nicknames(nicknames) + .build(); + } +} From 3255fb66874016f5d03246e3a7f727db118f600a Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 00:27:42 +0900 Subject: [PATCH 049/301] =?UTF-8?q?#25=20[fix]=20response=20dto=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/todo/dto/response/GetUsersInfoResponse.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java index 7571a5a2..d555c98f 100644 --- a/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java @@ -1,5 +1,6 @@ package hous.server.service.todo.dto.response; +import hous.server.domain.personality.PersonalityColor; import hous.server.domain.user.Onboarding; import lombok.*; @@ -22,7 +23,7 @@ public class GetUsersInfoResponse { @Builder(access = AccessLevel.PRIVATE) private static class UserInfo { private Long onboardingId; - private String color; + private PersonalityColor color; private String nickname; } @@ -31,7 +32,7 @@ public static GetUsersInfoResponse of(List onboardings) { .users(onboardings.stream() .map(onboarding -> UserInfo.builder() .onboardingId(onboarding.getId()) - .color(onboarding.getPersonality().getColor().toString()) + .color(onboarding.getPersonality().getColor()) .nickname(onboarding.getNickname()) .build()) .collect(Collectors.toList())) From 6e0ff83aee380b9e3dffcd84e7fc74722ec5568c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 00:55:42 +0900 Subject: [PATCH 050/301] =?UTF-8?q?#25=20[feat]=20todo=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../server/common/success/SuccessCode.java | 1 + .../todo/TodoRetrieveController.java | 30 +++++- .../todo/repository/TodoRepositoryCustom.java | 4 + .../todo/repository/TodoRepositoryImpl.java | 10 ++ .../service/todo/TodoRetrieveService.java | 19 +++- .../server/service/todo/TodoServiceUtils.java | 11 +++ .../todo/dto/response/TodoInfoResponse.java | 95 +++++++++++++++++++ 8 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 6867ff14..2447137a 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -46,6 +46,7 @@ public enum ErrorCode { NOT_FOUND_ROOM_EXCEPTION(NOT_FOUND, "존재하지 않는 방입니다."), NOT_FOUND_PARTICIPATE_EXCEPTION(NOT_FOUND, "참가중인 방이 존재하지 않습니다."), NOT_FOUND_RULE_EXCEPTION(NOT_FOUND, "존재하지 않는 규칙입니다."), + NOT_FOUND_TODO_EXCEPTION(NOT_FOUND, "존재하지 않는 todo 입니다."), /** * 405 Method Not Allowed diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 63721eee..0057b8b3 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -27,6 +27,7 @@ public enum SuccessCode { // to-do GET_USERS_INFO_SUCCESS(OK, "담당자 목록 조회 성공입니다."), + GET_TODO_INFO_SUCCESS(OK, "todo 정보 조회 성공입니다."), GET_TODO_MAIN_SUCCESS(OK, "todo 메인 페이지 조회 성공입니다."), // rule diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 0d36e7c2..d101174c 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -8,13 +8,12 @@ import hous.server.service.todo.TodoRetrieveService; import hous.server.service.todo.dto.response.GetTodoMainResponse; import hous.server.service.todo.dto.response.GetUsersInfoResponse; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import hous.server.service.todo.dto.response.TodoInfoResponse; +import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; @@ -66,4 +65,27 @@ public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long public ResponseEntity getTodoMain(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_MAIN_SUCCESS, todoRetrieveService.getTodoMain(userId)); } + + @ApiOperation( + value = "[인증] todo 수정 페이지 - 저장된 todo 정보를 조회합니다.", + notes = "저장된 todo 이름, 알림 여부, 담당자, 담당 요일을 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "todo 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.\n" + + "3. 존재하지 않는 todo 입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/todo/{todoId}") + public ResponseEntity getTodoInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_TODO_INFO_SUCCESS, todoRetrieveService.getTodoInfo(todoId, userId)); + } } diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java index 0771ecb4..ebcabf9c 100644 --- a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryCustom.java @@ -1,4 +1,8 @@ package hous.server.domain.todo.repository; +import hous.server.domain.todo.Todo; + public interface TodoRepositoryCustom { + + Todo findTodoById(Long id); } diff --git a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java index a14f1f7b..8b14c4da 100644 --- a/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/TodoRepositoryImpl.java @@ -1,10 +1,20 @@ package hous.server.domain.todo.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.todo.Todo; import lombok.RequiredArgsConstructor; +import static hous.server.domain.todo.QTodo.todo; + @RequiredArgsConstructor public class TodoRepositoryImpl implements TodoRepositoryCustom { private final JPAQueryFactory queryFactory; + + @Override + public Todo findTodoById(Long id) { + return queryFactory.selectFrom(todo) + .where(todo.id.eq(id)) + .fetchOne(); + } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 7cff3d9f..9eb454ef 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -5,14 +5,12 @@ import hous.server.domain.room.Room; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; +import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; -import hous.server.service.todo.dto.response.GetTodoMainResponse; -import hous.server.service.todo.dto.response.GetUsersInfoResponse; -import hous.server.service.todo.dto.response.MyTodoInfo; -import hous.server.service.todo.dto.response.OurTodoInfo; +import hous.server.service.todo.dto.response.*; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -30,6 +28,7 @@ public class TodoRetrieveService { private final UserRepository userRepository; + private final TodoRepository todoRepository; private final DoneRepository doneRepository; public GetUsersInfoResponse getUsersInfo(Long userId) { @@ -68,4 +67,16 @@ public GetTodoMainResponse getTodoMain(Long userId) { .collect(Collectors.toList()); return GetTodoMainResponse.of(now, todayMyTodos, todayOurTodos); } + + public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); + List participates = room.getParticipates(); + List onboardings = participates.stream() + .map(Participate::getOnboarding) + .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) + .collect(Collectors.toList()); + return TodoInfoResponse.of(todo, onboardings); + } } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 857f827a..35230efe 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -1,9 +1,11 @@ package hous.server.service.todo; import hous.server.common.exception.ForbiddenException; +import hous.server.common.exception.NotFoundException; import hous.server.common.util.DateUtils; import hous.server.domain.room.Room; import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -13,10 +15,19 @@ import java.util.List; import static hous.server.common.exception.ErrorCode.FORBIDDEN_TODO_COUNT_EXCEPTION; +import static hous.server.common.exception.ErrorCode.NOT_FOUND_TODO_EXCEPTION; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class TodoServiceUtils { + public static Todo findTodoById(TodoRepository todoRepository, Long todoId) { + Todo todo = todoRepository.findTodoById(todoId); + if (todo == null) { + throw new NotFoundException(String.format("존재하지 않는 todo (%s) 입니다", todoId), NOT_FOUND_TODO_EXCEPTION); + } + return todo; + } + public static void validateTodoCounts(Room room) { if (room.getTodosCnt() >= 60) { throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_TODO_COUNT_EXCEPTION); diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java new file mode 100644 index 00000000..0838c13a --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java @@ -0,0 +1,95 @@ +package hous.server.service.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.todo.DayOfWeek; +import hous.server.domain.todo.Redo; +import hous.server.domain.todo.Take; +import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; +import lombok.*; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class TodoInfoResponse { + + private String name; + private boolean isPushNotification; + private List selectedUsers; + private List todoUsers; + + @JsonProperty("isPushNotification") + public boolean isPushNotification() { + return isPushNotification; + } + + @ToString + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + private static class UserInfo { + private Long onboardingId; + private PersonalityColor color; + private String nickname; + } + + @ToString + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + public static class TodoUser { + private Long onboardingId; + private PersonalityColor color; + private String nickname; + private boolean isSelected; + private List dayOfWeeks; + + @JsonProperty("isSelected") + public boolean isSelected() { + return isSelected; + } + } + + public static TodoInfoResponse of(Todo todo, List onboardings) { + List selectedUsers = todo.getTakes().stream() + .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getCreatedAt())) + .map(take -> UserInfo.builder() + .onboardingId(take.getOnboarding().getId()) + .color(take.getOnboarding().getPersonality().getColor()) + .nickname(take.getOnboarding().getNickname()) + .build()) + .collect(Collectors.toList()); + List todoUsers = onboardings.stream() + .map(onboarding -> { + List takes = todo.getTakes().stream() + .filter(take -> take.getOnboarding().getId().equals(onboarding.getId())) + .collect(Collectors.toList()); + return TodoUser.builder() + .onboardingId(onboarding.getId()) + .color(onboarding.getPersonality().getColor()) + .nickname(onboarding.getNickname()) + .isSelected(takes.size() == 1) + .dayOfWeeks(takes.size() == 1 ? takes.get(0).getRedos().stream() + .map(Redo::getDayOfWeek) + .collect(Collectors.toList()) : new ArrayList<>()) + .build(); + }) + .collect(Collectors.toList()); + return TodoInfoResponse.builder() + .name(todo.getName()) + .isPushNotification(todo.isPushNotification()) + .selectedUsers(selectedUsers) + .todoUsers(todoUsers) + .build(); + } +} From 5eff0732d4da848d12a496969a39eff58ec52484 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 01:34:22 +0900 Subject: [PATCH 051/301] =?UTF-8?q?#25=20[feat]=20todo=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../todo/TodoRetrieveController.java | 23 ++++++++ .../service/todo/TodoRetrieveService.java | 6 ++ .../todo/dto/response/TodoInfoResponse.java | 2 +- .../dto/response/TodoSummaryInfoResponse.java | 59 +++++++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 0057b8b3..6fff89ad 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -28,6 +28,7 @@ public enum SuccessCode { // to-do GET_USERS_INFO_SUCCESS(OK, "담당자 목록 조회 성공입니다."), GET_TODO_INFO_SUCCESS(OK, "todo 정보 조회 성공입니다."), + GET_TODO_SUMMARY_INFO_SUCCESS(OK, "todo 요약 정보 조회 성공입니다."), GET_TODO_MAIN_SUCCESS(OK, "todo 메인 페이지 조회 성공입니다."), // rule diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index d101174c..3bd30ef9 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -9,6 +9,7 @@ import hous.server.service.todo.dto.response.GetTodoMainResponse; import hous.server.service.todo.dto.response.GetUsersInfoResponse; import hous.server.service.todo.dto.response.TodoInfoResponse; +import hous.server.service.todo.dto.response.TodoSummaryInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -88,4 +89,26 @@ public ResponseEntity getTodoInfo(@ApiParam(name = "todoId", v @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_INFO_SUCCESS, todoRetrieveService.getTodoInfo(todoId, userId)); } + + @ApiOperation( + value = "[인증] todo 전체 페이지 - 저장된 todo 요약 정보를 조회합니다.", + notes = "저장된 전체 담당자, 전체 담당 요일을 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "todo 요약 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 todo 입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/todo/{todoId}/summary") + public ResponseEntity getTodoSummaryInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_TODO_SUMMARY_INFO_SUCCESS, todoRetrieveService.getTodoSummaryInfo(todoId, userId)); + } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 9eb454ef..048bf3d6 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -79,4 +79,10 @@ public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { .collect(Collectors.toList()); return TodoInfoResponse.of(todo, onboardings); } + + public TodoSummaryInfoResponse getTodoSummaryInfo(Long todoId, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); + return TodoSummaryInfoResponse.of(todo, user.getOnboarding()); + } } diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java index 0838c13a..00622040 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java @@ -47,7 +47,7 @@ private static class UserInfo { @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) - public static class TodoUser { + private static class TodoUser { private Long onboardingId; private PersonalityColor color; private String nickname; diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java new file mode 100644 index 00000000..be841257 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java @@ -0,0 +1,59 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.todo.DayOfWeek; +import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; +import lombok.*; + +import java.util.*; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class TodoSummaryInfoResponse { + + private String name; + private List selectedUsers; + private List dayOfWeeks; + + @ToString + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + private static class UserInfo { + private Long onboardingId; + private PersonalityColor color; + private String nickname; + } + + public static TodoSummaryInfoResponse of(Todo todo, Onboarding me) { + List selectedUsers = todo.getTakes().stream() + .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getCreatedAt())) + .map(take -> UserInfo.builder() + .onboardingId(take.getOnboarding().getId()) + .color(take.getOnboarding().getPersonality().getColor()) + .nickname(take.getOnboarding().getNickname()) + .build()) + .collect(Collectors.toList()); + for (int i = 0; i < selectedUsers.size(); i++) { + if (selectedUsers.get(i).getOnboardingId().equals(me.getId())) { + UserInfo myInfo = selectedUsers.get(i); + selectedUsers.remove(i); + selectedUsers.add(0, myInfo); + break; + } + } + Set dayOfWeekSet = new HashSet<>(); + todo.getTakes().forEach(take -> take.getRedos().forEach(redo -> dayOfWeekSet.add(redo.getDayOfWeek()))); + return TodoSummaryInfoResponse.builder() + .name(todo.getName()) + .selectedUsers(selectedUsers) + .dayOfWeeks(new ArrayList<>(dayOfWeekSet)) + .build(); + } +} From a21de261f6e77ff17f63521245489d50c6b4be1c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 12:28:40 +0900 Subject: [PATCH 052/301] =?UTF-8?q?#25=20[refactor]=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/TodoRetrieveController.java | 8 +- .../service/todo/TodoRetrieveService.java | 14 ++-- .../server/service/todo/TodoServiceUtils.java | 13 +++ .../dto/response/GetUsersInfoResponse.java | 41 ---------- .../todo/dto/response/TodoInfoResponse.java | 81 ++++++------------- ...ainResponse.java => TodoMainResponse.java} | 6 +- .../dto/response/TodoSummaryInfoResponse.java | 40 ++------- .../todo/dto/response/TodoUserInfo.java | 40 +++++++++ .../dto/response/UserPersonalityInfo.java | 39 +++++++++ .../response/UserPersonalityInfoResponse.java | 28 +++++++ 10 files changed, 165 insertions(+), 145 deletions(-) delete mode 100644 src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java rename src/main/java/hous/server/service/todo/dto/response/{GetTodoMainResponse.java => TodoMainResponse.java} (85%) create mode 100644 src/main/java/hous/server/service/todo/dto/response/TodoUserInfo.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfo.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 3bd30ef9..e54db6ce 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -6,10 +6,10 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoRetrieveService; -import hous.server.service.todo.dto.response.GetTodoMainResponse; -import hous.server.service.todo.dto.response.GetUsersInfoResponse; import hous.server.service.todo.dto.response.TodoInfoResponse; +import hous.server.service.todo.dto.response.TodoMainResponse; import hous.server.service.todo.dto.response.TodoSummaryInfoResponse; +import hous.server.service.todo.dto.response.UserPersonalityInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -43,7 +43,7 @@ public class TodoRetrieveController { }) @Auth @GetMapping("/todo") - public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_USERS_INFO_SUCCESS, todoRetrieveService.getUsersInfo(userId)); } @@ -63,7 +63,7 @@ public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long }) @Auth @GetMapping("/todos") - public ResponseEntity getTodoMain(@ApiIgnore @UserId Long userId) { + public ResponseEntity getTodoMain(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_MAIN_SUCCESS, todoRetrieveService.getTodoMain(userId)); } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 048bf3d6..f04b37ce 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -31,7 +31,7 @@ public class TodoRetrieveService { private final TodoRepository todoRepository; private final DoneRepository doneRepository; - public GetUsersInfoResponse getUsersInfo(Long userId) { + public UserPersonalityInfoResponse getUsersInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); List participates = room.getParticipates(); @@ -39,10 +39,10 @@ public GetUsersInfoResponse getUsersInfo(Long userId) { .map(Participate::getOnboarding) .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) .collect(Collectors.toList()); - return GetUsersInfoResponse.of(onboardings); + return UserPersonalityInfoResponse.of(onboardings); } - public GetTodoMainResponse getTodoMain(Long userId) { + public TodoMainResponse getTodoMain(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); LocalDate now = LocalDate.now(ZoneId.of("Asia/Seoul")); @@ -65,7 +65,7 @@ public GetTodoMainResponse getTodoMain(Long userId) { .map(take -> take.getOnboarding().getNickname()) .collect(Collectors.toList()))) .collect(Collectors.toList()); - return GetTodoMainResponse.of(now, todayMyTodos, todayOurTodos); + return TodoMainResponse.of(now, todayMyTodos, todayOurTodos); } public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { @@ -77,12 +77,14 @@ public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { .map(Participate::getOnboarding) .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) .collect(Collectors.toList()); - return TodoInfoResponse.of(todo, onboardings); + List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(todo); + return TodoInfoResponse.of(todo, userPersonalityInfos, onboardings); } public TodoSummaryInfoResponse getTodoSummaryInfo(Long todoId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); - return TodoSummaryInfoResponse.of(todo, user.getOnboarding()); + List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(todo); + return TodoSummaryInfoResponse.of(todo, userPersonalityInfos, user.getOnboarding()); } } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 35230efe..26b4c518 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -7,12 +7,15 @@ import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; +import hous.server.service.todo.dto.response.UserPersonalityInfo; import lombok.AccessLevel; import lombok.NoArgsConstructor; import java.time.LocalDate; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; import static hous.server.common.exception.ErrorCode.FORBIDDEN_TODO_COUNT_EXCEPTION; import static hous.server.common.exception.ErrorCode.NOT_FOUND_TODO_EXCEPTION; @@ -34,6 +37,16 @@ public static void validateTodoCounts(Room room) { } } + public static List toUserPersonalityInfoList(Todo todo) { + return todo.getTakes().stream() + .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getCreatedAt())) + .map(take -> UserPersonalityInfo.of( + take.getOnboarding().getId(), + take.getOnboarding().getPersonality().getColor(), + take.getOnboarding().getNickname())) + .collect(Collectors.toList()); + } + public static List filterTodayOurTodos(LocalDate now, List todos) { List todayOurTodosList = new ArrayList<>(); todos.forEach(todo -> { diff --git a/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java deleted file mode 100644 index d555c98f..00000000 --- a/src/main/java/hous/server/service/todo/dto/response/GetUsersInfoResponse.java +++ /dev/null @@ -1,41 +0,0 @@ -package hous.server.service.todo.dto.response; - -import hous.server.domain.personality.PersonalityColor; -import hous.server.domain.user.Onboarding; -import lombok.*; - -import java.util.List; -import java.util.stream.Collectors; - -@ToString -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Builder(access = AccessLevel.PRIVATE) -public class GetUsersInfoResponse { - - private List users; - - @ToString - @Getter - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Builder(access = AccessLevel.PRIVATE) - private static class UserInfo { - private Long onboardingId; - private PersonalityColor color; - private String nickname; - } - - public static GetUsersInfoResponse of(List onboardings) { - return GetUsersInfoResponse.builder() - .users(onboardings.stream() - .map(onboarding -> UserInfo.builder() - .onboardingId(onboarding.getId()) - .color(onboarding.getPersonality().getColor()) - .nickname(onboarding.getNickname()) - .build()) - .collect(Collectors.toList())) - .build(); - } -} diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java index 00622040..10f52abd 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java @@ -1,8 +1,6 @@ package hous.server.service.todo.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; -import hous.server.domain.personality.PersonalityColor; -import hous.server.domain.todo.DayOfWeek; import hous.server.domain.todo.Redo; import hous.server.domain.todo.Take; import hous.server.domain.todo.Todo; @@ -10,8 +8,8 @@ import lombok.*; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @ToString @@ -23,73 +21,40 @@ public class TodoInfoResponse { private String name; private boolean isPushNotification; - private List selectedUsers; - private List todoUsers; + private List selectedUsers; + private List todoUsers; @JsonProperty("isPushNotification") public boolean isPushNotification() { return isPushNotification; } - @ToString - @Getter - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Builder(access = AccessLevel.PRIVATE) - private static class UserInfo { - private Long onboardingId; - private PersonalityColor color; - private String nickname; - } - - @ToString - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @Builder(access = AccessLevel.PRIVATE) - private static class TodoUser { - private Long onboardingId; - private PersonalityColor color; - private String nickname; - private boolean isSelected; - private List dayOfWeeks; - - @JsonProperty("isSelected") - public boolean isSelected() { - return isSelected; - } + public static TodoInfoResponse of(Todo todo, List userPersonalityInfos, List onboardings) { + List todoUsers = toTodoInfoList(todo, onboardings); + return TodoInfoResponse.builder() + .name(todo.getName()) + .isPushNotification(todo.isPushNotification()) + .selectedUsers(userPersonalityInfos) + .todoUsers(todoUsers) + .build(); } - public static TodoInfoResponse of(Todo todo, List onboardings) { - List selectedUsers = todo.getTakes().stream() - .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getCreatedAt())) - .map(take -> UserInfo.builder() - .onboardingId(take.getOnboarding().getId()) - .color(take.getOnboarding().getPersonality().getColor()) - .nickname(take.getOnboarding().getNickname()) - .build()) - .collect(Collectors.toList()); - List todoUsers = onboardings.stream() + private static List toTodoInfoList(Todo todo, List onboardings) { + return onboardings.stream() .map(onboarding -> { - List takes = todo.getTakes().stream() + Optional myTake = todo.getTakes().stream() .filter(take -> take.getOnboarding().getId().equals(onboarding.getId())) - .collect(Collectors.toList()); - return TodoUser.builder() - .onboardingId(onboarding.getId()) - .color(onboarding.getPersonality().getColor()) - .nickname(onboarding.getNickname()) - .isSelected(takes.size() == 1) - .dayOfWeeks(takes.size() == 1 ? takes.get(0).getRedos().stream() + .findFirst(); + return TodoUserInfo.of( + onboarding.getId(), + onboarding.getPersonality().getColor(), + onboarding.getNickname(), + myTake.isPresent(), + myTake.map(take -> take.getRedos().stream() .map(Redo::getDayOfWeek) - .collect(Collectors.toList()) : new ArrayList<>()) - .build(); + .collect(Collectors.toList())).orElseGet(ArrayList::new) + ); }) .collect(Collectors.toList()); - return TodoInfoResponse.builder() - .name(todo.getName()) - .isPushNotification(todo.isPushNotification()) - .selectedUsers(selectedUsers) - .todoUsers(todoUsers) - .build(); } } diff --git a/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java similarity index 85% rename from src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java rename to src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java index 21dbf696..237f77d5 100644 --- a/src/main/java/hous/server/service/todo/dto/response/GetTodoMainResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java @@ -13,7 +13,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) -public class GetTodoMainResponse { +public class TodoMainResponse { private String date; private String dayOfWeek; @@ -23,9 +23,9 @@ public class GetTodoMainResponse { private List myTodos; private List ourTodos; - public static GetTodoMainResponse of(LocalDate now, List myTodos, List ourTodos) { + public static TodoMainResponse of(LocalDate now, List myTodos, List ourTodos) { int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); - return GetTodoMainResponse.builder() + return TodoMainResponse.builder() .date(DateUtils.nowMonthAndDay(now)) .dayOfWeek(DateUtils.nowDayOfWeek(now)) .progress(MathUtils.percent(doneOurTodosCnt, ourTodos.size())) diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java index be841257..2fd6dd60 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java @@ -1,13 +1,14 @@ package hous.server.service.todo.dto.response; -import hous.server.domain.personality.PersonalityColor; import hous.server.domain.todo.DayOfWeek; import hous.server.domain.todo.Todo; import hous.server.domain.user.Onboarding; import lombok.*; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; @ToString @Getter @@ -17,42 +18,15 @@ public class TodoSummaryInfoResponse { private String name; - private List selectedUsers; + private List selectedUsers; private List dayOfWeeks; - @ToString - @Getter - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @Builder(access = AccessLevel.PRIVATE) - private static class UserInfo { - private Long onboardingId; - private PersonalityColor color; - private String nickname; - } - - public static TodoSummaryInfoResponse of(Todo todo, Onboarding me) { - List selectedUsers = todo.getTakes().stream() - .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getCreatedAt())) - .map(take -> UserInfo.builder() - .onboardingId(take.getOnboarding().getId()) - .color(take.getOnboarding().getPersonality().getColor()) - .nickname(take.getOnboarding().getNickname()) - .build()) - .collect(Collectors.toList()); - for (int i = 0; i < selectedUsers.size(); i++) { - if (selectedUsers.get(i).getOnboardingId().equals(me.getId())) { - UserInfo myInfo = selectedUsers.get(i); - selectedUsers.remove(i); - selectedUsers.add(0, myInfo); - break; - } - } + public static TodoSummaryInfoResponse of(Todo todo, List userPersonalityInfos, Onboarding me) { Set dayOfWeekSet = new HashSet<>(); todo.getTakes().forEach(take -> take.getRedos().forEach(redo -> dayOfWeekSet.add(redo.getDayOfWeek()))); return TodoSummaryInfoResponse.builder() .name(todo.getName()) - .selectedUsers(selectedUsers) + .selectedUsers(UserPersonalityInfo.sortMeFirst(userPersonalityInfos, me)) .dayOfWeeks(new ArrayList<>(dayOfWeekSet)) .build(); } diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoUserInfo.java b/src/main/java/hous/server/service/todo/dto/response/TodoUserInfo.java new file mode 100644 index 00000000..99f9da50 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/TodoUserInfo.java @@ -0,0 +1,40 @@ +package hous.server.service.todo.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.todo.DayOfWeek; +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class TodoUserInfo extends UserPersonalityInfo { + + private boolean isSelected; + private List dayOfWeeks; + + @JsonProperty("isSelected") + public boolean isSelected() { + return isSelected; + } + + @Builder(access = AccessLevel.PRIVATE) + public TodoUserInfo(Long onboardingId, PersonalityColor color, String nickname, boolean isSelected, List dayOfWeeks) { + super(onboardingId, color, nickname); + this.isSelected = isSelected; + this.dayOfWeeks = dayOfWeeks; + } + + public static TodoUserInfo of(Long onboardingId, PersonalityColor color, String nickname, boolean isSelected, List dayOfWeeks) { + return TodoUserInfo.builder() + .onboardingId(onboardingId) + .color(color) + .nickname(nickname) + .isSelected(isSelected) + .dayOfWeeks(dayOfWeeks) + .build(); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfo.java b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfo.java new file mode 100644 index 00000000..3f317434 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfo.java @@ -0,0 +1,39 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.user.Onboarding; +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Builder(access = AccessLevel.PRIVATE) +public class UserPersonalityInfo { + + private Long onboardingId; + private PersonalityColor color; + private String nickname; + + public static UserPersonalityInfo of(Long onboardingId, PersonalityColor color, String nickname) { + return UserPersonalityInfo.builder() + .onboardingId(onboardingId) + .color(color) + .nickname(nickname) + .build(); + } + + public static List sortMeFirst(List userPersonalityInfos, Onboarding me) { + for (int i = 0; i < userPersonalityInfos.size(); i++) { + if (userPersonalityInfos.get(i).getOnboardingId().equals(me.getId())) { + UserPersonalityInfo myInfo = userPersonalityInfos.get(i); + userPersonalityInfos.remove(i); + userPersonalityInfos.add(0, myInfo); + break; + } + } + return userPersonalityInfos; + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java new file mode 100644 index 00000000..217fc4aa --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java @@ -0,0 +1,28 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.user.Onboarding; +import lombok.*; + +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class UserPersonalityInfoResponse { + + private List users; + + public static UserPersonalityInfoResponse of(List onboardings) { + return UserPersonalityInfoResponse.builder() + .users(onboardings.stream() + .map(onboarding -> UserPersonalityInfo.of( + onboarding.getId(), + onboarding.getPersonality().getColor(), + onboarding.getNickname())) + .collect(Collectors.toList())) + .build(); + } +} From 3a35cc1704fb539934ab82a17667ab61aa73bf8f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 31 Aug 2022 12:39:18 +0900 Subject: [PATCH 053/301] =?UTF-8?q?#28=20[fix]=20=EC=98=A8=EB=B3=B4?= =?UTF-8?q?=EB=94=A9=20=EC=A0=95=EB=B3=B4=20=EC=84=A4=EC=A0=95=20=EC=8B=9C?= =?UTF-8?q?,=20=EC=83=9D=EB=85=84=EC=9B=94=EC=9D=BC=20=EA=B3=B5=EA=B0=9C?= =?UTF-8?q?=20=EC=97=AC=EB=B6=80=EB=8F=84=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/controller/user/UserController.java | 3 ++- src/main/java/hous/server/domain/user/Onboarding.java | 3 ++- .../java/hous/server/service/user/UserService.java | 2 +- .../user/dto/request/SetOnboardingInfoRequestDto.java | 10 ++++++++++ src/main/resources/messages/validation.properties | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index abf5ce81..0053c847 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -37,7 +37,8 @@ public class UserController { code = 400, message = "1. 닉네임을 입력해주세요. (nickname)\n" + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" - + "3. 생년월일을 입력해주세요. (birthday)", + + "3. 생년월일을 입력해주세요. (birthday)\n" + + "4. 생년월일을 공개 여부를 체크해주세요. (isPublic)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 384c256e..8d6332e7 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -86,9 +86,10 @@ public static Onboarding newInstance(Personality personality) { .build(); } - public void setOnboarding(String nickname, LocalDate birthday) { + public void setOnboarding(String nickname, LocalDate birthday, boolean isPublic) { this.nickname = nickname; this.birthday = birthday; + this.isPublic = isPublic; this.isChecked = true; } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 65ffde4f..66869a45 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -31,6 +31,6 @@ public Long registerUser(CreateUserDto request) { public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); - onboarding.setOnboarding(request.getNickname(), request.getBirthday()); + onboarding.setOnboarding(request.getNickname(), request.getBirthday(), request.isPublic()); } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index f8003801..d6888f67 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -1,6 +1,7 @@ package hous.server.service.user.dto.request; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -26,4 +27,13 @@ public class SetOnboardingInfoRequestDto { @NotNull(message = "{onboarding.birthday.notNull}") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") private LocalDate birthday; + + @ApiModelProperty(value = "생년월일 공개 여부", example = "true") + @NotNull(message = "{onboarding.isPublic.notNull}") + private boolean isPublic; + + @JsonProperty("isPublic") + public boolean isPublic() { + return isPublic; + } } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 797c85b1..5b5081d3 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -10,6 +10,7 @@ onboarding.name.notBlank=\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694 onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.nickname.max=\uB2C9\uB124\uC784\uC740 5 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.isPublic.notNull=\uC0DD\uB144\uC6D4\uC77C \uACF5\uAC1C \uC5EC\uBD80\uB97C \uCCB4\uD06C\uD574\uC8FC\uC138\uC694. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.name.notBlank=todo \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. From 32bd173bad2ca73cf69bccd623fda49e312a6ade Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 18:48:43 +0900 Subject: [PATCH 054/301] =?UTF-8?q?#30=20[refactor]=20no=20content=20respo?= =?UTF-8?q?nse=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/dto/SuccessResponse.java | 2 ++ .../controller/rule/RuleController.java | 19 ++++++++----------- .../controller/todo/TodoController.java | 5 ++--- .../controller/user/UserController.java | 6 ++---- .../hous/server/service/rule/RuleService.java | 4 +--- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/java/hous/server/common/dto/SuccessResponse.java b/src/main/java/hous/server/common/dto/SuccessResponse.java index 8d95a287..cb2912aa 100644 --- a/src/main/java/hous/server/common/dto/SuccessResponse.java +++ b/src/main/java/hous/server/common/dto/SuccessResponse.java @@ -10,6 +10,8 @@ @AllArgsConstructor(access = AccessLevel.PRIVATE) public class SuccessResponse { + public static final ResponseEntity NO_CONTENT = success(SuccessCode.NO_CONTENT_SUCCESS, ""); + private int status; private boolean success; private String message; diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 4c13ff8b..dd5575dd 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -2,13 +2,11 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; -import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleService; import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; -import hous.server.service.rule.dto.response.RuleInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -48,10 +46,10 @@ public class RuleController { @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/rule") - public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { ruleService.createRule(request, userId); - return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); + return SuccessResponse.NO_CONTENT; } @ApiOperation( @@ -77,12 +75,11 @@ public ResponseEntity createRule(@Valid @RequestBody CreateRul @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/rule/{ruleId}") - public ResponseEntity UpdateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") - @PathVariable Long ruleId, - @Valid @RequestBody UpdateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity UpdateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") + @PathVariable Long ruleId, + @Valid @RequestBody UpdateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { ruleService.updateRule(request, ruleId, userId); - return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); + return SuccessResponse.NO_CONTENT; } - } diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 938f5072..e7550377 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -2,7 +2,6 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; -import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; @@ -53,8 +52,8 @@ public class TodoController { @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/todo") - public ResponseEntity createTodo(@Valid @RequestBody CreateTodoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity createTodo(@Valid @RequestBody CreateTodoRequestDto request, @ApiIgnore @UserId Long userId) { todoService.createTodo(request, userId); - return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); + return SuccessResponse.NO_CONTENT; } } diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 0053c847..431b4814 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -2,7 +2,6 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; -import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.user.UserService; @@ -47,10 +46,9 @@ public class UserController { @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/user/onboarding") - public ResponseEntity setOnboardingInfo( + public ResponseEntity setOnboardingInfo( @Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { userService.setOnboardingInfo(request, userId); - return SuccessResponse.success(SuccessCode.NO_CONTENT_SUCCESS, null); + return SuccessResponse.NO_CONTENT; } - } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 6820e5ee..de2db4db 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -8,7 +8,6 @@ import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; -import hous.server.service.rule.dto.response.RuleInfoResponse; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -22,14 +21,13 @@ public class RuleService { private final UserRepository userRepository; private final RuleRepository ruleRepository; - public RuleInfoResponse createRule(CreateRuleRequestDto request, Long userId) { + public void createRule(CreateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); RuleServiceUtils.validateRuleCounts(room); int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room); Rule rule = ruleRepository.save(Rule.newInstance(room, request.getName(), ruleIdx + 1)); room.addRule(rule); - return RuleInfoResponse.of(rule); } public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { From 91acf7e072983883f41bb17312c4d05b353dcc97 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 18:52:08 +0900 Subject: [PATCH 055/301] =?UTF-8?q?#30=20[rename]=20dto=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/todo/TodoService.java | 4 ++-- .../{CreateTodoRequestDto.java => UpdateTodoRequestDto.java} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/hous/server/service/todo/dto/request/{CreateTodoRequestDto.java => UpdateTodoRequestDto.java} (97%) diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 245cfe58..6bdda71c 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -12,7 +12,7 @@ import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; -import hous.server.service.todo.dto.request.CreateTodoRequestDto; +import hous.server.service.todo.dto.request.UpdateTodoRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -29,7 +29,7 @@ public class TodoService { private final TakeRepository takeRepository; private final RedoRepository redoRepository; - public void createTodo(CreateTodoRequestDto request, Long userId) { + public void createTodo(UpdateTodoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); TodoServiceUtils.validateTodoCounts(room); diff --git a/src/main/java/hous/server/service/todo/dto/request/CreateTodoRequestDto.java b/src/main/java/hous/server/service/todo/dto/request/UpdateTodoRequestDto.java similarity index 97% rename from src/main/java/hous/server/service/todo/dto/request/CreateTodoRequestDto.java rename to src/main/java/hous/server/service/todo/dto/request/UpdateTodoRequestDto.java index 517eaa3e..b65bc7e9 100644 --- a/src/main/java/hous/server/service/todo/dto/request/CreateTodoRequestDto.java +++ b/src/main/java/hous/server/service/todo/dto/request/UpdateTodoRequestDto.java @@ -17,7 +17,7 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CreateTodoRequestDto { +public class UpdateTodoRequestDto { @ApiModelProperty(value = "todo 이름", example = "청소기 돌리기") @NotBlank(message = "{todo.name.notBlank}") From 9f2ccba14d186693236f7d5422cda27b786f4f82 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 19:02:13 +0900 Subject: [PATCH 056/301] =?UTF-8?q?#30=20[fix]=20done=20=EA=B2=80=EC=82=AC?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/todo/repository/DoneRepositoryImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index 08a71865..3b04f351 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -22,7 +22,10 @@ public class DoneRepositoryImpl implements DoneRepositoryCustom { @Override public boolean findTodayMyTodoCheckStatus(LocalDate now, Onboarding me, Todo todo) { Done lastDone = queryFactory.selectFrom(done) - .where(done.onboarding.eq(me)) + .where( + done.onboarding.eq(me), + done.todo.eq(todo) + ) .orderBy(done.createdAt.desc()) .fetchFirst(); if (lastDone == null) return false; @@ -34,7 +37,10 @@ public OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo) { List takes = todo.getTakes(); int doneCnt = (int) takes.stream() .map(take -> queryFactory.selectFrom(done) - .where(done.onboarding.eq(take.getOnboarding())) + .where( + done.onboarding.eq(take.getOnboarding()), + done.todo.eq(todo) + ) .orderBy(done.createdAt.desc()) .fetchFirst()) .filter(lastDone -> lastDone != null && DateUtils.isSameDate(lastDone.getCreatedAt(), now)) From 864a68f442447fa4c807c1009288b325d8f77a68 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 19:41:28 +0900 Subject: [PATCH 057/301] =?UTF-8?q?#30=20[feat]=20todo=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/todo/TodoController.java | 37 ++++++++++++++++--- .../java/hous/server/domain/todo/Todo.java | 7 ++++ .../hous/server/service/todo/TodoService.java | 22 +++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index e7550377..98c808d6 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -5,11 +5,8 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; -import hous.server.service.todo.dto.request.CreateTodoRequestDto; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import hous.server.service.todo.dto.request.UpdateTodoRequestDto; +import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -52,8 +49,36 @@ public class TodoController { @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/todo") - public ResponseEntity createTodo(@Valid @RequestBody CreateTodoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity createTodo(@Valid @RequestBody UpdateTodoRequestDto request, @ApiIgnore @UserId Long userId) { todoService.createTodo(request, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] todo 수정 페이지 - todo 를 수정합니다.", + notes = "todo 이름을 15글자 이내로 설정하고 알림 여부, 담당자, 담당 요일을 설정하여 todo 수정을 요청합니다.\n" + + "성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. todo 이름을 입력해주세요. (name)\n" + + "2. todo 이름을 15 글자 이내로 입력해주세요. (name)\n" + + "3. 담당자 목록은 빈 배열일 수 없습니다. (todoUsers)\n" + + "4. 담당 요일 목록은 빈 배열일 수 없습니다. (todoUsers[0].dayOfWeeks)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/todo/{todoId}") + public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수정할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @Valid @RequestBody UpdateTodoRequestDto request) { + todoService.updateTodo(todoId, request); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/todo/Todo.java b/src/main/java/hous/server/domain/todo/Todo.java index 76559281..e762e4ec 100644 --- a/src/main/java/hous/server/domain/todo/Todo.java +++ b/src/main/java/hous/server/domain/todo/Todo.java @@ -51,6 +51,13 @@ public static Todo newInstance(Room room, String name, boolean isPushNotificatio .build(); } + public void updateTodo(String name, boolean isPushNotification, List takes) { + this.name = name; + this.isPushNotification = isPushNotification; + this.takes.clear(); + this.takes.addAll(takes); + } + public void addTake(Take take) { this.takes.add(take); } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 6bdda71c..f3875bbc 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -18,6 +18,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + @RequiredArgsConstructor @Service @Transactional @@ -45,4 +48,23 @@ public void createTodo(UpdateTodoRequestDto request, Long userId) { }); room.addTodo(todo); } + + public void updateTodo(Long todoId, UpdateTodoRequestDto request) { + Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); + todo.getTakes().forEach(take -> { + redoRepository.deleteAll(take.getRedos()); + takeRepository.delete(take); + }); + List takes = new ArrayList<>(); + request.getTodoUsers().forEach(todoUser -> { + Onboarding onboarding = onboardingRepository.findOnboardingById(todoUser.getOnboardingId()); + Take take = takeRepository.save(Take.newInstance(todo, onboarding)); + todoUser.getDayOfWeeks().forEach(dayOfWeek -> { + Redo redo = redoRepository.save(Redo.newInstance(take, dayOfWeek)); + take.addRedo(redo); + }); + takes.add(take); + }); + todo.updateTodo(request.getName(), request.isPushNotification(), takes); + } } From 9661301e0c0537d2c6d29b44607f4ccde37795f6 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 19:54:06 +0900 Subject: [PATCH 058/301] =?UTF-8?q?#30=20[feat]=20todo=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/todo/TodoController.java | 20 +++++++++++++++++++ .../java/hous/server/domain/room/Room.java | 7 ++++++- .../hous/server/service/todo/TodoService.java | 14 +++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 98c808d6..bc0fcaba 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -81,4 +81,24 @@ public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수 todoService.updateTodo(todoId, request); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] todo 전체 페이지 - todo 를 삭제합니다.", + notes = "todo 삭제를 요청합니다.\n" + + "성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @DeleteMapping("/todo/{todoId}") + public ResponseEntity deleteTodo(@ApiParam(name = "todoId", value = "삭제할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId) { + todoService.deleteTodo(todoId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index 223597c4..ef5f4617 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -75,7 +75,7 @@ public void addParticipate(Participate participate) { this.participates.add(participate); this.participantsCnt += 1; } - + public void addRule(Rule rule) { this.rules.add(rule); this.rulesCnt += 1; @@ -85,4 +85,9 @@ public void addTodo(Todo todo) { this.todos.add(todo); this.todosCnt += 1; } + + public void deleteTodo(Todo todo) { + this.todos.remove(todo); + this.todosCnt -= 1; + } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index f3875bbc..5d1c9c88 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -4,6 +4,7 @@ import hous.server.domain.todo.Redo; import hous.server.domain.todo.Take; import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.todo.repository.RedoRepository; import hous.server.domain.todo.repository.TakeRepository; import hous.server.domain.todo.repository.TodoRepository; @@ -31,6 +32,7 @@ public class TodoService { private final TodoRepository todoRepository; private final TakeRepository takeRepository; private final RedoRepository redoRepository; + private final DoneRepository doneRepository; public void createTodo(UpdateTodoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -67,4 +69,16 @@ public void updateTodo(Long todoId, UpdateTodoRequestDto request) { }); todo.updateTodo(request.getName(), request.isPushNotification(), takes); } + + public void deleteTodo(Long todoId) { + Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); + Room room = todo.getRoom(); + todo.getTakes().forEach(take -> { + redoRepository.deleteAll(take.getRedos()); + takeRepository.delete(take); + }); + doneRepository.deleteAll(todo.getDones()); + room.deleteTodo(todo); + todoRepository.delete(todo); + } } From 7a2db3bc1698c5fcbdcb6d322b8575b51d45ddfa Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 20:21:03 +0900 Subject: [PATCH 059/301] =?UTF-8?q?#32=20[rename]=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/todo/repository/DoneRepositoryCustom.java | 2 +- .../server/domain/todo/repository/DoneRepositoryImpl.java | 4 ++-- .../java/hous/server/service/todo/TodoRetrieveService.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java index c7bf26b7..514a81eb 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java @@ -8,7 +8,7 @@ public interface DoneRepositoryCustom { - boolean findTodayMyTodoCheckStatus(LocalDate now, Onboarding me, Todo todo); + boolean findTodayTodoCheckStatus(LocalDate now, Onboarding onboarding, Todo todo); OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo); } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index 3b04f351..46e62b29 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -20,10 +20,10 @@ public class DoneRepositoryImpl implements DoneRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public boolean findTodayMyTodoCheckStatus(LocalDate now, Onboarding me, Todo todo) { + public boolean findTodayTodoCheckStatus(LocalDate now, Onboarding onboarding, Todo todo) { Done lastDone = queryFactory.selectFrom(done) .where( - done.onboarding.eq(me), + done.onboarding.eq(onboarding), done.todo.eq(todo) ) .orderBy(done.createdAt.desc()) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index f04b37ce..d42c568e 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -54,7 +54,7 @@ public TodoMainResponse getTodoMain(Long userId) { .map(todo -> MyTodoInfo.of( todo.getId(), todo.getName(), - doneRepository.findTodayMyTodoCheckStatus(now, user.getOnboarding(), todo))) + doneRepository.findTodayTodoCheckStatus(now, user.getOnboarding(), todo))) .collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) From b6de23ab8f393f73b1deaee69723572d0c2e89b7 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 20:27:18 +0900 Subject: [PATCH 060/301] =?UTF-8?q?#32=20[refactor]=20=EC=98=A4=EB=8A=98?= =?UTF-8?q?=20=EB=82=A0=EC=A7=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/common/util/DateUtils.java | 5 +++++ .../todo/repository/DoneRepositoryCustom.java | 4 ++-- .../domain/todo/repository/DoneRepositoryImpl.java | 8 ++++---- .../server/service/todo/TodoRetrieveService.java | 14 +++++++------- .../hous/server/service/todo/TodoServiceUtils.java | 8 ++++---- .../todo/dto/response/TodoMainResponse.java | 6 +++--- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index 2ff53afa..369af11b 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -5,11 +5,16 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class DateUtils { + public static LocalDate today() { + return LocalDate.now(ZoneId.of("Asia/Seoul")); + } + public static String nowMonthAndDay(LocalDate now) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd"); return now.format(formatter); diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java index 514a81eb..0cd16fcd 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java @@ -8,7 +8,7 @@ public interface DoneRepositoryCustom { - boolean findTodayTodoCheckStatus(LocalDate now, Onboarding onboarding, Todo todo); + boolean findTodayTodoCheckStatus(LocalDate today, Onboarding onboarding, Todo todo); - OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo); + OurTodoStatus findTodayOurTodoStatus(LocalDate today, Todo todo); } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index 46e62b29..817f27a3 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -20,7 +20,7 @@ public class DoneRepositoryImpl implements DoneRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public boolean findTodayTodoCheckStatus(LocalDate now, Onboarding onboarding, Todo todo) { + public boolean findTodayTodoCheckStatus(LocalDate today, Onboarding onboarding, Todo todo) { Done lastDone = queryFactory.selectFrom(done) .where( done.onboarding.eq(onboarding), @@ -29,11 +29,11 @@ public boolean findTodayTodoCheckStatus(LocalDate now, Onboarding onboarding, To .orderBy(done.createdAt.desc()) .fetchFirst(); if (lastDone == null) return false; - return DateUtils.isSameDate(lastDone.getCreatedAt(), now); + return DateUtils.isSameDate(lastDone.getCreatedAt(), today); } @Override - public OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo) { + public OurTodoStatus findTodayOurTodoStatus(LocalDate today, Todo todo) { List takes = todo.getTakes(); int doneCnt = (int) takes.stream() .map(take -> queryFactory.selectFrom(done) @@ -43,7 +43,7 @@ public OurTodoStatus findTodayOurTodoStatus(LocalDate now, Todo todo) { ) .orderBy(done.createdAt.desc()) .fetchFirst()) - .filter(lastDone -> lastDone != null && DateUtils.isSameDate(lastDone.getCreatedAt(), now)) + .filter(lastDone -> lastDone != null && DateUtils.isSameDate(lastDone.getCreatedAt(), today)) .count(); if (doneCnt == 0) return OurTodoStatus.EMPTY; else if (doneCnt == takes.size()) return OurTodoStatus.FULL_CHECK; diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index d42c568e..f86f87b7 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -1,5 +1,6 @@ package hous.server.service.todo; +import hous.server.common.util.DateUtils; import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; @@ -17,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; -import java.time.ZoneId; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -45,27 +45,27 @@ public UserPersonalityInfoResponse getUsersInfo(Long userId) { public TodoMainResponse getTodoMain(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - LocalDate now = LocalDate.now(ZoneId.of("Asia/Seoul")); + LocalDate today = DateUtils.today(); List todos = room.getTodos(); - List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(now, todos); - List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(now, user.getOnboarding(), todos); + List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(today, todos); + List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(today, user.getOnboarding(), todos); List todayMyTodos = todayMyTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> MyTodoInfo.of( todo.getId(), todo.getName(), - doneRepository.findTodayTodoCheckStatus(now, user.getOnboarding(), todo))) + doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))) .collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> OurTodoInfo.of( todo.getName(), - doneRepository.findTodayOurTodoStatus(now, todo), + doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() .map(take -> take.getOnboarding().getNickname()) .collect(Collectors.toList()))) .collect(Collectors.toList()); - return TodoMainResponse.of(now, todayMyTodos, todayOurTodos); + return TodoMainResponse.of(today, todayMyTodos, todayOurTodos); } public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 26b4c518..a77bf6d6 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -47,12 +47,12 @@ public static List toUserPersonalityInfoList(Todo todo) { .collect(Collectors.toList()); } - public static List filterTodayOurTodos(LocalDate now, List todos) { + public static List filterTodayOurTodos(LocalDate today, List todos) { List todayOurTodosList = new ArrayList<>(); todos.forEach(todo -> { todo.getTakes().forEach(take -> { take.getRedos().forEach(redo -> { - if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(now))) { + if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(today))) { todayOurTodosList.add(todo); } }); @@ -61,9 +61,9 @@ public static List filterTodayOurTodos(LocalDate now, List todos) { return todayOurTodosList; } - public static List filterTodayMyTodos(LocalDate now, Onboarding me, List todos) { + public static List filterTodayMyTodos(LocalDate today, Onboarding me, List todos) { List todayMyTodosList = new ArrayList<>(); - List todayOurTodosList = filterTodayOurTodos(now, todos); + List todayOurTodosList = filterTodayOurTodos(today, todos); todayOurTodosList.forEach(todo -> { todo.getTakes().forEach(take -> { if (take.getOnboarding().getId().equals(me.getId())) { diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java index 237f77d5..4f591aeb 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java @@ -23,11 +23,11 @@ public class TodoMainResponse { private List myTodos; private List ourTodos; - public static TodoMainResponse of(LocalDate now, List myTodos, List ourTodos) { + public static TodoMainResponse of(LocalDate today, List myTodos, List ourTodos) { int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); return TodoMainResponse.builder() - .date(DateUtils.nowMonthAndDay(now)) - .dayOfWeek(DateUtils.nowDayOfWeek(now)) + .date(DateUtils.nowMonthAndDay(today)) + .dayOfWeek(DateUtils.nowDayOfWeek(today)) .progress(MathUtils.percent(doneOurTodosCnt, ourTodos.size())) .myTodosCnt(myTodos.size()) .ourTodosCnt(ourTodos.size()) From 55e16e05caf87926365a98cc2d3485303a5fa9a1 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 31 Aug 2022 21:04:34 +0900 Subject: [PATCH 061/301] =?UTF-8?q?#32=20[feat]=20todo=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../controller/todo/TodoController.java | 33 +++++++++++++++++++ .../java/hous/server/domain/todo/Done.java | 13 ++++++-- .../java/hous/server/domain/todo/Todo.java | 8 +++++ .../todo/repository/DoneRepositoryCustom.java | 3 ++ .../todo/repository/DoneRepositoryImpl.java | 13 ++++++++ .../hous/server/service/todo/TodoService.java | 20 +++++++++++ .../server/service/todo/TodoServiceUtils.java | 11 +++++-- .../todo/dto/request/CheckTodoRequestDto.java | 19 +++++++++++ .../resources/messages/validation.properties | 1 + 10 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 2447137a..0a93a89f 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -19,6 +19,7 @@ public enum ErrorCode { VALIDATION_WRONG_TYPE_EXCEPTION(BAD_REQUEST, "잘못된 타입이 입력되었습니다."), VALIDATION_SOCIAL_TYPE_EXCEPTION(BAD_REQUEST, "잘못된 소셜 프로바이더 입니다."), VALIDATION_SORT_TYPE_EXCEPTION(BAD_REQUEST, "허용하지 않는 정렬기준을 입력했습니다."), + VALIDATION_TODO_STATUS_EXCEPTION(BAD_REQUEST, "잘못된 상태로 요청했습니다."), /** * 401 UnAuthorized diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index bc0fcaba..ada16d6d 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -5,6 +5,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; +import hous.server.service.todo.dto.request.CheckTodoRequestDto; import hous.server.service.todo.dto.request.UpdateTodoRequestDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; @@ -82,6 +83,38 @@ public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수 return SuccessResponse.NO_CONTENT; } + @ApiOperation( + value = "[인증] todo 메인 페이지 - todo 를 체크합니다.", + notes = "체크 요청 (status = true), 해제 요청 (status = false) 로 todo 체크를 요청합니다.\n" + + "요청한 status 가 현재 서버의 status 인 경우, 400 에러 (잘못된 상태로 요청했습니다.) 를 전달합니다. \n" + + "성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. 요청할 체크 상태를 입력해주세요.\n" + + "2. 잘못된 상태로 요청했습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 todo 입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping("/todo/{todoId}/check") + public ResponseEntity checkTodo(@ApiParam(name = "todoId", value = "체크할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @Valid @RequestBody CheckTodoRequestDto request, + @ApiIgnore @UserId Long userId) { + todoService.checkTodo(todoId, request, userId); + return SuccessResponse.NO_CONTENT; + } + @ApiOperation( value = "[인증] todo 전체 페이지 - todo 를 삭제합니다.", notes = "todo 삭제를 요청합니다.\n" + diff --git a/src/main/java/hous/server/domain/todo/Done.java b/src/main/java/hous/server/domain/todo/Done.java index 48893d3d..187db42d 100644 --- a/src/main/java/hous/server/domain/todo/Done.java +++ b/src/main/java/hous/server/domain/todo/Done.java @@ -2,15 +2,15 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder(access = AccessLevel.PRIVATE) public class Done extends AuditingTimeEntity { @Id @@ -24,4 +24,11 @@ public class Done extends AuditingTimeEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "todo_id") private Todo todo; + + public static Done newInstance(Onboarding onboarding, Todo todo) { + return Done.builder() + .onboarding(onboarding) + .todo(todo) + .build(); + } } diff --git a/src/main/java/hous/server/domain/todo/Todo.java b/src/main/java/hous/server/domain/todo/Todo.java index e762e4ec..04758ce0 100644 --- a/src/main/java/hous/server/domain/todo/Todo.java +++ b/src/main/java/hous/server/domain/todo/Todo.java @@ -61,4 +61,12 @@ public void updateTodo(String name, boolean isPushNotification, List takes public void addTake(Take take) { this.takes.add(take); } + + public void addDone(Done done) { + this.dones.add(done); + } + + public void deleteDone(Done done) { + this.dones.remove(done); + } } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java index 0cd16fcd..c492f68a 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java @@ -1,5 +1,6 @@ package hous.server.domain.todo.repository; +import hous.server.domain.todo.Done; import hous.server.domain.todo.OurTodoStatus; import hous.server.domain.todo.Todo; import hous.server.domain.user.Onboarding; @@ -11,4 +12,6 @@ public interface DoneRepositoryCustom { boolean findTodayTodoCheckStatus(LocalDate today, Onboarding onboarding, Todo todo); OurTodoStatus findTodayOurTodoStatus(LocalDate today, Todo todo); + + Done findTodayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboarding, Todo todo); } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index 817f27a3..7205035c 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -49,4 +49,17 @@ public OurTodoStatus findTodayOurTodoStatus(LocalDate today, Todo todo) { else if (doneCnt == takes.size()) return OurTodoStatus.FULL_CHECK; else return OurTodoStatus.FULL; } + + @Override + public Done findTodayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboarding, Todo todo) { + Done lastDone = queryFactory.selectFrom(done) + .where( + done.onboarding.eq(onboarding), + done.todo.eq(todo) + ) + .orderBy(done.createdAt.desc()) + .fetchFirst(); + if (DateUtils.isSameDate(lastDone.getCreatedAt(), today)) return lastDone; + return null; + } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 5d1c9c88..2c44ada1 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -1,6 +1,8 @@ package hous.server.service.todo; +import hous.server.common.util.DateUtils; import hous.server.domain.room.Room; +import hous.server.domain.todo.Done; import hous.server.domain.todo.Redo; import hous.server.domain.todo.Take; import hous.server.domain.todo.Todo; @@ -13,6 +15,7 @@ import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; +import hous.server.service.todo.dto.request.CheckTodoRequestDto; import hous.server.service.todo.dto.request.UpdateTodoRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -70,6 +73,23 @@ public void updateTodo(Long todoId, UpdateTodoRequestDto request) { todo.updateTodo(request.getName(), request.isPushNotification(), takes); } + public void checkTodo(Long todoId, CheckTodoRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); + Onboarding onboarding = user.getOnboarding(); + TodoServiceUtils.validateTodoStatus(doneRepository, request.isStatus(), onboarding, todo); + if (request.isStatus()) { + Done done = doneRepository.save(Done.newInstance(onboarding, todo)); + todo.addDone(done); + } else { + Done done = doneRepository.findTodayDoneByOnboardingAndTodo(DateUtils.today(), onboarding, todo); + if (done != null) { + todo.deleteDone(done); + doneRepository.delete(done); + } + } + } + public void deleteTodo(Long todoId) { Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); Room room = todo.getRoom(); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index a77bf6d6..9134a490 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -2,9 +2,11 @@ import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; +import hous.server.common.exception.ValidationException; import hous.server.common.util.DateUtils; import hous.server.domain.room.Room; import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; import hous.server.service.todo.dto.response.UserPersonalityInfo; @@ -17,8 +19,7 @@ import java.util.List; import java.util.stream.Collectors; -import static hous.server.common.exception.ErrorCode.FORBIDDEN_TODO_COUNT_EXCEPTION; -import static hous.server.common.exception.ErrorCode.NOT_FOUND_TODO_EXCEPTION; +import static hous.server.common.exception.ErrorCode.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class TodoServiceUtils { @@ -37,6 +38,12 @@ public static void validateTodoCounts(Room room) { } } + public static void validateTodoStatus(DoneRepository doneRepository, boolean status, Onboarding onboarding, Todo todo) { + if (status == doneRepository.findTodayTodoCheckStatus(DateUtils.today(), onboarding, todo)) { + throw new ValidationException(String.format("(%s) 유저의 todo (%s) 상태는 이미 (%s) 입니다.", onboarding.getId(), todo.getId(), status), VALIDATION_TODO_STATUS_EXCEPTION); + } + } + public static List toUserPersonalityInfoList(Todo todo) { return todo.getTakes().stream() .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getCreatedAt())) diff --git a/src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java b/src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java new file mode 100644 index 00000000..29e77221 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java @@ -0,0 +1,19 @@ +package hous.server.service.todo.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CheckTodoRequestDto { + + @ApiModelProperty(value = "요청할 체크 상태", example = "true") + @NotNull(message = "{todo.status.notNull}") + private boolean status; +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 5b5081d3..f4bee7f7 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -17,5 +17,6 @@ todo.name.notBlank=todo \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.name.max=todo \uC774\uB984\uC744 15 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From eb23cc05116ee811c189520d335c95086d3fb3c4 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 1 Sep 2022 12:19:45 +0900 Subject: [PATCH 062/301] =?UTF-8?q?#22=20[feat]=20rule=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EC=88=98=EC=A0=95=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../controller/rule/RuleController.java | 38 ++++++++++++++++++- .../java/hous/server/domain/rule/Rule.java | 5 +++ .../hous/server/service/rule/RuleService.java | 11 ++++++ .../server/service/rule/RuleServiceUtils.java | 13 +++++-- .../request/UpdateSortByRuleRequestDto.java | 20 ++++++++++ .../resources/messages/validation.properties | 2 + 7 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 0a93a89f..3d3032c1 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -36,6 +36,7 @@ public enum ErrorCode { FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), + FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule의 개수와 방의 rule의 수가 맞지 않습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index dd5575dd..fba5b4d5 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -7,6 +7,7 @@ import hous.server.service.rule.RuleService; import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; +import hous.server.service.rule.dto.request.UpdateSortByRuleRequestDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -57,7 +58,7 @@ public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDt notes = "성공시 status code = 204, 빈 response body를 보냅니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = "규칙 생성을 성공입니다."), + @ApiResponse(code = 204, message = ""), @ApiResponse( code = 400, message = "1. 규칙 내용을 입력해주세요. (name)\n" @@ -75,11 +76,44 @@ public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDt @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/rule/{ruleId}") - public ResponseEntity UpdateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") + public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") @PathVariable Long ruleId, @Valid @RequestBody UpdateRuleRequestDto request, @ApiIgnore @UserId Long userId) { ruleService.updateRule(request, ruleId, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 규칙 페이지 - 규칙 여러 개의 정렬을 수정합니다.", + notes = "성공시 status code = 204, 빈 response body를 보냅니다.\n" + + "순서를 변경할 규칙의 id를 정렬 순서에 따라 resquest dto에 리스트 형태로 담아주세요." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. 크기가 1에서 2147483647 사이여야 합니다 (updateRules)\n" + + "2. 규칙 id를 입력해주세요. (id)\n" + + "3. 규칙 변경 위치를 입력해주세요 (index)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 방입니다.\n" + + "3. 존재하지 않는 규칙입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/rules") + public ResponseEntity updateSortByRule(@Valid @RequestBody UpdateSortByRuleRequestDto request, + @ApiIgnore @UserId Long userId) { + ruleService.updateSortByRule(request, userId); + return SuccessResponse.NO_CONTENT; + } + + } diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index d5fd4bbe..eb0bdc7e 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -39,4 +39,9 @@ public static Rule newInstance(Room room, String name, int idx) { public void updateRuleName(UpdateRuleRequestDto request) { this.name = request.getName(); } + + public void setRule(int ruleIdx) { + this.idx = ruleIdx; + } + } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index de2db4db..2fc0643d 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -8,6 +8,7 @@ import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; +import hous.server.service.rule.dto.request.UpdateSortByRuleRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -37,4 +38,14 @@ public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { rule.updateRuleName(request); } + public void updateSortByRule(UpdateSortByRuleRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + RuleServiceUtils.validateReqeustRuleCounts(room, request.getUpdateRuleIds().size()); + for (int idx = 0; idx < request.getUpdateRuleIds().size(); idx++) { + Long ruleId = request.getUpdateRuleIds().get(idx); + Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, ruleId, room); + rule.setRule(idx); + } + } } diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index f2c72f4b..1944c347 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -9,8 +9,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static hous.server.common.exception.ErrorCode.FORBIDDEN_RULE_COUNT_EXCEPTION; -import static hous.server.common.exception.ErrorCode.NOT_FOUND_RULE_EXCEPTION; +import static hous.server.common.exception.ErrorCode.*; @RequiredArgsConstructor @Service @@ -19,7 +18,7 @@ public class RuleServiceUtils { public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Room room) { Rule rule = ruleRepository.findLastRuleByRoom(room); if (rule == null) { - return 0; + return -1; } return rule.getIdx(); } @@ -37,4 +36,12 @@ public static Rule findRuleByIdAndRoom(RuleRepository ruleRepository, Long ruleI } return rule; } + + public static void validateReqeustRuleCounts(Room room, int requstRuleCounts) { + if (room.getRulesCnt() != requstRuleCounts) { + throw new NotFoundException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requstRuleCounts), + FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION); + } + } + } diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java new file mode 100644 index 00000000..1e4c3772 --- /dev/null +++ b/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java @@ -0,0 +1,20 @@ +package hous.server.service.rule.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import javax.validation.constraints.Size; +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateSortByRuleRequestDto { + + @ApiModelProperty(value = "규칙 id 배열", example = "[12, 13, 14, ...]") + @Size(min = 1) + List updateRuleIds; +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index f4bee7f7..044ff16e 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -20,3 +20,5 @@ todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uB todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +rule.id.notNull=\uADDC\uCE59 id\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +rule.index.notNull=\uADDC\uCE59 \uBCC0\uACBD \uC704\uCE58\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 639724931555d36c8194563df1d2f3d4a19eeb9f Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 1 Sep 2022 12:27:22 +0900 Subject: [PATCH 063/301] =?UTF-8?q?#32=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/todo/TodoController.java | 6 +++--- .../server/domain/todo/repository/DoneRepositoryImpl.java | 3 +-- src/main/java/hous/server/service/todo/TodoService.java | 6 +++--- .../{UpdateTodoRequestDto.java => TodoInfoRequestDto.java} | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) rename src/main/java/hous/server/service/todo/dto/request/{UpdateTodoRequestDto.java => TodoInfoRequestDto.java} (97%) diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index ada16d6d..3535e152 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -6,7 +6,7 @@ import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; import hous.server.service.todo.dto.request.CheckTodoRequestDto; -import hous.server.service.todo.dto.request.UpdateTodoRequestDto; +import hous.server.service.todo.dto.request.TodoInfoRequestDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -50,7 +50,7 @@ public class TodoController { @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/todo") - public ResponseEntity createTodo(@Valid @RequestBody UpdateTodoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity createTodo(@Valid @RequestBody TodoInfoRequestDto request, @ApiIgnore @UserId Long userId) { todoService.createTodo(request, userId); return SuccessResponse.NO_CONTENT; } @@ -78,7 +78,7 @@ public ResponseEntity createTodo(@Valid @RequestBody UpdateTodoRequestDt @PutMapping("/todo/{todoId}") public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수정할 todo 의 id", required = true, example = "1") @PathVariable Long todoId, - @Valid @RequestBody UpdateTodoRequestDto request) { + @Valid @RequestBody TodoInfoRequestDto request) { todoService.updateTodo(todoId, request); return SuccessResponse.NO_CONTENT; } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index 7205035c..a3d4a0fc 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -59,7 +59,6 @@ public Done findTodayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboard ) .orderBy(done.createdAt.desc()) .fetchFirst(); - if (DateUtils.isSameDate(lastDone.getCreatedAt(), today)) return lastDone; - return null; + return DateUtils.isSameDate(lastDone.getCreatedAt(), today) ? lastDone : null; } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 2c44ada1..2e8d922a 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -16,7 +16,7 @@ import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.dto.request.CheckTodoRequestDto; -import hous.server.service.todo.dto.request.UpdateTodoRequestDto; +import hous.server.service.todo.dto.request.TodoInfoRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -37,7 +37,7 @@ public class TodoService { private final RedoRepository redoRepository; private final DoneRepository doneRepository; - public void createTodo(UpdateTodoRequestDto request, Long userId) { + public void createTodo(TodoInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); TodoServiceUtils.validateTodoCounts(room); @@ -54,7 +54,7 @@ public void createTodo(UpdateTodoRequestDto request, Long userId) { room.addTodo(todo); } - public void updateTodo(Long todoId, UpdateTodoRequestDto request) { + public void updateTodo(Long todoId, TodoInfoRequestDto request) { Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); todo.getTakes().forEach(take -> { redoRepository.deleteAll(take.getRedos()); diff --git a/src/main/java/hous/server/service/todo/dto/request/UpdateTodoRequestDto.java b/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java similarity index 97% rename from src/main/java/hous/server/service/todo/dto/request/UpdateTodoRequestDto.java rename to src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java index b65bc7e9..8ee9ebd9 100644 --- a/src/main/java/hous/server/service/todo/dto/request/UpdateTodoRequestDto.java +++ b/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java @@ -17,7 +17,7 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateTodoRequestDto { +public class TodoInfoRequestDto { @ApiModelProperty(value = "todo 이름", example = "청소기 돌리기") @NotBlank(message = "{todo.name.notBlank}") From 828d09e41c24840440b0f1d8261f6251e5dc526d Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 1 Sep 2022 12:49:26 +0900 Subject: [PATCH 064/301] =?UTF-8?q?#22=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/exception/ErrorCode.java | 2 +- .../java/hous/server/controller/rule/RuleController.java | 8 +++----- src/main/java/hous/server/domain/rule/Rule.java | 2 +- src/main/java/hous/server/service/rule/RuleService.java | 2 +- .../java/hous/server/service/rule/RuleServiceUtils.java | 2 +- .../rule/dto/request/UpdateSortByRuleRequestDto.java | 2 +- src/main/resources/messages/validation.properties | 3 +-- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 3d3032c1..89f1d39c 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -36,7 +36,7 @@ public enum ErrorCode { FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), - FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule의 개수와 방의 rule의 수가 맞지 않습니다."), + FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index fba5b4d5..e82cc934 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -93,9 +93,7 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 @ApiResponse(code = 204, message = ""), @ApiResponse( code = 400, - message = "1. 크기가 1에서 2147483647 사이여야 합니다 (updateRules)\n" - + "2. 규칙 id를 입력해주세요. (id)\n" - + "3. 규칙 변경 위치를 입력해주세요 (index)", + message = "규칙 id 리스트는 방 내 모든 규칙 수와 같습니다. (updateRuleIds)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( @@ -109,8 +107,8 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/rules") - public ResponseEntity updateSortByRule(@Valid @RequestBody UpdateSortByRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity updateSortByRules(@Valid @RequestBody UpdateSortByRuleRequestDto request, + @ApiIgnore @UserId Long userId) { ruleService.updateSortByRule(request, userId); return SuccessResponse.NO_CONTENT; } diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index eb0bdc7e..694130d3 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -40,7 +40,7 @@ public void updateRuleName(UpdateRuleRequestDto request) { this.name = request.getName(); } - public void setRule(int ruleIdx) { + public void updateRuleIndex(int ruleIdx) { this.idx = ruleIdx; } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 2fc0643d..a4a81bc9 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -45,7 +45,7 @@ public void updateSortByRule(UpdateSortByRuleRequestDto request, Long userId) { for (int idx = 0; idx < request.getUpdateRuleIds().size(); idx++) { Long ruleId = request.getUpdateRuleIds().get(idx); Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, ruleId, room); - rule.setRule(idx); + rule.updateRuleIndex(idx); } } } diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index 1944c347..afd53726 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -39,7 +39,7 @@ public static Rule findRuleByIdAndRoom(RuleRepository ruleRepository, Long ruleI public static void validateReqeustRuleCounts(Room room, int requstRuleCounts) { if (room.getRulesCnt() != requstRuleCounts) { - throw new NotFoundException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requstRuleCounts), + throw new ForbiddenException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requstRuleCounts), FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java index 1e4c3772..4aefb327 100644 --- a/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java @@ -15,6 +15,6 @@ public class UpdateSortByRuleRequestDto { @ApiModelProperty(value = "규칙 id 배열", example = "[12, 13, 14, ...]") - @Size(min = 1) + @Size(min = 1, message = "{rule.list.min}") List updateRuleIds; } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 044ff16e..826782bb 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -20,5 +20,4 @@ todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uB todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -rule.id.notNull=\uADDC\uCE59 id\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -rule.index.notNull=\uADDC\uCE59 \uBCC0\uACBD \uC704\uCE58\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +rule.list.min=\uADDC\uCE59 id \uB9AC\uC2A4\uD2B8\uB294 \uBC29 \uB0B4 \uBAA8\uB4E0 \uADDC\uCE59 \uC218\uC640 \uAC19\uC2B5\uB2C8\uB2E4. From 76690a258134b7c780183ccc8170fa58c17ed353 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 1 Sep 2022 13:33:33 +0900 Subject: [PATCH 065/301] =?UTF-8?q?#36=20[fix]=20rules=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20index=20=EC=95=88=EB=B3=B4=EC=9D=B4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/rule/dto/response/RuleInfoResponse.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java index ff35cd8c..7a41c498 100644 --- a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java @@ -16,14 +16,11 @@ public class RuleInfoResponse { private Long id; - private int index; - private String name; public static RuleInfoResponse of(Rule rule) { return RuleInfoResponse.builder() .id(rule.getId()) - .index(rule.getIdx()) .name(rule.getName()) .build(); } From 265a93abe96cc571c01070dcfe376fe167f8d02a Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 1 Sep 2022 13:34:20 +0900 Subject: [PATCH 066/301] =?UTF-8?q?#36=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=88=98=EC=A0=95/=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EB=90=98=EB=8A=94=20request=20dto=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC=EC=9D=84=20=EC=9C=84=ED=95=B4=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EB=B0=8F=20=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ateSortByRuleRequestDto.java => ModifyRuleReqeustDto.java} | 4 ++-- src/main/resources/messages/validation.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/hous/server/service/rule/dto/request/{UpdateSortByRuleRequestDto.java => ModifyRuleReqeustDto.java} (86%) diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java similarity index 86% rename from src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java rename to src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java index 4aefb327..b7fad506 100644 --- a/src/main/java/hous/server/service/rule/dto/request/UpdateSortByRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java @@ -12,9 +12,9 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateSortByRuleRequestDto { +public class ModifyRuleReqeustDto { @ApiModelProperty(value = "규칙 id 배열", example = "[12, 13, 14, ...]") @Size(min = 1, message = "{rule.list.min}") - List updateRuleIds; + List rulesIdList; } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 826782bb..0a5256e2 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -20,4 +20,4 @@ todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uB todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -rule.list.min=\uADDC\uCE59 id \uB9AC\uC2A4\uD2B8\uB294 \uBC29 \uB0B4 \uBAA8\uB4E0 \uADDC\uCE59 \uC218\uC640 \uAC19\uC2B5\uB2C8\uB2E4. +rule.list.min=\uADDC\uCE59 id \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uAC12\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. From 1022ac601cd668f0aa69f44851c2ee8bcfe555fd Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 1 Sep 2022 13:35:31 +0900 Subject: [PATCH 067/301] =?UTF-8?q?#36=20[feat]=20rule=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 2 +- .../controller/rule/RuleController.java | 37 ++++++++++++++++--- .../java/hous/server/domain/room/Room.java | 5 +++ .../hous/server/service/rule/RuleService.java | 21 ++++++++--- .../server/service/rule/RuleServiceUtils.java | 4 +- 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 89f1d39c..3d3032c1 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -36,7 +36,7 @@ public enum ErrorCode { FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), - FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), + FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule의 개수와 방의 rule의 수가 맞지 않습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index e82cc934..9d90c985 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -6,8 +6,8 @@ import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleService; import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; -import hous.server.service.rule.dto.request.UpdateSortByRuleRequestDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -87,13 +87,13 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 @ApiOperation( value = "[인증] 규칙 페이지 - 규칙 여러 개의 정렬을 수정합니다.", notes = "성공시 status code = 204, 빈 response body를 보냅니다.\n" + - "순서를 변경할 규칙의 id를 정렬 순서에 따라 resquest dto에 리스트 형태로 담아주세요." + "전체 규칙 id 리스트를 정렬 순서에 따라 resquest dto에 리스트 형태로 담아주세요." ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), @ApiResponse( code = 400, - message = "규칙 id 리스트는 방 내 모든 규칙 수와 같습니다. (updateRuleIds)", + message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( @@ -107,11 +107,38 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/rules") - public ResponseEntity updateSortByRules(@Valid @RequestBody UpdateSortByRuleRequestDto request, + public ResponseEntity updateSortByRules(@Valid @RequestBody ModifyRuleReqeustDto request, @ApiIgnore @UserId Long userId) { ruleService.updateSortByRule(request, userId); return SuccessResponse.NO_CONTENT; } - + @ApiOperation( + value = "[인증] 규칙 페이지 - 규칙 여러 개를 삭제합니다.", + notes = "성공시 status code = 204, 빈 response body를 보냅니다.\n" + + "삭제할 규칙의 id만 resquest dto에 리스트 형태로 담아주세요." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 방입니다.\n" + + "3. 존재하지 않는 규칙입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @DeleteMapping("/rules") + public ResponseEntity deleteRules(@Valid @RequestBody ModifyRuleReqeustDto request, + @ApiIgnore @UserId Long userId) { + ruleService.deleteRules(request, userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index ef5f4617..67d474a6 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -81,6 +81,11 @@ public void addRule(Rule rule) { this.rulesCnt += 1; } + public void deleteRule(Rule rule) { + this.rules.remove(rule); + this.rulesCnt -= 1; + } + public void addTodo(Todo todo) { this.todos.add(todo); this.todosCnt += 1; diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index a4a81bc9..6bc9b53f 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -7,8 +7,8 @@ import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; +import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; -import hous.server.service.rule.dto.request.UpdateSortByRuleRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -38,14 +38,25 @@ public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { rule.updateRuleName(request); } - public void updateSortByRule(UpdateSortByRuleRequestDto request, Long userId) { + public void updateSortByRule(ModifyRuleReqeustDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - RuleServiceUtils.validateReqeustRuleCounts(room, request.getUpdateRuleIds().size()); - for (int idx = 0; idx < request.getUpdateRuleIds().size(); idx++) { - Long ruleId = request.getUpdateRuleIds().get(idx); + RuleServiceUtils.validateRequestRuleCounts(room, request.getRulesIdList().size()); + for (int idx = 0; idx < request.getRulesIdList().size(); idx++) { + Long ruleId = request.getRulesIdList().get(idx); Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, ruleId, room); rule.updateRuleIndex(idx); } } + + public void deleteRules(ModifyRuleReqeustDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + request.getRulesIdList().forEach(ruleId -> { + Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, ruleId, room); + room.deleteRule(rule); + ruleRepository.delete(rule); + }); + + } } diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index afd53726..4aa8ed15 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -37,9 +37,9 @@ public static Rule findRuleByIdAndRoom(RuleRepository ruleRepository, Long ruleI return rule; } - public static void validateReqeustRuleCounts(Room room, int requstRuleCounts) { + public static void validateRequestRuleCounts(Room room, int requstRuleCounts) { if (room.getRulesCnt() != requstRuleCounts) { - throw new ForbiddenException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requstRuleCounts), + throw new NotFoundException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requstRuleCounts), FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION); } } From 4a80d2ac91133c656969876603ab55e67a08d8bc Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 1 Sep 2022 17:54:14 +0900 Subject: [PATCH 068/301] =?UTF-8?q?#36=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/common/exception/ErrorCode.java | 2 +- .../server/controller/rule/RuleController.java | 10 ++-------- .../server/service/rule/RuleServiceUtils.java | 15 ++++++--------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 3d3032c1..89f1d39c 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -36,7 +36,7 @@ public enum ErrorCode { FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), - FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule의 개수와 방의 rule의 수가 맞지 않습니다."), + FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 9d90c985..f225da19 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -91,10 +91,7 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), - @ApiResponse( - code = 400, - message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", - response = ErrorResponse.class), + @ApiResponse(code = 400, message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, @@ -120,10 +117,7 @@ public ResponseEntity updateSortByRules(@Valid @RequestBody ModifyRuleRe ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), - @ApiResponse( - code = 400, - message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", - response = ErrorResponse.class), + @ApiResponse(code = 400, message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index 4aa8ed15..eee1abe3 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -5,15 +5,12 @@ import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import static hous.server.common.exception.ErrorCode.*; -@RequiredArgsConstructor -@Service -@Transactional +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class RuleServiceUtils { public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Room room) { Rule rule = ruleRepository.findLastRuleByRoom(room); @@ -37,9 +34,9 @@ public static Rule findRuleByIdAndRoom(RuleRepository ruleRepository, Long ruleI return rule; } - public static void validateRequestRuleCounts(Room room, int requstRuleCounts) { - if (room.getRulesCnt() != requstRuleCounts) { - throw new NotFoundException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requstRuleCounts), + public static void validateRequestRuleCounts(Room room, int requestRuleCnt) { + if (room.getRulesCnt() != requestRuleCnt) { + throw new ForbiddenException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requestRuleCnt), FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION); } } From 282e287b36252b33bc058ba5b7485588ba6f5e3c Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 2 Sep 2022 18:37:59 +0900 Subject: [PATCH 069/301] =?UTF-8?q?#38=20[feat]=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=EB=B7=B0=EC=97=90=EC=84=9C=20=EB=82=98=EC=9D=98=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 + .../hous/server/common/util/MathUtils.java | 7 +++ .../user/UserRetrieveController.java | 18 ++++++ .../badge/repository/RepresentRepository.java | 7 +++ .../repository/RepresentRepositoryCustom.java | 9 +++ .../repository/RepresentRepositoryImpl.java | 22 +++++++ .../service/user/UserRetrieveService.java | 11 ++++ .../server/service/user/UserServiceUtils.java | 1 + .../user/dto/response/UserInfoResponse.java | 57 +++++++++++++++++++ 9 files changed, 135 insertions(+) create mode 100644 src/main/java/hous/server/domain/badge/repository/RepresentRepository.java create mode 100644 src/main/java/hous/server/domain/badge/repository/RepresentRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/badge/repository/RepresentRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 6fff89ad..e8439cbc 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -34,6 +34,9 @@ public enum SuccessCode { // rule GET_RULE_INFO_SUCCESS(OK, "규칙 조회 성공입니다."), + // profile + GET_PROFILE_INFO_SUCCESS(OK, "나의 프로필 정보 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/common/util/MathUtils.java b/src/main/java/hous/server/common/util/MathUtils.java index 09246b29..2bfa4c23 100644 --- a/src/main/java/hous/server/common/util/MathUtils.java +++ b/src/main/java/hous/server/common/util/MathUtils.java @@ -3,10 +3,17 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.time.LocalDate; + @NoArgsConstructor(access = AccessLevel.PRIVATE) public class MathUtils { public static int percent(int part, int total) { return (int) ((double) part / (double) total * 100); } + + public static int getAge(LocalDate date) { + LocalDate today = DateUtils.today(); + return today.getYear() - date.getYear() + 1; + } } diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index e1fdc370..1cb09296 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -7,6 +7,7 @@ import hous.server.config.resolver.UserId; import hous.server.service.user.UserRetrieveService; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; +import hous.server.service.user.dto.response.UserInfoResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -40,4 +41,21 @@ public class UserRetrieveController { public ResponseEntity checkMyOnboardingInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CHECK_ONBOARDING_SUCCESS, userRetrieveService.checkMyOnboardingInfo(userId)); } + + @ApiOperation( + value = "[인증] 마이 페이지(프로필 뷰) - 나의 프로필 정보를 확인합니다.", + notes = "성공 시, 생년월일 공개 여부(birthdayPublic) false 일 경우, 생년월일(birthday)은 null 입니다.\n" + + "사용자가 아직 입력하지 않은 데이터의 경우 null 이 전달됩니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "나의 프로필 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/user") + public ResponseEntity getUserInfo(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.CHECK_ONBOARDING_SUCCESS, userRetrieveService.getUserInfo(userId)); + } } diff --git a/src/main/java/hous/server/domain/badge/repository/RepresentRepository.java b/src/main/java/hous/server/domain/badge/repository/RepresentRepository.java new file mode 100644 index 00000000..74706f2e --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/RepresentRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.badge.repository; + +import hous.server.domain.badge.Represent; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RepresentRepository extends JpaRepository, RepresentRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/badge/repository/RepresentRepositoryCustom.java b/src/main/java/hous/server/domain/badge/repository/RepresentRepositoryCustom.java new file mode 100644 index 00000000..6fc2e25e --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/RepresentRepositoryCustom.java @@ -0,0 +1,9 @@ +package hous.server.domain.badge.repository; + +import hous.server.domain.badge.Represent; +import hous.server.domain.user.Onboarding; + +public interface RepresentRepositoryCustom { + Represent findRepresentByOnboarding(Onboarding onboarding); + +} diff --git a/src/main/java/hous/server/domain/badge/repository/RepresentRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/RepresentRepositoryImpl.java new file mode 100644 index 00000000..6cbadffa --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/RepresentRepositoryImpl.java @@ -0,0 +1,22 @@ +package hous.server.domain.badge.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.badge.Represent; +import hous.server.domain.user.Onboarding; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.badge.QRepresent.represent; + +@RequiredArgsConstructor +public class RepresentRepositoryImpl implements RepresentRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Represent findRepresentByOnboarding(Onboarding onboarding) { + return queryFactory + .selectFrom(represent) + .where(represent.onboarding.eq(onboarding)) + .fetchOne(); + } +} diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 968b731a..5ce56599 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -1,9 +1,12 @@ package hous.server.service.user; +import hous.server.domain.badge.Represent; +import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; +import hous.server.service.user.dto.response.UserInfoResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,6 +17,7 @@ public class UserRetrieveService { private final UserRepository userRepository; + private final RepresentRepository representRepository; public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -21,5 +25,12 @@ public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { return !onboarding.isChecked() ? CheckOnboardingInfoResponse.of(false) : CheckOnboardingInfoResponse.of(true); } + public UserInfoResponse getUserInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); + Represent represent = representRepository.findRepresentByOnboarding(onboarding); + return UserInfoResponse.of(onboarding, represent); + } + } diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 3565b897..69317f1e 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -31,4 +31,5 @@ public static User findUserById(UserRepository userRepository, Long userId) { } return user; } + } diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java new file mode 100644 index 00000000..04f5d1a5 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -0,0 +1,57 @@ +package hous.server.service.user.dto.response; + +import hous.server.common.util.MathUtils; +import hous.server.domain.badge.Represent; +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.TestScore; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class UserInfoResponse { + + private PersonalityColor personalityColor; + + private String nickname; + + private int age; + + private boolean birthdayPublic; + + private String birthday; + + private String mbti; + + private String job; + + private boolean isSmoke; + + private String introduction; + + private TestScore testScore; + + private String representBadge; + + + public static UserInfoResponse of(Onboarding onboarding, Represent represent) { + String representBadgeImageUrl = represent != null ? represent.getBadge().getImageUrl() : null; + return UserInfoResponse.builder() + .personalityColor(onboarding.getPersonality().getColor()) + .nickname(onboarding.getNickname()) + .birthdayPublic(onboarding.isPublic()) + .age(MathUtils.getAge(onboarding.getBirthday())) + .birthday(onboarding.isPublic() ? onboarding.getBirthday().toString() : null) + .mbti(onboarding.getMbti()) + .job(onboarding.getJob()) + .isSmoke(onboarding.isSmoke()) + .mbti(onboarding.getMbti()) + .introduction(onboarding.getIntroduction()) + .testScore(onboarding.getTestScore()) + .representBadge(representBadgeImageUrl) + .build(); + } +} From 1ab749800e37af32ccf445dde08342666bf20d75 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Fri, 2 Sep 2022 21:29:28 +0900 Subject: [PATCH 070/301] =?UTF-8?q?#39=20[fix]=20=EC=9A=94=EC=9D=BC=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C=20=EC=88=98=EC=A0=95=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20response=20dto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/todo/DayOfWeek.java | 48 +++++++++++++++---- .../dto/response/TodoSummaryInfoResponse.java | 5 +- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/main/java/hous/server/domain/todo/DayOfWeek.java b/src/main/java/hous/server/domain/todo/DayOfWeek.java index 3736af50..13ce4e6f 100644 --- a/src/main/java/hous/server/domain/todo/DayOfWeek.java +++ b/src/main/java/hous/server/domain/todo/DayOfWeek.java @@ -1,11 +1,43 @@ package hous.server.domain.todo; -public enum DayOfWeek { - MONDAY, - TUESDAY, - WEDNESDAY, - THURSDAY, - FRIDAY, - SATURDAY, - SUNDAY; +import hous.server.common.model.EnumModel; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Comparator; +import java.util.Set; +import java.util.stream.Collectors; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum DayOfWeek implements EnumModel { + MONDAY("월", 1), + TUESDAY("화", 2), + WEDNESDAY("수", 3), + THURSDAY("목", 4), + FRIDAY("금", 5), + SATURDAY("토", 6), + SUNDAY("일", 7); + + private final String value; + + private final int index; + + @Override + public String getKey() { + return name(); + } + + @Override + public String getValue() { + return value; + } + + public static String toString(Set dayOfWeekSet) { + return dayOfWeekSet.stream() + .sorted(Comparator.comparing(DayOfWeek::getIndex)) + .map(DayOfWeek::getValue) + .collect(Collectors.joining(", ")); + } } diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java index 2fd6dd60..650df605 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoSummaryInfoResponse.java @@ -5,7 +5,6 @@ import hous.server.domain.user.Onboarding; import lombok.*; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -19,7 +18,7 @@ public class TodoSummaryInfoResponse { private String name; private List selectedUsers; - private List dayOfWeeks; + private String dayOfWeeks; public static TodoSummaryInfoResponse of(Todo todo, List userPersonalityInfos, Onboarding me) { Set dayOfWeekSet = new HashSet<>(); @@ -27,7 +26,7 @@ public static TodoSummaryInfoResponse of(Todo todo, List us return TodoSummaryInfoResponse.builder() .name(todo.getName()) .selectedUsers(UserPersonalityInfo.sortMeFirst(userPersonalityInfos, me)) - .dayOfWeeks(new ArrayList<>(dayOfWeekSet)) + .dayOfWeeks(DayOfWeek.toString(dayOfWeekSet)) .build(); } } From cffce298a560143a4112d3406a5f3a520e4b2a42 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 2 Sep 2022 21:40:28 +0900 Subject: [PATCH 071/301] =?UTF-8?q?#38=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/common/util/DateUtils.java | 3 ++- .../service/todo/dto/response/TodoMainResponse.java | 2 +- .../service/user/dto/response/UserInfoResponse.java | 13 ++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index 369af11b..7b4ce355 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -15,7 +15,7 @@ public static LocalDate today() { return LocalDate.now(ZoneId.of("Asia/Seoul")); } - public static String nowMonthAndDay(LocalDate now) { + public static String parseMonthAndDay(LocalDate now) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd"); return now.format(formatter); } @@ -28,4 +28,5 @@ public static boolean isSameDate(LocalDateTime localDateTime, LocalDate localDat DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); return localDateTime.format(formatter).equals(localDate.format(formatter)); } + } diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java index 4f591aeb..c8bca349 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java @@ -26,7 +26,7 @@ public class TodoMainResponse { public static TodoMainResponse of(LocalDate today, List myTodos, List ourTodos) { int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); return TodoMainResponse.builder() - .date(DateUtils.nowMonthAndDay(today)) + .date(DateUtils.parseMonthAndDay(today)) .dayOfWeek(DateUtils.nowDayOfWeek(today)) .progress(MathUtils.percent(doneOurTodosCnt, ourTodos.size())) .myTodosCnt(myTodos.size()) diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index 04f5d1a5..b3830a0a 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -1,5 +1,6 @@ package hous.server.service.user.dto.response; +import hous.server.common.util.DateUtils; import hous.server.common.util.MathUtils; import hous.server.domain.badge.Represent; import hous.server.domain.personality.PersonalityColor; @@ -18,7 +19,7 @@ public class UserInfoResponse { private String nickname; - private int age; + private String age; private boolean birthdayPublic; @@ -36,22 +37,24 @@ public class UserInfoResponse { private String representBadge; + private String representBadgeImage; + public static UserInfoResponse of(Onboarding onboarding, Represent represent) { - String representBadgeImageUrl = represent != null ? represent.getBadge().getImageUrl() : null; return UserInfoResponse.builder() .personalityColor(onboarding.getPersonality().getColor()) .nickname(onboarding.getNickname()) .birthdayPublic(onboarding.isPublic()) - .age(MathUtils.getAge(onboarding.getBirthday())) - .birthday(onboarding.isPublic() ? onboarding.getBirthday().toString() : null) + .age(MathUtils.getAge(onboarding.getBirthday()) + "세") + .birthday(onboarding.isPublic() ? DateUtils.parseMonthAndDay(onboarding.getBirthday()) : null) .mbti(onboarding.getMbti()) .job(onboarding.getJob()) .isSmoke(onboarding.isSmoke()) .mbti(onboarding.getMbti()) .introduction(onboarding.getIntroduction()) .testScore(onboarding.getTestScore()) - .representBadge(representBadgeImageUrl) + .representBadge(represent != null ? represent.getBadge().getName() : null) + .representBadgeImage(represent != null ? represent.getBadge().getImageUrl() : null) .build(); } } From 4000c6419b08eaab68be131836b88cb030bdfa4e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 2 Sep 2022 21:40:50 +0900 Subject: [PATCH 072/301] =?UTF-8?q?#38=20[fix]=20deploy=20=EC=8B=9C=20slee?= =?UTF-8?q?p=20=EC=8B=9C=EA=B0=84=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 8e281805..dfe4c2e0 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -16,7 +16,7 @@ then else echo "> kill -15 $CURRENT_PID" kill -15 $CURRENT_PID - sleep 5 + sleep 15 fi DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME From db9a530ea931e78d5672c2fa2c46523f0cf4e116 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 2 Sep 2022 21:55:26 +0900 Subject: [PATCH 073/301] =?UTF-8?q?#38=20[fix]=20DateUtils=EC=97=90=20mm.d?= =?UTF-8?q?d=20=ED=98=95=ED=83=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=ED=95=A8=EC=88=98=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/DateUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index 7b4ce355..f650ad88 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -15,9 +15,9 @@ public static LocalDate today() { return LocalDate.now(ZoneId.of("Asia/Seoul")); } - public static String parseMonthAndDay(LocalDate now) { + public static String parseMonthAndDay(LocalDate date) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd"); - return now.format(formatter); + return date.format(formatter); } public static String nowDayOfWeek(LocalDate now) { From 8075de37868993716e8ac78fdde137afdbf5e333 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 2 Sep 2022 22:13:16 +0900 Subject: [PATCH 074/301] =?UTF-8?q?#38=20[fix]=20deploy=20=EC=8B=9C=20SIGT?= =?UTF-8?q?ERM=20=EC=8B=A0=ED=98=B8=20=EB=B0=9B=EC=9D=84=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0,=20=EC=8B=A4=ED=96=89=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index dfe4c2e0..d25c4283 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -10,16 +10,15 @@ cp $BUILD_JAR $DEPLOY_PATH echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ubuntu/hous/deploy.log CURRENT_PID=$(pgrep -f $JAR_NAME) +DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME + if [ -z $CURRENT_PID ] then echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ubuntu/hous/deploy.log + echo "> DEPLOY_JAR 배포" >> /home/ubuntu/hous/deploy.log + nohup java -jar $DEPLOY_JAR >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & else + trap echo "> DEPLOY_JAR 배포" >> /home/ubuntu/hous/deploy.log | nohup java -jar $DEPLOY_JAR >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & SIGTERM echo "> kill -15 $CURRENT_PID" kill -15 $CURRENT_PID - sleep 15 fi - -DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME - -echo "> DEPLOY_JAR 배포" >> /home/ubuntu/hous/deploy.log -nohup java -jar $DEPLOY_JAR >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & From 17118a94b0103df83da78bb05bda28fd8833232d Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 3 Sep 2022 23:25:09 +0900 Subject: [PATCH 075/301] =?UTF-8?q?#34=20[feat]=20=EB=B0=A9=20=EB=B3=84?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RoomController.java | 32 +++++++++++++++++-- .../java/hous/server/domain/room/Room.java | 4 +++ .../hous/server/service/room/RoomService.java | 10 ++++-- ...estDto.java => SetRoomNameRequestDto.java} | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) rename src/main/java/hous/server/service/room/dto/request/{CreateRoomRequestDto.java => SetRoomNameRequestDto.java} (93%) diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index ccb485a5..a13100eb 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -6,7 +6,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.room.RoomService; -import hous.server.service.room.dto.request.CreateRoomRequestDto; +import hous.server.service.room.dto.request.SetRoomNameRequestDto; import hous.server.service.room.dto.response.RoomInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; @@ -45,7 +45,7 @@ public class RoomController { @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/room") - public ResponseEntity createRoom(@Valid @RequestBody CreateRoomRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity createRoom(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CREATE_ROOM_SUCCESS, roomService.createRoom(request, userId)); } @@ -73,4 +73,32 @@ public ResponseEntity joinRoom(@ApiParam(name = "roomId", valu @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.JOIN_ROOM_SUCCESS, roomService.joinRoom(roomId, userId)); } + + @ApiOperation( + value = "[인증] Hous- 페이지 - 방 별명을 수정합니다.", + notes = "방 별명을 8글자 이내로 설정하여 수정을 요청합니다.\n" + + "성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. 방 이름을 입력해주세요. (name)\n" + + "2. 방 이름을 8 글자 이내로 입력해주세요. (name)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/room/name") + public ResponseEntity updateRoomName(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { + roomService.updateRoomName(request, userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index 67d474a6..65b98f36 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -71,6 +71,10 @@ public static Room newInstance(Onboarding owner, String name, String code) { .build(); } + public void updateRoomName(String name) { + this.name = name; + } + public void addParticipate(Participate participate) { this.participates.add(participate); this.participantsCnt += 1; diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index a67fd94d..d4ecda5d 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -7,7 +7,7 @@ import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; -import hous.server.service.room.dto.request.CreateRoomRequestDto; +import hous.server.service.room.dto.request.SetRoomNameRequestDto; import hous.server.service.room.dto.response.RoomInfoResponse; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -23,7 +23,7 @@ public class RoomService { private final RoomRepository roomRepository; private final ParticipateRepository participateRepository; - public RoomInfoResponse createRoom(CreateRoomRequestDto request, Long userId) { + public RoomInfoResponse createRoom(SetRoomNameRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); @@ -45,4 +45,10 @@ public RoomInfoResponse joinRoom(Long roomId, Long userId) { room.addParticipate(participate); return RoomInfoResponse.of(room); } + + public void updateRoomName(SetRoomNameRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + room.updateRoomName(request.getName()); + } } diff --git a/src/main/java/hous/server/service/room/dto/request/CreateRoomRequestDto.java b/src/main/java/hous/server/service/room/dto/request/SetRoomNameRequestDto.java similarity index 93% rename from src/main/java/hous/server/service/room/dto/request/CreateRoomRequestDto.java rename to src/main/java/hous/server/service/room/dto/request/SetRoomNameRequestDto.java index 34c8a37b..35d5163f 100644 --- a/src/main/java/hous/server/service/room/dto/request/CreateRoomRequestDto.java +++ b/src/main/java/hous/server/service/room/dto/request/SetRoomNameRequestDto.java @@ -12,7 +12,7 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CreateRoomRequestDto { +public class SetRoomNameRequestDto { @ApiModelProperty(value = "방 이름", example = "러블리더블리") @NotBlank(message = "{room.name.notBlank}") From c590e664d9a5689afd284bf52a64b59b29dd0a0f Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 3 Sep 2022 23:35:39 +0900 Subject: [PATCH 076/301] =?UTF-8?q?#34=20[fix]=20=EB=B0=A9=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20->=20=EC=B0=B8=EA=B0=80?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EB=B0=A9=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=97=90=20=ED=8F=AC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/room/dto/response/GetRoomResponse.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java b/src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java index a04d61b5..08ba16a7 100644 --- a/src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java +++ b/src/main/java/hous/server/service/room/dto/response/GetRoomResponse.java @@ -13,6 +13,7 @@ public class GetRoomResponse { private boolean isJoiningRoom; private Long roomId; + private String roomCode; @JsonProperty("isJoiningRoom") public boolean isJoiningRoom() { @@ -24,11 +25,13 @@ public static GetRoomResponse of(Room room) { return GetRoomResponse.builder() .isJoiningRoom(false) .roomId(null) + .roomCode(null) .build(); } else { return GetRoomResponse.builder() .isJoiningRoom(true) .roomId(room.getId()) + .roomCode(room.getCode()) .build(); } } From 218fcebe3e590c971c9517f03814d8053b3d4d15 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 4 Sep 2022 20:28:38 +0900 Subject: [PATCH 077/301] =?UTF-8?q?#38=20[feat]=20=EB=A3=B8=EB=A9=94?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../server/common/success/SuccessCode.java | 3 +- .../user/UserRetrieveController.java | 27 +++++++++++++--- .../hous/server/domain/user/Onboarding.java | 18 ++--------- .../server/service/room/RoomServiceUtils.java | 8 +++++ .../service/user/UserRetrieveService.java | 20 ++++++++++-- .../hous/server/service/user/UserService.java | 1 + .../server/service/user/UserServiceUtils.java | 1 - .../request/SetOnboardingInfoRequestDto.java | 6 +--- .../user/dto/response/UserInfoResponse.java | 31 +++++++++++++++++-- 10 files changed, 85 insertions(+), 31 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 89f1d39c..60cc8491 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -37,6 +37,7 @@ public enum ErrorCode { FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), + FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "같은 방에 참가하고 있지 않습니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index e8439cbc..0885e691 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -35,7 +35,8 @@ public enum SuccessCode { GET_RULE_INFO_SUCCESS(OK, "규칙 조회 성공입니다."), // profile - GET_PROFILE_INFO_SUCCESS(OK, "나의 프로필 정보 조회 성공입니다."), + GET_MY_PROFILE_INFO_SUCCESS(OK, "나의 프로필 정보 조회 성공입니다."), + GET_HOMIE_PROFILE_INFO_SUCCESS(OK, "호미 프로필 정보 조회 성공입니다."), /** * 201 CREATED diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 1cb09296..0639a651 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -8,13 +8,11 @@ import hous.server.service.user.UserRetrieveService; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; import hous.server.service.user.dto.response.UserInfoResponse; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; @@ -56,6 +54,25 @@ public ResponseEntity checkMyOnboardingInfo(@ApiIgn @Auth @GetMapping("/user") public ResponseEntity getUserInfo(@ApiIgnore @UserId Long userId) { - return SuccessResponse.success(SuccessCode.CHECK_ONBOARDING_SUCCESS, userRetrieveService.getUserInfo(userId)); + return SuccessResponse.success(SuccessCode.GET_MY_PROFILE_INFO_SUCCESS, userRetrieveService.getUserInfo(userId)); + } + + @ApiOperation( + value = "[인증] 룸메이트 정보 페이지(Hous 뷰에서 호미 카드 클릭) - 룸메이트 프로필 정보를 확인합니다.", + notes = "성공 시, 생년월일 공개 여부(birthdayPublic) false 일 경우, 생년월일(birthday)은 null 입니다.\n" + + "사용자가 아직 입력하지 않은 데이터의 경우 null 이 전달됩니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "룸메이트 프로필 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "같은 방에 참가하고 있지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/user/{homieId}") + public ResponseEntity getHomieInfo(@ApiParam(name = "homieId", value = "조회할 호미의 id", required = true, example = "1") + @PathVariable Long homieId, @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_HOMIE_PROFILE_INFO_SUCCESS, userRetrieveService.getHomieInfo(homieId, userId)); } } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 8d6332e7..96a1bdc9 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -6,10 +6,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.personality.Personality; import hous.server.domain.room.Participate; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; import java.time.LocalDate; @@ -18,7 +15,9 @@ @Getter @Entity +@Builder(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) public class Onboarding extends AuditingTimeEntity { @Id @@ -68,17 +67,6 @@ public class Onboarding extends AuditingTimeEntity { @JoinColumn(name = "badge_id") private final List badges = new ArrayList<>(); - @Builder(access = AccessLevel.PRIVATE) - public Onboarding(String nickname, LocalDate birthday, String introduction, boolean isChecked, Personality personality, Represent represent, TestScore testScore) { - this.nickname = nickname; - this.birthday = birthday; - this.introduction = introduction; - this.isChecked = isChecked; - this.personality = personality; - this.represent = represent; - this.testScore = testScore; - } - public static Onboarding newInstance(Personality personality) { return Onboarding.builder() .isChecked(false) diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index db5c9ddb..6f1ddb66 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -13,6 +13,7 @@ import lombok.NoArgsConstructor; import java.util.List; +import java.util.Objects; import java.util.Random; import static hous.server.common.exception.ErrorCode.*; @@ -48,6 +49,13 @@ public static Room findParticipatingRoom(User user) { return participates.get(0).getRoom(); } + public static void checkParticipatingRoom(Room userRoom, Room homieRoom) { + if (!Objects.equals(userRoom.getId(), homieRoom.getId())) { + throw new ForbiddenException(String.format("같은 방에 참가하고 있지 않습니다. (요청 사용자 방 id: %s, 호미 방 id: %s)", + userRoom.getId(), homieRoom.getId()), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION); + } + } + private static boolean isNotUniqueRoomCode(RoomRepository roomRepository, String code) { return roomRepository.existsByRoomCode(code); } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 5ce56599..0bea84d4 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -2,9 +2,12 @@ import hous.server.domain.badge.Represent; import hous.server.domain.badge.repository.RepresentRepository; +import hous.server.domain.room.Room; +import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; import hous.server.service.user.dto.response.UserInfoResponse; import lombok.RequiredArgsConstructor; @@ -18,6 +21,7 @@ public class UserRetrieveService { private final UserRepository userRepository; private final RepresentRepository representRepository; + private final RoomRepository roomRepository; public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -25,12 +29,24 @@ public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { return !onboarding.isChecked() ? CheckOnboardingInfoResponse.of(false) : CheckOnboardingInfoResponse.of(true); } + public UserInfoResponse getHomieInfo(Long homieId, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + User homie = UserServiceUtils.findUserById(userRepository, homieId); + Room userRoom = RoomServiceUtils.findParticipatingRoom(user); + Room homieRoom = RoomServiceUtils.findParticipatingRoom(homie); + RoomServiceUtils.checkParticipatingRoom(userRoom, homieRoom); + return getProfileInfoByUser(homie); + } + public UserInfoResponse getUserInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); + return getProfileInfoByUser(user); + } + + private UserInfoResponse getProfileInfoByUser(User user) { Onboarding onboarding = user.getOnboarding(); Represent represent = representRepository.findRepresentByOnboarding(onboarding); return UserInfoResponse.of(onboarding, represent); } - - } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 66869a45..0d1ebdb7 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -31,6 +31,7 @@ public Long registerUser(CreateUserDto request) { public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); + System.out.println(request.isPublic()); onboarding.setOnboarding(request.getNickname(), request.getBirthday(), request.isPublic()); } } diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 69317f1e..3565b897 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -31,5 +31,4 @@ public static User findUserById(UserRepository userRepository, Long userId) { } return user; } - } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index d6888f67..6c8090cb 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -30,10 +30,6 @@ public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "생년월일 공개 여부", example = "true") @NotNull(message = "{onboarding.isPublic.notNull}") - private boolean isPublic; - @JsonProperty("isPublic") - public boolean isPublic() { - return isPublic; - } + private boolean isPublic; } diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index b3830a0a..619c54be 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -33,13 +33,40 @@ public class UserInfoResponse { private String introduction; - private TestScore testScore; + private TestScoreResponse testScore; private String representBadge; private String representBadgeImage; + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + public static class TestScoreResponse { + private int light; + + private int noise; + + private int clean; + + private int smell; + + public static TestScoreResponse of(TestScore testScore) { + if (testScore != null) { + return TestScoreResponse.builder() + .light(testScore.getLight()) + .noise(testScore.getNoise()) + .smell(testScore.getSmell()) + .clean(testScore.getClean()) + .build(); + + } else { + return null; + } + } + } + + public static UserInfoResponse of(Onboarding onboarding, Represent represent) { return UserInfoResponse.builder() .personalityColor(onboarding.getPersonality().getColor()) @@ -52,7 +79,7 @@ public static UserInfoResponse of(Onboarding onboarding, Represent represent) { .isSmoke(onboarding.isSmoke()) .mbti(onboarding.getMbti()) .introduction(onboarding.getIntroduction()) - .testScore(onboarding.getTestScore()) + .testScore(TestScoreResponse.of(onboarding.getTestScore())) .representBadge(represent != null ? represent.getBadge().getName() : null) .representBadgeImage(represent != null ? represent.getBadge().getImageUrl() : null) .build(); From 8c348a17fd9c69478772788b07aa50c6f2e125a7 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 4 Sep 2022 21:43:23 +0900 Subject: [PATCH 078/301] =?UTF-8?q?#38=20[fix]=20=ED=9D=A1=EC=97=B0=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EC=82=AC=EB=9D=BC=EC=A7=90=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/user/Onboarding.java | 3 --- .../server/service/user/dto/response/UserInfoResponse.java | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 96a1bdc9..1c0aabc5 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -40,9 +40,6 @@ public class Onboarding extends AuditingTimeEntity { @Column(length = 30) private String job; - @Column(nullable = false) - private boolean isSmoke; - @Column(nullable = false) private boolean isChecked; diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index 619c54be..929bb7c6 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -29,8 +29,6 @@ public class UserInfoResponse { private String job; - private boolean isSmoke; - private String introduction; private TestScoreResponse testScore; @@ -76,7 +74,6 @@ public static UserInfoResponse of(Onboarding onboarding, Represent represent) { .birthday(onboarding.isPublic() ? DateUtils.parseMonthAndDay(onboarding.getBirthday()) : null) .mbti(onboarding.getMbti()) .job(onboarding.getJob()) - .isSmoke(onboarding.isSmoke()) .mbti(onboarding.getMbti()) .introduction(onboarding.getIntroduction()) .testScore(TestScoreResponse.of(onboarding.getTestScore())) From b6bebc5b09c91757e652fc43b5150b122f7c5adb Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 4 Sep 2022 21:53:33 +0900 Subject: [PATCH 079/301] =?UTF-8?q?#38=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/user/UserController.java | 5 ++++- src/main/java/hous/server/service/user/UserService.java | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 431b4814..5c84d966 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -40,7 +40,10 @@ public class UserController { + "4. 생년월일을 공개 여부를 체크해주세요. (isPublic)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + + "2. 같은 방에 참가하고 있지 않습니다.\n", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 0d1ebdb7..66869a45 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -31,7 +31,6 @@ public Long registerUser(CreateUserDto request) { public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); - System.out.println(request.isPublic()); onboarding.setOnboarding(request.getNickname(), request.getBirthday(), request.isPublic()); } } From d538cb7ee3bf6beb8a4cedf6c09c8f5cd4cddb53 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 4 Sep 2022 22:23:11 +0900 Subject: [PATCH 080/301] =?UTF-8?q?#38=20[fix]=20request=20dto=EC=97=90?= =?UTF-8?q?=EC=84=9C=20boolean=20=ED=83=80=EC=9E=85=EC=9D=84=20Boolean?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EA=B3=A0=20@No?= =?UTF-8?q?tNull=20validate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/todo/TodoController.java | 6 ++++-- .../service/todo/dto/request/CheckTodoRequestDto.java | 6 +++++- .../service/todo/dto/request/TodoInfoRequestDto.java | 8 +++++--- .../user/dto/request/SetOnboardingInfoRequestDto.java | 6 +++++- src/main/resources/messages/validation.properties | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 3535e152..c79982a6 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -36,7 +36,8 @@ public class TodoController { message = "1. todo 이름을 입력해주세요. (name)\n" + "2. todo 이름을 15 글자 이내로 입력해주세요. (name)\n" + "3. 담당자 목록은 빈 배열일 수 없습니다. (todoUsers)\n" - + "4. 담당 요일 목록은 빈 배열일 수 없습니다. (todoUsers[0].dayOfWeeks)", + + "4. 담당 요일 목록은 빈 배열일 수 없습니다. (todoUsers[0].dayOfWeeks)\n" + + "5. todo 의 푸쉬 알림 여부를 입력해주세요. (isPushNotification)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 403, message = "todo 는 60개를 초과할 수 없습니다.", response = ErrorResponse.class), @@ -67,7 +68,8 @@ public ResponseEntity createTodo(@Valid @RequestBody TodoInfoRequestDto message = "1. todo 이름을 입력해주세요. (name)\n" + "2. todo 이름을 15 글자 이내로 입력해주세요. (name)\n" + "3. 담당자 목록은 빈 배열일 수 없습니다. (todoUsers)\n" - + "4. 담당 요일 목록은 빈 배열일 수 없습니다. (todoUsers[0].dayOfWeeks)", + + "4. 담당 요일 목록은 빈 배열일 수 없습니다. (todoUsers[0].dayOfWeeks)\n" + + "5. todo 의 푸쉬 알림 여부를 입력해주세요. (isPushNotification)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "존재하지 않는 todo 입니다.", response = ErrorResponse.class), diff --git a/src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java b/src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java index 29e77221..116f6ba6 100644 --- a/src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java +++ b/src/main/java/hous/server/service/todo/dto/request/CheckTodoRequestDto.java @@ -15,5 +15,9 @@ public class CheckTodoRequestDto { @ApiModelProperty(value = "요청할 체크 상태", example = "true") @NotNull(message = "{todo.status.notNull}") - private boolean status; + private Boolean status; + + public Boolean isStatus() { + return status; + } } diff --git a/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java b/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java index 8ee9ebd9..4b184b74 100644 --- a/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java +++ b/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java @@ -11,6 +11,7 @@ import javax.validation.Valid; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; @@ -24,8 +25,9 @@ public class TodoInfoRequestDto { @Size(max = 15, message = "{todo.name.max}") private String name; - @ApiModelProperty(value = "알림 여부") - private boolean isPushNotification; + @ApiModelProperty(value = "알림 여부", example = "true") + @NotNull(message = "{todo.isPushNotification.notNull}") + private Boolean isPushNotification; @ApiModelProperty(value = "담당자 목록") @NotEmpty(message = "{todo.todoUsers.notEmpty}") @@ -45,7 +47,7 @@ public static class TodoUser { } @JsonProperty("isPushNotification") - public boolean isPushNotification() { + public Boolean isPushNotification() { return isPushNotification; } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index 6c8090cb..df3f0d50 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -30,6 +30,10 @@ public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "생년월일 공개 여부", example = "true") @NotNull(message = "{onboarding.isPublic.notNull}") + private Boolean isPublic; + @JsonProperty("isPublic") - private boolean isPublic; + public Boolean isPublic() { + return isPublic; + } } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 0a5256e2..90357e5f 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -15,6 +15,7 @@ room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC69 room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.name.notBlank=todo \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.name.max=todo \uC774\uB984\uC744 15 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +todo.isPushNotification.notNull=todo \uC758 \uD478\uC26C \uC54C\uB9BC \uC5EC\uBD80\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 2045fb078ea047271ceb4062b90adf6ef8a1e24a Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 4 Sep 2022 22:35:48 +0900 Subject: [PATCH 081/301] =?UTF-8?q?#43=20[feat]=20=EB=82=98=EC=9D=98=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 36 +++++++++++++++++++ .../hous/server/domain/user/Onboarding.java | 10 ++++++ .../hous/server/service/user/UserService.java | 9 +++++ .../request/SetOnboardingInfoRequestDto.java | 8 ++--- .../dto/request/UpdateUserInfoRequestDto.java | 30 ++++++++++++++++ .../resources/messages/validation.properties | 6 ++++ 6 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 5c84d966..ed438352 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -6,6 +6,7 @@ import hous.server.config.resolver.UserId; import hous.server.service.user.UserService; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; +import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -54,4 +55,39 @@ public ResponseEntity setOnboardingInfo( userService.setOnboardingInfo(request, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 마이 페이지(프로필 뷰) - 나의 프로필 정보를 수정합니다.", + notes = "프로필 정보를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, + message = "1. 닉네임을 입력해주세요. (nickname)\n" + + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" + + "3. 생년월일을 입력해주세요. (birthday)\n" + + "4. 생년월일을 공개 여부를 체크해주세요. (isPublic)\n" + + "5. mbti 를 입력해주세요. (mbti)\n" + + "6. mbti 는 4 글자 이내로 입력해주세요. (mbti)\n" + + "7. 직업을 입력해주세요. (job)\n" + + "8. 직업은 3 글자 이내로 입력해주세요. (job)\n" + + "9. 자기소개를 입력해주세요.(introduction)\n" + + "10. 자기소개는 40 글자 이내로 입력해주세요. (introduction)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + + "2. 존재하지 않는 방입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/user") + public ResponseEntity updateUserInfo( + @Valid @RequestBody UpdateUserInfoRequestDto request, @ApiIgnore @UserId Long userId) { + userService.updateUserInfo(request, userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 1c0aabc5..ddffb0db 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -6,6 +6,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.personality.Personality; import hous.server.domain.room.Participate; +import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import lombok.*; import javax.persistence.*; @@ -81,4 +82,13 @@ public void setOnboarding(String nickname, LocalDate birthday, boolean isPublic) public void addParticipate(Participate participate) { this.participates.add(participate); } + + public void setUserInfo(UpdateUserInfoRequestDto request) { + this.nickname = request.getNickname(); + this.isPublic = request.isPublic(); + this.birthday = request.getBirthday(); + this.mbti = request.getMbti(); + this.job = request.getJob(); + this.introduction = request.getIntroduction(); + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 66869a45..9aa2b1bd 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -6,8 +6,10 @@ import hous.server.domain.user.Setting; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.request.CreateUserDto; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; +import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,4 +35,11 @@ public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) Onboarding onboarding = user.getOnboarding(); onboarding.setOnboarding(request.getNickname(), request.getBirthday(), request.isPublic()); } + + public void updateUserInfo(UpdateUserInfoRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); + Onboarding onboarding = user.getOnboarding(); + onboarding.setUserInfo(request); + } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index df3f0d50..82f35bd4 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -3,10 +3,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModelProperty; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; +import lombok.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; @@ -15,7 +12,8 @@ @ToString @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java new file mode 100644 index 00000000..14ec7141 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java @@ -0,0 +1,30 @@ +package hous.server.service.user.dto.request; + + +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateUserInfoRequestDto extends SetOnboardingInfoRequestDto { + + @ApiModelProperty(value = "MBTI", example = "CUTE") + @NotBlank(message = "{user.mbti.notBlank}") + @Size(min = 1, max = 4, message = "{user.mbti.max}") + private String mbti; + + @ApiModelProperty(value = "직업", example = "대학생") + @NotBlank(message = "{user.job.notBlank}") + @Size(min = 1, max = 3, message = "{user.job.max}") + private String job; + + @ApiModelProperty(value = "자기소개", example = "안녕하세요. 저는 혜조니입니다~") + @NotBlank(message = "{user.introduction.notBlank}") + @Size(min = 1, max = 40, message = "{user.introduction.max}") + private String introduction; +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 90357e5f..b74cc3ef 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -22,3 +22,9 @@ todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 id \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uAC12\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +user.mbti.notBlank=mbti \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +user.mbti.max=mbti \uB294 4 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +user.job.notBlank=\uC9C1\uC5C5\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +user.job.max=\uC9C1\uC5C5\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +user.introduction.notBlank=\uC790\uAE30\uC18C\uAC1C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +user.introduction.max=\uC790\uAE30\uC18C\uAC1C\uB294 40 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From e13a6bcf9a90655b6361a867fe05712fc40a5de5 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 4 Sep 2022 22:54:05 +0900 Subject: [PATCH 082/301] =?UTF-8?q?#46=20[fix]=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/exception/ErrorCode.java | 2 +- src/main/java/hous/server/service/todo/TodoServiceUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 60cc8491..38077d87 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -19,7 +19,7 @@ public enum ErrorCode { VALIDATION_WRONG_TYPE_EXCEPTION(BAD_REQUEST, "잘못된 타입이 입력되었습니다."), VALIDATION_SOCIAL_TYPE_EXCEPTION(BAD_REQUEST, "잘못된 소셜 프로바이더 입니다."), VALIDATION_SORT_TYPE_EXCEPTION(BAD_REQUEST, "허용하지 않는 정렬기준을 입력했습니다."), - VALIDATION_TODO_STATUS_EXCEPTION(BAD_REQUEST, "잘못된 상태로 요청했습니다."), + VALIDATION_STATUS_EXCEPTION(BAD_REQUEST, "잘못된 상태로 요청했습니다."), /** * 401 UnAuthorized diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 9134a490..939a35de 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -40,7 +40,7 @@ public static void validateTodoCounts(Room room) { public static void validateTodoStatus(DoneRepository doneRepository, boolean status, Onboarding onboarding, Todo todo) { if (status == doneRepository.findTodayTodoCheckStatus(DateUtils.today(), onboarding, todo)) { - throw new ValidationException(String.format("(%s) 유저의 todo (%s) 상태는 이미 (%s) 입니다.", onboarding.getId(), todo.getId(), status), VALIDATION_TODO_STATUS_EXCEPTION); + throw new ValidationException(String.format("(%s) 유저의 todo (%s) 상태는 이미 (%s) 입니다.", onboarding.getId(), todo.getId(), status), VALIDATION_STATUS_EXCEPTION); } } From eda74ee690d2932ebc475e80b81fad2b1fb7363c Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 4 Sep 2022 22:54:32 +0900 Subject: [PATCH 083/301] =?UTF-8?q?#46=20[feat]=20=EB=82=98=EC=9D=98=20?= =?UTF-8?q?=ED=91=B8=EC=89=AC=20=EC=95=8C=EB=A6=BC=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 29 ++++++++++++++++--- .../java/hous/server/domain/user/Setting.java | 4 +++ .../hous/server/service/user/UserService.java | 9 ++++++ .../server/service/user/UserServiceUtils.java | 11 +++++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index ed438352..ca3c7e5f 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -7,10 +7,7 @@ import hous.server.service.user.UserService; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -90,4 +87,28 @@ public ResponseEntity updateUserInfo( userService.updateUserInfo(request, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 마이 페이지(프로필 뷰) - 나의 푸쉬 알림 설정 정보를 수정합니다.", + notes = "푸쉬 알림 설정 여부를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, message = "자기소개는 40 글자 이내로 입력해주세요. (introduction)", response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + + "2. 존재하지 않는 방입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/user/push/{state}") + public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = "푸쉬 알림 여부", required = false, example = "1") + @PathVariable boolean state, @ApiIgnore @UserId Long userId) { + userService.updateUserPushState(state, userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/user/Setting.java b/src/main/java/hous/server/domain/user/Setting.java index eb17dd57..686a6251 100644 --- a/src/main/java/hous/server/domain/user/Setting.java +++ b/src/main/java/hous/server/domain/user/Setting.java @@ -30,4 +30,8 @@ public static Setting newInstance() { .isPushNotification(true) .build(); } + + public void setPushNotification(boolean isPushNotification) { + this.isPushNotification = isPushNotification; + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 9aa2b1bd..6b99ed30 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -42,4 +42,13 @@ public void updateUserInfo(UpdateUserInfoRequestDto request, Long userId) { Onboarding onboarding = user.getOnboarding(); onboarding.setUserInfo(request); } + + public void updateUserPushState(boolean state, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); + Setting setting = user.getSetting(); + UserServiceUtils.validatePushNotificationStatus(setting.isPushNotification(), state); + setting.setPushNotification(state); + } + } diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 3565b897..b7833d72 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -2,14 +2,14 @@ import hous.server.common.exception.ConflictException; import hous.server.common.exception.NotFoundException; +import hous.server.common.exception.ValidationException; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import static hous.server.common.exception.ErrorCode.CONFLICT_USER_EXCEPTION; -import static hous.server.common.exception.ErrorCode.NOT_FOUND_USER_EXCEPTION; +import static hous.server.common.exception.ErrorCode.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class UserServiceUtils { @@ -31,4 +31,11 @@ public static User findUserById(UserRepository userRepository, Long userId) { } return user; } + + public static void validatePushNotificationStatus(boolean state, boolean requestState) { + if (state == requestState) { + throw new ValidationException(String.format("(%s) 유저의 푸쉬 알림 여부 상태는 이미 (%s) 입니다.", state, requestState), + VALIDATION_STATUS_EXCEPTION); + } + } } From aad0efcbbf3d9d8a3452ce855af127ba5040ef7d Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 14:27:27 +0900 Subject: [PATCH 084/301] =?UTF-8?q?#48=20[fix]=20query=20parameter?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/user/UserController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index ca3c7e5f..f5dfa9ba 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -105,9 +105,9 @@ public ResponseEntity updateUserInfo( }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) - @PutMapping("/user/push/{state}") - public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = "푸쉬 알림 여부", required = false, example = "1") - @PathVariable boolean state, @ApiIgnore @UserId Long userId) { + @PutMapping("/user/push") + public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = "푸쉬 알림 여부", required = true, example = "true") + @RequestParam boolean state, @ApiIgnore @UserId Long userId) { userService.updateUserPushState(state, userId); return SuccessResponse.NO_CONTENT; } From c628cbce26e6e457dcc89a875e40cea776fa05bb Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 7 Sep 2022 18:11:40 +0900 Subject: [PATCH 085/301] =?UTF-8?q?#49=20[fix]=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/user/UserService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 9aa2b1bd..fb3a4caf 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -23,7 +23,6 @@ public class UserService { private final PersonalityRepository personalityRepository; public Long registerUser(CreateUserDto request) { - System.out.println(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY)); UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), Onboarding.newInstance(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY)), Setting.newInstance())); From 79369d0a68b2c67c7da9055cb535e398b1bff93d Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 7 Sep 2022 19:05:17 +0900 Subject: [PATCH 086/301] =?UTF-8?q?#49=20[feat]=20=ED=99=88=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 + .../home/HomeRetrieveController.java | 48 +++++++++++++ .../service/home/HomeRetrieveService.java | 66 +++++++++++++++++ .../home/dto/response/HomeInfoResponse.java | 71 +++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 src/main/java/hous/server/controller/home/HomeRetrieveController.java create mode 100644 src/main/java/hous/server/service/home/HomeRetrieveService.java create mode 100644 src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 0885e691..a24f3319 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -25,6 +25,9 @@ public enum SuccessCode { GET_ROOM_INFO_SUCCESS(OK, "참가하려는 방 정보 조회 성공입니다."), JOIN_ROOM_SUCCESS(OK, "방 참여 성공입니다."), + // 홈 + GET_HOME_INFO_SUCCESS(OK, "홈 화면 정보 조회 성공입니다."), + // to-do GET_USERS_INFO_SUCCESS(OK, "담당자 목록 조회 성공입니다."), GET_TODO_INFO_SUCCESS(OK, "todo 정보 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/home/HomeRetrieveController.java b/src/main/java/hous/server/controller/home/HomeRetrieveController.java new file mode 100644 index 00000000..c049f0b4 --- /dev/null +++ b/src/main/java/hous/server/controller/home/HomeRetrieveController.java @@ -0,0 +1,48 @@ +package hous.server.controller.home; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; +import hous.server.service.home.HomeRetrieveService; +import hous.server.service.home.dto.response.HomeInfoResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +@Api(tags = "Home") +@RestController +@RequestMapping("/v1") +@RequiredArgsConstructor +public class HomeRetrieveController { + + private final HomeRetrieveService homeRetrieveService; + + @ApiOperation( + value = "[인증] Hous- 페이지 - 홈 화면 정보를 조회합니다.", + notes = "오늘 우리의 to-do 진행률, MY to-do, Our Rules, Homies 정보를 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "홈 화면 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/home") + public ResponseEntity getHomeInfo(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_HOME_INFO_SUCCESS, homeRetrieveService.getHomeInfo(userId)); + } +} diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java new file mode 100644 index 00000000..02854bdb --- /dev/null +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -0,0 +1,66 @@ +package hous.server.service.home; + +import hous.server.common.util.DateUtils; +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.room.Participate; +import hous.server.domain.room.Room; +import hous.server.domain.rule.Rule; +import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.home.dto.response.HomeInfoResponse; +import hous.server.service.room.RoomServiceUtils; +import hous.server.service.todo.TodoServiceUtils; +import hous.server.service.todo.dto.response.MyTodoInfo; +import hous.server.service.todo.dto.response.OurTodoInfo; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class HomeRetrieveService { + + private final UserRepository userRepository; + private final DoneRepository doneRepository; + + public HomeInfoResponse getHomeInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + LocalDate today = DateUtils.today(); + List todos = room.getTodos(); + List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(today, todos); + List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(today, user.getOnboarding(), todos); + List todayMyTodos = todayMyTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> MyTodoInfo.of( + todo.getId(), + todo.getName(), + doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))) + .collect(Collectors.toList()); + List todayOurTodos = todayOurTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> OurTodoInfo.of( + todo.getName(), + doneRepository.findTodayOurTodoStatus(today, todo), + todo.getTakes().stream() + .map(take -> take.getOnboarding().getNickname()) + .collect(Collectors.toList()))) + .collect(Collectors.toList()); + List rules = room.getRules(); + List participants = room.getParticipates().stream() + .map(Participate::getOnboarding) + .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) + .collect(Collectors.toList()); + return HomeInfoResponse.of(user.getOnboarding(), room, today, todayMyTodos, todayOurTodos, rules, participants); + } +} diff --git a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java new file mode 100644 index 00000000..793e8313 --- /dev/null +++ b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java @@ -0,0 +1,71 @@ +package hous.server.service.home.dto.response; + +import hous.server.common.util.MathUtils; +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.room.Room; +import hous.server.domain.rule.Rule; +import hous.server.domain.todo.OurTodoStatus; +import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; +import hous.server.service.todo.dto.response.MyTodoInfo; +import hous.server.service.todo.dto.response.OurTodoInfo; +import lombok.*; + +import java.time.LocalDate; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class HomeInfoResponse { + + private String userNickname; + private String roomName; + private int progress; + private int myTodosCnt; + private List myTodos; + private List ourRules; + private List homies; + + @ToString + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + public static class HomieInfo { + private Long homieId; + private String userNickname; + private PersonalityColor color; + } + + public static HomeInfoResponse of(Onboarding me, Room room, LocalDate today, List myTodos, + List ourTodos, List rules, List participants) { + int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); + return HomeInfoResponse.builder() + .userNickname(me.getNickname()) + .roomName(room.getName()) + .progress(MathUtils.percent(doneOurTodosCnt, ourTodos.size())) + .myTodosCnt(myTodos.size()) + .myTodos(myTodos.stream() + .limit(3) + .map(MyTodoInfo::getTodoName) + .collect(Collectors.toList())) + .ourRules(rules.stream() + .sorted(Comparator.comparing(Rule::getIdx)) + .limit(3) + .map(Rule::getName) + .collect(Collectors.toList())) + .homies(participants.stream() + .map(onboarding -> HomieInfo.builder() + .homieId(onboarding.getId()) + .userNickname(onboarding.getNickname()) + .color(onboarding.getPersonality().getColor()) + .build()) + .collect(Collectors.toList())) + .build(); + } +} From 96ca59cb72bc72d8afa872667543074d4e5aae9b Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 22:00:08 +0900 Subject: [PATCH 087/301] =?UTF-8?q?#48=20[fix]=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=AC=EC=82=AC=EC=9A=A9=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/todo/dto/response/MyTodo.java | 20 ++++++++++++++++ .../service/todo/dto/response/MyTodoInfo.java | 14 ++++++----- .../service/todo/dto/response/OurTodo.java | 23 +++++++++++++++++++ .../todo/dto/response/OurTodoInfo.java | 12 ++++++---- 4 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/dto/response/MyTodo.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/OurTodo.java diff --git a/src/main/java/hous/server/service/todo/dto/response/MyTodo.java b/src/main/java/hous/server/service/todo/dto/response/MyTodo.java new file mode 100644 index 00000000..b7681137 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/MyTodo.java @@ -0,0 +1,20 @@ +package hous.server.service.todo.dto.response; + +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@Builder(access = AccessLevel.PRIVATE) +public class MyTodo { + private Long todoId; + private String todoName; + + public static MyTodo of(Long todoId, String todoName) { + return MyTodo.builder() + .todoId(todoId) + .todoName(todoName) + .build(); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java index cf56ef94..79b6bc51 100644 --- a/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java +++ b/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java @@ -5,13 +5,9 @@ @ToString @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Builder(access = AccessLevel.PRIVATE) -public class MyTodoInfo { +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class MyTodoInfo extends MyTodo { - private Long todoId; - private String todoName; private boolean isChecked; @JsonProperty("isChecked") @@ -19,6 +15,12 @@ public boolean isChecked() { return isChecked; } + @Builder(access = AccessLevel.PRIVATE) + public MyTodoInfo(Long todoId, String todoName, boolean isChecked) { + super(todoId, todoName); + this.isChecked = isChecked; + } + public static MyTodoInfo of(Long todoId, String todoName, boolean isChecked) { return MyTodoInfo.builder() .todoId(todoId) diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java new file mode 100644 index 00000000..9b453f12 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java @@ -0,0 +1,23 @@ +package hous.server.service.todo.dto.response; + +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@Builder(access = AccessLevel.PRIVATE) +public class OurTodo { + + private String todoName; + private List nicknames; + + public static OurTodo of(String todoName, List nicknames) { + return OurTodo.builder() + .todoName(todoName) + .nicknames(nicknames) + .build(); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java index c3ca183e..08bf6f3c 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java @@ -8,13 +8,15 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Builder(access = AccessLevel.PRIVATE) -public class OurTodoInfo { +public class OurTodoInfo extends OurTodo { - private String todoName; private OurTodoStatus status; - private List nicknames; + + @Builder(access = AccessLevel.PRIVATE) + public OurTodoInfo(String todoName, List nicknames, OurTodoStatus status) { + super(todoName, nicknames); + this.status = status; + } public static OurTodoInfo of(String todoName, OurTodoStatus status, List nicknames) { return OurTodoInfo.builder() From c9f35d41b07d51aadd14413bee4bc491aae1481b Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 22:00:36 +0900 Subject: [PATCH 088/301] =?UTF-8?q?#48=20[fix]=20DayOfWeek=20index=20?= =?UTF-8?q?=EA=B0=92=EC=9D=84=20=EC=A3=BC=EB=A9=B4,=20value=20=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/todo/DayOfWeek.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/hous/server/domain/todo/DayOfWeek.java b/src/main/java/hous/server/domain/todo/DayOfWeek.java index 13ce4e6f..357c3795 100644 --- a/src/main/java/hous/server/domain/todo/DayOfWeek.java +++ b/src/main/java/hous/server/domain/todo/DayOfWeek.java @@ -40,4 +40,24 @@ public static String toString(Set dayOfWeekSet) { .map(DayOfWeek::getValue) .collect(Collectors.joining(", ")); } + + public static String fromIndex(int index) { + switch (index) { + case 1: + return MONDAY.getValue(); + case 2: + return TUESDAY.getValue(); + case 3: + return WEDNESDAY.getValue(); + case 4: + return THURSDAY.getValue(); + case 5: + return FRIDAY.getValue(); + case 6: + return SATURDAY.getValue(); + case 7: + return SUNDAY.getValue(); + } + return null; + } } From b45e71cc4af9690f6ba5415f5ebbf14950317ef9 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 22:01:50 +0900 Subject: [PATCH 089/301] =?UTF-8?q?#48=20[feat]=20todo=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EB=B3=B4=EA=B8=B0=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9A=94=EC=9D=BC=EB=B3=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../todo/TodoRetrieveController.java | 30 +++++++++++--- .../service/todo/TodoRetrieveService.java | 39 +++++++++++++++++++ .../server/service/todo/TodoServiceUtils.java | 30 ++++++++++++++ .../todo/dto/response/TodoAllDayResponse.java | 27 +++++++++++++ 5 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 0885e691..f0341884 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -30,6 +30,7 @@ public enum SuccessCode { GET_TODO_INFO_SUCCESS(OK, "todo 정보 조회 성공입니다."), GET_TODO_SUMMARY_INFO_SUCCESS(OK, "todo 요약 정보 조회 성공입니다."), GET_TODO_MAIN_SUCCESS(OK, "todo 메인 페이지 조회 성공입니다."), + GET_TODO_ALL_DAY_SUCCESS(OK, "todo 요일별 정보 조회 성공입니다."), // rule GET_RULE_INFO_SUCCESS(OK, "규칙 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index e54db6ce..f7801e0f 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -6,10 +6,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoRetrieveService; -import hous.server.service.todo.dto.response.TodoInfoResponse; -import hous.server.service.todo.dto.response.TodoMainResponse; -import hous.server.service.todo.dto.response.TodoSummaryInfoResponse; -import hous.server.service.todo.dto.response.UserPersonalityInfoResponse; +import hous.server.service.todo.dto.response.*; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -19,6 +16,8 @@ import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; +import java.util.List; + @Api(tags = "Todo") @RestController @RequestMapping("/v1") @@ -91,7 +90,7 @@ public ResponseEntity getTodoInfo(@ApiParam(name = "todoId", v } @ApiOperation( - value = "[인증] todo 전체 페이지 - 저장된 todo 요약 정보를 조회합니다.", + value = "[인증] todo 전체 보기 페이지 - 저장된 todo 요약 정보를 조회합니다.", notes = "저장된 전체 담당자, 전체 담당 요일을 조회합니다." ) @ApiResponses(value = { @@ -111,4 +110,25 @@ public ResponseEntity getTodoSummaryInfo(@ApiParam(name @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_SUMMARY_INFO_SUCCESS, todoRetrieveService.getTodoSummaryInfo(todoId, userId)); } + + @ApiOperation( + value = "[인증] todo 전체 보기 페이지 - 저장된 todo 요약 정보를 조회합니다.", + notes = "모든 요일의 todo별 나의 todo와 방의 todo를 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "todo 요일별 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 todo 입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/todos/day") + public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { + todoRetrieveService.getTodoAllDayInfo(userId); + return SuccessResponse.success(SuccessCode.GET_TODO_ALL_DAY_SUCCESS, todoRetrieveService.getTodoAllDayInfo(userId)); + } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index f86f87b7..5f101eea 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -4,6 +4,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; +import hous.server.domain.todo.DayOfWeek; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.todo.repository.TodoRepository; @@ -18,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -83,8 +85,45 @@ public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { public TodoSummaryInfoResponse getTodoSummaryInfo(Long todoId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(todo); return TodoSummaryInfoResponse.of(todo, userPersonalityInfos, user.getOnboarding()); } + + public List getTodoAllDayInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + List todos = room.getTodos(); + + // 이 방의 모든 요일의 todo list 조회 + List ourTodosList = TodoServiceUtils.filterAllDaysOurTodos(todos); + List myTodosList = TodoServiceUtils.filterAllDaysMyTodos(todos, user.getOnboarding()); + + // 요일별(index) todo list 형태로 가공 + List[] allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToList(ourTodosList); + List[] allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToList(myTodosList); + + // List response dto 형태로 가공 + List allDayTodosList = new ArrayList<>(); + for (int i = 1; i < 8; i++) { + String dayOfWeek = DayOfWeek.fromIndex(i); + List myTodoInfos = allDayMyTodosList[i].stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> MyTodo.of( + todo.getId(), + todo.getName())) + .collect(Collectors.toList()); + List ourTodoInfos = allDayOurTodosList[i].stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> OurTodo.of( + todo.getName(), + todo.getTakes().stream() + .map(take -> take.getOnboarding().getNickname()) + .collect(Collectors.toList()))) + .collect(Collectors.toList()); + allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, myTodoInfos, ourTodoInfos)); + } + return allDayTodosList; + } } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 939a35de..3fa4a69c 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -68,6 +68,36 @@ public static List filterTodayOurTodos(LocalDate today, List todos) return todayOurTodosList; } + public static List filterAllDaysOurTodos(List todos) { + List allDaysOurTodosList = new ArrayList<>(); + todos.forEach(todo -> todo.getTakes().forEach(take -> + take.getRedos().forEach(redo -> + allDaysOurTodosList.add(todo)))); + return allDaysOurTodosList; + } + + public static List filterAllDaysMyTodos(List todos, Onboarding me) { + List myTodosList = new ArrayList<>(); + todos.forEach(todo -> todo.getTakes().forEach(take -> { + if (take.getOnboarding().getId().equals(me.getId())) { + myTodosList.add(todo); + } + })); + return myTodosList; + } + + public static List[] mapByDayOfWeekToList(List todos) { + List[] todosList = new ArrayList[8]; + for (int index = 0; index < 8; index++) { + todosList[index] = new ArrayList<>(); + } + todos.forEach(todo -> todo.getTakes().forEach(take -> { + take.getRedos().forEach(redo -> + todosList[redo.getDayOfWeek().getIndex()].add(todo)); + })); + return todosList; + } + public static List filterTodayMyTodos(LocalDate today, Onboarding me, List todos) { List todayMyTodosList = new ArrayList<>(); List todayOurTodosList = filterTodayOurTodos(today, todos); diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java new file mode 100644 index 00000000..5162fff9 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java @@ -0,0 +1,27 @@ +package hous.server.service.todo.dto.response; + +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class TodoAllDayResponse { + + private String dayOfWeek; + private int ourTodosCnt; + private List myTodos; + private List ourTodos; + + public static TodoAllDayResponse of(String dayOfWeek, List myTodos, List ourTodos) { + return TodoAllDayResponse.builder() + .dayOfWeek(dayOfWeek) + .ourTodosCnt(ourTodos.size()) + .myTodos(myTodos) + .ourTodos(ourTodos) + .build(); + } +} From 9671a378ac01c2bd578e992cc975265054df658f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 22:29:10 +0900 Subject: [PATCH 090/301] =?UTF-8?q?#48=20[fix]=20onboarding=20=EC=99=B8?= =?UTF-8?q?=EB=9E=98=ED=82=A4=20=EC=A0=9C=EC=95=BD=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/todo/Take.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/todo/Take.java b/src/main/java/hous/server/domain/todo/Take.java index 53ba3063..f6f13a48 100644 --- a/src/main/java/hous/server/domain/todo/Take.java +++ b/src/main/java/hous/server/domain/todo/Take.java @@ -24,7 +24,7 @@ public class Take extends AuditingTimeEntity { @JoinColumn(name = "todo_id", nullable = false) private Todo todo; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "onboarding_id") private Onboarding onboarding; From 12dd1f8a8e9713f0279e9201b249b21e34fb22bc Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 22:31:57 +0900 Subject: [PATCH 091/301] =?UTF-8?q?#48=20[comment]=20=ED=91=B8=EC=89=AC?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B4=80=EB=A0=A8=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20TODO=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/user/UserController.java | 1 + src/main/java/hous/server/service/user/UserService.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index f5dfa9ba..436c0688 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -88,6 +88,7 @@ public ResponseEntity updateUserInfo( return SuccessResponse.NO_CONTENT; } + // TODO 푸쉬알림 설정뷰 확정나면 수정하기 @ApiOperation( value = "[인증] 마이 페이지(프로필 뷰) - 나의 푸쉬 알림 설정 정보를 수정합니다.", notes = "푸쉬 알림 설정 여부를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 6b99ed30..99c67658 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -43,6 +43,7 @@ public void updateUserInfo(UpdateUserInfoRequestDto request, Long userId) { onboarding.setUserInfo(request); } + // TODO 푸쉬알림 설정뷰 확정나면 수정하기 public void updateUserPushState(boolean state, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); RoomServiceUtils.findParticipatingRoom(user); From ecde0708989956b224b52c4d7700b0c6609834fc Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 22:49:23 +0900 Subject: [PATCH 092/301] =?UTF-8?q?#48=20[fix]=20controller=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=9A=94=EC=9D=BC=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=AA=85=EC=84=B8=EC=84=9C=20=EC=84=A4=EB=AA=85=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 --- .../hous/server/controller/todo/TodoRetrieveController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index f7801e0f..b22e6c17 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -112,7 +112,7 @@ public ResponseEntity getTodoSummaryInfo(@ApiParam(name } @ApiOperation( - value = "[인증] todo 전체 보기 페이지 - 저장된 todo 요약 정보를 조회합니다.", + value = "[인증] todo 전체 보기 페이지 - 요일별 todo를 조회합니다.", notes = "모든 요일의 todo별 나의 todo와 방의 todo를 조회합니다." ) @ApiResponses(value = { @@ -121,14 +121,14 @@ public ResponseEntity getTodoSummaryInfo(@ApiParam(name @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" - + "2. 존재하지 않는 todo 입니다.", + + "2. 존재하지 않는 todo 입니다.\n" + + "3. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @GetMapping("/todos/day") public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { - todoRetrieveService.getTodoAllDayInfo(userId); return SuccessResponse.success(SuccessCode.GET_TODO_ALL_DAY_SUCCESS, todoRetrieveService.getTodoAllDayInfo(userId)); } } From 848543a1adf8c1d6cba1150876fd7f3d9f280201 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 7 Sep 2022 23:05:42 +0900 Subject: [PATCH 093/301] =?UTF-8?q?#48=20[fix]=20DayOfWeek=20index=20?= =?UTF-8?q?=EA=B0=92=EC=9D=84=20=EC=A3=BC=EB=A9=B4,=20value=20=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/todo/DayOfWeek.java | 2 +- src/main/java/hous/server/service/todo/TodoRetrieveService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/domain/todo/DayOfWeek.java b/src/main/java/hous/server/domain/todo/DayOfWeek.java index 357c3795..a57d5fa7 100644 --- a/src/main/java/hous/server/domain/todo/DayOfWeek.java +++ b/src/main/java/hous/server/domain/todo/DayOfWeek.java @@ -41,7 +41,7 @@ public static String toString(Set dayOfWeekSet) { .collect(Collectors.joining(", ")); } - public static String fromIndex(int index) { + public static String getValueByIndex(int index) { switch (index) { case 1: return MONDAY.getValue(); diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 5f101eea..a0c1fe2a 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -107,7 +107,7 @@ public List getTodoAllDayInfo(Long userId) { // List response dto 형태로 가공 List allDayTodosList = new ArrayList<>(); for (int i = 1; i < 8; i++) { - String dayOfWeek = DayOfWeek.fromIndex(i); + String dayOfWeek = DayOfWeek.getValueByIndex(i); List myTodoInfos = allDayMyTodosList[i].stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> MyTodo.of( From a516a04e4c9f5f4e0be494fa4f65e7aefcf911b6 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 12:07:37 +0900 Subject: [PATCH 094/301] =?UTF-8?q?#54=20[fix]=20=EC=B9=BC=EB=9F=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9D=B4=EC=A6=88=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/personality/Personality.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/personality/Personality.java b/src/main/java/hous/server/domain/personality/Personality.java index ccb74598..086db98b 100644 --- a/src/main/java/hous/server/domain/personality/Personality.java +++ b/src/main/java/hous/server/domain/personality/Personality.java @@ -29,7 +29,7 @@ public class Personality extends AuditingTimeEntity { @Column(nullable = false, length = 300) private String title; - @Column(nullable = false, length = 300) + @Column(nullable = false, length = 500) private String description; @Column(nullable = false, length = 300) From ebd58cb563dc8d7c1662051c13130d7033145a17 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 12:17:58 +0900 Subject: [PATCH 095/301] =?UTF-8?q?#54=20[refactor]=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EC=88=9C=EC=84=9C=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EA=B2=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/user/UserRetrieveService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 0bea84d4..2a7c66a3 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -29,6 +29,12 @@ public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { return !onboarding.isChecked() ? CheckOnboardingInfoResponse.of(false) : CheckOnboardingInfoResponse.of(true); } + public UserInfoResponse getUserInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); + return getProfileInfoByUser(user); + } + public UserInfoResponse getHomieInfo(Long homieId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); User homie = UserServiceUtils.findUserById(userRepository, homieId); @@ -38,12 +44,6 @@ public UserInfoResponse getHomieInfo(Long homieId, Long userId) { return getProfileInfoByUser(homie); } - public UserInfoResponse getUserInfo(Long userId) { - User user = UserServiceUtils.findUserById(userRepository, userId); - RoomServiceUtils.findParticipatingRoom(user); - return getProfileInfoByUser(user); - } - private UserInfoResponse getProfileInfoByUser(User user) { Onboarding onboarding = user.getOnboarding(); Represent represent = representRepository.findRepresentByOnboarding(onboarding); From 4ec24316402b6a5f5b6058de260304d9af6822c0 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 12:56:34 +0900 Subject: [PATCH 096/301] =?UTF-8?q?#54=20[feat]=20=EC=84=B1=ED=96=A5=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../server/common/success/SuccessCode.java | 3 ++ .../user/UserRetrieveController.java | 25 ++++++++-- .../service/user/UserRetrieveService.java | 11 +++++ .../server/service/user/UserServiceUtils.java | 7 +++ .../dto/response/PersonalityInfoResponse.java | 49 +++++++++++++++++++ 6 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/main/java/hous/server/service/user/dto/response/PersonalityInfoResponse.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 38077d87..1139ed8b 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -50,6 +50,7 @@ public enum ErrorCode { NOT_FOUND_PARTICIPATE_EXCEPTION(NOT_FOUND, "참가중인 방이 존재하지 않습니다."), NOT_FOUND_RULE_EXCEPTION(NOT_FOUND, "존재하지 않는 규칙입니다."), NOT_FOUND_TODO_EXCEPTION(NOT_FOUND, "존재하지 않는 todo 입니다."), + NOT_FOUND_PERSONALITY_COLOR_EXCEPTION(NOT_FOUND, "GRAY 에 대한 성향 정보는 존재하지 않습니다."), /** * 405 Method Not Allowed diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 4462d4c0..17d2169c 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -42,6 +42,9 @@ public enum SuccessCode { GET_MY_PROFILE_INFO_SUCCESS(OK, "나의 프로필 정보 조회 성공입니다."), GET_HOMIE_PROFILE_INFO_SUCCESS(OK, "호미 프로필 정보 조회 성공입니다."), + // 성향 + GET_HOMIE_PERSONALITY_INFO_SUCCESS(OK, "호미 성향 정보 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 0639a651..c4d396a9 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -5,16 +5,15 @@ import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; +import hous.server.domain.personality.PersonalityColor; import hous.server.service.user.UserRetrieveService; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; +import hous.server.service.user.dto.response.PersonalityInfoResponse; import hous.server.service.user.dto.response.UserInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @Api(tags = "User") @@ -75,4 +74,22 @@ public ResponseEntity getHomieInfo(@ApiParam(name = "homieId", @PathVariable Long homieId, @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_HOMIE_PROFILE_INFO_SUCCESS, userRetrieveService.getHomieInfo(homieId, userId)); } + + @ApiOperation( + value = "[인증] 룸메이트 정보 페이지(Hous 뷰에서 호미 카드 클릭) - 룸메이트 성향 정보를 확인합니다.", + notes = "color 쿼리에 조회할 성향 색깔을 담아서 요청을 보냅니다.\n" + + "GRAY 에 대한 정보는 존재하지 않기 때문에 404 에러를 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "룸메이트 성향 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "GRAY 에 대한 성향 정보는 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/user/personality") + public ResponseEntity getHomiePersonalityInfo(@ApiParam(name = "color", value = "조회할 성향 색깔", required = true, example = "RED") + @RequestParam PersonalityColor color) { + return SuccessResponse.success(SuccessCode.GET_HOMIE_PERSONALITY_INFO_SUCCESS, userRetrieveService.getHomiePersonalityInfo(color)); + } } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 2a7c66a3..5cbc8d3f 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -2,6 +2,9 @@ import hous.server.domain.badge.Represent; import hous.server.domain.badge.repository.RepresentRepository; +import hous.server.domain.personality.Personality; +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.room.Room; import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.user.Onboarding; @@ -9,6 +12,7 @@ import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; +import hous.server.service.user.dto.response.PersonalityInfoResponse; import hous.server.service.user.dto.response.UserInfoResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,6 +24,7 @@ public class UserRetrieveService { private final UserRepository userRepository; + private final PersonalityRepository personalityRepository; private final RepresentRepository representRepository; private final RoomRepository roomRepository; @@ -44,6 +49,12 @@ public UserInfoResponse getHomieInfo(Long homieId, Long userId) { return getProfileInfoByUser(homie); } + public PersonalityInfoResponse getHomiePersonalityInfo(PersonalityColor color) { + UserServiceUtils.validatePersonalityColor(color); + Personality personality = personalityRepository.findPersonalityByColor(color); + return PersonalityInfoResponse.of(personality); + } + private UserInfoResponse getProfileInfoByUser(User user) { Onboarding onboarding = user.getOnboarding(); Represent represent = representRepository.findRepresentByOnboarding(onboarding); diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index b7833d72..5c0c2fd9 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -3,6 +3,7 @@ import hous.server.common.exception.ConflictException; import hous.server.common.exception.NotFoundException; import hous.server.common.exception.ValidationException; +import hous.server.domain.personality.PersonalityColor; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; @@ -38,4 +39,10 @@ public static void validatePushNotificationStatus(boolean state, boolean request VALIDATION_STATUS_EXCEPTION); } } + + public static void validatePersonalityColor(PersonalityColor color) { + if (color == PersonalityColor.GRAY) { + throw new NotFoundException("GRAY 에 대한 성향 정보는 존재하지 않습니다.", NOT_FOUND_PERSONALITY_COLOR_EXCEPTION); + } + } } diff --git a/src/main/java/hous/server/service/user/dto/response/PersonalityInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/PersonalityInfoResponse.java new file mode 100644 index 00000000..7a6a5570 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/PersonalityInfoResponse.java @@ -0,0 +1,49 @@ +package hous.server.service.user.dto.response; + +import hous.server.domain.personality.Personality; +import hous.server.domain.personality.PersonalityColor; +import lombok.*; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class PersonalityInfoResponse { + + private String name; + private String imageUrl; + private PersonalityColor color; + private String title; + private List description; + private String recommendTitle; + private List recommendTodo; + private String goodPersonalityName; + private String goodPersonalityImageUrl; + private String badPersonalityName; + private String badPersonalityImageUrl; + + public static PersonalityInfoResponse of(Personality personality) { + return PersonalityInfoResponse.builder() + .name(personality.getName()) + .imageUrl(personality.getImageUrl()) + .color(personality.getColor()) + .title(personality.getTitle()) + .description(splitToListByLineBreak(personality.getDescription())) + .recommendTitle(personality.getRecommendTitle()) + .recommendTodo(splitToListByLineBreak(personality.getRecommendTodo())) + .goodPersonalityName(personality.getGoodPersonalityName()) + .goodPersonalityImageUrl(personality.getGoodPersonalityImageUrl()) + .badPersonalityName(personality.getBadPersonalityName()) + .badPersonalityImageUrl(personality.getBadPersonalityImageUrl()) + .build(); + } + + private static List splitToListByLineBreak(String content) { + return Arrays.stream(content.split("\n")).collect(Collectors.toList()); + } +} From 2023f86a1b66878d1500ec18bc79dce068a35a23 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 15:29:30 +0900 Subject: [PATCH 097/301] =?UTF-8?q?#56=20[fix]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=EC=8B=9C=20TestScore=20=EA=B0=99=EC=9D=B4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=84=B1=ED=96=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=82=A0=EC=A7=9C=20=EB=B9=84=EA=B5=90=20updatedAt=20?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/domain/user/Onboarding.java | 5 +++-- .../java/hous/server/domain/user/TestScore.java | 16 +++++++++++++--- .../user/repository/SettingRepository.java | 7 +++++++ .../user/repository/SettingRepositoryCustom.java | 4 ++++ .../user/repository/SettingRepositoryImpl.java | 10 ++++++++++ .../user/repository/TestScoreRepository.java | 7 +++++++ .../repository/TestScoreRepositoryCustom.java | 4 ++++ .../user/repository/TestScoreRepositoryImpl.java | 10 ++++++++++ .../server/service/home/HomeRetrieveService.java | 2 +- .../server/service/todo/TodoRetrieveService.java | 4 ++-- .../server/service/todo/TodoServiceUtils.java | 2 +- .../hous/server/service/user/UserService.java | 12 +++++++++++- 12 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 src/main/java/hous/server/domain/user/repository/SettingRepository.java create mode 100644 src/main/java/hous/server/domain/user/repository/SettingRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/user/repository/SettingRepositoryImpl.java create mode 100644 src/main/java/hous/server/domain/user/repository/TestScoreRepository.java create mode 100644 src/main/java/hous/server/domain/user/repository/TestScoreRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/user/repository/TestScoreRepositoryImpl.java diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index ddffb0db..fb36a70f 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -55,7 +55,7 @@ public class Onboarding extends AuditingTimeEntity { private Represent represent; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "test_score_id") + @JoinColumn(name = "test_score_id", nullable = false) private TestScore testScore; @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @@ -65,10 +65,11 @@ public class Onboarding extends AuditingTimeEntity { @JoinColumn(name = "badge_id") private final List badges = new ArrayList<>(); - public static Onboarding newInstance(Personality personality) { + public static Onboarding newInstance(Personality personality, TestScore testScore) { return Onboarding.builder() .isChecked(false) .personality(personality) + .testScore(testScore) .build(); } diff --git a/src/main/java/hous/server/domain/user/TestScore.java b/src/main/java/hous/server/domain/user/TestScore.java index 57076874..90417c1e 100644 --- a/src/main/java/hous/server/domain/user/TestScore.java +++ b/src/main/java/hous/server/domain/user/TestScore.java @@ -1,15 +1,15 @@ package hous.server.domain.user; import hous.server.domain.common.AuditingTimeEntity; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class TestScore extends AuditingTimeEntity { @Id @@ -30,4 +30,14 @@ public class TestScore extends AuditingTimeEntity { @Column(nullable = false) private int introversion; + + public static TestScore newInstance() { + return TestScore.builder() + .light(0) + .noise(0) + .clean(0) + .smell(0) + .introversion(0) + .build(); + } } diff --git a/src/main/java/hous/server/domain/user/repository/SettingRepository.java b/src/main/java/hous/server/domain/user/repository/SettingRepository.java new file mode 100644 index 00000000..ab961135 --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/SettingRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.user.repository; + +import hous.server.domain.user.Setting; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface SettingRepository extends JpaRepository, SettingRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/user/repository/SettingRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/SettingRepositoryCustom.java new file mode 100644 index 00000000..8c6642cb --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/SettingRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.user.repository; + +public interface SettingRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/user/repository/SettingRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/SettingRepositoryImpl.java new file mode 100644 index 00000000..fcd901c5 --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/SettingRepositoryImpl.java @@ -0,0 +1,10 @@ +package hous.server.domain.user.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class SettingRepositoryImpl implements SettingRepositoryCustom { + + private final JPAQueryFactory queryFactory; +} diff --git a/src/main/java/hous/server/domain/user/repository/TestScoreRepository.java b/src/main/java/hous/server/domain/user/repository/TestScoreRepository.java new file mode 100644 index 00000000..c50f4c62 --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/TestScoreRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.user.repository; + +import hous.server.domain.user.TestScore; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TestScoreRepository extends JpaRepository, TestScoreRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/user/repository/TestScoreRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/TestScoreRepositoryCustom.java new file mode 100644 index 00000000..93f0a615 --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/TestScoreRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.user.repository; + +public interface TestScoreRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/user/repository/TestScoreRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/TestScoreRepositoryImpl.java new file mode 100644 index 00000000..69816550 --- /dev/null +++ b/src/main/java/hous/server/domain/user/repository/TestScoreRepositoryImpl.java @@ -0,0 +1,10 @@ +package hous.server.domain.user.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class TestScoreRepositoryImpl implements TestScoreRepositoryCustom { + + private final JPAQueryFactory queryFactory; +} diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index 02854bdb..8180920e 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -59,7 +59,7 @@ public HomeInfoResponse getHomeInfo(Long userId) { List rules = room.getRules(); List participants = room.getParticipates().stream() .map(Participate::getOnboarding) - .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) + .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getUpdatedAt())) .collect(Collectors.toList()); return HomeInfoResponse.of(user.getOnboarding(), room, today, todayMyTodos, todayOurTodos, rules, participants); } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index a0c1fe2a..a3534c14 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -39,7 +39,7 @@ public UserPersonalityInfoResponse getUsersInfo(Long userId) { List participates = room.getParticipates(); List onboardings = participates.stream() .map(Participate::getOnboarding) - .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) + .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getUpdatedAt())) .collect(Collectors.toList()); return UserPersonalityInfoResponse.of(onboardings); } @@ -77,7 +77,7 @@ public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { List participates = room.getParticipates(); List onboardings = participates.stream() .map(Participate::getOnboarding) - .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getCreatedAt())) + .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getUpdatedAt())) .collect(Collectors.toList()); List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(todo); return TodoInfoResponse.of(todo, userPersonalityInfos, onboardings); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 3fa4a69c..5988f586 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -46,7 +46,7 @@ public static void validateTodoStatus(DoneRepository doneRepository, boolean sta public static List toUserPersonalityInfoList(Todo todo) { return todo.getTakes().stream() - .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getCreatedAt())) + .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getUpdatedAt())) .map(take -> UserPersonalityInfo.of( take.getOnboarding().getId(), take.getOnboarding().getPersonality().getColor(), diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 73fe5d72..d2757646 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -4,7 +4,11 @@ import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.Setting; +import hous.server.domain.user.TestScore; import hous.server.domain.user.User; +import hous.server.domain.user.repository.OnboardingRepository; +import hous.server.domain.user.repository.SettingRepository; +import hous.server.domain.user.repository.TestScoreRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.request.CreateUserDto; @@ -20,12 +24,18 @@ public class UserService { private final UserRepository userRepository; + private final OnboardingRepository onboardingRepository; + private final SettingRepository settingRepository; + private final TestScoreRepository testScoreRepository; private final PersonalityRepository personalityRepository; public Long registerUser(CreateUserDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), - Onboarding.newInstance(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY)), Setting.newInstance())); + onboardingRepository.save( + Onboarding.newInstance(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), + testScoreRepository.save(TestScore.newInstance()))), + settingRepository.save(Setting.newInstance()))); return user.getId(); } From 38ecff3d723c2d8487889303c39fc25549b29bdf Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 15:30:00 +0900 Subject: [PATCH 098/301] =?UTF-8?q?#56=20[fix]=20access=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/rule/Rule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index 694130d3..ec270540 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -10,7 +10,7 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) public class Rule extends AuditingTimeEntity { From 4a53ea7c3b7298234dd5812c3db22b416088ab56 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 16:40:04 +0900 Subject: [PATCH 099/301] =?UTF-8?q?#56=20[feat]=20=EB=B0=A9=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC=ED=95=98=EA=B8=B0=20api=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RoomController.java | 22 +++++++ .../hous/server/domain/badge/Represent.java | 4 +- .../java/hous/server/domain/room/Room.java | 7 +- .../java/hous/server/domain/todo/Todo.java | 4 ++ .../hous/server/domain/user/Onboarding.java | 20 ++++++ .../hous/server/domain/user/TestScore.java | 13 ++++ .../hous/server/service/room/RoomService.java | 66 +++++++++++++++++++ .../server/service/todo/TodoServiceUtils.java | 19 ++++++ 8 files changed, 152 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index a13100eb..47757b39 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -101,4 +101,26 @@ public ResponseEntity updateRoomName(@Valid @RequestBody SetRoomNameRequ roomService.updateRoomName(request, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 마이 페이지(설정) - 방에서 퇴사합니다.", + notes = "성공시 status code = 204, 빈 response body로 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @DeleteMapping("/room/leave") + public ResponseEntity leaveRoom(@ApiIgnore @UserId Long userId) { + roomService.leaveRoom(userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/badge/Represent.java b/src/main/java/hous/server/domain/badge/Represent.java index 5f17c007..de856db7 100644 --- a/src/main/java/hous/server/domain/badge/Represent.java +++ b/src/main/java/hous/server/domain/badge/Represent.java @@ -17,11 +17,11 @@ public class Represent extends AuditingTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "onboarding_id") private Onboarding onboarding; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "badge_id") private Badge badge; } diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index 65b98f36..84a94cc5 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -22,7 +22,7 @@ public class Room extends AuditingTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "onboarding_id", nullable = false) private Onboarding owner; @@ -80,6 +80,11 @@ public void addParticipate(Participate participate) { this.participantsCnt += 1; } + public void deleteParticipate(Participate participate) { + this.participates.remove(participate); + this.participantsCnt -= 1; + } + public void addRule(Rule rule) { this.rules.add(rule); this.rulesCnt += 1; diff --git a/src/main/java/hous/server/domain/todo/Todo.java b/src/main/java/hous/server/domain/todo/Todo.java index 04758ce0..2b3e9928 100644 --- a/src/main/java/hous/server/domain/todo/Todo.java +++ b/src/main/java/hous/server/domain/todo/Todo.java @@ -66,6 +66,10 @@ public void addDone(Done done) { this.dones.add(done); } + public void deleteTake(Take take) { + this.takes.remove(take); + } + public void deleteDone(Done done) { this.dones.remove(done); } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index fb36a70f..1c34c80b 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -84,6 +84,10 @@ public void addParticipate(Participate participate) { this.participates.add(participate); } + public void deleteParticipate(Participate participate) { + this.participates.remove(participate); + } + public void setUserInfo(UpdateUserInfoRequestDto request) { this.nickname = request.getNickname(); this.isPublic = request.isPublic(); @@ -92,4 +96,20 @@ public void setUserInfo(UpdateUserInfoRequestDto request) { this.job = request.getJob(); this.introduction = request.getIntroduction(); } + + public void resetUserInfo() { + this.isPublic = false; + this.mbti = null; + this.job = null; + this.introduction = null; + } + + public void resetBadge() { + this.represent = null; + this.badges.clear(); + } + + public void resetTestScore(TestScore testScore) { + this.testScore = testScore.resetScore(testScore); + } } diff --git a/src/main/java/hous/server/domain/user/TestScore.java b/src/main/java/hous/server/domain/user/TestScore.java index 90417c1e..06a6a5ce 100644 --- a/src/main/java/hous/server/domain/user/TestScore.java +++ b/src/main/java/hous/server/domain/user/TestScore.java @@ -40,4 +40,17 @@ public static TestScore newInstance() { .introversion(0) .build(); } + + public void updateScore(int light, int noise, int clean, int smell, int introversion) { + this.light = light; + this.noise = noise; + this.clean = clean; + this.smell = smell; + this.introversion = introversion; + } + + public TestScore resetScore(TestScore testScore) { + testScore.updateScore(0, 0, 0, 0, 0); + return testScore; + } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index d4ecda5d..b1b0275d 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -1,19 +1,30 @@ package hous.server.service.room; +import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; import hous.server.domain.room.repository.RoomRepository; +import hous.server.domain.todo.Done; +import hous.server.domain.todo.Take; +import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; +import hous.server.domain.todo.repository.TakeRepository; +import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.dto.request.SetRoomNameRequestDto; import hous.server.service.room.dto.response.RoomInfoResponse; +import hous.server.service.todo.TodoServiceUtils; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.Optional; + @RequiredArgsConstructor @Service @Transactional @@ -22,6 +33,10 @@ public class RoomService { private final UserRepository userRepository; private final RoomRepository roomRepository; private final ParticipateRepository participateRepository; + private final TodoRepository todoRepository; + private final TakeRepository takeRepository; + private final DoneRepository doneRepository; + private final RepresentRepository representRepository; public RoomInfoResponse createRoom(SetRoomNameRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -51,4 +66,55 @@ public void updateRoomName(SetRoomNameRequestDto request, Long userId) { Room room = RoomServiceUtils.findParticipatingRoom(user); room.updateRoomName(request.getName()); } + + public void leaveRoom(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + Onboarding me = user.getOnboarding(); + + List todos = room.getTodos(); + List myTodos = TodoServiceUtils.filterMyTodos(me, todos); + myTodos.forEach(todo -> { + // todo 담당자가 여러명이면 나의 담당 해제 + if (todo.getTakes().size() > 1) { + Optional myTake = todo.getTakes().stream() + .filter(take -> take.getOnboarding().getId().equals(me.getId())) + .findFirst(); + if (myTake.isPresent()) { + List myDones = TodoServiceUtils.filterMyDones(me, todo.getDones()); + takeRepository.delete(myTake.get()); + myDones.forEach(todo::deleteDone); + doneRepository.deleteAll(myDones); + todo.deleteTake(myTake.get()); + } + } + // todo 담당자가 나뿐이면 todo 삭제 + else { + Todo myTodo = myTodos.get(0); + room.deleteTodo(myTodo); + todoRepository.delete(myTodo); + } + }); + + // 방의 참가자가 여러명이면 나만 방을 나감 + List participates = room.getParticipates(); + if (participates.size() > 1) { + room.deleteParticipate(participates.get(0)); + me.deleteParticipate(participates.get(0)); + participateRepository.delete(participates.get(0)); + } + // 방의 참가자가 나 혼자면 방을 나가고 삭제 + else { + me.deleteParticipate(participates.get(0)); + roomRepository.delete(room); + } + + //내 뱃지, 프로필 작성 내역, 테스트 결과 초기화 + if (me.getRepresent() != null) { + representRepository.delete(me.getRepresent()); + } + me.resetUserInfo(); + me.resetBadge(); + me.resetTestScore(me.getTestScore()); + } } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 5988f586..f3fcc538 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -5,6 +5,7 @@ import hous.server.common.exception.ValidationException; import hous.server.common.util.DateUtils; import hous.server.domain.room.Room; +import hous.server.domain.todo.Done; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.todo.repository.TodoRepository; @@ -110,4 +111,22 @@ public static List filterTodayMyTodos(LocalDate today, Onboarding me, List }); return todayMyTodosList; } + + public static List filterMyTodos(Onboarding me, List todos) { + List myTodos = new ArrayList<>(); + todos.forEach(todo -> { + todo.getTakes().forEach(take -> { + if (take.getOnboarding().getId().equals(me.getId())) { + myTodos.add(todo); + } + }); + }); + return myTodos; + } + + public static List filterMyDones(Onboarding me, List dones) { + return dones.stream() + .filter(done -> done.getOnboarding().getId().equals(me.getId())) + .collect(Collectors.toList()); + } } From a68a39311678cac661a362be09320f1b8d6caa2b Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 17:00:59 +0900 Subject: [PATCH 100/301] =?UTF-8?q?#56=20[refactor]=20Entity=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/room/Participate.java | 13 +++-------- .../java/hous/server/domain/room/Room.java | 17 +++----------- .../java/hous/server/domain/todo/Done.java | 2 +- .../java/hous/server/domain/todo/Redo.java | 13 +++-------- .../java/hous/server/domain/todo/Take.java | 13 +++-------- .../java/hous/server/domain/todo/Todo.java | 14 +++--------- .../hous/server/domain/user/Onboarding.java | 4 ++-- .../java/hous/server/domain/user/Setting.java | 12 +++------- .../java/hous/server/domain/user/User.java | 22 +++++++++---------- 9 files changed, 31 insertions(+), 79 deletions(-) diff --git a/src/main/java/hous/server/domain/room/Participate.java b/src/main/java/hous/server/domain/room/Participate.java index 240199a8..40e4bc47 100644 --- a/src/main/java/hous/server/domain/room/Participate.java +++ b/src/main/java/hous/server/domain/room/Participate.java @@ -2,16 +2,15 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Participate extends AuditingTimeEntity { @Id @@ -26,12 +25,6 @@ public class Participate extends AuditingTimeEntity { @JoinColumn(name = "room_id") private Room room; - @Builder(access = AccessLevel.PRIVATE) - public Participate(Onboarding onboarding, Room room) { - this.onboarding = onboarding; - this.room = room; - } - public static Participate newInstance(Onboarding onboarding, Room room) { return Participate.builder() .onboarding(onboarding) diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index 84a94cc5..79d09467 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -4,10 +4,7 @@ import hous.server.domain.rule.Rule; import hous.server.domain.todo.Todo; import hous.server.domain.user.Onboarding; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; import java.util.ArrayList; @@ -16,6 +13,8 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Room extends AuditingTimeEntity { @Id @@ -50,16 +49,6 @@ public class Room extends AuditingTimeEntity { @OneToMany(mappedBy = "room", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List todos = new ArrayList<>(); - @Builder(access = AccessLevel.PRIVATE) - public Room(Onboarding owner, String name, String code, int participantsCnt, int rulesCnt, int todosCnt) { - this.owner = owner; - this.name = name; - this.code = code; - this.participantsCnt = participantsCnt; - this.rulesCnt = rulesCnt; - this.todosCnt = todosCnt; - } - public static Room newInstance(Onboarding owner, String name, String code) { return Room.builder() .owner(owner) diff --git a/src/main/java/hous/server/domain/todo/Done.java b/src/main/java/hous/server/domain/todo/Done.java index 187db42d..c0972423 100644 --- a/src/main/java/hous/server/domain/todo/Done.java +++ b/src/main/java/hous/server/domain/todo/Done.java @@ -9,7 +9,7 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) public class Done extends AuditingTimeEntity { diff --git a/src/main/java/hous/server/domain/todo/Redo.java b/src/main/java/hous/server/domain/todo/Redo.java index 568ec4ff..085b1a29 100644 --- a/src/main/java/hous/server/domain/todo/Redo.java +++ b/src/main/java/hous/server/domain/todo/Redo.java @@ -1,16 +1,15 @@ package hous.server.domain.todo; import hous.server.domain.common.AuditingTimeEntity; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Redo extends AuditingTimeEntity { @Id @@ -25,12 +24,6 @@ public class Redo extends AuditingTimeEntity { @Enumerated(EnumType.STRING) private DayOfWeek dayOfWeek; - @Builder(access = AccessLevel.PRIVATE) - public Redo(Take take, DayOfWeek dayOfWeek) { - this.take = take; - this.dayOfWeek = dayOfWeek; - } - public static Redo newInstance(Take take, DayOfWeek dayOfWeek) { return Redo.builder() .take(take) diff --git a/src/main/java/hous/server/domain/todo/Take.java b/src/main/java/hous/server/domain/todo/Take.java index f6f13a48..8fcb05c4 100644 --- a/src/main/java/hous/server/domain/todo/Take.java +++ b/src/main/java/hous/server/domain/todo/Take.java @@ -2,10 +2,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; import java.util.ArrayList; @@ -14,6 +11,8 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Take extends AuditingTimeEntity { @Id @@ -31,12 +30,6 @@ public class Take extends AuditingTimeEntity { @OneToMany(mappedBy = "take", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List redos = new ArrayList<>(); - @Builder(access = AccessLevel.PRIVATE) - public Take(Todo todo, Onboarding onboarding) { - this.todo = todo; - this.onboarding = onboarding; - } - public static Take newInstance(Todo todo, Onboarding onboarding) { return Take.builder() .todo(todo) diff --git a/src/main/java/hous/server/domain/todo/Todo.java b/src/main/java/hous/server/domain/todo/Todo.java index 2b3e9928..4768eb2c 100644 --- a/src/main/java/hous/server/domain/todo/Todo.java +++ b/src/main/java/hous/server/domain/todo/Todo.java @@ -2,10 +2,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Room; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; import java.util.ArrayList; @@ -14,6 +11,8 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Todo extends AuditingTimeEntity { @Id @@ -36,13 +35,6 @@ public class Todo extends AuditingTimeEntity { @OneToMany(mappedBy = "todo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List dones = new ArrayList<>(); - @Builder(access = AccessLevel.PRIVATE) - public Todo(Room room, String name, boolean isPushNotification) { - this.room = room; - this.name = name; - this.isPushNotification = isPushNotification; - } - public static Todo newInstance(Room room, String name, boolean isPushNotification) { return Todo.builder() .room(room) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 1c34c80b..a9f772bc 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -16,9 +16,9 @@ @Getter @Entity -@Builder(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Onboarding extends AuditingTimeEntity { @Id diff --git a/src/main/java/hous/server/domain/user/Setting.java b/src/main/java/hous/server/domain/user/Setting.java index 686a6251..e4d8ab77 100644 --- a/src/main/java/hous/server/domain/user/Setting.java +++ b/src/main/java/hous/server/domain/user/Setting.java @@ -1,16 +1,15 @@ package hous.server.domain.user; import hous.server.domain.common.AuditingTimeEntity; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Setting extends AuditingTimeEntity { @Id @@ -20,11 +19,6 @@ public class Setting extends AuditingTimeEntity { @Column(nullable = false) private boolean isPushNotification; - @Builder(access = AccessLevel.PRIVATE) - public Setting(boolean isPushNotification) { - this.isPushNotification = isPushNotification; - } - public static Setting newInstance() { return Setting.builder() .isPushNotification(true) diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index 719a403f..7bd5fe59 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -1,15 +1,15 @@ package hous.server.domain.user; import hous.server.domain.common.AuditingTimeEntity; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class User extends AuditingTimeEntity { @Id @@ -34,15 +34,13 @@ public class User extends AuditingTimeEntity { @JoinColumn(name = "setting_id", nullable = false) private Setting setting; - private User(String socialId, UserSocialType socialType, String fcmToken, Onboarding onboarding, Setting setting) { - this.socialInfo = SocialInfo.of(socialId, socialType); - this.fcmToken = fcmToken; - this.status = UserStatus.ACTIVE; - this.onboarding = onboarding; - this.setting = setting; - } - public static User newInstance(String socialId, UserSocialType socialType, String fcmToken, Onboarding onboarding, Setting setting) { - return new User(socialId, socialType, fcmToken, onboarding, setting); + return User.builder() + .socialInfo(SocialInfo.of(socialId, socialType)) + .fcmToken(fcmToken) + .onboarding(onboarding) + .setting(setting) + .status(UserStatus.ACTIVE) + .build(); } } From ecc224d6a978d742ce95e99bbb17c40fda4da520 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 17:04:27 +0900 Subject: [PATCH 101/301] =?UTF-8?q?#56=20[fix]=20#55=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/common/success/SuccessCode.java | 2 +- .../server/controller/user/UserRetrieveController.java | 10 +++++----- .../hous/server/service/user/UserRetrieveService.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 17d2169c..6210499b 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -43,7 +43,7 @@ public enum SuccessCode { GET_HOMIE_PROFILE_INFO_SUCCESS(OK, "호미 프로필 정보 조회 성공입니다."), // 성향 - GET_HOMIE_PERSONALITY_INFO_SUCCESS(OK, "호미 성향 정보 조회 성공입니다."), + GET_PERSONALITY_INFO_SUCCESS(OK, "성향 정보 조회 성공입니다."), /** * 201 CREATED diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index c4d396a9..d9520daa 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -76,20 +76,20 @@ public ResponseEntity getHomieInfo(@ApiParam(name = "homieId", } @ApiOperation( - value = "[인증] 룸메이트 정보 페이지(Hous 뷰에서 호미 카드 클릭) - 룸메이트 성향 정보를 확인합니다.", + value = "[인증] 룸메이트 정보 페이지(Hous 뷰에서 호미 카드 클릭) - 성향 정보를 확인합니다.", notes = "color 쿼리에 조회할 성향 색깔을 담아서 요청을 보냅니다.\n" + "GRAY 에 대한 정보는 존재하지 않기 때문에 404 에러를 전달합니다." ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "룸메이트 성향 정보 조회 성공입니다."), + @ApiResponse(code = 200, message = "성향 정보 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "GRAY 에 대한 성향 정보는 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @GetMapping("/user/personality") - public ResponseEntity getHomiePersonalityInfo(@ApiParam(name = "color", value = "조회할 성향 색깔", required = true, example = "RED") - @RequestParam PersonalityColor color) { - return SuccessResponse.success(SuccessCode.GET_HOMIE_PERSONALITY_INFO_SUCCESS, userRetrieveService.getHomiePersonalityInfo(color)); + public ResponseEntity getPersonalityInfo(@ApiParam(name = "color", value = "조회할 성향 색깔", required = true, example = "RED") + @RequestParam PersonalityColor color) { + return SuccessResponse.success(SuccessCode.GET_PERSONALITY_INFO_SUCCESS, userRetrieveService.getPersonalityInfo(color)); } } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 5cbc8d3f..59292941 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -49,7 +49,7 @@ public UserInfoResponse getHomieInfo(Long homieId, Long userId) { return getProfileInfoByUser(homie); } - public PersonalityInfoResponse getHomiePersonalityInfo(PersonalityColor color) { + public PersonalityInfoResponse getPersonalityInfo(PersonalityColor color) { UserServiceUtils.validatePersonalityColor(color); Personality personality = personalityRepository.findPersonalityByColor(color); return PersonalityInfoResponse.of(personality); From 887e64899aedde258f53be006265bd8eb8d47891 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 17:26:33 +0900 Subject: [PATCH 102/301] =?UTF-8?q?#56=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/room/RoomService.java | 4 +-- .../service/todo/TodoRetrieveService.java | 2 +- .../server/service/todo/TodoServiceUtils.java | 28 ++++++------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index b1b0275d..b26bdc5b 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -73,7 +73,7 @@ public void leaveRoom(Long userId) { Onboarding me = user.getOnboarding(); List todos = room.getTodos(); - List myTodos = TodoServiceUtils.filterMyTodos(me, todos); + List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); myTodos.forEach(todo -> { // todo 담당자가 여러명이면 나의 담당 해제 if (todo.getTakes().size() > 1) { @@ -81,7 +81,7 @@ public void leaveRoom(Long userId) { .filter(take -> take.getOnboarding().getId().equals(me.getId())) .findFirst(); if (myTake.isPresent()) { - List myDones = TodoServiceUtils.filterMyDones(me, todo.getDones()); + List myDones = TodoServiceUtils.filterAllDaysMyDones(me, todo.getDones()); takeRepository.delete(myTake.get()); myDones.forEach(todo::deleteDone); doneRepository.deleteAll(myDones); diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index a3534c14..251a5af0 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -98,7 +98,7 @@ public List getTodoAllDayInfo(Long userId) { // 이 방의 모든 요일의 todo list 조회 List ourTodosList = TodoServiceUtils.filterAllDaysOurTodos(todos); - List myTodosList = TodoServiceUtils.filterAllDaysMyTodos(todos, user.getOnboarding()); + List myTodosList = TodoServiceUtils.filterAllDaysUserTodos(todos, user.getOnboarding()); // 요일별(index) todo list 형태로 가공 List[] allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToList(ourTodosList); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index f3fcc538..8e71b761 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -77,16 +77,22 @@ public static List filterAllDaysOurTodos(List todos) { return allDaysOurTodosList; } - public static List filterAllDaysMyTodos(List todos, Onboarding me) { + public static List filterAllDaysUserTodos(List todos, Onboarding onboarding) { List myTodosList = new ArrayList<>(); todos.forEach(todo -> todo.getTakes().forEach(take -> { - if (take.getOnboarding().getId().equals(me.getId())) { + if (take.getOnboarding().getId().equals(onboarding.getId())) { myTodosList.add(todo); } })); return myTodosList; } + public static List filterAllDaysMyDones(Onboarding me, List dones) { + return dones.stream() + .filter(done -> done.getOnboarding().getId().equals(me.getId())) + .collect(Collectors.toList()); + } + public static List[] mapByDayOfWeekToList(List todos) { List[] todosList = new ArrayList[8]; for (int index = 0; index < 8; index++) { @@ -111,22 +117,4 @@ public static List filterTodayMyTodos(LocalDate today, Onboarding me, List }); return todayMyTodosList; } - - public static List filterMyTodos(Onboarding me, List todos) { - List myTodos = new ArrayList<>(); - todos.forEach(todo -> { - todo.getTakes().forEach(take -> { - if (take.getOnboarding().getId().equals(me.getId())) { - myTodos.add(todo); - } - }); - }); - return myTodos; - } - - public static List filterMyDones(Onboarding me, List dones) { - return dones.stream() - .filter(done -> done.getOnboarding().getId().equals(me.getId())) - .collect(Collectors.toList()); - } } From 5beb0f2a3875a52e86b4c417b0d2d21a3995717e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 8 Sep 2022 17:40:19 +0900 Subject: [PATCH 103/301] =?UTF-8?q?#52=20[feat]=20todo=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../todo/TodoRetrieveController.java | 20 ++++++ .../service/home/HomeRetrieveService.java | 2 +- .../service/todo/TodoRetrieveService.java | 69 ++++++++++++------- .../server/service/todo/TodoServiceUtils.java | 18 +++-- .../todo/dto/response/DayOfWeekTodo.java | 24 +++++++ .../service/todo/dto/response/OurTodo.java | 6 +- .../todo/dto/response/OurTodoInfo.java | 6 +- .../dto/response/TodoAllMemberResponse.java | 41 +++++++++++ 9 files changed, 149 insertions(+), 38 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 6210499b..fdbfd9b7 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -34,6 +34,7 @@ public enum SuccessCode { GET_TODO_SUMMARY_INFO_SUCCESS(OK, "todo 요약 정보 조회 성공입니다."), GET_TODO_MAIN_SUCCESS(OK, "todo 메인 페이지 조회 성공입니다."), GET_TODO_ALL_DAY_SUCCESS(OK, "todo 요일별 정보 조회 성공입니다."), + GET_TODO_ALL_MEMBER_SUCCESS(OK, "todo 멤버별 정보 조회 성공입니다."), // rule GET_RULE_INFO_SUCCESS(OK, "규칙 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index b22e6c17..9adef25f 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -131,4 +131,24 @@ public ResponseEntity getTodoSummaryInfo(@ApiParam(name public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_ALL_DAY_SUCCESS, todoRetrieveService.getTodoAllDayInfo(userId)); } + + @ApiOperation( + value = "[인증] todo 전체 보기 페이지 - 멤버별 todo를 조회합니다.", + notes = "방 내 모든 멤버의 요일별 todo를 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "todo 멤버별 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 todo 입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/todos/member") + public ResponseEntity> getTodoAllMemberInfo(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_TODO_ALL_MEMBER_SUCCESS, todoRetrieveService.getTodoAllMemberInfo(userId)); + } } diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index 8180920e..ba49adbb 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -54,7 +54,7 @@ public HomeInfoResponse getHomeInfo(Long userId) { doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() .map(take -> take.getOnboarding().getNickname()) - .collect(Collectors.toList()))) + .collect(Collectors.toSet()))) .collect(Collectors.toList()); List rules = room.getRules(); List participants = room.getParticipates().stream() diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 251a5af0..ceb84a0b 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -2,6 +2,7 @@ import hous.server.common.util.DateUtils; import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.personality.PersonalityColor; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.todo.DayOfWeek; @@ -51,22 +52,8 @@ public TodoMainResponse getTodoMain(Long userId) { List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(today, todos); List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(today, user.getOnboarding(), todos); - List todayMyTodos = todayMyTodosList.stream() - .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> MyTodoInfo.of( - todo.getId(), - todo.getName(), - doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))) - .collect(Collectors.toList()); - List todayOurTodos = todayOurTodosList.stream() - .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> OurTodoInfo.of( - todo.getName(), - doneRepository.findTodayOurTodoStatus(today, todo), - todo.getTakes().stream() - .map(take -> take.getOnboarding().getNickname()) - .collect(Collectors.toList()))) - .collect(Collectors.toList()); + List todayMyTodos = todayMyTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> MyTodoInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))).collect(Collectors.toList()); + List todayOurTodos = todayOurTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream().map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))).collect(Collectors.toList()); return TodoMainResponse.of(today, todayMyTodos, todayOurTodos); } @@ -110,20 +97,54 @@ public List getTodoAllDayInfo(Long userId) { String dayOfWeek = DayOfWeek.getValueByIndex(i); List myTodoInfos = allDayMyTodosList[i].stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> MyTodo.of( - todo.getId(), - todo.getName())) + .map(todo -> MyTodo.of(todo.getId(), todo.getName())) .collect(Collectors.toList()); List ourTodoInfos = allDayOurTodosList[i].stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> OurTodo.of( - todo.getName(), - todo.getTakes().stream() - .map(take -> take.getOnboarding().getNickname()) - .collect(Collectors.toList()))) + .map(todo -> OurTodo.of(todo.getName(), todo.getTakes().stream() + .map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))) .collect(Collectors.toList()); allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, myTodoInfos, ourTodoInfos)); } return allDayTodosList; } + + public List getTodoAllMemberInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + List todos = room.getTodos(); + + List allMemberTodos = new ArrayList<>(); + List otherMemberTodos = new ArrayList<>(); + + // 성향테스트 참여 순서로 정렬 + room.getParticipates().stream().sorted( + Comparator.comparing(participate -> participate.getOnboarding().getTestScore().getUpdatedAt()) + ).forEach(participate -> { + List memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); + + List[] allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos); + + List dayOfWeekTodos = new ArrayList<>(); + int totalTodoCnt = 0; + for (int i = 1; i < allDayMemberTodos.length; i++) { + String dayOfWeek = DayOfWeek.getValueByIndex(i); + List thisDayTodosName = allDayMemberTodos[i].stream().map(Todo::getName).collect(Collectors.toList()); + dayOfWeekTodos.add(DayOfWeekTodo.of(dayOfWeek, thisDayTodosName.size(), thisDayTodosName)); + totalTodoCnt += thisDayTodosName.size(); + } + + String userName = participate.getOnboarding().getNickname(); + PersonalityColor color = participate.getOnboarding().getPersonality().getColor(); + + if (user.getOnboarding().equals(participate.getOnboarding())) { + allMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); + } else { + otherMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); + } + }); + allMemberTodos.addAll(otherMemberTodos); + + return allMemberTodos; + } } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 8e71b761..03b4d646 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -78,13 +78,13 @@ public static List filterAllDaysOurTodos(List todos) { } public static List filterAllDaysUserTodos(List todos, Onboarding onboarding) { - List myTodosList = new ArrayList<>(); + List userTodosList = new ArrayList<>(); todos.forEach(todo -> todo.getTakes().forEach(take -> { if (take.getOnboarding().getId().equals(onboarding.getId())) { - myTodosList.add(todo); + userTodosList.add(todo); } })); - return myTodosList; + return userTodosList; } public static List filterAllDaysMyDones(Onboarding me, List dones) { @@ -98,10 +98,14 @@ public static List[] mapByDayOfWeekToList(List todos) { for (int index = 0; index < 8; index++) { todosList[index] = new ArrayList<>(); } - todos.forEach(todo -> todo.getTakes().forEach(take -> { - take.getRedos().forEach(redo -> - todosList[redo.getDayOfWeek().getIndex()].add(todo)); - })); + todos.forEach(todo -> todo.getTakes().forEach(take -> + take.getRedos().forEach(redo -> + { + if (!todosList[redo.getDayOfWeek().getIndex()].contains(todo)) { + todosList[redo.getDayOfWeek().getIndex()].add(todo); + } + }) + )); return todosList; } diff --git a/src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java b/src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java new file mode 100644 index 00000000..896e96fe --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java @@ -0,0 +1,24 @@ +package hous.server.service.todo.dto.response; + +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class DayOfWeekTodo { + private String dayOfWeek; + private int todoCnt; + private List dayOfWeekTodos; + + public static DayOfWeekTodo of(String dayOfWeek, int todoCnt, List dayOfWeekTodos) { + return DayOfWeekTodo.builder() + .dayOfWeek(dayOfWeek) + .todoCnt(todoCnt) + .dayOfWeekTodos(dayOfWeekTodos) + .build(); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java index 9b453f12..3eb6f97d 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java @@ -2,7 +2,7 @@ import lombok.*; -import java.util.List; +import java.util.Set; @ToString @Getter @@ -12,9 +12,9 @@ public class OurTodo { private String todoName; - private List nicknames; + private Set nicknames; - public static OurTodo of(String todoName, List nicknames) { + public static OurTodo of(String todoName, Set nicknames) { return OurTodo.builder() .todoName(todoName) .nicknames(nicknames) diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java index 08bf6f3c..8b4b6e20 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java @@ -3,7 +3,7 @@ import hous.server.domain.todo.OurTodoStatus; import lombok.*; -import java.util.List; +import java.util.Set; @ToString @Getter @@ -13,12 +13,12 @@ public class OurTodoInfo extends OurTodo { private OurTodoStatus status; @Builder(access = AccessLevel.PRIVATE) - public OurTodoInfo(String todoName, List nicknames, OurTodoStatus status) { + public OurTodoInfo(String todoName, Set nicknames, OurTodoStatus status) { super(todoName, nicknames); this.status = status; } - public static OurTodoInfo of(String todoName, OurTodoStatus status, List nicknames) { + public static OurTodoInfo of(String todoName, OurTodoStatus status, Set nicknames) { return OurTodoInfo.builder() .todoName(todoName) .status(status) diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java new file mode 100644 index 00000000..1e699176 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java @@ -0,0 +1,41 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.user.Onboarding; +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class TodoAllMemberResponse { + + private String userName; + private PersonalityColor color; + private int totalTodoCnt; + private List dayOfWeekTodos; + + public static TodoAllMemberResponse of(String userName, PersonalityColor color, int totalTodoCnt, List dayOfWeekTodos) { + return TodoAllMemberResponse.builder() + .userName(userName) + .color(color) + .totalTodoCnt(totalTodoCnt) + .dayOfWeekTodos(dayOfWeekTodos) + .build(); + } + + public static List sortMeFirst(List allMemberTodosList, Onboarding me) { + for (int i = 0; i < allMemberTodosList.size(); i++) { + if (allMemberTodosList.get(i).getUserName().equals(me.getNickname())) { + TodoAllMemberResponse todoInfo = allMemberTodosList.get(i); + allMemberTodosList.remove(i); + allMemberTodosList.add(0, todoInfo); + break; + } + } + return allMemberTodosList; + } +} From 73915fefcd109b78240aa14c56b02b1354f240de Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 8 Sep 2022 17:47:04 +0900 Subject: [PATCH 104/301] =?UTF-8?q?#52=20[fix]=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=AA=85=EC=84=B8=EC=84=9C=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/controller/todo/TodoRetrieveController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 9adef25f..420dff4f 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -142,7 +142,8 @@ public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @Us @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" - + "2. 존재하지 않는 todo 입니다.", + + "2. 존재하지 않는 todo 입니다.\n" + + "3. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) From a8672e234240a12b6bf1867a8f3cbe5f486780c8 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 8 Sep 2022 18:02:15 +0900 Subject: [PATCH 105/301] =?UTF-8?q?#52=20[fix]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/dto/response/TodoAllMemberResponse.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java index 1e699176..4380dfd7 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java @@ -1,7 +1,6 @@ package hous.server.service.todo.dto.response; import hous.server.domain.personality.PersonalityColor; -import hous.server.domain.user.Onboarding; import lombok.*; import java.util.List; @@ -26,16 +25,4 @@ public static TodoAllMemberResponse of(String userName, PersonalityColor color, .dayOfWeekTodos(dayOfWeekTodos) .build(); } - - public static List sortMeFirst(List allMemberTodosList, Onboarding me) { - for (int i = 0; i < allMemberTodosList.size(); i++) { - if (allMemberTodosList.get(i).getUserName().equals(me.getNickname())) { - TodoAllMemberResponse todoInfo = allMemberTodosList.get(i); - allMemberTodosList.remove(i); - allMemberTodosList.add(0, todoInfo); - break; - } - } - return allMemberTodosList; - } } From 95201760c7da53a51231cd3f142d7300493d6c97 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 8 Sep 2022 20:23:15 +0900 Subject: [PATCH 106/301] =?UTF-8?q?#61=20[feat]=20=EC=84=B1=ED=96=A5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=82=B4=EC=9A=A9=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../user/UserRetrieveController.java | 18 ++++++++ .../repository/PersonalityTestRepository.java | 7 +++ .../service/user/UserRetrieveService.java | 18 ++++++++ .../response/PersonalityTestInfoResponse.java | 44 +++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java create mode 100644 src/main/java/hous/server/service/user/dto/response/PersonalityTestInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index fdbfd9b7..876872ee 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -45,6 +45,7 @@ public enum SuccessCode { // 성향 GET_PERSONALITY_INFO_SUCCESS(OK, "성향 정보 조회 성공입니다."), + GET_PERSONALITY_TEST_INFO_SUCCESS(OK, "성향테스트 정보 조회 성공입니다."), /** * 201 CREATED diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index d9520daa..2b891663 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -9,6 +9,7 @@ import hous.server.service.user.UserRetrieveService; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; import hous.server.service.user.dto.response.PersonalityInfoResponse; +import hous.server.service.user.dto.response.PersonalityTestInfoResponse; import hous.server.service.user.dto.response.UserInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; @@ -16,6 +17,8 @@ import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import java.util.List; + @Api(tags = "User") @RequiredArgsConstructor @RestController @@ -92,4 +95,19 @@ public ResponseEntity getPersonalityInfo(@ApiParam(name @RequestParam PersonalityColor color) { return SuccessResponse.success(SuccessCode.GET_PERSONALITY_INFO_SUCCESS, userRetrieveService.getPersonalityInfo(color)); } + + @ApiOperation( + value = "[인증] 마이 페이지(Profile 뷰) - 성향테스트 정보를 조회합니다.", + notes = "15 개의 질문을 리스트에 순서대로 담아서 테스트 내용을 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "성향테스트 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/user/personality/test") + public ResponseEntity> getPersonalityTestInfo() { + return SuccessResponse.success(SuccessCode.GET_PERSONALITY_TEST_INFO_SUCCESS, userRetrieveService.getPersonalityTestInfo()); + } } diff --git a/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java new file mode 100644 index 00000000..157e3322 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.personality.repository; + +import hous.server.domain.personality.PersonalityTest; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PersonalityTestRepository extends JpaRepository { +} diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 59292941..54759bbd 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -4,7 +4,9 @@ import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.personality.PersonalityTest; import hous.server.domain.personality.repository.PersonalityRepository; +import hous.server.domain.personality.repository.PersonalityTestRepository; import hous.server.domain.room.Room; import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.user.Onboarding; @@ -13,11 +15,16 @@ import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; import hous.server.service.user.dto.response.PersonalityInfoResponse; +import hous.server.service.user.dto.response.PersonalityTestInfoResponse; import hous.server.service.user.dto.response.UserInfoResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + @RequiredArgsConstructor @Service @Transactional(readOnly = true) @@ -25,6 +32,7 @@ public class UserRetrieveService { private final UserRepository userRepository; private final PersonalityRepository personalityRepository; + private final PersonalityTestRepository personalityTestRepository; private final RepresentRepository representRepository; private final RoomRepository roomRepository; @@ -55,6 +63,16 @@ public PersonalityInfoResponse getPersonalityInfo(PersonalityColor color) { return PersonalityInfoResponse.of(personality); } + public List getPersonalityTestInfo() { + List personalityTests = personalityTestRepository.findAll(); + personalityTests = personalityTests.stream() + .sorted(Comparator.comparing(PersonalityTest::getIdx)) + .collect(Collectors.toList()); + return personalityTests.stream() + .map(PersonalityTestInfoResponse::of) + .collect(Collectors.toList()); + } + private UserInfoResponse getProfileInfoByUser(User user) { Onboarding onboarding = user.getOnboarding(); Represent represent = representRepository.findRepresentByOnboarding(onboarding); diff --git a/src/main/java/hous/server/service/user/dto/response/PersonalityTestInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/PersonalityTestInfoResponse.java new file mode 100644 index 00000000..022508af --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/PersonalityTestInfoResponse.java @@ -0,0 +1,44 @@ +package hous.server.service.user.dto.response; + +import hous.server.domain.personality.PersonalityTest; +import hous.server.domain.personality.QuestionType; +import lombok.*; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class PersonalityTestInfoResponse { + + private int index; + private List question; + private QuestionType questionType; + private List> answers; + private String imageUrl; + + public static PersonalityTestInfoResponse of(PersonalityTest personalityTest) { + return PersonalityTestInfoResponse.builder() + .index(personalityTest.getIdx()) + .question(splitToListByLineBreak(personalityTest.getQuestion())) + .questionType(personalityTest.getQuestionType()) + .answers(splitTwiceToListByLineBreak(personalityTest.getAnswers())) + .imageUrl(personalityTest.getImageUrl()) + .build(); + } + + private static List splitToListByLineBreak(String content) { + return Arrays.stream(content.split("\n")).collect(Collectors.toList()); + } + + private static List> splitTwiceToListByLineBreak(String content) { + List splitOnceList = Arrays.stream(content.split("\n")).collect(Collectors.toList()); + return splitOnceList.stream().map(splitOnce -> + Arrays.stream(splitOnce.split("\t")).collect(Collectors.toList()) + ).collect(Collectors.toList()); + } +} From af54bf987a39b61fb3863ed9b0d5322d4aba6bce Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 8 Sep 2022 18:10:37 +0900 Subject: [PATCH 107/301] =?UTF-8?q?#57=20[feat]=20=EC=84=B1=ED=96=A5?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A0=90=EC=88=98=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EB=B0=8F=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 29 +++++++++++++- .../hous/server/domain/user/Onboarding.java | 4 ++ .../hous/server/domain/user/TestScore.java | 4 ++ .../hous/server/service/user/UserService.java | 11 ++++++ .../server/service/user/UserServiceUtils.java | 20 ++++++++++ .../request/UpdateTestScoreRequestDto.java | 39 +++++++++++++++++++ .../resources/messages/validation.properties | 1 + 7 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 436c0688..8e2fb07f 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -6,6 +6,7 @@ import hous.server.config.resolver.UserId; import hous.server.service.user.UserService; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; +import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; @@ -54,7 +55,7 @@ public ResponseEntity setOnboardingInfo( } @ApiOperation( - value = "[인증] 마이 페이지(프로필 뷰) - 나의 프로필 정보를 수정합니다.", + value = "[인증] 마이 페이지(Profile 뷰) - 나의 프로필 정보를 수정합니다.", notes = "프로필 정보를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." ) @ApiResponses(value = { @@ -90,7 +91,7 @@ public ResponseEntity updateUserInfo( // TODO 푸쉬알림 설정뷰 확정나면 수정하기 @ApiOperation( - value = "[인증] 마이 페이지(프로필 뷰) - 나의 푸쉬 알림 설정 정보를 수정합니다.", + value = "[인증] 마이 페이지(Profile 뷰) - 나의 푸쉬 알림 설정 정보를 수정합니다.", notes = "푸쉬 알림 설정 여부를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." ) @ApiResponses(value = { @@ -112,4 +113,28 @@ public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = " userService.updateUserPushState(state, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 마이 페이지(Profile 뷰) - 성향테스트 결과 정보를 수정합니다.", + notes = "성향테스트 결과를 수정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse( + code = 400, message = "성향 테스트의 각 성향 점수는 최소 3점, 최대 9점입니다. (smell, light, noise, clean, introversion)", response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + + "2. 같은 방에 참가하고 있지 않습니다.\n", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/user/personality") + public ResponseEntity updateUserTestScore( + @Valid @RequestBody UpdateTestScoreRequestDto request, @ApiIgnore @UserId Long userId) { + userService.updateUserTestScore(request, userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index a9f772bc..945ec0c7 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -80,6 +80,10 @@ public void setOnboarding(String nickname, LocalDate birthday, boolean isPublic) this.isChecked = true; } + public void setPersonality(Personality personality) { + this.personality = personality; + } + public void addParticipate(Participate participate) { this.participates.add(participate); } diff --git a/src/main/java/hous/server/domain/user/TestScore.java b/src/main/java/hous/server/domain/user/TestScore.java index 06a6a5ce..142f022a 100644 --- a/src/main/java/hous/server/domain/user/TestScore.java +++ b/src/main/java/hous/server/domain/user/TestScore.java @@ -53,4 +53,8 @@ public TestScore resetScore(TestScore testScore) { testScore.updateScore(0, 0, 0, 0, 0); return testScore; } + + public int getTotalTestScore() { + return this.getLight() + this.getNoise() + this.getClean() + this.getSmell() + this.getIntroversion(); + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index d2757646..0222fd64 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,5 +1,6 @@ package hous.server.service.user; +import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.user.Onboarding; @@ -13,6 +14,7 @@ import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.request.CreateUserDto; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; +import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -61,4 +63,13 @@ public void updateUserPushState(boolean state, Long userId) { setting.setPushNotification(state); } + public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); + Onboarding onboarding = user.getOnboarding(); + TestScore testScore = onboarding.getTestScore(); + testScore.updateScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); + Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); + onboarding.setPersonality(personality); + } } diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 5c0c2fd9..f2d3aaae 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -3,7 +3,10 @@ import hous.server.common.exception.ConflictException; import hous.server.common.exception.NotFoundException; import hous.server.common.exception.ValidationException; +import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.personality.repository.PersonalityRepository; +import hous.server.domain.user.TestScore; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; @@ -45,4 +48,21 @@ public static void validatePersonalityColor(PersonalityColor color) { throw new NotFoundException("GRAY 에 대한 성향 정보는 존재하지 않습니다.", NOT_FOUND_PERSONALITY_COLOR_EXCEPTION); } } + + public static Personality getPersonalityColorByTestScore(PersonalityRepository personalityRepository, TestScore testScore) { + int totalTestScore = testScore.getTotalTestScore(); + if (totalTestScore >= 15 && totalTestScore <= 20) { + return personalityRepository.findPersonalityByColor(PersonalityColor.YELLOW); + } else if (totalTestScore >= 21 && totalTestScore <= 26) { + return personalityRepository.findPersonalityByColor(PersonalityColor.RED); + } else if (totalTestScore >= 27 && totalTestScore <= 33) { + return personalityRepository.findPersonalityByColor(PersonalityColor.BLUE); + } else if (totalTestScore >= 34 && totalTestScore <= 39) { + return personalityRepository.findPersonalityByColor(PersonalityColor.PURPLE); + } else if (totalTestScore >= 40 && totalTestScore <= 45) { + return personalityRepository.findPersonalityByColor(PersonalityColor.GREEN); + } + return null; + } + } diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java new file mode 100644 index 00000000..5ed3e46a --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java @@ -0,0 +1,39 @@ +package hous.server.service.user.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class UpdateTestScoreRequestDto { + + @ApiModelProperty(value = "빛", example = "15") + @Min(value = 3, message = "{user.testScore.size}") + @Max(value = 9, message = "{user.testScore.size}") + private int light; + + @ApiModelProperty(value = "소음", example = "19") + @Min(value = 3, message = "{user.testScore.size}") + @Max(value = 9, message = "{user.testScore.size}") + private int noise; + + @ApiModelProperty(value = "정리정돈", example = "3") + @Min(value = 3, message = "{user.testScore.size}") + @Max(value = 9, message = "{user.testScore.size}") + private int clean; + + @ApiModelProperty(value = "냄새", example = "4") + @Min(value = 3, message = "{user.testScore.size}") + @Max(value = 9, message = "{user.testScore.size}") + private int smell; + + @ApiModelProperty(value = "내향", example = "5") + @Min(value = 3, message = "{user.testScore.size}") + @Max(value = 9, message = "{user.testScore.size}") + private int introversion; +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index b74cc3ef..b73f2287 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -28,3 +28,4 @@ user.job.notBlank=\uC9C1\uC5C5\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. user.job.max=\uC9C1\uC5C5\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.introduction.notBlank=\uC790\uAE30\uC18C\uAC1C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.introduction.max=\uC790\uAE30\uC18C\uAC1C\uB294 40 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +user.testScore.size=\uC131\uD5A5 \uD14C\uC2A4\uD2B8\uC758 \uAC01 \uC131\uD5A5 \uC810\uC218\uB294 \uCD5C\uC18C 3\uC810, \uCD5C\uB300 9\uC810\uC785\uB2C8\uB2E4. From 59c2fb8329d4131d5810265708f5644adea74cbf Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 9 Sep 2022 19:07:26 +0900 Subject: [PATCH 108/301] =?UTF-8?q?#57=20[fix]=20gray=EB=8F=84=20testScore?= =?UTF-8?q?=EB=A5=BC=200,0,0,0,0=EC=9C=BC=EB=A1=9C=20=EB=91=A0=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EB=B6=84=EA=B8=B0=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/dto/response/UserInfoResponse.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index 929bb7c6..e6407e74 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -37,7 +37,7 @@ public class UserInfoResponse { private String representBadgeImage; - + @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) public static class TestScoreResponse { @@ -49,18 +49,16 @@ public static class TestScoreResponse { private int smell; + private int introversion; + public static TestScoreResponse of(TestScore testScore) { - if (testScore != null) { - return TestScoreResponse.builder() - .light(testScore.getLight()) - .noise(testScore.getNoise()) - .smell(testScore.getSmell()) - .clean(testScore.getClean()) - .build(); - - } else { - return null; - } + return TestScoreResponse.builder() + .light(testScore.getLight()) + .noise(testScore.getNoise()) + .smell(testScore.getSmell()) + .clean(testScore.getClean()) + .introversion(testScore.getIntroversion()) + .build(); } } From bea1e762dd6e43ebcd8df46f0c63dca53e7e061f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 9 Sep 2022 19:26:48 +0900 Subject: [PATCH 109/301] =?UTF-8?q?#57=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/user/UserController.java | 2 +- .../service/user/dto/request/UpdateTestScoreRequestDto.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 8e2fb07f..13c2e104 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -121,7 +121,7 @@ public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = " @ApiResponses(value = { @ApiResponse(code = 204, message = ""), @ApiResponse( - code = 400, message = "성향 테스트의 각 성향 점수는 최소 3점, 최대 9점입니다. (smell, light, noise, clean, introversion)", response = ErrorResponse.class), + code = 400, message = "성향 테스트의 각 성향 점수는 최소 3점, 최대 9점입니다. (smell, light, noise, clean, introversion)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java index 5ed3e46a..67047f82 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java @@ -12,12 +12,12 @@ @AllArgsConstructor(access = AccessLevel.PROTECTED) public class UpdateTestScoreRequestDto { - @ApiModelProperty(value = "빛", example = "15") + @ApiModelProperty(value = "빛", example = "4") @Min(value = 3, message = "{user.testScore.size}") @Max(value = 9, message = "{user.testScore.size}") private int light; - @ApiModelProperty(value = "소음", example = "19") + @ApiModelProperty(value = "소음", example = "5") @Min(value = 3, message = "{user.testScore.size}") @Max(value = 9, message = "{user.testScore.size}") private int noise; From 0eac0fe8ae22e589ff91975a6e1115ebbb164170 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Fri, 9 Sep 2022 21:10:10 +0900 Subject: [PATCH 110/301] =?UTF-8?q?#61=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PersonalityTestRepository.java | 2 +- .../PersonalityTestRepositoryCustom.java | 10 +++++++++ .../PersonalityTestRepositoryImpl.java | 22 +++++++++++++++++++ .../service/user/UserRetrieveService.java | 6 +---- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryImpl.java diff --git a/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java index 157e3322..6adada98 100644 --- a/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java +++ b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepository.java @@ -3,5 +3,5 @@ import hous.server.domain.personality.PersonalityTest; import org.springframework.data.jpa.repository.JpaRepository; -public interface PersonalityTestRepository extends JpaRepository { +public interface PersonalityTestRepository extends JpaRepository, PersonalityTestRepositoryCustom { } diff --git a/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryCustom.java b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryCustom.java new file mode 100644 index 00000000..d8649298 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryCustom.java @@ -0,0 +1,10 @@ +package hous.server.domain.personality.repository; + +import hous.server.domain.personality.PersonalityTest; + +import java.util.List; + +public interface PersonalityTestRepositoryCustom { + + List findAllPersonalityTest(); +} diff --git a/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryImpl.java b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryImpl.java new file mode 100644 index 00000000..5daa99d9 --- /dev/null +++ b/src/main/java/hous/server/domain/personality/repository/PersonalityTestRepositoryImpl.java @@ -0,0 +1,22 @@ +package hous.server.domain.personality.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.personality.PersonalityTest; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +import static hous.server.domain.personality.QPersonalityTest.personalityTest; + +@RequiredArgsConstructor +public class PersonalityTestRepositoryImpl implements PersonalityTestRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public List findAllPersonalityTest() { + return queryFactory.selectFrom(personalityTest) + .orderBy(personalityTest.idx.asc()) + .fetch(); + } +} diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 54759bbd..09d390de 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -21,7 +21,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -64,10 +63,7 @@ public PersonalityInfoResponse getPersonalityInfo(PersonalityColor color) { } public List getPersonalityTestInfo() { - List personalityTests = personalityTestRepository.findAll(); - personalityTests = personalityTests.stream() - .sorted(Comparator.comparing(PersonalityTest::getIdx)) - .collect(Collectors.toList()); + List personalityTests = personalityTestRepository.findAllPersonalityTest(); return personalityTests.stream() .map(PersonalityTestInfoResponse::of) .collect(Collectors.toList()); From 502fa2f825c052b1e0abd107afa08d2967629591 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 13 Sep 2022 11:54:03 +0900 Subject: [PATCH 111/301] =?UTF-8?q?#63=20[feat]=20=EB=82=98=EC=9D=98=20tod?= =?UTF-8?q?o=20=EC=A1=B0=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../todo/TodoRetrieveController.java | 20 ++++++++ .../service/todo/TodoRetrieveService.java | 10 ++++ .../todo/dto/response/MyTodoInfoResponse.java | 49 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/main/java/hous/server/service/todo/dto/response/MyTodoInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 876872ee..0d70aafe 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -35,6 +35,7 @@ public enum SuccessCode { GET_TODO_MAIN_SUCCESS(OK, "todo 메인 페이지 조회 성공입니다."), GET_TODO_ALL_DAY_SUCCESS(OK, "todo 요일별 정보 조회 성공입니다."), GET_TODO_ALL_MEMBER_SUCCESS(OK, "todo 멤버별 정보 조회 성공입니다."), + GET_MY_TODO_SUCCESS(OK, "나의 todo 정보 조회 성공입니다."), // rule GET_RULE_INFO_SUCCESS(OK, "규칙 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 420dff4f..b7214d49 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -152,4 +152,24 @@ public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @Us public ResponseEntity> getTodoAllMemberInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_ALL_MEMBER_SUCCESS, todoRetrieveService.getTodoAllMemberInfo(userId)); } + + @ApiOperation( + value = "[인증] 마이 페이지(설정) - MY to-do 를 조회합니다.", + notes = "방에서 퇴사할 때 MY to-do 를 조회합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "나의 todo 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/todos/me") + public ResponseEntity getMyTodoInfo(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_MY_TODO_SUCCESS, todoRetrieveService.getMyTodoInfo(userId)); + } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index ceb84a0b..f9b829b5 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -147,4 +147,14 @@ public List getTodoAllMemberInfo(Long userId) { return allMemberTodos; } + + public MyTodoInfoResponse getMyTodoInfo(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Room room = RoomServiceUtils.findParticipatingRoom(user); + List todos = room.getTodos(); + List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, user.getOnboarding()).stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .collect(Collectors.toList()); + return MyTodoInfoResponse.of(myTodos, user.getOnboarding()); + } } diff --git a/src/main/java/hous/server/service/todo/dto/response/MyTodoInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/MyTodoInfoResponse.java new file mode 100644 index 00000000..02e56275 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/MyTodoInfoResponse.java @@ -0,0 +1,49 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.todo.DayOfWeek; +import hous.server.domain.todo.Redo; +import hous.server.domain.todo.Todo; +import hous.server.domain.user.Onboarding; +import lombok.*; + +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class MyTodoInfoResponse { + + private int myTodosCnt; + private List myTodos; + + @ToString + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + private static class TodoWithDayOfWeek { + private String todoName; + private String dayOfWeeks; + } + + public static MyTodoInfoResponse of(List myTodos, Onboarding me) { + return MyTodoInfoResponse.builder() + .myTodosCnt(myTodos.size()) + .myTodos(myTodos.stream() + .map(myTodo -> TodoWithDayOfWeek.builder() + .todoName(myTodo.getName()) + .dayOfWeeks(DayOfWeek.toString(myTodo.getTakes().stream() + .filter(take -> take.getOnboarding().getId().equals(me.getId())) + .findFirst().get().getRedos().stream() + .map(Redo::getDayOfWeek) + .sorted(Comparator.comparing(DayOfWeek::getIndex)) + .collect(Collectors.toSet()))) + .build()) + .collect(Collectors.toList())) + .build(); + } +} From 70987944cdc946d0ecfc5583c0a25182067fe4dc Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 14 Sep 2022 01:10:06 +0900 Subject: [PATCH 112/301] =?UTF-8?q?#65=20[feat]=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=ED=83=88=ED=87=B4=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 2 ++ .../controller/user/UserController.java | 26 ++++++++++++++++++- .../user/repository/UserRepositoryCustom.java | 2 ++ .../user/repository/UserRepositoryImpl.java | 8 ++++++ .../hous/server/service/user/UserService.java | 21 +++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 1139ed8b..1d1e4d5b 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -38,6 +38,7 @@ public enum ErrorCode { FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "같은 방에 참가하고 있지 않습니다."), + FORBIDDEN_USER_DELETE_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "방에 참가하고 있는 유저는 탈퇴할 수 없습니다."), /** * 404 Not Found @@ -51,6 +52,7 @@ public enum ErrorCode { NOT_FOUND_RULE_EXCEPTION(NOT_FOUND, "존재하지 않는 규칙입니다."), NOT_FOUND_TODO_EXCEPTION(NOT_FOUND, "존재하지 않는 todo 입니다."), NOT_FOUND_PERSONALITY_COLOR_EXCEPTION(NOT_FOUND, "GRAY 에 대한 성향 정보는 존재하지 않습니다."), + NOTFOUND_USER_EXCEPTION(NOT_FOUND, "존재하지 않는 유저입니다."), /** * 405 Method Not Allowed diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 13c2e104..1179cfba 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -125,7 +125,7 @@ public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = " @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 같은 방에 참가하고 있지 않습니다.\n", + + "2. 같은 방에 참가하고 있지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @@ -137,4 +137,28 @@ public ResponseEntity updateUserTestScore( userService.updateUserTestScore(request, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 마이 페이지(설정) - 회원 정보를 삭제합니다.", + notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "방에 참가하고 있는 유저는 탈퇴할 수 없습니다..", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + + "2. 같은 방에 참가하고 있지 않습니다.\n" + + "3. 존재하지 않는 유저입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/user") + public ResponseEntity deleteUser( + @Valid @RequestBody UpdateTestScoreRequestDto request, @ApiIgnore @UserId Long userId) { + userService.deleteUser(userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java index 0251a864..438c20f4 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java @@ -10,4 +10,6 @@ public interface UserRepositoryCustom { User findUserById(Long id); User findUserBySocialIdAndSocialType(String socialId, UserSocialType socialType); + + long deleteUserById(Long id); } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java index e3d7bb3f..ff9b45ed 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java @@ -46,4 +46,12 @@ public User findUserBySocialIdAndSocialType(String socialId, UserSocialType soci ) .fetchOne(); } + + @Override + public long deleteUserById(Long id) { + return queryFactory + .delete(user) + .where(user.id.eq(id)) + .execute(); + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 0222fd64..2175cd6b 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,8 +1,11 @@ package hous.server.service.user; +import hous.server.common.exception.ForbiddenException; +import hous.server.common.exception.NotFoundException; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; +import hous.server.domain.room.Participate; import hous.server.domain.user.Onboarding; import hous.server.domain.user.Setting; import hous.server.domain.user.TestScore; @@ -20,6 +23,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + +import static hous.server.common.exception.ErrorCode.FORBIDDEN_USER_DELETE_ROOM_PARTICIPATE_EXCEPTION; +import static hous.server.common.exception.ErrorCode.NOTFOUND_USER_EXCEPTION; + @RequiredArgsConstructor @Service @Transactional @@ -72,4 +80,17 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); onboarding.setPersonality(personality); } + + public void deleteUser(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + List participateList = user.getOnboarding().getParticipates(); + if (!participateList.isEmpty()) { + throw new ForbiddenException(String.format("방 (%s) 의 참가자 는 탈퇴할 수 없습니다.", participateList.get(0).getRoom().getId()), + FORBIDDEN_USER_DELETE_ROOM_PARTICIPATE_EXCEPTION); + } + if (userRepository.deleteUserById(userId) != 1) { + throw new NotFoundException(String.format("존재 하지 않은 유저 (%s) 는 탈퇴할 수 없습니다.", userId), + NOTFOUND_USER_EXCEPTION); + } + } } From 366b97b9f68067c48c0bc974560c3ad743bce93e Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 14 Sep 2022 13:56:42 +0900 Subject: [PATCH 113/301] =?UTF-8?q?#67=20[feat]=20Notification=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/Notification.java | 33 +++++++++++++++++++ .../domain/notification/NotificationType.java | 8 +++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/hous/server/domain/notification/Notification.java create mode 100644 src/main/java/hous/server/domain/notification/NotificationType.java diff --git a/src/main/java/hous/server/domain/notification/Notification.java b/src/main/java/hous/server/domain/notification/Notification.java new file mode 100644 index 00000000..60d3ae48 --- /dev/null +++ b/src/main/java/hous/server/domain/notification/Notification.java @@ -0,0 +1,33 @@ +package hous.server.domain.notification; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.user.Onboarding; +import lombok.*; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class Notification extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "onboarding_id", nullable = false) + private Onboarding onboarding; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private NotificationType type; + + @Column(nullable = false, length = 100) + private String content; + + @Column(nullable = false) + private boolean isRead; +} diff --git a/src/main/java/hous/server/domain/notification/NotificationType.java b/src/main/java/hous/server/domain/notification/NotificationType.java new file mode 100644 index 00000000..94c35556 --- /dev/null +++ b/src/main/java/hous/server/domain/notification/NotificationType.java @@ -0,0 +1,8 @@ +package hous.server.domain.notification; + +public enum NotificationType { + + TODO, + RULE, + BADGE; +} From 364985f2698a678ec8428577d0d571558b36ab1b Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 14 Sep 2022 13:57:23 +0900 Subject: [PATCH 114/301] =?UTF-8?q?#67=20[chore]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B4=80=EB=A0=A8=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + build.gradle | 129 ++++++++++++++++++++++++++------------------------- 2 files changed, 68 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index cde9d221..b3dce725 100644 --- a/.gitignore +++ b/.gitignore @@ -36,8 +36,10 @@ out/ ### VS Code ### .vscode/ +/src/main/resources/firebase/firebase_service_key.json application.yml application-local.yml application-prod.yml application-aws.yml application-jwt.yml +application-firebase.yml diff --git a/build.gradle b/build.gradle index 8a6221df..efec2b6c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ plugins { - id 'org.springframework.boot' version '2.7.1' - id 'io.spring.dependency-management' version '1.0.11.RELEASE' - id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" - id 'java' + id 'org.springframework.boot' version '2.7.1' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" + id 'java' } group = 'hous' @@ -10,112 +10,115 @@ version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' configurations { - compileOnly { - extendsFrom annotationProcessor - } + compileOnly { + extendsFrom annotationProcessor + } } repositories { - mavenCentral() + mavenCentral() } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation group: 'org.postgresql', name: 'postgresql', version: '42.4.0' - runtimeOnly 'org.postgresql:postgresql' + implementation group: 'org.postgresql', name: 'postgresql', version: '42.4.0' + runtimeOnly 'org.postgresql:postgresql' - runtimeOnly 'mysql:mysql-connector-java' + runtimeOnly 'mysql:mysql-connector-java' - implementation 'org.springframework.boot:spring-boot-starter-data-redis' - implementation 'org.springframework.session:spring-session-data-redis' + implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'org.springframework.session:spring-session-data-redis' - implementation 'com.querydsl:querydsl-jpa' - implementation("com.querydsl:querydsl-apt") + implementation 'com.querydsl:querydsl-jpa' + implementation("com.querydsl:querydsl-apt") - implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2' - implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2' - implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' + implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2' + implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2' + implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' - testCompileOnly("org.projectlombok:lombok") - testAnnotationProcessor("org.projectlombok:lombok") - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' + testCompileOnly("org.projectlombok:lombok") + testAnnotationProcessor("org.projectlombok:lombok") + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' - implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' - compileOnly 'org.jetbrains:annotations:16.0.2' + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + compileOnly 'org.jetbrains:annotations:16.0.2' - implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' - implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' + implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' + implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' - implementation "org.springframework.cloud:spring-cloud-starter-openfeign" + implementation "org.springframework.cloud:spring-cloud-starter-openfeign" - testImplementation('org.springframework.boot:spring-boot-starter-test') { - exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' - } - testImplementation 'org.springframework.security:spring-security-test' + implementation 'com.google.firebase:firebase-admin:6.8.1' + implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2' + + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } + testImplementation 'org.springframework.security:spring-security-test' } dependencyManagement { - imports { - mavenBom "org.springframework.cloud:spring-cloud-dependencies:2021.0.1" - } + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:2021.0.1" + } } jar { - enabled = false + enabled = false } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() } def querydslDir = "$buildDir/generated/querydsl" //def querydslDir = "src/main/generated" querydsl { - library = "com.querydsl:querydsl-apt" - jpa = true - querydslSourcesDir = querydslDir + library = "com.querydsl:querydsl-apt" + jpa = true + querydslSourcesDir = querydslDir } sourceSets { - main { - java { - srcDirs = ['src/main/java', querydslDir] - } - } + main { + java { + srcDirs = ['src/main/java', querydslDir] + } + } } configurations { - compileOnly { - extendsFrom annotationProcessor - } - querydsl.extendsFrom compileClasspath + compileOnly { + extendsFrom annotationProcessor + } + querydsl.extendsFrom compileClasspath } compileQuerydsl { - if (file(querydslDir)) { - delete(file(querydslDir)) - } - options.annotationProcessorPath = configurations.querydsl + if (file(querydslDir)) { + delete(file(querydslDir)) + } + options.annotationProcessorPath = configurations.querydsl } project.afterEvaluate { - project.tasks.compileQuerydsl.options.compilerArgs = [ - "-proc:only", - "-processor", project.querydsl.processors() + - ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor' - ] + project.tasks.compileQuerydsl.options.compilerArgs = [ + "-proc:only", + "-processor", project.querydsl.processors() + + ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor' + ] } tasks.withType(JavaCompile) { - options.generatedSourceOutputDirectory = file(querydslDir) + options.generatedSourceOutputDirectory = file(querydslDir) } clean.doLast { - delete file(querydslDir) + delete file(querydslDir) } From c320d86c3820d840498fed57b4e9520f9b913219 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 14 Sep 2022 13:57:32 +0900 Subject: [PATCH 115/301] =?UTF-8?q?#67=20[feat]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firebase/FirebaseCloudMessageService.java | 71 +++++++++++++++++++ .../firebase/dto/request/FcmMessage.java | 29 ++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java create mode 100644 src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java new file mode 100644 index 00000000..94cbc8d1 --- /dev/null +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -0,0 +1,71 @@ +package hous.server.service.firebase; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.auth.oauth2.GoogleCredentials; +import com.google.common.net.HttpHeaders; +import com.google.gson.JsonParseException; +import hous.server.common.util.YamlPropertySourceFactory; +import hous.server.service.firebase.dto.request.FcmMessage; +import lombok.RequiredArgsConstructor; +import okhttp3.*; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.io.ClassPathResource; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.List; + +@RequiredArgsConstructor +@Service +@PropertySource(value = "classpath:application-firebase.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) +public class FirebaseCloudMessageService { + + private final ObjectMapper objectMapper; + + @Value("${cloud.firebase.credentials.uri}") + private String API_URL; + + public void sendMessageTo(String targetToken, String title, String body) throws IOException { + String message = makeMessage(targetToken, title, body); + + OkHttpClient client = new OkHttpClient(); + RequestBody requestBody = RequestBody.create(message, + MediaType.get("application/json; charset=utf-8")); + Request request = new Request.Builder() + .url(API_URL) + .post(requestBody) + .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) + .addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8") + .build(); + + Response response = client.newCall(request).execute(); + } + + private String makeMessage(String targetToken, String title, String body) throws JsonParseException, JsonProcessingException { + FcmMessage fcmMessage = FcmMessage.builder() + .validateOnly(false) + .message(FcmMessage.Message.builder() + .notification(FcmMessage.Notification.builder() + .title(title) + .body(body) + .build()) + .token(targetToken) + .build()) + .build(); + + return objectMapper.writeValueAsString(fcmMessage); + } + + private String getAccessToken() throws IOException { + String firebaseConfigPath = "firebase/firebase_service_key.json"; + + GoogleCredentials googleCredentials = GoogleCredentials + .fromStream(new ClassPathResource(firebaseConfigPath).getInputStream()) + .createScoped(List.of("https://www.googleapis.com/auth/cloud-platform")); + + googleCredentials.refreshIfExpired(); + return googleCredentials.getAccessToken().getTokenValue(); + } +} diff --git a/src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java b/src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java new file mode 100644 index 00000000..51ab8580 --- /dev/null +++ b/src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java @@ -0,0 +1,29 @@ +package hous.server.service.firebase.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Builder +@AllArgsConstructor +@Getter +public class FcmMessage { + private boolean validateOnly; + private Message message; + + @Builder + @AllArgsConstructor + @Getter + public static class Message { + private Notification notification; + private String token; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Notification { + private String title; + private String body; + } +} From cb2b9feb88788e182613038e2447451bff48fc3e Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 14 Sep 2022 15:42:13 +0900 Subject: [PATCH 116/301] =?UTF-8?q?#69=20[fix]=20Badge=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/domain/badge/Badge.java | 9 +---- .../hous/server/domain/badge/BadgeInfo.java | 40 +++++++++++++++++++ .../user/dto/response/UserInfoResponse.java | 4 +- 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 src/main/java/hous/server/domain/badge/BadgeInfo.java diff --git a/src/main/java/hous/server/domain/badge/Badge.java b/src/main/java/hous/server/domain/badge/Badge.java index 903748e8..0367babd 100644 --- a/src/main/java/hous/server/domain/badge/Badge.java +++ b/src/main/java/hous/server/domain/badge/Badge.java @@ -17,11 +17,6 @@ public class Badge extends AuditingTimeEntity { private Long id; @Column(nullable = false, length = 30) - private String name; - - @Column(nullable = false, length = 100) - private String description; - - @Column(nullable = false, length = 300) - private String imageUrl; + @Enumerated(EnumType.STRING) + private BadgeInfo info; } diff --git a/src/main/java/hous/server/domain/badge/BadgeInfo.java b/src/main/java/hous/server/domain/badge/BadgeInfo.java new file mode 100644 index 00000000..a4f92875 --- /dev/null +++ b/src/main/java/hous/server/domain/badge/BadgeInfo.java @@ -0,0 +1,40 @@ +package hous.server.domain.badge; + +import hous.server.common.model.EnumModel; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum BadgeInfo implements EnumModel { + + POUNDING_HOUSE("두근두근 하우스", "어서와요\n우리 Hous-에!", "imageUrl"), + I_AM_SUCH_A_PERSON("나 이런 사람이야", "Homie 카드를\n완성한 호미", "imageUrl"), + OUR_HOUSE_HOMIES("우리 집 호미들", "모든 Homie들의\n카드 확인", "imageUrl"), + I_DONT_EVEN_KNOW_ME("나도 날 모르겠어", "성향 테스트를\n5번 이상 한 호미", "imageUrl"), + HOMIE_IS_BORN("Homie 탄생", "Hous-에서의\n첫 생일", "imageUrl"), + TODO_ONE_STEP("to-do 한 걸음", "to-do 전체보기에서\n첫 to-do 등록", "imageUrl"), + GOOD_JOB("참 잘했어요", "1주 동안 to-do\n모두 완료", "imageUrl"), + SINCERITY_KING_HOMIE("성실왕 호미", "2주 동안\nto-do 모두 완료", "imageUrl"), + TODO_MASTER("to-do 마스터", "3주 동안\nto-do 모두 완료", "imageUrl"), + LETS_BUILD_A_POLE("기둥을 세우자", "우리 집 규칙에서\n집 Rules 등록", "imageUrl"), + OUR_HOUSE_PILLAR_HOMIE("우리 집 기둥 호미", "우리 집 Rules\n5개 이상 등록", "imageUrl"), + FEEDBACK_ONE_STEP("피드백 한 걸음", "좋은 의견을\n호미 나라에 전달", "imageUrl"); + + private final String value; + + private final String description; + + private final String imageUrl; + + @Override + public String getKey() { + return name(); + } + + @Override + public String getValue() { + return value; + } +} diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index e6407e74..87aafac2 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -75,8 +75,8 @@ public static UserInfoResponse of(Onboarding onboarding, Represent represent) { .mbti(onboarding.getMbti()) .introduction(onboarding.getIntroduction()) .testScore(TestScoreResponse.of(onboarding.getTestScore())) - .representBadge(represent != null ? represent.getBadge().getName() : null) - .representBadgeImage(represent != null ? represent.getBadge().getImageUrl() : null) + .representBadge(represent != null ? represent.getBadge().getInfo().getValue() : null) + .representBadgeImage(represent != null ? represent.getBadge().getInfo().getImageUrl() : null) .build(); } } From a492ff876d9d98f5c7420b5a886fa72cc4b543ec Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 14 Sep 2022 16:26:45 +0900 Subject: [PATCH 117/301] =?UTF-8?q?#67=20[fix]=20User,=20Onboarding=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/user/Onboarding.java | 6 +++++- src/main/java/hous/server/domain/user/User.java | 10 ++++++---- .../java/hous/server/service/user/UserService.java | 11 +++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 945ec0c7..870e4c8c 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -25,6 +25,9 @@ public class Onboarding extends AuditingTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; @Column(length = 30) private String nickname; @@ -65,8 +68,9 @@ public class Onboarding extends AuditingTimeEntity { @JoinColumn(name = "badge_id") private final List badges = new ArrayList<>(); - public static Onboarding newInstance(Personality personality, TestScore testScore) { + public static Onboarding newInstance(User user, Personality personality, TestScore testScore) { return Onboarding.builder() + .user(user) .isChecked(false) .personality(personality) .testScore(testScore) diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index 7bd5fe59..928fdb62 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -26,21 +26,23 @@ public class User extends AuditingTimeEntity { @Enumerated(EnumType.STRING) private UserStatus status; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "onboarding_id", nullable = false) + @OneToOne(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private Onboarding onboarding; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "setting_id", nullable = false) private Setting setting; - public static User newInstance(String socialId, UserSocialType socialType, String fcmToken, Onboarding onboarding, Setting setting) { + public static User newInstance(String socialId, UserSocialType socialType, String fcmToken, Setting setting) { return User.builder() .socialInfo(SocialInfo.of(socialId, socialType)) .fcmToken(fcmToken) - .onboarding(onboarding) .setting(setting) .status(UserStatus.ACTIVE) .build(); } + + public void setOnboarding(Onboarding onboarding) { + this.onboarding = onboarding; + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 0222fd64..d61d9ad0 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -33,11 +33,14 @@ public class UserService { public Long registerUser(CreateUserDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); - User user = userRepository.save(User.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), - onboardingRepository.save( - Onboarding.newInstance(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), - testScoreRepository.save(TestScore.newInstance()))), + User user = userRepository.save(User.newInstance( + request.getSocialId(), request.getSocialType(), request.getFcmToken(), settingRepository.save(Setting.newInstance()))); + Onboarding onboarding = onboardingRepository.save(Onboarding.newInstance( + user, + personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), + testScoreRepository.save(TestScore.newInstance()))); + user.setOnboarding(onboarding); return user.getId(); } From a862103ecd496ba8067aaf37cc1baee2ac7ffc01 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 14 Sep 2022 17:37:38 +0900 Subject: [PATCH 118/301] =?UTF-8?q?#67=20[fix]=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EC=8B=9C=20fcmToken=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/user/User.java | 4 ++++ .../hous/server/service/auth/impl/AppleAuthService.java | 1 + .../hous/server/service/auth/impl/KaKaoAuthService.java | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index 928fdb62..1c7c5491 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -45,4 +45,8 @@ public static User newInstance(String socialId, UserSocialType socialType, Strin public void setOnboarding(Onboarding onboarding) { this.onboarding = onboarding; } + + public void updateFcmToken(String fcmToken) { + this.fcmToken = fcmToken; + } } diff --git a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java index 2f2f5edc..9c3fabb6 100644 --- a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java @@ -27,6 +27,7 @@ public Long login(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); if (user == null) return userService.registerUser(request.toCreateUserDto(socialId)); + else user.updateFcmToken(request.getFcmToken()); return user.getId(); } } diff --git a/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java index 475b797f..329ebbe6 100644 --- a/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java @@ -8,6 +8,7 @@ import hous.server.external.client.kakao.dto.response.KakaoProfileResponse; import hous.server.service.auth.AuthService; import hous.server.service.auth.dto.request.LoginDto; +import hous.server.service.firebase.FirebaseCloudMessageService; import hous.server.service.user.UserService; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -20,6 +21,8 @@ public class KaKaoAuthService implements AuthService { private static final UserSocialType socialType = UserSocialType.KAKAO; private final KakaoApiClient kaKaoApiCaller; + private final FirebaseCloudMessageService firebaseCloudMessageService; + private final UserService userService; private final UserRepository userRepository; @@ -28,8 +31,8 @@ public class KaKaoAuthService implements AuthService { public Long login(LoginDto request) { KakaoProfileResponse response = kaKaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); - if (user == null) - return userService.registerUser(request.toCreateUserDto(response.getId())); + if (user == null) return userService.registerUser(request.toCreateUserDto(response.getId())); + else user.updateFcmToken(request.getFcmToken()); return user.getId(); } } From d6920b2d85fee29f74542c1b3907871e44966397 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 14 Sep 2022 18:37:16 +0900 Subject: [PATCH 119/301] =?UTF-8?q?#67=20[refactor]=20firebase=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=8B=9C=20feign=20=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/firebase/FirebaseApiClient.java | 17 ++++++++++++ .../firebase/dto/response/FcmResponse.java | 19 ++++++++++++++ .../firebase/FirebaseCloudMessageService.java | 26 +++++-------------- 3 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java create mode 100644 src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java diff --git a/src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java b/src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java new file mode 100644 index 00000000..55f4833b --- /dev/null +++ b/src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java @@ -0,0 +1,17 @@ +package hous.server.external.client.firebase; + +import feign.Headers; +import hous.server.external.client.firebase.dto.response.FcmResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; + +@FeignClient(name = "firebaseApiClient", url = "${cloud.firebase.credentials.uri}") +public interface FirebaseApiClient { + + @PostMapping() + @Headers("Content-Type: application/json; UTF-8") + FcmResponse requestFcmMessaging(@RequestHeader("Authorization") String accessTokenWithBearer, + @RequestBody String requestBody); +} diff --git a/src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java b/src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java new file mode 100644 index 00000000..1f2b5c5a --- /dev/null +++ b/src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java @@ -0,0 +1,19 @@ +package hous.server.external.client.firebase.dto.response; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@ToString +@Getter +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class FcmResponse { + private String name; +} diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index 94cbc8d1..4ad5d7c6 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -3,13 +3,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.auth.oauth2.GoogleCredentials; -import com.google.common.net.HttpHeaders; -import com.google.gson.JsonParseException; +import hous.server.common.util.HttpHeaderUtils; import hous.server.common.util.YamlPropertySourceFactory; +import hous.server.external.client.firebase.FirebaseApiClient; +import hous.server.external.client.firebase.dto.response.FcmResponse; import hous.server.service.firebase.dto.request.FcmMessage; import lombok.RequiredArgsConstructor; -import okhttp3.*; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -24,26 +23,15 @@ public class FirebaseCloudMessageService { private final ObjectMapper objectMapper; - @Value("${cloud.firebase.credentials.uri}") - private String API_URL; + private final FirebaseApiClient firebaseApiCaller; public void sendMessageTo(String targetToken, String title, String body) throws IOException { String message = makeMessage(targetToken, title, body); - - OkHttpClient client = new OkHttpClient(); - RequestBody requestBody = RequestBody.create(message, - MediaType.get("application/json; charset=utf-8")); - Request request = new Request.Builder() - .url(API_URL) - .post(requestBody) - .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) - .addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8") - .build(); - - Response response = client.newCall(request).execute(); + FcmResponse fcmResponse = firebaseApiCaller.requestFcmMessaging(HttpHeaderUtils.withBearerToken(getAccessToken()), message); + // TODO fcmResponse.name == null 처리 추가하기 } - private String makeMessage(String targetToken, String title, String body) throws JsonParseException, JsonProcessingException { + private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { FcmMessage fcmMessage = FcmMessage.builder() .validateOnly(false) .message(FcmMessage.Message.builder() From cbe82ff1f6d05d4430a4b51a0b2178562df12883 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 12:57:01 +0900 Subject: [PATCH 120/301] =?UTF-8?q?#67=20[remove]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firebase/dto/response/FcmResponse.java | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java diff --git a/src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java b/src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java deleted file mode 100644 index 1f2b5c5a..00000000 --- a/src/main/java/hous/server/external/client/firebase/dto/response/FcmResponse.java +++ /dev/null @@ -1,19 +0,0 @@ -package hous.server.external.client.firebase.dto.response; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -@ToString -@Getter -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -public class FcmResponse { - private String name; -} From 0ad77120ebe0639239db7d4487a5aa7a8e093815 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 12:57:24 +0900 Subject: [PATCH 121/301] =?UTF-8?q?#67=20[feat]=20refresh=20token=20?= =?UTF-8?q?=EB=A7=8C=EB=A3=8C=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/JwtUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index f5968c74..584bd4c7 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -22,10 +22,11 @@ public class JwtUtils { private final RedisTemplate redisTemplate; - // private static final long ACCESS_TOKEN_EXPIRE_TIME = 30 * 60 * 1000L; // 30분 - // private static final long REFRESH_TOKEN_EXPIRE_TIME = 7 * 24 * 60 * 60 * 1000L; // 7일 + // private static final long ACCESS_TOKEN_EXPIRE_TIME = 30 * 60 * 1000L; // 30분 +// private static final long REFRESH_TOKEN_EXPIRE_TIME = 7 * 24 * 60 * 60 * 1000L; // 7일 private static final long ACCESS_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 private static final long REFRESH_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 + private static final long EXPIRED = 0L; private final Key secretKey; @@ -60,6 +61,10 @@ public TokenResponse createTokenInfo(Long userId) { return TokenResponse.of(accessToken, refreshToken); } + public void expireRefreshToken(Long userId) { + redisTemplate.opsForValue().set("RT:" + userId, "", EXPIRED, TimeUnit.MILLISECONDS); + } + public boolean validateToken(String token) { try { Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token); From 802a8a15b85ddf96dbc0a44eee21cd52b59efac2 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 12:58:11 +0900 Subject: [PATCH 122/301] =?UTF-8?q?#67=20[fix]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EC=8B=A4=ED=8C=A8=EC=8B=9C=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/repository/UserRepositoryCustom.java | 2 ++ .../user/repository/UserRepositoryImpl.java | 11 ++++++++++ .../client/firebase/FirebaseApiClient.java | 5 ++--- .../firebase/FirebaseCloudMessageService.java | 21 +++++++++++++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java index 0251a864..1cb1214e 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java @@ -10,4 +10,6 @@ public interface UserRepositoryCustom { User findUserById(Long id); User findUserBySocialIdAndSocialType(String socialId, UserSocialType socialType); + + User findUserByFcmToken(String fcmToken); } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java index e3d7bb3f..45086eb9 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java @@ -46,4 +46,15 @@ public User findUserBySocialIdAndSocialType(String socialId, UserSocialType soci ) .fetchOne(); } + + @Override + public User findUserByFcmToken(String fcmToken) { + return queryFactory + .selectFrom(user) + .where( + user.fcmToken.eq(fcmToken), + user.status.eq(UserStatus.ACTIVE) + ) + .fetchOne(); + } } diff --git a/src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java b/src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java index 55f4833b..51e1315a 100644 --- a/src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java +++ b/src/main/java/hous/server/external/client/firebase/FirebaseApiClient.java @@ -1,7 +1,6 @@ package hous.server.external.client.firebase; import feign.Headers; -import hous.server.external.client.firebase.dto.response.FcmResponse; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -12,6 +11,6 @@ public interface FirebaseApiClient { @PostMapping() @Headers("Content-Type: application/json; UTF-8") - FcmResponse requestFcmMessaging(@RequestHeader("Authorization") String accessTokenWithBearer, - @RequestBody String requestBody); + void requestFcmMessaging(@RequestHeader("Authorization") String accessTokenWithBearer, + @RequestBody String requestBody); } diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index 4ad5d7c6..e16075e8 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -3,12 +3,16 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.auth.oauth2.GoogleCredentials; +import hous.server.common.exception.FeignClientException; import hous.server.common.util.HttpHeaderUtils; +import hous.server.common.util.JwtUtils; import hous.server.common.util.YamlPropertySourceFactory; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; import hous.server.external.client.firebase.FirebaseApiClient; -import hous.server.external.client.firebase.dto.response.FcmResponse; import hous.server.service.firebase.dto.request.FcmMessage; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.PropertySource; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -16,19 +20,28 @@ import java.io.IOException; import java.util.List; +@Slf4j @RequiredArgsConstructor @Service @PropertySource(value = "classpath:application-firebase.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) public class FirebaseCloudMessageService { + private final UserRepository userRepository; private final ObjectMapper objectMapper; - private final FirebaseApiClient firebaseApiCaller; + private final JwtUtils jwtProvider; public void sendMessageTo(String targetToken, String title, String body) throws IOException { String message = makeMessage(targetToken, title, body); - FcmResponse fcmResponse = firebaseApiCaller.requestFcmMessaging(HttpHeaderUtils.withBearerToken(getAccessToken()), message); - // TODO fcmResponse.name == null 처리 추가하기 + try { + firebaseApiCaller.requestFcmMessaging(HttpHeaderUtils.withBearerToken(getAccessToken()), message); + } catch (FeignClientException exception) { + User user = userRepository.findUserByFcmToken(targetToken); + if (user != null) { + jwtProvider.expireRefreshToken(user.getId()); + } + log.error(exception.getErrorMessage(), exception); + } } private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { From 7a9b04aaf05df12d46c57a2375ee6f13508753a2 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 15 Sep 2022 14:25:54 +0900 Subject: [PATCH 123/301] =?UTF-8?q?#71=20[chore]=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EA=B4=80=EB=A0=A8=20con?= =?UTF-8?q?fig=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 8 ++++++++ .github/workflows/pr-check.yml | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2997d56a..43c4623a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,6 +33,8 @@ jobs: AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} AWS_REGION: ${{ secrets.AWS_REGION }} + FIREBASE_URI: $${{ secrets.FIREBASE_URI }} + FIREBASE_SERVICE_JSON: $${{ secrets.FIREBASE_SERVICE_JSON }} run: | touch application.properties @@ -58,6 +60,12 @@ jobs: echo cloud.aws.s3.bucket=$AWS_S3_BUCKET >> application.properties echo cloud.aws.region.static=$AWS_REGION >> application.properties echo cloud.aws.stack.auto=false >> application.properties + echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties + + mkdir firebase + cd firebase + touch firebase_service_key.json + echo firebase_service_key=$FIREBASE_SERVICE_JSON >> firebase_service_key.json - name: Set up JDK 11 uses: actions/setup-java@v1 diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index cf45cb1c..f16062c6 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -33,6 +33,8 @@ jobs: AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} AWS_REGION: ${{ secrets.AWS_REGION }} + FIREBASE_URI: $${{ secrets.FIREBASE_URI }} + FIREBASE_SERVICE_JSON: $${{ secrets.FIREBASE_SERVICE_JSON }} run: | touch application.properties @@ -58,6 +60,12 @@ jobs: echo cloud.aws.s3.bucket=$AWS_S3_BUCKET >> application.properties echo cloud.aws.region.static=$AWS_REGION >> application.properties echo cloud.aws.stack.auto=false >> application.properties + echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties + + mkdir firebase + cd firebase + touch firebase_service_key.json + echo firebase_service_key=$FIREBASE_SERVICE_JSON >> firebase_service_key.json - name: Set up JDK 11 uses: actions/setup-java@v1 From 6790924d72e4c3d49bf0ad0875f8e639b4cfa3e6 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 15 Sep 2022 14:34:05 +0900 Subject: [PATCH 124/301] =?UTF-8?q?#72=20[feat]=20Acquire=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/badge/Acquire.java | 27 +++++++++++++++++++ .../badge/repository/AcquireRepository.java | 7 +++++ .../repository/AcquireRepositoryCustom.java | 4 +++ .../repository/AcquireRepositoryImpl.java | 10 +++++++ .../hous/server/domain/user/Onboarding.java | 9 +++---- 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/main/java/hous/server/domain/badge/Acquire.java create mode 100644 src/main/java/hous/server/domain/badge/repository/AcquireRepository.java create mode 100644 src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java diff --git a/src/main/java/hous/server/domain/badge/Acquire.java b/src/main/java/hous/server/domain/badge/Acquire.java new file mode 100644 index 00000000..a20da1db --- /dev/null +++ b/src/main/java/hous/server/domain/badge/Acquire.java @@ -0,0 +1,27 @@ +package hous.server.domain.badge; + +import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Acquire extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "onboarding_id") + private Onboarding onboarding; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "badge_id") + private Badge badge; +} diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepository.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepository.java new file mode 100644 index 00000000..0f364185 --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.badge.repository; + +import hous.server.domain.badge.Acquire; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AcquireRepository extends JpaRepository, AcquireRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java new file mode 100644 index 00000000..3230390c --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.badge.repository; + +public interface AcquireRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java new file mode 100644 index 00000000..7c177972 --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java @@ -0,0 +1,10 @@ +package hous.server.domain.badge.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class AcquireRepositoryImpl implements AcquireRepositoryCustom { + + private final JPAQueryFactory queryFactory; +} diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 870e4c8c..80413927 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -1,7 +1,7 @@ package hous.server.domain.user; import com.fasterxml.jackson.annotation.JsonFormat; -import hous.server.domain.badge.Badge; +import hous.server.domain.badge.Acquire; import hous.server.domain.badge.Represent; import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.personality.Personality; @@ -64,9 +64,8 @@ public class Onboarding extends AuditingTimeEntity { @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List participates = new ArrayList<>(); - @OneToMany(fetch = FetchType.LAZY) - @JoinColumn(name = "badge_id") - private final List badges = new ArrayList<>(); + @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List acquires = new ArrayList<>(); public static Onboarding newInstance(User user, Personality personality, TestScore testScore) { return Onboarding.builder() @@ -114,7 +113,7 @@ public void resetUserInfo() { public void resetBadge() { this.represent = null; - this.badges.clear(); + this.acquires.clear(); } public void resetTestScore(TestScore testScore) { From c7dbd51f830e8e44c7007342c52b2fc69815e9a8 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 15 Sep 2022 14:43:38 +0900 Subject: [PATCH 125/301] =?UTF-8?q?#72=20[fix]=20=EB=B0=A9=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC=ED=95=98=EA=B8=B0=20=EB=A1=9C=EC=A7=81=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 --- src/main/java/hous/server/service/room/RoomService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index b26bdc5b..b55dbb16 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -1,5 +1,6 @@ package hous.server.service.room; +import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; @@ -36,6 +37,7 @@ public class RoomService { private final TodoRepository todoRepository; private final TakeRepository takeRepository; private final DoneRepository doneRepository; + private final AcquireRepository acquireRepository; private final RepresentRepository representRepository; public RoomInfoResponse createRoom(SetRoomNameRequestDto request, Long userId) { @@ -109,10 +111,11 @@ public void leaveRoom(Long userId) { roomRepository.delete(room); } - //내 뱃지, 프로필 작성 내역, 테스트 결과 초기화 + // 내 뱃지, 프로필 작성 내역, 테스트 결과 초기화 if (me.getRepresent() != null) { representRepository.delete(me.getRepresent()); } + acquireRepository.deleteAll(me.getAcquires()); me.resetUserInfo(); me.resetBadge(); me.resetTestScore(me.getTestScore()); From 8ee1fba4f33c73274cb3ef57355070f68a30aa10 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 15 Sep 2022 14:25:54 +0900 Subject: [PATCH 126/301] =?UTF-8?q?#71=20[chore]=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EA=B4=80=EB=A0=A8=20con?= =?UTF-8?q?fig=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 7 +++++++ .github/workflows/pr-check.yml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2997d56a..2ce2fbfc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,6 +33,8 @@ jobs: AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} AWS_REGION: ${{ secrets.AWS_REGION }} + FIREBASE_URI: $${{ secrets.FIREBASE_URI }} + FIREBASE_SERVICE_JSON: $${{ secrets.FIREBASE_SERVICE_JSON }} run: | touch application.properties @@ -58,6 +60,11 @@ jobs: echo cloud.aws.s3.bucket=$AWS_S3_BUCKET >> application.properties echo cloud.aws.region.static=$AWS_REGION >> application.properties echo cloud.aws.stack.auto=false >> application.properties + echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties + + mkdir firebase + touch ./firebase/firebase_service_key.json + echo $FIREBASE_SERVICE_JSON >> firebase_service_key.json - name: Set up JDK 11 uses: actions/setup-java@v1 diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index cf45cb1c..94b47c59 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -33,6 +33,8 @@ jobs: AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} AWS_REGION: ${{ secrets.AWS_REGION }} + FIREBASE_URI: $${{ secrets.FIREBASE_URI }} + FIREBASE_SERVICE_JSON: $${{ secrets.FIREBASE_SERVICE_JSON }} run: | touch application.properties @@ -58,6 +60,11 @@ jobs: echo cloud.aws.s3.bucket=$AWS_S3_BUCKET >> application.properties echo cloud.aws.region.static=$AWS_REGION >> application.properties echo cloud.aws.stack.auto=false >> application.properties + echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties + + mkdir firebase + touch ./firebase/firebase_service_key.json + echo $FIREBASE_SERVICE_JSON >> firebase_service_key.json - name: Set up JDK 11 uses: actions/setup-java@v1 From ff614807fd6f6a0168c686fae5c4464d8c4c2d32 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 15 Sep 2022 15:58:52 +0900 Subject: [PATCH 127/301] =?UTF-8?q?#75=20[feat]=20=EB=B1=83=EC=A7=80=20?= =?UTF-8?q?=ED=9A=8D=EB=93=9D=20=EC=97=AC=EB=B6=80=20=EA=B2=80=EC=82=AC=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../repository/AcquireRepositoryCustom.java | 5 ++++ .../repository/AcquireRepositoryImpl.java | 13 ++++++++++ .../badge/repository/BadgeRepository.java | 7 ++++++ .../repository/BadgeRepositoryCustom.java | 9 +++++++ .../badge/repository/BadgeRepositoryImpl.java | 22 ++++++++++++++++ .../service/badge/BadgeServiceUtils.java | 25 +++++++++++++++++++ 7 files changed, 82 insertions(+) create mode 100644 src/main/java/hous/server/domain/badge/repository/BadgeRepository.java create mode 100644 src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/badge/BadgeServiceUtils.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 1139ed8b..dd854f48 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -50,6 +50,7 @@ public enum ErrorCode { NOT_FOUND_PARTICIPATE_EXCEPTION(NOT_FOUND, "참가중인 방이 존재하지 않습니다."), NOT_FOUND_RULE_EXCEPTION(NOT_FOUND, "존재하지 않는 규칙입니다."), NOT_FOUND_TODO_EXCEPTION(NOT_FOUND, "존재하지 않는 todo 입니다."), + NOT_FOUND_BADGE_EXCEPTION(NOT_FOUND, "존재하지 않는 뱃지 입니다."), NOT_FOUND_PERSONALITY_COLOR_EXCEPTION(NOT_FOUND, "GRAY 에 대한 성향 정보는 존재하지 않습니다."), /** diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java index 3230390c..54d0ac76 100644 --- a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java @@ -1,4 +1,9 @@ package hous.server.domain.badge.repository; +import hous.server.domain.badge.Badge; +import hous.server.domain.user.Onboarding; + public interface AcquireRepositoryCustom { + + boolean existsByOnboardingAndBadge(Onboarding onboarding, Badge badge); } diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java index 7c177972..f6bd7f24 100644 --- a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java @@ -1,10 +1,23 @@ package hous.server.domain.badge.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.badge.Badge; +import hous.server.domain.user.Onboarding; import lombok.RequiredArgsConstructor; +import static hous.server.domain.badge.QAcquire.acquire; + @RequiredArgsConstructor public class AcquireRepositoryImpl implements AcquireRepositoryCustom { private final JPAQueryFactory queryFactory; + + @Override + public boolean existsByOnboardingAndBadge(Onboarding onboarding, Badge badge) { + return queryFactory.selectFrom(acquire) + .where( + acquire.onboarding.eq(onboarding), + acquire.badge.eq(badge) + ).fetchOne() != null; + } } diff --git a/src/main/java/hous/server/domain/badge/repository/BadgeRepository.java b/src/main/java/hous/server/domain/badge/repository/BadgeRepository.java new file mode 100644 index 00000000..d033f61a --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/BadgeRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.badge.repository; + +import hous.server.domain.badge.Badge; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BadgeRepository extends JpaRepository, BadgeRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java new file mode 100644 index 00000000..1382843c --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java @@ -0,0 +1,9 @@ +package hous.server.domain.badge.repository; + +import hous.server.domain.badge.Badge; +import hous.server.domain.badge.BadgeInfo; + +public interface BadgeRepositoryCustom { + + Badge findBadgeByBadgeInfo(BadgeInfo badgeInfo); +} diff --git a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java new file mode 100644 index 00000000..926a7333 --- /dev/null +++ b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java @@ -0,0 +1,22 @@ +package hous.server.domain.badge.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.badge.Badge; +import hous.server.domain.badge.BadgeInfo; +import lombok.RequiredArgsConstructor; + +import static hous.server.domain.badge.QBadge.badge; + +@RequiredArgsConstructor +public class BadgeRepositoryImpl implements BadgeRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Badge findBadgeByBadgeInfo(BadgeInfo badgeInfo) { + return queryFactory + .selectFrom(badge) + .where(badge.info.eq(badgeInfo)) + .fetchOne(); + } +} diff --git a/src/main/java/hous/server/service/badge/BadgeServiceUtils.java b/src/main/java/hous/server/service/badge/BadgeServiceUtils.java new file mode 100644 index 00000000..e2c48942 --- /dev/null +++ b/src/main/java/hous/server/service/badge/BadgeServiceUtils.java @@ -0,0 +1,25 @@ +package hous.server.service.badge; + +import hous.server.common.exception.NotFoundException; +import hous.server.domain.badge.Badge; +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static hous.server.common.exception.ErrorCode.NOT_FOUND_BADGE_EXCEPTION; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BadgeServiceUtils { + + public static boolean hasBadge(BadgeRepository badgeRepository, AcquireRepository acquireRepository, + BadgeInfo badgeInfo, Onboarding onboarding) { + Badge badge = badgeRepository.findBadgeByBadgeInfo(badgeInfo); + if (badge == null) { + throw new NotFoundException(String.format("존재하지 않는 badge (%s) 입니다", badgeInfo.getValue()), NOT_FOUND_BADGE_EXCEPTION); + } + return acquireRepository.existsByOnboardingAndBadge(onboarding, badge); + } +} From 21b7b8da10c7c92e162697f83c2b2a0cdc4dd724 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 15 Sep 2022 16:15:10 +0900 Subject: [PATCH 128/301] =?UTF-8?q?#75=20[feat]=20to-do=20=ED=95=9C?= =?UTF-8?q?=EA=B1=B8=EC=9D=8C=20=EB=B1=83=EC=A7=80=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/badge/Acquire.java | 13 ++++++++++--- .../java/hous/server/domain/user/Onboarding.java | 4 ++++ .../java/hous/server/service/todo/TodoService.java | 13 +++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/domain/badge/Acquire.java b/src/main/java/hous/server/domain/badge/Acquire.java index a20da1db..970d60db 100644 --- a/src/main/java/hous/server/domain/badge/Acquire.java +++ b/src/main/java/hous/server/domain/badge/Acquire.java @@ -2,15 +2,15 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Acquire extends AuditingTimeEntity { @Id @@ -24,4 +24,11 @@ public class Acquire extends AuditingTimeEntity { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "badge_id") private Badge badge; + + public static Acquire newInstance(Onboarding onboarding, Badge badge) { + return Acquire.builder() + .onboarding(onboarding) + .badge(badge) + .build(); + } } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 80413927..7f8118dc 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -91,6 +91,10 @@ public void addParticipate(Participate participate) { this.participates.add(participate); } + public void addAcquire(Acquire acquire) { + this.acquires.add(acquire); + } + public void deleteParticipate(Participate participate) { this.participates.remove(participate); } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 2e8d922a..9789c3aa 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -1,6 +1,10 @@ package hous.server.service.todo; import hous.server.common.util.DateUtils; +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.room.Room; import hous.server.domain.todo.Done; import hous.server.domain.todo.Redo; @@ -14,6 +18,7 @@ import hous.server.domain.user.User; import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.dto.request.CheckTodoRequestDto; import hous.server.service.todo.dto.request.TodoInfoRequestDto; @@ -36,9 +41,12 @@ public class TodoService { private final TakeRepository takeRepository; private final RedoRepository redoRepository; private final DoneRepository doneRepository; + private final BadgeRepository badgeRepository; + private final AcquireRepository acquireRepository; public void createTodo(TodoInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding me = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); TodoServiceUtils.validateTodoCounts(room); Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); @@ -52,6 +60,11 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { todo.addTake(take); }); room.addTodo(todo); + + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_ONE_STEP, me)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_ONE_STEP))); + me.addAcquire(acquire); + } } public void updateTodo(Long todoId, TodoInfoRequestDto request) { From 6024ba4dab74b9b430fba80d0250c3da9bd74706 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 15 Sep 2022 16:55:28 +0900 Subject: [PATCH 129/301] =?UTF-8?q?#75=20[fix]=20fcmService=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=ED=95=B8=EB=93=A4=EB=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firebase/FirebaseCloudMessageService.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index e16075e8..04d45d9d 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.auth.oauth2.GoogleCredentials; import hous.server.common.exception.FeignClientException; +import hous.server.common.exception.InternalServerException; import hous.server.common.util.HttpHeaderUtils; import hous.server.common.util.JwtUtils; import hous.server.common.util.YamlPropertySourceFactory; @@ -20,6 +21,8 @@ import java.io.IOException; import java.util.List; +import static hous.server.common.exception.ErrorCode.INTERNAL_SERVER_EXCEPTION; + @Slf4j @RequiredArgsConstructor @Service @@ -31,7 +34,7 @@ public class FirebaseCloudMessageService { private final FirebaseApiClient firebaseApiCaller; private final JwtUtils jwtProvider; - public void sendMessageTo(String targetToken, String title, String body) throws IOException { + public void sendMessageTo(String targetToken, String title, String body) { String message = makeMessage(targetToken, title, body); try { firebaseApiCaller.requestFcmMessaging(HttpHeaderUtils.withBearerToken(getAccessToken()), message); @@ -44,7 +47,7 @@ public void sendMessageTo(String targetToken, String title, String body) throws } } - private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { + private String makeMessage(String targetToken, String title, String body) { FcmMessage fcmMessage = FcmMessage.builder() .validateOnly(false) .message(FcmMessage.Message.builder() @@ -55,18 +58,25 @@ private String makeMessage(String targetToken, String title, String body) throws .token(targetToken) .build()) .build(); - - return objectMapper.writeValueAsString(fcmMessage); + try { + return objectMapper.writeValueAsString(fcmMessage); + } catch (JsonProcessingException exception) { + log.error(exception.getMessage(), exception); + throw new InternalServerException("FCM makeMessage exception", INTERNAL_SERVER_EXCEPTION); + } } - private String getAccessToken() throws IOException { + private String getAccessToken() { String firebaseConfigPath = "firebase/firebase_service_key.json"; - - GoogleCredentials googleCredentials = GoogleCredentials - .fromStream(new ClassPathResource(firebaseConfigPath).getInputStream()) - .createScoped(List.of("https://www.googleapis.com/auth/cloud-platform")); - - googleCredentials.refreshIfExpired(); - return googleCredentials.getAccessToken().getTokenValue(); + try { + GoogleCredentials googleCredentials = GoogleCredentials + .fromStream(new ClassPathResource(firebaseConfigPath).getInputStream()) + .createScoped(List.of("https://www.googleapis.com/auth/cloud-platform")); + googleCredentials.refreshIfExpired(); + return googleCredentials.getAccessToken().getTokenValue(); + } catch (IOException exception) { + log.error(exception.getMessage(), exception); + throw new InternalServerException("FCM getAccessToken exception", INTERNAL_SERVER_EXCEPTION); + } } } From 9e8c2014deb8d76f0b35f88ae464ec87c192c77c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 15 Sep 2022 17:25:43 +0900 Subject: [PATCH 130/301] =?UTF-8?q?#75=20[feat]=20=EC=83=88=EB=A1=9C?= =?UTF-8?q?=EC=9A=B4=20=EB=B0=B0=EC=A7=80=20=EC=83=9D=EC=84=B1=20=ED=91=B8?= =?UTF-8?q?=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/Notification.java | 9 +++++ .../notification/NotificationMessage.java | 29 ++++++++++++++ .../domain/notification/PushMessage.java | 30 ++++++++++++++ .../repository/NotificationRepository.java | 7 ++++ .../NotificationRepositoryCustom.java | 4 ++ .../NotificationRepositoryImpl.java | 11 +++++ .../notification/NotificationService.java | 40 +++++++++++++++++++ .../hous/server/service/todo/TodoService.java | 3 ++ 8 files changed, 133 insertions(+) create mode 100644 src/main/java/hous/server/domain/notification/NotificationMessage.java create mode 100644 src/main/java/hous/server/domain/notification/PushMessage.java create mode 100644 src/main/java/hous/server/domain/notification/repository/NotificationRepository.java create mode 100644 src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/notification/NotificationService.java diff --git a/src/main/java/hous/server/domain/notification/Notification.java b/src/main/java/hous/server/domain/notification/Notification.java index 60d3ae48..b1933758 100644 --- a/src/main/java/hous/server/domain/notification/Notification.java +++ b/src/main/java/hous/server/domain/notification/Notification.java @@ -30,4 +30,13 @@ public class Notification extends AuditingTimeEntity { @Column(nullable = false) private boolean isRead; + + public static Notification newInstance(Onboarding onboarding, NotificationType type, String content, boolean isRead) { + return Notification.builder() + .onboarding(onboarding) + .type(type) + .content(content) + .isRead(isRead) + .build(); + } } diff --git a/src/main/java/hous/server/domain/notification/NotificationMessage.java b/src/main/java/hous/server/domain/notification/NotificationMessage.java new file mode 100644 index 00000000..e1f3fd56 --- /dev/null +++ b/src/main/java/hous/server/domain/notification/NotificationMessage.java @@ -0,0 +1,29 @@ +package hous.server.domain.notification; + +import hous.server.common.model.EnumModel; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum NotificationMessage implements EnumModel { + + NEW_RULE("Rules가 추가되었어요!"), + NEW_TODO("to-do가 새로 추가되었어요!"), + NEW_TODO_TAKE("to-do의 담당자가 되었어요!"), + TODO_REMIND("to-do가 완료되지 않았어요!"), + NEW_BADGE("배지를 얻었어요!"); + + private final String value; + + @Override + public String getKey() { + return name(); + } + + @Override + public String getValue() { + return value; + } +} diff --git a/src/main/java/hous/server/domain/notification/PushMessage.java b/src/main/java/hous/server/domain/notification/PushMessage.java new file mode 100644 index 00000000..c923d47a --- /dev/null +++ b/src/main/java/hous/server/domain/notification/PushMessage.java @@ -0,0 +1,30 @@ +package hous.server.domain.notification; + +import hous.server.common.model.EnumModel; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum PushMessage implements EnumModel { + + NEW_RULE("새로운 Rules 추가", "우리 집에 새로운 Rules가 추가되었어요.\n어떤 규칙인지 확인해봐요!"), + NEW_TODO("새로운 to-do 추가", "우리 집에 새로운 to-do가 추가되었어요.\n어떤 to-do인지 확인해봐요!"), + TODAY_TODO_START("오늘의 to-do 시작", "상쾌한 Hous-의 아침!\n오늘은 어떤 to-do 기다리고 있을까요?"), + TODO_REMIND("미완료 to-do 알림", "이런, 오늘 해야 할 to-do가 아직 끝나지 않았어요!\n빠르게 확인하고, 후다닥 끝내볼까요?"), + NEW_BADGE("배지 획득", "님, 축하해요!\n새로 받은 배지를 지금 확인해봐요!"); + + private final String title; + private final String body; + + @Override + public String getKey() { + return name(); + } + + @Override + public String getValue() { + return title; + } +} diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepository.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepository.java new file mode 100644 index 00000000..1f3c2ea8 --- /dev/null +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.notification.repository; + +import hous.server.domain.notification.Notification; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationRepository extends JpaRepository, NotificationRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java new file mode 100644 index 00000000..cf7d3153 --- /dev/null +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.notification.repository; + +public interface NotificationRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java new file mode 100644 index 00000000..505cbdca --- /dev/null +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java @@ -0,0 +1,11 @@ +package hous.server.domain.notification.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + + +@RequiredArgsConstructor +public class NotificationRepositoryImpl implements NotificationRepositoryCustom { + + private final JPAQueryFactory queryFactory; +} diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java new file mode 100644 index 00000000..a4c56396 --- /dev/null +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -0,0 +1,40 @@ +package hous.server.service.notification; + +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.notification.Notification; +import hous.server.domain.notification.NotificationMessage; +import hous.server.domain.notification.NotificationType; +import hous.server.domain.notification.PushMessage; +import hous.server.domain.notification.repository.NotificationRepository; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.service.firebase.FirebaseCloudMessageService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class NotificationService { + + private final NotificationRepository notificationRepository; + private final FirebaseCloudMessageService firebaseCloudMessageService; + + public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) { + notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.BADGE, newBadgeNotification(badgeInfo), false)); + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), newBadgePushTitle(badgeInfo), newBadgePushBody(to.getOnboarding())); + } + + private String newBadgePushTitle(BadgeInfo badgeInfo) { + return String.format("'%s' %s", badgeInfo.getValue(), PushMessage.NEW_BADGE.getTitle()); + } + + private String newBadgePushBody(Onboarding onboarding) { + return String.format("%s%s", onboarding.getNickname(), PushMessage.NEW_BADGE.getBody()); + } + + private String newBadgeNotification(BadgeInfo badgeInfo) { + return String.format("\"%s\" %s", badgeInfo.getValue(), NotificationMessage.NEW_BADGE.getValue()); + } +} diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 9789c3aa..a9518024 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -19,6 +19,7 @@ import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.badge.BadgeServiceUtils; +import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.dto.request.CheckTodoRequestDto; import hous.server.service.todo.dto.request.TodoInfoRequestDto; @@ -43,6 +44,7 @@ public class TodoService { private final DoneRepository doneRepository; private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; + private final NotificationService notificationService; public void createTodo(TodoInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -64,6 +66,7 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_ONE_STEP, me)) { Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_ONE_STEP))); me.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.TODO_ONE_STEP); } } From 70055c303d7997196d6fcc00398a4e5136c1e1a3 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 15 Sep 2022 18:20:01 +0900 Subject: [PATCH 131/301] =?UTF-8?q?#76=20[feat]=20=EB=82=98=20=EC=9D=B4?= =?UTF-8?q?=EB=9F=B0=20=EC=82=AC=EB=9E=8C=EC=9D=B4=EC=95=BC=20=EB=B1=83?= =?UTF-8?q?=EC=A7=80=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/user/UserService.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index d61d9ad0..cacdc386 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,5 +1,9 @@ package hous.server.service.user; +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; @@ -11,6 +15,8 @@ import hous.server.domain.user.repository.SettingRepository; import hous.server.domain.user.repository.TestScoreRepository; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeServiceUtils; +import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.request.CreateUserDto; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; @@ -30,6 +36,10 @@ public class UserService { private final SettingRepository settingRepository; private final TestScoreRepository testScoreRepository; private final PersonalityRepository personalityRepository; + private final BadgeRepository badgeRepository; + private final AcquireRepository acquireRepository; + + private final NotificationService notificationService; public Long registerUser(CreateUserDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); @@ -69,10 +79,16 @@ public void updateUserPushState(boolean state, Long userId) { public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); RoomServiceUtils.findParticipatingRoom(user); - Onboarding onboarding = user.getOnboarding(); - TestScore testScore = onboarding.getTestScore(); + Onboarding me = user.getOnboarding(); + TestScore testScore = me.getTestScore(); testScore.updateScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); - onboarding.setPersonality(personality); + me.setPersonality(personality); + + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.I_AM_SUCH_A_PERSON, me)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.I_AM_SUCH_A_PERSON))); + me.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.I_AM_SUCH_A_PERSON); + } } } From 887744a2c997ffccdd669ef9403ee884940f1ec1 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 18:32:05 +0900 Subject: [PATCH 132/301] =?UTF-8?q?#78=20[refactor]=20Redis=20=ED=82=A4=20?= =?UTF-8?q?=EA=B0=92=20final=20=EA=B0=92=EC=9C=BC=EB=A1=9C=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 --- src/main/java/hous/server/common/util/JwtUtils.java | 5 +++-- src/main/java/hous/server/domain/common/RedisKey.java | 9 +++++++++ .../hous/server/service/auth/CreateTokenService.java | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/main/java/hous/server/domain/common/RedisKey.java diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index 584bd4c7..605bbc40 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -1,6 +1,7 @@ package hous.server.common.util; import hous.server.config.security.JwtConstants; +import hous.server.domain.common.RedisKey; import hous.server.service.auth.dto.response.TokenResponse; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; @@ -56,13 +57,13 @@ public TokenResponse createTokenInfo(Long userId) { .compact(); redisTemplate.opsForValue() - .set("RT:" + userId, refreshToken, REFRESH_TOKEN_EXPIRE_TIME, TimeUnit.MILLISECONDS); + .set(RedisKey.REFRESH_TOKEN + userId, refreshToken, REFRESH_TOKEN_EXPIRE_TIME, TimeUnit.MILLISECONDS); return TokenResponse.of(accessToken, refreshToken); } public void expireRefreshToken(Long userId) { - redisTemplate.opsForValue().set("RT:" + userId, "", EXPIRED, TimeUnit.MILLISECONDS); + redisTemplate.opsForValue().set(RedisKey.REFRESH_TOKEN + userId, "", EXPIRED, TimeUnit.MILLISECONDS); } public boolean validateToken(String token) { diff --git a/src/main/java/hous/server/domain/common/RedisKey.java b/src/main/java/hous/server/domain/common/RedisKey.java new file mode 100644 index 00000000..d3d1ea8e --- /dev/null +++ b/src/main/java/hous/server/domain/common/RedisKey.java @@ -0,0 +1,9 @@ +package hous.server.domain.common; + +public final class RedisKey { + + public static final String REFRESH_TOKEN = "RT:"; + public static final String PERSONALITY_TEST_COUNT = "PTC:"; + public static final String CREATE_RULE_COUNT = "CRC:"; + public static final String TODO_COMPLETE_COUNT = "TCC:"; +} diff --git a/src/main/java/hous/server/service/auth/CreateTokenService.java b/src/main/java/hous/server/service/auth/CreateTokenService.java index bb764647..d6be2c60 100644 --- a/src/main/java/hous/server/service/auth/CreateTokenService.java +++ b/src/main/java/hous/server/service/auth/CreateTokenService.java @@ -2,6 +2,7 @@ import hous.server.common.exception.UnAuthorizedException; import hous.server.common.util.JwtUtils; +import hous.server.domain.common.RedisKey; import hous.server.service.auth.dto.request.TokenRequestDto; import hous.server.service.auth.dto.response.TokenResponse; import lombok.RequiredArgsConstructor; @@ -30,7 +31,7 @@ public TokenResponse reissueToken(TokenRequestDto request) { throw new UnAuthorizedException(String.format("주어진 리프레시 토큰 (%s) 이 유효하지 않습니다.", request.getRefreshToken())); } Long userId = jwtProvider.getUserIdFromJwt(request.getAccessToken()); - String refreshToken = (String) redisTemplate.opsForValue().get("RT:" + userId); + String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + userId); if (Objects.isNull(refreshToken)) { throw new UnAuthorizedException(String.format("이미 만료된 리프레시 토큰 (%s) 입니다.", request.getRefreshToken())); From bdf9e5fddad97d2b883b2a785b9caaabcf0c00fd Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 15 Sep 2022 18:42:07 +0900 Subject: [PATCH 133/301] =?UTF-8?q?#76=20[feat]=20=EB=91=90=EA=B7=BC?= =?UTF-8?q?=EB=91=90=EA=B7=BC=20=ED=95=98=EC=9A=B0=EC=8A=A4=20=EB=B1=83?= =?UTF-8?q?=EC=A7=80=20=ED=9A=8D=EB=93=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EC=84=9C=EB=B9=84=EC=8A=A4=EB=8B=A8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=8F=99=EC=9E=91=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9C=84=EC=B9=98=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/room/RoomService.java | 54 +++++++++++++++---- .../server/service/room/RoomServiceUtils.java | 18 ------- .../hous/server/service/todo/TodoService.java | 1 + 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index b55dbb16..f7dc2dbf 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -1,6 +1,9 @@ package hous.server.service.room; +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; @@ -15,6 +18,8 @@ import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeServiceUtils; +import hous.server.service.notification.NotificationService; import hous.server.service.room.dto.request.SetRoomNameRequestDto; import hous.server.service.room.dto.response.RoomInfoResponse; import hous.server.service.todo.TodoServiceUtils; @@ -25,6 +30,7 @@ import java.util.List; import java.util.Optional; +import java.util.Random; @RequiredArgsConstructor @Service @@ -39,27 +45,32 @@ public class RoomService { private final DoneRepository doneRepository; private final AcquireRepository acquireRepository; private final RepresentRepository representRepository; + private final BadgeRepository badgeRepository; + + private final NotificationService notificationService; public RoomInfoResponse createRoom(SetRoomNameRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - Onboarding onboarding = user.getOnboarding(); - RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); - Room room = roomRepository.save(Room.newInstance(onboarding, request.getName(), RoomServiceUtils.createUniqueRoomCode(roomRepository))); - Participate participate = participateRepository.save(Participate.newInstance(onboarding, room)); - onboarding.addParticipate(participate); + Onboarding me = user.getOnboarding(); + RoomServiceUtils.validateNotExistsParticipate(participateRepository, me); + Room room = roomRepository.save(Room.newInstance(me, request.getName(), createUniqueRoomCode())); + Participate participate = participateRepository.save(Participate.newInstance(me, room)); + me.addParticipate(participate); room.addParticipate(participate); + getBadgeByPoundingHouse(user, me); return RoomInfoResponse.of(room); } public RoomInfoResponse joinRoom(Long roomId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - Onboarding onboarding = user.getOnboarding(); - RoomServiceUtils.validateNotExistsParticipate(participateRepository, onboarding); + Onboarding me = user.getOnboarding(); + RoomServiceUtils.validateNotExistsParticipate(participateRepository, me); Room room = RoomServiceUtils.findRoomById(roomRepository, roomId); RoomServiceUtils.validateParticipateCounts(participateRepository, room); - Participate participate = participateRepository.save(Participate.newInstance(onboarding, room)); - onboarding.addParticipate(participate); + Participate participate = participateRepository.save(Participate.newInstance(me, room)); + me.addParticipate(participate); room.addParticipate(participate); + getBadgeByPoundingHouse(user, me); return RoomInfoResponse.of(room); } @@ -120,4 +131,29 @@ public void leaveRoom(Long userId) { me.resetBadge(); me.resetTestScore(me.getTestScore()); } + + private String createUniqueRoomCode() { + String code; + do { + Random random = new Random(); + code = random.ints(48, 91) + .filter(i -> (i <= 57 || i >= 65) && (i <= 90)) + .limit(8) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString(); + } while (isNotUniqueRoomCode(code)); + return code; + } + + private boolean isNotUniqueRoomCode(String code) { + return roomRepository.existsByRoomCode(code); + } + + private void getBadgeByPoundingHouse(User user, Onboarding me) { + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.POUNDING_HOUSE, me)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.POUNDING_HOUSE))); + me.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.POUNDING_HOUSE); + } + } } diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 6f1ddb66..2aa8b2a0 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -14,7 +14,6 @@ import java.util.List; import java.util.Objects; -import java.util.Random; import static hous.server.common.exception.ErrorCode.*; @@ -55,21 +54,4 @@ public static void checkParticipatingRoom(Room userRoom, Room homieRoom) { userRoom.getId(), homieRoom.getId()), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION); } } - - private static boolean isNotUniqueRoomCode(RoomRepository roomRepository, String code) { - return roomRepository.existsByRoomCode(code); - } - - static String createUniqueRoomCode(RoomRepository roomRepository) { - String code; - do { - Random random = new Random(); - code = random.ints(48, 91) - .filter(i -> (i <= 57 || i >= 65) && (i <= 90)) - .limit(8) - .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) - .toString(); - } while (isNotUniqueRoomCode(roomRepository, code)); - return code; - } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index a9518024..34560cdd 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -44,6 +44,7 @@ public class TodoService { private final DoneRepository doneRepository; private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; + private final NotificationService notificationService; public void createTodo(TodoInfoRequestDto request, Long userId) { From 43b68ce23f534798ac77ac9b1f4a6b7078db84c9 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 15 Sep 2022 19:05:30 +0900 Subject: [PATCH 134/301] =?UTF-8?q?#84=20[feat]=20=EA=B8=B0=EB=91=A5?= =?UTF-8?q?=EC=9D=84=20=EC=84=B8=EC=9A=B0=EC=9E=90=20=EB=B1=83=EC=A7=80=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/rule/RuleService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 6bc9b53f..f08797ef 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -1,10 +1,17 @@ package hous.server.service.rule; +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; +import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeServiceUtils; +import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; @@ -21,14 +28,25 @@ public class RuleService { private final UserRepository userRepository; private final RuleRepository ruleRepository; + private final BadgeRepository badgeRepository; + private final AcquireRepository acquireRepository; + + private final NotificationService notificationService; public void createRule(CreateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding me = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); RuleServiceUtils.validateRuleCounts(room); int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room); Rule rule = ruleRepository.save(Rule.newInstance(room, request.getName(), ruleIdx + 1)); room.addRule(rule); + + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.LETS_BUILD_A_POLE, me)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.LETS_BUILD_A_POLE))); + me.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.LETS_BUILD_A_POLE); + } } public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { From d7707664672afe56541446cf94b7a3f7f1e2b4ef Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 19:20:38 +0900 Subject: [PATCH 135/301] =?UTF-8?q?#82=20[feat]=20=EC=9A=B0=EB=A6=AC=20?= =?UTF-8?q?=EC=A7=91=20=ED=98=B8=EB=AF=B8=EB=93=A4=20=EB=B0=B0=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/user/UserService.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index cacdc386..2549408e 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -7,6 +7,8 @@ import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; +import hous.server.domain.room.Participate; +import hous.server.domain.room.Room; import hous.server.domain.user.Onboarding; import hous.server.domain.user.Setting; import hous.server.domain.user.TestScore; @@ -26,6 +28,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @RequiredArgsConstructor @Service @Transactional @@ -78,7 +82,7 @@ public void updateUserPushState(boolean state, Long userId) { public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - RoomServiceUtils.findParticipatingRoom(user); + Room room = RoomServiceUtils.findParticipatingRoom(user); Onboarding me = user.getOnboarding(); TestScore testScore = me.getTestScore(); testScore.updateScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); @@ -90,5 +94,20 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) me.addAcquire(acquire); notificationService.sendNewBadgeNotification(user, BadgeInfo.I_AM_SUCH_A_PERSON); } + + List participates = room.getParticipates(); + int testCompleteCnt = (int) participates.stream() + .filter(participate -> participate.getOnboarding().getPersonality().getColor() != PersonalityColor.GRAY) + .count(); + if (room.getParticipantsCnt() == testCompleteCnt) { + participates.forEach(participate -> { + Onboarding onboarding = participate.getOnboarding(); + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.OUR_HOUSE_HOMIES, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.OUR_HOUSE_HOMIES))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(onboarding.getUser(), BadgeInfo.OUR_HOUSE_HOMIES); + } + }); + } } } From 749d146bc913ab91a6aceebf14790ceb56803370 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 19:22:39 +0900 Subject: [PATCH 136/301] =?UTF-8?q?#82=20[fix]=20Redis=20expire=20time=200?= =?UTF-8?q?L=20=EB=93=A4=EC=96=B4=EA=B0=80=EC=A7=80=20=EC=95=8A=EB=8A=94?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/JwtUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index 605bbc40..f955aba5 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -27,7 +27,7 @@ public class JwtUtils { // private static final long REFRESH_TOKEN_EXPIRE_TIME = 7 * 24 * 60 * 60 * 1000L; // 7일 private static final long ACCESS_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 private static final long REFRESH_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 - private static final long EXPIRED = 0L; + private static final long EXPIRED_TIME = 1L; private final Key secretKey; @@ -63,7 +63,7 @@ public TokenResponse createTokenInfo(Long userId) { } public void expireRefreshToken(Long userId) { - redisTemplate.opsForValue().set(RedisKey.REFRESH_TOKEN + userId, "", EXPIRED, TimeUnit.MILLISECONDS); + redisTemplate.opsForValue().set(RedisKey.REFRESH_TOKEN + userId, "", EXPIRED_TIME, TimeUnit.MILLISECONDS); } public boolean validateToken(String token) { From d87eaeb6dcfc601112f14556dbe36f4115b4c0b7 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 21:02:31 +0900 Subject: [PATCH 137/301] =?UTF-8?q?#88=20[feat]=20=EC=9A=B0=EB=A6=AC=20?= =?UTF-8?q?=EC=A7=91=20=EA=B8=B0=EB=91=A5=20=ED=98=B8=EB=AF=B8=20=EB=B0=B0?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/rule/RuleService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index f08797ef..37a48722 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -4,6 +4,7 @@ import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.common.RedisKey; import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; @@ -18,6 +19,7 @@ import hous.server.service.rule.dto.request.UpdateRuleRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,6 +28,8 @@ @Transactional public class RuleService { + private final RedisTemplate redisTemplate; + private final UserRepository userRepository; private final RuleRepository ruleRepository; private final BadgeRepository badgeRepository; @@ -47,6 +51,22 @@ public void createRule(CreateRuleRequestDto request, Long userId) { me.addAcquire(acquire); notificationService.sendNewBadgeNotification(user, BadgeInfo.LETS_BUILD_A_POLE); } + + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.OUR_HOUSE_PILLAR_HOMIE, me)) { + String createRuleCountString = (String) redisTemplate.opsForValue().get(RedisKey.CREATE_RULE_COUNT + userId); + if (createRuleCountString != null && Integer.parseInt(createRuleCountString) >= 4) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.OUR_HOUSE_PILLAR_HOMIE))); + me.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.OUR_HOUSE_PILLAR_HOMIE); + redisTemplate.delete(RedisKey.CREATE_RULE_COUNT + user.getId()); + } else { + if (createRuleCountString == null) { + redisTemplate.opsForValue().set(RedisKey.CREATE_RULE_COUNT + user.getId(), Integer.toString(1)); + } else { + redisTemplate.opsForValue().set(RedisKey.CREATE_RULE_COUNT + user.getId(), Integer.toString(Integer.parseInt(createRuleCountString) + 1)); + } + } + } } public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { From 874b131a4c04b64da9e220a3a5d0053b90a64599 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 21:59:32 +0900 Subject: [PATCH 138/301] =?UTF-8?q?#90=20[rename]=20DateUtils=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=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 --- src/main/java/hous/server/common/util/DateUtils.java | 6 +++++- src/main/java/hous/server/common/util/MathUtils.java | 2 +- .../java/hous/server/service/home/HomeRetrieveService.java | 2 +- .../java/hous/server/service/todo/TodoRetrieveService.java | 2 +- src/main/java/hous/server/service/todo/TodoService.java | 4 ++-- .../java/hous/server/service/todo/TodoServiceUtils.java | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index f650ad88..fc413db4 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -11,10 +11,14 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class DateUtils { - public static LocalDate today() { + public static LocalDate todayLocalDate() { return LocalDate.now(ZoneId.of("Asia/Seoul")); } + public static LocalDateTime todayLocalDateTime() { + return LocalDateTime.now(ZoneId.of("Asia/Seoul")); + } + public static String parseMonthAndDay(LocalDate date) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd"); return date.format(formatter); diff --git a/src/main/java/hous/server/common/util/MathUtils.java b/src/main/java/hous/server/common/util/MathUtils.java index 2bfa4c23..ceb97f89 100644 --- a/src/main/java/hous/server/common/util/MathUtils.java +++ b/src/main/java/hous/server/common/util/MathUtils.java @@ -13,7 +13,7 @@ public static int percent(int part, int total) { } public static int getAge(LocalDate date) { - LocalDate today = DateUtils.today(); + LocalDate today = DateUtils.todayLocalDate(); return today.getYear() - date.getYear() + 1; } } diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index ba49adbb..8a8244a4 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -36,7 +36,7 @@ public class HomeRetrieveService { public HomeInfoResponse getHomeInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - LocalDate today = DateUtils.today(); + LocalDate today = DateUtils.todayLocalDate(); List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(today, todos); List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(today, user.getOnboarding(), todos); diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index f9b829b5..e2c67f69 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -48,7 +48,7 @@ public UserPersonalityInfoResponse getUsersInfo(Long userId) { public TodoMainResponse getTodoMain(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - LocalDate today = DateUtils.today(); + LocalDate today = DateUtils.todayLocalDate(); List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(today, todos); List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(today, user.getOnboarding(), todos); diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 34560cdd..2efd630e 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -44,7 +44,7 @@ public class TodoService { private final DoneRepository doneRepository; private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; - + private final NotificationService notificationService; public void createTodo(TodoInfoRequestDto request, Long userId) { @@ -99,7 +99,7 @@ public void checkTodo(Long todoId, CheckTodoRequestDto request, Long userId) { Done done = doneRepository.save(Done.newInstance(onboarding, todo)); todo.addDone(done); } else { - Done done = doneRepository.findTodayDoneByOnboardingAndTodo(DateUtils.today(), onboarding, todo); + Done done = doneRepository.findTodayDoneByOnboardingAndTodo(DateUtils.todayLocalDate(), onboarding, todo); if (done != null) { todo.deleteDone(done); doneRepository.delete(done); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 03b4d646..e5be8e06 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -40,7 +40,7 @@ public static void validateTodoCounts(Room room) { } public static void validateTodoStatus(DoneRepository doneRepository, boolean status, Onboarding onboarding, Todo todo) { - if (status == doneRepository.findTodayTodoCheckStatus(DateUtils.today(), onboarding, todo)) { + if (status == doneRepository.findTodayTodoCheckStatus(DateUtils.todayLocalDate(), onboarding, todo)) { throw new ValidationException(String.format("(%s) 유저의 todo (%s) 상태는 이미 (%s) 입니다.", onboarding.getId(), todo.getId(), status), VALIDATION_STATUS_EXCEPTION); } } From 8a1739bfe5d069cf3b78f4149de0e570d73916cc Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 23:47:16 +0900 Subject: [PATCH 139/301] =?UTF-8?q?#90=20[fix]=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=ED=98=95=ED=83=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/notification/NotificationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index a4c56396..2d44a362 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -35,6 +35,6 @@ private String newBadgePushBody(Onboarding onboarding) { } private String newBadgeNotification(BadgeInfo badgeInfo) { - return String.format("\"%s\" %s", badgeInfo.getValue(), NotificationMessage.NEW_BADGE.getValue()); + return String.format("'%s' %s", badgeInfo.getValue(), NotificationMessage.NEW_BADGE.getValue()); } } From 16cb6ef8af80d4fe23d9f3c96742e64ee416c2f4 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 15 Sep 2022 23:47:40 +0900 Subject: [PATCH 140/301] =?UTF-8?q?#90=20[feat]=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 ++ .../hous/server/common/util/DateUtils.java | 18 +++++++ .../user/UserRetrieveController.java | 27 ++++++++++ .../NotificationRepositoryCustom.java | 9 ++++ .../NotificationRepositoryImpl.java | 25 +++++++++ .../NotificationRetrieveService.java | 32 ++++++++++++ .../dto/response/NotificationInfo.java | 31 +++++++++++ .../response/NotificationsInfoResponse.java | 52 +++++++++++++++++++ 8 files changed, 197 insertions(+) create mode 100644 src/main/java/hous/server/service/notification/NotificationRetrieveService.java create mode 100644 src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java create mode 100644 src/main/java/hous/server/service/notification/dto/response/NotificationsInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 0d70aafe..0a7add3b 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -48,6 +48,9 @@ public enum SuccessCode { GET_PERSONALITY_INFO_SUCCESS(OK, "성향 정보 조회 성공입니다."), GET_PERSONALITY_TEST_INFO_SUCCESS(OK, "성향테스트 정보 조회 성공입니다."), + // 알림 + GET_NOTIFICATIONS_INFO_SUCCESS(OK, "알림 목록 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index fc413db4..b0a301cf 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -3,6 +3,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; @@ -33,4 +34,21 @@ public static boolean isSameDate(LocalDateTime localDateTime, LocalDate localDat return localDateTime.format(formatter).equals(localDate.format(formatter)); } + public static String passedTime(LocalDateTime now, LocalDateTime createdAt) { + Duration duration = Duration.between(createdAt, now); + long seconds = duration.getSeconds(); + long minutes = seconds / 60; + long hours = minutes / 60; + long days = hours / 24; + long weeks = days / 7; + long months = days / 30; + long years = days / 365; + if (years != 0) return years + "년 전"; + if (months != 0) return months + "달 전"; + if (weeks != 0) return weeks + "주 전"; + if (days != 0) return days + "일 전"; + if (hours != 0) return hours + "시간 전"; + if (minutes != 0) return minutes + "분 전"; + return "방금"; + } } diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 2b891663..0a088f28 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -6,6 +6,8 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.domain.personality.PersonalityColor; +import hous.server.service.notification.NotificationRetrieveService; +import hous.server.service.notification.dto.response.NotificationsInfoResponse; import hous.server.service.user.UserRetrieveService; import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; import hous.server.service.user.dto.response.PersonalityInfoResponse; @@ -26,6 +28,7 @@ public class UserRetrieveController { private final UserRetrieveService userRetrieveService; + private final NotificationRetrieveService notificationRetrieveService; @ApiOperation( value = "[인증] 온보딩 페이지 - 나의 온보딩 정보 등록여부를 확인합니다." @@ -110,4 +113,28 @@ public ResponseEntity getPersonalityInfo(@ApiParam(name public ResponseEntity> getPersonalityTestInfo() { return SuccessResponse.success(SuccessCode.GET_PERSONALITY_TEST_INFO_SUCCESS, userRetrieveService.getPersonalityTestInfo()); } + + @ApiOperation( + value = "[인증] 알림 페이지 - 알림 목록을 조회합니다.", + notes = "알림 목록을 스크롤 페이지네이션으로 조회합니다.\n" + + "size 에는 스크롤 1회당 조회할 개수를 담습니다.\n" + + "최초 요청으로 lastNotificationId 에 Long 최대값을 담습니다.\n" + + "다음 스크롤의 lastNotificationId 에는 nextCursor 값을 담습니다.\n" + + "nextCursor = -1 일 경우 더이상 조회할 데이터가 없음을 의미합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "알림 목록 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/user/notifications") + public ResponseEntity getNotificationsInfo(@ApiParam(name = "size", value = "스크롤 1회당 조회할 개수", required = true, example = "10") + @RequestParam int size, + @ApiParam(name = "lastNotificationId", value = "마지막으로 조회된 notificationId", required = true, example = "100") + @RequestParam Long lastNotificationId, + @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_NOTIFICATIONS_INFO_SUCCESS, notificationRetrieveService.getNotificationsInfo(size, lastNotificationId, userId)); + } } diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java index cf7d3153..89ed0bfb 100644 --- a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java @@ -1,4 +1,13 @@ package hous.server.domain.notification.repository; +import hous.server.domain.notification.Notification; +import hous.server.domain.user.Onboarding; + +import java.util.List; + public interface NotificationRepositoryCustom { + + List findNotificationsByOnboardingAndCursor(Onboarding onboarding, Long lastNotificationId, int size); + + long countAllByOnboarding(Onboarding onboarding); } diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java index 505cbdca..07169921 100644 --- a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java @@ -1,11 +1,36 @@ package hous.server.domain.notification.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.notification.Notification; +import hous.server.domain.user.Onboarding; import lombok.RequiredArgsConstructor; +import java.util.List; + +import static hous.server.domain.notification.QNotification.notification; + @RequiredArgsConstructor public class NotificationRepositoryImpl implements NotificationRepositoryCustom { private final JPAQueryFactory queryFactory; + + @Override + public List findNotificationsByOnboardingAndCursor(Onboarding onboarding, Long lastNotificationId, int size) { + return queryFactory.selectFrom(notification) + .where( + notification.onboarding.eq(onboarding), + notification.id.lt(lastNotificationId) + ) + .limit(size) + .orderBy(notification.id.desc()) + .fetch(); + } + + @Override + public long countAllByOnboarding(Onboarding onboarding) { + return queryFactory.selectFrom(notification) + .where(notification.onboarding.eq(onboarding)) + .fetch().size(); + } } diff --git a/src/main/java/hous/server/service/notification/NotificationRetrieveService.java b/src/main/java/hous/server/service/notification/NotificationRetrieveService.java new file mode 100644 index 00000000..8024ccca --- /dev/null +++ b/src/main/java/hous/server/service/notification/NotificationRetrieveService.java @@ -0,0 +1,32 @@ +package hous.server.service.notification; + +import hous.server.domain.common.collection.ScrollPaginationCollection; +import hous.server.domain.notification.Notification; +import hous.server.domain.notification.repository.NotificationRepository; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.notification.dto.response.NotificationsInfoResponse; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class NotificationRetrieveService { + + private final UserRepository userRepository; + private final NotificationRepository notificationRepository; + + public NotificationsInfoResponse getNotificationsInfo(int size, Long lastNotificationId, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding me = user.getOnboarding(); + List notifications = notificationRepository.findNotificationsByOnboardingAndCursor(me, lastNotificationId, size + 1); + ScrollPaginationCollection notificationsCursor = ScrollPaginationCollection.of(notifications, size); + return NotificationsInfoResponse.of(notificationsCursor, notificationRepository.countAllByOnboarding(me)); + } +} diff --git a/src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java b/src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java new file mode 100644 index 00000000..5004e1e5 --- /dev/null +++ b/src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java @@ -0,0 +1,31 @@ +package hous.server.service.notification.dto.response; + +import hous.server.common.util.DateUtils; +import hous.server.domain.notification.Notification; +import hous.server.domain.notification.NotificationType; +import lombok.*; + +import java.time.LocalDateTime; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class NotificationInfo { + + private Long notificationId; + private NotificationType type; + private String content; + private boolean isRead; + private String createdAt; + + public static NotificationInfo of(Notification notification, LocalDateTime now) { + return NotificationInfo.builder() + .notificationId(notification.getId()) + .type(notification.getType()) + .content(notification.getContent()) + .createdAt(DateUtils.passedTime(now, notification.getCreatedAt())) + .build(); + } +} diff --git a/src/main/java/hous/server/service/notification/dto/response/NotificationsInfoResponse.java b/src/main/java/hous/server/service/notification/dto/response/NotificationsInfoResponse.java new file mode 100644 index 00000000..ca5bfc6a --- /dev/null +++ b/src/main/java/hous/server/service/notification/dto/response/NotificationsInfoResponse.java @@ -0,0 +1,52 @@ +package hous.server.service.notification.dto.response; + +import hous.server.common.util.DateUtils; +import hous.server.domain.common.collection.ScrollPaginationCollection; +import hous.server.domain.notification.Notification; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class NotificationsInfoResponse { + private static final long LAST_CURSOR = -1L; + + private List contents = new ArrayList<>(); + private long totalElements; + private long nextCursor; + + private NotificationsInfoResponse(List contents, long totalElements, long nextCursor) { + this.contents = contents; + this.totalElements = totalElements; + this.nextCursor = nextCursor; + } + + public static NotificationsInfoResponse of(ScrollPaginationCollection notificationsScroll, long totalElements) { + if (notificationsScroll.isLastScroll()) { + return NotificationsInfoResponse.newLastScroll(notificationsScroll.getCurrentScrollItems(), totalElements); + } + return NotificationsInfoResponse.newScrollHasNext(notificationsScroll.getCurrentScrollItems(), totalElements, notificationsScroll.getNextCursor().getId()); + } + + private static NotificationsInfoResponse newLastScroll(List notificationsScroll, long totalElements) { + return newScrollHasNext(notificationsScroll, totalElements, LAST_CURSOR); + } + + private static NotificationsInfoResponse newScrollHasNext(List notificationsScroll, long totalElements, long nextCursor) { + return new NotificationsInfoResponse(getContents(notificationsScroll, DateUtils.todayLocalDateTime()), totalElements, nextCursor); + } + + private static List getContents(List notificationsScroll, LocalDateTime now) { + return notificationsScroll.stream() + .map(notification -> NotificationInfo.of(notification, now)) + .collect(Collectors.toList()); + } +} From f62fe6439ab3d5d60e993c36b79a21d4bff5a351 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 15 Sep 2022 23:27:53 +0900 Subject: [PATCH 141/301] =?UTF-8?q?#86=20[feat]=20=EB=82=98=EC=9D=98=20?= =?UTF-8?q?=EB=B1=83=EC=A7=80=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 + .../user/UserRetrieveController.java | 25 +++++- .../repository/AcquireRepositoryCustom.java | 5 ++ .../repository/AcquireRepositoryImpl.java | 13 +++ .../repository/BadgeRepositoryCustom.java | 4 + .../badge/repository/BadgeRepositoryImpl.java | 10 +++ .../service/user/UserRetrieveService.java | 23 +++-- .../dto/response/MyBadgeInfoResponse.java | 85 +++++++++++++++++++ .../user/dto/response/RepresentBadgeInfo.java | 23 +++++ 9 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java create mode 100644 src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 0d70aafe..6fe22108 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -48,6 +48,9 @@ public enum SuccessCode { GET_PERSONALITY_INFO_SUCCESS(OK, "성향 정보 조회 성공입니다."), GET_PERSONALITY_TEST_INFO_SUCCESS(OK, "성향테스트 정보 조회 성공입니다."), + // 뱃지 + GET_BADGE_INFO_SUCCESS(OK, "나의 뱃지 목록 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 2b891663..a7f8b4c3 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -7,10 +7,7 @@ import hous.server.config.resolver.UserId; import hous.server.domain.personality.PersonalityColor; import hous.server.service.user.UserRetrieveService; -import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; -import hous.server.service.user.dto.response.PersonalityInfoResponse; -import hous.server.service.user.dto.response.PersonalityTestInfoResponse; -import hous.server.service.user.dto.response.UserInfoResponse; +import hous.server.service.user.dto.response.*; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -110,4 +107,24 @@ public ResponseEntity getPersonalityInfo(@ApiParam(name public ResponseEntity> getPersonalityTestInfo() { return SuccessResponse.success(SuccessCode.GET_PERSONALITY_TEST_INFO_SUCCESS, userRetrieveService.getPersonalityTestInfo()); } + + @ApiOperation( + value = "[인증] 마이 페이지(뱃지 목록 뷰) - 나의 뱃지 정보를 조회합니다.", + notes = "대표 뱃지가 없는 경우, null을 보냅니다.\n" + + "뱃지 목록에서는 모든 뱃지 리스트를 전달하지만. 내가 획득한 뱃지의 경우 acquire = true 입니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "나의 뱃지 목록 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 방입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/user/badge") + public ResponseEntity getMyBadgeList(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_BADGE_INFO_SUCCESS, userRetrieveService.getMyBadgeList(userId)); + } } diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java index 54d0ac76..5c64f2b6 100644 --- a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryCustom.java @@ -1,9 +1,14 @@ package hous.server.domain.badge.repository; +import hous.server.domain.badge.Acquire; import hous.server.domain.badge.Badge; import hous.server.domain.user.Onboarding; +import java.util.List; + public interface AcquireRepositoryCustom { boolean existsByOnboardingAndBadge(Onboarding onboarding, Badge badge); + + List findAllAcquireByOnboarding(Onboarding onboarding); } diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java index f6bd7f24..c0995a52 100644 --- a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java @@ -1,10 +1,13 @@ package hous.server.domain.badge.repository; import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.badge.Acquire; import hous.server.domain.badge.Badge; import hous.server.domain.user.Onboarding; import lombok.RequiredArgsConstructor; +import java.util.List; + import static hous.server.domain.badge.QAcquire.acquire; @RequiredArgsConstructor @@ -20,4 +23,14 @@ public boolean existsByOnboardingAndBadge(Onboarding onboarding, Badge badge) { acquire.badge.eq(badge) ).fetchOne() != null; } + + @Override + public List findAllAcquireByOnboarding(Onboarding onboarding) { + return queryFactory.selectFrom(acquire) + .where( + acquire.onboarding.eq(onboarding) + ) + .orderBy(acquire.badge.id.asc()) + .fetch(); + } } diff --git a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java index 1382843c..56aa6f1d 100644 --- a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java +++ b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java @@ -3,7 +3,11 @@ import hous.server.domain.badge.Badge; import hous.server.domain.badge.BadgeInfo; +import java.util.List; + public interface BadgeRepositoryCustom { Badge findBadgeByBadgeInfo(BadgeInfo badgeInfo); + + List findAllBadge(); } diff --git a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java index 926a7333..bbbe0940 100644 --- a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java +++ b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java @@ -5,6 +5,8 @@ import hous.server.domain.badge.BadgeInfo; import lombok.RequiredArgsConstructor; +import java.util.List; + import static hous.server.domain.badge.QBadge.badge; @RequiredArgsConstructor @@ -19,4 +21,12 @@ public Badge findBadgeByBadgeInfo(BadgeInfo badgeInfo) { .where(badge.info.eq(badgeInfo)) .fetchOne(); } + + @Override + public List findAllBadge() { + return queryFactory + .selectFrom(badge) + .orderBy(badge.id.asc()) + .fetch(); + } } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 09d390de..6a324454 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -1,6 +1,10 @@ package hous.server.service.user; +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.Badge; import hous.server.domain.badge.Represent; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; @@ -8,15 +12,11 @@ import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.personality.repository.PersonalityTestRepository; import hous.server.domain.room.Room; -import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; -import hous.server.service.user.dto.response.CheckOnboardingInfoResponse; -import hous.server.service.user.dto.response.PersonalityInfoResponse; -import hous.server.service.user.dto.response.PersonalityTestInfoResponse; -import hous.server.service.user.dto.response.UserInfoResponse; +import hous.server.service.user.dto.response.*; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,7 +33,8 @@ public class UserRetrieveService { private final PersonalityRepository personalityRepository; private final PersonalityTestRepository personalityTestRepository; private final RepresentRepository representRepository; - private final RoomRepository roomRepository; + private final BadgeRepository badgeRepository; + private final AcquireRepository acquireRepository; public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -69,6 +70,16 @@ public List getPersonalityTestInfo() { .collect(Collectors.toList()); } + public MyBadgeInfoResponse getMyBadgeList(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); + RoomServiceUtils.findParticipatingRoom(user); + Represent represent = onboarding.getRepresent(); + List badgeList = badgeRepository.findAllBadge(); + List myBadges = acquireRepository.findAllAcquireByOnboarding(onboarding); + return MyBadgeInfoResponse.of(represent, badgeList, myBadges); + } + private UserInfoResponse getProfileInfoByUser(User user) { Onboarding onboarding = user.getOnboarding(); Represent represent = representRepository.findRepresentByOnboarding(onboarding); diff --git a/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java new file mode 100644 index 00000000..9b8ad8da --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java @@ -0,0 +1,85 @@ +package hous.server.service.user.dto.response; + +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.Badge; +import hous.server.domain.badge.Represent; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class MyBadgeInfoResponse { + private RepresentBadgeInfo representBadge; + private List badges; + + public static MyBadgeInfoResponse of(Represent represent, List badgeList, List myBadges) { + RepresentBadgeInfo representBadge = represent != null ? RepresentBadgeInfo.of(represent) : null; + List badges = !badgeList.isEmpty() ? BadgeInfo.of(badgeList, myBadges) : new ArrayList<>(); + return MyBadgeInfoResponse.builder() + .representBadge(representBadge) + .badges(badges) + .build(); + } + + @ToString + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + public static class BadgeInfo extends RepresentBadgeInfo { + private boolean acquire; + private String description; + + @Builder(access = AccessLevel.PRIVATE) + public BadgeInfo(Long badgeId, String name, String imageUrl, boolean acquire, String description) { + super(badgeId, name, imageUrl); + this.acquire = acquire; + this.description = description; + } + + private static BadgeInfo toBadgeInfo(Badge badge, boolean acquire) { + return BadgeInfo.builder() + .badgeId(badge.getId()) + .name(badge.getInfo().getValue()) + .imageUrl(badge.getInfo().getImageUrl()) + .acquire(acquire) + .description(badge.getInfo().getDescription()) + .build(); + } + + public static BadgeInfo of(BadgeInfo badgeInfo, boolean acquire) { + return BadgeInfo.builder() + .badgeId(badgeInfo.getBadgeId()) + .name(badgeInfo.getName()) + .imageUrl(badgeInfo.getImageUrl()) + .acquire(acquire) + .description(badgeInfo.getDescription()) + .build(); + } + + public static List of(List badgesList, List acquireBadgesList) { + List acquireBadgeInfos = acquireBadgesList.stream() + .map(acquire -> toBadgeInfo(acquire.getBadge(), true)) + .collect(Collectors.toList()); + + List badgeInfos = badgesList.stream() + .map(badge -> toBadgeInfo(badge, false)) + .collect(Collectors.toList()); + + List badges = new ArrayList<>(); + for (int i = 0; i < badgeInfos.size(); i++) { + badges.add(BadgeInfo.of(badgeInfos.get(i), false)); + for (int j = 0; j < acquireBadgeInfos.size(); j++) { + if (badgeInfos.get(i).getBadgeId().equals(acquireBadgeInfos.get(j).getBadgeId())) { + badges.set(i, BadgeInfo.of(acquireBadgeInfos.get(j), true)); + } + } + } + return badges; + } + } +} diff --git a/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java b/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java new file mode 100644 index 00000000..4e8be134 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java @@ -0,0 +1,23 @@ +package hous.server.service.user.dto.response; + +import hous.server.domain.badge.Represent; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@Builder(access = AccessLevel.PRIVATE) +public class RepresentBadgeInfo { + private Long badgeId; + private String name; + private String imageUrl; + + public static RepresentBadgeInfo of(Represent represent) { + return RepresentBadgeInfo.builder() + .badgeId(represent.getBadge().getId()) + .name(represent.getBadge().getInfo().getValue()) + .imageUrl(represent.getBadge().getInfo().getImageUrl()) + .build(); + } +} From 081a84920d013c08328c750369a246e6155c3f61 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 16 Sep 2022 01:15:43 +0900 Subject: [PATCH 142/301] =?UTF-8?q?#86=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81=20=EB=B0=8F=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/UserRetrieveController.java | 4 +- .../repository/AcquireRepositoryImpl.java | 4 +- .../service/user/UserRetrieveService.java | 8 ++- .../dto/response/MyBadgeInfoResponse.java | 57 ++++++------------- .../user/dto/response/RepresentBadgeInfo.java | 1 + 5 files changed, 26 insertions(+), 48 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index a7f8b4c3..64ff2dc5 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -118,12 +118,12 @@ public ResponseEntity> getPersonalityTestInfo( @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" - + "2. 존재하지 않는 방입니다.", + + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping("/user/badge") + @GetMapping("/user/badges") public ResponseEntity getMyBadgeList(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_BADGE_INFO_SUCCESS, userRetrieveService.getMyBadgeList(userId)); } diff --git a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java index c0995a52..0351a9f7 100644 --- a/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java +++ b/src/main/java/hous/server/domain/badge/repository/AcquireRepositoryImpl.java @@ -27,9 +27,7 @@ public boolean existsByOnboardingAndBadge(Onboarding onboarding, Badge badge) { @Override public List findAllAcquireByOnboarding(Onboarding onboarding) { return queryFactory.selectFrom(acquire) - .where( - acquire.onboarding.eq(onboarding) - ) + .where(acquire.onboarding.eq(onboarding)) .orderBy(acquire.badge.id.asc()) .fetch(); } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 6a324454..b3b35a8c 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -75,9 +75,11 @@ public MyBadgeInfoResponse getMyBadgeList(Long userId) { Onboarding onboarding = user.getOnboarding(); RoomServiceUtils.findParticipatingRoom(user); Represent represent = onboarding.getRepresent(); - List badgeList = badgeRepository.findAllBadge(); - List myBadges = acquireRepository.findAllAcquireByOnboarding(onboarding); - return MyBadgeInfoResponse.of(represent, badgeList, myBadges); + List badges = badgeRepository.findAllBadge(); + List myBadges = acquireRepository.findAllAcquireByOnboarding(onboarding).stream() + .map(Acquire::getBadge) + .collect(Collectors.toList()); + return MyBadgeInfoResponse.of(represent, badges, myBadges); } private UserInfoResponse getProfileInfoByUser(User user) { diff --git a/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java index 9b8ad8da..bca83ba2 100644 --- a/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java @@ -1,11 +1,10 @@ package hous.server.service.user.dto.response; -import hous.server.domain.badge.Acquire; +import com.fasterxml.jackson.annotation.JsonProperty; import hous.server.domain.badge.Badge; import hous.server.domain.badge.Represent; import lombok.*; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -18,12 +17,10 @@ public class MyBadgeInfoResponse { private RepresentBadgeInfo representBadge; private List badges; - public static MyBadgeInfoResponse of(Represent represent, List badgeList, List myBadges) { - RepresentBadgeInfo representBadge = represent != null ? RepresentBadgeInfo.of(represent) : null; - List badges = !badgeList.isEmpty() ? BadgeInfo.of(badgeList, myBadges) : new ArrayList<>(); + public static MyBadgeInfoResponse of(Represent represent, List badgeList, List myBadges) { return MyBadgeInfoResponse.builder() - .representBadge(representBadge) - .badges(badges) + .representBadge(RepresentBadgeInfo.of(represent)) + .badges(BadgeInfo.of(badgeList, myBadges)) .build(); } @@ -31,55 +28,35 @@ public static MyBadgeInfoResponse of(Represent represent, List badgeList, @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class BadgeInfo extends RepresentBadgeInfo { - private boolean acquire; + private boolean isAcquired; private String description; + @JsonProperty("isAcquired") + public boolean isAcquired() { + return isAcquired; + } + @Builder(access = AccessLevel.PRIVATE) - public BadgeInfo(Long badgeId, String name, String imageUrl, boolean acquire, String description) { + public BadgeInfo(Long badgeId, String name, String imageUrl, boolean isAcquired, String description) { super(badgeId, name, imageUrl); - this.acquire = acquire; + this.isAcquired = isAcquired; this.description = description; } - private static BadgeInfo toBadgeInfo(Badge badge, boolean acquire) { + public static BadgeInfo of(Badge badge, boolean isAcquired) { return BadgeInfo.builder() .badgeId(badge.getId()) .name(badge.getInfo().getValue()) .imageUrl(badge.getInfo().getImageUrl()) - .acquire(acquire) + .isAcquired(isAcquired) .description(badge.getInfo().getDescription()) .build(); } - public static BadgeInfo of(BadgeInfo badgeInfo, boolean acquire) { - return BadgeInfo.builder() - .badgeId(badgeInfo.getBadgeId()) - .name(badgeInfo.getName()) - .imageUrl(badgeInfo.getImageUrl()) - .acquire(acquire) - .description(badgeInfo.getDescription()) - .build(); - } - - public static List of(List badgesList, List acquireBadgesList) { - List acquireBadgeInfos = acquireBadgesList.stream() - .map(acquire -> toBadgeInfo(acquire.getBadge(), true)) - .collect(Collectors.toList()); - - List badgeInfos = badgesList.stream() - .map(badge -> toBadgeInfo(badge, false)) + public static List of(List badges, List myBadges) { + return badges.stream() + .map(badge -> BadgeInfo.of(badge, myBadges.contains(badge))) .collect(Collectors.toList()); - - List badges = new ArrayList<>(); - for (int i = 0; i < badgeInfos.size(); i++) { - badges.add(BadgeInfo.of(badgeInfos.get(i), false)); - for (int j = 0; j < acquireBadgeInfos.size(); j++) { - if (badgeInfos.get(i).getBadgeId().equals(acquireBadgeInfos.get(j).getBadgeId())) { - badges.set(i, BadgeInfo.of(acquireBadgeInfos.get(j), true)); - } - } - } - return badges; } } } diff --git a/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java b/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java index 4e8be134..5634fbfd 100644 --- a/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java +++ b/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java @@ -14,6 +14,7 @@ public class RepresentBadgeInfo { private String imageUrl; public static RepresentBadgeInfo of(Represent represent) { + if (represent == null) return null; return RepresentBadgeInfo.builder() .badgeId(represent.getBadge().getId()) .name(represent.getBadge().getInfo().getValue()) From 0b05a81f5c4e900df2aa8723460db297f725db17 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 16 Sep 2022 02:16:09 +0900 Subject: [PATCH 143/301] =?UTF-8?q?#91=20[fix]=20=EB=B0=A9=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=ED=99=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/NotificationRepositoryCustom.java | 2 ++ .../repository/NotificationRepositoryImpl.java | 7 +++++++ src/main/java/hous/server/service/room/RoomService.java | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java index 89ed0bfb..31ae4f03 100644 --- a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java @@ -10,4 +10,6 @@ public interface NotificationRepositoryCustom { List findNotificationsByOnboardingAndCursor(Onboarding onboarding, Long lastNotificationId, int size); long countAllByOnboarding(Onboarding onboarding); + + List findNotificationsByOnboarding(Onboarding onboarding); } diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java index 07169921..66fd3d1f 100644 --- a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java @@ -33,4 +33,11 @@ public long countAllByOnboarding(Onboarding onboarding) { .where(notification.onboarding.eq(onboarding)) .fetch().size(); } + + @Override + public List findNotificationsByOnboarding(Onboarding onboarding) { + return queryFactory.selectFrom(notification) + .where(notification.onboarding.eq(onboarding)) + .fetch(); + } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index f7dc2dbf..4b960a04 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -5,6 +5,7 @@ import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; +import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; @@ -46,6 +47,7 @@ public class RoomService { private final AcquireRepository acquireRepository; private final RepresentRepository representRepository; private final BadgeRepository badgeRepository; + private final NotificationRepository notificationRepository; private final NotificationService notificationService; @@ -122,11 +124,12 @@ public void leaveRoom(Long userId) { roomRepository.delete(room); } - // 내 뱃지, 프로필 작성 내역, 테스트 결과 초기화 + // 내 뱃지, 알림 목록, 프로필 작성 내역, 테스트 결과 초기화 if (me.getRepresent() != null) { representRepository.delete(me.getRepresent()); } acquireRepository.deleteAll(me.getAcquires()); + notificationRepository.deleteAll(notificationRepository.findNotificationsByOnboarding(me)); me.resetUserInfo(); me.resetBadge(); me.resetTestScore(me.getTestScore()); From 78d0db277c181c59c7fbaef9bdd4b80459fe7455 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 16 Sep 2022 02:15:40 +0900 Subject: [PATCH 144/301] =?UTF-8?q?#94=20[fix]=20reqeustDto=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=AA=85=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/auth/dto/request/LoginDto.java | 6 +++--- src/main/java/hous/server/service/user/UserService.java | 4 ++-- .../{CreateUserDto.java => CreateUserRequestDto.java} | 6 +++--- .../user/dto/request/SetOnboardingInfoRequestDto.java | 6 ++++-- .../service/user/dto/request/UpdateTestScoreRequestDto.java | 4 ++-- .../service/user/dto/request/UpdateUserInfoRequestDto.java | 6 ++++-- 6 files changed, 18 insertions(+), 14 deletions(-) rename src/main/java/hous/server/service/user/dto/request/{CreateUserDto.java => CreateUserRequestDto.java} (61%) diff --git a/src/main/java/hous/server/service/auth/dto/request/LoginDto.java b/src/main/java/hous/server/service/auth/dto/request/LoginDto.java index 6d318a55..7f3cd95e 100644 --- a/src/main/java/hous/server/service/auth/dto/request/LoginDto.java +++ b/src/main/java/hous/server/service/auth/dto/request/LoginDto.java @@ -1,7 +1,7 @@ package hous.server.service.auth.dto.request; import hous.server.domain.user.UserSocialType; -import hous.server.service.user.dto.request.CreateUserDto; +import hous.server.service.user.dto.request.CreateUserRequestDto; import lombok.*; @ToString @@ -20,7 +20,7 @@ public static LoginDto of(UserSocialType socialType, String token, String fcmTok return new LoginDto(socialType, token, fcmToken); } - public CreateUserDto toCreateUserDto(String socialId) { - return CreateUserDto.of(socialId, socialType, fcmToken); + public CreateUserRequestDto toCreateUserDto(String socialId) { + return CreateUserRequestDto.of(socialId, socialType, fcmToken); } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 2549408e..96a6afbe 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -20,7 +20,7 @@ import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; -import hous.server.service.user.dto.request.CreateUserDto; +import hous.server.service.user.dto.request.CreateUserRequestDto; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; @@ -45,7 +45,7 @@ public class UserService { private final NotificationService notificationService; - public Long registerUser(CreateUserDto request) { + public Long registerUser(CreateUserRequestDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); User user = userRepository.save(User.newInstance( request.getSocialId(), request.getSocialType(), request.getFcmToken(), diff --git a/src/main/java/hous/server/service/user/dto/request/CreateUserDto.java b/src/main/java/hous/server/service/user/dto/request/CreateUserRequestDto.java similarity index 61% rename from src/main/java/hous/server/service/user/dto/request/CreateUserDto.java rename to src/main/java/hous/server/service/user/dto/request/CreateUserRequestDto.java index d872f371..28baa9e4 100644 --- a/src/main/java/hous/server/service/user/dto/request/CreateUserDto.java +++ b/src/main/java/hous/server/service/user/dto/request/CreateUserRequestDto.java @@ -7,7 +7,7 @@ @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CreateUserDto { +public class CreateUserRequestDto { private String socialId; @@ -15,7 +15,7 @@ public class CreateUserDto { private String fcmToken; - public static CreateUserDto of(String socialId, UserSocialType socialType, String fcmToken) { - return new CreateUserDto(socialId, socialType, fcmToken); + public static CreateUserRequestDto of(String socialId, UserSocialType socialType, String fcmToken) { + return new CreateUserRequestDto(socialId, socialType, fcmToken); } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index 82f35bd4..35374d34 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -3,7 +3,10 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModelProperty; -import lombok.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; @@ -13,7 +16,6 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor(access = AccessLevel.PROTECTED) public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java index 67047f82..c4e1761e 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java @@ -8,8 +8,8 @@ @ToString @Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class UpdateTestScoreRequestDto { @ApiModelProperty(value = "빛", example = "4") diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java index 14ec7141..56d2cca3 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java @@ -2,7 +2,10 @@ import io.swagger.annotations.ApiModelProperty; -import lombok.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; @@ -10,7 +13,6 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor(access = AccessLevel.PRIVATE) public class UpdateUserInfoRequestDto extends SetOnboardingInfoRequestDto { @ApiModelProperty(value = "MBTI", example = "CUTE") From fe8de620b7e4ec405eeff3197bad9b19c845bf48 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 16 Sep 2022 03:42:05 +0900 Subject: [PATCH 145/301] =?UTF-8?q?#94=20[feat]=20=EB=82=98=EC=9D=98=20?= =?UTF-8?q?=EB=8C=80=ED=91=9C=20=EB=B1=83=EC=A7=80=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 1 + .../controller/user/UserController.java | 29 +++++++++++++++++-- .../hous/server/domain/badge/Represent.java | 13 +++++++-- .../repository/BadgeRepositoryCustom.java | 2 ++ .../badge/repository/BadgeRepositoryImpl.java | 8 +++++ .../hous/server/domain/user/Onboarding.java | 4 +++ .../service/badge/AcquireServiceUtils.java | 20 +++++++++++++ .../service/badge/BadgeServiceUtils.java | 8 +++++ .../hous/server/service/user/UserService.java | 15 ++++++++++ 9 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 src/main/java/hous/server/service/badge/AcquireServiceUtils.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index dd854f48..7b0a8544 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -38,6 +38,7 @@ public enum ErrorCode { FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "같은 방에 참가하고 있지 않습니다."), + FORBIDDEN_ACQUIRE_BADGE_EXCEPTION(FORBIDDEN, "유저가 획득한 뱃지가 아닙니다."), /** * 404 Not Found diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 13c2e104..2978cb7a 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -41,7 +41,7 @@ public class UserController { @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 같은 방에 참가하고 있지 않습니다.\n", + + "2. 같은 방에 참가하고 있지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @@ -125,7 +125,7 @@ public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = " @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 같은 방에 참가하고 있지 않습니다.\n", + + "2. 같은 방에 참가하고 있지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @@ -137,4 +137,29 @@ public ResponseEntity updateUserTestScore( userService.updateUserTestScore(request, userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 마이 페이지(뱃지 목록 뷰) - 대표 뱃지를 설정합니다.", + notes = "대표 뱃지를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 400, message = "잘못된 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "유저가 획득한 뱃지가 아닙니다.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/user/badge/{badgeId}/represent") + public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", value = "대표 뱃지로 설정할 badge 의 id", required = true, example = "1") + @PathVariable Long badgeId, + @ApiIgnore @UserId Long userId) { + userService.updateRepresentBadge(badgeId, userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/badge/Represent.java b/src/main/java/hous/server/domain/badge/Represent.java index de856db7..c9a6acc6 100644 --- a/src/main/java/hous/server/domain/badge/Represent.java +++ b/src/main/java/hous/server/domain/badge/Represent.java @@ -2,15 +2,15 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class Represent extends AuditingTimeEntity { @Id @@ -24,4 +24,11 @@ public class Represent extends AuditingTimeEntity { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "badge_id") private Badge badge; + + public static Represent newInstance(Onboarding onboarding, Badge badge) { + return Represent.builder() + .onboarding(onboarding) + .badge(badge) + .build(); + } } diff --git a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java index 56aa6f1d..f5608f17 100644 --- a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java +++ b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryCustom.java @@ -10,4 +10,6 @@ public interface BadgeRepositoryCustom { Badge findBadgeByBadgeInfo(BadgeInfo badgeInfo); List findAllBadge(); + + Badge findBadgeByBadgeId(Long id); } diff --git a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java index bbbe0940..cbf24f2c 100644 --- a/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java +++ b/src/main/java/hous/server/domain/badge/repository/BadgeRepositoryImpl.java @@ -29,4 +29,12 @@ public List findAllBadge() { .orderBy(badge.id.asc()) .fetch(); } + + @Override + public Badge findBadgeByBadgeId(Long id) { + return queryFactory + .selectFrom(badge) + .where(badge.id.eq(id)) + .fetchOne(); + } } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 7f8118dc..867fa8ae 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -83,6 +83,10 @@ public void setOnboarding(String nickname, LocalDate birthday, boolean isPublic) this.isChecked = true; } + public void setRepresent(Represent represent) { + this.represent = represent; + } + public void setPersonality(Personality personality) { this.personality = personality; } diff --git a/src/main/java/hous/server/service/badge/AcquireServiceUtils.java b/src/main/java/hous/server/service/badge/AcquireServiceUtils.java new file mode 100644 index 00000000..50605c9c --- /dev/null +++ b/src/main/java/hous/server/service/badge/AcquireServiceUtils.java @@ -0,0 +1,20 @@ +package hous.server.service.badge; + +import hous.server.common.exception.ForbiddenException; +import hous.server.domain.badge.Badge; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.user.Onboarding; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static hous.server.common.exception.ErrorCode.FORBIDDEN_ACQUIRE_BADGE_EXCEPTION; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AcquireServiceUtils { + + public static void existsByOnboardingAndBadge(AcquireRepository acquireRepository, Onboarding onboarding, Badge badge) { + if (!acquireRepository.existsByOnboardingAndBadge(onboarding, badge)) { + throw new ForbiddenException(String.format("유저가 (%s) 획득한 badge (%s) 가 아닙니다.", onboarding.getId(), badge.getId()), FORBIDDEN_ACQUIRE_BADGE_EXCEPTION); + } + } +} diff --git a/src/main/java/hous/server/service/badge/BadgeServiceUtils.java b/src/main/java/hous/server/service/badge/BadgeServiceUtils.java index e2c48942..83a91f79 100644 --- a/src/main/java/hous/server/service/badge/BadgeServiceUtils.java +++ b/src/main/java/hous/server/service/badge/BadgeServiceUtils.java @@ -22,4 +22,12 @@ public static boolean hasBadge(BadgeRepository badgeRepository, AcquireRepositor } return acquireRepository.existsByOnboardingAndBadge(onboarding, badge); } + + public static Badge findBadgeById(BadgeRepository badgeRepository, Long badgeId) { + Badge badge = badgeRepository.findBadgeByBadgeId(badgeId); + if (badge == null) { + throw new NotFoundException(String.format("존재하지 않는 badge (%s) 입니다", badgeId), NOT_FOUND_BADGE_EXCEPTION); + } + return badge; + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 96a6afbe..77c58e50 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,9 +1,12 @@ package hous.server.service.user; import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.Badge; import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.badge.Represent; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; @@ -17,6 +20,7 @@ import hous.server.domain.user.repository.SettingRepository; import hous.server.domain.user.repository.TestScoreRepository; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.AcquireServiceUtils; import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; @@ -42,6 +46,7 @@ public class UserService { private final PersonalityRepository personalityRepository; private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; + private final RepresentRepository representRepository; private final NotificationService notificationService; @@ -110,4 +115,14 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) }); } } + + public void updateRepresentBadge(Long badgeId, Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding me = user.getOnboarding(); + RoomServiceUtils.findParticipatingRoom(user); + Badge badge = BadgeServiceUtils.findBadgeById(badgeRepository, badgeId); + AcquireServiceUtils.existsByOnboardingAndBadge(acquireRepository, me, badge); + Represent represent = representRepository.save(Represent.newInstance(me, badge)); + me.setRepresent(represent); + } } From 35adb161c3c5839de6b6965d34234d5562621d77 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 16 Sep 2022 04:59:05 +0900 Subject: [PATCH 146/301] =?UTF-8?q?#96=20[rename]=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/home/HomeRetrieveService.java | 4 ++-- .../service/todo/TodoRetrieveService.java | 4 ++-- .../server/service/todo/TodoServiceUtils.java | 22 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index 8a8244a4..c4a26935 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -38,8 +38,8 @@ public HomeInfoResponse getHomeInfo(Long userId) { Room room = RoomServiceUtils.findParticipatingRoom(user); LocalDate today = DateUtils.todayLocalDate(); List todos = room.getTodos(); - List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(today, todos); - List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(today, user.getOnboarding(), todos); + List todayOurTodosList = TodoServiceUtils.filterDayOurTodos(today, todos); + List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, user.getOnboarding(), todos); List todayMyTodos = todayMyTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> MyTodoInfo.of( diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index e2c67f69..99125a36 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -50,8 +50,8 @@ public TodoMainResponse getTodoMain(Long userId) { Room room = RoomServiceUtils.findParticipatingRoom(user); LocalDate today = DateUtils.todayLocalDate(); List todos = room.getTodos(); - List todayOurTodosList = TodoServiceUtils.filterTodayOurTodos(today, todos); - List todayMyTodosList = TodoServiceUtils.filterTodayMyTodos(today, user.getOnboarding(), todos); + List todayOurTodosList = TodoServiceUtils.filterDayOurTodos(today, todos); + List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, user.getOnboarding(), todos); List todayMyTodos = todayMyTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> MyTodoInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))).collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream().map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))).collect(Collectors.toList()); return TodoMainResponse.of(today, todayMyTodos, todayOurTodos); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index e5be8e06..da34beb6 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -55,18 +55,18 @@ public static List toUserPersonalityInfoList(Todo todo) { .collect(Collectors.toList()); } - public static List filterTodayOurTodos(LocalDate today, List todos) { - List todayOurTodosList = new ArrayList<>(); + public static List filterDayOurTodos(LocalDate day, List todos) { + List dayOurTodosList = new ArrayList<>(); todos.forEach(todo -> { todo.getTakes().forEach(take -> { take.getRedos().forEach(redo -> { - if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(today))) { - todayOurTodosList.add(todo); + if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(day))) { + dayOurTodosList.add(todo); } }); }); }); - return todayOurTodosList; + return dayOurTodosList; } public static List filterAllDaysOurTodos(List todos) { @@ -109,16 +109,16 @@ public static List[] mapByDayOfWeekToList(List todos) { return todosList; } - public static List filterTodayMyTodos(LocalDate today, Onboarding me, List todos) { - List todayMyTodosList = new ArrayList<>(); - List todayOurTodosList = filterTodayOurTodos(today, todos); - todayOurTodosList.forEach(todo -> { + public static List filterDayMyTodos(LocalDate day, Onboarding me, List todos) { + List dayMyTodosList = new ArrayList<>(); + List dayOurTodosList = filterDayOurTodos(day, todos); + dayOurTodosList.forEach(todo -> { todo.getTakes().forEach(take -> { if (take.getOnboarding().getId().equals(me.getId())) { - todayMyTodosList.add(todo); + dayMyTodosList.add(todo); } }); }); - return todayMyTodosList; + return dayMyTodosList; } } From a6b2d467753535db591df1b23b27552856796d5c Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 16 Sep 2022 05:01:29 +0900 Subject: [PATCH 147/301] =?UTF-8?q?#96=20[feat]=20todo=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=20=EA=B4=80=EB=A0=A8=20=EB=B0=B0=EC=A7=80=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/ServerApplication.java | 8 ++- .../hous/server/common/util/DateUtils.java | 5 ++ .../todo/repository/DoneRepositoryCustom.java | 2 + .../todo/repository/DoneRepositoryImpl.java | 13 +++++ .../user/repository/UserRepositoryCustom.java | 4 ++ .../user/repository/UserRepositoryImpl.java | 10 ++++ .../hous/server/service/todo/TodoService.java | 55 +++++++++++++++++++ 7 files changed, 94 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/ServerApplication.java b/src/main/java/hous/server/ServerApplication.java index c6beafac..724e1e32 100644 --- a/src/main/java/hous/server/ServerApplication.java +++ b/src/main/java/hous/server/ServerApplication.java @@ -4,16 +4,18 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableScheduling; import springfox.documentation.swagger2.annotations.EnableSwagger2; +@EnableScheduling @EnableFeignClients @EnableJpaAuditing @SpringBootApplication @EnableSwagger2 public class ServerApplication { - public static void main(String[] args) { - SpringApplication.run(ServerApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ServerApplication.class, args); + } } diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index b0a301cf..3706887d 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -20,6 +20,11 @@ public static LocalDateTime todayLocalDateTime() { return LocalDateTime.now(ZoneId.of("Asia/Seoul")); } + public static LocalDate yesterdayLocalDate() { + LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul")); + return today.minusDays(1); + } + public static String parseMonthAndDay(LocalDate date) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd"); return date.format(formatter); diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java index c492f68a..364dc5e8 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java @@ -14,4 +14,6 @@ public interface DoneRepositoryCustom { OurTodoStatus findTodayOurTodoStatus(LocalDate today, Todo todo); Done findTodayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboarding, Todo todo); + + boolean existsDayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboarding, Todo todo); } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index a3d4a0fc..cffcf867 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -61,4 +61,17 @@ public Done findTodayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboard .fetchFirst(); return DateUtils.isSameDate(lastDone.getCreatedAt(), today) ? lastDone : null; } + + @Override + public boolean existsDayDoneByOnboardingAndTodo(LocalDate day, Onboarding onboarding, Todo todo) { + Done lastDone = queryFactory.selectFrom(done) + .where( + done.onboarding.eq(onboarding), + done.todo.eq(todo) + ) + .orderBy(done.createdAt.desc()) + .fetchFirst(); + if (lastDone == null) return false; + return DateUtils.isSameDate(lastDone.getCreatedAt(), day); + } } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java index 1cb1214e..07edec34 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java @@ -3,6 +3,8 @@ import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; +import java.util.List; + public interface UserRepositoryCustom { boolean existsBySocialIdAndSocialType(String socialId, UserSocialType socialType); @@ -12,4 +14,6 @@ public interface UserRepositoryCustom { User findUserBySocialIdAndSocialType(String socialId, UserSocialType socialType); User findUserByFcmToken(String fcmToken); + + List findAllUsers(); } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java index 45086eb9..932c1866 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java @@ -6,6 +6,8 @@ import hous.server.domain.user.UserStatus; import lombok.RequiredArgsConstructor; +import java.util.List; + import static hous.server.domain.user.QUser.user; @RequiredArgsConstructor @@ -57,4 +59,12 @@ public User findUserByFcmToken(String fcmToken) { ) .fetchOne(); } + + @Override + public List findAllUsers() { + return queryFactory + .selectFrom(user) + .where(user.status.eq(UserStatus.ACTIVE)) + .fetch(); + } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 2efd630e..406c158b 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -5,6 +5,8 @@ import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.common.RedisKey; +import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.todo.Done; import hous.server.domain.todo.Redo; @@ -25,9 +27,12 @@ import hous.server.service.todo.dto.request.TodoInfoRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -36,6 +41,8 @@ @Transactional public class TodoService { + private final RedisTemplate redisTemplate; + private final UserRepository userRepository; private final OnboardingRepository onboardingRepository; private final TodoRepository todoRepository; @@ -118,4 +125,52 @@ public void deleteTodo(Long todoId) { room.deleteTodo(todo); todoRepository.delete(todo); } + + @Scheduled(cron = "0 0 0 * * *") + public void scheduledDoneMyToDos() { + List users = userRepository.findAllUsers(); + users.forEach(user -> { + Onboarding onboarding = user.getOnboarding(); + List participates = onboarding.getParticipates(); + if (participates.size() != 0) { + LocalDate yesterday = DateUtils.yesterdayLocalDate(); + Room room = participates.get(0).getRoom(); + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { + List todos = room.getTodos(); + List allDayMyTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding); + List yesterdayMyTodos = TodoServiceUtils.filterDayMyTodos(yesterday, onboarding, todos); + int yesterdayDoneMyTodosCnt = (int) yesterdayMyTodos.stream() + .filter(todo -> doneRepository.existsDayDoneByOnboardingAndTodo(yesterday, onboarding, todo)) + .count(); + if (allDayMyTodos.size() > 0 && yesterdayMyTodos.size() == yesterdayDoneMyTodosCnt) { + String todoCompleteCountString = (String) redisTemplate.opsForValue().get(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + if (todoCompleteCountString == null) { + redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(1)); + } else { + redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(Integer.parseInt(todoCompleteCountString) + 1)); + System.out.println(todoCompleteCountString); + if (Integer.parseInt(todoCompleteCountString) == 6 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.GOOD_JOB, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.GOOD_JOB))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.GOOD_JOB); + } + if (Integer.parseInt(todoCompleteCountString) == 13 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.SINCERITY_KING_HOMIE, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.SINCERITY_KING_HOMIE))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.SINCERITY_KING_HOMIE); + } + if (Integer.parseInt(todoCompleteCountString) == 20 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_MASTER))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.TODO_MASTER); + redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + } + } + } else { + redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + } + } + } + }); + } } From 88e19ffc2e9f8fab42dc8fb1fd897759d9850974 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 16 Sep 2022 07:55:30 +0900 Subject: [PATCH 148/301] =?UTF-8?q?#100=20[fix]=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=9D=BD?= =?UTF-8?q?=EC=9D=8C=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/notification/Notification.java | 4 ++++ .../notification/NotificationRetrieveService.java | 1 + .../notification/dto/response/NotificationInfo.java | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/notification/Notification.java b/src/main/java/hous/server/domain/notification/Notification.java index b1933758..9ac77b09 100644 --- a/src/main/java/hous/server/domain/notification/Notification.java +++ b/src/main/java/hous/server/domain/notification/Notification.java @@ -39,4 +39,8 @@ public static Notification newInstance(Onboarding onboarding, NotificationType t .isRead(isRead) .build(); } + + public void updateIsRead() { + this.isRead = true; + } } diff --git a/src/main/java/hous/server/service/notification/NotificationRetrieveService.java b/src/main/java/hous/server/service/notification/NotificationRetrieveService.java index 8024ccca..950b0f16 100644 --- a/src/main/java/hous/server/service/notification/NotificationRetrieveService.java +++ b/src/main/java/hous/server/service/notification/NotificationRetrieveService.java @@ -22,6 +22,7 @@ public class NotificationRetrieveService { private final UserRepository userRepository; private final NotificationRepository notificationRepository; + @Transactional public NotificationsInfoResponse getNotificationsInfo(int size, Long lastNotificationId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding me = user.getOnboarding(); diff --git a/src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java b/src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java index 5004e1e5..95b786b1 100644 --- a/src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java +++ b/src/main/java/hous/server/service/notification/dto/response/NotificationInfo.java @@ -1,5 +1,6 @@ package hous.server.service.notification.dto.response; +import com.fasterxml.jackson.annotation.JsonProperty; import hous.server.common.util.DateUtils; import hous.server.domain.notification.Notification; import hous.server.domain.notification.NotificationType; @@ -20,12 +21,20 @@ public class NotificationInfo { private boolean isRead; private String createdAt; + @JsonProperty("isRead") + public boolean isRead() { + return isRead; + } + public static NotificationInfo of(Notification notification, LocalDateTime now) { - return NotificationInfo.builder() + NotificationInfo notificationInfo = NotificationInfo.builder() .notificationId(notification.getId()) .type(notification.getType()) .content(notification.getContent()) + .isRead(notification.isRead()) .createdAt(DateUtils.passedTime(now, notification.getCreatedAt())) .build(); + notification.updateIsRead(); + return notificationInfo; } } From 11f5d3f3604ca911fc51ced0f7d01564261a38da Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 16 Sep 2022 05:01:29 +0900 Subject: [PATCH 149/301] =?UTF-8?q?#96=20[feat]=20todo=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=20=EA=B4=80=EB=A0=A8=20=EB=B0=B0=EC=A7=80=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/ServerApplication.java | 8 +-- .../hous/server/common/util/DateUtils.java | 5 ++ .../todo/repository/DoneRepositoryCustom.java | 2 + .../todo/repository/DoneRepositoryImpl.java | 13 +++++ .../user/repository/UserRepositoryCustom.java | 4 ++ .../user/repository/UserRepositoryImpl.java | 10 ++++ .../hous/server/service/todo/TodoService.java | 54 +++++++++++++++++++ 7 files changed, 93 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/ServerApplication.java b/src/main/java/hous/server/ServerApplication.java index c6beafac..724e1e32 100644 --- a/src/main/java/hous/server/ServerApplication.java +++ b/src/main/java/hous/server/ServerApplication.java @@ -4,16 +4,18 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableScheduling; import springfox.documentation.swagger2.annotations.EnableSwagger2; +@EnableScheduling @EnableFeignClients @EnableJpaAuditing @SpringBootApplication @EnableSwagger2 public class ServerApplication { - public static void main(String[] args) { - SpringApplication.run(ServerApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ServerApplication.class, args); + } } diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index b0a301cf..3706887d 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -20,6 +20,11 @@ public static LocalDateTime todayLocalDateTime() { return LocalDateTime.now(ZoneId.of("Asia/Seoul")); } + public static LocalDate yesterdayLocalDate() { + LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul")); + return today.minusDays(1); + } + public static String parseMonthAndDay(LocalDate date) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd"); return date.format(formatter); diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java index c492f68a..364dc5e8 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryCustom.java @@ -14,4 +14,6 @@ public interface DoneRepositoryCustom { OurTodoStatus findTodayOurTodoStatus(LocalDate today, Todo todo); Done findTodayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboarding, Todo todo); + + boolean existsDayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboarding, Todo todo); } diff --git a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java index a3d4a0fc..cffcf867 100644 --- a/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java +++ b/src/main/java/hous/server/domain/todo/repository/DoneRepositoryImpl.java @@ -61,4 +61,17 @@ public Done findTodayDoneByOnboardingAndTodo(LocalDate today, Onboarding onboard .fetchFirst(); return DateUtils.isSameDate(lastDone.getCreatedAt(), today) ? lastDone : null; } + + @Override + public boolean existsDayDoneByOnboardingAndTodo(LocalDate day, Onboarding onboarding, Todo todo) { + Done lastDone = queryFactory.selectFrom(done) + .where( + done.onboarding.eq(onboarding), + done.todo.eq(todo) + ) + .orderBy(done.createdAt.desc()) + .fetchFirst(); + if (lastDone == null) return false; + return DateUtils.isSameDate(lastDone.getCreatedAt(), day); + } } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java index 1cb1214e..07edec34 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java @@ -3,6 +3,8 @@ import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; +import java.util.List; + public interface UserRepositoryCustom { boolean existsBySocialIdAndSocialType(String socialId, UserSocialType socialType); @@ -12,4 +14,6 @@ public interface UserRepositoryCustom { User findUserBySocialIdAndSocialType(String socialId, UserSocialType socialType); User findUserByFcmToken(String fcmToken); + + List findAllUsers(); } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java index 45086eb9..932c1866 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java @@ -6,6 +6,8 @@ import hous.server.domain.user.UserStatus; import lombok.RequiredArgsConstructor; +import java.util.List; + import static hous.server.domain.user.QUser.user; @RequiredArgsConstructor @@ -57,4 +59,12 @@ public User findUserByFcmToken(String fcmToken) { ) .fetchOne(); } + + @Override + public List findAllUsers() { + return queryFactory + .selectFrom(user) + .where(user.status.eq(UserStatus.ACTIVE)) + .fetch(); + } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 2efd630e..6478c1fd 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -5,6 +5,8 @@ import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.common.RedisKey; +import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.todo.Done; import hous.server.domain.todo.Redo; @@ -25,9 +27,12 @@ import hous.server.service.todo.dto.request.TodoInfoRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -36,6 +41,8 @@ @Transactional public class TodoService { + private final RedisTemplate redisTemplate; + private final UserRepository userRepository; private final OnboardingRepository onboardingRepository; private final TodoRepository todoRepository; @@ -118,4 +125,51 @@ public void deleteTodo(Long todoId) { room.deleteTodo(todo); todoRepository.delete(todo); } + + @Scheduled(cron = "0 0 0 * * *") + public void scheduledDoneMyToDos() { + List users = userRepository.findAllUsers(); + users.forEach(user -> { + Onboarding onboarding = user.getOnboarding(); + List participates = onboarding.getParticipates(); + if (participates.size() != 0) { + LocalDate yesterday = DateUtils.yesterdayLocalDate(); + Room room = participates.get(0).getRoom(); + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { + List todos = room.getTodos(); + List allDayMyTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding); + List yesterdayMyTodos = TodoServiceUtils.filterDayMyTodos(yesterday, onboarding, todos); + int yesterdayDoneMyTodosCnt = (int) yesterdayMyTodos.stream() + .filter(todo -> doneRepository.existsDayDoneByOnboardingAndTodo(yesterday, onboarding, todo)) + .count(); + if (allDayMyTodos.size() > 0 && yesterdayMyTodos.size() == yesterdayDoneMyTodosCnt) { + String todoCompleteCountString = (String) redisTemplate.opsForValue().get(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + if (todoCompleteCountString == null) { + redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(1)); + } else { + redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(Integer.parseInt(todoCompleteCountString) + 1)); + if (Integer.parseInt(todoCompleteCountString) == 6 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.GOOD_JOB, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.GOOD_JOB))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.GOOD_JOB); + } + if (Integer.parseInt(todoCompleteCountString) == 13 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.SINCERITY_KING_HOMIE, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.SINCERITY_KING_HOMIE))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.SINCERITY_KING_HOMIE); + } + if (Integer.parseInt(todoCompleteCountString) == 20 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_MASTER))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.TODO_MASTER); + redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + } + } + } else { + redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + } + } + } + }); + } } From fbdebc33b64eb3de255bb0208100118558fd61e8 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 16 Sep 2022 03:53:04 +0900 Subject: [PATCH 150/301] =?UTF-8?q?#94=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81=20=EB=B0=8F=20=EB=B0=B0?= =?UTF-8?q?=EC=A7=80=20=EC=9B=8C=EB=94=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/common/exception/ErrorCode.java | 4 ++-- .../java/hous/server/common/success/SuccessCode.java | 4 ++-- .../hous/server/controller/user/UserController.java | 10 +++++----- .../server/controller/user/UserRetrieveController.java | 8 ++++---- .../hous/server/service/badge/AcquireServiceUtils.java | 2 +- .../java/hous/server/service/user/UserService.java | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 7b0a8544..4bad50f0 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -38,7 +38,7 @@ public enum ErrorCode { FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "같은 방에 참가하고 있지 않습니다."), - FORBIDDEN_ACQUIRE_BADGE_EXCEPTION(FORBIDDEN, "유저가 획득한 뱃지가 아닙니다."), + FORBIDDEN_ACQUIRE_BADGE_EXCEPTION(FORBIDDEN, "유저가 획득한 배지가 아닙니다."), /** * 404 Not Found @@ -51,7 +51,7 @@ public enum ErrorCode { NOT_FOUND_PARTICIPATE_EXCEPTION(NOT_FOUND, "참가중인 방이 존재하지 않습니다."), NOT_FOUND_RULE_EXCEPTION(NOT_FOUND, "존재하지 않는 규칙입니다."), NOT_FOUND_TODO_EXCEPTION(NOT_FOUND, "존재하지 않는 todo 입니다."), - NOT_FOUND_BADGE_EXCEPTION(NOT_FOUND, "존재하지 않는 뱃지 입니다."), + NOT_FOUND_BADGE_EXCEPTION(NOT_FOUND, "존재하지 않는 배지 입니다."), NOT_FOUND_PERSONALITY_COLOR_EXCEPTION(NOT_FOUND, "GRAY 에 대한 성향 정보는 존재하지 않습니다."), /** diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 5eff707c..58f1dcd9 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -49,8 +49,8 @@ public enum SuccessCode { GET_PERSONALITY_TEST_INFO_SUCCESS(OK, "성향테스트 정보 조회 성공입니다."), // 뱃지 - GET_BADGE_INFO_SUCCESS(OK, "나의 뱃지 목록 조회 성공입니다."), - + GET_BADGE_INFO_SUCCESS(OK, "나의 배지 목록 조회 성공입니다."), + // 알림 GET_NOTIFICATIONS_INFO_SUCCESS(OK, "알림 목록 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 2978cb7a..5c0690ef 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -139,17 +139,17 @@ public ResponseEntity updateUserTestScore( } @ApiOperation( - value = "[인증] 마이 페이지(뱃지 목록 뷰) - 대표 뱃지를 설정합니다.", - notes = "대표 뱃지를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + value = "[인증] 마이 페이지(배지 목록 뷰) - 대표 배지를 설정합니다.", + notes = "대표 배지를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), - @ApiResponse(code = 400, message = "잘못된 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 403, message = "유저가 획득한 뱃지가 아닙니다.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "유저가 획득한 배지가 아닙니다.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 참가중인 방이 존재하지 않습니다.", + + "2. 참가중인 방이 존재하지 않습니다. \n" + + "3. 존재하지 않는 배지 입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 5b87c1a5..949eefd3 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -112,12 +112,12 @@ public ResponseEntity> getPersonalityTestInfo( } @ApiOperation( - value = "[인증] 마이 페이지(뱃지 목록 뷰) - 나의 뱃지 정보를 조회합니다.", - notes = "대표 뱃지가 없는 경우, null을 보냅니다.\n" + - "뱃지 목록에서는 모든 뱃지 리스트를 전달하지만. 내가 획득한 뱃지의 경우 acquire = true 입니다." + value = "[인증] 마이 페이지(배지 목록 뷰) - 나의 배지 정보를 조회합니다.", + notes = "대표 배지가 없는 경우, null을 보냅니다.\n" + + "배지 목록에서는 모든 배지 리스트를 전달하지만. 내가 획득한 배지의 경우 acquire = true 입니다." ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "나의 뱃지 목록 조회 성공입니다."), + @ApiResponse(code = 200, message = "나의 배지 목록 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" diff --git a/src/main/java/hous/server/service/badge/AcquireServiceUtils.java b/src/main/java/hous/server/service/badge/AcquireServiceUtils.java index 50605c9c..78614add 100644 --- a/src/main/java/hous/server/service/badge/AcquireServiceUtils.java +++ b/src/main/java/hous/server/service/badge/AcquireServiceUtils.java @@ -12,7 +12,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class AcquireServiceUtils { - public static void existsByOnboardingAndBadge(AcquireRepository acquireRepository, Onboarding onboarding, Badge badge) { + public static void validateExistsByOnboardingAndBadge(AcquireRepository acquireRepository, Onboarding onboarding, Badge badge) { if (!acquireRepository.existsByOnboardingAndBadge(onboarding, badge)) { throw new ForbiddenException(String.format("유저가 (%s) 획득한 badge (%s) 가 아닙니다.", onboarding.getId(), badge.getId()), FORBIDDEN_ACQUIRE_BADGE_EXCEPTION); } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 77c58e50..7cbbc039 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -121,7 +121,7 @@ public void updateRepresentBadge(Long badgeId, Long userId) { Onboarding me = user.getOnboarding(); RoomServiceUtils.findParticipatingRoom(user); Badge badge = BadgeServiceUtils.findBadgeById(badgeRepository, badgeId); - AcquireServiceUtils.existsByOnboardingAndBadge(acquireRepository, me, badge); + AcquireServiceUtils.validateExistsByOnboardingAndBadge(acquireRepository, me, badge); Represent represent = representRepository.save(Represent.newInstance(me, badge)); me.setRepresent(represent); } From 07167cbe10e9e165904812952dcc6c2b2581483c Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 16 Sep 2022 08:38:58 +0900 Subject: [PATCH 151/301] =?UTF-8?q?#98=20[feat]=20=EB=82=98=EB=8F=84=20?= =?UTF-8?q?=EB=82=A0=20=EB=AA=A8=EB=A5=B4=EA=B2=A0=EC=96=B4=20=EB=B0=B0?= =?UTF-8?q?=EC=A7=80=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/user/UserService.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 2549408e..8a51f125 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -4,6 +4,8 @@ import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.badge.repository.RepresentRepository; +import hous.server.domain.common.RedisKey; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; @@ -25,6 +27,7 @@ import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,6 +38,8 @@ @Transactional public class UserService { + private final RedisTemplate redisTemplate; + private final UserRepository userRepository; private final OnboardingRepository onboardingRepository; private final SettingRepository settingRepository; @@ -89,6 +94,22 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); me.setPersonality(personality); + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.I_DONT_EVEN_KNOW_ME, me)) { + String personalityTestCountString = (String) redisTemplate.opsForValue().get(RedisKey.PERSONALITY_TEST_COUNT + userId); + if (personalityTestCountString != null && Integer.parseInt(personalityTestCountString) >= 4) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.I_DONT_EVEN_KNOW_ME))); + me.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.I_DONT_EVEN_KNOW_ME); + redisTemplate.delete(RedisKey.PERSONALITY_TEST_COUNT + user.getId()); + } else { + if (personalityTestCountString == null) { + redisTemplate.opsForValue().set(RedisKey.PERSONALITY_TEST_COUNT + user.getId(), Integer.toString(1)); + } else { + redisTemplate.opsForValue().set(RedisKey.PERSONALITY_TEST_COUNT + user.getId(), Integer.toString(Integer.parseInt(personalityTestCountString) + 1)); + } + } + } + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.I_AM_SUCH_A_PERSON, me)) { Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.I_AM_SUCH_A_PERSON))); me.addAcquire(acquire); From 4385161c595d28ea971071af49cb7493b628b3c9 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 18 Sep 2022 15:24:19 +0900 Subject: [PATCH 152/301] =?UTF-8?q?#104=20[refactor]=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/todo/TodoScheduledService.java | 90 +++++++++++++++++++ .../hous/server/service/todo/TodoService.java | 54 ----------- 2 files changed, 90 insertions(+), 54 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/TodoScheduledService.java diff --git a/src/main/java/hous/server/service/todo/TodoScheduledService.java b/src/main/java/hous/server/service/todo/TodoScheduledService.java new file mode 100644 index 00000000..d2ee818f --- /dev/null +++ b/src/main/java/hous/server/service/todo/TodoScheduledService.java @@ -0,0 +1,90 @@ +package hous.server.service.todo; + +import hous.server.common.util.DateUtils; +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.common.RedisKey; +import hous.server.domain.room.Participate; +import hous.server.domain.room.Room; +import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; +import hous.server.domain.user.Onboarding; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeServiceUtils; +import hous.server.service.notification.NotificationService; +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.util.List; + +@RequiredArgsConstructor +@Service +@Transactional +public class TodoScheduledService { + + private final RedisTemplate redisTemplate; + + private final UserRepository userRepository; + private final DoneRepository doneRepository; + private final BadgeRepository badgeRepository; + private final AcquireRepository acquireRepository; + + private final NotificationService notificationService; + + /** + * 매일 0시 0분 0초마다 실행 + */ + @Scheduled(cron = "0 0 0 * * *") + public void scheduledDoneMyToDos() { + List users = userRepository.findAllUsers(); + users.forEach(user -> { + Onboarding onboarding = user.getOnboarding(); + List participates = onboarding.getParticipates(); + if (participates.size() != 0) { + LocalDate yesterday = DateUtils.yesterdayLocalDate(); + Room room = participates.get(0).getRoom(); + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { + List todos = room.getTodos(); + List allDayMyTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding); + List yesterdayMyTodos = TodoServiceUtils.filterDayMyTodos(yesterday, onboarding, todos); + int yesterdayDoneMyTodosCnt = (int) yesterdayMyTodos.stream() + .filter(todo -> doneRepository.existsDayDoneByOnboardingAndTodo(yesterday, onboarding, todo)) + .count(); + if (allDayMyTodos.size() > 0 && yesterdayMyTodos.size() == yesterdayDoneMyTodosCnt) { + String todoCompleteCountString = (String) redisTemplate.opsForValue().get(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + if (todoCompleteCountString == null) { + redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(1)); + } else { + redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(Integer.parseInt(todoCompleteCountString) + 1)); + if (Integer.parseInt(todoCompleteCountString) == 6 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.GOOD_JOB, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.GOOD_JOB))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.GOOD_JOB); + } + if (Integer.parseInt(todoCompleteCountString) == 13 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.SINCERITY_KING_HOMIE, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.SINCERITY_KING_HOMIE))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.SINCERITY_KING_HOMIE); + } + if (Integer.parseInt(todoCompleteCountString) == 20 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_MASTER))); + onboarding.addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, BadgeInfo.TODO_MASTER); + redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + } + } + } else { + redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); + } + } + } + }); + } +} diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 6478c1fd..2efd630e 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -5,8 +5,6 @@ import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; -import hous.server.domain.common.RedisKey; -import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.todo.Done; import hous.server.domain.todo.Redo; @@ -27,12 +25,9 @@ import hous.server.service.todo.dto.request.TodoInfoRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -41,8 +36,6 @@ @Transactional public class TodoService { - private final RedisTemplate redisTemplate; - private final UserRepository userRepository; private final OnboardingRepository onboardingRepository; private final TodoRepository todoRepository; @@ -125,51 +118,4 @@ public void deleteTodo(Long todoId) { room.deleteTodo(todo); todoRepository.delete(todo); } - - @Scheduled(cron = "0 0 0 * * *") - public void scheduledDoneMyToDos() { - List users = userRepository.findAllUsers(); - users.forEach(user -> { - Onboarding onboarding = user.getOnboarding(); - List participates = onboarding.getParticipates(); - if (participates.size() != 0) { - LocalDate yesterday = DateUtils.yesterdayLocalDate(); - Room room = participates.get(0).getRoom(); - if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { - List todos = room.getTodos(); - List allDayMyTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding); - List yesterdayMyTodos = TodoServiceUtils.filterDayMyTodos(yesterday, onboarding, todos); - int yesterdayDoneMyTodosCnt = (int) yesterdayMyTodos.stream() - .filter(todo -> doneRepository.existsDayDoneByOnboardingAndTodo(yesterday, onboarding, todo)) - .count(); - if (allDayMyTodos.size() > 0 && yesterdayMyTodos.size() == yesterdayDoneMyTodosCnt) { - String todoCompleteCountString = (String) redisTemplate.opsForValue().get(RedisKey.TODO_COMPLETE_COUNT + user.getId()); - if (todoCompleteCountString == null) { - redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(1)); - } else { - redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(Integer.parseInt(todoCompleteCountString) + 1)); - if (Integer.parseInt(todoCompleteCountString) == 6 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.GOOD_JOB, onboarding)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.GOOD_JOB))); - onboarding.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.GOOD_JOB); - } - if (Integer.parseInt(todoCompleteCountString) == 13 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.SINCERITY_KING_HOMIE, onboarding)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.SINCERITY_KING_HOMIE))); - onboarding.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.SINCERITY_KING_HOMIE); - } - if (Integer.parseInt(todoCompleteCountString) == 20 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_MASTER))); - onboarding.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.TODO_MASTER); - redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); - } - } - } else { - redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); - } - } - } - }); - } } From e3cb0f57193c2cc044402e558c361aaa1296bda8 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 18 Sep 2022 15:50:41 +0900 Subject: [PATCH 153/301] =?UTF-8?q?#104=20[refactor]=20=EB=B0=B0=EC=A7=80?= =?UTF-8?q?=20=ED=9A=8D=EB=93=9D=20=EB=A1=9C=EC=A7=81=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/badge/BadgeService.java | 30 +++++++++++++++++++ .../hous/server/service/room/RoomService.java | 20 +++---------- .../hous/server/service/rule/RuleService.java | 17 +++-------- .../service/todo/TodoScheduledService.java | 23 +++++--------- .../hous/server/service/todo/TodoService.java | 18 ++--------- .../hous/server/service/user/UserService.java | 24 ++++----------- 6 files changed, 54 insertions(+), 78 deletions(-) create mode 100644 src/main/java/hous/server/service/badge/BadgeService.java diff --git a/src/main/java/hous/server/service/badge/BadgeService.java b/src/main/java/hous/server/service/badge/BadgeService.java new file mode 100644 index 00000000..c6d5c4fd --- /dev/null +++ b/src/main/java/hous/server/service/badge/BadgeService.java @@ -0,0 +1,30 @@ +package hous.server.service.badge; + +import hous.server.domain.badge.Acquire; +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.BadgeRepository; +import hous.server.domain.user.User; +import hous.server.service.notification.NotificationService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class BadgeService { + + private final BadgeRepository badgeRepository; + private final AcquireRepository acquireRepository; + + private final NotificationService notificationService; + + public void acquireBadge(User user, BadgeInfo badgeInfo) { + if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, badgeInfo, user.getOnboarding())) { + Acquire acquire = acquireRepository.save(Acquire.newInstance(user.getOnboarding(), badgeRepository.findBadgeByBadgeInfo(badgeInfo))); + user.getOnboarding().addAcquire(acquire); + notificationService.sendNewBadgeNotification(user, badgeInfo); + } + } +} diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 4b960a04..138c2a3d 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -1,9 +1,7 @@ package hous.server.service.room; -import hous.server.domain.badge.Acquire; import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; -import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.room.Participate; @@ -19,8 +17,7 @@ import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; -import hous.server.service.badge.BadgeServiceUtils; -import hous.server.service.notification.NotificationService; +import hous.server.service.badge.BadgeService; import hous.server.service.room.dto.request.SetRoomNameRequestDto; import hous.server.service.room.dto.response.RoomInfoResponse; import hous.server.service.todo.TodoServiceUtils; @@ -46,10 +43,9 @@ public class RoomService { private final DoneRepository doneRepository; private final AcquireRepository acquireRepository; private final RepresentRepository representRepository; - private final BadgeRepository badgeRepository; private final NotificationRepository notificationRepository; - private final NotificationService notificationService; + private final BadgeService badgeService; public RoomInfoResponse createRoom(SetRoomNameRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -59,7 +55,7 @@ public RoomInfoResponse createRoom(SetRoomNameRequestDto request, Long userId) { Participate participate = participateRepository.save(Participate.newInstance(me, room)); me.addParticipate(participate); room.addParticipate(participate); - getBadgeByPoundingHouse(user, me); + badgeService.acquireBadge(user, BadgeInfo.POUNDING_HOUSE); return RoomInfoResponse.of(room); } @@ -72,7 +68,7 @@ public RoomInfoResponse joinRoom(Long roomId, Long userId) { Participate participate = participateRepository.save(Participate.newInstance(me, room)); me.addParticipate(participate); room.addParticipate(participate); - getBadgeByPoundingHouse(user, me); + badgeService.acquireBadge(user, BadgeInfo.POUNDING_HOUSE); return RoomInfoResponse.of(room); } @@ -151,12 +147,4 @@ private String createUniqueRoomCode() { private boolean isNotUniqueRoomCode(String code) { return roomRepository.existsByRoomCode(code); } - - private void getBadgeByPoundingHouse(User user, Onboarding me) { - if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.POUNDING_HOUSE, me)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.POUNDING_HOUSE))); - me.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.POUNDING_HOUSE); - } - } } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 37a48722..7a5e4f2a 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -1,6 +1,5 @@ package hous.server.service.rule; -import hous.server.domain.badge.Acquire; import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; @@ -11,8 +10,8 @@ import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; -import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; @@ -35,7 +34,7 @@ public class RuleService { private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; - private final NotificationService notificationService; + private final BadgeService badgeService; public void createRule(CreateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -45,19 +44,11 @@ public void createRule(CreateRuleRequestDto request, Long userId) { int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room); Rule rule = ruleRepository.save(Rule.newInstance(room, request.getName(), ruleIdx + 1)); room.addRule(rule); - - if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.LETS_BUILD_A_POLE, me)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.LETS_BUILD_A_POLE))); - me.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.LETS_BUILD_A_POLE); - } - + badgeService.acquireBadge(user, BadgeInfo.LETS_BUILD_A_POLE); if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.OUR_HOUSE_PILLAR_HOMIE, me)) { String createRuleCountString = (String) redisTemplate.opsForValue().get(RedisKey.CREATE_RULE_COUNT + userId); if (createRuleCountString != null && Integer.parseInt(createRuleCountString) >= 4) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.OUR_HOUSE_PILLAR_HOMIE))); - me.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.OUR_HOUSE_PILLAR_HOMIE); + badgeService.acquireBadge(user, BadgeInfo.OUR_HOUSE_PILLAR_HOMIE); redisTemplate.delete(RedisKey.CREATE_RULE_COUNT + user.getId()); } else { if (createRuleCountString == null) { diff --git a/src/main/java/hous/server/service/todo/TodoScheduledService.java b/src/main/java/hous/server/service/todo/TodoScheduledService.java index d2ee818f..5c2e568e 100644 --- a/src/main/java/hous/server/service/todo/TodoScheduledService.java +++ b/src/main/java/hous/server/service/todo/TodoScheduledService.java @@ -1,7 +1,6 @@ package hous.server.service.todo; import hous.server.common.util.DateUtils; -import hous.server.domain.badge.Acquire; import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; @@ -13,8 +12,8 @@ import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; -import hous.server.service.notification.NotificationService; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.Scheduled; @@ -36,7 +35,7 @@ public class TodoScheduledService { private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; - private final NotificationService notificationService; + private final BadgeService badgeService; /** * 매일 0시 0분 0초마다 실행 @@ -63,20 +62,14 @@ public void scheduledDoneMyToDos() { redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(1)); } else { redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(Integer.parseInt(todoCompleteCountString) + 1)); - if (Integer.parseInt(todoCompleteCountString) == 6 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.GOOD_JOB, onboarding)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.GOOD_JOB))); - onboarding.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.GOOD_JOB); + if (Integer.parseInt(todoCompleteCountString) == 6) { + badgeService.acquireBadge(user, BadgeInfo.GOOD_JOB); } - if (Integer.parseInt(todoCompleteCountString) == 13 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.SINCERITY_KING_HOMIE, onboarding)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.SINCERITY_KING_HOMIE))); - onboarding.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.SINCERITY_KING_HOMIE); + if (Integer.parseInt(todoCompleteCountString) == 13) { + badgeService.acquireBadge(user, BadgeInfo.SINCERITY_KING_HOMIE); } - if (Integer.parseInt(todoCompleteCountString) == 20 && !BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_MASTER))); - onboarding.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.TODO_MASTER); + if (Integer.parseInt(todoCompleteCountString) == 20) { + badgeService.acquireBadge(user, BadgeInfo.TODO_MASTER); redisTemplate.delete(RedisKey.TODO_COMPLETE_COUNT + user.getId()); } } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 2efd630e..9bb0ac03 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -1,10 +1,7 @@ package hous.server.service.todo; import hous.server.common.util.DateUtils; -import hous.server.domain.badge.Acquire; import hous.server.domain.badge.BadgeInfo; -import hous.server.domain.badge.repository.AcquireRepository; -import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.room.Room; import hous.server.domain.todo.Done; import hous.server.domain.todo.Redo; @@ -18,8 +15,7 @@ import hous.server.domain.user.User; import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; -import hous.server.service.badge.BadgeServiceUtils; -import hous.server.service.notification.NotificationService; +import hous.server.service.badge.BadgeService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.dto.request.CheckTodoRequestDto; import hous.server.service.todo.dto.request.TodoInfoRequestDto; @@ -42,14 +38,11 @@ public class TodoService { private final TakeRepository takeRepository; private final RedoRepository redoRepository; private final DoneRepository doneRepository; - private final BadgeRepository badgeRepository; - private final AcquireRepository acquireRepository; - private final NotificationService notificationService; + private final BadgeService badgeService; public void createTodo(TodoInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - Onboarding me = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); TodoServiceUtils.validateTodoCounts(room); Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); @@ -63,12 +56,7 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { todo.addTake(take); }); room.addTodo(todo); - - if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_ONE_STEP, me)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.TODO_ONE_STEP))); - me.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.TODO_ONE_STEP); - } + badgeService.acquireBadge(user, BadgeInfo.TODO_ONE_STEP); } public void updateTodo(Long todoId, TodoInfoRequestDto request) { diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 120e8d96..93aae67c 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,6 +1,5 @@ package hous.server.service.user; -import hous.server.domain.badge.Acquire; import hous.server.domain.badge.Badge; import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.Represent; @@ -22,8 +21,8 @@ import hous.server.domain.user.repository.TestScoreRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.badge.AcquireServiceUtils; +import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; -import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.request.CreateUserRequestDto; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; @@ -52,7 +51,7 @@ public class UserService { private final AcquireRepository acquireRepository; private final RepresentRepository representRepository; - private final NotificationService notificationService; + private final BadgeService badgeService; public Long registerUser(CreateUserRequestDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); @@ -97,13 +96,11 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) testScore.updateScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); me.setPersonality(personality); - + badgeService.acquireBadge(user, BadgeInfo.I_AM_SUCH_A_PERSON); if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.I_DONT_EVEN_KNOW_ME, me)) { String personalityTestCountString = (String) redisTemplate.opsForValue().get(RedisKey.PERSONALITY_TEST_COUNT + userId); if (personalityTestCountString != null && Integer.parseInt(personalityTestCountString) >= 4) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.I_DONT_EVEN_KNOW_ME))); - me.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.I_DONT_EVEN_KNOW_ME); + badgeService.acquireBadge(user, BadgeInfo.I_DONT_EVEN_KNOW_ME); redisTemplate.delete(RedisKey.PERSONALITY_TEST_COUNT + user.getId()); } else { if (personalityTestCountString == null) { @@ -113,13 +110,6 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) } } } - - if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.I_AM_SUCH_A_PERSON, me)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(me, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.I_AM_SUCH_A_PERSON))); - me.addAcquire(acquire); - notificationService.sendNewBadgeNotification(user, BadgeInfo.I_AM_SUCH_A_PERSON); - } - List participates = room.getParticipates(); int testCompleteCnt = (int) participates.stream() .filter(participate -> participate.getOnboarding().getPersonality().getColor() != PersonalityColor.GRAY) @@ -127,11 +117,7 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) if (room.getParticipantsCnt() == testCompleteCnt) { participates.forEach(participate -> { Onboarding onboarding = participate.getOnboarding(); - if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.OUR_HOUSE_HOMIES, onboarding)) { - Acquire acquire = acquireRepository.save(Acquire.newInstance(onboarding, badgeRepository.findBadgeByBadgeInfo(BadgeInfo.OUR_HOUSE_HOMIES))); - onboarding.addAcquire(acquire); - notificationService.sendNewBadgeNotification(onboarding.getUser(), BadgeInfo.OUR_HOUSE_HOMIES); - } + badgeService.acquireBadge(onboarding.getUser(), BadgeInfo.OUR_HOUSE_HOMIES); }); } } From e06bb28dd9daec54c6cef2ce1cccb65f096d28cd Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 18 Sep 2022 16:23:20 +0900 Subject: [PATCH 154/301] =?UTF-8?q?#106=20[refactor]=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/badge/AcquireServiceUtils.java | 20 ------------------- .../service/badge/BadgeServiceUtils.java | 8 ++++++++ .../hous/server/service/user/UserService.java | 3 +-- 3 files changed, 9 insertions(+), 22 deletions(-) delete mode 100644 src/main/java/hous/server/service/badge/AcquireServiceUtils.java diff --git a/src/main/java/hous/server/service/badge/AcquireServiceUtils.java b/src/main/java/hous/server/service/badge/AcquireServiceUtils.java deleted file mode 100644 index 78614add..00000000 --- a/src/main/java/hous/server/service/badge/AcquireServiceUtils.java +++ /dev/null @@ -1,20 +0,0 @@ -package hous.server.service.badge; - -import hous.server.common.exception.ForbiddenException; -import hous.server.domain.badge.Badge; -import hous.server.domain.badge.repository.AcquireRepository; -import hous.server.domain.user.Onboarding; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static hous.server.common.exception.ErrorCode.FORBIDDEN_ACQUIRE_BADGE_EXCEPTION; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AcquireServiceUtils { - - public static void validateExistsByOnboardingAndBadge(AcquireRepository acquireRepository, Onboarding onboarding, Badge badge) { - if (!acquireRepository.existsByOnboardingAndBadge(onboarding, badge)) { - throw new ForbiddenException(String.format("유저가 (%s) 획득한 badge (%s) 가 아닙니다.", onboarding.getId(), badge.getId()), FORBIDDEN_ACQUIRE_BADGE_EXCEPTION); - } - } -} diff --git a/src/main/java/hous/server/service/badge/BadgeServiceUtils.java b/src/main/java/hous/server/service/badge/BadgeServiceUtils.java index 83a91f79..cf75b6e1 100644 --- a/src/main/java/hous/server/service/badge/BadgeServiceUtils.java +++ b/src/main/java/hous/server/service/badge/BadgeServiceUtils.java @@ -1,5 +1,6 @@ package hous.server.service.badge; +import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; import hous.server.domain.badge.Badge; import hous.server.domain.badge.BadgeInfo; @@ -9,6 +10,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import static hous.server.common.exception.ErrorCode.FORBIDDEN_ACQUIRE_BADGE_EXCEPTION; import static hous.server.common.exception.ErrorCode.NOT_FOUND_BADGE_EXCEPTION; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -30,4 +32,10 @@ public static Badge findBadgeById(BadgeRepository badgeRepository, Long badgeId) } return badge; } + + public static void validateExistsByOnboardingAndBadge(AcquireRepository acquireRepository, Onboarding onboarding, Badge badge) { + if (!acquireRepository.existsByOnboardingAndBadge(onboarding, badge)) { + throw new ForbiddenException(String.format("유저가 (%s) 획득한 badge (%s) 가 아닙니다.", onboarding.getId(), badge.getId()), FORBIDDEN_ACQUIRE_BADGE_EXCEPTION); + } + } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 93aae67c..4e8050c0 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -20,7 +20,6 @@ import hous.server.domain.user.repository.SettingRepository; import hous.server.domain.user.repository.TestScoreRepository; import hous.server.domain.user.repository.UserRepository; -import hous.server.service.badge.AcquireServiceUtils; import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.room.RoomServiceUtils; @@ -127,7 +126,7 @@ public void updateRepresentBadge(Long badgeId, Long userId) { Onboarding me = user.getOnboarding(); RoomServiceUtils.findParticipatingRoom(user); Badge badge = BadgeServiceUtils.findBadgeById(badgeRepository, badgeId); - AcquireServiceUtils.validateExistsByOnboardingAndBadge(acquireRepository, me, badge); + BadgeServiceUtils.validateExistsByOnboardingAndBadge(acquireRepository, me, badge); Represent represent = representRepository.save(Represent.newInstance(me, badge)); me.setRepresent(represent); } From 0f71da07f54f658a96b93698229ae9bafc2ea052 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 18 Sep 2022 16:30:43 +0900 Subject: [PATCH 155/301] =?UTF-8?q?#106=20[feat]=20Rules=20=ED=91=B8?= =?UTF-8?q?=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/notification/NotificationService.java | 10 ++++++++++ .../hous/server/service/room/RoomServiceUtils.java | 8 ++++++++ .../java/hous/server/service/rule/RuleService.java | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index 2d44a362..f70b4fa4 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -6,6 +6,7 @@ import hous.server.domain.notification.NotificationType; import hous.server.domain.notification.PushMessage; import hous.server.domain.notification.repository.NotificationRepository; +import hous.server.domain.rule.Rule; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; import hous.server.service.firebase.FirebaseCloudMessageService; @@ -21,11 +22,20 @@ public class NotificationService { private final NotificationRepository notificationRepository; private final FirebaseCloudMessageService firebaseCloudMessageService; + public void sendNewRuleNotification(User to, Rule rule) { + notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_RULE.getTitle(), PushMessage.NEW_RULE.getBody()); + } + public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) { notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.BADGE, newBadgeNotification(badgeInfo), false)); firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), newBadgePushTitle(badgeInfo), newBadgePushBody(to.getOnboarding())); } + private String newRuleNotification(Rule rule) { + return String.format("'%s' %s", rule.getName(), NotificationMessage.NEW_RULE); + } + private String newBadgePushTitle(BadgeInfo badgeInfo) { return String.format("'%s' %s", badgeInfo.getValue(), PushMessage.NEW_BADGE.getTitle()); } diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 2aa8b2a0..18471d8f 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import static hous.server.common.exception.ErrorCode.*; @@ -54,4 +55,11 @@ public static void checkParticipatingRoom(Room userRoom, Room homieRoom) { userRoom.getId(), homieRoom.getId()), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION); } } + + public static List findParticipatingUsersExceptMe(Room room, User me) { + return room.getParticipates().stream() + .filter(participate -> !participate.getOnboarding().getId().equals(me.getOnboarding().getId())) + .map(participate -> participate.getOnboarding().getUser()) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 7a5e4f2a..5b3a0e14 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -12,6 +12,7 @@ import hous.server.domain.user.repository.UserRepository; import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; +import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; @@ -22,6 +23,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @RequiredArgsConstructor @Service @Transactional @@ -35,6 +38,7 @@ public class RuleService { private final AcquireRepository acquireRepository; private final BadgeService badgeService; + private final NotificationService notificationService; public void createRule(CreateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -58,6 +62,8 @@ public void createRule(CreateRuleRequestDto request, Long userId) { } } } + List usersExceptMe = RoomServiceUtils.findParticipatingUsersExceptMe(room, user); + usersExceptMe.forEach(userExceptMe -> notificationService.sendNewRuleNotification(userExceptMe, rule)); } public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { From 142bafb5931df6064705bd5e093371e3448b1b8f Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 18 Sep 2022 17:42:31 +0900 Subject: [PATCH 156/301] =?UTF-8?q?#53=20[fix]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B4=80=EB=A0=A8=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EB=B0=8F=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 22 +++++------ .../hous/server/domain/user/PushStatus.java | 6 +++ .../java/hous/server/domain/user/Setting.java | 35 +++++++++++++++++- .../server/domain/user/TodoPushStatus.java | 7 ++++ .../hous/server/service/user/UserService.java | 13 ++----- .../server/service/user/UserServiceUtils.java | 13 +++++-- .../request/UpdatePushSettingRequestDto.java | 37 +++++++++++++++++++ 7 files changed, 106 insertions(+), 27 deletions(-) create mode 100644 src/main/java/hous/server/domain/user/PushStatus.java create mode 100644 src/main/java/hous/server/domain/user/TodoPushStatus.java create mode 100644 src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 5c0690ef..2c168ac2 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -6,6 +6,7 @@ import hous.server.config.resolver.UserId; import hous.server.service.user.UserService; import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; +import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import io.swagger.annotations.*; @@ -89,28 +90,25 @@ public ResponseEntity updateUserInfo( return SuccessResponse.NO_CONTENT; } - // TODO 푸쉬알림 설정뷰 확정나면 수정하기 @ApiOperation( - value = "[인증] 마이 페이지(Profile 뷰) - 나의 푸쉬 알림 설정 정보를 수정합니다.", - notes = "푸쉬 알림 설정 여부를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + value = "[인증] 마이 페이지(Profile 뷰) - 나의 푸시 알림 설정 정보를 수정합니다.", + notes = "푸시 알림 설정 여부를 설정합니다.\n" + + "Rules, Badge 설정으로는 ON, OFF 를 담습니다.\n" + + "Todo 관련 설정으로는 ON_ALL, ON_MY, OFF 를 담습니다.\n" + + "성공시 status code = 204, 빈 response body를 보냅니다." ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), - @ApiResponse( - code = 400, message = "자기소개는 40 글자 이내로 입력해주세요. (introduction)", response = ErrorResponse.class), + @ApiResponse(code = 400, message = "잘못된 상태로 요청했습니다.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, - message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 존재하지 않는 방입니다.", - response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/user/push") - public ResponseEntity updateUserInfo(@ApiParam(name = "state", value = "푸쉬 알림 여부", required = true, example = "true") - @RequestParam boolean state, @ApiIgnore @UserId Long userId) { - userService.updateUserPushState(state, userId); + public ResponseEntity updateUserPushSetting(@Valid @RequestBody UpdatePushSettingRequestDto request, @ApiIgnore @UserId Long userId) { + userService.updateUserPushSetting(request, userId); return SuccessResponse.NO_CONTENT; } diff --git a/src/main/java/hous/server/domain/user/PushStatus.java b/src/main/java/hous/server/domain/user/PushStatus.java new file mode 100644 index 00000000..58833c81 --- /dev/null +++ b/src/main/java/hous/server/domain/user/PushStatus.java @@ -0,0 +1,6 @@ +package hous.server.domain.user; + +public enum PushStatus { + ON, + OFF; +} diff --git a/src/main/java/hous/server/domain/user/Setting.java b/src/main/java/hous/server/domain/user/Setting.java index e4d8ab77..1f2cc4e3 100644 --- a/src/main/java/hous/server/domain/user/Setting.java +++ b/src/main/java/hous/server/domain/user/Setting.java @@ -1,6 +1,7 @@ package hous.server.domain.user; import hous.server.domain.common.AuditingTimeEntity; +import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import lombok.*; import javax.persistence.*; @@ -19,13 +20,43 @@ public class Setting extends AuditingTimeEntity { @Column(nullable = false) private boolean isPushNotification; + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private PushStatus rulesPushStatus; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private TodoPushStatus newTodoPushStatus; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private TodoPushStatus todayTodoPushStatus; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private TodoPushStatus remindTodoPushStatus; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private PushStatus badgePushStatus; + public static Setting newInstance() { return Setting.builder() .isPushNotification(true) + .rulesPushStatus(PushStatus.ON) + .newTodoPushStatus(TodoPushStatus.ON_ALL) + .todayTodoPushStatus(TodoPushStatus.ON_ALL) + .remindTodoPushStatus(TodoPushStatus.ON_ALL) + .badgePushStatus(PushStatus.ON) .build(); } - public void setPushNotification(boolean isPushNotification) { - this.isPushNotification = isPushNotification; + public void updatePushSetting(UpdatePushSettingRequestDto request) { + this.isPushNotification = request.isPushNotification(); + this.rulesPushStatus = request.getRulesPushStatus(); + this.newTodoPushStatus = request.getNewTodoPushStatus(); + this.todayTodoPushStatus = request.getTodayTodoPushStatus(); + this.remindTodoPushStatus = request.getRemindTodoPushStatus(); + this.badgePushStatus = request.getBadgePushStatus(); } } diff --git a/src/main/java/hous/server/domain/user/TodoPushStatus.java b/src/main/java/hous/server/domain/user/TodoPushStatus.java new file mode 100644 index 00000000..aab74400 --- /dev/null +++ b/src/main/java/hous/server/domain/user/TodoPushStatus.java @@ -0,0 +1,7 @@ +package hous.server.domain.user; + +public enum TodoPushStatus { + ON_ALL, + ON_MY, + OFF; +} diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 4e8050c0..995e7563 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -23,10 +23,7 @@ import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.room.RoomServiceUtils; -import hous.server.service.user.dto.request.CreateUserRequestDto; -import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; -import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; -import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; +import hous.server.service.user.dto.request.*; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -78,13 +75,11 @@ public void updateUserInfo(UpdateUserInfoRequestDto request, Long userId) { onboarding.setUserInfo(request); } - // TODO 푸쉬알림 설정뷰 확정나면 수정하기 - public void updateUserPushState(boolean state, Long userId) { + public void updateUserPushSetting(UpdatePushSettingRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - RoomServiceUtils.findParticipatingRoom(user); Setting setting = user.getSetting(); - UserServiceUtils.validatePushNotificationStatus(setting.isPushNotification(), state); - setting.setPushNotification(state); + UserServiceUtils.validatePushSettingRequestStatus(request, user); + setting.updatePushSetting(request); } public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) { diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index f2d3aaae..e1c31e13 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -10,6 +10,7 @@ import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; +import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -36,10 +37,14 @@ public static User findUserById(UserRepository userRepository, Long userId) { return user; } - public static void validatePushNotificationStatus(boolean state, boolean requestState) { - if (state == requestState) { - throw new ValidationException(String.format("(%s) 유저의 푸쉬 알림 여부 상태는 이미 (%s) 입니다.", state, requestState), - VALIDATION_STATUS_EXCEPTION); + public static void validatePushSettingRequestStatus(UpdatePushSettingRequestDto request, User user) { + if (request.isPushNotification() == user.getSetting().isPushNotification() && + request.getRulesPushStatus() == user.getSetting().getRulesPushStatus() && + request.getNewTodoPushStatus() == user.getSetting().getNewTodoPushStatus() && + request.getTodayTodoPushStatus() == user.getSetting().getTodayTodoPushStatus() && + request.getRemindTodoPushStatus() == user.getSetting().getRemindTodoPushStatus() && + request.getBadgePushStatus() == user.getSetting().getBadgePushStatus()) { + throw new ValidationException(String.format("(%s) 유저의 푸시 알림 상태 중복입니다.\n%s", user.getId(), request), VALIDATION_STATUS_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java new file mode 100644 index 00000000..948b7a14 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java @@ -0,0 +1,37 @@ +package hous.server.service.user.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.user.PushStatus; +import hous.server.domain.user.TodoPushStatus; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdatePushSettingRequestDto { + + @ApiModelProperty(value = "알림 받기", example = "true") + private boolean isPushNotification; + + @ApiModelProperty(value = "새로운 Rules 추가", example = "ON") + private PushStatus rulesPushStatus; + + @ApiModelProperty(value = "새로운 to-do 추가 알림", example = "ON_ALL") + private TodoPushStatus newTodoPushStatus; + + @ApiModelProperty(value = "오늘의 to-do 시작 알림", example = "ON_MY") + private TodoPushStatus todayTodoPushStatus; + + @ApiModelProperty(value = "미완료 to-do 알림", example = "OFF") + private TodoPushStatus remindTodoPushStatus; + + @ApiModelProperty(value = "배지 알림", example = "ON") + private PushStatus badgePushStatus; + + @JsonProperty("isPushNotification") + public boolean isPushNotification() { + return isPushNotification; + } +} From e327f06db71e80b0901e814a7e1e4f5f7dd44019 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 18 Sep 2022 17:51:25 +0900 Subject: [PATCH 157/301] =?UTF-8?q?#102=20[fix]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EB=B3=B4=EB=82=BC=20=EB=95=8C=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EC=84=A4=EC=A0=95=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/notification/NotificationService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index f70b4fa4..e614a512 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -8,6 +8,7 @@ import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.rule.Rule; import hous.server.domain.user.Onboarding; +import hous.server.domain.user.PushStatus; import hous.server.domain.user.User; import hous.server.service.firebase.FirebaseCloudMessageService; import lombok.RequiredArgsConstructor; @@ -24,12 +25,16 @@ public class NotificationService { public void sendNewRuleNotification(User to, Rule rule) { notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_RULE.getTitle(), PushMessage.NEW_RULE.getBody()); + if (to.getSetting().isPushNotification() && to.getSetting().getRulesPushStatus() == PushStatus.ON) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_RULE.getTitle(), PushMessage.NEW_RULE.getBody()); + } } public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) { notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.BADGE, newBadgeNotification(badgeInfo), false)); - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), newBadgePushTitle(badgeInfo), newBadgePushBody(to.getOnboarding())); + if (to.getSetting().isPushNotification() && to.getSetting().getBadgePushStatus() == PushStatus.ON) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), newBadgePushTitle(badgeInfo), newBadgePushBody(to.getOnboarding())); + } } private String newRuleNotification(Rule rule) { From d20d2afc0d360d3d7365aa88bb1b0bb117bcd1e2 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 21 Sep 2022 13:18:51 +0900 Subject: [PATCH 158/301] =?UTF-8?q?#110=20[fix]=20=EB=B0=B0=EC=A7=80=20?= =?UTF-8?q?=EC=84=A4=EB=AA=85=20=EB=AC=B8=EA=B5=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/badge/BadgeInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/badge/BadgeInfo.java b/src/main/java/hous/server/domain/badge/BadgeInfo.java index a4f92875..39dc2bba 100644 --- a/src/main/java/hous/server/domain/badge/BadgeInfo.java +++ b/src/main/java/hous/server/domain/badge/BadgeInfo.java @@ -11,7 +11,7 @@ public enum BadgeInfo implements EnumModel { POUNDING_HOUSE("두근두근 하우스", "어서와요\n우리 Hous-에!", "imageUrl"), I_AM_SUCH_A_PERSON("나 이런 사람이야", "Homie 카드를\n완성한 호미", "imageUrl"), - OUR_HOUSE_HOMIES("우리 집 호미들", "모든 Homie들의\n카드 확인", "imageUrl"), + OUR_HOUSE_HOMIES("우리 집 호미들", "모든 Homie들의\n테스트 참여", "imageUrl"), I_DONT_EVEN_KNOW_ME("나도 날 모르겠어", "성향 테스트를\n5번 이상 한 호미", "imageUrl"), HOMIE_IS_BORN("Homie 탄생", "Hous-에서의\n첫 생일", "imageUrl"), TODO_ONE_STEP("to-do 한 걸음", "to-do 전체보기에서\n첫 to-do 등록", "imageUrl"), From 25db8d67738441e5f29bd36be0172b61ab41a6c7 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 21 Sep 2022 14:32:49 +0900 Subject: [PATCH 159/301] =?UTF-8?q?#65=20[refactor]=20=EA=B3=B5=ED=86=B5?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=ED=95=A8=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/room/RoomService.java | 46 ++----------- .../server/service/room/RoomServiceUtils.java | 65 +++++++++++++++++++ 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 138c2a3d..ca5ba315 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -8,8 +8,6 @@ import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; import hous.server.domain.room.repository.RoomRepository; -import hous.server.domain.todo.Done; -import hous.server.domain.todo.Take; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.todo.repository.TakeRepository; @@ -27,7 +25,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; -import java.util.Optional; import java.util.Random; @RequiredArgsConstructor @@ -85,47 +82,14 @@ public void leaveRoom(Long userId) { List todos = room.getTodos(); List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); - myTodos.forEach(todo -> { - // todo 담당자가 여러명이면 나의 담당 해제 - if (todo.getTakes().size() > 1) { - Optional myTake = todo.getTakes().stream() - .filter(take -> take.getOnboarding().getId().equals(me.getId())) - .findFirst(); - if (myTake.isPresent()) { - List myDones = TodoServiceUtils.filterAllDaysMyDones(me, todo.getDones()); - takeRepository.delete(myTake.get()); - myDones.forEach(todo::deleteDone); - doneRepository.deleteAll(myDones); - todo.deleteTake(myTake.get()); - } - } - // todo 담당자가 나뿐이면 todo 삭제 - else { - Todo myTodo = myTodos.get(0); - room.deleteTodo(myTodo); - todoRepository.delete(myTodo); - } - }); - // 방의 참가자가 여러명이면 나만 방을 나감 - List participates = room.getParticipates(); - if (participates.size() > 1) { - room.deleteParticipate(participates.get(0)); - me.deleteParticipate(participates.get(0)); - participateRepository.delete(participates.get(0)); - } - // 방의 참가자가 나 혼자면 방을 나가고 삭제 - else { - me.deleteParticipate(participates.get(0)); - roomRepository.delete(room); - } + RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); + RoomServiceUtils.leaveParticipateRoom(participateRepository, roomRepository, me, room); // 내 뱃지, 알림 목록, 프로필 작성 내역, 테스트 결과 초기화 - if (me.getRepresent() != null) { - representRepository.delete(me.getRepresent()); - } - acquireRepository.deleteAll(me.getAcquires()); - notificationRepository.deleteAll(notificationRepository.findNotificationsByOnboarding(me)); + RoomServiceUtils.deleteRepresentByOnboarding(representRepository, me); + RoomServiceUtils.deleteAcquireByOnboarding(acquireRepository, me); + RoomServiceUtils.deleteNotificationByOnboarding(notificationRepository, me); me.resetUserInfo(); me.resetBadge(); me.resetTestScore(me.getTestScore()); diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 18471d8f..f72eeb5f 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -3,17 +3,28 @@ import hous.server.common.exception.ConflictException; import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; +import hous.server.domain.badge.repository.AcquireRepository; +import hous.server.domain.badge.repository.RepresentRepository; +import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; import hous.server.domain.room.repository.RoomRepository; +import hous.server.domain.todo.Done; +import hous.server.domain.todo.Take; +import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; +import hous.server.domain.todo.repository.TakeRepository; +import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; +import hous.server.service.todo.TodoServiceUtils; import lombok.AccessLevel; import lombok.NoArgsConstructor; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; import static hous.server.common.exception.ErrorCode.*; @@ -62,4 +73,58 @@ public static List findParticipatingUsersExceptMe(Room room, User me) { .map(participate -> participate.getOnboarding().getUser()) .collect(Collectors.toList()); } + + public static void deleteMyTodosTakeMe(TakeRepository takeRepository, DoneRepository doneRepository, TodoRepository todoRepository, + List myTodos, Onboarding me, Room room) { + myTodos.forEach(todo -> { + // todo 담당자가 여러명이면 나의 담당 해제 + if (todo.getTakes().size() > 1) { + Optional myTake = todo.getTakes().stream() + .filter(take -> take.getOnboarding().getId().equals(me.getId())) + .findFirst(); + if (myTake.isPresent()) { + List myDones = TodoServiceUtils.filterAllDaysMyDones(me, todo.getDones()); + takeRepository.delete(myTake.get()); + myDones.forEach(todo::deleteDone); + doneRepository.deleteAll(myDones); + todo.deleteTake(myTake.get()); + } + } + // todo 담당자가 나뿐이면 todo 삭제 + else { + Todo myTodo = myTodos.get(0); + room.deleteTodo(myTodo); + todoRepository.delete(myTodo); + } + }); + } + + public static void leaveParticipateRoom(ParticipateRepository participateRepository, RoomRepository roomRepository, + Onboarding me, Room room) { + List participates = room.getParticipates(); + if (participates.size() > 1) { + room.deleteParticipate(participates.get(0)); + me.deleteParticipate(participates.get(0)); + participateRepository.delete(participates.get(0)); + } + // 방의 참가자가 나 혼자면 방을 나가고 삭제 + else { + me.deleteParticipate(participates.get(0)); + roomRepository.delete(room); + } + } + + public static void deleteRepresentByOnboarding(RepresentRepository representRepository, Onboarding me) { + if (me.getRepresent() != null) { + representRepository.delete(me.getRepresent()); + } + } + + public static void deleteAcquireByOnboarding(AcquireRepository acquireRepository, Onboarding me) { + acquireRepository.deleteAll(me.getAcquires()); + } + + public static void deleteNotificationByOnboarding(NotificationRepository notificationRepository, Onboarding me) { + notificationRepository.deleteAll(notificationRepository.findNotificationsByOnboarding(me)); + } } From 5fd2392e151e5913e9daef202598f0a8ce9bd40e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 21 Sep 2022 14:47:13 +0900 Subject: [PATCH 160/301] =?UTF-8?q?#65=20[fix]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/exception/ErrorCode.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 0452fc31..4bad50f0 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -39,7 +39,6 @@ public enum ErrorCode { FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "같은 방에 참가하고 있지 않습니다."), FORBIDDEN_ACQUIRE_BADGE_EXCEPTION(FORBIDDEN, "유저가 획득한 배지가 아닙니다."), - FORBIDDEN_USER_DELETE_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "방에 참가하고 있는 유저는 탈퇴할 수 없습니다."), /** * 404 Not Found @@ -54,7 +53,6 @@ public enum ErrorCode { NOT_FOUND_TODO_EXCEPTION(NOT_FOUND, "존재하지 않는 todo 입니다."), NOT_FOUND_BADGE_EXCEPTION(NOT_FOUND, "존재하지 않는 배지 입니다."), NOT_FOUND_PERSONALITY_COLOR_EXCEPTION(NOT_FOUND, "GRAY 에 대한 성향 정보는 존재하지 않습니다."), - NOTFOUND_USER_EXCEPTION(NOT_FOUND, "존재하지 않는 유저입니다."), /** * 405 Method Not Allowed From 0d2e6f78a556ddc470757731c8a5fdb4c4ae1ec8 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 21 Sep 2022 14:47:31 +0900 Subject: [PATCH 161/301] =?UTF-8?q?#65=20[fix]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=ED=83=88=ED=87=B4=20api=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 10 ++--- .../hous/server/service/user/UserService.java | 43 +++++++++++-------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index f665db00..909a5634 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -160,7 +160,7 @@ public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", v userService.updateRepresentBadge(badgeId, userId); return SuccessResponse.NO_CONTENT; } - + @ApiOperation( value = "[인증] 마이 페이지(설정) - 회원 정보를 삭제합니다.", @@ -169,19 +169,17 @@ public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", v @ApiResponses(value = { @ApiResponse(code = 204, message = ""), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 403, message = "방에 참가하고 있는 유저는 탈퇴할 수 없습니다..", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + "2. 같은 방에 참가하고 있지 않습니다.\n" - + "3. 존재하지 않는 유저입니다.", + + "3. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) - @PutMapping("/user") - public ResponseEntity deleteUser( - @Valid @RequestBody UpdateTestScoreRequestDto request, @ApiIgnore @UserId Long userId) { + @DeleteMapping("/user") + public ResponseEntity deleteUser(@ApiIgnore @UserId Long userId) { userService.deleteUser(userId); return SuccessResponse.NO_CONTENT; } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 8b562d02..b5a8681f 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -7,14 +7,18 @@ import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.common.RedisKey; -import hous.server.common.exception.ForbiddenException; -import hous.server.common.exception.NotFoundException; +import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; -import hous.server.domain.room.Participate; +import hous.server.domain.room.repository.ParticipateRepository; +import hous.server.domain.room.repository.RoomRepository; +import hous.server.domain.todo.Todo; +import hous.server.domain.todo.repository.DoneRepository; +import hous.server.domain.todo.repository.TakeRepository; +import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.Setting; import hous.server.domain.user.TestScore; @@ -26,6 +30,7 @@ import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.room.RoomServiceUtils; +import hous.server.service.todo.TodoServiceUtils; import hous.server.service.user.dto.request.*; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -34,11 +39,6 @@ import java.util.List; -import java.util.List; - -import static hous.server.common.exception.ErrorCode.FORBIDDEN_USER_DELETE_ROOM_PARTICIPATE_EXCEPTION; -import static hous.server.common.exception.ErrorCode.NOTFOUND_USER_EXCEPTION; - @RequiredArgsConstructor @Service @Transactional @@ -54,6 +54,12 @@ public class UserService { private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; private final RepresentRepository representRepository; + private final TakeRepository takeRepository; + private final DoneRepository doneRepository; + private final TodoRepository todoRepository; + private final ParticipateRepository participateRepository; + private final RoomRepository roomRepository; + private final NotificationRepository notificationRepository; private final BadgeService badgeService; @@ -136,14 +142,17 @@ public void updateRepresentBadge(Long badgeId, Long userId) { public void deleteUser(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - List participateList = user.getOnboarding().getParticipates(); - if (!participateList.isEmpty()) { - throw new ForbiddenException(String.format("방 (%s) 의 참가자 는 탈퇴할 수 없습니다.", participateList.get(0).getRoom().getId()), - FORBIDDEN_USER_DELETE_ROOM_PARTICIPATE_EXCEPTION); - } - if (userRepository.deleteUserById(userId) != 1) { - throw new NotFoundException(String.format("존재 하지 않은 유저 (%s) 는 탈퇴할 수 없습니다.", userId), - NOTFOUND_USER_EXCEPTION); - } + Room room = RoomServiceUtils.findParticipatingRoom(user); + Onboarding me = user.getOnboarding(); + + List todos = room.getTodos(); + List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); + RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); + RoomServiceUtils.leaveParticipateRoom(participateRepository, roomRepository, me, room); + RoomServiceUtils.deleteRepresentByOnboarding(representRepository, me); + RoomServiceUtils.deleteAcquireByOnboarding(acquireRepository, me); + RoomServiceUtils.deleteNotificationByOnboarding(notificationRepository, me); + + userRepository.delete(user); } } From b62e676a174449b533c19a04106e8b750d335dde Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 21 Sep 2022 17:44:11 +0900 Subject: [PATCH 162/301] =?UTF-8?q?#111=20[fix]=20User=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20fcmToken?= =?UTF-8?q?=20=EC=A4=91=EB=B3=B5=20=EA=B2=80=EC=82=AC=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/common/exception/ErrorCode.java | 1 + .../hous/server/controller/auth/AuthController.java | 6 +++++- src/main/java/hous/server/domain/user/User.java | 5 ++--- .../server/service/auth/impl/AppleAuthService.java | 10 ++++++++-- .../server/service/auth/impl/KaKaoAuthService.java | 11 +++++++---- .../java/hous/server/service/user/UserService.java | 4 +++- .../hous/server/service/user/UserServiceUtils.java | 7 +++++++ 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 4bad50f0..dd84161e 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -70,6 +70,7 @@ public enum ErrorCode { CONFLICT_EXCEPTION(CONFLICT, "이미 존재합니다."), CONFLICT_USER_EXCEPTION(CONFLICT, "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), CONFLICT_JOINED_ROOM_EXCEPTION(CONFLICT, "이미 참가중인 방이 있습니다."), + CONFLICT_FCM_TOKEN_EXCEPTION(CONFLICT, "fcm token 중복입니다."), /** * 415 Unsupported Media Type diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 3b4d1d2b..2b63b4ce 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -47,7 +47,11 @@ public class AuthController { + "3. fcm token 을 입력해주세요.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 409, + message = "1. 이미 해당 계정으로 회원가입하셨습니다.\n 로그인 해주세요.\n" + + "2. fcm token 중복입니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PostMapping("/auth/login") diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index 1c7c5491..6d8e22a3 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -19,7 +19,7 @@ public class User extends AuditingTimeEntity { @Embedded private SocialInfo socialInfo; - @Column(nullable = false, length = 300) + @Column(unique = true, length = 300) private String fcmToken; @Column(nullable = false, length = 30) @@ -33,10 +33,9 @@ public class User extends AuditingTimeEntity { @JoinColumn(name = "setting_id", nullable = false) private Setting setting; - public static User newInstance(String socialId, UserSocialType socialType, String fcmToken, Setting setting) { + public static User newInstance(String socialId, UserSocialType socialType, Setting setting) { return User.builder() .socialInfo(SocialInfo.of(socialId, socialType)) - .fcmToken(fcmToken) .setting(setting) .status(UserStatus.ACTIVE) .build(); diff --git a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java index 9c3fabb6..b4b76bf0 100644 --- a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java @@ -10,24 +10,30 @@ import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service +@Transactional public class AppleAuthService implements AuthService { private static final UserSocialType socialType = UserSocialType.APPLE; private final AppleTokenProvider appleTokenDecoder; - private final UserService userService; private final UserRepository userRepository; + private final UserService userService; + @Override public Long login(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); if (user == null) return userService.registerUser(request.toCreateUserDto(socialId)); - else user.updateFcmToken(request.getFcmToken()); + else { + UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + user.updateFcmToken(request.getFcmToken()); + } return user.getId(); } } diff --git a/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java index 329ebbe6..576be0ee 100644 --- a/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java @@ -8,31 +8,34 @@ import hous.server.external.client.kakao.dto.response.KakaoProfileResponse; import hous.server.service.auth.AuthService; import hous.server.service.auth.dto.request.LoginDto; -import hous.server.service.firebase.FirebaseCloudMessageService; import hous.server.service.user.UserService; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service +@Transactional public class KaKaoAuthService implements AuthService { private static final UserSocialType socialType = UserSocialType.KAKAO; private final KakaoApiClient kaKaoApiCaller; - private final FirebaseCloudMessageService firebaseCloudMessageService; + private final UserRepository userRepository; private final UserService userService; - private final UserRepository userRepository; @Override public Long login(LoginDto request) { KakaoProfileResponse response = kaKaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); if (user == null) return userService.registerUser(request.toCreateUserDto(response.getId())); - else user.updateFcmToken(request.getFcmToken()); + else { + UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + user.updateFcmToken(request.getFcmToken()); + } return user.getId(); } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 995e7563..5f3d07c9 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -52,12 +52,14 @@ public class UserService { public Long registerUser(CreateUserRequestDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); User user = userRepository.save(User.newInstance( - request.getSocialId(), request.getSocialType(), request.getFcmToken(), + request.getSocialId(), request.getSocialType(), settingRepository.save(Setting.newInstance()))); Onboarding onboarding = onboardingRepository.save(Onboarding.newInstance( user, personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), testScoreRepository.save(TestScore.newInstance()))); + UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + user.updateFcmToken(request.getFcmToken()); user.setOnboarding(onboarding); return user.getId(); } diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index e1c31e13..d439c215 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -37,6 +37,13 @@ public static User findUserById(UserRepository userRepository, Long userId) { return user; } + public static void validateUniqueFcmToken(UserRepository userRepository, String fcmToken) { + User user = userRepository.findUserByFcmToken(fcmToken); + if (user != null) { + throw new ConflictException(String.format("fcm token (%s) 중복입니다.", fcmToken), CONFLICT_FCM_TOKEN_EXCEPTION); + } + } + public static void validatePushSettingRequestStatus(UpdatePushSettingRequestDto request, User user) { if (request.isPushNotification() == user.getSetting().isPushNotification() && request.getRulesPushStatus() == user.getSetting().getRulesPushStatus() && From 56aba6855b1eb528e2a6581c55ca19504bfb13e6 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 21 Sep 2022 18:32:48 +0900 Subject: [PATCH 163/301] =?UTF-8?q?#65=20[fix]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20controller=EC=97=90=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/user/UserController.java | 3 +-- .../domain/user/repository/UserRepositoryCustom.java | 2 -- .../server/domain/user/repository/UserRepositoryImpl.java | 8 -------- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 909a5634..34563724 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -171,8 +171,7 @@ public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", v @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 같은 방에 참가하고 있지 않습니다.\n" - + "3. 참가중인 방이 존재하지 않습니다.", + + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java index a4df368c..07edec34 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java @@ -16,6 +16,4 @@ public interface UserRepositoryCustom { User findUserByFcmToken(String fcmToken); List findAllUsers(); - - long deleteUserById(Long id); } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java index 0a21c3bf..932c1866 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java @@ -67,12 +67,4 @@ public List findAllUsers() { .where(user.status.eq(UserStatus.ACTIVE)) .fetch(); } - - @Override - public long deleteUserById(Long id) { - return queryFactory - .delete(user) - .where(user.id.eq(id)) - .execute(); - } } From d39ec59b6f5ef68f764a67889294cf424295752f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 21 Sep 2022 18:52:50 +0900 Subject: [PATCH 164/301] =?UTF-8?q?#65=20[fix]=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/Notification.java | 4 +-- .../hous/server/domain/user/Onboarding.java | 8 +++++ .../hous/server/service/room/RoomService.java | 20 +++++++++--- .../server/service/room/RoomServiceUtils.java | 32 ------------------- .../hous/server/service/user/UserService.java | 7 ++-- 5 files changed, 29 insertions(+), 42 deletions(-) diff --git a/src/main/java/hous/server/domain/notification/Notification.java b/src/main/java/hous/server/domain/notification/Notification.java index 9ac77b09..c1646958 100644 --- a/src/main/java/hous/server/domain/notification/Notification.java +++ b/src/main/java/hous/server/domain/notification/Notification.java @@ -17,8 +17,8 @@ public class Notification extends AuditingTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "onboarding_id", nullable = false) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "onboarding_id") private Onboarding onboarding; @Column(nullable = false, length = 30) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 867fa8ae..3e5ea74e 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -4,6 +4,7 @@ import hous.server.domain.badge.Acquire; import hous.server.domain.badge.Represent; import hous.server.domain.common.AuditingTimeEntity; +import hous.server.domain.notification.Notification; import hous.server.domain.personality.Personality; import hous.server.domain.room.Participate; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; @@ -67,6 +68,9 @@ public class Onboarding extends AuditingTimeEntity { @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List acquires = new ArrayList<>(); + @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private final List notifications = new ArrayList<>(); + public static Onboarding newInstance(User user, Personality personality, TestScore testScore) { return Onboarding.builder() .user(user) @@ -99,6 +103,10 @@ public void addAcquire(Acquire acquire) { this.acquires.add(acquire); } + public void addNotification(Notification notification) { + this.notifications.add(notification); + } + public void deleteParticipate(Participate participate) { this.participates.remove(participate); } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index ca5ba315..4a1f05b3 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -84,12 +84,24 @@ public void leaveRoom(Long userId) { List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); - RoomServiceUtils.leaveParticipateRoom(participateRepository, roomRepository, me, room); + List participates = room.getParticipates(); + if (participates.size() > 1) { + room.deleteParticipate(participates.get(0)); + me.deleteParticipate(participates.get(0)); + participateRepository.delete(participates.get(0)); + } + // 방의 참가자가 나 혼자면 방을 나가고 삭제 + else { + me.deleteParticipate(participates.get(0)); + roomRepository.delete(room); + } // 내 뱃지, 알림 목록, 프로필 작성 내역, 테스트 결과 초기화 - RoomServiceUtils.deleteRepresentByOnboarding(representRepository, me); - RoomServiceUtils.deleteAcquireByOnboarding(acquireRepository, me); - RoomServiceUtils.deleteNotificationByOnboarding(notificationRepository, me); + if (me.getRepresent() != null) { + representRepository.delete(me.getRepresent()); + } + acquireRepository.deleteAll(me.getAcquires()); + notificationRepository.deleteAll(notificationRepository.findNotificationsByOnboarding(me)); me.resetUserInfo(); me.resetBadge(); me.resetTestScore(me.getTestScore()); diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index f72eeb5f..0e76d9bb 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -3,9 +3,6 @@ import hous.server.common.exception.ConflictException; import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; -import hous.server.domain.badge.repository.AcquireRepository; -import hous.server.domain.badge.repository.RepresentRepository; -import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; @@ -98,33 +95,4 @@ public static void deleteMyTodosTakeMe(TakeRepository takeRepository, DoneReposi } }); } - - public static void leaveParticipateRoom(ParticipateRepository participateRepository, RoomRepository roomRepository, - Onboarding me, Room room) { - List participates = room.getParticipates(); - if (participates.size() > 1) { - room.deleteParticipate(participates.get(0)); - me.deleteParticipate(participates.get(0)); - participateRepository.delete(participates.get(0)); - } - // 방의 참가자가 나 혼자면 방을 나가고 삭제 - else { - me.deleteParticipate(participates.get(0)); - roomRepository.delete(room); - } - } - - public static void deleteRepresentByOnboarding(RepresentRepository representRepository, Onboarding me) { - if (me.getRepresent() != null) { - representRepository.delete(me.getRepresent()); - } - } - - public static void deleteAcquireByOnboarding(AcquireRepository acquireRepository, Onboarding me) { - acquireRepository.deleteAll(me.getAcquires()); - } - - public static void deleteNotificationByOnboarding(NotificationRepository notificationRepository, Onboarding me) { - notificationRepository.deleteAll(notificationRepository.findNotificationsByOnboarding(me)); - } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index b5a8681f..d15e5ab8 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -148,11 +148,10 @@ public void deleteUser(Long userId) { List todos = room.getTodos(); List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); - RoomServiceUtils.leaveParticipateRoom(participateRepository, roomRepository, me, room); - RoomServiceUtils.deleteRepresentByOnboarding(representRepository, me); - RoomServiceUtils.deleteAcquireByOnboarding(acquireRepository, me); - RoomServiceUtils.deleteNotificationByOnboarding(notificationRepository, me); userRepository.delete(user); + if (room.getParticipates().isEmpty()) { + roomRepository.delete(room); + } } } From e5b9de755b5018989fe105e24c48ed98238082bc Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 21 Sep 2022 18:55:36 +0900 Subject: [PATCH 165/301] =?UTF-8?q?#65=20[fix]=20findNotificationsByOnboar?= =?UTF-8?q?ding=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/NotificationRepositoryCustom.java | 2 -- .../repository/NotificationRepositoryImpl.java | 7 ------- .../server/service/notification/NotificationService.java | 6 ++++-- src/main/java/hous/server/service/room/RoomService.java | 2 +- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java index 31ae4f03..89ed0bfb 100644 --- a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryCustom.java @@ -10,6 +10,4 @@ public interface NotificationRepositoryCustom { List findNotificationsByOnboardingAndCursor(Onboarding onboarding, Long lastNotificationId, int size); long countAllByOnboarding(Onboarding onboarding); - - List findNotificationsByOnboarding(Onboarding onboarding); } diff --git a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java index 66fd3d1f..07169921 100644 --- a/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java +++ b/src/main/java/hous/server/domain/notification/repository/NotificationRepositoryImpl.java @@ -33,11 +33,4 @@ public long countAllByOnboarding(Onboarding onboarding) { .where(notification.onboarding.eq(onboarding)) .fetch().size(); } - - @Override - public List findNotificationsByOnboarding(Onboarding onboarding) { - return queryFactory.selectFrom(notification) - .where(notification.onboarding.eq(onboarding)) - .fetch(); - } } diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index e614a512..d29f2894 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -24,14 +24,16 @@ public class NotificationService { private final FirebaseCloudMessageService firebaseCloudMessageService; public void sendNewRuleNotification(User to, Rule rule) { - notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); + Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); + to.getOnboarding().addNotification(notification); if (to.getSetting().isPushNotification() && to.getSetting().getRulesPushStatus() == PushStatus.ON) { firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_RULE.getTitle(), PushMessage.NEW_RULE.getBody()); } } public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) { - notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.BADGE, newBadgeNotification(badgeInfo), false)); + Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.BADGE, newBadgeNotification(badgeInfo), false)); + to.getOnboarding().addNotification(notification); if (to.getSetting().isPushNotification() && to.getSetting().getBadgePushStatus() == PushStatus.ON) { firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), newBadgePushTitle(badgeInfo), newBadgePushBody(to.getOnboarding())); } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 4a1f05b3..87e1084e 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -101,7 +101,7 @@ public void leaveRoom(Long userId) { representRepository.delete(me.getRepresent()); } acquireRepository.deleteAll(me.getAcquires()); - notificationRepository.deleteAll(notificationRepository.findNotificationsByOnboarding(me)); + notificationRepository.deleteAll(me.getNotifications()); me.resetUserInfo(); me.resetBadge(); me.resetTestScore(me.getTestScore()); From cfbb9aec9402419c009403dfcfb4d781838ef97e Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 21 Sep 2022 14:33:20 +0900 Subject: [PATCH 166/301] =?UTF-8?q?#113=20[feat]=20=EC=83=88=EB=A1=9C?= =?UTF-8?q?=EC=9A=B4=20todo=20=EC=B6=94=EA=B0=80=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=91=B8=EC=8B=9C=EC=95=8C=EB=A6=BC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/notification/PushMessage.java | 1 + .../notification/NotificationService.java | 17 +++++++++++++++++ .../hous/server/service/todo/TodoService.java | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/main/java/hous/server/domain/notification/PushMessage.java b/src/main/java/hous/server/domain/notification/PushMessage.java index c923d47a..9c40801d 100644 --- a/src/main/java/hous/server/domain/notification/PushMessage.java +++ b/src/main/java/hous/server/domain/notification/PushMessage.java @@ -11,6 +11,7 @@ public enum PushMessage implements EnumModel { NEW_RULE("새로운 Rules 추가", "우리 집에 새로운 Rules가 추가되었어요.\n어떤 규칙인지 확인해봐요!"), NEW_TODO("새로운 to-do 추가", "우리 집에 새로운 to-do가 추가되었어요.\n어떤 to-do인지 확인해봐요!"), + NEW_TODO_TAKE("새로운 to-do 추가", "우리 집에 새로운 내 to-do가 추가되었어요.\n어떤 to-do인지 확인해봐요!"), TODAY_TODO_START("오늘의 to-do 시작", "상쾌한 Hous-의 아침!\n오늘은 어떤 to-do 기다리고 있을까요?"), TODO_REMIND("미완료 to-do 알림", "이런, 오늘 해야 할 to-do가 아직 끝나지 않았어요!\n빠르게 확인하고, 후다닥 끝내볼까요?"), NEW_BADGE("배지 획득", "님, 축하해요!\n새로 받은 배지를 지금 확인해봐요!"); diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index d29f2894..389682e7 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -7,8 +7,10 @@ import hous.server.domain.notification.PushMessage; import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.rule.Rule; +import hous.server.domain.todo.Todo; import hous.server.domain.user.Onboarding; import hous.server.domain.user.PushStatus; +import hous.server.domain.user.TodoPushStatus; import hous.server.domain.user.User; import hous.server.service.firebase.FirebaseCloudMessageService; import lombok.RequiredArgsConstructor; @@ -23,6 +25,16 @@ public class NotificationService { private final NotificationRepository notificationRepository; private final FirebaseCloudMessageService firebaseCloudMessageService; + public void sendNewTodoNotification(User to, Todo todo, boolean isTake) { + notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, newTodoNotification(todo, isTake), false)); + if (to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_ALL) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_TODO.getTitle(), PushMessage.NEW_TODO.getBody()); + } + if (to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_TODO_TAKE.getTitle(), PushMessage.NEW_TODO_TAKE.getBody()); + } + } + public void sendNewRuleNotification(User to, Rule rule) { Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); to.getOnboarding().addNotification(notification); @@ -39,6 +51,11 @@ public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) { } } + private String newTodoNotification(Todo todo, boolean isTake) { + if (isTake) return String.format("'%s' %s", todo.getName(), NotificationMessage.NEW_TODO_TAKE); + else return String.format("'%s' %s", todo.getName(), NotificationMessage.NEW_TODO); + } + private String newRuleNotification(Rule rule) { return String.format("'%s' %s", rule.getName(), NotificationMessage.NEW_RULE); } diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 9bb0ac03..461620ad 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -16,6 +16,7 @@ import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.badge.BadgeService; +import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.dto.request.CheckTodoRequestDto; import hous.server.service.todo.dto.request.TodoInfoRequestDto; @@ -26,6 +27,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @RequiredArgsConstructor @Service @@ -40,6 +42,7 @@ public class TodoService { private final DoneRepository doneRepository; private final BadgeService badgeService; + private final NotificationService notificationService; public void createTodo(TodoInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -57,6 +60,13 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { }); room.addTodo(todo); badgeService.acquireBadge(user, BadgeInfo.TODO_ONE_STEP); + List usersExceptMe = RoomServiceUtils.findParticipatingUsersExceptMe(room, user); + usersExceptMe.forEach(userExceptMe -> { + List onboardings = todo.getTakes().stream() + .map(Take::getOnboarding) + .collect(Collectors.toList()); + notificationService.sendNewTodoNotification(userExceptMe, todo, onboardings.contains(userExceptMe.getOnboarding())); + }); } public void updateTodo(Long todoId, TodoInfoRequestDto request) { From acda3ae45281129d39150d5fc2edafdbe074c2a5 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 21 Sep 2022 15:05:07 +0900 Subject: [PATCH 167/301] =?UTF-8?q?#113=20[feat]=20=EC=98=A4=EB=8A=98?= =?UTF-8?q?=EC=9D=98=20todo=20=EC=8B=9C=EC=9E=91=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=91=B8=EC=8B=9C=EC=95=8C=EB=A6=BC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/PushMessage.java | 3 ++- .../notification/NotificationService.java | 9 +++++++ .../service/todo/TodoScheduledService.java | 25 ++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/domain/notification/PushMessage.java b/src/main/java/hous/server/domain/notification/PushMessage.java index 9c40801d..d6ff9415 100644 --- a/src/main/java/hous/server/domain/notification/PushMessage.java +++ b/src/main/java/hous/server/domain/notification/PushMessage.java @@ -12,7 +12,8 @@ public enum PushMessage implements EnumModel { NEW_RULE("새로운 Rules 추가", "우리 집에 새로운 Rules가 추가되었어요.\n어떤 규칙인지 확인해봐요!"), NEW_TODO("새로운 to-do 추가", "우리 집에 새로운 to-do가 추가되었어요.\n어떤 to-do인지 확인해봐요!"), NEW_TODO_TAKE("새로운 to-do 추가", "우리 집에 새로운 내 to-do가 추가되었어요.\n어떤 to-do인지 확인해봐요!"), - TODAY_TODO_START("오늘의 to-do 시작", "상쾌한 Hous-의 아침!\n오늘은 어떤 to-do 기다리고 있을까요?"), + TODAY_TODO_START("오늘의 to-do 시작", "상쾌한 Hous-의 아침!\n오늘은 어떤 to-do가 기다리고 있을까요?"), + TODAY_TODO_TAKE_START("오늘의 to-do 시작", "상쾌한 Hous-의 아침!\n오늘은 어떤 to-do가 나를 기다리고 있을까요?"), TODO_REMIND("미완료 to-do 알림", "이런, 오늘 해야 할 to-do가 아직 끝나지 않았어요!\n빠르게 확인하고, 후다닥 끝내볼까요?"), NEW_BADGE("배지 획득", "님, 축하해요!\n새로 받은 배지를 지금 확인해봐요!"); diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index 389682e7..5dccb9d5 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -35,6 +35,15 @@ public void sendNewTodoNotification(User to, Todo todo, boolean isTake) { } } + public void sendTodayTodoNotification(User to, boolean isTake) { + if (to.getSetting().isPushNotification() && to.getSetting().getTodayTodoPushStatus() == TodoPushStatus.ON_ALL) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODAY_TODO_START.getTitle(), PushMessage.TODAY_TODO_START.getBody()); + } + if (to.getSetting().isPushNotification() && to.getSetting().getTodayTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODAY_TODO_TAKE_START.getTitle(), PushMessage.TODAY_TODO_TAKE_START.getBody()); + } + } + public void sendNewRuleNotification(User to, Rule rule) { Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); to.getOnboarding().addNotification(notification); diff --git a/src/main/java/hous/server/service/todo/TodoScheduledService.java b/src/main/java/hous/server/service/todo/TodoScheduledService.java index 5c2e568e..88957a1a 100644 --- a/src/main/java/hous/server/service/todo/TodoScheduledService.java +++ b/src/main/java/hous/server/service/todo/TodoScheduledService.java @@ -14,6 +14,7 @@ import hous.server.domain.user.repository.UserRepository; import hous.server.service.badge.BadgeService; import hous.server.service.badge.BadgeServiceUtils; +import hous.server.service.notification.NotificationService; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.Scheduled; @@ -36,12 +37,13 @@ public class TodoScheduledService { private final AcquireRepository acquireRepository; private final BadgeService badgeService; + private final NotificationService notificationService; /** * 매일 0시 0분 0초마다 실행 */ @Scheduled(cron = "0 0 0 * * *") - public void scheduledDoneMyToDos() { + public void scheduledDoneMyTodos() { List users = userRepository.findAllUsers(); users.forEach(user -> { Onboarding onboarding = user.getOnboarding(); @@ -80,4 +82,25 @@ public void scheduledDoneMyToDos() { } }); } + + /** + * 매일 9시 0분 0초마다 실행 + */ + @Scheduled(cron = "0 0 9 * * *") + public void scheduledTodayTodos() { + List users = userRepository.findAllUsers(); + users.forEach(user -> { + Onboarding onboarding = user.getOnboarding(); + List participates = onboarding.getParticipates(); + if (participates.size() != 0) { + LocalDate today = DateUtils.todayLocalDate(); + Room room = participates.get(0).getRoom(); + List todayOurTodos = TodoServiceUtils.filterDayOurTodos(today, room.getTodos()); + List todayMyTodos = TodoServiceUtils.filterDayMyTodos(today, onboarding, room.getTodos()); + if (!todayOurTodos.isEmpty()) { + notificationService.sendTodayTodoNotification(user, !todayMyTodos.isEmpty()); + } + } + }); + } } From 72d552fc29769f676c7bf2a6ab873f702a48c08c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Wed, 21 Sep 2022 15:46:38 +0900 Subject: [PATCH 168/301] =?UTF-8?q?#113=20[feat]=20=EB=AF=B8=EC=99=84?= =?UTF-8?q?=EB=A3=8C=20todo=20=EA=B4=80=EB=A0=A8=20=ED=91=B8=EC=8B=9C?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/PushMessage.java | 3 +- .../notification/NotificationService.java | 16 ++++++++++ .../service/todo/TodoScheduledService.java | 29 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/notification/PushMessage.java b/src/main/java/hous/server/domain/notification/PushMessage.java index d6ff9415..c884ca9b 100644 --- a/src/main/java/hous/server/domain/notification/PushMessage.java +++ b/src/main/java/hous/server/domain/notification/PushMessage.java @@ -14,7 +14,8 @@ public enum PushMessage implements EnumModel { NEW_TODO_TAKE("새로운 to-do 추가", "우리 집에 새로운 내 to-do가 추가되었어요.\n어떤 to-do인지 확인해봐요!"), TODAY_TODO_START("오늘의 to-do 시작", "상쾌한 Hous-의 아침!\n오늘은 어떤 to-do가 기다리고 있을까요?"), TODAY_TODO_TAKE_START("오늘의 to-do 시작", "상쾌한 Hous-의 아침!\n오늘은 어떤 to-do가 나를 기다리고 있을까요?"), - TODO_REMIND("미완료 to-do 알림", "이런, 오늘 해야 할 to-do가 아직 끝나지 않았어요!\n빠르게 확인하고, 후다닥 끝내볼까요?"), + TODO_REMIND("미완료 to-do 알림", "이런, 오늘의 to-do가 아직 끝나지 않았어요!\n쾌적한 우리 집을 위해, 지금 확인해봐요!"), + TODO_TAKE_REMIND("미완료 to-do 알림", "이런, 오늘 해야 할 to-do가 아직 끝나지 않았어요!\n빠르게 확인하고, 후다닥 끝내볼까요?"), NEW_BADGE("배지 획득", "님, 축하해요!\n새로 받은 배지를 지금 확인해봐요!"); private final String title; diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index 5dccb9d5..d14e913f 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -17,6 +17,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @RequiredArgsConstructor @Service @Transactional @@ -44,6 +46,16 @@ public void sendTodayTodoNotification(User to, boolean isTake) { } } + public void sendRemindTodoNotification(User to, List todos, boolean isTake) { + todos.forEach(todo -> notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, remindTodoNotification(todo), false))); + if (to.getSetting().isPushNotification() && to.getSetting().getRemindTodoPushStatus() == TodoPushStatus.ON_ALL) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODO_REMIND.getTitle(), PushMessage.TODO_REMIND.getBody()); + } + if (to.getSetting().isPushNotification() && to.getSetting().getRemindTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { + firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODO_TAKE_REMIND.getTitle(), PushMessage.TODO_TAKE_REMIND.getBody()); + } + } + public void sendNewRuleNotification(User to, Rule rule) { Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); to.getOnboarding().addNotification(notification); @@ -65,6 +77,10 @@ private String newTodoNotification(Todo todo, boolean isTake) { else return String.format("'%s' %s", todo.getName(), NotificationMessage.NEW_TODO); } + private String remindTodoNotification(Todo todo) { + return String.format("'%s' %s", todo.getName(), NotificationMessage.TODO_REMIND); + } + private String newRuleNotification(Rule rule) { return String.format("'%s' %s", rule.getName(), NotificationMessage.NEW_RULE); } diff --git a/src/main/java/hous/server/service/todo/TodoScheduledService.java b/src/main/java/hous/server/service/todo/TodoScheduledService.java index 88957a1a..d637e5a8 100644 --- a/src/main/java/hous/server/service/todo/TodoScheduledService.java +++ b/src/main/java/hous/server/service/todo/TodoScheduledService.java @@ -7,6 +7,7 @@ import hous.server.domain.common.RedisKey; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; +import hous.server.domain.todo.OurTodoStatus; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.user.Onboarding; @@ -23,6 +24,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.stream.Collectors; @RequiredArgsConstructor @Service @@ -103,4 +105,31 @@ public void scheduledTodayTodos() { } }); } + + /** + * 매일 22시 0분 0초마다 실행 + */ + @Scheduled(cron = "0 0 22 * * *") + public void scheduledRemindTodos() { + List users = userRepository.findAllUsers(); + users.forEach(user -> { + Onboarding onboarding = user.getOnboarding(); + List participates = onboarding.getParticipates(); + if (participates.size() != 0) { + LocalDate today = DateUtils.todayLocalDate(); + Room room = participates.get(0).getRoom(); + List todayOurTodos = TodoServiceUtils.filterDayOurTodos(today, room.getTodos()); + List todayMyTodos = TodoServiceUtils.filterDayMyTodos(today, onboarding, room.getTodos()); + List undoneTodayOurTodos = todayOurTodos.stream() + .filter(todayOurTodo -> doneRepository.findTodayOurTodoStatus(today, todayOurTodo) != OurTodoStatus.FULL_CHECK) + .collect(Collectors.toList()); + List undoneTodayMyTodos = todayMyTodos.stream() + .filter(todayOurTodo -> !doneRepository.findTodayTodoCheckStatus(today, onboarding, todayOurTodo)) + .collect(Collectors.toList()); + if (!undoneTodayOurTodos.isEmpty()) { + notificationService.sendRemindTodoNotification(user, undoneTodayOurTodos, !undoneTodayMyTodos.isEmpty()); + } + } + }); + } } From 3c384341176190f06bf8f602210f0faef827d550 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 21 Sep 2022 19:14:41 +0900 Subject: [PATCH 169/301] =?UTF-8?q?#113=20[fix]=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=88=98=EC=A0=95=20=EC=82=AC=ED=95=AD=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/notification/NotificationService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index d14e913f..0d3c921e 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -28,7 +28,8 @@ public class NotificationService { private final FirebaseCloudMessageService firebaseCloudMessageService; public void sendNewTodoNotification(User to, Todo todo, boolean isTake) { - notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, newTodoNotification(todo, isTake), false)); + Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, newTodoNotification(todo, isTake), false)); + to.getOnboarding().addNotification(notification); if (to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_ALL) { firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_TODO.getTitle(), PushMessage.NEW_TODO.getBody()); } @@ -47,7 +48,10 @@ public void sendTodayTodoNotification(User to, boolean isTake) { } public void sendRemindTodoNotification(User to, List todos, boolean isTake) { - todos.forEach(todo -> notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, remindTodoNotification(todo), false))); + todos.forEach(todo -> { + Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, remindTodoNotification(todo), false)); + to.getOnboarding().addNotification(notification); + }); if (to.getSetting().isPushNotification() && to.getSetting().getRemindTodoPushStatus() == TodoPushStatus.ON_ALL) { firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODO_REMIND.getTitle(), PushMessage.TODO_REMIND.getBody()); } From f51c592c3ad05f1565e680754b618ce375e7efd3 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 22 Sep 2022 13:32:23 +0900 Subject: [PATCH 170/301] =?UTF-8?q?#119=20[feat]=20=ED=94=BC=EB=93=9C?= =?UTF-8?q?=EB=B0=B1=20=ED=95=9C=EA=B1=B8=EC=9D=8C=20=EB=B1=83=EC=A7=80=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 2 +- .../controller/user/UserController.java | 24 +++++++++++++++++-- .../hous/server/service/room/RoomService.java | 2 +- .../hous/server/service/user/UserService.java | 7 ++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 58f1dcd9..c1e371eb 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -48,7 +48,7 @@ public enum SuccessCode { GET_PERSONALITY_INFO_SUCCESS(OK, "성향 정보 조회 성공입니다."), GET_PERSONALITY_TEST_INFO_SUCCESS(OK, "성향테스트 정보 조회 성공입니다."), - // 뱃지 + // 배지 GET_BADGE_INFO_SUCCESS(OK, "나의 배지 목록 조회 성공입니다."), // 알림 diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 34563724..7115e3ac 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -154,14 +154,13 @@ public ResponseEntity updateUserTestScore( @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/user/badge/{badgeId}/represent") - public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", value = "대표 뱃지로 설정할 badge 의 id", required = true, example = "1") + public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", value = "대표 배지로 설정할 badge 의 id", required = true, example = "1") @PathVariable Long badgeId, @ApiIgnore @UserId Long userId) { userService.updateRepresentBadge(badgeId, userId); return SuccessResponse.NO_CONTENT; } - @ApiOperation( value = "[인증] 마이 페이지(설정) - 회원 정보를 삭제합니다.", notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다. 성공시 status code = 204, 빈 response body를 보냅니다." @@ -182,4 +181,25 @@ public ResponseEntity deleteUser(@ApiIgnore @UserId Long userId) { userService.deleteUser(userId); return SuccessResponse.NO_CONTENT; } + + @ApiOperation( + value = "[인증] 마이 페이지(설정) - 피드백 보내기 버튼 클릭 시 피드백 한걸음 배지를 전달 받습니다.", + notes = "요청에 디해여 성공시 status code = 204, 빈 response body를 보냅니다. 배지는 푸쉬알림으로 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping("/user/feedback") + public ResponseEntity acquireFeedbackBadge(@ApiIgnore @UserId Long userId) { + userService.acquireFeedbackBadge(userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 87e1084e..8400eb5d 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -96,7 +96,7 @@ public void leaveRoom(Long userId) { me.deleteParticipate(participates.get(0)); roomRepository.delete(room); } - // 내 뱃지, 알림 목록, 프로필 작성 내역, 테스트 결과 초기화 + // 내 배지, 알림 목록, 프로필 작성 내역, 테스트 결과 초기화 if (me.getRepresent() != null) { representRepository.delete(me.getRepresent()); } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 6f203a21..83f98402 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -156,4 +156,11 @@ public void deleteUser(Long userId) { roomRepository.delete(room); } } + + public void acquireFeedbackBadge(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); + badgeService.acquireBadge(user, BadgeInfo.FEEDBACK_ONE_STEP); + } + } From 2191cb187b9f00095b23040052f68a62344adef3 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 22 Sep 2022 13:33:23 +0900 Subject: [PATCH 171/301] =?UTF-8?q?#118=20[fix]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EC=84=A4=EC=A0=95=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20PATCH=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 5 +- .../java/hous/server/domain/user/Setting.java | 24 +++++++--- .../hous/server/service/user/UserService.java | 2 +- .../server/service/user/UserServiceUtils.java | 48 +++++++++++++++---- .../request/UpdatePushSettingRequestDto.java | 4 +- 5 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 34563724..074d06c6 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -91,8 +91,9 @@ public ResponseEntity updateUserInfo( } @ApiOperation( - value = "[인증] 마이 페이지(Profile 뷰) - 나의 푸시 알림 설정 정보를 수정합니다.", + value = "[인증] 마이 페이지(설정) - 나의 푸시 알림 설정 정보를 수정합니다.", notes = "푸시 알림 설정 여부를 설정합니다.\n" + + "6가지 상태값 중 수정할 상태값 1개만 담아서 요청합니다.\n" + "Rules, Badge 설정으로는 ON, OFF 를 담습니다.\n" + "Todo 관련 설정으로는 ON_ALL, ON_MY, OFF 를 담습니다.\n" + "성공시 status code = 204, 빈 response body를 보냅니다." @@ -106,7 +107,7 @@ public ResponseEntity updateUserInfo( }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) - @PutMapping("/user/push") + @PatchMapping("/user/push") public ResponseEntity updateUserPushSetting(@Valid @RequestBody UpdatePushSettingRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserPushSetting(request, userId); return SuccessResponse.NO_CONTENT; diff --git a/src/main/java/hous/server/domain/user/Setting.java b/src/main/java/hous/server/domain/user/Setting.java index 1f2cc4e3..2f0552e1 100644 --- a/src/main/java/hous/server/domain/user/Setting.java +++ b/src/main/java/hous/server/domain/user/Setting.java @@ -52,11 +52,23 @@ public static Setting newInstance() { } public void updatePushSetting(UpdatePushSettingRequestDto request) { - this.isPushNotification = request.isPushNotification(); - this.rulesPushStatus = request.getRulesPushStatus(); - this.newTodoPushStatus = request.getNewTodoPushStatus(); - this.todayTodoPushStatus = request.getTodayTodoPushStatus(); - this.remindTodoPushStatus = request.getRemindTodoPushStatus(); - this.badgePushStatus = request.getBadgePushStatus(); + if (request.isPushNotification() != null) { + this.isPushNotification = request.isPushNotification(); + } + if (request.getRulesPushStatus() != null) { + this.rulesPushStatus = request.getRulesPushStatus(); + } + if (request.getNewTodoPushStatus() != null) { + this.newTodoPushStatus = request.getNewTodoPushStatus(); + } + if (request.getTodayTodoPushStatus() != null) { + this.todayTodoPushStatus = request.getTodayTodoPushStatus(); + } + if (request.getRemindTodoPushStatus() != null) { + this.remindTodoPushStatus = request.getRemindTodoPushStatus(); + } + if (request.getBadgePushStatus() != null) { + this.badgePushStatus = request.getBadgePushStatus(); + } } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 6f203a21..5eeed809 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -94,7 +94,7 @@ public void updateUserInfo(UpdateUserInfoRequestDto request, Long userId) { public void updateUserPushSetting(UpdatePushSettingRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Setting setting = user.getSetting(); - UserServiceUtils.validatePushSettingRequestStatus(request, user); + UserServiceUtils.validatePushSettingRequest(request, user); setting.updatePushSetting(request); } diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index d439c215..eea93e66 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -44,14 +44,46 @@ public static void validateUniqueFcmToken(UserRepository userRepository, String } } - public static void validatePushSettingRequestStatus(UpdatePushSettingRequestDto request, User user) { - if (request.isPushNotification() == user.getSetting().isPushNotification() && - request.getRulesPushStatus() == user.getSetting().getRulesPushStatus() && - request.getNewTodoPushStatus() == user.getSetting().getNewTodoPushStatus() && - request.getTodayTodoPushStatus() == user.getSetting().getTodayTodoPushStatus() && - request.getRemindTodoPushStatus() == user.getSetting().getRemindTodoPushStatus() && - request.getBadgePushStatus() == user.getSetting().getBadgePushStatus()) { - throw new ValidationException(String.format("(%s) 유저의 푸시 알림 상태 중복입니다.\n%s", user.getId(), request), VALIDATION_STATUS_EXCEPTION); + public static void validatePushSettingRequest(UpdatePushSettingRequestDto request, User user) { + int notNullStatusCnt = 0; + if (request.isPushNotification() != null) { + if (request.isPushNotification() == user.getSetting().isPushNotification()) { + throw new ValidationException(String.format("(%s) 유저의 알림 상태 중복입니다.", user.getId()), VALIDATION_STATUS_EXCEPTION); + } + notNullStatusCnt++; + } + if (request.getRulesPushStatus() != null) { + if (request.getRulesPushStatus() == user.getSetting().getRulesPushStatus()) { + throw new ValidationException(String.format("(%s) 유저의 알림 상태 중복입니다.", user.getId()), VALIDATION_STATUS_EXCEPTION); + } + notNullStatusCnt++; + } + if (request.getNewTodoPushStatus() != null) { + if (request.getNewTodoPushStatus() == user.getSetting().getNewTodoPushStatus()) { + throw new ValidationException(String.format("(%s) 유저의 알림 상태 중복입니다.", user.getId()), VALIDATION_STATUS_EXCEPTION); + } + notNullStatusCnt++; + } + if (request.getTodayTodoPushStatus() != null) { + if (request.getTodayTodoPushStatus() == user.getSetting().getTodayTodoPushStatus()) { + throw new ValidationException(String.format("(%s) 유저의 알림 상태 중복입니다.", user.getId()), VALIDATION_STATUS_EXCEPTION); + } + notNullStatusCnt++; + } + if (request.getRemindTodoPushStatus() != null) { + if (request.getRemindTodoPushStatus() == user.getSetting().getRemindTodoPushStatus()) { + throw new ValidationException(String.format("(%s) 유저의 알림 상태 중복입니다.", user.getId()), VALIDATION_STATUS_EXCEPTION); + } + notNullStatusCnt++; + } + if (request.getBadgePushStatus() != null) { + if (request.getBadgePushStatus() == user.getSetting().getBadgePushStatus()) { + throw new ValidationException(String.format("(%s) 유저의 알림 상태 중복입니다.", user.getId()), VALIDATION_STATUS_EXCEPTION); + } + notNullStatusCnt++; + } + if (notNullStatusCnt != 1) { + throw new ValidationException(String.format("(%s) 유저의 잘못된 요청 (%s) 입니다.", user.getId(), request), VALIDATION_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java index 948b7a14..3f3f8395 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdatePushSettingRequestDto.java @@ -13,7 +13,7 @@ public class UpdatePushSettingRequestDto { @ApiModelProperty(value = "알림 받기", example = "true") - private boolean isPushNotification; + private Boolean isPushNotification; @ApiModelProperty(value = "새로운 Rules 추가", example = "ON") private PushStatus rulesPushStatus; @@ -31,7 +31,7 @@ public class UpdatePushSettingRequestDto { private PushStatus badgePushStatus; @JsonProperty("isPushNotification") - public boolean isPushNotification() { + public Boolean isPushNotification() { return isPushNotification; } } From 32f44b3506384a591dba4daae91c856645055da0 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 22 Sep 2022 14:09:40 +0900 Subject: [PATCH 172/301] =?UTF-8?q?#117=20[docs]=20swagger=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/rule/RuleController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index f225da19..0e062d9a 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -40,7 +40,7 @@ public class RuleController { @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" - + "2. 존재하지 않는 방입니다.", + + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) From b4db0500958f7cd41966c4f8982eb41b2918d33a Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 22 Sep 2022 14:16:06 +0900 Subject: [PATCH 173/301] =?UTF-8?q?#117=20[rename]=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=AA=85,=20=EB=B3=80=EC=88=98=EB=AA=85=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 --- .../java/hous/server/service/auth/AuthServiceProvider.java | 6 +++--- .../impl/{KaKaoAuthService.java => KakaoAuthService.java} | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/hous/server/service/auth/impl/{KaKaoAuthService.java => KakaoAuthService.java} (89%) diff --git a/src/main/java/hous/server/service/auth/AuthServiceProvider.java b/src/main/java/hous/server/service/auth/AuthServiceProvider.java index d6bee416..f621f84b 100644 --- a/src/main/java/hous/server/service/auth/AuthServiceProvider.java +++ b/src/main/java/hous/server/service/auth/AuthServiceProvider.java @@ -2,7 +2,7 @@ import hous.server.domain.user.UserSocialType; import hous.server.service.auth.impl.AppleAuthService; -import hous.server.service.auth.impl.KaKaoAuthService; +import hous.server.service.auth.impl.KakaoAuthService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -17,12 +17,12 @@ public class AuthServiceProvider { private static final Map authServiceMap = new HashMap<>(); private final AppleAuthService appleAuthService; - private final KaKaoAuthService kaKaoAuthService; + private final KakaoAuthService kakaoAuthService; @PostConstruct void initializeAuthServicesMap() { authServiceMap.put(UserSocialType.APPLE, appleAuthService); - authServiceMap.put(UserSocialType.KAKAO, kaKaoAuthService); + authServiceMap.put(UserSocialType.KAKAO, kakaoAuthService); } public AuthService getAuthService(UserSocialType socialType) { diff --git a/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java similarity index 89% rename from src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java rename to src/main/java/hous/server/service/auth/impl/KakaoAuthService.java index 576be0ee..fbe89e36 100644 --- a/src/main/java/hous/server/service/auth/impl/KaKaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java @@ -17,11 +17,11 @@ @RequiredArgsConstructor @Service @Transactional -public class KaKaoAuthService implements AuthService { +public class KakaoAuthService implements AuthService { private static final UserSocialType socialType = UserSocialType.KAKAO; - private final KakaoApiClient kaKaoApiCaller; + private final KakaoApiClient kakaoApiCaller; private final UserRepository userRepository; @@ -29,7 +29,7 @@ public class KaKaoAuthService implements AuthService { @Override public Long login(LoginDto request) { - KakaoProfileResponse response = kaKaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); + KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); if (user == null) return userService.registerUser(request.toCreateUserDto(response.getId())); else { From 78d2cb6e7551bc8ba898051e5985753149b39ccd Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 22 Sep 2022 14:33:30 +0900 Subject: [PATCH 174/301] =?UTF-8?q?#117=20[feat]=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/auth/AuthController.java | 33 ++++++++++++++++--- .../java/hous/server/domain/user/User.java | 4 +++ .../service/auth/CommonAuthService.java | 27 +++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/main/java/hous/server/service/auth/CommonAuthService.java diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 2b63b4ce..1e6250af 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -3,10 +3,13 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; +import hous.server.config.interceptor.Auth; +import hous.server.config.resolver.UserId; import hous.server.controller.auth.dto.request.LoginRequestDto; import hous.server.controller.auth.dto.response.LoginResponse; import hous.server.service.auth.AuthService; import hous.server.service.auth.AuthServiceProvider; +import hous.server.service.auth.CommonAuthService; import hous.server.service.auth.CreateTokenService; import hous.server.service.auth.dto.request.TokenRequestDto; import hous.server.service.auth.dto.response.TokenResponse; @@ -15,11 +18,10 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -31,6 +33,7 @@ public class AuthController { private final AuthServiceProvider authServiceProvider; private final CreateTokenService createTokenService; + private final CommonAuthService commonAuthService; @ApiOperation( value = "로그인 페이지 - 로그인을 요청합니다.", @@ -82,4 +85,26 @@ public ResponseEntity login(@Valid @RequestBody LoginRequestDto r public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto request) { return SuccessResponse.success(SuccessCode.REISSUE_TOKEN_SUCCESS, createTokenService.reissueToken(request)); } + + @ApiOperation( + value = "[인증] 마이 페이지(설정) - 로그아웃을 요청합니다.", + notes = "성공시 status code = 204, 빈 response body로 보냅니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping("/auth/logout") + public ResponseEntity logout(@ApiIgnore @UserId Long userId) { + commonAuthService.logout(userId); + return SuccessResponse.NO_CONTENT; + } } diff --git a/src/main/java/hous/server/domain/user/User.java b/src/main/java/hous/server/domain/user/User.java index 6d8e22a3..0412aeb5 100644 --- a/src/main/java/hous/server/domain/user/User.java +++ b/src/main/java/hous/server/domain/user/User.java @@ -48,4 +48,8 @@ public void setOnboarding(Onboarding onboarding) { public void updateFcmToken(String fcmToken) { this.fcmToken = fcmToken; } + + public void resetFcmToken() { + this.fcmToken = null; + } } diff --git a/src/main/java/hous/server/service/auth/CommonAuthService.java b/src/main/java/hous/server/service/auth/CommonAuthService.java new file mode 100644 index 00000000..48b85406 --- /dev/null +++ b/src/main/java/hous/server/service/auth/CommonAuthService.java @@ -0,0 +1,27 @@ +package hous.server.service.auth; + +import hous.server.common.util.JwtUtils; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.room.RoomServiceUtils; +import hous.server.service.user.UserServiceUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class CommonAuthService { + + private final UserRepository userRepository; + + private final JwtUtils jwtProvider; + + public void logout(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + RoomServiceUtils.findParticipatingRoom(user); + jwtProvider.expireRefreshToken(user.getId()); + user.resetFcmToken(); + } +} From aa82055960a707d19d7090d37342a335626144a4 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 22 Sep 2022 14:51:17 +0900 Subject: [PATCH 175/301] =?UTF-8?q?#117=20[fix]=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=82=B4=EB=B6=80=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EB=A1=9C=EC=A7=81=EC=97=90=20fcmToken=20null=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/auth/AuthController.java | 1 + .../server/service/auth/CreateTokenService.java | 15 ++++++++++++--- .../firebase/FirebaseCloudMessageService.java | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 1e6250af..2cf9cd25 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -79,6 +79,7 @@ public ResponseEntity login(@Valid @RequestBody LoginRequestDto r + "2. refresh token 을 입력해주세요.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PostMapping("/auth/refresh") diff --git a/src/main/java/hous/server/service/auth/CreateTokenService.java b/src/main/java/hous/server/service/auth/CreateTokenService.java index d6be2c60..2ba70e91 100644 --- a/src/main/java/hous/server/service/auth/CreateTokenService.java +++ b/src/main/java/hous/server/service/auth/CreateTokenService.java @@ -3,8 +3,11 @@ import hous.server.common.exception.UnAuthorizedException; import hous.server.common.util.JwtUtils; import hous.server.domain.common.RedisKey; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; import hous.server.service.auth.dto.request.TokenRequestDto; import hous.server.service.auth.dto.response.TokenResponse; +import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -16,6 +19,8 @@ @Service public class CreateTokenService { + private final UserRepository userRepository; + private final JwtUtils jwtProvider; private final RedisTemplate redisTemplate; @@ -27,17 +32,21 @@ public TokenResponse createTokenInfo(Long userId) { @Transactional public TokenResponse reissueToken(TokenRequestDto request) { + Long userId = jwtProvider.getUserIdFromJwt(request.getAccessToken()); + User user = UserServiceUtils.findUserById(userRepository, userId); if (!jwtProvider.validateToken(request.getRefreshToken())) { + user.resetFcmToken(); throw new UnAuthorizedException(String.format("주어진 리프레시 토큰 (%s) 이 유효하지 않습니다.", request.getRefreshToken())); } - Long userId = jwtProvider.getUserIdFromJwt(request.getAccessToken()); String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + userId); - if (Objects.isNull(refreshToken)) { + user.resetFcmToken(); throw new UnAuthorizedException(String.format("이미 만료된 리프레시 토큰 (%s) 입니다.", request.getRefreshToken())); } if (!refreshToken.equals(request.getRefreshToken())) { - throw new UnAuthorizedException(String.format("해당 리프레시 토큰의 정보가 일치하지 않습니다.", request.getRefreshToken())); + jwtProvider.expireRefreshToken(user.getId()); + user.resetFcmToken(); + throw new UnAuthorizedException(String.format("해당 리프레시 토큰 (%s) 의 정보가 일치하지 않습니다.", request.getRefreshToken())); } return jwtProvider.createTokenInfo(userId); } diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index 04d45d9d..d70f8ee7 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -42,6 +42,7 @@ public void sendMessageTo(String targetToken, String title, String body) { User user = userRepository.findUserByFcmToken(targetToken); if (user != null) { jwtProvider.expireRefreshToken(user.getId()); + user.resetFcmToken(); } log.error(exception.getErrorMessage(), exception); } From ecc9c1a9c095d0b98d09d1bd0ed4a99bce30069a Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 22 Sep 2022 15:22:18 +0900 Subject: [PATCH 176/301] =?UTF-8?q?#124=20[fix]=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EB=A0=88=EB=B2=A8=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advice/ControllerExceptionAdvice.java | 96 ++++++++++--------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java index 9e79a538..ece638a2 100644 --- a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java +++ b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java @@ -30,15 +30,47 @@ @RestControllerAdvice public class ControllerExceptionAdvice { + /** + * Hous Custom Exception + */ + @ExceptionHandler(HousException.class) + protected ResponseEntity handleBaseException(HousException exception) { + if (exception.getStatus() >= 400 && exception.getStatus() < 500) { + log.warn(exception.getMessage(), exception); + } else { + log.error(exception.getMessage(), exception); + } + return ResponseEntity.status(exception.getStatus()) + .body(ErrorResponse.error(exception.getErrorCode())); + } + + /** + * Feign Client Exception + */ + @ExceptionHandler(FeignClientException.class) + protected ResponseEntity handleFeignClientException(final FeignClientException exception) { + if (exception.getStatus() >= 400 && exception.getStatus() < 500) { + log.warn(exception.getMessage(), exception); + } else { + log.error(exception.getMessage(), exception); + } + if (exception.getStatus() == UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) { + return ResponseEntity.status(UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) + .body(ErrorResponse.error(UNAUTHORIZED_INVALID_TOKEN_EXCEPTION)); + } + return ResponseEntity.status(INTERNAL_SERVER_EXCEPTION.getStatus()) + .body(ErrorResponse.error(INTERNAL_SERVER_EXCEPTION)); + } + /** * 400 BadRequest * Spring Validation */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(BindException.class) - protected ErrorResponse handleBadRequest(final BindException e) { - log.error(e.getMessage()); - FieldError fieldError = Objects.requireNonNull(e.getFieldError()); + protected ErrorResponse handleBadRequest(final BindException exception) { + log.warn(exception.getMessage()); + FieldError fieldError = Objects.requireNonNull(exception.getFieldError()); return ErrorResponse.error(VALIDATION_EXCEPTION, String.format("%s (%s)", fieldError.getDefaultMessage(), fieldError.getField())); } @@ -48,8 +80,8 @@ protected ErrorResponse handleBadRequest(final BindException e) { */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(ConstraintViolationException.class) - protected ErrorResponse handleConstraintViolationException(final ConstraintViolationException e) { - log.error(e.getMessage()); + protected ErrorResponse handleConstraintViolationException(final ConstraintViolationException exception) { + log.warn(exception.getMessage()); return ErrorResponse.error(VALIDATION_SORT_TYPE_EXCEPTION); } @@ -59,8 +91,8 @@ protected ErrorResponse handleConstraintViolationException(final ConstraintViola */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(HttpMessageNotReadableException.class) - protected ErrorResponse handleHttpMessageNotReadableException(final HttpMessageNotReadableException e) { - log.error(e.getMessage()); + protected ErrorResponse handleHttpMessageNotReadableException(final HttpMessageNotReadableException exception) { + log.warn(exception.getMessage()); return ErrorResponse.error(VALIDATION_ENUM_VALUE_EXCEPTION); } @@ -70,8 +102,8 @@ protected ErrorResponse handleHttpMessageNotReadableException(final HttpMessageN */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MissingRequestValueException.class) - protected ErrorResponse handle(final MissingRequestValueException e) { - log.error(e.getMessage()); + protected ErrorResponse handle(final MissingRequestValueException exception) { + log.warn(exception.getMessage()); return ErrorResponse.error(VALIDATION_REQUEST_MISSING_EXCEPTION); } @@ -81,9 +113,9 @@ protected ErrorResponse handle(final MissingRequestValueException e) { */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(TypeMismatchException.class) - protected ErrorResponse handleTypeMismatchException(final TypeMismatchException e) { - log.error(e.getMessage()); - return ErrorResponse.error(VALIDATION_WRONG_TYPE_EXCEPTION, String.format("%s (%s)", VALIDATION_WRONG_TYPE_EXCEPTION.getMessage(), e.getValue())); + protected ErrorResponse handleTypeMismatchException(final TypeMismatchException exception) { + log.warn(exception.getMessage()); + return ErrorResponse.error(VALIDATION_WRONG_TYPE_EXCEPTION, String.format("%s (%s)", VALIDATION_WRONG_TYPE_EXCEPTION.getMessage(), exception.getValue())); } /** @@ -95,8 +127,8 @@ protected ErrorResponse handleTypeMismatchException(final TypeMismatchException ServletRequestBindingException.class, MethodArgumentTypeMismatchException.class }) - protected ErrorResponse handleInvalidFormatException(final Exception e) { - log.error(e.getMessage()); + protected ErrorResponse handleInvalidFormatException(final Exception exception) { + log.warn(exception.getMessage()); return ErrorResponse.error(VALIDATION_EXCEPTION); } @@ -106,8 +138,8 @@ protected ErrorResponse handleInvalidFormatException(final Exception e) { */ @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler(HttpRequestMethodNotSupportedException.class) - protected ErrorResponse handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { - log.error(e.getMessage()); + protected ErrorResponse handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) { + log.warn(exception.getMessage()); return ErrorResponse.error(METHOD_NOT_ALLOWED_EXCEPTION); } @@ -116,8 +148,8 @@ protected ErrorResponse handleHttpRequestMethodNotSupportedException(HttpRequest */ @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) @ExceptionHandler(HttpMediaTypeNotAcceptableException.class) - protected ErrorResponse handleHttpMediaTypeNotAcceptableException(HttpMediaTypeNotAcceptableException e) { - log.error(e.getMessage()); + protected ErrorResponse handleHttpMediaTypeNotAcceptableException(HttpMediaTypeNotAcceptableException exception) { + log.warn(exception.getMessage()); return ErrorResponse.error(NOT_ACCEPTABLE_EXCEPTION); } @@ -127,35 +159,11 @@ protected ErrorResponse handleHttpMediaTypeNotAcceptableException(HttpMediaTypeN */ @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) @ExceptionHandler(HttpMediaTypeException.class) - protected ErrorResponse handleHttpMediaTypeException(final HttpMediaTypeException e) { - log.error(e.getMessage(), e); + protected ErrorResponse handleHttpMediaTypeException(final HttpMediaTypeException exception) { + log.warn(exception.getMessage(), exception); return ErrorResponse.error(UNSUPPORTED_MEDIA_TYPE_EXCEPTION); } - /** - * Feign Client Exception - */ - @ExceptionHandler(FeignClientException.class) - protected ResponseEntity handleFeignClientException(final FeignClientException e) { - log.error(e.getErrorMessage(), e); - if (e.getStatus() == UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) { - return ResponseEntity.status(UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) - .body(ErrorResponse.error(UNAUTHORIZED_INVALID_TOKEN_EXCEPTION)); - } - return ResponseEntity.status(INTERNAL_SERVER_EXCEPTION.getStatus()) - .body(ErrorResponse.error(INTERNAL_SERVER_EXCEPTION)); - } - - /** - * Hous Custom Exception - */ - @ExceptionHandler(HousException.class) - protected ResponseEntity handleBaseException(HousException exception) { - log.error(exception.getMessage(), exception); - return ResponseEntity.status(exception.getStatus()) - .body(ErrorResponse.error(exception.getErrorCode())); - } - /** * 500 Internal Server */ From 97e9f2b897cafc63b42fd834bec8fe1edd6968e3 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 22 Sep 2022 15:47:06 +0900 Subject: [PATCH 177/301] =?UTF-8?q?#122=20[feat]=20=ED=98=B8=EB=AF=B8?= =?UTF-8?q?=EC=9D=98=20=ED=83=84=EC=83=9D=20=EB=B0=B0=EC=A7=80=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/repository/UserRepositoryCustom.java | 3 ++ .../user/repository/UserRepositoryImpl.java | 12 +++++++ .../service/user/UserScheduledService.java | 32 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/main/java/hous/server/service/user/UserScheduledService.java diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java index 07edec34..9ba8f2c5 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryCustom.java @@ -3,6 +3,7 @@ import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; +import java.time.LocalDate; import java.util.List; public interface UserRepositoryCustom { @@ -16,4 +17,6 @@ public interface UserRepositoryCustom { User findUserByFcmToken(String fcmToken); List findAllUsers(); + + List findAllUserByBirthday(LocalDate birthday); } diff --git a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java index 932c1866..58fdfa82 100644 --- a/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java +++ b/src/main/java/hous/server/domain/user/repository/UserRepositoryImpl.java @@ -6,6 +6,7 @@ import hous.server.domain.user.UserStatus; import lombok.RequiredArgsConstructor; +import java.time.LocalDate; import java.util.List; import static hous.server.domain.user.QUser.user; @@ -67,4 +68,15 @@ public List findAllUsers() { .where(user.status.eq(UserStatus.ACTIVE)) .fetch(); } + + @Override + public List findAllUserByBirthday(LocalDate birthday) { + return queryFactory + .selectFrom(user) + .where( + user.status.eq(UserStatus.ACTIVE), + user.onboarding.birthday.eq(birthday) + ) + .fetch(); + } } diff --git a/src/main/java/hous/server/service/user/UserScheduledService.java b/src/main/java/hous/server/service/user/UserScheduledService.java new file mode 100644 index 00000000..6775306d --- /dev/null +++ b/src/main/java/hous/server/service/user/UserScheduledService.java @@ -0,0 +1,32 @@ +package hous.server.service.user; + +import hous.server.common.util.DateUtils; +import hous.server.domain.badge.BadgeInfo; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import hous.server.service.badge.BadgeService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@RequiredArgsConstructor +@Service +@Transactional +public class UserScheduledService { + + private final UserRepository userRepository; + + private final BadgeService badgeService; + + /** + * 매일 9시 0분 0초마다 실행 + */ + @Scheduled(cron = "0 0 9 * * *") + public void scheduledTodayBirthday() { + List users = userRepository.findAllUserByBirthday(DateUtils.todayLocalDate()); + users.forEach(user -> badgeService.acquireBadge(user, BadgeInfo.HOMIE_IS_BORN)); + } +} From c857dbf2ac09223d40cb5a643f5d938efee8af0c Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 23 Sep 2022 12:14:22 +0900 Subject: [PATCH 178/301] =?UTF-8?q?#131=20[fix]=20fcmToken=20null=20?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=97=90=EB=9F=AC=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firebase/FirebaseCloudMessageService.java | 12 ++++-------- .../notification/NotificationService.java | 16 ++++++++-------- .../server/service/user/UserServiceUtils.java | 8 +++++--- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index d70f8ee7..fdf388a5 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -9,7 +9,6 @@ import hous.server.common.util.JwtUtils; import hous.server.common.util.YamlPropertySourceFactory; import hous.server.domain.user.User; -import hous.server.domain.user.repository.UserRepository; import hous.server.external.client.firebase.FirebaseApiClient; import hous.server.service.firebase.dto.request.FcmMessage; import lombok.RequiredArgsConstructor; @@ -29,21 +28,18 @@ @PropertySource(value = "classpath:application-firebase.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) public class FirebaseCloudMessageService { - private final UserRepository userRepository; private final ObjectMapper objectMapper; private final FirebaseApiClient firebaseApiCaller; private final JwtUtils jwtProvider; - public void sendMessageTo(String targetToken, String title, String body) { + public void sendMessageTo(User to, String title, String body) { + String targetToken = to.getFcmToken(); String message = makeMessage(targetToken, title, body); try { firebaseApiCaller.requestFcmMessaging(HttpHeaderUtils.withBearerToken(getAccessToken()), message); } catch (FeignClientException exception) { - User user = userRepository.findUserByFcmToken(targetToken); - if (user != null) { - jwtProvider.expireRefreshToken(user.getId()); - user.resetFcmToken(); - } + jwtProvider.expireRefreshToken(to.getId()); + to.resetFcmToken(); log.error(exception.getErrorMessage(), exception); } } diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index 0d3c921e..892b3579 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -31,19 +31,19 @@ public void sendNewTodoNotification(User to, Todo todo, boolean isTake) { Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, newTodoNotification(todo, isTake), false)); to.getOnboarding().addNotification(notification); if (to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_ALL) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_TODO.getTitle(), PushMessage.NEW_TODO.getBody()); + firebaseCloudMessageService.sendMessageTo(to, PushMessage.NEW_TODO.getTitle(), PushMessage.NEW_TODO.getBody()); } if (to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_TODO_TAKE.getTitle(), PushMessage.NEW_TODO_TAKE.getBody()); + firebaseCloudMessageService.sendMessageTo(to, PushMessage.NEW_TODO_TAKE.getTitle(), PushMessage.NEW_TODO_TAKE.getBody()); } } public void sendTodayTodoNotification(User to, boolean isTake) { if (to.getSetting().isPushNotification() && to.getSetting().getTodayTodoPushStatus() == TodoPushStatus.ON_ALL) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODAY_TODO_START.getTitle(), PushMessage.TODAY_TODO_START.getBody()); + firebaseCloudMessageService.sendMessageTo(to, PushMessage.TODAY_TODO_START.getTitle(), PushMessage.TODAY_TODO_START.getBody()); } if (to.getSetting().isPushNotification() && to.getSetting().getTodayTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODAY_TODO_TAKE_START.getTitle(), PushMessage.TODAY_TODO_TAKE_START.getBody()); + firebaseCloudMessageService.sendMessageTo(to, PushMessage.TODAY_TODO_TAKE_START.getTitle(), PushMessage.TODAY_TODO_TAKE_START.getBody()); } } @@ -53,10 +53,10 @@ public void sendRemindTodoNotification(User to, List todos, boolean isTake to.getOnboarding().addNotification(notification); }); if (to.getSetting().isPushNotification() && to.getSetting().getRemindTodoPushStatus() == TodoPushStatus.ON_ALL) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODO_REMIND.getTitle(), PushMessage.TODO_REMIND.getBody()); + firebaseCloudMessageService.sendMessageTo(to, PushMessage.TODO_REMIND.getTitle(), PushMessage.TODO_REMIND.getBody()); } if (to.getSetting().isPushNotification() && to.getSetting().getRemindTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.TODO_TAKE_REMIND.getTitle(), PushMessage.TODO_TAKE_REMIND.getBody()); + firebaseCloudMessageService.sendMessageTo(to, PushMessage.TODO_TAKE_REMIND.getTitle(), PushMessage.TODO_TAKE_REMIND.getBody()); } } @@ -64,7 +64,7 @@ public void sendNewRuleNotification(User to, Rule rule) { Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); to.getOnboarding().addNotification(notification); if (to.getSetting().isPushNotification() && to.getSetting().getRulesPushStatus() == PushStatus.ON) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), PushMessage.NEW_RULE.getTitle(), PushMessage.NEW_RULE.getBody()); + firebaseCloudMessageService.sendMessageTo(to, PushMessage.NEW_RULE.getTitle(), PushMessage.NEW_RULE.getBody()); } } @@ -72,7 +72,7 @@ public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) { Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.BADGE, newBadgeNotification(badgeInfo), false)); to.getOnboarding().addNotification(notification); if (to.getSetting().isPushNotification() && to.getSetting().getBadgePushStatus() == PushStatus.ON) { - firebaseCloudMessageService.sendMessageTo(to.getFcmToken(), newBadgePushTitle(badgeInfo), newBadgePushBody(to.getOnboarding())); + firebaseCloudMessageService.sendMessageTo(to, newBadgePushTitle(badgeInfo), newBadgePushBody(to.getOnboarding())); } } diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index eea93e66..97434244 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -38,9 +38,11 @@ public static User findUserById(UserRepository userRepository, Long userId) { } public static void validateUniqueFcmToken(UserRepository userRepository, String fcmToken) { - User user = userRepository.findUserByFcmToken(fcmToken); - if (user != null) { - throw new ConflictException(String.format("fcm token (%s) 중복입니다.", fcmToken), CONFLICT_FCM_TOKEN_EXCEPTION); + if (fcmToken != null) { + User user = userRepository.findUserByFcmToken(fcmToken); + if (user != null) { + throw new ConflictException(String.format("fcm token (%s) 중복입니다.", fcmToken), CONFLICT_FCM_TOKEN_EXCEPTION); + } } } From a490f18131714f247be4f328d6cc94395f231388 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 23 Sep 2022 22:05:11 +0900 Subject: [PATCH 179/301] =?UTF-8?q?#133=20[fix]=20=EC=95=A0=ED=94=8C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=97=90=EB=9F=AC=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/UnAuthorizedException.java | 4 ++++ .../external/client/apple/AppleTokenProviderImpl.java | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/common/exception/UnAuthorizedException.java b/src/main/java/hous/server/common/exception/UnAuthorizedException.java index 6015e556..315d5b61 100644 --- a/src/main/java/hous/server/common/exception/UnAuthorizedException.java +++ b/src/main/java/hous/server/common/exception/UnAuthorizedException.java @@ -5,4 +5,8 @@ public class UnAuthorizedException extends HousException { public UnAuthorizedException(String message) { super(message, ErrorCode.UNAUTHORIZED_EXCEPTION); } + + public UnAuthorizedException(String message, ErrorCode errorCode) { + super(message, errorCode); + } } diff --git a/src/main/java/hous/server/external/client/apple/AppleTokenProviderImpl.java b/src/main/java/hous/server/external/client/apple/AppleTokenProviderImpl.java index 5c7dd731..888eaa3c 100644 --- a/src/main/java/hous/server/external/client/apple/AppleTokenProviderImpl.java +++ b/src/main/java/hous/server/external/client/apple/AppleTokenProviderImpl.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import hous.server.common.exception.UnAuthorizedException; import hous.server.external.client.apple.dto.response.ApplePublicKeyResponse; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -21,6 +22,8 @@ import java.util.Base64; import java.util.Map; +import static hous.server.common.exception.ErrorCode.UNAUTHORIZED_INVALID_TOKEN_EXCEPTION; + @RequiredArgsConstructor @Component public class AppleTokenProviderImpl implements AppleTokenProvider { @@ -42,10 +45,10 @@ public String getSocialIdFromIdToken(String idToken) { .getBody(); return claims.getSubject(); // return socialId; } catch (JsonProcessingException | InvalidKeySpecException | InvalidClaimException | - NoSuchAlgorithmException e) { - throw new IllegalArgumentException(String.format("잘못된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage())); + NoSuchAlgorithmException | IllegalArgumentException e) { + throw new UnAuthorizedException(String.format("잘못된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage()), UNAUTHORIZED_INVALID_TOKEN_EXCEPTION); } catch (ExpiredJwtException e) { - throw new IllegalArgumentException(String.format("만료된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage())); + throw new UnAuthorizedException(String.format("만료된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage()), UNAUTHORIZED_INVALID_TOKEN_EXCEPTION); } } From 6a3dce70fba1c1f73efdc598f8475080db151687 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 28 Sep 2022 19:05:18 +0900 Subject: [PATCH 180/301] =?UTF-8?q?#137=20[fix]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85,=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../controller/auth/AuthController.java | 52 ++++++++++++++---- .../auth/dto/request/SignUpRequestDto.java | 55 +++++++++++++++++++ .../hous/server/domain/user/Onboarding.java | 11 +++- .../hous/server/service/auth/AuthService.java | 3 + .../service/auth/dto/request/LoginDto.java | 12 ++-- .../service/auth/dto/request/SignUpDto.java | 44 +++++++++++++++ .../service/auth/impl/AppleAuthService.java | 14 +++-- .../service/auth/impl/KakaoAuthService.java | 14 +++-- .../hous/server/service/user/UserService.java | 9 ++- .../server/service/user/UserServiceUtils.java | 6 +- .../dto/request/CreateUserRequestDto.java | 26 +++++++-- .../request/SetOnboardingInfoRequestDto.java | 2 +- .../resources/messages/validation.properties | 2 +- 14 files changed, 210 insertions(+), 41 deletions(-) create mode 100644 src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java create mode 100644 src/main/java/hous/server/service/auth/dto/request/SignUpDto.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index c1e371eb..3a8da57b 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -14,6 +14,7 @@ public enum SuccessCode { * 200 OK */ // 인증 + SIGNUP_SUCCESS(OK, "회원가입 성공입니다."), LOGIN_SUCCESS(OK, "로그인 성공입니다."), REISSUE_TOKEN_SUCCESS(OK, "토큰 갱신 성공입니다."), diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 2cf9cd25..3135a8ef 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -6,6 +6,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.controller.auth.dto.request.LoginRequestDto; +import hous.server.controller.auth.dto.request.SignUpRequestDto; import hous.server.controller.auth.dto.response.LoginResponse; import hous.server.service.auth.AuthService; import hous.server.service.auth.AuthServiceProvider; @@ -36,18 +37,21 @@ public class AuthController { private final CommonAuthService commonAuthService; @ApiOperation( - value = "로그인 페이지 - 로그인을 요청합니다.", - notes = "카카오 로그인, 애플 로그인을 요청합니다.\n" + - "최초 로그인의 경우 회원가입 처리 후 로그인됩니다.\n" + - "socialType - KAKAO (카카오), APPLE (애플)\n" + value = "온보딩 페이지 - 회원가입을 요청합니다.", + notes = "카카오 회원가입, 애플 회원가입을 요청합니다.\n" + + "socialType - KAKAO (카카오), APPLE (애플)" ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "로그인 성공입니다."), + @ApiResponse(code = 200, message = "회원가입 성공입니다."), @ApiResponse( code = 400, - message = "1. 유저의 socialType 를 입력해주세요.\n" - + "2. access token 을 입력해주세요.\n" - + "3. fcm token 을 입력해주세요.", + message = "1. 유저의 socialType 를 입력해주세요. (socialType)\n" + + "2. access token 을 입력해주세요. (token)\n" + + "3. fcm token 을 입력해주세요. (fcmToken)\n" + + "4. 닉네임을 입력해주세요. (nickname)\n" + + "5. 닉네임은 최대 3글자까지 가능합니다. (nickname)\n" + + "6. 생년월일을 입력해주세요. (birthday)\n" + + "7. 생년월일을 공개 여부를 체크해주세요. (isPublic)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), @ApiResponse( @@ -57,6 +61,34 @@ public class AuthController { response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PostMapping("/auth/signup") + public ResponseEntity signUp(@Valid @RequestBody SignUpRequestDto request) { + AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); + Long userId = authService.signUp(request.toServiceDto()); + + TokenResponse tokenInfo = createTokenService.createTokenInfo(userId); + return SuccessResponse.success(SuccessCode.SIGNUP_SUCCESS, LoginResponse.of(userId, tokenInfo)); + } + + @ApiOperation( + value = "로그인 페이지 - 로그인을 요청합니다.", + notes = "카카오 로그인, 애플 로그인을 요청합니다.\n" + + "socialType - KAKAO (카카오), APPLE (애플)\n" + + "회원가입이 완료되지 않은 사용자일 경우 404 에러를 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "로그인 성공입니다."), + @ApiResponse( + code = 400, + message = "1. 유저의 socialType 를 입력해주세요. (socialType)\n" + + "2. access token 을 입력해주세요. (token)\n" + + "3. fcm token 을 입력해주세요. (fcmToken)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "fcm token 중복입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) @PostMapping("/auth/login") public ResponseEntity login(@Valid @RequestBody LoginRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); @@ -75,8 +107,8 @@ public ResponseEntity login(@Valid @RequestBody LoginRequestDto r @ApiResponse(code = 200, message = "토큰 갱신 성공입니다."), @ApiResponse( code = 400, - message = "1. access token 을 입력해주세요.\n" - + "2. refresh token 을 입력해주세요.", + message = "1. access token 을 입력해주세요. (accessToken)\n" + + "2. refresh token 을 입력해주세요. (refreshToken)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), diff --git a/src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java b/src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java new file mode 100644 index 00000000..66144d6a --- /dev/null +++ b/src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java @@ -0,0 +1,55 @@ +package hous.server.controller.auth.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.user.UserSocialType; +import hous.server.service.auth.dto.request.SignUpDto; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.time.LocalDate; + +@ToString +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SignUpRequestDto { + + @ApiModelProperty(value = "소셜 로그인 타입 - KAKAO, APPLE", example = "KAKAO") + @NotNull(message = "{user.socialType.notNull}") + private UserSocialType socialType; + + @ApiModelProperty(value = "토큰 - socialToken", example = "ijv4qLk0I7jYuDpFe-9A-oAx59-AAfC6UbTuairPCj1zTQAAAYI6e-6o") + @NotBlank(message = "{auth.token.notBlank}") + private String token; + + @ApiModelProperty(value = "토큰 - fcmToken", example = "dfdafjdslkfjslfjslifsjvmdsklvdosijiofjamvsdlkvmiodsjfdiosmvsdjvosadjvosd") + @NotBlank(message = "{auth.fcmToken.notBlank}") + private String fcmToken; + + @ApiModelProperty(value = "닉네임", example = "혜조니") + @NotBlank(message = "{onboarding.nickname.notBlank}") + @Size(min = 1, max = 3, message = "{onboarding.nickname.max}") + private String nickname; + + @ApiModelProperty(value = "생년월일", example = "1999-03-04") + @NotNull(message = "{onboarding.birthday.notNull}") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") + private LocalDate birthday; + + @ApiModelProperty(value = "생년월일 공개 여부", example = "true") + @NotNull(message = "{onboarding.isPublic.notNull}") + private Boolean isPublic; + + @JsonProperty("isPublic") + public Boolean isPublic() { + return isPublic; + } + + public SignUpDto toServiceDto() { + return SignUpDto.of(socialType, token, fcmToken, nickname, birthday, isPublic); + } +} diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 3e5ea74e..ef1cac5b 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -29,10 +29,11 @@ public class Onboarding extends AuditingTimeEntity { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) private User user; - @Column(length = 30) + + @Column(nullable = false, length = 30) private String nickname; - @Column + @Column(nullable = false) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") private LocalDate birthday; @@ -71,12 +72,16 @@ public class Onboarding extends AuditingTimeEntity { @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List notifications = new ArrayList<>(); - public static Onboarding newInstance(User user, Personality personality, TestScore testScore) { + public static Onboarding newInstance(User user, Personality personality, TestScore testScore, + String nickname, LocalDate birthday, boolean isPublic) { return Onboarding.builder() .user(user) .isChecked(false) .personality(personality) .testScore(testScore) + .nickname(nickname) + .birthday(birthday) + .isPublic(isPublic) .build(); } diff --git a/src/main/java/hous/server/service/auth/AuthService.java b/src/main/java/hous/server/service/auth/AuthService.java index a1dff192..8ba89abd 100644 --- a/src/main/java/hous/server/service/auth/AuthService.java +++ b/src/main/java/hous/server/service/auth/AuthService.java @@ -1,8 +1,11 @@ package hous.server.service.auth; import hous.server.service.auth.dto.request.LoginDto; +import hous.server.service.auth.dto.request.SignUpDto; public interface AuthService { + Long signUp(SignUpDto request); + Long login(LoginDto request); } diff --git a/src/main/java/hous/server/service/auth/dto/request/LoginDto.java b/src/main/java/hous/server/service/auth/dto/request/LoginDto.java index 7f3cd95e..427cdef3 100644 --- a/src/main/java/hous/server/service/auth/dto/request/LoginDto.java +++ b/src/main/java/hous/server/service/auth/dto/request/LoginDto.java @@ -1,13 +1,13 @@ package hous.server.service.auth.dto.request; import hous.server.domain.user.UserSocialType; -import hous.server.service.user.dto.request.CreateUserRequestDto; import lombok.*; @ToString @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class LoginDto { private UserSocialType socialType; @@ -17,10 +17,10 @@ public class LoginDto { private String fcmToken; public static LoginDto of(UserSocialType socialType, String token, String fcmToken) { - return new LoginDto(socialType, token, fcmToken); - } - - public CreateUserRequestDto toCreateUserDto(String socialId) { - return CreateUserRequestDto.of(socialId, socialType, fcmToken); + return LoginDto.builder() + .socialType(socialType) + .token(token) + .fcmToken(fcmToken) + .build(); } } diff --git a/src/main/java/hous/server/service/auth/dto/request/SignUpDto.java b/src/main/java/hous/server/service/auth/dto/request/SignUpDto.java new file mode 100644 index 00000000..bb0debf9 --- /dev/null +++ b/src/main/java/hous/server/service/auth/dto/request/SignUpDto.java @@ -0,0 +1,44 @@ +package hous.server.service.auth.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.user.UserSocialType; +import hous.server.service.user.dto.request.CreateUserRequestDto; +import lombok.*; + +import java.time.LocalDate; + +@ToString +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class SignUpDto { + + private UserSocialType socialType; + private String token; + private String fcmToken; + private String nickname; + private LocalDate birthday; + private Boolean isPublic; + + @JsonProperty("isPublic") + public Boolean isPublic() { + return isPublic; + } + + public static SignUpDto of(UserSocialType socialType, String token, String fcmToken, + String nickname, LocalDate birthday, Boolean isPublic) { + return SignUpDto.builder() + .socialType(socialType) + .token(token) + .fcmToken(fcmToken) + .nickname(nickname) + .birthday(birthday) + .isPublic(isPublic) + .build(); + } + + public CreateUserRequestDto toCreateUserDto(String socialId) { + return CreateUserRequestDto.of(socialId, socialType, fcmToken, nickname, birthday, isPublic); + } +} diff --git a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java index b4b76bf0..582bf3f3 100644 --- a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java @@ -6,6 +6,7 @@ import hous.server.external.client.apple.AppleTokenProvider; import hous.server.service.auth.AuthService; import hous.server.service.auth.dto.request.LoginDto; +import hous.server.service.auth.dto.request.SignUpDto; import hous.server.service.user.UserService; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -25,15 +26,18 @@ public class AppleAuthService implements AuthService { private final UserService userService; + @Override + public Long signUp(SignUpDto request) { + String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); + return userService.registerUser(request.toCreateUserDto(socialId)); + } + @Override public Long login(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); - if (user == null) return userService.registerUser(request.toCreateUserDto(socialId)); - else { - UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); - user.updateFcmToken(request.getFcmToken()); - } + UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + user.updateFcmToken(request.getFcmToken()); return user.getId(); } } diff --git a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java index fbe89e36..1ce808d5 100644 --- a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java @@ -8,6 +8,7 @@ import hous.server.external.client.kakao.dto.response.KakaoProfileResponse; import hous.server.service.auth.AuthService; import hous.server.service.auth.dto.request.LoginDto; +import hous.server.service.auth.dto.request.SignUpDto; import hous.server.service.user.UserService; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -27,15 +28,18 @@ public class KakaoAuthService implements AuthService { private final UserService userService; + @Override + public Long signUp(SignUpDto request) { + KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); + return userService.registerUser(request.toCreateUserDto(response.getId())); + } + @Override public Long login(LoginDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); - if (user == null) return userService.registerUser(request.toCreateUserDto(response.getId())); - else { - UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); - user.updateFcmToken(request.getFcmToken()); - } + UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + user.updateFcmToken(request.getFcmToken()); return user.getId(); } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 9f0bc0d4..97b3f74c 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -7,13 +7,11 @@ import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.common.RedisKey; -import hous.server.domain.notification.repository.NotificationRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; -import hous.server.domain.room.repository.ParticipateRepository; import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; @@ -57,9 +55,7 @@ public class UserService { private final TakeRepository takeRepository; private final DoneRepository doneRepository; private final TodoRepository todoRepository; - private final ParticipateRepository participateRepository; private final RoomRepository roomRepository; - private final NotificationRepository notificationRepository; private final BadgeService badgeService; @@ -71,7 +67,10 @@ public Long registerUser(CreateUserRequestDto request) { Onboarding onboarding = onboardingRepository.save(Onboarding.newInstance( user, personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), - testScoreRepository.save(TestScore.newInstance()))); + testScoreRepository.save(TestScore.newInstance()), + request.getNickname(), + request.getBirthday(), + request.getIsPublic())); UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); user.updateFcmToken(request.getFcmToken()); user.setOnboarding(onboarding); diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 97434244..ff040cc1 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -26,7 +26,11 @@ static void validateNotExistsUser(UserRepository userRepository, String socialId } public static User findUserBySocialIdAndSocialType(UserRepository userRepository, String socialId, UserSocialType socialType) { - return userRepository.findUserBySocialIdAndSocialType(socialId, socialType); + User user = userRepository.findUserBySocialIdAndSocialType(socialId, socialType); + if (user == null) { + throw new NotFoundException(String.format("존재하지 않는 유저 (%s) (%s) 입니다", socialType, socialId), NOT_FOUND_USER_EXCEPTION); + } + return user; } public static User findUserById(UserRepository userRepository, Long userId) { diff --git a/src/main/java/hous/server/service/user/dto/request/CreateUserRequestDto.java b/src/main/java/hous/server/service/user/dto/request/CreateUserRequestDto.java index 28baa9e4..88481586 100644 --- a/src/main/java/hous/server/service/user/dto/request/CreateUserRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/CreateUserRequestDto.java @@ -1,21 +1,39 @@ package hous.server.service.user.dto.request; +import com.fasterxml.jackson.annotation.JsonProperty; import hous.server.domain.user.UserSocialType; import lombok.*; +import java.time.LocalDate; + @ToString @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) public class CreateUserRequestDto { private String socialId; - private UserSocialType socialType; - private String fcmToken; + private String nickname; + private LocalDate birthday; + private Boolean isPublic; + + @JsonProperty("isPublic") + public Boolean isPublic() { + return isPublic; + } - public static CreateUserRequestDto of(String socialId, UserSocialType socialType, String fcmToken) { - return new CreateUserRequestDto(socialId, socialType, fcmToken); + public static CreateUserRequestDto of(String socialId, UserSocialType socialType, String fcmToken, + String nickname, LocalDate birthday, Boolean isPublic) { + return CreateUserRequestDto.builder() + .socialId(socialId) + .socialType(socialType) + .fcmToken(fcmToken) + .nickname(nickname) + .birthday(birthday) + .isPublic(isPublic) + .build(); } } diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java index 35374d34..4261f785 100644 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java @@ -20,7 +20,7 @@ public class SetOnboardingInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") @NotBlank(message = "{onboarding.nickname.notBlank}") - @Size(min = 1, max = 5, message = "{onboarding.nickname.max}") + @Size(min = 1, max = 3, message = "{onboarding.nickname.max}") private String nickname; @ApiModelProperty(value = "생년월일", example = "1999-03-04") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index b73f2287..0e79892c 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -8,7 +8,7 @@ user.socialId.notBlank=\uC720\uC800\uC758 socialId \uB97C \uC785\uB825\uD574\uC8 user.socialType.notNull=\uC720\uC800\uC758 socialType \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.name.notBlank=\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.nickname.max=\uB2C9\uB124\uC784\uC740 5 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.nickname.max=\uB2C9\uB124\uC784\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.isPublic.notNull=\uC0DD\uB144\uC6D4\uC77C \uACF5\uAC1C \uC5EC\uBD80\uB97C \uCCB4\uD06C\uD574\uC8FC\uC138\uC694. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. From d0aff6350bd64c43b78c0d89e537664c88694e9b Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 28 Sep 2022 19:10:20 +0900 Subject: [PATCH 181/301] =?UTF-8?q?#137=20[remove]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20api=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 --- .../user/UserRetrieveController.java | 20 ++++------------ .../service/user/UserRetrieveService.java | 11 ++++----- .../response/CheckOnboardingInfoResponse.java | 24 ------------------- 4 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 3a8da57b..c748eab6 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -18,9 +18,6 @@ public enum SuccessCode { LOGIN_SUCCESS(OK, "로그인 성공입니다."), REISSUE_TOKEN_SUCCESS(OK, "토큰 갱신 성공입니다."), - // 온보딩 - CHECK_ONBOARDING_SUCCESS(OK, "온보딩 등록여부 조회 성공입니다."), - // 방 GET_ROOM_SUCCESS(OK, "참가중인 방 조회 성공입니다."), GET_ROOM_INFO_SUCCESS(OK, "참가하려는 방 정보 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 949eefd3..0252a115 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -9,7 +9,10 @@ import hous.server.service.notification.NotificationRetrieveService; import hous.server.service.notification.dto.response.NotificationsInfoResponse; import hous.server.service.user.UserRetrieveService; -import hous.server.service.user.dto.response.*; +import hous.server.service.user.dto.response.MyBadgeInfoResponse; +import hous.server.service.user.dto.response.PersonalityInfoResponse; +import hous.server.service.user.dto.response.PersonalityTestInfoResponse; +import hous.server.service.user.dto.response.UserInfoResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -27,21 +30,6 @@ public class UserRetrieveController { private final UserRetrieveService userRetrieveService; private final NotificationRetrieveService notificationRetrieveService; - @ApiOperation( - value = "[인증] 온보딩 페이지 - 나의 온보딩 정보 등록여부를 확인합니다." - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "온보딩 등록여부 조회 성공입니다."), - @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), - @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) - }) - @Auth - @GetMapping("/user/onboarding/check") - public ResponseEntity checkMyOnboardingInfo(@ApiIgnore @UserId Long userId) { - return SuccessResponse.success(SuccessCode.CHECK_ONBOARDING_SUCCESS, userRetrieveService.checkMyOnboardingInfo(userId)); - } - @ApiOperation( value = "[인증] 마이 페이지(프로필 뷰) - 나의 프로필 정보를 확인합니다.", notes = "성공 시, 생년월일 공개 여부(birthdayPublic) false 일 경우, 생년월일(birthday)은 null 입니다.\n" + diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index b3b35a8c..e60447a6 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -16,7 +16,10 @@ import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; -import hous.server.service.user.dto.response.*; +import hous.server.service.user.dto.response.MyBadgeInfoResponse; +import hous.server.service.user.dto.response.PersonalityInfoResponse; +import hous.server.service.user.dto.response.PersonalityTestInfoResponse; +import hous.server.service.user.dto.response.UserInfoResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,12 +39,6 @@ public class UserRetrieveService { private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; - public CheckOnboardingInfoResponse checkMyOnboardingInfo(Long userId) { - User user = UserServiceUtils.findUserById(userRepository, userId); - Onboarding onboarding = user.getOnboarding(); - return !onboarding.isChecked() ? CheckOnboardingInfoResponse.of(false) : CheckOnboardingInfoResponse.of(true); - } - public UserInfoResponse getUserInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); RoomServiceUtils.findParticipatingRoom(user); diff --git a/src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java deleted file mode 100644 index 138648a2..00000000 --- a/src/main/java/hous/server/service/user/dto/response/CheckOnboardingInfoResponse.java +++ /dev/null @@ -1,24 +0,0 @@ -package hous.server.service.user.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.*; - -@ToString -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@Builder(access = AccessLevel.PRIVATE) -public class CheckOnboardingInfoResponse { - - private boolean isChecked; - - @JsonProperty("isChecked") - public boolean isChecked() { - return isChecked; - } - - public static CheckOnboardingInfoResponse of(boolean isChecked) { - return CheckOnboardingInfoResponse.builder() - .isChecked(isChecked) - .build(); - } -} From e3515c5e0c16b68215fbc323536763af7b23cac6 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 28 Sep 2022 19:14:22 +0900 Subject: [PATCH 182/301] =?UTF-8?q?#137=20[fix]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=B9=BC=EB=9F=BC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/user/Onboarding.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index ef1cac5b..287c42f9 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -46,9 +46,6 @@ public class Onboarding extends AuditingTimeEntity { @Column(length = 30) private String job; - @Column(nullable = false) - private boolean isChecked; - @Column(nullable = false) private boolean isPublic; @@ -76,7 +73,6 @@ public static Onboarding newInstance(User user, Personality personality, TestSco String nickname, LocalDate birthday, boolean isPublic) { return Onboarding.builder() .user(user) - .isChecked(false) .personality(personality) .testScore(testScore) .nickname(nickname) @@ -89,7 +85,6 @@ public void setOnboarding(String nickname, LocalDate birthday, boolean isPublic) this.nickname = nickname; this.birthday = birthday; this.isPublic = isPublic; - this.isChecked = true; } public void setRepresent(Represent represent) { From 70ad78317cce3de210b503f27683ebf8e2a1e5f2 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 28 Sep 2022 19:18:36 +0900 Subject: [PATCH 183/301] =?UTF-8?q?#137=20[remove]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20api=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 33 +--------------- .../hous/server/domain/user/Onboarding.java | 6 --- .../hous/server/service/user/UserService.java | 11 ++---- .../request/SetOnboardingInfoRequestDto.java | 39 ------------------- .../dto/request/UpdateUserInfoRequestDto.java | 25 +++++++++++- 5 files changed, 29 insertions(+), 85 deletions(-) delete mode 100644 src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index c1dcdfc5..bb2e92a5 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -5,7 +5,6 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.user.UserService; -import hous.server.service.user.dto.request.SetOnboardingInfoRequestDto; import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; @@ -26,35 +25,6 @@ public class UserController { private final UserService userService; - @ApiOperation( - value = "[인증] 온보딩 페이지 - 나의 온보딩 정보를 설정합니다.", - notes = "닉네임, 생년월일을 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." - ) - @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), - @ApiResponse( - code = 400, - message = "1. 닉네임을 입력해주세요. (nickname)\n" - + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" - + "3. 생년월일을 입력해주세요. (birthday)\n" - + "4. 생년월일을 공개 여부를 체크해주세요. (isPublic)", - response = ErrorResponse.class), - @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, - message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 같은 방에 참가하고 있지 않습니다.", - response = ErrorResponse.class), - @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) - }) - @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) - @PostMapping("/user/onboarding") - public ResponseEntity setOnboardingInfo( - @Valid @RequestBody SetOnboardingInfoRequestDto request, @ApiIgnore @UserId Long userId) { - userService.setOnboardingInfo(request, userId); - return SuccessResponse.NO_CONTENT; - } - @ApiOperation( value = "[인증] 마이 페이지(Profile 뷰) - 나의 프로필 정보를 수정합니다.", notes = "프로필 정보를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." @@ -84,8 +54,7 @@ public ResponseEntity setOnboardingInfo( @Auth @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/user") - public ResponseEntity updateUserInfo( - @Valid @RequestBody UpdateUserInfoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity updateUserInfo(@Valid @RequestBody UpdateUserInfoRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserInfo(request, userId); return SuccessResponse.NO_CONTENT; } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 287c42f9..70e10ced 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -81,12 +81,6 @@ public static Onboarding newInstance(User user, Personality personality, TestSco .build(); } - public void setOnboarding(String nickname, LocalDate birthday, boolean isPublic) { - this.nickname = nickname; - this.birthday = birthday; - this.isPublic = isPublic; - } - public void setRepresent(Represent represent) { this.represent = represent; } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 97b3f74c..41b1a1cb 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -29,7 +29,10 @@ import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.TodoServiceUtils; -import hous.server.service.user.dto.request.*; +import hous.server.service.user.dto.request.CreateUserRequestDto; +import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; +import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; +import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -77,12 +80,6 @@ public Long registerUser(CreateUserRequestDto request) { return user.getId(); } - public void setOnboardingInfo(SetOnboardingInfoRequestDto request, Long userId) { - User user = UserServiceUtils.findUserById(userRepository, userId); - Onboarding onboarding = user.getOnboarding(); - onboarding.setOnboarding(request.getNickname(), request.getBirthday(), request.isPublic()); - } - public void updateUserInfo(UpdateUserInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); RoomServiceUtils.findParticipatingRoom(user); diff --git a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java deleted file mode 100644 index 4261f785..00000000 --- a/src/main/java/hous/server/service/user/dto/request/SetOnboardingInfoRequestDto.java +++ /dev/null @@ -1,39 +0,0 @@ -package hous.server.service.user.dto.request; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.annotations.ApiModelProperty; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import java.time.LocalDate; - -@ToString -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class SetOnboardingInfoRequestDto { - - @ApiModelProperty(value = "닉네임", example = "혜조니") - @NotBlank(message = "{onboarding.nickname.notBlank}") - @Size(min = 1, max = 3, message = "{onboarding.nickname.max}") - private String nickname; - - @ApiModelProperty(value = "생년월일", example = "1999-03-04") - @NotNull(message = "{onboarding.birthday.notNull}") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") - private LocalDate birthday; - - @ApiModelProperty(value = "생년월일 공개 여부", example = "true") - @NotNull(message = "{onboarding.isPublic.notNull}") - private Boolean isPublic; - - @JsonProperty("isPublic") - public Boolean isPublic() { - return isPublic; - } -} diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java index 56d2cca3..6aca67db 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java @@ -1,6 +1,8 @@ package hous.server.service.user.dto.request; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -8,12 +10,28 @@ import lombok.ToString; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import java.time.LocalDate; @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateUserInfoRequestDto extends SetOnboardingInfoRequestDto { +public class UpdateUserInfoRequestDto { + + @ApiModelProperty(value = "닉네임", example = "혜조니") + @NotBlank(message = "{onboarding.nickname.notBlank}") + @Size(min = 1, max = 3, message = "{onboarding.nickname.max}") + private String nickname; + + @ApiModelProperty(value = "생년월일", example = "1999-03-04") + @NotNull(message = "{onboarding.birthday.notNull}") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") + private LocalDate birthday; + + @ApiModelProperty(value = "생년월일 공개 여부", example = "true") + @NotNull(message = "{onboarding.isPublic.notNull}") + private Boolean isPublic; @ApiModelProperty(value = "MBTI", example = "CUTE") @NotBlank(message = "{user.mbti.notBlank}") @@ -29,4 +47,9 @@ public class UpdateUserInfoRequestDto extends SetOnboardingInfoRequestDto { @NotBlank(message = "{user.introduction.notBlank}") @Size(min = 1, max = 40, message = "{user.introduction.max}") private String introduction; + + @JsonProperty("isPublic") + public Boolean isPublic() { + return isPublic; + } } From c69358cd064bfc6ee5fa1bb348316e05a1eb131d Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 28 Sep 2022 19:21:10 +0900 Subject: [PATCH 184/301] =?UTF-8?q?#137=20[rename]=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/user/Onboarding.java | 6 +++--- src/main/java/hous/server/service/user/UserService.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 70e10ced..a61bb358 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -81,11 +81,11 @@ public static Onboarding newInstance(User user, Personality personality, TestSco .build(); } - public void setRepresent(Represent represent) { + public void updateRepresent(Represent represent) { this.represent = represent; } - public void setPersonality(Personality personality) { + public void updatePersonality(Personality personality) { this.personality = personality; } @@ -105,7 +105,7 @@ public void deleteParticipate(Participate participate) { this.participates.remove(participate); } - public void setUserInfo(UpdateUserInfoRequestDto request) { + public void updateUserInfo(UpdateUserInfoRequestDto request) { this.nickname = request.getNickname(); this.isPublic = request.isPublic(); this.birthday = request.getBirthday(); diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 41b1a1cb..8e212906 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -84,7 +84,7 @@ public void updateUserInfo(UpdateUserInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); RoomServiceUtils.findParticipatingRoom(user); Onboarding onboarding = user.getOnboarding(); - onboarding.setUserInfo(request); + onboarding.updateUserInfo(request); } public void updateUserPushSetting(UpdatePushSettingRequestDto request, Long userId) { @@ -101,7 +101,7 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) TestScore testScore = me.getTestScore(); testScore.updateScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); - me.setPersonality(personality); + me.updatePersonality(personality); badgeService.acquireBadge(user, BadgeInfo.I_AM_SUCH_A_PERSON); if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.I_DONT_EVEN_KNOW_ME, me)) { String personalityTestCountString = (String) redisTemplate.opsForValue().get(RedisKey.PERSONALITY_TEST_COUNT + userId); @@ -135,7 +135,7 @@ public void updateRepresentBadge(Long badgeId, Long userId) { Badge badge = BadgeServiceUtils.findBadgeById(badgeRepository, badgeId); BadgeServiceUtils.validateExistsByOnboardingAndBadge(acquireRepository, me, badge); Represent represent = representRepository.save(Represent.newInstance(me, badge)); - me.setRepresent(represent); + me.updateRepresent(represent); } public void deleteUser(Long userId) { From c9ba1fb0282f5a793d0462b5cd333a0cca0c3c23 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 29 Sep 2022 13:18:57 +0900 Subject: [PATCH 185/301] =?UTF-8?q?#141=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20api=20=EC=97=AC=EB=9F=AC=EA=B0=9C=EC=9D=98?= =?UTF-8?q?=20=EA=B7=9C=EC=B9=99=20=EC=83=9D=EC=84=B1=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/common/exception/ErrorCode.java | 2 ++ .../server/controller/rule/RuleController.java | 9 ++++++--- src/main/java/hous/server/domain/room/Room.java | 6 +++--- .../notification/NotificationService.java | 8 +++++--- .../hous/server/service/rule/RuleService.java | 17 ++++++++++++----- .../server/service/rule/RuleServiceUtils.java | 16 +++++++++++++--- .../rule/dto/request/CreateRuleRequestDto.java | 12 ++++++------ .../rule/dto/request/ModifyRuleReqeustDto.java | 2 +- .../resources/messages/validation.properties | 2 -- 9 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index dd84161e..f1c262a4 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -20,6 +20,8 @@ public enum ErrorCode { VALIDATION_SOCIAL_TYPE_EXCEPTION(BAD_REQUEST, "잘못된 소셜 프로바이더 입니다."), VALIDATION_SORT_TYPE_EXCEPTION(BAD_REQUEST, "허용하지 않는 정렬기준을 입력했습니다."), VALIDATION_STATUS_EXCEPTION(BAD_REQUEST, "잘못된 상태로 요청했습니다."), + VALIDATION_RULE_MAX_LENGTH_EXCEPTION(BAD_REQUEST, "규칙은 20 글자 이내로 입력해주세요."), + VALIDATION_RULE_MIN_LENGTH_EXCEPTION(BAD_REQUEST, "규칙 내용을 입력해주세요."), /** * 401 UnAuthorized diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 0e062d9a..89c566b5 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -27,16 +27,19 @@ public class RuleController { @ApiOperation( value = "[인증] 규칙 페이지 - 방의 규칙을 생성합니다.", - notes = "성공시 status code = 204, 빈 response body로 보냅니다." + notes = "성공시 status code = 204, 빈 response body로 보냅니다.\n" + + "생성할 규칙을 resquest dto에 리스트 형태로 담아주세요." ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), @ApiResponse( code = 400, - message = "1. 규칙 내용을 입력해주세요. (name)\n" - + "2. 규칙은 20 글자 이내로 입력해주세요. (name)", + message = "1. 규칙 내용을 입력해주세요.\n" + + "2. 규칙은 20 글자 이내로 입력해주세요.\n" + + "3. 규칙 id 리스트는 빈 값을 보낼 수 없습니다. (ruleNames)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "rule 은 30개를 초과할 수 없습니다.", response = ErrorResponse.class), @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index 79d09467..d3fe8f4a 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -74,9 +74,9 @@ public void deleteParticipate(Participate participate) { this.participantsCnt -= 1; } - public void addRule(Rule rule) { - this.rules.add(rule); - this.rulesCnt += 1; + public void addRules(List rules) { + this.rules.addAll(rules); + this.rulesCnt += rules.size(); } public void deleteRule(Rule rule) { diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index 892b3579..c0c390f7 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -60,9 +60,11 @@ public void sendRemindTodoNotification(User to, List todos, boolean isTake } } - public void sendNewRuleNotification(User to, Rule rule) { - Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); - to.getOnboarding().addNotification(notification); + public void sendNewRuleNotification(User to, List rules) { + rules.stream().forEach(rule -> { + Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.RULE, newRuleNotification(rule), false)); + to.getOnboarding().addNotification(notification); + }); if (to.getSetting().isPushNotification() && to.getSetting().getRulesPushStatus() == PushStatus.ON) { firebaseCloudMessageService.sendMessageTo(to, PushMessage.NEW_RULE.getTitle(), PushMessage.NEW_RULE.getBody()); } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 5b3a0e14..e9e2e189 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -24,6 +24,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; @RequiredArgsConstructor @Service @@ -44,10 +46,15 @@ public void createRule(CreateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding me = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); - RuleServiceUtils.validateRuleCounts(room); - int ruleIdx = RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room); - Rule rule = ruleRepository.save(Rule.newInstance(room, request.getName(), ruleIdx + 1)); - room.addRule(rule); + RuleServiceUtils.validateRuleCounts(room, request.getRuleNames().size()); + AtomicInteger ruleIdx = new AtomicInteger(RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room)); + List rules = request.getRuleNames().stream() + .map(ruleName -> { + RuleServiceUtils.validateRuleName(room, ruleName); + return ruleRepository.save(Rule.newInstance(room, ruleName, ruleIdx.addAndGet(1))); + }) + .collect(Collectors.toList()); + room.addRules(rules); badgeService.acquireBadge(user, BadgeInfo.LETS_BUILD_A_POLE); if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.OUR_HOUSE_PILLAR_HOMIE, me)) { String createRuleCountString = (String) redisTemplate.opsForValue().get(RedisKey.CREATE_RULE_COUNT + userId); @@ -63,7 +70,7 @@ public void createRule(CreateRuleRequestDto request, Long userId) { } } List usersExceptMe = RoomServiceUtils.findParticipatingUsersExceptMe(room, user); - usersExceptMe.forEach(userExceptMe -> notificationService.sendNewRuleNotification(userExceptMe, rule)); + usersExceptMe.forEach(userExceptMe -> notificationService.sendNewRuleNotification(userExceptMe, rules)); } public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index eee1abe3..f2f15ed5 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -2,6 +2,7 @@ import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; +import hous.server.common.exception.ValidationException; import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; @@ -20,9 +21,18 @@ public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Room room) return rule.getIdx(); } - public static void validateRuleCounts(Room room) { - if (room.getRulesCnt() >= 30) { - throw new ForbiddenException(String.format("방 (%s) 의 rule 는 30개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_RULE_COUNT_EXCEPTION); + public static void validateRuleName(Room room, String ruleName) { + if (ruleName.length() <= 0) { + throw new ValidationException(String.format("방 (%s) 의 rule 은 빈 값이 될 수 없습니다.", room.getId()), VALIDATION_RULE_MIN_LENGTH_EXCEPTION); + } + if (ruleName.length() > 20) { + throw new ValidationException(String.format("방 (%s) 의 rule 의 최대 길이는 20 글자 이내만 가능합니다.", room.getId()), VALIDATION_RULE_MAX_LENGTH_EXCEPTION); + } + } + + public static void validateRuleCounts(Room room, int requestRuleCnt) { + if (room.getRulesCnt() + requestRuleCnt >= 30) { + throw new ForbiddenException(String.format("방 (%s) 의 rule 는 30 개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_RULE_COUNT_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java index a1a90983..945f7483 100644 --- a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java @@ -1,20 +1,20 @@ package hous.server.service.rule.dto.request; import io.swagger.annotations.ApiModelProperty; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; +import javax.validation.constraints.Size; +import java.util.List; + @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CreateRuleRequestDto { - @ApiModelProperty(value = "규칙 내용", example = "우리집 대장은 김또순") - @NotBlank(message = "{rule.name.notBlank") - @Size(max = 20, message = "{rule.name.max}") - private String name; + @ApiModelProperty(value = "규칙 내용 배열", example = "[\"우리집 대장은 김또순\", \"우리집 대장은 혜조니\", \"우리집 대장은 혁주니\", ...]") + @Size(min = 1, message = "{rule.list.min}") + private List ruleNames; } diff --git a/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java b/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java index b7fad506..f90e289a 100644 --- a/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java @@ -16,5 +16,5 @@ public class ModifyRuleReqeustDto { @ApiModelProperty(value = "규칙 id 배열", example = "[12, 13, 14, ...]") @Size(min = 1, message = "{rule.list.min}") - List rulesIdList; + private List rulesIdList; } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 0e79892c..ab9bd03c 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -19,8 +19,6 @@ todo.isPushNotification.notNull=todo \uC758 \uD478\uC26C \uC54C\uB9BC \uC5EC\uBD todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -rule.name.notBlank=\uADDC\uCE59 \uB0B4\uC6A9\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 id \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uAC12\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. user.mbti.notBlank=mbti \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.mbti.max=mbti \uB294 4 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 57a77134b926c93e40075d894953d5a92c857e65 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 28 Sep 2022 14:04:43 +0900 Subject: [PATCH 186/301] =?UTF-8?q?#126=20[chore]=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 1 + .github/workflows/pr-check.yml | 1 + .gitignore | 3 +++ build.gradle | 2 +- scripts/deploy.sh | 2 +- src/main/resources/console-appender.xml | 7 ++++++ src/main/resources/file-error-appender.xml | 21 +++++++++++++++++ src/main/resources/file-info-appender.xml | 21 +++++++++++++++++ src/main/resources/file-warn-appender.xml | 21 +++++++++++++++++ src/main/resources/logback-spring.xml | 27 ++++++++++++++++++++++ 10 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/console-appender.xml create mode 100644 src/main/resources/file-error-appender.xml create mode 100644 src/main/resources/file-info-appender.xml create mode 100644 src/main/resources/file-warn-appender.xml create mode 100644 src/main/resources/logback-spring.xml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3bd7316c..7e56a0f5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,6 +41,7 @@ jobs: echo server.port=$PORT >> application.properties echo server.servlet.encoding.charset=UTF-8 >> application.properties echo server.servlet.encoding.force=true >> application.properties + echo spring.profiles.default=prod >> application.properties echo spring.servlet.multipart.max-file-size=10MB >> application.properties echo spring.servlet.multipart.max-request-size=10MB >> application.properties echo logging.level.org.hibernate.type.descriptor.sql=trace >> application.properties diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index ca750fe5..a13f8be8 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -41,6 +41,7 @@ jobs: echo server.port=$PORT >> application.properties echo server.servlet.encoding.charset=UTF-8 >> application.properties echo server.servlet.encoding.force=true >> application.properties + echo spring.profiles.default=prod >> application.properties echo spring.servlet.multipart.max-file-size=10MB >> application.properties echo spring.servlet.multipart.max-request-size=10MB >> application.properties echo logging.level.org.hibernate.type.descriptor.sql=trace >> application.properties diff --git a/.gitignore b/.gitignore index b3dce725..476076fc 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ application-prod.yml application-aws.yml application-jwt.yml application-firebase.yml + +### log 파일 ### +logs diff --git a/build.gradle b/build.gradle index efec2b6c..371bb985 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'hous' -version = '0.0.1-SNAPSHOT' +version = '1.0.0-SNAPSHOT' sourceCompatibility = '11' configurations { diff --git a/scripts/deploy.sh b/scripts/deploy.sh index a5a6caeb..b2ff9207 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -22,4 +22,4 @@ fi DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME echo "> DEPLOY_JAR 배포" >> /home/ubuntu/hous/deploy.log -nohup java -jar $DEPLOY_JAR >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & +java -jar $DEPLOY_JAR & diff --git a/src/main/resources/console-appender.xml b/src/main/resources/console-appender.xml new file mode 100644 index 00000000..48ec4fcb --- /dev/null +++ b/src/main/resources/console-appender.xml @@ -0,0 +1,7 @@ + + + + ${LOG_PATTERN} + + + diff --git a/src/main/resources/file-error-appender.xml b/src/main/resources/file-error-appender.xml new file mode 100644 index 00000000..670729a8 --- /dev/null +++ b/src/main/resources/file-error-appender.xml @@ -0,0 +1,21 @@ + + + ./logs/error/error.log + + ERROR + ACCEPT + DENY + + + ${LOG_PATTERN} + + + + + ./logs/error/error-%d{yyyy-MM-dd}.log + + 30 + 3GB + + + diff --git a/src/main/resources/file-info-appender.xml b/src/main/resources/file-info-appender.xml new file mode 100644 index 00000000..7149cb33 --- /dev/null +++ b/src/main/resources/file-info-appender.xml @@ -0,0 +1,21 @@ + + + ./logs/info/info.log + + INFO + ACCEPT + DENY + + + ${LOG_PATTERN} + + + + + ./logs/info/info-%d{yyyy-MM-dd}.log + + 30 + 3GB + + + diff --git a/src/main/resources/file-warn-appender.xml b/src/main/resources/file-warn-appender.xml new file mode 100644 index 00000000..ab22ba3f --- /dev/null +++ b/src/main/resources/file-warn-appender.xml @@ -0,0 +1,21 @@ + + + ./logs/warn/warn.log + + WARN + ACCEPT + DENY + + + ${LOG_PATTERN} + + + + + ./logs/warn/warn-%d{yyyy-MM-dd}.log + + 30 + 3GB + + + diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..beca3c1f --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From bd125a9d9fa412f5a35d2d9a46a1da9d6398ac20 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 29 Sep 2022 16:50:44 +0900 Subject: [PATCH 187/301] =?UTF-8?q?#141=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/controller/rule/RuleController.java | 10 +++++----- .../hous/server/service/rule/RuleServiceUtils.java | 6 +++--- src/main/resources/messages/validation.properties | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 89c566b5..de749b68 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -36,7 +36,7 @@ public class RuleController { code = 400, message = "1. 규칙 내용을 입력해주세요.\n" + "2. 규칙은 20 글자 이내로 입력해주세요.\n" - + "3. 규칙 id 리스트는 빈 값을 보낼 수 없습니다. (ruleNames)", + + "3. 규칙 리스트는 빈 배열을 보낼 수 없습니다. (ruleNames)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 403, message = "rule 은 30개를 초과할 수 없습니다.", response = ErrorResponse.class), @@ -49,7 +49,7 @@ public class RuleController { }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) - @PostMapping("/rule") + @PostMapping("/rules") public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, @ApiIgnore @UserId Long userId) { ruleService.createRule(request, userId); @@ -78,7 +78,7 @@ public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDt }) @Auth @ResponseStatus(HttpStatus.NO_CONTENT) - @PostMapping("/rule/{ruleId}") + @PutMapping("/rule/{ruleId}") public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") @PathVariable Long ruleId, @Valid @RequestBody UpdateRuleRequestDto request, @@ -94,7 +94,7 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), - @ApiResponse(code = 400, message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), + @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, @@ -120,7 +120,7 @@ public ResponseEntity updateSortByRules(@Valid @RequestBody ModifyRuleRe ) @ApiResponses(value = { @ApiResponse(code = 204, message = ""), - @ApiResponse(code = 400, message = "규칙 id 리스트는 빈 값을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), + @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index f2f15ed5..f2467a88 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -23,15 +23,15 @@ public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Room room) public static void validateRuleName(Room room, String ruleName) { if (ruleName.length() <= 0) { - throw new ValidationException(String.format("방 (%s) 의 rule 은 빈 값이 될 수 없습니다.", room.getId()), VALIDATION_RULE_MIN_LENGTH_EXCEPTION); + throw new ValidationException(String.format("방 (%s) 의 ruleName (%s) 은 빈 값이 될 수 없습니다.", room.getId(), ruleName), VALIDATION_RULE_MIN_LENGTH_EXCEPTION); } if (ruleName.length() > 20) { - throw new ValidationException(String.format("방 (%s) 의 rule 의 최대 길이는 20 글자 이내만 가능합니다.", room.getId()), VALIDATION_RULE_MAX_LENGTH_EXCEPTION); + throw new ValidationException(String.format("방 (%s) 의 ruleName (%s) 의 최대 길이는 20 글자 이내만 가능합니다.", room.getId(), ruleName), VALIDATION_RULE_MAX_LENGTH_EXCEPTION); } } public static void validateRuleCounts(Room room, int requestRuleCnt) { - if (room.getRulesCnt() + requestRuleCnt >= 30) { + if (room.getRulesCnt() + requestRuleCnt > 30) { throw new ForbiddenException(String.format("방 (%s) 의 rule 는 30 개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_RULE_COUNT_EXCEPTION); } } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index ab9bd03c..070581f5 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -19,7 +19,7 @@ todo.isPushNotification.notNull=todo \uC758 \uD478\uC26C \uC54C\uB9BC \uC5EC\uBD todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -rule.list.min=\uADDC\uCE59 id \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uAC12\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. user.mbti.notBlank=mbti \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.mbti.max=mbti \uB294 4 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. user.job.notBlank=\uC9C1\uC5C5\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. From acde022a45b95a6262e9e1db72d82e083cd3686c Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 29 Sep 2022 17:13:22 +0900 Subject: [PATCH 188/301] =?UTF-8?q?#143=20[fix]=20=EB=B0=B0=EC=A7=80=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94,=20enum=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/domain/badge/Badge.java | 3 +++ .../hous/server/domain/badge/BadgeInfo.java | 26 +++++++++---------- .../dto/response/MyBadgeInfoResponse.java | 2 +- .../user/dto/response/RepresentBadgeInfo.java | 2 +- .../user/dto/response/UserInfoResponse.java | 2 +- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/hous/server/domain/badge/Badge.java b/src/main/java/hous/server/domain/badge/Badge.java index 0367babd..9b7c4a5e 100644 --- a/src/main/java/hous/server/domain/badge/Badge.java +++ b/src/main/java/hous/server/domain/badge/Badge.java @@ -19,4 +19,7 @@ public class Badge extends AuditingTimeEntity { @Column(nullable = false, length = 30) @Enumerated(EnumType.STRING) private BadgeInfo info; + + @Column(nullable = false, length = 300) + private String imageUrl; } diff --git a/src/main/java/hous/server/domain/badge/BadgeInfo.java b/src/main/java/hous/server/domain/badge/BadgeInfo.java index 39dc2bba..2a361aa2 100644 --- a/src/main/java/hous/server/domain/badge/BadgeInfo.java +++ b/src/main/java/hous/server/domain/badge/BadgeInfo.java @@ -9,25 +9,23 @@ @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum BadgeInfo implements EnumModel { - POUNDING_HOUSE("두근두근 하우스", "어서와요\n우리 Hous-에!", "imageUrl"), - I_AM_SUCH_A_PERSON("나 이런 사람이야", "Homie 카드를\n완성한 호미", "imageUrl"), - OUR_HOUSE_HOMIES("우리 집 호미들", "모든 Homie들의\n테스트 참여", "imageUrl"), - I_DONT_EVEN_KNOW_ME("나도 날 모르겠어", "성향 테스트를\n5번 이상 한 호미", "imageUrl"), - HOMIE_IS_BORN("Homie 탄생", "Hous-에서의\n첫 생일", "imageUrl"), - TODO_ONE_STEP("to-do 한 걸음", "to-do 전체보기에서\n첫 to-do 등록", "imageUrl"), - GOOD_JOB("참 잘했어요", "1주 동안 to-do\n모두 완료", "imageUrl"), - SINCERITY_KING_HOMIE("성실왕 호미", "2주 동안\nto-do 모두 완료", "imageUrl"), - TODO_MASTER("to-do 마스터", "3주 동안\nto-do 모두 완료", "imageUrl"), - LETS_BUILD_A_POLE("기둥을 세우자", "우리 집 규칙에서\n집 Rules 등록", "imageUrl"), - OUR_HOUSE_PILLAR_HOMIE("우리 집 기둥 호미", "우리 집 Rules\n5개 이상 등록", "imageUrl"), - FEEDBACK_ONE_STEP("피드백 한 걸음", "좋은 의견을\n호미 나라에 전달", "imageUrl"); + POUNDING_HOUSE("두근두근 하우스", "어서와요\n우리 Hous-에!"), + I_AM_SUCH_A_PERSON("나 이런 사람이야", "Homie 카드를\n완성한 호미"), + OUR_HOUSE_HOMIES("우리 집 호미들", "모든 Homie들의\n테스트 참여"), + I_DONT_EVEN_KNOW_ME("나도 날 모르겠어", "성향 테스트를\n5번 이상 한 호미"), + HOMIE_IS_BORN("Homie 탄생", "Hous-에서의\n첫 생일"), + TODO_ONE_STEP("to-do 한 걸음", "to-do 전체보기에서\n첫 to-do 등록"), + GOOD_JOB("참 잘했어요", "1주 동안 to-do\n모두 완료"), + SINCERITY_KING_HOMIE("성실왕 호미", "2주 동안\nto-do 모두 완료"), + TODO_MASTER("to-do 마스터", "3주 동안\nto-do 모두 완료"), + LETS_BUILD_A_POLE("기둥을 세우자", "우리 집 규칙에서\n집 Rules 등록"), + OUR_HOUSE_PILLAR_HOMIE("우리 집 기둥 호미", "우리 집 Rules\n5개 이상 등록"), + FEEDBACK_ONE_STEP("피드백 한 걸음", "좋은 의견을\n호미 나라에 전달"); private final String value; private final String description; - private final String imageUrl; - @Override public String getKey() { return name(); diff --git a/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java index bca83ba2..ac51a82c 100644 --- a/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java @@ -47,7 +47,7 @@ public static BadgeInfo of(Badge badge, boolean isAcquired) { return BadgeInfo.builder() .badgeId(badge.getId()) .name(badge.getInfo().getValue()) - .imageUrl(badge.getInfo().getImageUrl()) + .imageUrl(badge.getImageUrl()) .isAcquired(isAcquired) .description(badge.getInfo().getDescription()) .build(); diff --git a/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java b/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java index 5634fbfd..683a6f1b 100644 --- a/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java +++ b/src/main/java/hous/server/service/user/dto/response/RepresentBadgeInfo.java @@ -18,7 +18,7 @@ public static RepresentBadgeInfo of(Represent represent) { return RepresentBadgeInfo.builder() .badgeId(represent.getBadge().getId()) .name(represent.getBadge().getInfo().getValue()) - .imageUrl(represent.getBadge().getInfo().getImageUrl()) + .imageUrl(represent.getBadge().getImageUrl()) .build(); } } diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index 87aafac2..339cf61a 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -76,7 +76,7 @@ public static UserInfoResponse of(Onboarding onboarding, Represent represent) { .introduction(onboarding.getIntroduction()) .testScore(TestScoreResponse.of(onboarding.getTestScore())) .representBadge(represent != null ? represent.getBadge().getInfo().getValue() : null) - .representBadgeImage(represent != null ? represent.getBadge().getInfo().getImageUrl() : null) + .representBadgeImage(represent != null ? represent.getBadge().getImageUrl() : null) .build(); } } From 8d912d7af3341456b85e43b7813b1ddb6f2fbf72 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 29 Sep 2022 19:28:43 +0900 Subject: [PATCH 189/301] =?UTF-8?q?#139=20[refactor]=20=EA=B8=B8=EC=9D=B4,?= =?UTF-8?q?=20=ED=81=AC=EA=B8=B0=20=EC=A0=9C=ED=95=9C=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/dto/request/SignUpRequestDto.java | 3 ++- .../hous/server/domain/common/Constraint.java | 18 ++++++++++++++++ .../ParticipateRepositoryCustom.java | 3 --- .../repository/ParticipateRepositoryImpl.java | 8 ------- .../hous/server/service/room/RoomService.java | 2 +- .../server/service/room/RoomServiceUtils.java | 5 +++-- .../dto/request/SetRoomNameRequestDto.java | 3 ++- .../server/service/rule/RuleServiceUtils.java | 7 ++++--- .../dto/request/CreateRuleRequestDto.java | 3 ++- .../dto/request/ModifyRuleReqeustDto.java | 3 ++- .../dto/request/UpdateRuleRequestDto.java | 3 ++- .../server/service/todo/TodoServiceUtils.java | 3 ++- .../todo/dto/request/TodoInfoRequestDto.java | 3 ++- .../request/UpdateTestScoreRequestDto.java | 21 ++++++++++--------- .../dto/request/UpdateUserInfoRequestDto.java | 15 ++++++------- .../resources/messages/validation.properties | 17 +++++++-------- 16 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 src/main/java/hous/server/domain/common/Constraint.java diff --git a/src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java b/src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java index 66144d6a..7d98fa3c 100644 --- a/src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java +++ b/src/main/java/hous/server/controller/auth/dto/request/SignUpRequestDto.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.common.Constraint; import hous.server.domain.user.UserSocialType; import hous.server.service.auth.dto.request.SignUpDto; import io.swagger.annotations.ApiModelProperty; @@ -32,7 +33,7 @@ public class SignUpRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") @NotBlank(message = "{onboarding.nickname.notBlank}") - @Size(min = 1, max = 3, message = "{onboarding.nickname.max}") + @Size(max = Constraint.ONBOARDING_NICKNAME_MAX, message = "{onboarding.nickname.max}") private String nickname; @ApiModelProperty(value = "생년월일", example = "1999-03-04") diff --git a/src/main/java/hous/server/domain/common/Constraint.java b/src/main/java/hous/server/domain/common/Constraint.java new file mode 100644 index 00000000..6f1fb292 --- /dev/null +++ b/src/main/java/hous/server/domain/common/Constraint.java @@ -0,0 +1,18 @@ +package hous.server.domain.common; + +public final class Constraint { + + public static final int ONBOARDING_NICKNAME_MAX = 3; + public static final int ONBOARDING_MBTI_MAX = 4; + public static final int ONBOARDING_JOB_MAX = 3; + public static final int ONBOARDING_INTRODUCTION_MAX = 40; + public static final int ONBOARDING_TESTSCORE_MIN = 3; + public static final int ONBOARDING_TESTSCORE_MAX = 9; + public static final int ROOM_NAME_MAX = 8; + public static final int ROOM_PARTICIPATE_MAX = 16; + public static final int TODO_NAME_MAX = 15; + public static final int TODO_COUNT_MAX = 60; + public static final int RULE_NAME_MAX = 20; + public static final int RULE_COUNT_MAX = 30; + public static final int RULE_LIST_MIN = 1; +} diff --git a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java index 7a1a183b..46134d70 100644 --- a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java +++ b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryCustom.java @@ -1,11 +1,8 @@ package hous.server.domain.room.repository; -import hous.server.domain.room.Room; import hous.server.domain.user.Onboarding; public interface ParticipateRepositoryCustom { boolean existsByOnboarding(Onboarding onboarding); - - int findCountsByRoom(Room room); } diff --git a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java index 24e24a0a..bca61de9 100644 --- a/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java +++ b/src/main/java/hous/server/domain/room/repository/ParticipateRepositoryImpl.java @@ -1,7 +1,6 @@ package hous.server.domain.room.repository; import com.querydsl.jpa.impl.JPAQueryFactory; -import hous.server.domain.room.Room; import hous.server.domain.user.Onboarding; import lombok.RequiredArgsConstructor; @@ -19,11 +18,4 @@ public boolean existsByOnboarding(Onboarding onboarding) { .where(participate.onboarding.eq(onboarding)) .fetchFirst() != null; } - - @Override - public int findCountsByRoom(Room room) { - return queryFactory.selectFrom(participate) - .where(participate.room.eq(room)) - .fetch().size(); - } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 8400eb5d..415d81c8 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -61,7 +61,7 @@ public RoomInfoResponse joinRoom(Long roomId, Long userId) { Onboarding me = user.getOnboarding(); RoomServiceUtils.validateNotExistsParticipate(participateRepository, me); Room room = RoomServiceUtils.findRoomById(roomRepository, roomId); - RoomServiceUtils.validateParticipateCounts(participateRepository, room); + RoomServiceUtils.validateParticipateCounts(room); Participate participate = participateRepository.save(Participate.newInstance(me, room)); me.addParticipate(participate); room.addParticipate(participate); diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 0e76d9bb..3b2d747d 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -3,6 +3,7 @@ import hous.server.common.exception.ConflictException; import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; +import hous.server.domain.common.Constraint; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; @@ -35,8 +36,8 @@ public static void validateNotExistsParticipate(ParticipateRepository participat } } - public static void validateParticipateCounts(ParticipateRepository participateRepository, Room room) { - if (participateRepository.findCountsByRoom(room) >= 16) { + public static void validateParticipateCounts(Room room) { + if (room.getParticipantsCnt() >= Constraint.ROOM_PARTICIPATE_MAX) { throw new ForbiddenException(String.format("방 (%s) 의 참가자 는 16명을 초과할 수 없습니다.", room.getId()), FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/room/dto/request/SetRoomNameRequestDto.java b/src/main/java/hous/server/service/room/dto/request/SetRoomNameRequestDto.java index 35d5163f..ffa13560 100644 --- a/src/main/java/hous/server/service/room/dto/request/SetRoomNameRequestDto.java +++ b/src/main/java/hous/server/service/room/dto/request/SetRoomNameRequestDto.java @@ -1,5 +1,6 @@ package hous.server.service.room.dto.request; +import hous.server.domain.common.Constraint; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -16,6 +17,6 @@ public class SetRoomNameRequestDto { @ApiModelProperty(value = "방 이름", example = "러블리더블리") @NotBlank(message = "{room.name.notBlank}") - @Size(max = 8, message = "{room.name.max}") + @Size(max = Constraint.ROOM_NAME_MAX, message = "{room.name.max}") private String name; } diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index f2467a88..e8eb45fa 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -3,6 +3,7 @@ import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; import hous.server.common.exception.ValidationException; +import hous.server.domain.common.Constraint; import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.rule.repository.RuleRepository; @@ -22,16 +23,16 @@ public static int findRuleIdxByRoomId(RuleRepository ruleRepository, Room room) } public static void validateRuleName(Room room, String ruleName) { - if (ruleName.length() <= 0) { + if (ruleName.length() == 0) { throw new ValidationException(String.format("방 (%s) 의 ruleName (%s) 은 빈 값이 될 수 없습니다.", room.getId(), ruleName), VALIDATION_RULE_MIN_LENGTH_EXCEPTION); } - if (ruleName.length() > 20) { + if (ruleName.length() > Constraint.RULE_NAME_MAX) { throw new ValidationException(String.format("방 (%s) 의 ruleName (%s) 의 최대 길이는 20 글자 이내만 가능합니다.", room.getId(), ruleName), VALIDATION_RULE_MAX_LENGTH_EXCEPTION); } } public static void validateRuleCounts(Room room, int requestRuleCnt) { - if (room.getRulesCnt() + requestRuleCnt > 30) { + if (room.getRulesCnt() + requestRuleCnt > Constraint.RULE_COUNT_MAX) { throw new ForbiddenException(String.format("방 (%s) 의 rule 는 30 개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_RULE_COUNT_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java index 945f7483..3f9f2f1b 100644 --- a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java @@ -1,5 +1,6 @@ package hous.server.service.rule.dto.request; +import hous.server.domain.common.Constraint; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -15,6 +16,6 @@ public class CreateRuleRequestDto { @ApiModelProperty(value = "규칙 내용 배열", example = "[\"우리집 대장은 김또순\", \"우리집 대장은 혜조니\", \"우리집 대장은 혁주니\", ...]") - @Size(min = 1, message = "{rule.list.min}") + @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") private List ruleNames; } diff --git a/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java b/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java index f90e289a..b5ec792f 100644 --- a/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java @@ -1,5 +1,6 @@ package hous.server.service.rule.dto.request; +import hous.server.domain.common.Constraint; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -15,6 +16,6 @@ public class ModifyRuleReqeustDto { @ApiModelProperty(value = "규칙 id 배열", example = "[12, 13, 14, ...]") - @Size(min = 1, message = "{rule.list.min}") + @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") private List rulesIdList; } diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java index df754c12..26785301 100644 --- a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java @@ -1,5 +1,6 @@ package hous.server.service.rule.dto.request; +import hous.server.domain.common.Constraint; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -16,6 +17,6 @@ public class UpdateRuleRequestDto { @ApiModelProperty(value = "규칙 내용", example = "우리집 대장은 김또순") @NotBlank(message = "{rule.name.notBlank") - @Size(max = 20, message = "{rule.name.max}") + @Size(max = Constraint.RULE_NAME_MAX, message = "{rule.name.max}") private String name; } diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index da34beb6..b4622888 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -4,6 +4,7 @@ import hous.server.common.exception.NotFoundException; import hous.server.common.exception.ValidationException; import hous.server.common.util.DateUtils; +import hous.server.domain.common.Constraint; import hous.server.domain.room.Room; import hous.server.domain.todo.Done; import hous.server.domain.todo.Todo; @@ -34,7 +35,7 @@ public static Todo findTodoById(TodoRepository todoRepository, Long todoId) { } public static void validateTodoCounts(Room room) { - if (room.getTodosCnt() >= 60) { + if (room.getTodosCnt() >= Constraint.TODO_COUNT_MAX) { throw new ForbiddenException(String.format("방 (%s) 의 todo 는 60개를 초과할 수 없습니다.", room.getId()), FORBIDDEN_TODO_COUNT_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java b/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java index 4b184b74..b7c34902 100644 --- a/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java +++ b/src/main/java/hous/server/service/todo/dto/request/TodoInfoRequestDto.java @@ -1,6 +1,7 @@ package hous.server.service.todo.dto.request; import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.common.Constraint; import hous.server.domain.todo.DayOfWeek; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; @@ -22,7 +23,7 @@ public class TodoInfoRequestDto { @ApiModelProperty(value = "todo 이름", example = "청소기 돌리기") @NotBlank(message = "{todo.name.notBlank}") - @Size(max = 15, message = "{todo.name.max}") + @Size(max = Constraint.TODO_NAME_MAX, message = "{todo.name.max}") private String name; @ApiModelProperty(value = "알림 여부", example = "true") diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java index c4e1761e..1addc704 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdateTestScoreRequestDto.java @@ -1,5 +1,6 @@ package hous.server.service.user.dto.request; +import hous.server.domain.common.Constraint; import io.swagger.annotations.ApiModelProperty; import lombok.*; @@ -13,27 +14,27 @@ public class UpdateTestScoreRequestDto { @ApiModelProperty(value = "빛", example = "4") - @Min(value = 3, message = "{user.testScore.size}") - @Max(value = 9, message = "{user.testScore.size}") + @Min(value = Constraint.ONBOARDING_TESTSCORE_MIN, message = "{onboarding.testScore.size}") + @Max(value = Constraint.ONBOARDING_TESTSCORE_MAX, message = "{onboarding.testScore.size}") private int light; @ApiModelProperty(value = "소음", example = "5") - @Min(value = 3, message = "{user.testScore.size}") - @Max(value = 9, message = "{user.testScore.size}") + @Min(value = Constraint.ONBOARDING_TESTSCORE_MIN, message = "{onboarding.testScore.size}") + @Max(value = Constraint.ONBOARDING_TESTSCORE_MAX, message = "{onboarding.testScore.size}") private int noise; @ApiModelProperty(value = "정리정돈", example = "3") - @Min(value = 3, message = "{user.testScore.size}") - @Max(value = 9, message = "{user.testScore.size}") + @Min(value = Constraint.ONBOARDING_TESTSCORE_MIN, message = "{onboarding.testScore.size}") + @Max(value = Constraint.ONBOARDING_TESTSCORE_MAX, message = "{onboarding.testScore.size}") private int clean; @ApiModelProperty(value = "냄새", example = "4") - @Min(value = 3, message = "{user.testScore.size}") - @Max(value = 9, message = "{user.testScore.size}") + @Min(value = Constraint.ONBOARDING_TESTSCORE_MIN, message = "{onboarding.testScore.size}") + @Max(value = Constraint.ONBOARDING_TESTSCORE_MAX, message = "{onboarding.testScore.size}") private int smell; @ApiModelProperty(value = "내향", example = "5") - @Min(value = 3, message = "{user.testScore.size}") - @Max(value = 9, message = "{user.testScore.size}") + @Min(value = Constraint.ONBOARDING_TESTSCORE_MIN, message = "{onboarding.testScore.size}") + @Max(value = Constraint.ONBOARDING_TESTSCORE_MAX, message = "{onboarding.testScore.size}") private int introversion; } diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java index 6aca67db..592563d7 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.common.Constraint; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -21,7 +22,7 @@ public class UpdateUserInfoRequestDto { @ApiModelProperty(value = "닉네임", example = "혜조니") @NotBlank(message = "{onboarding.nickname.notBlank}") - @Size(min = 1, max = 3, message = "{onboarding.nickname.max}") + @Size(max = Constraint.ONBOARDING_NICKNAME_MAX, message = "{onboarding.nickname.max}") private String nickname; @ApiModelProperty(value = "생년월일", example = "1999-03-04") @@ -34,18 +35,18 @@ public class UpdateUserInfoRequestDto { private Boolean isPublic; @ApiModelProperty(value = "MBTI", example = "CUTE") - @NotBlank(message = "{user.mbti.notBlank}") - @Size(min = 1, max = 4, message = "{user.mbti.max}") + @NotBlank(message = "{onboarding.mbti.notBlank}") + @Size(max = Constraint.ONBOARDING_MBTI_MAX, message = "{onboarding.mbti.max}") private String mbti; @ApiModelProperty(value = "직업", example = "대학생") - @NotBlank(message = "{user.job.notBlank}") - @Size(min = 1, max = 3, message = "{user.job.max}") + @NotBlank(message = "{onboarding.job.notBlank}") + @Size(max = Constraint.ONBOARDING_JOB_MAX, message = "{onboarding.job.max}") private String job; @ApiModelProperty(value = "자기소개", example = "안녕하세요. 저는 혜조니입니다~") - @NotBlank(message = "{user.introduction.notBlank}") - @Size(min = 1, max = 40, message = "{user.introduction.max}") + @NotBlank(message = "{onboarding.introduction.notBlank}") + @Size(max = Constraint.ONBOARDING_INTRODUCTION_MAX, message = "{onboarding.introduction.max}") private String introduction; @JsonProperty("isPublic") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 070581f5..6a10e512 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -1,5 +1,3 @@ -common.size.min=\uC870\uD68C\uD560 \uAC1C\uC218\uB97C {value} \uC774\uC0C1 \uC785\uB825\uD574\uC8FC\uC138\uC694. -common.size.max=\uC870\uD68C\uD560 \uAC1C\uC218\uB97C {value} \uC774\uD558 \uC785\uB825\uD574\uC8FC\uC138\uC694. auth.token.notBlank=access token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. auth.fcmToken.notBlank=fcm token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. auth.accessToken.notBlank=access token \uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. @@ -11,6 +9,13 @@ onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\u onboarding.nickname.max=\uB2C9\uB124\uC784\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.isPublic.notNull=\uC0DD\uB144\uC6D4\uC77C \uACF5\uAC1C \uC5EC\uBD80\uB97C \uCCB4\uD06C\uD574\uC8FC\uC138\uC694. +onboarding.mbti.notBlank=mbti \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.mbti.max=mbti \uB294 4 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.job.notBlank=\uC9C1\uC5C5\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.job.max=\uC9C1\uC5C5\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.introduction.notBlank=\uC790\uAE30\uC18C\uAC1C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.introduction.max=\uC790\uAE30\uC18C\uAC1C\uB294 40 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. +onboarding.testScore.size=\uC131\uD5A5 \uD14C\uC2A4\uD2B8\uC758 \uAC01 \uC131\uD5A5 \uC810\uC218\uB294 \uCD5C\uC18C 3\uC810, \uCD5C\uB300 9\uC810\uC785\uB2C8\uB2E4. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. room.name.max=\uBC29 \uC774\uB984\uC744 8 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. todo.name.notBlank=todo \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. @@ -19,11 +24,5 @@ todo.isPushNotification.notNull=todo \uC758 \uD478\uC26C \uC54C\uB9BC \uC5EC\uBD todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. -user.mbti.notBlank=mbti \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -user.mbti.max=mbti \uB294 4 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -user.job.notBlank=\uC9C1\uC5C5\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. -user.job.max=\uC9C1\uC5C5\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -user.introduction.notBlank=\uC790\uAE30\uC18C\uAC1C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -user.introduction.max=\uC790\uAE30\uC18C\uAC1C\uB294 40 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -user.testScore.size=\uC131\uD5A5 \uD14C\uC2A4\uD2B8\uC758 \uAC01 \uC131\uD5A5 \uC810\uC218\uB294 \uCD5C\uC18C 3\uC810, \uCD5C\uB300 9\uC810\uC785\uB2C8\uB2E4. From e33e754afea10821a8cf58801d55a459ee0b5877 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 30 Sep 2022 14:32:56 +0900 Subject: [PATCH 190/301] =?UTF-8?q?#147=20[fix]=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=9F=AC=20=EA=B4=80=EB=A0=A8=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/scheduler/SchedulerConfig.java | 20 +++++++++++++++ .../scheduler/SchedulerErrorHandler.java | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/main/java/hous/server/config/scheduler/SchedulerConfig.java create mode 100644 src/main/java/hous/server/config/scheduler/SchedulerErrorHandler.java diff --git a/src/main/java/hous/server/config/scheduler/SchedulerConfig.java b/src/main/java/hous/server/config/scheduler/SchedulerConfig.java new file mode 100644 index 00000000..ca7a6112 --- /dev/null +++ b/src/main/java/hous/server/config/scheduler/SchedulerConfig.java @@ -0,0 +1,20 @@ +package hous.server.config.scheduler; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; + +@Configuration +public class SchedulerConfig implements SchedulingConfigurer { + + @Override + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { + ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); + threadPoolTaskScheduler.setPoolSize(10); + threadPoolTaskScheduler.setErrorHandler(new SchedulerErrorHandler()); + threadPoolTaskScheduler.initialize(); + + scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler); + } +} diff --git a/src/main/java/hous/server/config/scheduler/SchedulerErrorHandler.java b/src/main/java/hous/server/config/scheduler/SchedulerErrorHandler.java new file mode 100644 index 00000000..37e71a66 --- /dev/null +++ b/src/main/java/hous/server/config/scheduler/SchedulerErrorHandler.java @@ -0,0 +1,25 @@ +package hous.server.config.scheduler; + +import hous.server.common.exception.HousException; +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.springframework.util.ErrorHandler; + +@Slf4j +public class SchedulerErrorHandler implements ErrorHandler { + + @Override + public void handleError(@NotNull Throwable throwable) { + if (throwable instanceof HousException) { + HousException exception = (HousException) throwable; + if (exception.getStatus() >= 400 && exception.getStatus() < 500) { + log.warn(exception.getMessage(), exception); + } else { + log.error(exception.getMessage(), exception); + } + } else { + Exception exception = (Exception) throwable; + log.error(exception.getMessage(), exception); + } + } +} From 31c827184882a15d24b4ca99d3d904a0d9369ca7 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 3 Oct 2022 15:23:49 +0900 Subject: [PATCH 191/301] =?UTF-8?q?#150=20[fix]=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20204=20->=20200,=20201=20=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/dto/SuccessResponse.java | 4 +- .../server/common/success/SuccessCode.java | 3 ++ .../controller/auth/AuthController.java | 13 +++--- .../controller/room/RoomController.java | 15 +++---- .../controller/rule/RuleController.java | 32 ++++++-------- .../controller/todo/TodoController.java | 33 ++++++-------- .../controller/user/UserController.java | 44 ++++++++----------- 7 files changed, 63 insertions(+), 81 deletions(-) diff --git a/src/main/java/hous/server/common/dto/SuccessResponse.java b/src/main/java/hous/server/common/dto/SuccessResponse.java index cb2912aa..e1fe2788 100644 --- a/src/main/java/hous/server/common/dto/SuccessResponse.java +++ b/src/main/java/hous/server/common/dto/SuccessResponse.java @@ -10,7 +10,9 @@ @AllArgsConstructor(access = AccessLevel.PRIVATE) public class SuccessResponse { - public static final ResponseEntity NO_CONTENT = success(SuccessCode.NO_CONTENT_SUCCESS, ""); + public static final ResponseEntity OK = success(SuccessCode.OK_SUCCESS, null); + public static final ResponseEntity CREATED = success(SuccessCode.CREATED_SUCCESS, null); + public static final ResponseEntity NO_CONTENT = success(SuccessCode.NO_CONTENT_SUCCESS, null); private int status; private boolean success; diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index c748eab6..aa7f2442 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -13,6 +13,8 @@ public enum SuccessCode { /** * 200 OK */ + OK_SUCCESS(OK, "성공입니다."), + // 인증 SIGNUP_SUCCESS(OK, "회원가입 성공입니다."), LOGIN_SUCCESS(OK, "로그인 성공입니다."), @@ -55,6 +57,7 @@ public enum SuccessCode { /** * 201 CREATED */ + CREATED_SUCCESS(CREATED, "생성 성공입니다."), // 방 CREATE_ROOM_SUCCESS(CREATED, "방 생성 성공입니다."), diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 3135a8ef..da8eba16 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -19,9 +19,11 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -121,10 +123,10 @@ public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto @ApiOperation( value = "[인증] 마이 페이지(설정) - 로그아웃을 요청합니다.", - notes = "성공시 status code = 204, 빈 response body로 보냅니다." + notes = "로그아웃 성공시 로그인 페이지로 이동합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, @@ -134,10 +136,9 @@ public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/auth/logout") public ResponseEntity logout(@ApiIgnore @UserId Long userId) { commonAuthService.logout(userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } } diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 47757b39..4aaa23be 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -76,11 +76,10 @@ public ResponseEntity joinRoom(@ApiParam(name = "roomId", valu @ApiOperation( value = "[인증] Hous- 페이지 - 방 별명을 수정합니다.", - notes = "방 별명을 8글자 이내로 설정하여 수정을 요청합니다.\n" + - "성공시 status code = 204, 빈 response body를 보냅니다." + notes = "방 별명을 8글자 이내로 설정하여 수정을 요청합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse( code = 400, message = "1. 방 이름을 입력해주세요. (name)\n" @@ -95,19 +94,18 @@ public ResponseEntity joinRoom(@ApiParam(name = "roomId", valu @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/room/name") public ResponseEntity updateRoomName(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { roomService.updateRoomName(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] 마이 페이지(설정) - 방에서 퇴사합니다.", - notes = "성공시 status code = 204, 빈 response body로 보냅니다." + notes = "퇴사 성공시 방 생성, 입장 페이지로 이동합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, @@ -117,10 +115,9 @@ public ResponseEntity updateRoomName(@Valid @RequestBody SetRoomNameRequ @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/room/leave") public ResponseEntity leaveRoom(@ApiIgnore @UserId Long userId) { roomService.leaveRoom(userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } } diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index de749b68..561d8759 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -27,11 +27,10 @@ public class RuleController { @ApiOperation( value = "[인증] 규칙 페이지 - 방의 규칙을 생성합니다.", - notes = "성공시 status code = 204, 빈 response body로 보냅니다.\n" + - "생성할 규칙을 resquest dto에 리스트 형태로 담아주세요." + notes = "생성할 규칙을 resquest dto에 리스트 형태로 담아주세요." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 201, message = "생성 성공입니다."), @ApiResponse( code = 400, message = "1. 규칙 내용을 입력해주세요.\n" @@ -48,20 +47,20 @@ public class RuleController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) + @ResponseStatus(HttpStatus.CREATED) @PostMapping("/rules") public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, @ApiIgnore @UserId Long userId) { ruleService.createRule(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.CREATED; } @ApiOperation( value = "[인증] 규칙 페이지 - 규칙 1개를 수정합니다.", - notes = "성공시 status code = 204, 빈 response body를 보냅니다." + notes = "규칙 내용 수정을 요청합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse( code = 400, message = "1. 규칙 내용을 입력해주세요. (name)\n" @@ -77,23 +76,21 @@ public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDt @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/rule/{ruleId}") public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") @PathVariable Long ruleId, @Valid @RequestBody UpdateRuleRequestDto request, @ApiIgnore @UserId Long userId) { ruleService.updateRule(request, ruleId, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] 규칙 페이지 - 규칙 여러 개의 정렬을 수정합니다.", - notes = "성공시 status code = 204, 빈 response body를 보냅니다.\n" + - "전체 규칙 id 리스트를 정렬 순서에 따라 resquest dto에 리스트 형태로 담아주세요." + notes = "전체 규칙 id 리스트를 정렬 순서에 따라 resquest dto에 리스트 형태로 담아주세요." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( @@ -105,21 +102,19 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/rules") public ResponseEntity updateSortByRules(@Valid @RequestBody ModifyRuleReqeustDto request, @ApiIgnore @UserId Long userId) { ruleService.updateSortByRule(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] 규칙 페이지 - 규칙 여러 개를 삭제합니다.", - notes = "성공시 status code = 204, 빈 response body를 보냅니다.\n" + - "삭제할 규칙의 id만 resquest dto에 리스트 형태로 담아주세요." + notes = "삭제할 규칙의 id만 resquest dto에 리스트 형태로 담아주세요." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( @@ -131,11 +126,10 @@ public ResponseEntity updateSortByRules(@Valid @RequestBody ModifyRuleRe @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/rules") public ResponseEntity deleteRules(@Valid @RequestBody ModifyRuleReqeustDto request, @ApiIgnore @UserId Long userId) { ruleService.deleteRules(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } } diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index c79982a6..e92ade1a 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -26,11 +26,10 @@ public class TodoController { @ApiOperation( value = "[인증] todo 추가 페이지 - 새로운 todo 를 생성합니다.", - notes = "todo 이름을 15글자 이내로 설정하고 알림 여부, 담당자, 담당 요일을 설정하여 새로운 todo 생성을 요청합니다.\n" + - "성공시 status code = 204, 빈 response body를 보냅니다." + notes = "todo 이름을 15글자 이내로 설정하고 알림 여부, 담당자, 담당 요일을 설정하여 새로운 todo 생성을 요청합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 201, message = "생성 성공입니다."), @ApiResponse( code = 400, message = "1. todo 이름을 입력해주세요. (name)\n" @@ -49,20 +48,19 @@ public class TodoController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) + @ResponseStatus(HttpStatus.CREATED) @PostMapping("/todo") public ResponseEntity createTodo(@Valid @RequestBody TodoInfoRequestDto request, @ApiIgnore @UserId Long userId) { todoService.createTodo(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.CREATED; } @ApiOperation( value = "[인증] todo 수정 페이지 - todo 를 수정합니다.", - notes = "todo 이름을 15글자 이내로 설정하고 알림 여부, 담당자, 담당 요일을 설정하여 todo 수정을 요청합니다.\n" + - "성공시 status code = 204, 빈 response body를 보냅니다." + notes = "todo 이름을 15글자 이내로 설정하고 알림 여부, 담당자, 담당 요일을 설정하여 todo 수정을 요청합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse( code = 400, message = "1. todo 이름을 입력해주세요. (name)\n" @@ -76,23 +74,21 @@ public ResponseEntity createTodo(@Valid @RequestBody TodoInfoRequestDto @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/todo/{todoId}") public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수정할 todo 의 id", required = true, example = "1") @PathVariable Long todoId, @Valid @RequestBody TodoInfoRequestDto request) { todoService.updateTodo(todoId, request); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] todo 메인 페이지 - todo 를 체크합니다.", notes = "체크 요청 (status = true), 해제 요청 (status = false) 로 todo 체크를 요청합니다.\n" + - "요청한 status 가 현재 서버의 status 인 경우, 400 에러 (잘못된 상태로 요청했습니다.) 를 전달합니다. \n" + - "성공시 status code = 204, 빈 response body를 보냅니다." + "요청한 status 가 현재 서버의 status 인 경우, 400 에러 (잘못된 상태로 요청했습니다.) 를 전달합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse( code = 400, message = "1. 요청할 체크 상태를 입력해주세요.\n" @@ -107,33 +103,30 @@ public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수 @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/todo/{todoId}/check") public ResponseEntity checkTodo(@ApiParam(name = "todoId", value = "체크할 todo 의 id", required = true, example = "1") @PathVariable Long todoId, @Valid @RequestBody CheckTodoRequestDto request, @ApiIgnore @UserId Long userId) { todoService.checkTodo(todoId, request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] todo 전체 페이지 - todo 를 삭제합니다.", - notes = "todo 삭제를 요청합니다.\n" + - "성공시 status code = 204, 빈 response body를 보냅니다." + notes = "todo 삭제를 요청합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "존재하지 않는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/todo/{todoId}") public ResponseEntity deleteTodo(@ApiParam(name = "todoId", value = "삭제할 todo 의 id", required = true, example = "1") @PathVariable Long todoId) { todoService.deleteTodo(todoId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } } diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index bb2e92a5..741b557a 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -10,7 +10,6 @@ import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @@ -27,10 +26,10 @@ public class UserController { @ApiOperation( value = "[인증] 마이 페이지(Profile 뷰) - 나의 프로필 정보를 수정합니다.", - notes = "프로필 정보를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + notes = "프로필 정보 수정을 요청합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse( code = 400, message = "1. 닉네임을 입력해주세요. (nickname)\n" @@ -52,11 +51,10 @@ public class UserController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/user") public ResponseEntity updateUserInfo(@Valid @RequestBody UpdateUserInfoRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserInfo(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( @@ -64,30 +62,28 @@ public ResponseEntity updateUserInfo(@Valid @RequestBody UpdateUserInfoR notes = "푸시 알림 설정 여부를 설정합니다.\n" + "6가지 상태값 중 수정할 상태값 1개만 담아서 요청합니다.\n" + "Rules, Badge 설정으로는 ON, OFF 를 담습니다.\n" + - "Todo 관련 설정으로는 ON_ALL, ON_MY, OFF 를 담습니다.\n" + - "성공시 status code = 204, 빈 response body를 보냅니다." + "Todo 관련 설정으로는 ON_ALL, ON_MY, OFF 를 담습니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 400, message = "잘못된 상태로 요청했습니다.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/user/push") public ResponseEntity updateUserPushSetting(@Valid @RequestBody UpdatePushSettingRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserPushSetting(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] 마이 페이지(Profile 뷰) - 성향테스트 결과 정보를 수정합니다.", - notes = "성향테스트 결과를 수정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + notes = "성향테스트 결과를 수정합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse( code = 400, message = "성향 테스트의 각 성향 점수는 최소 3점, 최대 9점입니다. (smell, light, noise, clean, introversion)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @@ -98,20 +94,19 @@ public ResponseEntity updateUserPushSetting(@Valid @RequestBody UpdatePu @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/user/personality") public ResponseEntity updateUserTestScore( @Valid @RequestBody UpdateTestScoreRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserTestScore(request, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] 마이 페이지(배지 목록 뷰) - 대표 배지를 설정합니다.", - notes = "대표 배지를 설정합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + notes = "대표 배지를 설정합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 403, message = "유저가 획득한 배지가 아닙니다.", response = ErrorResponse.class), @ApiResponse(code = 404, @@ -122,21 +117,20 @@ public ResponseEntity updateUserTestScore( @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/user/badge/{badgeId}/represent") public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", value = "대표 배지로 설정할 badge 의 id", required = true, example = "1") @PathVariable Long badgeId, @ApiIgnore @UserId Long userId) { userService.updateRepresentBadge(badgeId, userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] 마이 페이지(설정) - 회원 정보를 삭제합니다.", - notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다. 성공시 status code = 204, 빈 response body를 보냅니다." + notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" @@ -145,19 +139,18 @@ public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", v @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/user") public ResponseEntity deleteUser(@ApiIgnore @UserId Long userId) { userService.deleteUser(userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } @ApiOperation( value = "[인증] 마이 페이지(설정) - 피드백 보내기 버튼 클릭 시 피드백 한걸음 배지를 전달 받습니다.", - notes = "요청에 디해여 성공시 status code = 204, 빈 response body를 보냅니다. 배지는 푸쉬알림으로 전달합니다." + notes = "배지는 푸시알림으로 전달합니다." ) @ApiResponses(value = { - @ApiResponse(code = 204, message = ""), + @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" @@ -166,10 +159,9 @@ public ResponseEntity deleteUser(@ApiIgnore @UserId Long userId) { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/user/feedback") public ResponseEntity acquireFeedbackBadge(@ApiIgnore @UserId Long userId) { userService.acquireFeedbackBadge(userId); - return SuccessResponse.NO_CONTENT; + return SuccessResponse.OK; } } From fb362c9fc7172cec52119b701c87d172bc2162e5 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 3 Oct 2022 15:30:08 +0900 Subject: [PATCH 192/301] =?UTF-8?q?#151=20[fix]=20=EC=95=8C=EB=A6=BC=20con?= =?UTF-8?q?tent=20enum=20name=EC=9C=BC=EB=A1=9C=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/notification/NotificationService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index c0c390f7..09dfac0e 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -79,16 +79,16 @@ public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) { } private String newTodoNotification(Todo todo, boolean isTake) { - if (isTake) return String.format("'%s' %s", todo.getName(), NotificationMessage.NEW_TODO_TAKE); - else return String.format("'%s' %s", todo.getName(), NotificationMessage.NEW_TODO); + if (isTake) return String.format("'%s' %s", todo.getName(), NotificationMessage.NEW_TODO_TAKE.getValue()); + else return String.format("'%s' %s", todo.getName(), NotificationMessage.NEW_TODO.getValue()); } private String remindTodoNotification(Todo todo) { - return String.format("'%s' %s", todo.getName(), NotificationMessage.TODO_REMIND); + return String.format("'%s' %s", todo.getName(), NotificationMessage.TODO_REMIND.getValue()); } private String newRuleNotification(Rule rule) { - return String.format("'%s' %s", rule.getName(), NotificationMessage.NEW_RULE); + return String.format("'%s' %s", rule.getName(), NotificationMessage.NEW_RULE.getValue()); } private String newBadgePushTitle(BadgeInfo badgeInfo) { From 261683f760783cac94e67e1cba6878f17b8768a4 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 4 Oct 2022 17:12:26 +0900 Subject: [PATCH 193/301] =?UTF-8?q?#150=20[docs]=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20response=20dto=20=ED=91=9C=EC=8B=9C=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/dto/SuccessResponse.java | 13 +++++----- .../controller/auth/AuthController.java | 8 +++---- .../home/HomeRetrieveController.java | 2 +- .../controller/room/RoomController.java | 12 +++++----- .../room/RoomRetrieveController.java | 6 ++--- .../controller/rule/RuleController.java | 20 ++++++++-------- .../rule/RuleRetrieveController.java | 2 +- .../controller/todo/TodoController.java | 20 ++++++++-------- .../todo/TodoRetrieveController.java | 22 ++++++++--------- .../controller/user/UserController.java | 16 ++++++------- .../user/UserRetrieveController.java | 24 +++++++++---------- 11 files changed, 73 insertions(+), 72 deletions(-) diff --git a/src/main/java/hous/server/common/dto/SuccessResponse.java b/src/main/java/hous/server/common/dto/SuccessResponse.java index e1fe2788..9770124c 100644 --- a/src/main/java/hous/server/common/dto/SuccessResponse.java +++ b/src/main/java/hous/server/common/dto/SuccessResponse.java @@ -10,17 +10,18 @@ @AllArgsConstructor(access = AccessLevel.PRIVATE) public class SuccessResponse { - public static final ResponseEntity OK = success(SuccessCode.OK_SUCCESS, null); - public static final ResponseEntity CREATED = success(SuccessCode.CREATED_SUCCESS, null); - public static final ResponseEntity NO_CONTENT = success(SuccessCode.NO_CONTENT_SUCCESS, null); + public static final ResponseEntity> OK = success(SuccessCode.OK_SUCCESS, null); + public static final ResponseEntity> CREATED = success(SuccessCode.CREATED_SUCCESS, null); + public static final ResponseEntity> NO_CONTENT = success(SuccessCode.NO_CONTENT_SUCCESS, null); private int status; private boolean success; private String message; private T data; - public static ResponseEntity success(SuccessCode successCode, T data) { - return (ResponseEntity) ResponseEntity.status(successCode.getStatus()) - .body(new SuccessResponse(successCode.getStatus(), true, successCode.getMessage(), data)); + public static ResponseEntity> success(SuccessCode successCode, T data) { + return ResponseEntity + .status(successCode.getStatus()) + .body(new SuccessResponse<>(successCode.getStatus(), true, successCode.getMessage(), data)); } } diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index da8eba16..d9cd3845 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -64,7 +64,7 @@ public class AuthController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PostMapping("/auth/signup") - public ResponseEntity signUp(@Valid @RequestBody SignUpRequestDto request) { + public ResponseEntity> signUp(@Valid @RequestBody SignUpRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); Long userId = authService.signUp(request.toServiceDto()); @@ -92,7 +92,7 @@ public ResponseEntity signUp(@Valid @RequestBody SignUpRequestDto @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PostMapping("/auth/login") - public ResponseEntity login(@Valid @RequestBody LoginRequestDto request) { + public ResponseEntity> login(@Valid @RequestBody LoginRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); Long userId = authService.login(request.toServiceDto()); @@ -117,7 +117,7 @@ public ResponseEntity login(@Valid @RequestBody LoginRequestDto r @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PostMapping("/auth/refresh") - public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto request) { + public ResponseEntity> reissue(@Valid @RequestBody TokenRequestDto request) { return SuccessResponse.success(SuccessCode.REISSUE_TOKEN_SUCCESS, createTokenService.reissueToken(request)); } @@ -137,7 +137,7 @@ public ResponseEntity reissue(@Valid @RequestBody TokenRequestDto }) @Auth @PostMapping("/auth/logout") - public ResponseEntity logout(@ApiIgnore @UserId Long userId) { + public ResponseEntity> logout(@ApiIgnore @UserId Long userId) { commonAuthService.logout(userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/controller/home/HomeRetrieveController.java b/src/main/java/hous/server/controller/home/HomeRetrieveController.java index c049f0b4..d67ca878 100644 --- a/src/main/java/hous/server/controller/home/HomeRetrieveController.java +++ b/src/main/java/hous/server/controller/home/HomeRetrieveController.java @@ -42,7 +42,7 @@ public class HomeRetrieveController { }) @Auth @GetMapping("/home") - public ResponseEntity getHomeInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getHomeInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_HOME_INFO_SUCCESS, homeRetrieveService.getHomeInfo(userId)); } } diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 4aaa23be..9b22b64c 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -45,7 +45,7 @@ public class RoomController { @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/room") - public ResponseEntity createRoom(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> createRoom(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.CREATE_ROOM_SUCCESS, roomService.createRoom(request, userId)); } @@ -68,9 +68,9 @@ public ResponseEntity createRoom(@Valid @RequestBody SetRoomNa }) @Auth @PostMapping("/room/{roomId}/join") - public ResponseEntity joinRoom(@ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") - @PathVariable Long roomId, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> joinRoom(@ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") + @PathVariable Long roomId, + @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.JOIN_ROOM_SUCCESS, roomService.joinRoom(roomId, userId)); } @@ -95,7 +95,7 @@ public ResponseEntity joinRoom(@ApiParam(name = "roomId", valu }) @Auth @PutMapping("/room/name") - public ResponseEntity updateRoomName(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateRoomName(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { roomService.updateRoomName(request, userId); return SuccessResponse.OK; } @@ -116,7 +116,7 @@ public ResponseEntity updateRoomName(@Valid @RequestBody SetRoomNameRequ }) @Auth @DeleteMapping("/room/leave") - public ResponseEntity leaveRoom(@ApiIgnore @UserId Long userId) { + public ResponseEntity> leaveRoom(@ApiIgnore @UserId Long userId) { roomService.leaveRoom(userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index 100026a2..733eea7c 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -38,7 +38,7 @@ public class RoomRetrieveController { }) @Auth @GetMapping("/room") - public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getRoom(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_ROOM_SUCCESS, roomRetrieveService.getRoom(userId)); } @@ -54,8 +54,8 @@ public ResponseEntity getRoom(@ApiIgnore @UserId Long userId) { }) @Auth @GetMapping("/room/info") - public ResponseEntity getRoomInfo(@ApiParam(name = "code", value = "참가하려는 방 코드", required = true, example = "PNO6VN6A") - @RequestParam String code) { + public ResponseEntity> getRoomInfo(@ApiParam(name = "code", value = "참가하려는 방 코드", required = true, example = "PNO6VN6A") + @RequestParam String code) { return SuccessResponse.success(SuccessCode.GET_ROOM_INFO_SUCCESS, roomRetrieveService.getRoomInfo(code)); } } diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 561d8759..aa13ab1d 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -49,8 +49,8 @@ public class RuleController { @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/rules") - public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> createRule(@Valid @RequestBody CreateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { ruleService.createRule(request, userId); return SuccessResponse.CREATED; } @@ -77,10 +77,10 @@ public ResponseEntity createRule(@Valid @RequestBody CreateRuleRequestDt }) @Auth @PutMapping("/rule/{ruleId}") - public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") - @PathVariable Long ruleId, - @Valid @RequestBody UpdateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") + @PathVariable Long ruleId, + @Valid @RequestBody UpdateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { ruleService.updateRule(request, ruleId, userId); return SuccessResponse.OK; } @@ -103,8 +103,8 @@ public ResponseEntity updateRule(@ApiParam(name = "ruleId", value = "수 }) @Auth @PutMapping("/rules") - public ResponseEntity updateSortByRules(@Valid @RequestBody ModifyRuleReqeustDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateSortByRules(@Valid @RequestBody ModifyRuleReqeustDto request, + @ApiIgnore @UserId Long userId) { ruleService.updateSortByRule(request, userId); return SuccessResponse.OK; } @@ -127,8 +127,8 @@ public ResponseEntity updateSortByRules(@Valid @RequestBody ModifyRuleRe }) @Auth @DeleteMapping("/rules") - public ResponseEntity deleteRules(@Valid @RequestBody ModifyRuleReqeustDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> deleteRules(@Valid @RequestBody ModifyRuleReqeustDto request, + @ApiIgnore @UserId Long userId) { ruleService.deleteRules(request, userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java index 9d72f75b..f33d1947 100644 --- a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java +++ b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java @@ -39,7 +39,7 @@ public class RuleRetrieveController { }) @Auth @GetMapping("/rules") - public ResponseEntity> getRulesInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity>> getRulesInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_RULE_INFO_SUCCESS, ruleRetrieveService.getRulesInfo(userId)); } } diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index e92ade1a..b0ef59bd 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -50,7 +50,7 @@ public class TodoController { @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/todo") - public ResponseEntity createTodo(@Valid @RequestBody TodoInfoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> createTodo(@Valid @RequestBody TodoInfoRequestDto request, @ApiIgnore @UserId Long userId) { todoService.createTodo(request, userId); return SuccessResponse.CREATED; } @@ -75,9 +75,9 @@ public ResponseEntity createTodo(@Valid @RequestBody TodoInfoRequestDto }) @Auth @PutMapping("/todo/{todoId}") - public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수정할 todo 의 id", required = true, example = "1") - @PathVariable Long todoId, - @Valid @RequestBody TodoInfoRequestDto request) { + public ResponseEntity> updateTodo(@ApiParam(name = "todoId", value = "수정할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @Valid @RequestBody TodoInfoRequestDto request) { todoService.updateTodo(todoId, request); return SuccessResponse.OK; } @@ -104,10 +104,10 @@ public ResponseEntity updateTodo(@ApiParam(name = "todoId", value = "수 }) @Auth @PostMapping("/todo/{todoId}/check") - public ResponseEntity checkTodo(@ApiParam(name = "todoId", value = "체크할 todo 의 id", required = true, example = "1") - @PathVariable Long todoId, - @Valid @RequestBody CheckTodoRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> checkTodo(@ApiParam(name = "todoId", value = "체크할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @Valid @RequestBody CheckTodoRequestDto request, + @ApiIgnore @UserId Long userId) { todoService.checkTodo(todoId, request, userId); return SuccessResponse.OK; } @@ -124,8 +124,8 @@ public ResponseEntity checkTodo(@ApiParam(name = "todoId", value = "체 }) @Auth @DeleteMapping("/todo/{todoId}") - public ResponseEntity deleteTodo(@ApiParam(name = "todoId", value = "삭제할 todo 의 id", required = true, example = "1") - @PathVariable Long todoId) { + public ResponseEntity> deleteTodo(@ApiParam(name = "todoId", value = "삭제할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId) { todoService.deleteTodo(todoId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index b7214d49..ce86a199 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -42,7 +42,7 @@ public class TodoRetrieveController { }) @Auth @GetMapping("/todo") - public ResponseEntity getUsersInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getUsersInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_USERS_INFO_SUCCESS, todoRetrieveService.getUsersInfo(userId)); } @@ -62,7 +62,7 @@ public ResponseEntity getUsersInfo(@ApiIgnore @User }) @Auth @GetMapping("/todos") - public ResponseEntity getTodoMain(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getTodoMain(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_MAIN_SUCCESS, todoRetrieveService.getTodoMain(userId)); } @@ -83,9 +83,9 @@ public ResponseEntity getTodoMain(@ApiIgnore @UserId Long user }) @Auth @GetMapping("/todo/{todoId}") - public ResponseEntity getTodoInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") - @PathVariable Long todoId, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> getTodoInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_INFO_SUCCESS, todoRetrieveService.getTodoInfo(todoId, userId)); } @@ -105,9 +105,9 @@ public ResponseEntity getTodoInfo(@ApiParam(name = "todoId", v }) @Auth @GetMapping("/todo/{todoId}/summary") - public ResponseEntity getTodoSummaryInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") - @PathVariable Long todoId, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> getTodoSummaryInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") + @PathVariable Long todoId, + @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_SUMMARY_INFO_SUCCESS, todoRetrieveService.getTodoSummaryInfo(todoId, userId)); } @@ -128,7 +128,7 @@ public ResponseEntity getTodoSummaryInfo(@ApiParam(name }) @Auth @GetMapping("/todos/day") - public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity>> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_ALL_DAY_SUCCESS, todoRetrieveService.getTodoAllDayInfo(userId)); } @@ -149,7 +149,7 @@ public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @Us }) @Auth @GetMapping("/todos/member") - public ResponseEntity> getTodoAllMemberInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity>> getTodoAllMemberInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_ALL_MEMBER_SUCCESS, todoRetrieveService.getTodoAllMemberInfo(userId)); } @@ -169,7 +169,7 @@ public ResponseEntity> getTodoAllMemberInfo(@ApiIgno }) @Auth @GetMapping("/todos/me") - public ResponseEntity getMyTodoInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getMyTodoInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_MY_TODO_SUCCESS, todoRetrieveService.getMyTodoInfo(userId)); } } diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 741b557a..89907d92 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -52,7 +52,7 @@ public class UserController { }) @Auth @PutMapping("/user") - public ResponseEntity updateUserInfo(@Valid @RequestBody UpdateUserInfoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateUserInfo(@Valid @RequestBody UpdateUserInfoRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserInfo(request, userId); return SuccessResponse.OK; } @@ -73,7 +73,7 @@ public ResponseEntity updateUserInfo(@Valid @RequestBody UpdateUserInfoR }) @Auth @PatchMapping("/user/push") - public ResponseEntity updateUserPushSetting(@Valid @RequestBody UpdatePushSettingRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateUserPushSetting(@Valid @RequestBody UpdatePushSettingRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserPushSetting(request, userId); return SuccessResponse.OK; } @@ -95,7 +95,7 @@ public ResponseEntity updateUserPushSetting(@Valid @RequestBody UpdatePu }) @Auth @PutMapping("/user/personality") - public ResponseEntity updateUserTestScore( + public ResponseEntity> updateUserTestScore( @Valid @RequestBody UpdateTestScoreRequestDto request, @ApiIgnore @UserId Long userId) { userService.updateUserTestScore(request, userId); return SuccessResponse.OK; @@ -118,9 +118,9 @@ public ResponseEntity updateUserTestScore( }) @Auth @PutMapping("/user/badge/{badgeId}/represent") - public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", value = "대표 배지로 설정할 badge 의 id", required = true, example = "1") - @PathVariable Long badgeId, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateRepresentBadge(@ApiParam(name = "badgeId", value = "대표 배지로 설정할 badge 의 id", required = true, example = "1") + @PathVariable Long badgeId, + @ApiIgnore @UserId Long userId) { userService.updateRepresentBadge(badgeId, userId); return SuccessResponse.OK; } @@ -140,7 +140,7 @@ public ResponseEntity updateRepresentBadge(@ApiParam(name = "badgeId", v }) @Auth @DeleteMapping("/user") - public ResponseEntity deleteUser(@ApiIgnore @UserId Long userId) { + public ResponseEntity> deleteUser(@ApiIgnore @UserId Long userId) { userService.deleteUser(userId); return SuccessResponse.OK; } @@ -160,7 +160,7 @@ public ResponseEntity deleteUser(@ApiIgnore @UserId Long userId) { }) @Auth @PostMapping("/user/feedback") - public ResponseEntity acquireFeedbackBadge(@ApiIgnore @UserId Long userId) { + public ResponseEntity> acquireFeedbackBadge(@ApiIgnore @UserId Long userId) { userService.acquireFeedbackBadge(userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 0252a115..9a1bf14f 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -43,7 +43,7 @@ public class UserRetrieveController { }) @Auth @GetMapping("/user") - public ResponseEntity getUserInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getUserInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_MY_PROFILE_INFO_SUCCESS, userRetrieveService.getUserInfo(userId)); } @@ -61,8 +61,8 @@ public ResponseEntity getUserInfo(@ApiIgnore @UserId Long user }) @Auth @GetMapping("/user/{homieId}") - public ResponseEntity getHomieInfo(@ApiParam(name = "homieId", value = "조회할 호미의 id", required = true, example = "1") - @PathVariable Long homieId, @ApiIgnore @UserId Long userId) { + public ResponseEntity> getHomieInfo(@ApiParam(name = "homieId", value = "조회할 호미의 id", required = true, example = "1") + @PathVariable Long homieId, @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_HOMIE_PROFILE_INFO_SUCCESS, userRetrieveService.getHomieInfo(homieId, userId)); } @@ -79,8 +79,8 @@ public ResponseEntity getHomieInfo(@ApiParam(name = "homieId", }) @Auth @GetMapping("/user/personality") - public ResponseEntity getPersonalityInfo(@ApiParam(name = "color", value = "조회할 성향 색깔", required = true, example = "RED") - @RequestParam PersonalityColor color) { + public ResponseEntity> getPersonalityInfo(@ApiParam(name = "color", value = "조회할 성향 색깔", required = true, example = "RED") + @RequestParam PersonalityColor color) { return SuccessResponse.success(SuccessCode.GET_PERSONALITY_INFO_SUCCESS, userRetrieveService.getPersonalityInfo(color)); } @@ -95,7 +95,7 @@ public ResponseEntity getPersonalityInfo(@ApiParam(name }) @Auth @GetMapping("/user/personality/test") - public ResponseEntity> getPersonalityTestInfo() { + public ResponseEntity>> getPersonalityTestInfo() { return SuccessResponse.success(SuccessCode.GET_PERSONALITY_TEST_INFO_SUCCESS, userRetrieveService.getPersonalityTestInfo()); } @@ -115,7 +115,7 @@ public ResponseEntity> getPersonalityTestInfo( }) @Auth @GetMapping("/user/badges") - public ResponseEntity getMyBadgeList(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getMyBadgeList(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_BADGE_INFO_SUCCESS, userRetrieveService.getMyBadgeList(userId)); } @@ -135,11 +135,11 @@ public ResponseEntity getMyBadgeList(@ApiIgnore @UserId Lon }) @Auth @GetMapping("/user/notifications") - public ResponseEntity getNotificationsInfo(@ApiParam(name = "size", value = "스크롤 1회당 조회할 개수", required = true, example = "10") - @RequestParam int size, - @ApiParam(name = "lastNotificationId", value = "마지막으로 조회된 notificationId", required = true, example = "100") - @RequestParam Long lastNotificationId, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> getNotificationsInfo(@ApiParam(name = "size", value = "스크롤 1회당 조회할 개수", required = true, example = "10") + @RequestParam int size, + @ApiParam(name = "lastNotificationId", value = "마지막으로 조회된 notificationId", required = true, example = "100") + @RequestParam Long lastNotificationId, + @ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_NOTIFICATIONS_INFO_SUCCESS, notificationRetrieveService.getNotificationsInfo(size, lastNotificationId, userId)); } } From 793855704ebbcc448feba5924719c51cb17535ec Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 4 Oct 2022 18:14:59 +0900 Subject: [PATCH 194/301] =?UTF-8?q?#150=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/dto/SuccessResponse.java | 1 - src/main/java/hous/server/common/success/SuccessCode.java | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/common/dto/SuccessResponse.java b/src/main/java/hous/server/common/dto/SuccessResponse.java index 9770124c..eb35668c 100644 --- a/src/main/java/hous/server/common/dto/SuccessResponse.java +++ b/src/main/java/hous/server/common/dto/SuccessResponse.java @@ -12,7 +12,6 @@ public class SuccessResponse { public static final ResponseEntity> OK = success(SuccessCode.OK_SUCCESS, null); public static final ResponseEntity> CREATED = success(SuccessCode.CREATED_SUCCESS, null); - public static final ResponseEntity> NO_CONTENT = success(SuccessCode.NO_CONTENT_SUCCESS, null); private int status; private boolean success; diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index aa7f2442..6d2d1e52 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -4,7 +4,8 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import static hous.server.common.success.SuccessStatusCode.*; +import static hous.server.common.success.SuccessStatusCode.CREATED; +import static hous.server.common.success.SuccessStatusCode.OK; @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -63,7 +64,7 @@ public enum SuccessCode { CREATE_ROOM_SUCCESS(CREATED, "방 생성 성공입니다."), // 규칙 - CREATE_RULE_SUCCESS(CREATED, "규칙 생성 성공입니다."), + CREATE_RULE_SUCCESS(CREATED, "규칙 생성 성공입니다."); /** * 202 ACCEPTED @@ -72,7 +73,6 @@ public enum SuccessCode { /** * 204 NO_CONTENT */ - NO_CONTENT_SUCCESS(NO_CONTENT, ""); private final SuccessStatusCode statusCode; private final String message; From 47ebc433c80ab07a137ef1e278561ecbdc4db15f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 30 Sep 2022 18:04:29 +0900 Subject: [PATCH 195/301] =?UTF-8?q?#128=20[feat]=20slack=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=95=8C=EB=A6=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 + .github/workflows/pr-check.yml | 2 + .gitignore | 1 + build.gradle | 2 + .../hous/server/common/util/JwtUtils.java | 8 +- .../advice/ControllerExceptionAdvice.java | 6 ++ .../server/service/slack/SlackService.java | 76 +++++++++++++++++++ 7 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/main/java/hous/server/service/slack/SlackService.java diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7e56a0f5..a7d6c4b7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -62,6 +62,8 @@ jobs: echo cloud.aws.region.static=$AWS_REGION >> application.properties echo cloud.aws.stack.auto=false >> application.properties echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties + echo slack.token=$SLACK_TOKEN >> application.properties + echo slack.channel.monitor=$SLACK_CHANNEL_MONITOR >> application.properties mkdir firebase touch ./firebase/firebase_service_key.json diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index a13f8be8..d089dbf2 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -62,6 +62,8 @@ jobs: echo cloud.aws.region.static=$AWS_REGION >> application.properties echo cloud.aws.stack.auto=false >> application.properties echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties + echo slack.token=$SLACK_TOKEN >> application.properties + echo slack.channel.monitor=$SLACK_CHANNEL_MONITOR >> application.properties mkdir firebase touch ./firebase/firebase_service_key.json diff --git a/.gitignore b/.gitignore index 476076fc..a552c44f 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ application-prod.yml application-aws.yml application-jwt.yml application-firebase.yml +application-slack.yml ### log 파일 ### logs diff --git a/build.gradle b/build.gradle index 371bb985..860a2955 100644 --- a/build.gradle +++ b/build.gradle @@ -56,6 +56,8 @@ dependencies { implementation 'com.google.firebase:firebase-admin:6.8.1' implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2' + implementation("com.slack.api:slack-api-client:1.25.1") + testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index f955aba5..6d5d9887 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -71,13 +71,13 @@ public boolean validateToken(String token) { Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token); return true; } catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e) { - log.info("Invalid JWT Token", e); + log.error("Invalid JWT Token", e); } catch (ExpiredJwtException e) { - log.info("Expired JWT Token", e); + log.error("Expired JWT Token", e); } catch (UnsupportedJwtException e) { - log.info("Unsupported JWT Token", e); + log.error("Unsupported JWT Token", e); } catch (IllegalArgumentException e) { - log.info("JWT claims string is empty.", e); + log.error("JWT claims string is empty.", e); } return false; } diff --git a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java index ece638a2..8f20ab7b 100644 --- a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java +++ b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java @@ -4,6 +4,8 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.exception.FeignClientException; import hous.server.common.exception.HousException; +import hous.server.service.slack.SlackService; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.TypeMismatchException; import org.springframework.http.HttpStatus; @@ -28,7 +30,9 @@ @Slf4j @RestControllerAdvice +@AllArgsConstructor public class ControllerExceptionAdvice { + private final SlackService slackService; /** * Hous Custom Exception @@ -39,6 +43,7 @@ protected ResponseEntity handleBaseException(HousException except log.warn(exception.getMessage(), exception); } else { log.error(exception.getMessage(), exception); + slackService.sendSlackMessage(exception); } return ResponseEntity.status(exception.getStatus()) .body(ErrorResponse.error(exception.getErrorCode())); @@ -170,6 +175,7 @@ protected ErrorResponse handleHttpMediaTypeException(final HttpMediaTypeExceptio @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Exception.class) protected ErrorResponse handleException(final Exception exception) { + slackService.sendSlackMessage(exception); log.error(exception.getMessage(), exception); return ErrorResponse.error(INTERNAL_SERVER_EXCEPTION); } diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java new file mode 100644 index 00000000..8ba9eb6d --- /dev/null +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -0,0 +1,76 @@ +package hous.server.service.slack; + +import com.slack.api.Slack; +import com.slack.api.methods.SlackApiException; +import com.slack.api.model.block.LayoutBlock; +import com.slack.api.model.block.composition.TextObject; +import hous.server.common.util.YamlPropertySourceFactory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static com.slack.api.model.block.Blocks.divider; +import static com.slack.api.model.block.Blocks.section; +import static com.slack.api.model.block.composition.BlockCompositions.markdownText; + +@Slf4j +@Service +@PropertySource(value = "classpath:application-slack.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) +public class SlackService { + @Value(value = "${slack.token}") + String token; + @Value(value = "${slack.channel.monitor}") + String channel; + + private static final String SLACK_MESSAGE_TITLE = "🤯 *500 에러 발생*"; + private static final String SLACK_NOTI_MESSAGE_TITLE = "호엥 에러 발생. 서버 다 모 여"; + private static final String FILTER_STRING = "hous.server"; + private static final String SLACK_ERROR_MESSAGE = "*Error Message:*\n"; + private static final String SLACK_ERROR_STACK = "*Error Stack:*\n"; + + public void sendSlackMessage(Exception exception) { + try { + Slack slack = Slack.getInstance(); + List layoutBlockList = createSlackMessage(exception); + slack.methods(token).chatPostMessage(req -> + req.channel(channel) + .blocks(layoutBlockList) + .text(SLACK_NOTI_MESSAGE_TITLE)); + } catch (SlackApiException | IOException e) { + log.error(e.getMessage()); + } + } + + private List createSlackMessage(Exception exception) { + StackTraceElement[] stacks = exception.getStackTrace(); + + List layoutBlockList = new ArrayList<>(); + layoutBlockList.add(section(header -> header.text(markdownText(SLACK_MESSAGE_TITLE)))); + + List sectionInFields = new ArrayList<>(); + sectionInFields.add(markdownText(SLACK_ERROR_MESSAGE + exception.getMessage())); + sectionInFields.add(markdownText(SLACK_ERROR_STACK + exception)); + layoutBlockList.add(section(section -> section.fields(sectionInFields))); + + layoutBlockList.add(divider()); + layoutBlockList.add(section(section -> section.text(markdownText(filterErrorStack(stacks))))); + return layoutBlockList; + } + + private String filterErrorStack(StackTraceElement[] stacks) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("```"); + for (StackTraceElement stack : stacks) { + if (stack.toString().contains(FILTER_STRING)) { + stringBuilder.append(stack).append("\n"); + } + } + stringBuilder.append("```"); + return stringBuilder.toString(); + } +} From 4b2314a79f5e0d1ce1b15ef5c7aa228bebcfe6a2 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 5 Oct 2022 15:05:23 +0900 Subject: [PATCH 196/301] =?UTF-8?q?#128=20[feat]=20attachment=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/slack/SlackService.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java index 8ba9eb6d..953f5882 100644 --- a/src/main/java/hous/server/service/slack/SlackService.java +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -2,6 +2,7 @@ import com.slack.api.Slack; import com.slack.api.methods.SlackApiException; +import com.slack.api.model.Attachment; import com.slack.api.model.block.LayoutBlock; import com.slack.api.model.block.composition.TextObject; import hous.server.common.util.YamlPropertySourceFactory; @@ -28,7 +29,7 @@ public class SlackService { String channel; private static final String SLACK_MESSAGE_TITLE = "🤯 *500 에러 발생*"; - private static final String SLACK_NOTI_MESSAGE_TITLE = "호엥 에러 발생. 서버 다 모 여"; + private static final String ATTACHMENTS_COLOR = "#eb4034"; private static final String FILTER_STRING = "hous.server"; private static final String SLACK_ERROR_MESSAGE = "*Error Message:*\n"; private static final String SLACK_ERROR_STACK = "*Error Stack:*\n"; @@ -36,21 +37,30 @@ public class SlackService { public void sendSlackMessage(Exception exception) { try { Slack slack = Slack.getInstance(); - List layoutBlockList = createSlackMessage(exception); + List attachments = createSlackAttachment(exception); slack.methods(token).chatPostMessage(req -> req.channel(channel) - .blocks(layoutBlockList) - .text(SLACK_NOTI_MESSAGE_TITLE)); + .attachments(attachments) + .text(SLACK_MESSAGE_TITLE)); } catch (SlackApiException | IOException e) { log.error(e.getMessage()); } } + private List createSlackAttachment(Exception exception) { + List attachments = new ArrayList<>(); + Attachment attachment = new Attachment(); + attachment.setColor(ATTACHMENTS_COLOR); + attachment.setBlocks(createSlackMessage(exception)); + attachments.add(attachment); + return attachments; + } + + private List createSlackMessage(Exception exception) { StackTraceElement[] stacks = exception.getStackTrace(); List layoutBlockList = new ArrayList<>(); - layoutBlockList.add(section(header -> header.text(markdownText(SLACK_MESSAGE_TITLE)))); List sectionInFields = new ArrayList<>(); sectionInFields.add(markdownText(SLACK_ERROR_MESSAGE + exception.getMessage())); From 8e31f2d209a9ca315ca4c80360a66ce7a13a4d95 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 5 Oct 2022 18:14:49 +0900 Subject: [PATCH 197/301] =?UTF-8?q?#128=20[fix]=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/JwtUtils.java | 8 ++++---- .../controller/advice/ControllerExceptionAdvice.java | 3 ++- src/main/java/hous/server/service/slack/SlackService.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index 6d5d9887..80ee5240 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -71,13 +71,13 @@ public boolean validateToken(String token) { Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token); return true; } catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e) { - log.error("Invalid JWT Token", e); + log.warn("Invalid JWT Token", e); } catch (ExpiredJwtException e) { - log.error("Expired JWT Token", e); + log.warn("Expired JWT Token", e); } catch (UnsupportedJwtException e) { - log.error("Unsupported JWT Token", e); + log.warn("Unsupported JWT Token", e); } catch (IllegalArgumentException e) { - log.error("JWT claims string is empty.", e); + log.warn("JWT claims string is empty.", e); } return false; } diff --git a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java index 8f20ab7b..d5709891 100644 --- a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java +++ b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java @@ -58,6 +58,7 @@ protected ResponseEntity handleFeignClientException(final FeignCl log.warn(exception.getMessage(), exception); } else { log.error(exception.getMessage(), exception); + slackService.sendSlackMessage(exception); } if (exception.getStatus() == UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) { return ResponseEntity.status(UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) @@ -175,8 +176,8 @@ protected ErrorResponse handleHttpMediaTypeException(final HttpMediaTypeExceptio @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Exception.class) protected ErrorResponse handleException(final Exception exception) { - slackService.sendSlackMessage(exception); log.error(exception.getMessage(), exception); + slackService.sendSlackMessage(exception); return ErrorResponse.error(INTERNAL_SERVER_EXCEPTION); } } diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java index 953f5882..d1daabb4 100644 --- a/src/main/java/hous/server/service/slack/SlackService.java +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -43,7 +43,7 @@ public void sendSlackMessage(Exception exception) { .attachments(attachments) .text(SLACK_MESSAGE_TITLE)); } catch (SlackApiException | IOException e) { - log.error(e.getMessage()); + log.error(e.getMessage(), e); } } From 76f831b37c402c603ae26ce826ab3a9241d9f983 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 7 Oct 2022 14:33:11 +0900 Subject: [PATCH 198/301] =?UTF-8?q?#156=20[fix]=20=ED=99=88=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=97=90=20room=20code=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/home/HomeRetrieveService.java | 2 +- .../server/service/home/dto/response/HomeInfoResponse.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index c4a26935..8ffe0446 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -61,6 +61,6 @@ public HomeInfoResponse getHomeInfo(Long userId) { .map(Participate::getOnboarding) .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getUpdatedAt())) .collect(Collectors.toList()); - return HomeInfoResponse.of(user.getOnboarding(), room, today, todayMyTodos, todayOurTodos, rules, participants); + return HomeInfoResponse.of(user.getOnboarding(), room, todayMyTodos, todayOurTodos, rules, participants); } } diff --git a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java index 793e8313..0019c2e1 100644 --- a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java +++ b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java @@ -5,13 +5,11 @@ import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; import hous.server.domain.todo.OurTodoStatus; -import hous.server.domain.todo.Todo; import hous.server.domain.user.Onboarding; import hous.server.service.todo.dto.response.MyTodoInfo; import hous.server.service.todo.dto.response.OurTodoInfo; import lombok.*; -import java.time.LocalDate; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -25,6 +23,7 @@ public class HomeInfoResponse { private String userNickname; private String roomName; + private String roomCode; private int progress; private int myTodosCnt; private List myTodos; @@ -42,12 +41,13 @@ public static class HomieInfo { private PersonalityColor color; } - public static HomeInfoResponse of(Onboarding me, Room room, LocalDate today, List myTodos, + public static HomeInfoResponse of(Onboarding me, Room room, List myTodos, List ourTodos, List rules, List participants) { int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); return HomeInfoResponse.builder() .userNickname(me.getNickname()) .roomName(room.getName()) + .roomCode(room.getCode()) .progress(MathUtils.percent(doneOurTodosCnt, ourTodos.size())) .myTodosCnt(myTodos.size()) .myTodos(myTodos.stream() From 4ab22a32e17f66c668216bc47a7a2c3b88040bd5 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 7 Oct 2022 16:07:08 +0900 Subject: [PATCH 199/301] =?UTF-8?q?#158=20[rename]=20MyTodo=20->=20TodoInf?= =?UTF-8?q?o,=20TodoInfo=20->=20TodoDetailInfo=20=EB=A1=9C=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/home/HomeRetrieveService.java | 6 +++--- .../service/home/dto/response/HomeInfoResponse.java | 6 +++--- .../service/todo/dto/response/TodoAllDayResponse.java | 6 +++--- .../dto/response/{MyTodoInfo.java => TodoDetailInfo.java} | 8 ++++---- .../todo/dto/response/{MyTodo.java => TodoInfo.java} | 6 +++--- .../service/todo/dto/response/TodoMainResponse.java | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) rename src/main/java/hous/server/service/todo/dto/response/{MyTodoInfo.java => TodoDetailInfo.java} (69%) rename src/main/java/hous/server/service/todo/dto/response/{MyTodo.java => TodoInfo.java} (76%) diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index 8ffe0446..69552e1f 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -13,8 +13,8 @@ import hous.server.service.home.dto.response.HomeInfoResponse; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.TodoServiceUtils; -import hous.server.service.todo.dto.response.MyTodoInfo; import hous.server.service.todo.dto.response.OurTodoInfo; +import hous.server.service.todo.dto.response.TodoDetailInfo; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -40,9 +40,9 @@ public HomeInfoResponse getHomeInfo(Long userId) { List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterDayOurTodos(today, todos); List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, user.getOnboarding(), todos); - List todayMyTodos = todayMyTodosList.stream() + List todayMyTodos = todayMyTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> MyTodoInfo.of( + .map(todo -> TodoDetailInfo.of( todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))) diff --git a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java index 0019c2e1..34bb15f8 100644 --- a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java +++ b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java @@ -6,8 +6,8 @@ import hous.server.domain.rule.Rule; import hous.server.domain.todo.OurTodoStatus; import hous.server.domain.user.Onboarding; -import hous.server.service.todo.dto.response.MyTodoInfo; import hous.server.service.todo.dto.response.OurTodoInfo; +import hous.server.service.todo.dto.response.TodoDetailInfo; import lombok.*; import java.util.Comparator; @@ -41,7 +41,7 @@ public static class HomieInfo { private PersonalityColor color; } - public static HomeInfoResponse of(Onboarding me, Room room, List myTodos, + public static HomeInfoResponse of(Onboarding me, Room room, List myTodos, List ourTodos, List rules, List participants) { int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); return HomeInfoResponse.builder() @@ -52,7 +52,7 @@ public static HomeInfoResponse of(Onboarding me, Room room, List myT .myTodosCnt(myTodos.size()) .myTodos(myTodos.stream() .limit(3) - .map(MyTodoInfo::getTodoName) + .map(TodoDetailInfo::getTodoName) .collect(Collectors.toList())) .ourRules(rules.stream() .sorted(Comparator.comparing(Rule::getIdx)) diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java index 5162fff9..52277093 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java @@ -13,14 +13,14 @@ public class TodoAllDayResponse { private String dayOfWeek; private int ourTodosCnt; - private List myTodos; + private List todoInfos; private List ourTodos; - public static TodoAllDayResponse of(String dayOfWeek, List myTodos, List ourTodos) { + public static TodoAllDayResponse of(String dayOfWeek, List todoInfos, List ourTodos) { return TodoAllDayResponse.builder() .dayOfWeek(dayOfWeek) .ourTodosCnt(ourTodos.size()) - .myTodos(myTodos) + .todoInfos(todoInfos) .ourTodos(ourTodos) .build(); } diff --git a/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/TodoDetailInfo.java similarity index 69% rename from src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java rename to src/main/java/hous/server/service/todo/dto/response/TodoDetailInfo.java index 79b6bc51..2148905e 100644 --- a/src/main/java/hous/server/service/todo/dto/response/MyTodoInfo.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoDetailInfo.java @@ -6,7 +6,7 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class MyTodoInfo extends MyTodo { +public class TodoDetailInfo extends TodoInfo { private boolean isChecked; @@ -16,13 +16,13 @@ public boolean isChecked() { } @Builder(access = AccessLevel.PRIVATE) - public MyTodoInfo(Long todoId, String todoName, boolean isChecked) { + public TodoDetailInfo(Long todoId, String todoName, boolean isChecked) { super(todoId, todoName); this.isChecked = isChecked; } - public static MyTodoInfo of(Long todoId, String todoName, boolean isChecked) { - return MyTodoInfo.builder() + public static TodoDetailInfo of(Long todoId, String todoName, boolean isChecked) { + return TodoDetailInfo.builder() .todoId(todoId) .todoName(todoName) .isChecked(isChecked) diff --git a/src/main/java/hous/server/service/todo/dto/response/MyTodo.java b/src/main/java/hous/server/service/todo/dto/response/TodoInfo.java similarity index 76% rename from src/main/java/hous/server/service/todo/dto/response/MyTodo.java rename to src/main/java/hous/server/service/todo/dto/response/TodoInfo.java index b7681137..50424c4e 100644 --- a/src/main/java/hous/server/service/todo/dto/response/MyTodo.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoInfo.java @@ -7,12 +7,12 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PROTECTED) @Builder(access = AccessLevel.PRIVATE) -public class MyTodo { +public class TodoInfo { private Long todoId; private String todoName; - public static MyTodo of(Long todoId, String todoName) { - return MyTodo.builder() + public static TodoInfo of(Long todoId, String todoName) { + return TodoInfo.builder() .todoId(todoId) .todoName(todoName) .build(); diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java index c8bca349..468d3454 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoMainResponse.java @@ -20,10 +20,10 @@ public class TodoMainResponse { private int progress; private int myTodosCnt; private int ourTodosCnt; - private List myTodos; + private List myTodos; private List ourTodos; - public static TodoMainResponse of(LocalDate today, List myTodos, List ourTodos) { + public static TodoMainResponse of(LocalDate today, List myTodos, List ourTodos) { int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); return TodoMainResponse.builder() .date(DateUtils.parseMonthAndDay(today)) From 89e24cd4ce186ab0a9116a499b0711d0fd3269b1 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 7 Oct 2022 16:07:32 +0900 Subject: [PATCH 200/301] =?UTF-8?q?#158=20[fix]=20=EB=A9=A4=EB=B2=84?= =?UTF-8?q?=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20todoId=EB=8F=84=20?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/todo/TodoRetrieveService.java | 12 +++++++----- .../service/todo/dto/response/DayOfWeekTodo.java | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 99125a36..777d5fe8 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -52,7 +52,7 @@ public TodoMainResponse getTodoMain(Long userId) { List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterDayOurTodos(today, todos); List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, user.getOnboarding(), todos); - List todayMyTodos = todayMyTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> MyTodoInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))).collect(Collectors.toList()); + List todayMyTodos = todayMyTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> TodoDetailInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))).collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream().map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))).collect(Collectors.toList()); return TodoMainResponse.of(today, todayMyTodos, todayOurTodos); } @@ -95,16 +95,16 @@ public List getTodoAllDayInfo(Long userId) { List allDayTodosList = new ArrayList<>(); for (int i = 1; i < 8; i++) { String dayOfWeek = DayOfWeek.getValueByIndex(i); - List myTodoInfos = allDayMyTodosList[i].stream() + List todoInfoInfos = allDayMyTodosList[i].stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> MyTodo.of(todo.getId(), todo.getName())) + .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) .collect(Collectors.toList()); List ourTodoInfos = allDayOurTodosList[i].stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> OurTodo.of(todo.getName(), todo.getTakes().stream() .map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))) .collect(Collectors.toList()); - allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, myTodoInfos, ourTodoInfos)); + allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, todoInfoInfos, ourTodoInfos)); } return allDayTodosList; } @@ -129,7 +129,9 @@ public List getTodoAllMemberInfo(Long userId) { int totalTodoCnt = 0; for (int i = 1; i < allDayMemberTodos.length; i++) { String dayOfWeek = DayOfWeek.getValueByIndex(i); - List thisDayTodosName = allDayMemberTodos[i].stream().map(Todo::getName).collect(Collectors.toList()); + List thisDayTodosName = allDayMemberTodos[i].stream() + .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) + .collect(Collectors.toList()); dayOfWeekTodos.add(DayOfWeekTodo.of(dayOfWeek, thisDayTodosName.size(), thisDayTodosName)); totalTodoCnt += thisDayTodosName.size(); } diff --git a/src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java b/src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java index 896e96fe..050bbb4d 100644 --- a/src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java +++ b/src/main/java/hous/server/service/todo/dto/response/DayOfWeekTodo.java @@ -12,9 +12,9 @@ public class DayOfWeekTodo { private String dayOfWeek; private int todoCnt; - private List dayOfWeekTodos; + private List dayOfWeekTodos; - public static DayOfWeekTodo of(String dayOfWeek, int todoCnt, List dayOfWeekTodos) { + public static DayOfWeekTodo of(String dayOfWeek, int todoCnt, List dayOfWeekTodos) { return DayOfWeekTodo.builder() .dayOfWeek(dayOfWeek) .todoCnt(todoCnt) From 548d277a874928896453faccb051b5ae7ca588ec Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 7 Oct 2022 16:14:07 +0900 Subject: [PATCH 201/301] =?UTF-8?q?#158=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/todo/TodoRetrieveService.java | 4 ++-- .../service/todo/dto/response/TodoAllDayResponse.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 777d5fe8..508f938a 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -95,7 +95,7 @@ public List getTodoAllDayInfo(Long userId) { List allDayTodosList = new ArrayList<>(); for (int i = 1; i < 8; i++) { String dayOfWeek = DayOfWeek.getValueByIndex(i); - List todoInfoInfos = allDayMyTodosList[i].stream() + List todoInfos = allDayMyTodosList[i].stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) .collect(Collectors.toList()); @@ -104,7 +104,7 @@ public List getTodoAllDayInfo(Long userId) { .map(todo -> OurTodo.of(todo.getName(), todo.getTakes().stream() .map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))) .collect(Collectors.toList()); - allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, todoInfoInfos, ourTodoInfos)); + allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, todoInfos, ourTodoInfos)); } return allDayTodosList; } diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java index 52277093..5f5b64cc 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java @@ -13,14 +13,14 @@ public class TodoAllDayResponse { private String dayOfWeek; private int ourTodosCnt; - private List todoInfos; + private List myTodos; private List ourTodos; - public static TodoAllDayResponse of(String dayOfWeek, List todoInfos, List ourTodos) { + public static TodoAllDayResponse of(String dayOfWeek, List myTodos, List ourTodos) { return TodoAllDayResponse.builder() .dayOfWeek(dayOfWeek) .ourTodosCnt(ourTodos.size()) - .todoInfos(todoInfos) + .myTodos(myTodos) .ourTodos(ourTodos) .build(); } From 88f9bc2b779e549c48e50427121738375cd4233e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 8 Oct 2022 15:41:17 +0900 Subject: [PATCH 202/301] =?UTF-8?q?#160=20[fix]=20=ED=81=B4=EB=9D=BC=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=9A=94=EC=B2=AD=20=EC=8B=9C=20=EB=B0=A9?= =?UTF-8?q?=20=EC=B0=B8=EA=B0=80=EC=97=AC=EB=B6=80=20=ED=95=A8=EA=BB=98=20?= =?UTF-8?q?=EC=A0=84=EB=8B=AC=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../hous/server/controller/auth/AuthController.java | 9 +++++---- .../controller/auth/dto/response/LoginResponse.java | 10 +++++++++- .../java/hous/server/service/room/RoomService.java | 6 ++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index d9cd3845..8ec1c65c 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -14,6 +14,7 @@ import hous.server.service.auth.CreateTokenService; import hous.server.service.auth.dto.request.TokenRequestDto; import hous.server.service.auth.dto.response.TokenResponse; +import hous.server.service.room.RoomService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -37,6 +38,7 @@ public class AuthController { private final AuthServiceProvider authServiceProvider; private final CreateTokenService createTokenService; private final CommonAuthService commonAuthService; + private final RoomService roomService; @ApiOperation( value = "온보딩 페이지 - 회원가입을 요청합니다.", @@ -67,9 +69,8 @@ public class AuthController { public ResponseEntity> signUp(@Valid @RequestBody SignUpRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); Long userId = authService.signUp(request.toServiceDto()); - TokenResponse tokenInfo = createTokenService.createTokenInfo(userId); - return SuccessResponse.success(SuccessCode.SIGNUP_SUCCESS, LoginResponse.of(userId, tokenInfo)); + return SuccessResponse.success(SuccessCode.SIGNUP_SUCCESS, LoginResponse.of(userId, tokenInfo, false)); } @ApiOperation( @@ -95,9 +96,9 @@ public ResponseEntity> signUp(@Valid @RequestBody public ResponseEntity> login(@Valid @RequestBody LoginRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); Long userId = authService.login(request.toServiceDto()); - + boolean isJoiningRoom = roomService.existsParticipatingRoomByUserId(userId); TokenResponse tokenInfo = createTokenService.createTokenInfo(userId); - return SuccessResponse.success(SuccessCode.LOGIN_SUCCESS, LoginResponse.of(userId, tokenInfo)); + return SuccessResponse.success(SuccessCode.LOGIN_SUCCESS, LoginResponse.of(userId, tokenInfo, isJoiningRoom)); } @ApiOperation( diff --git a/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java b/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java index f0123ba1..31ea8fab 100644 --- a/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java +++ b/src/main/java/hous/server/controller/auth/dto/response/LoginResponse.java @@ -1,5 +1,6 @@ package hous.server.controller.auth.dto.response; +import com.fasterxml.jackson.annotation.JsonProperty; import hous.server.service.auth.dto.response.TokenResponse; import lombok.*; @@ -12,11 +13,18 @@ public class LoginResponse { private Long userId; private TokenResponse token; + private boolean isJoiningRoom; - public static LoginResponse of(Long userId, TokenResponse token) { + @JsonProperty("isJoiningRoom") + public boolean isJoiningRoom() { + return isJoiningRoom; + } + + public static LoginResponse of(Long userId, TokenResponse token, boolean isJoiningRoom) { return LoginResponse.builder() .userId(userId) .token(token) + .isJoiningRoom(isJoiningRoom) .build(); } } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 415d81c8..65364f18 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -107,6 +107,12 @@ public void leaveRoom(Long userId) { me.resetTestScore(me.getTestScore()); } + public boolean existsParticipatingRoomByUserId(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + List participates = user.getOnboarding().getParticipates(); + return !participates.isEmpty(); + } + private String createUniqueRoomCode() { String code; do { From 8cf472c8f97e76ea8d733f83bf4326045ca272f8 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 11 Oct 2022 14:45:15 +0900 Subject: [PATCH 203/301] =?UTF-8?q?#162=20[fix]=20=EC=8B=A0=EA=B7=9C=20?= =?UTF-8?q?=EB=B0=B0=EC=A7=80=20=ED=91=9C=EC=8B=9C,=20=EC=9D=BD=EC=9D=8C?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/UserRetrieveController.java | 4 +++- .../hous/server/domain/badge/Acquire.java | 8 ++++++++ .../service/user/UserRetrieveService.java | 13 ++++++++++-- .../dto/response/MyBadgeInfoResponse.java | 20 +++++++++++++------ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 9a1bf14f..d936bcb2 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -102,7 +102,9 @@ public ResponseEntity>> getPer @ApiOperation( value = "[인증] 마이 페이지(배지 목록 뷰) - 나의 배지 정보를 조회합니다.", notes = "대표 배지가 없는 경우, null을 보냅니다.\n" + - "배지 목록에서는 모든 배지 리스트를 전달하지만. 내가 획득한 배지의 경우 acquire = true 입니다." + "배지 목록에서는 모든 배지 리스트를 전달합니다.\n" + + "내가 획득한 배지의 경우 isAcquired = true 입니다.\n" + + "신규 배지의 경우 isRead = false 입니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "나의 배지 목록 조회 성공입니다."), diff --git a/src/main/java/hous/server/domain/badge/Acquire.java b/src/main/java/hous/server/domain/badge/Acquire.java index 970d60db..339f7913 100644 --- a/src/main/java/hous/server/domain/badge/Acquire.java +++ b/src/main/java/hous/server/domain/badge/Acquire.java @@ -25,10 +25,18 @@ public class Acquire extends AuditingTimeEntity { @JoinColumn(name = "badge_id") private Badge badge; + @Column(nullable = false) + private boolean isRead; + public static Acquire newInstance(Onboarding onboarding, Badge badge) { return Acquire.builder() .onboarding(onboarding) .badge(badge) + .isRead(false) .build(); } + + public void updateIsRead() { + this.isRead = true; + } } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index e60447a6..cd7a34c6 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -67,16 +67,25 @@ public List getPersonalityTestInfo() { .collect(Collectors.toList()); } + @Transactional public MyBadgeInfoResponse getMyBadgeList(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); RoomServiceUtils.findParticipatingRoom(user); Represent represent = onboarding.getRepresent(); List badges = badgeRepository.findAllBadge(); - List myBadges = acquireRepository.findAllAcquireByOnboarding(onboarding).stream() + List acquires = acquireRepository.findAllAcquireByOnboarding(onboarding); + List myBadges = acquires.stream() .map(Acquire::getBadge) .collect(Collectors.toList()); - return MyBadgeInfoResponse.of(represent, badges, myBadges); + List newBadges = acquires.stream() + .filter(acquire -> !acquire.isRead()) + .map(Acquire::getBadge) + .collect(Collectors.toList()); + acquires.stream() + .filter(acquire -> !acquire.isRead()) + .forEach(Acquire::updateIsRead); + return MyBadgeInfoResponse.of(represent, badges, myBadges, newBadges); } private UserInfoResponse getProfileInfoByUser(User user) { diff --git a/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java index ac51a82c..650c92f7 100644 --- a/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/MyBadgeInfoResponse.java @@ -17,10 +17,10 @@ public class MyBadgeInfoResponse { private RepresentBadgeInfo representBadge; private List badges; - public static MyBadgeInfoResponse of(Represent represent, List badgeList, List myBadges) { + public static MyBadgeInfoResponse of(Represent represent, List badgeList, List myBadges, List newBadges) { return MyBadgeInfoResponse.builder() .representBadge(RepresentBadgeInfo.of(represent)) - .badges(BadgeInfo.of(badgeList, myBadges)) + .badges(BadgeInfo.of(badgeList, myBadges, newBadges)) .build(); } @@ -29,6 +29,7 @@ public static MyBadgeInfoResponse of(Represent represent, List badgeList, @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class BadgeInfo extends RepresentBadgeInfo { private boolean isAcquired; + private boolean isRead; private String description; @JsonProperty("isAcquired") @@ -36,26 +37,33 @@ public boolean isAcquired() { return isAcquired; } + @JsonProperty("isRead") + public boolean isRead() { + return isRead; + } + @Builder(access = AccessLevel.PRIVATE) - public BadgeInfo(Long badgeId, String name, String imageUrl, boolean isAcquired, String description) { + public BadgeInfo(Long badgeId, String name, String imageUrl, boolean isAcquired, boolean isRead, String description) { super(badgeId, name, imageUrl); this.isAcquired = isAcquired; + this.isRead = isRead; this.description = description; } - public static BadgeInfo of(Badge badge, boolean isAcquired) { + public static BadgeInfo of(Badge badge, boolean isAcquired, boolean isRead) { return BadgeInfo.builder() .badgeId(badge.getId()) .name(badge.getInfo().getValue()) .imageUrl(badge.getImageUrl()) .isAcquired(isAcquired) + .isRead(isRead) .description(badge.getInfo().getDescription()) .build(); } - public static List of(List badges, List myBadges) { + public static List of(List badges, List myBadges, List newBadges) { return badges.stream() - .map(badge -> BadgeInfo.of(badge, myBadges.contains(badge))) + .map(badge -> BadgeInfo.of(badge, myBadges.contains(badge), !newBadges.contains(badge))) .collect(Collectors.toList()); } } From 429c3405ba2e35ac30d7136c188001c8fbcf129f Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 17 Oct 2022 15:47:33 +0900 Subject: [PATCH 204/301] =?UTF-8?q?#164=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EA=B0=80=EB=8F=85=EC=84=B1=20=EC=B8=A1=EB=A9=B4=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/service/todo/TodoRetrieveService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 508f938a..d68bcba2 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -52,8 +52,16 @@ public TodoMainResponse getTodoMain(Long userId) { List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterDayOurTodos(today, todos); List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, user.getOnboarding(), todos); - List todayMyTodos = todayMyTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> TodoDetailInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))).collect(Collectors.toList()); - List todayOurTodos = todayOurTodosList.stream().sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)).map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream().map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))).collect(Collectors.toList()); + List todayMyTodos = todayMyTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> TodoDetailInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))) + .collect(Collectors.toList()); + List todayOurTodos = todayOurTodosList.stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) + .map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() + .map(take -> take.getOnboarding().getNickname()) + .collect(Collectors.toSet()))) + .collect(Collectors.toList()); return TodoMainResponse.of(today, todayMyTodos, todayOurTodos); } From c7423c78e1bdbac03c15896bd4ab48febf15bf9e Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 17 Oct 2022 16:01:48 +0900 Subject: [PATCH 205/301] =?UTF-8?q?#164=20[fix]=20TestScore=20=EC=B9=BC?= =?UTF-8?q?=EB=9F=BC=20nullable=20=3D=20true=20=EB=A1=9C=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 --- src/main/java/hous/server/domain/user/Onboarding.java | 11 +++-------- src/main/java/hous/server/domain/user/TestScore.java | 5 ----- .../java/hous/server/service/room/RoomService.java | 4 +++- .../java/hous/server/service/user/UserService.java | 4 +++- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index a61bb358..ac413fc8 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -57,7 +57,7 @@ public class Onboarding extends AuditingTimeEntity { private Represent represent; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "test_score_id", nullable = false) + @JoinColumn(name = "test_score_id") private TestScore testScore; @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @@ -69,12 +69,10 @@ public class Onboarding extends AuditingTimeEntity { @OneToMany(mappedBy = "onboarding", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private final List notifications = new ArrayList<>(); - public static Onboarding newInstance(User user, Personality personality, TestScore testScore, - String nickname, LocalDate birthday, boolean isPublic) { + public static Onboarding newInstance(User user, Personality personality, String nickname, LocalDate birthday, boolean isPublic) { return Onboarding.builder() .user(user) .personality(personality) - .testScore(testScore) .nickname(nickname) .birthday(birthday) .isPublic(isPublic) @@ -119,14 +117,11 @@ public void resetUserInfo() { this.mbti = null; this.job = null; this.introduction = null; + this.testScore = null; } public void resetBadge() { this.represent = null; this.acquires.clear(); } - - public void resetTestScore(TestScore testScore) { - this.testScore = testScore.resetScore(testScore); - } } diff --git a/src/main/java/hous/server/domain/user/TestScore.java b/src/main/java/hous/server/domain/user/TestScore.java index 142f022a..5bdd7995 100644 --- a/src/main/java/hous/server/domain/user/TestScore.java +++ b/src/main/java/hous/server/domain/user/TestScore.java @@ -49,11 +49,6 @@ public void updateScore(int light, int noise, int clean, int smell, int introver this.introversion = introversion; } - public TestScore resetScore(TestScore testScore) { - testScore.updateScore(0, 0, 0, 0, 0); - return testScore; - } - public int getTotalTestScore() { return this.getLight() + this.getNoise() + this.getClean() + this.getSmell() + this.getIntroversion(); } diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 65364f18..df2205f5 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -14,6 +14,7 @@ import hous.server.domain.todo.repository.TodoRepository; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; +import hous.server.domain.user.repository.TestScoreRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.badge.BadgeService; import hous.server.service.room.dto.request.SetRoomNameRequestDto; @@ -40,6 +41,7 @@ public class RoomService { private final DoneRepository doneRepository; private final AcquireRepository acquireRepository; private final RepresentRepository representRepository; + private final TestScoreRepository testScoreRepository; private final NotificationRepository notificationRepository; private final BadgeService badgeService; @@ -102,9 +104,9 @@ public void leaveRoom(Long userId) { } acquireRepository.deleteAll(me.getAcquires()); notificationRepository.deleteAll(me.getNotifications()); + testScoreRepository.delete(me.getTestScore()); me.resetUserInfo(); me.resetBadge(); - me.resetTestScore(me.getTestScore()); } public boolean existsParticipatingRoomByUserId(Long userId) { diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 8e212906..0d610a5e 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -70,7 +70,6 @@ public Long registerUser(CreateUserRequestDto request) { Onboarding onboarding = onboardingRepository.save(Onboarding.newInstance( user, personalityRepository.findPersonalityByColor(PersonalityColor.GRAY), - testScoreRepository.save(TestScore.newInstance()), request.getNickname(), request.getBirthday(), request.getIsPublic())); @@ -99,6 +98,9 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) Room room = RoomServiceUtils.findParticipatingRoom(user); Onboarding me = user.getOnboarding(); TestScore testScore = me.getTestScore(); + if (testScore == null) { + testScore = testScoreRepository.save(TestScore.newInstance()); + } testScore.updateScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); me.updatePersonality(personality); From ddf84cea6780e97dffb8952e5b3d055c19da1347 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 17 Oct 2022 17:39:27 +0900 Subject: [PATCH 206/301] =?UTF-8?q?#164=20[fix]=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/domain/room/Participate.java | 20 ++++- .../hous/server/domain/user/Onboarding.java | 22 +++++- .../hous/server/domain/user/TestScore.java | 2 +- .../service/home/HomeRetrieveService.java | 5 +- .../service/todo/TodoRetrieveService.java | 79 +++++++++++-------- .../server/service/todo/TodoServiceUtils.java | 14 ++-- .../hous/server/service/user/UserService.java | 3 +- .../server/service/user/UserServiceUtils.java | 17 ++++ 8 files changed, 115 insertions(+), 47 deletions(-) diff --git a/src/main/java/hous/server/domain/room/Participate.java b/src/main/java/hous/server/domain/room/Participate.java index 40e4bc47..8a4f3337 100644 --- a/src/main/java/hous/server/domain/room/Participate.java +++ b/src/main/java/hous/server/domain/room/Participate.java @@ -2,7 +2,9 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.user.Onboarding; +import hous.server.domain.user.TestScore; import lombok.*; +import org.jetbrains.annotations.NotNull; import javax.persistence.*; @@ -11,7 +13,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) -public class Participate extends AuditingTimeEntity { +public class Participate extends AuditingTimeEntity implements Comparable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -31,4 +33,20 @@ public static Participate newInstance(Onboarding onboarding, Room room) { .room(room) .build(); } + + @Override + public int compareTo(@NotNull Participate o) { + TestScore t1 = getOnboarding().getTestScore(); + TestScore t2 = o.getOnboarding().getTestScore(); + if (t1 == null && t2 != null) { + return 1; + } + if (t1 != null && t2 == null) { + return -1; + } + if (t1 == null && t2 == null) { + return 0; + } + return t1.getCreatedAt().compareTo(t2.getCreatedAt()); + } } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index ac413fc8..ffc71a35 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -20,7 +20,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) -public class Onboarding extends AuditingTimeEntity { +public class Onboarding extends AuditingTimeEntity implements Comparable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -103,6 +103,10 @@ public void deleteParticipate(Participate participate) { this.participates.remove(participate); } + public void setTestScore(TestScore testScore) { + this.testScore = testScore; + } + public void updateUserInfo(UpdateUserInfoRequestDto request) { this.nickname = request.getNickname(); this.isPublic = request.isPublic(); @@ -124,4 +128,20 @@ public void resetBadge() { this.represent = null; this.acquires.clear(); } + + @Override + public int compareTo(Onboarding o) { + TestScore t1 = getTestScore(); + TestScore t2 = o.getTestScore(); + if (t1 == null && t2 != null) { + return 1; + } + if (t1 != null && t2 == null) { + return -1; + } + if (t1 == null && t2 == null) { + return 0; + } + return t1.getCreatedAt().compareTo(t2.getCreatedAt()); + } } diff --git a/src/main/java/hous/server/domain/user/TestScore.java b/src/main/java/hous/server/domain/user/TestScore.java index 5bdd7995..d96ebc73 100644 --- a/src/main/java/hous/server/domain/user/TestScore.java +++ b/src/main/java/hous/server/domain/user/TestScore.java @@ -41,7 +41,7 @@ public static TestScore newInstance() { .build(); } - public void updateScore(int light, int noise, int clean, int smell, int introversion) { + public void updateTestScore(int light, int noise, int clean, int smell, int introversion) { this.light = light; this.noise = noise; this.clean = clean; diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index 69552e1f..e940d4e7 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -59,8 +59,9 @@ public HomeInfoResponse getHomeInfo(Long userId) { List rules = room.getRules(); List participants = room.getParticipates().stream() .map(Participate::getOnboarding) - .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getUpdatedAt())) + .sorted(Onboarding::compareTo) .collect(Collectors.toList()); - return HomeInfoResponse.of(user.getOnboarding(), room, todayMyTodos, todayOurTodos, rules, participants); + List meFirstList = UserServiceUtils.toMeFirstList(participants, user.getOnboarding()); + return HomeInfoResponse.of(user.getOnboarding(), room, todayMyTodos, todayOurTodos, rules, meFirstList); } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index d68bcba2..f32eae9e 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -6,6 +6,7 @@ import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.todo.DayOfWeek; +import hous.server.domain.todo.Take; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.todo.repository.TodoRepository; @@ -40,9 +41,10 @@ public UserPersonalityInfoResponse getUsersInfo(Long userId) { List participates = room.getParticipates(); List onboardings = participates.stream() .map(Participate::getOnboarding) - .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getUpdatedAt())) + .sorted(Onboarding::compareTo) .collect(Collectors.toList()); - return UserPersonalityInfoResponse.of(onboardings); + List meFirstList = UserServiceUtils.toMeFirstList(onboardings, user.getOnboarding()); + return UserPersonalityInfoResponse.of(meFirstList); } public TodoMainResponse getTodoMain(Long userId) { @@ -72,17 +74,28 @@ public TodoInfoResponse getTodoInfo(Long todoId, Long userId) { List participates = room.getParticipates(); List onboardings = participates.stream() .map(Participate::getOnboarding) - .sorted(Comparator.comparing(onboarding -> onboarding.getTestScore().getUpdatedAt())) + .sorted(Onboarding::compareTo) .collect(Collectors.toList()); - List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(todo); - return TodoInfoResponse.of(todo, userPersonalityInfos, onboardings); + List meFirstList = UserServiceUtils.toMeFirstList(onboardings, user.getOnboarding()); + List todoTakes = todo.getTakes().stream() + .map(Take::getOnboarding) + .sorted(Onboarding::compareTo) + .collect(Collectors.toList()); + List meFirstTodoTakes = UserServiceUtils.toMeFirstList(todoTakes, user.getOnboarding()); + List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(meFirstTodoTakes); + return TodoInfoResponse.of(todo, userPersonalityInfos, meFirstList); } public TodoSummaryInfoResponse getTodoSummaryInfo(Long todoId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); RoomServiceUtils.findParticipatingRoom(user); Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); - List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(todo); + List todoTakes = todo.getTakes().stream() + .map(Take::getOnboarding) + .sorted(Onboarding::compareTo) + .collect(Collectors.toList()); + List meFirstTodoTakes = UserServiceUtils.toMeFirstList(todoTakes, user.getOnboarding()); + List userPersonalityInfos = TodoServiceUtils.toUserPersonalityInfoList(meFirstTodoTakes); return TodoSummaryInfoResponse.of(todo, userPersonalityInfos, user.getOnboarding()); } @@ -126,33 +139,33 @@ public List getTodoAllMemberInfo(Long userId) { List otherMemberTodos = new ArrayList<>(); // 성향테스트 참여 순서로 정렬 - room.getParticipates().stream().sorted( - Comparator.comparing(participate -> participate.getOnboarding().getTestScore().getUpdatedAt()) - ).forEach(participate -> { - List memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); - - List[] allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos); - - List dayOfWeekTodos = new ArrayList<>(); - int totalTodoCnt = 0; - for (int i = 1; i < allDayMemberTodos.length; i++) { - String dayOfWeek = DayOfWeek.getValueByIndex(i); - List thisDayTodosName = allDayMemberTodos[i].stream() - .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) - .collect(Collectors.toList()); - dayOfWeekTodos.add(DayOfWeekTodo.of(dayOfWeek, thisDayTodosName.size(), thisDayTodosName)); - totalTodoCnt += thisDayTodosName.size(); - } - - String userName = participate.getOnboarding().getNickname(); - PersonalityColor color = participate.getOnboarding().getPersonality().getColor(); - - if (user.getOnboarding().equals(participate.getOnboarding())) { - allMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); - } else { - otherMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); - } - }); + room.getParticipates().stream() + .sorted(Participate::compareTo) + .forEach(participate -> { + List memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); + + List[] allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos); + + List dayOfWeekTodos = new ArrayList<>(); + int totalTodoCnt = 0; + for (int i = 1; i < allDayMemberTodos.length; i++) { + String dayOfWeek = DayOfWeek.getValueByIndex(i); + List thisDayTodosName = allDayMemberTodos[i].stream() + .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) + .collect(Collectors.toList()); + dayOfWeekTodos.add(DayOfWeekTodo.of(dayOfWeek, thisDayTodosName.size(), thisDayTodosName)); + totalTodoCnt += thisDayTodosName.size(); + } + + String userName = participate.getOnboarding().getNickname(); + PersonalityColor color = participate.getOnboarding().getPersonality().getColor(); + + if (user.getOnboarding().equals(participate.getOnboarding())) { + allMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); + } else { + otherMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); + } + }); allMemberTodos.addAll(otherMemberTodos); return allMemberTodos; diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index b4622888..c543667f 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -17,7 +17,6 @@ import java.time.LocalDate; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -46,13 +45,12 @@ public static void validateTodoStatus(DoneRepository doneRepository, boolean sta } } - public static List toUserPersonalityInfoList(Todo todo) { - return todo.getTakes().stream() - .sorted(Comparator.comparing(take -> take.getOnboarding().getTestScore().getUpdatedAt())) - .map(take -> UserPersonalityInfo.of( - take.getOnboarding().getId(), - take.getOnboarding().getPersonality().getColor(), - take.getOnboarding().getNickname())) + public static List toUserPersonalityInfoList(List onboardings) { + return onboardings.stream() + .map(onboarding -> UserPersonalityInfo.of( + onboarding.getId(), + onboarding.getPersonality().getColor(), + onboarding.getNickname())) .collect(Collectors.toList()); } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 0d610a5e..23e014e1 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -100,8 +100,9 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) TestScore testScore = me.getTestScore(); if (testScore == null) { testScore = testScoreRepository.save(TestScore.newInstance()); + me.setTestScore(testScore); } - testScore.updateScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); + testScore.updateTestScore(request.getLight(), request.getNoise(), request.getClean(), request.getSmell(), request.getIntroversion()); Personality personality = UserServiceUtils.getPersonalityColorByTestScore(personalityRepository, testScore); me.updatePersonality(personality); badgeService.acquireBadge(user, BadgeInfo.I_AM_SUCH_A_PERSON); diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index ff040cc1..8749adf7 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -6,6 +6,7 @@ import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; +import hous.server.domain.user.Onboarding; import hous.server.domain.user.TestScore; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; @@ -14,6 +15,10 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import static hous.server.common.exception.ErrorCode.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -115,4 +120,16 @@ public static Personality getPersonalityColorByTestScore(PersonalityRepository p return null; } + public static List toMeFirstList(List onboardings, Onboarding me) { + List result = new ArrayList<>(); + List justMeList = onboardings.stream() + .filter(onboarding -> onboarding.getId().equals(me.getId())) + .collect(Collectors.toList()); + List exceptMeList = onboardings.stream() + .filter(onboarding -> !onboarding.getId().equals(me.getId())) + .collect(Collectors.toList()); + result.addAll(justMeList); + result.addAll(exceptMeList); + return result; + } } From 812c9badf8e009fd53274024d9e6bcdd175a6eb7 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 17 Oct 2022 17:48:52 +0900 Subject: [PATCH 207/301] =?UTF-8?q?#164=20[fix]=20=EC=8A=AC=EB=9E=99=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=20prod=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=EC=97=90=EC=84=9C=EB=A7=8C=20=EB=B3=B4?= =?UTF-8?q?=EB=82=B4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/slack/SlackService.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java index d1daabb4..81ed5f39 100644 --- a/src/main/java/hous/server/service/slack/SlackService.java +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -23,6 +23,9 @@ @Service @PropertySource(value = "classpath:application-slack.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) public class SlackService { + + @Value(value = "${spring.profiles.default}") + String profile; @Value(value = "${slack.token}") String token; @Value(value = "${slack.channel.monitor}") @@ -35,15 +38,17 @@ public class SlackService { private static final String SLACK_ERROR_STACK = "*Error Stack:*\n"; public void sendSlackMessage(Exception exception) { - try { - Slack slack = Slack.getInstance(); - List attachments = createSlackAttachment(exception); - slack.methods(token).chatPostMessage(req -> - req.channel(channel) - .attachments(attachments) - .text(SLACK_MESSAGE_TITLE)); - } catch (SlackApiException | IOException e) { - log.error(e.getMessage(), e); + if (profile.equals("prod")) { + try { + Slack slack = Slack.getInstance(); + List attachments = createSlackAttachment(exception); + slack.methods(token).chatPostMessage(req -> + req.channel(channel) + .attachments(attachments) + .text(SLACK_MESSAGE_TITLE)); + } catch (SlackApiException | IOException e) { + log.error(e.getMessage(), e); + } } } From 34fdfe097ed5e54279ca62e92eb93cc35e10ef5f Mon Sep 17 00:00:00 2001 From: Joon Date: Tue, 18 Oct 2022 14:00:14 +0900 Subject: [PATCH 208/301] =?UTF-8?q?#164=20[fix]=20=EB=B0=A9=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=EC=88=9C=EC=84=9C=EB=A1=9C=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/room/Participate.java | 4 +++- src/main/java/hous/server/domain/user/Onboarding.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/domain/room/Participate.java b/src/main/java/hous/server/domain/room/Participate.java index 8a4f3337..14d73825 100644 --- a/src/main/java/hous/server/domain/room/Participate.java +++ b/src/main/java/hous/server/domain/room/Participate.java @@ -45,7 +45,9 @@ public int compareTo(@NotNull Participate o) { return -1; } if (t1 == null && t2 == null) { - return 0; + Participate p1 = getOnboarding().getParticipates().get(0); + Participate p2 = o.getOnboarding().getParticipates().get(0); + return p1.getCreatedAt().compareTo(p2.getCreatedAt()); } return t1.getCreatedAt().compareTo(t2.getCreatedAt()); } diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index ffc71a35..b2e80fe6 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -140,7 +140,9 @@ public int compareTo(Onboarding o) { return -1; } if (t1 == null && t2 == null) { - return 0; + Participate p1 = getParticipates().get(0); + Participate p2 = o.getParticipates().get(0); + return p1.getCreatedAt().compareTo(p2.getCreatedAt()); } return t1.getCreatedAt().compareTo(t2.getCreatedAt()); } From f792aaa2971c7fb21fcb35e117bb4cb9972a2660 Mon Sep 17 00:00:00 2001 From: Joon Date: Tue, 18 Oct 2022 14:11:56 +0900 Subject: [PATCH 209/301] =?UTF-8?q?#167=20[fix]=20=EB=B0=A9=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC=ED=95=A0=20=EB=95=8C=20=EB=82=98=EC=9D=98=20Todo=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EB=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/todo/TodoRetrieveService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index f32eae9e..2c071ca0 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -176,6 +176,7 @@ public MyTodoInfoResponse getMyTodoInfo(Long userId) { Room room = RoomServiceUtils.findParticipatingRoom(user); List todos = room.getTodos(); List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, user.getOnboarding()).stream() + .filter(todo -> todo.getTakes().size() == 1) .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .collect(Collectors.toList()); return MyTodoInfoResponse.of(myTodos, user.getOnboarding()); From f703c1bc13d070a0d98504ee00841db2d422e324 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 18 Oct 2022 14:31:26 +0900 Subject: [PATCH 210/301] =?UTF-8?q?[fix]=20=EA=B3=B5=ED=86=B5=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/room/RoomService.java | 14 ++------------ .../hous/server/service/room/RoomServiceUtils.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index df2205f5..34f5747f 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -86,18 +86,8 @@ public void leaveRoom(Long userId) { List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); - - List participates = room.getParticipates(); - if (participates.size() > 1) { - room.deleteParticipate(participates.get(0)); - me.deleteParticipate(participates.get(0)); - participateRepository.delete(participates.get(0)); - } - // 방의 참가자가 나 혼자면 방을 나가고 삭제 - else { - me.deleteParticipate(participates.get(0)); - roomRepository.delete(room); - } + RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room); + // 내 배지, 알림 목록, 프로필 작성 내역, 테스트 결과 초기화 if (me.getRepresent() != null) { representRepository.delete(me.getRepresent()); diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 3b2d747d..346beabd 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -96,4 +96,16 @@ public static void deleteMyTodosTakeMe(TakeRepository takeRepository, DoneReposi } }); } + + public static void deleteParticipateUser(ParticipateRepository participateRepository, RoomRepository roomRepository, Onboarding me, Room room) { + List participates = room.getParticipates(); + if (participates.size() > 1) { + room.deleteParticipate(participates.get(0)); + me.deleteParticipate(participates.get(0)); + participateRepository.delete(participates.get(0)); + } else { + me.deleteParticipate(participates.get(0)); + roomRepository.delete(room); + } + } } From b12012d96158a3d6e565f67b801ae21970e9d738 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 18 Oct 2022 14:31:44 +0900 Subject: [PATCH 211/301] =?UTF-8?q?[fix]=20=EB=B0=A9=EC=97=90=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=ED=95=9C=20=EA=B2=BD=EC=9A=B0=EC=99=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20=EA=B2=BD=EC=9A=B0=EC=97=90=20=EB=94=B0=EB=9D=BC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/user/UserService.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 23e014e1..716ff679 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -12,6 +12,7 @@ import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; +import hous.server.domain.room.repository.ParticipateRepository; import hous.server.domain.room.repository.RoomRepository; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; @@ -59,6 +60,7 @@ public class UserService { private final DoneRepository doneRepository; private final TodoRepository todoRepository; private final RoomRepository roomRepository; + private final ParticipateRepository participateRepository; private final BadgeService badgeService; @@ -143,17 +145,20 @@ public void updateRepresentBadge(Long badgeId, Long userId) { public void deleteUser(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - Room room = RoomServiceUtils.findParticipatingRoom(user); Onboarding me = user.getOnboarding(); - - List todos = room.getTodos(); - List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); - RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); + Room room = me.getParticipates().get(0).getRoom(); + + if (room != null) { + List todos = room.getTodos(); + List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); + RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); + RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room); + if (room.getParticipates().isEmpty()) { + roomRepository.delete(room); + } + } userRepository.delete(user); - if (room.getParticipates().isEmpty()) { - roomRepository.delete(room); - } } public void acquireFeedbackBadge(Long userId) { From 92175db53cda193743c8f658c391e98a2ae9903d Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 18 Oct 2022 14:56:23 +0900 Subject: [PATCH 212/301] =?UTF-8?q?[docs]=20=EB=8B=B4=EB=8B=B9=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20'=EB=82=98'=EC=9D=B8=20todo=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/controller/todo/TodoRetrieveController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index ce86a199..75732087 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -155,7 +155,7 @@ public ResponseEntity>> getTodoAllMe @ApiOperation( value = "[인증] 마이 페이지(설정) - MY to-do 를 조회합니다.", - notes = "방에서 퇴사할 때 MY to-do 를 조회합니다." + notes = "방에서 퇴사 또는 방에 참가한 유저가 방 퇴사하기 전에 탈퇴 요청 시 담당자가 '나'인 to-do 를 조회합니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "나의 todo 정보 조회 성공입니다."), From eccc202deaf3b04a2637060a3dd8a3da1844053e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 18 Oct 2022 16:11:52 +0900 Subject: [PATCH 213/301] =?UTF-8?q?[fix]=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/todo/TodoRetrieveController.java | 2 +- .../java/hous/server/controller/user/UserController.java | 5 +---- src/main/java/hous/server/service/user/UserService.java | 8 +++----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 75732087..06f742e6 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -155,7 +155,7 @@ public ResponseEntity>> getTodoAllMe @ApiOperation( value = "[인증] 마이 페이지(설정) - MY to-do 를 조회합니다.", - notes = "방에서 퇴사 또는 방에 참가한 유저가 방 퇴사하기 전에 탈퇴 요청 시 담당자가 '나'인 to-do 를 조회합니다." + notes = "방에서 퇴사 또는 탈퇴 요청 시 방에 참여하고 있을 때 담당자가 '나'인 to-do 를 조회합니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "나의 todo 정보 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 89907d92..69a0fbf0 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -132,10 +132,7 @@ public ResponseEntity> updateRepresentBadge(@ApiParam(na @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, - message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" - + "2. 참가중인 방이 존재하지 않습니다.", - response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 716ff679..5e111194 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -146,16 +146,14 @@ public void updateRepresentBadge(Long badgeId, Long userId) { public void deleteUser(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding me = user.getOnboarding(); - Room room = me.getParticipates().get(0).getRoom(); + List participates = me.getParticipates(); - if (room != null) { + if (!participates.isEmpty()) { + Room room = participates.get(0).getRoom(); List todos = room.getTodos(); List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room); - if (room.getParticipates().isEmpty()) { - roomRepository.delete(room); - } } userRepository.delete(user); From d4c441870f8f7a7d158b5011d6a4b4f65126dd67 Mon Sep 17 00:00:00 2001 From: Joon Date: Thu, 20 Oct 2022 18:46:46 +0900 Subject: [PATCH 214/301] =?UTF-8?q?#170=20[chore]=20=EB=AC=B4=EC=A4=91?= =?UTF-8?q?=EB=8B=A8=20=EB=B0=B0=ED=8F=AC=20BlueGreen=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appspec.yml | 10 ++++-- scripts/deploy.sh | 27 ---------------- scripts/health_check.sh | 31 +++++++++++++++++++ scripts/run_new_was.sh | 25 +++++++++++++++ scripts/switch.sh | 25 +++++++++++++++ .../controller/health/HealthController.java | 15 +++++++++ 6 files changed, 104 insertions(+), 29 deletions(-) delete mode 100644 scripts/deploy.sh create mode 100644 scripts/health_check.sh create mode 100644 scripts/run_new_was.sh create mode 100644 scripts/switch.sh create mode 100644 src/main/java/hous/server/controller/health/HealthController.java diff --git a/appspec.yml b/appspec.yml index 3a72e74f..913a9b13 100644 --- a/appspec.yml +++ b/appspec.yml @@ -13,6 +13,12 @@ permissions: hooks: ApplicationStart: - - location: scripts/deploy.sh - timeout: 60 + - location: scripts/run_new_was.sh + timeout: 180 + runas: ubuntu + - location: scripts/health_check.sh + timeout: 180 + runas: ubuntu + - location: scripts/switch.sh + timeout: 180 runas: ubuntu diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100644 index 5608d522..00000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" - -BUILD_JAR=$(ls /home/ubuntu/hous/build/libs/*.jar) -JAR_NAME=$(basename $BUILD_JAR) -echo "> [$NOW_TIME] build 파일명: $JAR_NAME" >> /home/ubuntu/hous/deploy.log - -echo "> [$NOW_TIME] build 파일 복사" >> /home/ubuntu/hous/deploy.log -DEPLOY_PATH=/home/ubuntu/hous/ -cp $BUILD_JAR $DEPLOY_PATH - -echo "> [$NOW_TIME] 현재 실행중인 애플리케이션 pid 확인" >> /home/ubuntu/hous/deploy.log -CURRENT_PID=$(pgrep -f $JAR_NAME) - -if [ -z $CURRENT_PID ] -then - echo "> [$NOW_TIME] 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ubuntu/hous/deploy.log -else - echo "> [$NOW_TIME] kill -15 $CURRENT_PID" >> /home/ubuntu/hous/deploy.log - kill -15 $CURRENT_PID - sleep 20 -fi - -DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME - -echo "> [$NOW_TIME] DEPLOY_JAR 배포" >> /home/ubuntu/hous/deploy.log -nohup java -jar $DEPLOY_JAR >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & diff --git a/scripts/health_check.sh b/scripts/health_check.sh new file mode 100644 index 00000000..06bf83f0 --- /dev/null +++ b/scripts/health_check.sh @@ -0,0 +1,31 @@ +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1) +TARGET_PORT=0 + +# Toggle port Number +if [ ${CURRENT_PORT} -eq 8081 ]; then + TARGET_PORT=8082 +elif [ ${CURRENT_PORT} -eq 8082 ]; then + TARGET_PORT=8081 +else + echo "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/hous/deploy_err.log + exit 1 +fi + +echo "[$NOW_TIME] Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..." >> /home/ubuntu/hous/deploy.log + +for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10 +do + echo "[$NOW_TIME] #${RETRY_COUNT} trying..." >> /home/ubuntu/hous/deploy.log + RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/health) + + if [ ${RESPONSE_CODE} -eq 200 ]; then + echo "[$NOW_TIME] New WAS successfully running" >> /home/ubuntu/hous/deploy.log + exit 0 + elif [ ${RETRY_COUNT} -eq 10 ]; then + echo "[$NOW_TIME] Health check failed." >> /home/ubuntu/hous/deploy_err.log + exit 1 + fi + sleep 10 +done diff --git a/scripts/run_new_was.sh b/scripts/run_new_was.sh new file mode 100644 index 00000000..2d9d03e6 --- /dev/null +++ b/scripts/run_new_was.sh @@ -0,0 +1,25 @@ +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1) +TARGET_PORT=0 + +echo "[$NOW_TIME] Current port of running WAS is ${CURRENT_PORT}." >> /home/ubuntu/hous/deploy.log + +if [ ${CURRENT_PORT} -eq 8081 ]; then + TARGET_PORT=8082 +elif [ ${CURRENT_PORT} -eq 8082 ]; then + TARGET_PORT=8081 +else + echo "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/hous/deploy.log +fi + +TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') + +if [ ! -z ${TARGET_PID} ]; then + echo "[$NOW_TIME] Kill WAS running at ${TARGET_PORT}." >> /home/ubuntu/hous/deploy.log + sudo kill ${TARGET_PID} +fi + +nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/hous/build/libs/*.jar >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & +echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/hous/deploy.log +exit 0 diff --git a/scripts/switch.sh b/scripts/switch.sh new file mode 100644 index 00000000..e54a4469 --- /dev/null +++ b/scripts/switch.sh @@ -0,0 +1,25 @@ +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1) +TARGET_PORT=0 + +echo "[$NOW_TIME] Nginx currently proxies to ${CURRENT_PORT}." >> /home/ubuntu/hous/deploy.log + +# Toggle port number +if [ ${CURRENT_PORT} -eq 8081 ]; then + TARGET_PORT=8082 +elif [ ${CURRENT_PORT} -eq 8082 ]; then + TARGET_PORT=8081 +else + echo "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/hous/deploy.log + exit 1 +fi + +# Change proxying port into target port +echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" | tee /etc/nginx/conf.d/service-url.inc + +echo "[$NOW_TIME] Now Nginx proxies to ${TARGET_PORT}." >> /home/ubuntu/hous/deploy.log +# Reload nginx +sudo service nginx reload + +echo "[$NOW_TIME] Nginx reloaded." >> /home/ubuntu/hous/deploy.log diff --git a/src/main/java/hous/server/controller/health/HealthController.java b/src/main/java/hous/server/controller/health/HealthController.java new file mode 100644 index 00000000..4fa6a763 --- /dev/null +++ b/src/main/java/hous/server/controller/health/HealthController.java @@ -0,0 +1,15 @@ +package hous.server.controller.health; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +@ApiIgnore +@RestController +public class HealthController { + + @GetMapping("/health") + public String checkHealth() { + return "healthy"; + } +} From 6c515d1d3d94be355f10d31c43aa03124bb306c1 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 23 Oct 2022 17:00:38 +0900 Subject: [PATCH 215/301] =?UTF-8?q?#172=20[fix]=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EA=B0=B1=EC=8B=A0=20=EC=9D=91=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/auth/AuthController.java | 3 ++- .../service/auth/CreateTokenService.java | 10 +++++-- .../auth/dto/response/RefreshResponse.java | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/main/java/hous/server/service/auth/dto/response/RefreshResponse.java diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 8ec1c65c..3793fc26 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -13,6 +13,7 @@ import hous.server.service.auth.CommonAuthService; import hous.server.service.auth.CreateTokenService; import hous.server.service.auth.dto.request.TokenRequestDto; +import hous.server.service.auth.dto.response.RefreshResponse; import hous.server.service.auth.dto.response.TokenResponse; import hous.server.service.room.RoomService; import io.swagger.annotations.Api; @@ -118,7 +119,7 @@ public ResponseEntity> login(@Valid @RequestBody @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PostMapping("/auth/refresh") - public ResponseEntity> reissue(@Valid @RequestBody TokenRequestDto request) { + public ResponseEntity> reissue(@Valid @RequestBody TokenRequestDto request) { return SuccessResponse.success(SuccessCode.REISSUE_TOKEN_SUCCESS, createTokenService.reissueToken(request)); } diff --git a/src/main/java/hous/server/service/auth/CreateTokenService.java b/src/main/java/hous/server/service/auth/CreateTokenService.java index 2ba70e91..fb24f09d 100644 --- a/src/main/java/hous/server/service/auth/CreateTokenService.java +++ b/src/main/java/hous/server/service/auth/CreateTokenService.java @@ -6,7 +6,9 @@ import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.auth.dto.request.TokenRequestDto; +import hous.server.service.auth.dto.response.RefreshResponse; import hous.server.service.auth.dto.response.TokenResponse; +import hous.server.service.room.RoomService; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -25,13 +27,15 @@ public class CreateTokenService { private final RedisTemplate redisTemplate; + private final RoomService roomService; + @Transactional public TokenResponse createTokenInfo(Long userId) { return jwtProvider.createTokenInfo(userId); } @Transactional - public TokenResponse reissueToken(TokenRequestDto request) { + public RefreshResponse reissueToken(TokenRequestDto request) { Long userId = jwtProvider.getUserIdFromJwt(request.getAccessToken()); User user = UserServiceUtils.findUserById(userRepository, userId); if (!jwtProvider.validateToken(request.getRefreshToken())) { @@ -48,6 +52,8 @@ public TokenResponse reissueToken(TokenRequestDto request) { user.resetFcmToken(); throw new UnAuthorizedException(String.format("해당 리프레시 토큰 (%s) 의 정보가 일치하지 않습니다.", request.getRefreshToken())); } - return jwtProvider.createTokenInfo(userId); + TokenResponse token = jwtProvider.createTokenInfo(userId); + boolean isJoiningRoom = roomService.existsParticipatingRoomByUserId(userId); + return RefreshResponse.of(token, isJoiningRoom); } } diff --git a/src/main/java/hous/server/service/auth/dto/response/RefreshResponse.java b/src/main/java/hous/server/service/auth/dto/response/RefreshResponse.java new file mode 100644 index 00000000..d9692bb4 --- /dev/null +++ b/src/main/java/hous/server/service/auth/dto/response/RefreshResponse.java @@ -0,0 +1,27 @@ +package hous.server.service.auth.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class RefreshResponse { + + private TokenResponse token; + private boolean isJoiningRoom; + + @JsonProperty("isJoiningRoom") + public boolean isJoiningRoom() { + return isJoiningRoom; + } + + public static RefreshResponse of(TokenResponse token, boolean isJoiningRoom) { + return RefreshResponse.builder() + .token(token) + .isJoiningRoom(isJoiningRoom) + .build(); + } +} From 36997dd824bd79f6755f382b32c399f9aedc3f21 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 23 Oct 2022 21:34:05 +0900 Subject: [PATCH 216/301] =?UTF-8?q?#174=20[fix]=20testScore=20null=20?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EA=B3=A0=EB=A0=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/room/RoomService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index df2205f5..4a56da6c 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -104,7 +104,9 @@ public void leaveRoom(Long userId) { } acquireRepository.deleteAll(me.getAcquires()); notificationRepository.deleteAll(me.getNotifications()); - testScoreRepository.delete(me.getTestScore()); + if (me.getTestScore() != null) { + testScoreRepository.delete(me.getTestScore()); + } me.resetUserInfo(); me.resetBadge(); } From 424b84ad98d7a4cc35ce274ad47f47fc9f839c2f Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 23 Oct 2022 21:36:23 +0900 Subject: [PATCH 217/301] =?UTF-8?q?#174=20[chore]=20=EC=8A=AC=EB=9E=99=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B4=80=EB=A0=A8=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 ++ .github/workflows/pr-check.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 849f1522..e75e9185 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,6 +34,8 @@ jobs: AWS_REGION: ${{ secrets.AWS_REGION }} FIREBASE_URI: ${{ secrets.FIREBASE_URI }} FIREBASE_SERVICE_JSON: ${{ secrets.FIREBASE_SERVICE_JSON }} + SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} + SLACK_CHANNEL_MONITOR: ${{ secrets.SLACK_CHANNEL_MONITOR }} run: | touch application.properties diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 971d3e54..2c286b0a 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -34,6 +34,8 @@ jobs: AWS_REGION: ${{ secrets.AWS_REGION }} FIREBASE_URI: ${{ secrets.FIREBASE_URI }} FIREBASE_SERVICE_JSON: ${{ secrets.FIREBASE_SERVICE_JSON }} + SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} + SLACK_CHANNEL_MONITOR: ${{ secrets.SLACK_CHANNEL_MONITOR }} run: | touch application.properties From 505bce84c1860eb25685ae04e380a0d380214c2b Mon Sep 17 00:00:00 2001 From: Joon Date: Tue, 25 Oct 2022 13:03:45 +0900 Subject: [PATCH 218/301] =?UTF-8?q?#176=20[feat]=20=EA=B0=95=EC=A0=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 2 +- .../controller/auth/AuthController.java | 29 +++++++++++++- .../hous/server/service/auth/AuthService.java | 2 + .../service/auth/impl/AppleAuthService.java | 38 ++++++++++++++++++- .../service/auth/impl/KakaoAuthService.java | 38 ++++++++++++++++++- .../hous/server/service/user/UserService.java | 9 ++++- .../server/service/user/UserServiceUtils.java | 9 ----- 7 files changed, 113 insertions(+), 14 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index f1c262a4..a0fd7d68 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -71,8 +71,8 @@ public enum ErrorCode { */ CONFLICT_EXCEPTION(CONFLICT, "이미 존재합니다."), CONFLICT_USER_EXCEPTION(CONFLICT, "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), + CONFLICT_LOGIN_EXCEPTION(CONFLICT, "이미 로그인 중인 유저입니다."), CONFLICT_JOINED_ROOM_EXCEPTION(CONFLICT, "이미 참가중인 방이 있습니다."), - CONFLICT_FCM_TOKEN_EXCEPTION(CONFLICT, "fcm token 중복입니다."), /** * 415 Unsupported Media Type diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 3793fc26..9ec07775 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -90,7 +90,7 @@ public ResponseEntity> signUp(@Valid @RequestBody response = ErrorResponse.class), @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "fcm token 중복입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "이미 로그인 중인 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PostMapping("/auth/login") @@ -102,6 +102,33 @@ public ResponseEntity> login(@Valid @RequestBody return SuccessResponse.success(SuccessCode.LOGIN_SUCCESS, LoginResponse.of(userId, tokenInfo, isJoiningRoom)); } + @ApiOperation( + value = "로그인 페이지 - 강제 로그인을 요청합니다.", + notes = "카카오 로그인, 애플 로그인을 요청합니다.\n" + + "socialType - KAKAO (카카오), APPLE (애플)\n" + + "회원가입이 완료되지 않은 사용자일 경우 404 에러를 전달합니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "로그인 성공입니다."), + @ApiResponse( + code = 400, + message = "1. 유저의 socialType 를 입력해주세요. (socialType)\n" + + "2. access token 을 입력해주세요. (token)\n" + + "3. fcm token 을 입력해주세요. (fcmToken)", + response = ErrorResponse.class), + @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @PostMapping("/auth/login/force") + public ResponseEntity> forceLogin(@Valid @RequestBody LoginRequestDto request) { + AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); + Long userId = authService.forceLogin(request.toServiceDto()); + boolean isJoiningRoom = roomService.existsParticipatingRoomByUserId(userId); + TokenResponse tokenInfo = createTokenService.createTokenInfo(userId); + return SuccessResponse.success(SuccessCode.LOGIN_SUCCESS, LoginResponse.of(userId, tokenInfo, isJoiningRoom)); + } + @ApiOperation( value = "JWT 인증 - Access Token 을 갱신합니다.", notes = "만료된 Access Token 을 Refresh Token 으로 갱신합니다.\n" + diff --git a/src/main/java/hous/server/service/auth/AuthService.java b/src/main/java/hous/server/service/auth/AuthService.java index 8ba89abd..dee1d632 100644 --- a/src/main/java/hous/server/service/auth/AuthService.java +++ b/src/main/java/hous/server/service/auth/AuthService.java @@ -8,4 +8,6 @@ public interface AuthService { Long signUp(SignUpDto request); Long login(LoginDto request); + + Long forceLogin(LoginDto request); } diff --git a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java index 582bf3f3..10100503 100644 --- a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java @@ -1,5 +1,8 @@ package hous.server.service.auth.impl; +import hous.server.common.exception.ConflictException; +import hous.server.common.util.JwtUtils; +import hous.server.domain.common.RedisKey; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; @@ -10,9 +13,12 @@ import hous.server.service.user.UserService; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static hous.server.common.exception.ErrorCode.CONFLICT_USER_EXCEPTION; + @RequiredArgsConstructor @Service @Transactional @@ -26,6 +32,10 @@ public class AppleAuthService implements AuthService { private final UserService userService; + private final JwtUtils jwtProvider; + + private final RedisTemplate redisTemplate; + @Override public Long signUp(SignUpDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); @@ -36,7 +46,33 @@ public Long signUp(SignUpDto request) { public Long login(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); - UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); + if (conflictFcmTokenUser != null) { + jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); + conflictFcmTokenUser.resetFcmToken(); + } + String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); + if (refreshToken != null) { + throw new ConflictException(String.format("이미 로그인된 유저 (%s) 입니다.", user.getId()), CONFLICT_USER_EXCEPTION); + } + user.updateFcmToken(request.getFcmToken()); + return user.getId(); + } + + @Override + public Long forceLogin(LoginDto request) { + String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); + User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); + User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); + if (conflictFcmTokenUser != null) { + jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); + conflictFcmTokenUser.resetFcmToken(); + } + String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); + if (refreshToken != null) { + jwtProvider.expireRefreshToken(user.getId()); + user.resetFcmToken(); + } user.updateFcmToken(request.getFcmToken()); return user.getId(); } diff --git a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java index 1ce808d5..04ec8197 100644 --- a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java @@ -1,6 +1,9 @@ package hous.server.service.auth.impl; +import hous.server.common.exception.ConflictException; import hous.server.common.util.HttpHeaderUtils; +import hous.server.common.util.JwtUtils; +import hous.server.domain.common.RedisKey; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; @@ -12,9 +15,12 @@ import hous.server.service.user.UserService; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static hous.server.common.exception.ErrorCode.CONFLICT_USER_EXCEPTION; + @RequiredArgsConstructor @Service @Transactional @@ -28,6 +34,10 @@ public class KakaoAuthService implements AuthService { private final UserService userService; + private final JwtUtils jwtProvider; + + private final RedisTemplate redisTemplate; + @Override public Long signUp(SignUpDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); @@ -38,7 +48,33 @@ public Long signUp(SignUpDto request) { public Long login(LoginDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); - UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); + if (conflictFcmTokenUser != null) { + jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); + conflictFcmTokenUser.resetFcmToken(); + } + String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); + if (refreshToken != null) { + throw new ConflictException(String.format("이미 로그인된 유저 (%s) 입니다.", user.getId()), CONFLICT_USER_EXCEPTION); + } + user.updateFcmToken(request.getFcmToken()); + return user.getId(); + } + + @Override + public Long forceLogin(LoginDto request) { + KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); + User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); + User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); + if (conflictFcmTokenUser != null) { + jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); + conflictFcmTokenUser.resetFcmToken(); + } + String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); + if (refreshToken != null) { + jwtProvider.expireRefreshToken(user.getId()); + user.resetFcmToken(); + } user.updateFcmToken(request.getFcmToken()); return user.getId(); } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 23e014e1..39f3cf2b 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -1,5 +1,6 @@ package hous.server.service.user; +import hous.server.common.util.JwtUtils; import hous.server.domain.badge.Badge; import hous.server.domain.badge.BadgeInfo; import hous.server.domain.badge.Represent; @@ -62,6 +63,8 @@ public class UserService { private final BadgeService badgeService; + private final JwtUtils jwtProvider; + public Long registerUser(CreateUserRequestDto request) { UserServiceUtils.validateNotExistsUser(userRepository, request.getSocialId(), request.getSocialType()); User user = userRepository.save(User.newInstance( @@ -73,7 +76,11 @@ public Long registerUser(CreateUserRequestDto request) { request.getNickname(), request.getBirthday(), request.getIsPublic())); - UserServiceUtils.validateUniqueFcmToken(userRepository, request.getFcmToken()); + User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); + if (conflictFcmTokenUser != null) { + jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); + conflictFcmTokenUser.resetFcmToken(); + } user.updateFcmToken(request.getFcmToken()); user.setOnboarding(onboarding); return user.getId(); diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 8749adf7..50fb2e3f 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -46,15 +46,6 @@ public static User findUserById(UserRepository userRepository, Long userId) { return user; } - public static void validateUniqueFcmToken(UserRepository userRepository, String fcmToken) { - if (fcmToken != null) { - User user = userRepository.findUserByFcmToken(fcmToken); - if (user != null) { - throw new ConflictException(String.format("fcm token (%s) 중복입니다.", fcmToken), CONFLICT_FCM_TOKEN_EXCEPTION); - } - } - } - public static void validatePushSettingRequest(UpdatePushSettingRequestDto request, User user) { int notNullStatusCnt = 0; if (request.isPushNotification() != null) { From 6fd653d74e79471074e1f26882070f0fcba1facf Mon Sep 17 00:00:00 2001 From: Joon Date: Tue, 25 Oct 2022 15:01:02 +0900 Subject: [PATCH 219/301] =?UTF-8?q?#177=20[fix]=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/auth/AuthController.java | 6 +----- .../java/hous/server/service/auth/CommonAuthService.java | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 9ec07775..cbe07d66 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -157,11 +157,7 @@ public ResponseEntity> reissue(@Valid @RequestB @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" - + "2. 참가중인 방이 존재하지 않습니다.", - response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth diff --git a/src/main/java/hous/server/service/auth/CommonAuthService.java b/src/main/java/hous/server/service/auth/CommonAuthService.java index 48b85406..1f326fa1 100644 --- a/src/main/java/hous/server/service/auth/CommonAuthService.java +++ b/src/main/java/hous/server/service/auth/CommonAuthService.java @@ -3,7 +3,6 @@ import hous.server.common.util.JwtUtils; import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; -import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,7 +19,6 @@ public class CommonAuthService { public void logout(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - RoomServiceUtils.findParticipatingRoom(user); jwtProvider.expireRefreshToken(user.getId()); user.resetFcmToken(); } From 7a2f49045043c394c502c19359ffcef549a88da0 Mon Sep 17 00:00:00 2001 From: Joon Date: Tue, 25 Oct 2022 15:09:25 +0900 Subject: [PATCH 220/301] =?UTF-8?q?#177=20[refactor]=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EA=B3=B5=ED=86=B5=20=EB=A1=9C=EC=A7=81=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/auth/CommonAuthServiceUtils.java | 39 +++++++++++++++++++ .../service/auth/impl/AppleAuthService.java | 28 +++---------- .../service/auth/impl/KakaoAuthService.java | 28 +++---------- 3 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java diff --git a/src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java b/src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java new file mode 100644 index 00000000..6614516b --- /dev/null +++ b/src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java @@ -0,0 +1,39 @@ +package hous.server.service.auth; + +import hous.server.common.exception.ConflictException; +import hous.server.common.util.JwtUtils; +import hous.server.domain.common.RedisKey; +import hous.server.domain.user.User; +import hous.server.domain.user.repository.UserRepository; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; + +import static hous.server.common.exception.ErrorCode.CONFLICT_USER_EXCEPTION; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CommonAuthServiceUtils { + + public static void resetConflictFcmToken(UserRepository userRepository, JwtUtils jwtProvider, String fcmToken) { + User conflictFcmTokenUser = userRepository.findUserByFcmToken(fcmToken); + if (conflictFcmTokenUser != null) { + jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); + conflictFcmTokenUser.resetFcmToken(); + } + } + + public static void validateUniqueLogin(RedisTemplate redisTemplate, User user) { + String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); + if (refreshToken != null) { + throw new ConflictException(String.format("이미 로그인된 유저 (%s) 입니다.", user.getId()), CONFLICT_USER_EXCEPTION); + } + } + + public static void forceLogoutUser(RedisTemplate redisTemplate, JwtUtils jwtProvider, User user) { + String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); + if (refreshToken != null) { + jwtProvider.expireRefreshToken(user.getId()); + user.resetFcmToken(); + } + } +} diff --git a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java index 10100503..cc853e93 100644 --- a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java @@ -1,13 +1,12 @@ package hous.server.service.auth.impl; -import hous.server.common.exception.ConflictException; import hous.server.common.util.JwtUtils; -import hous.server.domain.common.RedisKey; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; import hous.server.external.client.apple.AppleTokenProvider; import hous.server.service.auth.AuthService; +import hous.server.service.auth.CommonAuthServiceUtils; import hous.server.service.auth.dto.request.LoginDto; import hous.server.service.auth.dto.request.SignUpDto; import hous.server.service.user.UserService; @@ -17,8 +16,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static hous.server.common.exception.ErrorCode.CONFLICT_USER_EXCEPTION; - @RequiredArgsConstructor @Service @Transactional @@ -46,15 +43,8 @@ public Long signUp(SignUpDto request) { public Long login(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); - User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); - if (conflictFcmTokenUser != null) { - jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); - conflictFcmTokenUser.resetFcmToken(); - } - String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); - if (refreshToken != null) { - throw new ConflictException(String.format("이미 로그인된 유저 (%s) 입니다.", user.getId()), CONFLICT_USER_EXCEPTION); - } + CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + CommonAuthServiceUtils.validateUniqueLogin(redisTemplate, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); } @@ -63,16 +53,8 @@ public Long login(LoginDto request) { public Long forceLogin(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); - User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); - if (conflictFcmTokenUser != null) { - jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); - conflictFcmTokenUser.resetFcmToken(); - } - String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); - if (refreshToken != null) { - jwtProvider.expireRefreshToken(user.getId()); - user.resetFcmToken(); - } + CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + CommonAuthServiceUtils.forceLogoutUser(redisTemplate, jwtProvider, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); } diff --git a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java index 04ec8197..467dae52 100644 --- a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java @@ -1,15 +1,14 @@ package hous.server.service.auth.impl; -import hous.server.common.exception.ConflictException; import hous.server.common.util.HttpHeaderUtils; import hous.server.common.util.JwtUtils; -import hous.server.domain.common.RedisKey; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; import hous.server.domain.user.repository.UserRepository; import hous.server.external.client.kakao.KakaoApiClient; import hous.server.external.client.kakao.dto.response.KakaoProfileResponse; import hous.server.service.auth.AuthService; +import hous.server.service.auth.CommonAuthServiceUtils; import hous.server.service.auth.dto.request.LoginDto; import hous.server.service.auth.dto.request.SignUpDto; import hous.server.service.user.UserService; @@ -19,8 +18,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static hous.server.common.exception.ErrorCode.CONFLICT_USER_EXCEPTION; - @RequiredArgsConstructor @Service @Transactional @@ -48,15 +45,8 @@ public Long signUp(SignUpDto request) { public Long login(LoginDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); - User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); - if (conflictFcmTokenUser != null) { - jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); - conflictFcmTokenUser.resetFcmToken(); - } - String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); - if (refreshToken != null) { - throw new ConflictException(String.format("이미 로그인된 유저 (%s) 입니다.", user.getId()), CONFLICT_USER_EXCEPTION); - } + CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + CommonAuthServiceUtils.validateUniqueLogin(redisTemplate, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); } @@ -65,16 +55,8 @@ public Long login(LoginDto request) { public Long forceLogin(LoginDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); - User conflictFcmTokenUser = userRepository.findUserByFcmToken(request.getFcmToken()); - if (conflictFcmTokenUser != null) { - jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); - conflictFcmTokenUser.resetFcmToken(); - } - String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); - if (refreshToken != null) { - jwtProvider.expireRefreshToken(user.getId()); - user.resetFcmToken(); - } + CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + CommonAuthServiceUtils.forceLogoutUser(redisTemplate, jwtProvider, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); } From e6ce1c844bb477fa37978b66a076d08b9b53ebfe Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Tue, 25 Oct 2022 20:11:17 +0900 Subject: [PATCH 221/301] =?UTF-8?q?#180=20[fix]=20application.properties?= =?UTF-8?q?=20->=20yml=20=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 62 +++++++------------ .github/workflows/pr-check.yml | 58 ++++++----------- .../server/service/slack/SlackService.java | 7 +-- 3 files changed, 44 insertions(+), 83 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 035f4a27..b31e4b1b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,53 +21,35 @@ jobs: - name: create application.properties file working-directory: ./src/main/resources env: - MYSQL_URL: ${{ secrets.MYSQL_URL }} - MYSQL_USERNAME: ${{ secrets.MYSQL_USERNAME}} - MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD}} - MYSQL_DRIVER_CLASS_NAME: ${{ secrets.MYSQL_DRIVER_CLASS_NAME}} - REDIS_HOST: ${{ secrets.REDIS_HOST }} - REDIS_PORT: ${{ secrets.REDIS_PORT }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} AWS_S3_ACCESS_KEY: ${{ secrets.AWS_S3_ACCESS_KEY }} AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} AWS_REGION: ${{ secrets.AWS_REGION }} - FIREBASE_URI: ${{ secrets.FIREBASE_URI }} - FIREBASE_SERVICE_JSON: ${{ secrets.FIREBASE_SERVICE_JSON }} - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} - SLACK_CHANNEL_MONITOR: ${{ secrets.SLACK_CHANNEL_MONITOR }} + APPLICATION_YML: ${{ secrets.APPLICATION_YML }} + APPLICATION_PROD_YML: ${{ secrets.APPLICATION_PROD_YML }} + APPLICATION_AWS_YML: ${{ secrets.APPLICATION_AWS_YML }} + APPLICATION_FIREBASE_YML: ${{ secrets.APPLICATION_FIREBASE_YML }} + APPLICATION_JWT_YML: ${{ secrets.APPLICATION_JWT_YML }} + APPLICATION_SLACK_YML: ${{ secrets.APPLICATION_SLACK_YML }} + FIREBASE_SERVICE_KEY_JSON: ${{ secrets.FIREBASE_SERVICE_KEY_JSON }} run: | - touch application.properties - echo server.servlet.encoding.charset=UTF-8 >> application.properties - echo server.servlet.encoding.force=true >> application.properties - echo spring.profiles.default=prod >> application.properties - echo spring.servlet.multipart.max-file-size=10MB >> application.properties - echo spring.servlet.multipart.max-request-size=10MB >> application.properties - echo logging.level.org.hibernate.type.descriptor.sql=trace >> application.properties - echo logging.level.com.amazonaws.util.EC2MetadataUtils=error >> application.properties - echo spring.datasource.url=$MYSQL_URL >> application.properties - echo spring.datasource.username=$MYSQL_USERNAME >> application.properties - echo spring.datasource.password=$MYSQL_PASSWORD >> application.properties - echo spring.datasource.driver-class-name=$MYSQL_DRIVER_CLASS_NAME >> application.properties - echo spring.jpa.hibernate.ddl-auto=update >> application.properties - echo spring.jpa.properties.hibernate.format_sql=true >> application.properties - echo spring.jpa.properties.hibernate.default_batch_fetch_size=1000 >> application.properties - echo spring.redis.host=$REDIS_HOST >> application.properties - echo spring.redis.port=$REDIS_PORT >> application.properties - echo jwt.secret=$JWT_SECRET >> application.properties - echo cloud.aws.credentials.accessKey=$AWS_S3_ACCESS_KEY >> application.properties - echo cloud.aws.credentials.secretKey=$AWS_S3_SECRET_KEY >> application.properties - echo cloud.aws.s3.bucket=$AWS_S3_BUCKET >> application.properties - echo cloud.aws.region.static=$AWS_REGION >> application.properties - echo cloud.aws.stack.auto=false >> application.properties - echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties - echo slack.token=$SLACK_TOKEN >> application.properties - echo slack.channel.monitor=$SLACK_CHANNEL_MONITOR >> application.properties + touch application.yml + touch application-prod.yml + touch application-aws.yml + touch application-firebase.yml + touch application-jwt.yml + touch application-slack.yml + echo $APPLICATION_YML >> application.yml + echo $APPLICATION_PROD_YML >> application-prod.yml + echo $APPLICATION_AWS_YML >> application-aws.yml + echo $APPLICATION_FIREBASE_YML >> application-firebase.yml + echo $APPLICATION_JWT_YML >> application-jwt.yml + echo $APPLICATION_SLACK_YML >> application-slack.yml mkdir firebase touch ./firebase/firebase_service_key.json - echo $FIREBASE_SERVICE_JSON >> ./firebase/firebase_service_key.json + echo $FIREBASE_SERVICE_KEY_JSON >> ./firebase/firebase_service_key.json - name: Set up JDK 11 uses: actions/setup-java@v1 @@ -97,7 +79,9 @@ jobs: aws-region: ${{ secrets.AWS_REGION }} - name: Upload to S3 - run: aws s3 cp --region ap-northeast-2 ./code-deploy.zip s3://$S3_BUCKET_NAME/code-deploy.zip + run: | + echo $S3_BUCKET_NAME + aws s3 cp --region ap-northeast-2 ./code-deploy.zip s3://$S3_BUCKET_NAME/code-deploy.zip - name: Code Deploy run: aws deploy create-deployment diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 2c286b0a..960fe2f9 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -21,53 +21,35 @@ jobs: - name: create application.properties file working-directory: ./src/main/resources env: - MYSQL_URL: ${{ secrets.MYSQL_URL }} - MYSQL_USERNAME: ${{ secrets.MYSQL_USERNAME}} - MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD}} - MYSQL_DRIVER_CLASS_NAME: ${{ secrets.MYSQL_DRIVER_CLASS_NAME}} - REDIS_HOST: ${{ secrets.REDIS_HOST }} - REDIS_PORT: ${{ secrets.REDIS_PORT }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} AWS_S3_ACCESS_KEY: ${{ secrets.AWS_S3_ACCESS_KEY }} AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} AWS_REGION: ${{ secrets.AWS_REGION }} - FIREBASE_URI: ${{ secrets.FIREBASE_URI }} - FIREBASE_SERVICE_JSON: ${{ secrets.FIREBASE_SERVICE_JSON }} - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} - SLACK_CHANNEL_MONITOR: ${{ secrets.SLACK_CHANNEL_MONITOR }} + APPLICATION_YML: ${{ secrets.APPLICATION_YML }} + APPLICATION_PROD_YML: ${{ secrets.APPLICATION_PROD_YML }} + APPLICATION_AWS_YML: ${{ secrets.APPLICATION_AWS_YML }} + APPLICATION_FIREBASE_YML: ${{ secrets.APPLICATION_FIREBASE_YML }} + APPLICATION_JWT_YML: ${{ secrets.APPLICATION_JWT_YML }} + APPLICATION_SLACK_YML: ${{ secrets.APPLICATION_SLACK_YML }} + FIREBASE_SERVICE_KEY_JSON: ${{ secrets.FIREBASE_SERVICE_KEY_JSON }} run: | - touch application.properties - echo server.servlet.encoding.charset=UTF-8 >> application.properties - echo server.servlet.encoding.force=true >> application.properties - echo spring.profiles.default=prod >> application.properties - echo spring.servlet.multipart.max-file-size=10MB >> application.properties - echo spring.servlet.multipart.max-request-size=10MB >> application.properties - echo logging.level.org.hibernate.type.descriptor.sql=trace >> application.properties - echo logging.level.com.amazonaws.util.EC2MetadataUtils=error >> application.properties - echo spring.datasource.url=$MYSQL_URL >> application.properties - echo spring.datasource.username=$MYSQL_USERNAME >> application.properties - echo spring.datasource.password=$MYSQL_PASSWORD >> application.properties - echo spring.datasource.driver-class-name=$MYSQL_DRIVER_CLASS_NAME >> application.properties - echo spring.jpa.hibernate.ddl-auto=update >> application.properties - echo spring.jpa.properties.hibernate.format_sql=true >> application.properties - echo spring.jpa.properties.hibernate.default_batch_fetch_size=1000 >> application.properties - echo spring.redis.host=$REDIS_HOST >> application.properties - echo spring.redis.port=$REDIS_PORT >> application.properties - echo jwt.secret=$JWT_SECRET >> application.properties - echo cloud.aws.credentials.accessKey=$AWS_S3_ACCESS_KEY >> application.properties - echo cloud.aws.credentials.secretKey=$AWS_S3_SECRET_KEY >> application.properties - echo cloud.aws.s3.bucket=$AWS_S3_BUCKET >> application.properties - echo cloud.aws.region.static=$AWS_REGION >> application.properties - echo cloud.aws.stack.auto=false >> application.properties - echo cloud.firebase.credentials.uri=$FIREBASE_URI >> application.properties - echo slack.token=$SLACK_TOKEN >> application.properties - echo slack.channel.monitor=$SLACK_CHANNEL_MONITOR >> application.properties + touch application.yml + touch application-prod.yml + touch application-aws.yml + touch application-firebase.yml + touch application-jwt.yml + touch application-slack.yml + echo $APPLICATION_YML >> application.yml + echo $APPLICATION_PROD_YML >> application-prod.yml + echo $APPLICATION_AWS_YML >> application-aws.yml + echo $APPLICATION_FIREBASE_YML >> application-firebase.yml + echo $APPLICATION_JWT_YML >> application-jwt.yml + echo $APPLICATION_SLACK_YML >> application-slack.yml mkdir firebase touch ./firebase/firebase_service_key.json - echo $FIREBASE_SERVICE_JSON >> ./firebase/firebase_service_key.json + echo $FIREBASE_SERVICE_KEY_JSON >> ./firebase/firebase_service_key.json - name: Set up JDK 11 uses: actions/setup-java@v1 diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java index 61fd572a..632c299b 100644 --- a/src/main/java/hous/server/service/slack/SlackService.java +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -38,20 +38,15 @@ public class SlackService { private static final String SLACK_ERROR_STACK = "*Error Stack:*\n"; public void sendSlackMessage(Exception exception) { - log.info("함수 들어옴"); if (profile.equals("prod")) { - log.info("[test] prod start"); try { + log.info(channel); Slack slack = Slack.getInstance(); List attachments = createSlackAttachment(exception); slack.methods(token).chatPostMessage(req -> req.channel(channel) .attachments(attachments) .text(SLACK_MESSAGE_TITLE)); - log.info(token); - log.info(channel); - log.info(attachments.toString()); - log.info("[test] prod 슬랙 전송 완료"); } catch (SlackApiException | IOException e) { log.error(e.getMessage(), e); } From a9f672f9b1ba18bca5919b218276b36a8d732469 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 27 Oct 2022 20:58:45 +0900 Subject: [PATCH 222/301] =?UTF-8?q?#183=20[fix]=20TestScore=20null=20?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0,=20=EA=B0=81=20=EC=A0=90?= =?UTF-8?q?=EC=88=98=200=EC=A0=90=EC=9C=BC=EB=A1=9C=20=EC=A0=84=EB=8B=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/dto/response/UserInfoResponse.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index 339cf61a..d27d424f 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -52,13 +52,23 @@ public static class TestScoreResponse { private int introversion; public static TestScoreResponse of(TestScore testScore) { - return TestScoreResponse.builder() - .light(testScore.getLight()) - .noise(testScore.getNoise()) - .smell(testScore.getSmell()) - .clean(testScore.getClean()) - .introversion(testScore.getIntroversion()) - .build(); + if (testScore == null) { + return TestScoreResponse.builder() + .light(0) + .noise(0) + .smell(0) + .clean(0) + .introversion(0) + .build(); + } else { + return TestScoreResponse.builder() + .light(testScore.getLight()) + .noise(testScore.getNoise()) + .smell(testScore.getSmell()) + .clean(testScore.getClean()) + .introversion(testScore.getIntroversion()) + .build(); + } } } From 9f1d33c19ce803a32b6d3a7370054b3093ccefb4 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 28 Oct 2022 23:46:18 +0900 Subject: [PATCH 223/301] =?UTF-8?q?#185=20[fix]=20=EC=84=B1=ED=96=A5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8B=9C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20response=EC=99=80=20=ED=95=A8=EA=BB=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EB=90=9C=20Personality=20color=20=EC=A0=84?= =?UTF-8?q?=EB=8B=AC=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 1 + .../controller/user/UserController.java | 11 +++++----- .../hous/server/service/user/UserService.java | 4 +++- .../server/service/user/UserServiceUtils.java | 2 +- .../UpdatePersonalityColorResponse.java | 21 +++++++++++++++++++ 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/main/java/hous/server/service/user/dto/response/UpdatePersonalityColorResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index 6d2d1e52..c1b9b370 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -48,6 +48,7 @@ public enum SuccessCode { // 성향 GET_PERSONALITY_INFO_SUCCESS(OK, "성향 정보 조회 성공입니다."), GET_PERSONALITY_TEST_INFO_SUCCESS(OK, "성향테스트 정보 조회 성공입니다."), + UPDATE_PERSONALITY_TEST_SUCCESS(OK, "성향테스트 수정 성공입니다."), // 배지 GET_BADGE_INFO_SUCCESS(OK, "나의 배지 목록 조회 성공입니다."), diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 69a0fbf0..943cedf2 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -2,12 +2,14 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.user.UserService; import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; +import hous.server.service.user.dto.response.UpdatePersonalityColorResponse; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -80,10 +82,10 @@ public ResponseEntity> updateUserPushSetting(@Valid @Req @ApiOperation( value = "[인증] 마이 페이지(Profile 뷰) - 성향테스트 결과 정보를 수정합니다.", - notes = "성향테스트 결과를 수정합니다." + notes = "성향테스트 결과를 후 변경된 성향테스트 색상을 전달합니다." ) @ApiResponses(value = { - @ApiResponse(code = 200, message = "성공입니다."), + @ApiResponse(code = 200, message = "성향테스트 수정 성공입니다."), @ApiResponse( code = 400, message = "성향 테스트의 각 성향 점수는 최소 3점, 최대 9점입니다. (smell, light, noise, clean, introversion)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @@ -95,10 +97,9 @@ public ResponseEntity> updateUserPushSetting(@Valid @Req }) @Auth @PutMapping("/user/personality") - public ResponseEntity> updateUserTestScore( + public ResponseEntity> updateUserTestScore( @Valid @RequestBody UpdateTestScoreRequestDto request, @ApiIgnore @UserId Long userId) { - userService.updateUserTestScore(request, userId); - return SuccessResponse.OK; + return SuccessResponse.success(SuccessCode.UPDATE_PERSONALITY_TEST_SUCCESS, userService.updateUserTestScore(request, userId)); } @ApiOperation( diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 3ecde27f..1c7ec748 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -35,6 +35,7 @@ import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; +import hous.server.service.user.dto.response.UpdatePersonalityColorResponse; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -102,7 +103,7 @@ public void updateUserPushSetting(UpdatePushSettingRequestDto request, Long user setting.updatePushSetting(request); } - public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) { + public UpdatePersonalityColorResponse updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); Onboarding me = user.getOnboarding(); @@ -138,6 +139,7 @@ public void updateUserTestScore(UpdateTestScoreRequestDto request, Long userId) badgeService.acquireBadge(onboarding.getUser(), BadgeInfo.OUR_HOUSE_HOMIES); }); } + return UpdatePersonalityColorResponse.of(personality); } public void updateRepresentBadge(Long badgeId, Long userId) { diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 50fb2e3f..4e85387d 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -108,7 +108,7 @@ public static Personality getPersonalityColorByTestScore(PersonalityRepository p } else if (totalTestScore >= 40 && totalTestScore <= 45) { return personalityRepository.findPersonalityByColor(PersonalityColor.GREEN); } - return null; + return personalityRepository.findPersonalityByColor(PersonalityColor.GRAY); } public static List toMeFirstList(List onboardings, Onboarding me) { diff --git a/src/main/java/hous/server/service/user/dto/response/UpdatePersonalityColorResponse.java b/src/main/java/hous/server/service/user/dto/response/UpdatePersonalityColorResponse.java new file mode 100644 index 00000000..24a17f48 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/UpdatePersonalityColorResponse.java @@ -0,0 +1,21 @@ +package hous.server.service.user.dto.response; + +import hous.server.domain.personality.Personality; +import hous.server.domain.personality.PersonalityColor; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class UpdatePersonalityColorResponse { + + private PersonalityColor color; + + public static UpdatePersonalityColorResponse of(Personality personality) { + return UpdatePersonalityColorResponse.builder() + .color(personality.getColor()) + .build(); + } +} From 476d7354ad09772c62839154986c87d09ddaacd6 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 01:07:10 +0900 Subject: [PATCH 224/301] =?UTF-8?q?#187=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20api=201=EA=B0=9C=EB=A1=9C=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/rule/RuleController.java | 44 ++++--------------- .../java/hous/server/domain/room/Room.java | 5 +++ .../java/hous/server/domain/rule/Rule.java | 10 ++--- .../hous/server/service/rule/RuleService.java | 24 +++++----- .../dto/request/UpdateRuleRequestDto.java | 10 ++--- 5 files changed, 32 insertions(+), 61 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index aa13ab1d..928748ef 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -8,7 +8,10 @@ import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; -import io.swagger.annotations.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -56,43 +59,14 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr } @ApiOperation( - value = "[인증] 규칙 페이지 - 규칙 1개를 수정합니다.", - notes = "규칙 내용 수정을 요청합니다." - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "성공입니다."), - @ApiResponse( - code = 400, - message = "1. 규칙 내용을 입력해주세요. (name)\n" - + "2. 규칙은 20 글자 이내로 입력해주세요. (name)", - response = ErrorResponse.class), - @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" - + "2. 존재하지 않는 방입니다.\n" - + "3. 존재하지 않는 규칙입니다.", - response = ErrorResponse.class), - @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) - }) - @Auth - @PutMapping("/rule/{ruleId}") - public ResponseEntity> updateRule(@ApiParam(name = "ruleId", value = "수정할 rule 의 id", required = true, example = "1") - @PathVariable Long ruleId, - @Valid @RequestBody UpdateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { - ruleService.updateRule(request, ruleId, userId); - return SuccessResponse.OK; - } - - @ApiOperation( - value = "[인증] 규칙 페이지 - 규칙 여러 개의 정렬을 수정합니다.", - notes = "전체 규칙 id 리스트를 정렬 순서에 따라 resquest dto에 리스트 형태로 담아주세요." + value = "[인증] 규칙 페이지 - 규칙 여러 개의 정렬 및 내용을 수정합니다.", + notes = "전체 규칙 id와 내용이 담긴 리스트를 정렬 순서에 따라 resquest dto에 리스트 형태로 담아주세요." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 403, message = "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다.", response = ErrorResponse.class), @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" @@ -103,9 +77,9 @@ public ResponseEntity> updateRule(@ApiParam(name = "rule }) @Auth @PutMapping("/rules") - public ResponseEntity> updateSortByRules(@Valid @RequestBody ModifyRuleReqeustDto request, + public ResponseEntity> updateSortByRules(@Valid @RequestBody UpdateRuleRequestDto request, @ApiIgnore @UserId Long userId) { - ruleService.updateSortByRule(request, userId); + ruleService.updateRule(request, userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index d3fe8f4a..ecd61484 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -79,6 +79,11 @@ public void addRules(List rules) { this.rulesCnt += rules.size(); } + public void updateRules(List rules) { + this.rules.clear(); + this.rules.addAll(rules); + } + public void deleteRule(Rule rule) { this.rules.remove(rule); this.rulesCnt -= 1; diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index ec270540..7e0c7b15 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -2,7 +2,6 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Room; -import hous.server.service.rule.dto.request.UpdateRuleRequestDto; import lombok.*; import javax.persistence.*; @@ -36,12 +35,9 @@ public static Rule newInstance(Room room, String name, int idx) { .build(); } - public void updateRuleName(UpdateRuleRequestDto request) { - this.name = request.getName(); - } - - public void updateRuleIndex(int ruleIdx) { - this.idx = ruleIdx; + public void updateRule(String name, int idx) { + this.name = name; + this.idx = idx; } } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index e9e2e189..8bcc3cb7 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.stream.IntStream; @RequiredArgsConstructor @Service @@ -73,22 +74,17 @@ public void createRule(CreateRuleRequestDto request, Long userId) { usersExceptMe.forEach(userExceptMe -> notificationService.sendNewRuleNotification(userExceptMe, rules)); } - public void updateRule(UpdateRuleRequestDto request, Long ruleId, Long userId) { + public void updateRule(UpdateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, ruleId, room); - rule.updateRuleName(request); - } - - public void updateSortByRule(ModifyRuleReqeustDto request, Long userId) { - User user = UserServiceUtils.findUserById(userRepository, userId); - Room room = RoomServiceUtils.findParticipatingRoom(user); - RuleServiceUtils.validateRequestRuleCounts(room, request.getRulesIdList().size()); - for (int idx = 0; idx < request.getRulesIdList().size(); idx++) { - Long ruleId = request.getRulesIdList().get(idx); - Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, ruleId, room); - rule.updateRuleIndex(idx); - } + RuleServiceUtils.validateRequestRuleCounts(room, request.getRules().size()); + List rules = IntStream.range(0, request.getRules().size()) + .mapToObj(idx -> { + Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); + rule.updateRule(request.getRules().get(idx).getName(), idx); + return rule; + }).collect(Collectors.toList()); + room.updateRules(rules); } public void deleteRules(ModifyRuleReqeustDto request, Long userId) { diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java index 26785301..7ec94b21 100644 --- a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java @@ -1,22 +1,22 @@ package hous.server.service.rule.dto.request; import hous.server.domain.common.Constraint; +import hous.server.service.rule.dto.response.RuleInfoResponse; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; +import java.util.List; @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class UpdateRuleRequestDto { - @ApiModelProperty(value = "규칙 내용", example = "우리집 대장은 김또순") - @NotBlank(message = "{rule.name.notBlank") - @Size(max = Constraint.RULE_NAME_MAX, message = "{rule.name.max}") - private String name; + @ApiModelProperty(value = "수정된 규칙 리스트") + @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") + private List rules; } From 9e897d5602333c52d3de27a7c20d1fa2961ec265 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 01:11:02 +0900 Subject: [PATCH 225/301] =?UTF-8?q?#187=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=8B=9C=20=EB=82=B4=EC=9A=A9=EC=9D=B4=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EB=90=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20idx=EB=A7=8C=20=EC=88=98=EC=A0=95=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20if=EB=B6=84=EA=B8=B0=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/rule/Rule.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index 7e0c7b15..ed2a799e 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -36,8 +36,11 @@ public static Rule newInstance(Room room, String name, int idx) { } public void updateRule(String name, int idx) { - this.name = name; this.idx = idx; + if (this.name.equals(name)) { + return; + } + this.name = name; } } From 8eea8112c744ae8bedc3309e99986d483f378750 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 01:12:29 +0900 Subject: [PATCH 226/301] =?UTF-8?q?#187=20[rename]=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/rule/RuleController.java | 4 ++-- src/main/java/hous/server/service/rule/RuleService.java | 4 ++-- .../{ModifyRuleReqeustDto.java => DeleteRuleReqeustDto.java} | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/main/java/hous/server/service/rule/dto/request/{ModifyRuleReqeustDto.java => DeleteRuleReqeustDto.java} (94%) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 928748ef..991d954a 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -6,7 +6,7 @@ import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleService; import hous.server.service.rule.dto.request.CreateRuleRequestDto; -import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; +import hous.server.service.rule.dto.request.DeleteRuleReqeustDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -101,7 +101,7 @@ public ResponseEntity> updateSortByRules(@Valid @Request }) @Auth @DeleteMapping("/rules") - public ResponseEntity> deleteRules(@Valid @RequestBody ModifyRuleReqeustDto request, + public ResponseEntity> deleteRules(@Valid @RequestBody DeleteRuleReqeustDto request, @ApiIgnore @UserId Long userId) { ruleService.deleteRules(request, userId); return SuccessResponse.OK; diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 8bcc3cb7..82cf867f 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -15,7 +15,7 @@ import hous.server.service.notification.NotificationService; import hous.server.service.room.RoomServiceUtils; import hous.server.service.rule.dto.request.CreateRuleRequestDto; -import hous.server.service.rule.dto.request.ModifyRuleReqeustDto; +import hous.server.service.rule.dto.request.DeleteRuleReqeustDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; @@ -87,7 +87,7 @@ public void updateRule(UpdateRuleRequestDto request, Long userId) { room.updateRules(rules); } - public void deleteRules(ModifyRuleReqeustDto request, Long userId) { + public void deleteRules(DeleteRuleReqeustDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); request.getRulesIdList().forEach(ruleId -> { diff --git a/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java b/src/main/java/hous/server/service/rule/dto/request/DeleteRuleReqeustDto.java similarity index 94% rename from src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java rename to src/main/java/hous/server/service/rule/dto/request/DeleteRuleReqeustDto.java index b5ec792f..8dcd6f78 100644 --- a/src/main/java/hous/server/service/rule/dto/request/ModifyRuleReqeustDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/DeleteRuleReqeustDto.java @@ -13,7 +13,7 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ModifyRuleReqeustDto { +public class DeleteRuleReqeustDto { @ApiModelProperty(value = "규칙 id 배열", example = "[12, 13, 14, ...]") @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") From 590b6e2a2c06c9548ac9c4fc3dba24a1ae66514b Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 21:08:19 +0900 Subject: [PATCH 227/301] =?UTF-8?q?#185=20[docs]=20API=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=EC=97=90=20=EC=96=B4=EC=83=89=ED=95=9C=20?= =?UTF-8?q?=EC=9B=8C=EB=94=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 943cedf2..e61e6a71 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -82,7 +82,7 @@ public ResponseEntity> updateUserPushSetting(@Valid @Req @ApiOperation( value = "[인증] 마이 페이지(Profile 뷰) - 성향테스트 결과 정보를 수정합니다.", - notes = "성향테스트 결과를 후 변경된 성향테스트 색상을 전달합니다." + notes = "성향테스트 결과를 수정 후 변경된 성향테스트 색상을 전달합니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성향테스트 수정 성공입니다."), From 624a01d4a05baacf99bc45aedfbb36338fd79544 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 21:10:21 +0900 Subject: [PATCH 228/301] =?UTF-8?q?#187=20[fix]=20=EB=8D=94=EC=9D=B4?= =?UTF-8?q?=EC=83=81=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/messages/validation.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 6a10e512..20744c4d 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -24,5 +24,4 @@ todo.isPushNotification.notNull=todo \uC758 \uD478\uC26C \uC54C\uB9BC \uC5EC\uBD todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. -rule.name.max=\uADDC\uCE59\uC740 20 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. From a2095c2af7289107355f454f9f4fd7ab42a80309 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 23:51:40 +0900 Subject: [PATCH 229/301] =?UTF-8?q?#187=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=ED=9B=84=20room=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=95=88=EC=97=90=20=EC=9E=88=EB=8A=94=20rule=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/room/Room.java | 5 ++--- .../java/hous/server/service/rule/RuleService.java | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index ecd61484..fcca4f80 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -79,9 +79,8 @@ public void addRules(List rules) { this.rulesCnt += rules.size(); } - public void updateRules(List rules) { - this.rules.clear(); - this.rules.addAll(rules); + public void updateRule(Rule rule) { + this.rules.set(rules.indexOf(rule), rule); } public void deleteRule(Rule rule) { diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 82cf867f..bb9287a3 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -78,12 +78,12 @@ public void updateRule(UpdateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); RuleServiceUtils.validateRequestRuleCounts(room, request.getRules().size()); - List rules = IntStream.range(0, request.getRules().size()) + IntStream.range(0, request.getRules().size()).forEach(idx -> { .mapToObj(idx -> { - Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); - rule.updateRule(request.getRules().get(idx).getName(), idx); - return rule; - }).collect(Collectors.toList()); + Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); + rule.updateRule(request.getRules().get(idx).getName(), idx); + room.updateRule(rule); + }); room.updateRules(rules); } From c398b11b1524f5d4ab8e2240c76923aba9572072 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 23:52:44 +0900 Subject: [PATCH 230/301] =?UTF-8?q?#187=20[fix]=20idx,=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=EA=B0=84,=20id=20=EC=9A=B0=EC=84=A0=EC=88=9C?= =?UTF-8?q?=EC=9C=84=20=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/rule/Rule.java | 16 ++++++++++++---- .../rule/dto/response/RuleInfoResponse.java | 3 +-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/domain/rule/Rule.java b/src/main/java/hous/server/domain/rule/Rule.java index ed2a799e..47244701 100644 --- a/src/main/java/hous/server/domain/rule/Rule.java +++ b/src/main/java/hous/server/domain/rule/Rule.java @@ -3,6 +3,7 @@ import hous.server.domain.common.AuditingTimeEntity; import hous.server.domain.room.Room; import lombok.*; +import org.jetbrains.annotations.NotNull; import javax.persistence.*; @@ -11,7 +12,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) -public class Rule extends AuditingTimeEntity { +public class Rule extends AuditingTimeEntity implements Comparable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -37,10 +38,17 @@ public static Rule newInstance(Room room, String name, int idx) { public void updateRule(String name, int idx) { this.idx = idx; - if (this.name.equals(name)) { - return; - } this.name = name; } + @Override + public int compareTo(@NotNull Rule o) { + if (idx == o.idx) { + if (o.getCreatedAt().compareTo(getCreatedAt()) == 0) { + return Long.compare(id, o.id); + } + return getCreatedAt().compareTo(o.getCreatedAt()); + } + return Integer.compare(idx, o.idx); + } } diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java index 7a41c498..cace0eb0 100644 --- a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java @@ -3,7 +3,6 @@ import hous.server.domain.rule.Rule; import lombok.*; -import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -27,7 +26,7 @@ public static RuleInfoResponse of(Rule rule) { public static List of(List rules) { return rules.stream() - .sorted(Comparator.comparing(Rule::getIdx)) + .sorted(Rule::compareTo) .map(RuleInfoResponse::of).collect(Collectors.toList()); } } From f598fb87543a4feda648c356010e8f8ca41823b2 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 29 Oct 2022 23:53:26 +0900 Subject: [PATCH 231/301] =?UTF-8?q?#187=20[rename]=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/rule/RuleController.java | 2 +- src/main/java/hous/server/service/rule/RuleService.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 991d954a..2e45362d 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -79,7 +79,7 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr @PutMapping("/rules") public ResponseEntity> updateSortByRules(@Valid @RequestBody UpdateRuleRequestDto request, @ApiIgnore @UserId Long userId) { - ruleService.updateRule(request, userId); + ruleService.updateRules(request, userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index bb9287a3..c942520d 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -74,17 +74,15 @@ public void createRule(CreateRuleRequestDto request, Long userId) { usersExceptMe.forEach(userExceptMe -> notificationService.sendNewRuleNotification(userExceptMe, rules)); } - public void updateRule(UpdateRuleRequestDto request, Long userId) { + public void updateRules(UpdateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); RuleServiceUtils.validateRequestRuleCounts(room, request.getRules().size()); IntStream.range(0, request.getRules().size()).forEach(idx -> { - .mapToObj(idx -> { Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); rule.updateRule(request.getRules().get(idx).getName(), idx); room.updateRule(rule); }); - room.updateRules(rules); } public void deleteRules(DeleteRuleReqeustDto request, Long userId) { From 44073979ff0a5bdd6ed2c35bae0618a51f4158d8 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 30 Oct 2022 00:49:50 +0900 Subject: [PATCH 232/301] =?UTF-8?q?#187=20[fix]=20=EB=8D=94=EC=9D=B4?= =?UTF-8?q?=EC=83=81=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B0=8F=20enum=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/exception/ErrorCode.java | 1 - .../java/hous/server/controller/rule/RuleController.java | 1 - src/main/java/hous/server/service/rule/RuleService.java | 1 - .../java/hous/server/service/rule/RuleServiceUtils.java | 8 -------- 4 files changed, 11 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index a0fd7d68..b20672e5 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -38,7 +38,6 @@ public enum ErrorCode { FORBIDDEN_PARTICIPATE_COUNT_EXCEPTION(FORBIDDEN, "방 참가자는 16명을 초과할 수 없습니다."), FORBIDDEN_TODO_COUNT_EXCEPTION(FORBIDDEN, "todo 는 60개를 초과할 수 없습니다."), FORBIDDEN_RULE_COUNT_EXCEPTION(FORBIDDEN, "rule 은 30개를 초과할 수 없습니다."), - FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION(FORBIDDEN, "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다."), FORBIDDEN_ROOM_PARTICIPATE_EXCEPTION(FORBIDDEN, "같은 방에 참가하고 있지 않습니다."), FORBIDDEN_ACQUIRE_BADGE_EXCEPTION(FORBIDDEN, "유저가 획득한 배지가 아닙니다."), diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 2e45362d..a4f42aab 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -66,7 +66,6 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 403, message = "요청한 rule 의 개수와 방의 rule 의 수가 맞지 않습니다.", response = ErrorResponse.class), @ApiResponse( code = 404, message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index c942520d..d6325efa 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -77,7 +77,6 @@ public void createRule(CreateRuleRequestDto request, Long userId) { public void updateRules(UpdateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - RuleServiceUtils.validateRequestRuleCounts(room, request.getRules().size()); IntStream.range(0, request.getRules().size()).forEach(idx -> { Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); rule.updateRule(request.getRules().get(idx).getName(), idx); diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index e8eb45fa..5ca224f3 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -44,12 +44,4 @@ public static Rule findRuleByIdAndRoom(RuleRepository ruleRepository, Long ruleI } return rule; } - - public static void validateRequestRuleCounts(Room room, int requestRuleCnt) { - if (room.getRulesCnt() != requestRuleCnt) { - throw new ForbiddenException(String.format("방 (%s) 의 rule 는 (%s) 개가 아닙니다.", room.getId(), requestRuleCnt), - FORBIDDEN_REQUEST_RULE_COUNT_EXCEPTION); - } - } - } From dfa63901c97663ab2ddb789676616b638363f21a Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 30 Oct 2022 00:50:34 +0900 Subject: [PATCH 233/301] =?UTF-8?q?#187=20[rename]=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/rule/RuleController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index a4f42aab..e6f8b46b 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -76,8 +76,8 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr }) @Auth @PutMapping("/rules") - public ResponseEntity> updateSortByRules(@Valid @RequestBody UpdateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateRules(@Valid @RequestBody UpdateRuleRequestDto request, + @ApiIgnore @UserId Long userId) { ruleService.updateRules(request, userId); return SuccessResponse.OK; } From ccd32cee02ce8e9509fb8ce0cb979f14d644662f Mon Sep 17 00:00:00 2001 From: Joon Date: Sun, 30 Oct 2022 15:31:17 +0900 Subject: [PATCH 234/301] =?UTF-8?q?#189=20[fix]=20JWT=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=ED=95=B8=EB=93=A4=EB=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/JwtUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index 80ee5240..103804b5 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -5,6 +5,7 @@ import hous.server.service.auth.dto.response.TokenResponse; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; +import io.jsonwebtoken.io.DecodingException; import io.jsonwebtoken.security.Keys; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -70,7 +71,7 @@ public boolean validateToken(String token) { try { Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token); return true; - } catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e) { + } catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException | DecodingException e) { log.warn("Invalid JWT Token", e); } catch (ExpiredJwtException e) { log.warn("Expired JWT Token", e); @@ -78,6 +79,8 @@ public boolean validateToken(String token) { log.warn("Unsupported JWT Token", e); } catch (IllegalArgumentException e) { log.warn("JWT claims string is empty.", e); + } catch (Exception e) { + log.error("Unhandled JWT exception", e); } return false; } From ce395165c370ea1cea2fabc34631407dc37224c9 Mon Sep 17 00:00:00 2001 From: Joon Date: Sun, 30 Oct 2022 18:11:37 +0900 Subject: [PATCH 235/301] =?UTF-8?q?#191=20[fix]=20fcm=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=ED=95=B8=EB=93=A4=EB=A7=81=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 --- .../firebase/FirebaseCloudMessageService.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index fdf388a5..6e399a6a 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -1,9 +1,7 @@ package hous.server.service.firebase; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.auth.oauth2.GoogleCredentials; -import hous.server.common.exception.FeignClientException; import hous.server.common.exception.InternalServerException; import hous.server.common.util.HttpHeaderUtils; import hous.server.common.util.JwtUtils; @@ -17,7 +15,6 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.List; import static hous.server.common.exception.ErrorCode.INTERNAL_SERVER_EXCEPTION; @@ -33,14 +30,14 @@ public class FirebaseCloudMessageService { private final JwtUtils jwtProvider; public void sendMessageTo(User to, String title, String body) { - String targetToken = to.getFcmToken(); - String message = makeMessage(targetToken, title, body); try { + String targetToken = to.getFcmToken(); + String message = makeMessage(targetToken, title, body); firebaseApiCaller.requestFcmMessaging(HttpHeaderUtils.withBearerToken(getAccessToken()), message); - } catch (FeignClientException exception) { + } catch (Exception exception) { jwtProvider.expireRefreshToken(to.getId()); to.resetFcmToken(); - log.error(exception.getErrorMessage(), exception); + log.error(exception.getMessage(), exception); } } @@ -57,7 +54,7 @@ private String makeMessage(String targetToken, String title, String body) { .build(); try { return objectMapper.writeValueAsString(fcmMessage); - } catch (JsonProcessingException exception) { + } catch (Exception exception) { log.error(exception.getMessage(), exception); throw new InternalServerException("FCM makeMessage exception", INTERNAL_SERVER_EXCEPTION); } @@ -71,7 +68,7 @@ private String getAccessToken() { .createScoped(List.of("https://www.googleapis.com/auth/cloud-platform")); googleCredentials.refreshIfExpired(); return googleCredentials.getAccessToken().getTokenValue(); - } catch (IOException exception) { + } catch (Exception exception) { log.error(exception.getMessage(), exception); throw new InternalServerException("FCM getAccessToken exception", INTERNAL_SERVER_EXCEPTION); } From e25b30eb447aa3c769b8c28f32668894fa45dbf9 Mon Sep 17 00:00:00 2001 From: Joon Date: Sun, 30 Oct 2022 18:27:54 +0900 Subject: [PATCH 236/301] =?UTF-8?q?#191=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=97=90=EB=9F=AC=20=ED=95=B8=EB=93=A4?= =?UTF-8?q?=EB=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/rule/RuleController.java | 15 ++++++++++++--- .../rule/dto/request/CreateRuleRequestDto.java | 2 ++ .../rule/dto/request/DeleteRuleReqeustDto.java | 2 ++ .../rule/dto/request/UpdateRuleRequestDto.java | 2 ++ src/main/resources/messages/validation.properties | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index e6f8b46b..71b48481 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -38,7 +38,8 @@ public class RuleController { code = 400, message = "1. 규칙 내용을 입력해주세요.\n" + "2. 규칙은 20 글자 이내로 입력해주세요.\n" - + "3. 규칙 리스트는 빈 배열을 보낼 수 없습니다. (ruleNames)", + + "3. 규칙 리스트를 입력해주세요. (ruleNames)\n" + + "4. 규칙 리스트는 빈 배열을 보낼 수 없습니다. (ruleNames)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 403, message = "rule 은 30개를 초과할 수 없습니다.", response = ErrorResponse.class), @@ -64,7 +65,11 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), - @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), + @ApiResponse( + code = 400, + message = "1. 규칙 리스트를 입력해주세요. (rules)\n" + + "2. 규칙 리스트는 빈 배열을 보낼 수 없습니다. (rules)", + response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, @@ -88,7 +93,11 @@ public ResponseEntity> updateRules(@Valid @RequestBody U ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), - @ApiResponse(code = 400, message = "규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", response = ErrorResponse.class), + @ApiResponse( + code = 400, + message = "1. 규칙 리스트를 입력해주세요. (rulesIdList)\n" + + "2. 규칙 리스트는 빈 배열을 보낼 수 없습니다. (rulesIdList)", + response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( code = 404, diff --git a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java index 3f9f2f1b..2714f71d 100644 --- a/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/CreateRuleRequestDto.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import lombok.ToString; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; @@ -16,6 +17,7 @@ public class CreateRuleRequestDto { @ApiModelProperty(value = "규칙 내용 배열", example = "[\"우리집 대장은 김또순\", \"우리집 대장은 혜조니\", \"우리집 대장은 혁주니\", ...]") + @NotNull(message = "{rule.list.notNull}") @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") private List ruleNames; } diff --git a/src/main/java/hous/server/service/rule/dto/request/DeleteRuleReqeustDto.java b/src/main/java/hous/server/service/rule/dto/request/DeleteRuleReqeustDto.java index 8dcd6f78..78e6bf3d 100644 --- a/src/main/java/hous/server/service/rule/dto/request/DeleteRuleReqeustDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/DeleteRuleReqeustDto.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import lombok.ToString; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; @@ -16,6 +17,7 @@ public class DeleteRuleReqeustDto { @ApiModelProperty(value = "규칙 id 배열", example = "[12, 13, 14, ...]") + @NotNull(message = "{rule.list.notNull}") @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") private List rulesIdList; } diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java index 7ec94b21..556d0910 100644 --- a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java @@ -8,6 +8,7 @@ import lombok.NoArgsConstructor; import lombok.ToString; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; @@ -17,6 +18,7 @@ public class UpdateRuleRequestDto { @ApiModelProperty(value = "수정된 규칙 리스트") + @NotNull(message = "{rule.list.notNull}") @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") private List rules; } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 20744c4d..168e49f3 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -24,4 +24,5 @@ todo.isPushNotification.notNull=todo \uC758 \uD478\uC26C \uC54C\uB9BC \uC5EC\uBD todo.todoUsers.notEmpty=\uB2F4\uB2F9\uC790 \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uBC30\uC5F4\uC77C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. +rule.list.notNull=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. From aef7081d515aaadd903e163da6e776a4b1d9e2f1 Mon Sep 17 00:00:00 2001 From: Joon Date: Sun, 30 Oct 2022 18:37:25 +0900 Subject: [PATCH 237/301] =?UTF-8?q?#191=20[refactor]=20RuleInfo=20dto=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/RuleRetrieveController.java | 4 +--- .../service/rule/RuleRetrieveService.java | 2 +- .../dto/request/UpdateRuleRequestDto.java | 4 ++-- .../service/rule/dto/response/RuleInfo.java | 23 +++++++++++++++++++ .../rule/dto/response/RuleInfoResponse.java | 17 ++++---------- 5 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 src/main/java/hous/server/service/rule/dto/response/RuleInfo.java diff --git a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java index f33d1947..1de0102a 100644 --- a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java +++ b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java @@ -18,8 +18,6 @@ import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; -import java.util.List; - @Api(tags = "Rule") @RequiredArgsConstructor @RestController @@ -39,7 +37,7 @@ public class RuleRetrieveController { }) @Auth @GetMapping("/rules") - public ResponseEntity>> getRulesInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getRulesInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_RULE_INFO_SUCCESS, ruleRetrieveService.getRulesInfo(userId)); } } diff --git a/src/main/java/hous/server/service/rule/RuleRetrieveService.java b/src/main/java/hous/server/service/rule/RuleRetrieveService.java index 237663cb..c4718607 100644 --- a/src/main/java/hous/server/service/rule/RuleRetrieveService.java +++ b/src/main/java/hous/server/service/rule/RuleRetrieveService.java @@ -20,7 +20,7 @@ public class RuleRetrieveService { private final UserRepository userRepository; - public List getRulesInfo(Long userId) { + public RuleInfoResponse getRulesInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); List rules = room.getRules(); diff --git a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java index 556d0910..374ea251 100644 --- a/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java +++ b/src/main/java/hous/server/service/rule/dto/request/UpdateRuleRequestDto.java @@ -1,7 +1,7 @@ package hous.server.service.rule.dto.request; import hous.server.domain.common.Constraint; -import hous.server.service.rule.dto.response.RuleInfoResponse; +import hous.server.service.rule.dto.response.RuleInfo; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; import lombok.Getter; @@ -20,5 +20,5 @@ public class UpdateRuleRequestDto { @ApiModelProperty(value = "수정된 규칙 리스트") @NotNull(message = "{rule.list.notNull}") @Size(min = Constraint.RULE_LIST_MIN, message = "{rule.list.min}") - private List rules; + private List rules; } diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfo.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfo.java new file mode 100644 index 00000000..037eab14 --- /dev/null +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfo.java @@ -0,0 +1,23 @@ +package hous.server.service.rule.dto.response; + +import hous.server.domain.rule.Rule; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class RuleInfo { + + private Long id; + + private String name; + + public static RuleInfo of(Rule rule) { + return RuleInfo.builder() + .id(rule.getId()) + .name(rule.getName()) + .build(); + } +} diff --git a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java index cace0eb0..34988543 100644 --- a/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java +++ b/src/main/java/hous/server/service/rule/dto/response/RuleInfoResponse.java @@ -13,20 +13,13 @@ @Builder(access = AccessLevel.PRIVATE) public class RuleInfoResponse { - private Long id; + private List rules; - private String name; - - public static RuleInfoResponse of(Rule rule) { + public static RuleInfoResponse of(List rules) { return RuleInfoResponse.builder() - .id(rule.getId()) - .name(rule.getName()) + .rules(rules.stream() + .sorted(Rule::compareTo) + .map(RuleInfo::of).collect(Collectors.toList())) .build(); } - - public static List of(List rules) { - return rules.stream() - .sorted(Rule::compareTo) - .map(RuleInfoResponse::of).collect(Collectors.toList()); - } } From 01b3e28ce8f0038e2514295dac309bd332fa676c Mon Sep 17 00:00:00 2001 From: Joon Date: Sun, 30 Oct 2022 22:28:51 +0900 Subject: [PATCH 238/301] =?UTF-8?q?#193=20[fix]=20=ED=99=88=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EC=A1=B0=ED=9A=8C=20=EC=9A=94=EC=9D=BC=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/home/HomeRetrieveService.java | 2 +- .../server/service/home/dto/response/HomeInfoResponse.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index e940d4e7..6207178c 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -62,6 +62,6 @@ public HomeInfoResponse getHomeInfo(Long userId) { .sorted(Onboarding::compareTo) .collect(Collectors.toList()); List meFirstList = UserServiceUtils.toMeFirstList(participants, user.getOnboarding()); - return HomeInfoResponse.of(user.getOnboarding(), room, todayMyTodos, todayOurTodos, rules, meFirstList); + return HomeInfoResponse.of(user.getOnboarding(), room, today, todayMyTodos, todayOurTodos, rules, meFirstList); } } diff --git a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java index 34bb15f8..35769c82 100644 --- a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java +++ b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java @@ -1,5 +1,6 @@ package hous.server.service.home.dto.response; +import hous.server.common.util.DateUtils; import hous.server.common.util.MathUtils; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.room.Room; @@ -10,6 +11,7 @@ import hous.server.service.todo.dto.response.TodoDetailInfo; import lombok.*; +import java.time.LocalDate; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -24,6 +26,7 @@ public class HomeInfoResponse { private String userNickname; private String roomName; private String roomCode; + private String dayOfWeek; private int progress; private int myTodosCnt; private List myTodos; @@ -41,13 +44,14 @@ public static class HomieInfo { private PersonalityColor color; } - public static HomeInfoResponse of(Onboarding me, Room room, List myTodos, + public static HomeInfoResponse of(Onboarding me, Room room, LocalDate today, List myTodos, List ourTodos, List rules, List participants) { int doneOurTodosCnt = (int) ourTodos.stream().filter(ourTodo -> ourTodo.getStatus() == OurTodoStatus.FULL_CHECK).count(); return HomeInfoResponse.builder() .userNickname(me.getNickname()) .roomName(room.getName()) .roomCode(room.getCode()) + .dayOfWeek(DateUtils.nowDayOfWeek(today)) .progress(MathUtils.percent(doneOurTodosCnt, ourTodos.size())) .myTodosCnt(myTodos.size()) .myTodos(myTodos.stream() From 239c628db15236bd880e9c5317faa9986161da1a Mon Sep 17 00:00:00 2001 From: Joon Date: Mon, 31 Oct 2022 01:20:30 +0900 Subject: [PATCH 239/301] =?UTF-8?q?#129=20[fix]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=ED=94=8C=EB=9E=AB=ED=8F=BC=EB=B3=84=20?= =?UTF-8?q?=EC=84=B8=EB=B6=80=20=EC=98=B5=EC=85=98=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firebase/FirebaseCloudMessageService.java | 18 ++++++-- .../firebase/dto/request/FcmMessage.java | 41 ++++++++++++++++++- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index 6e399a6a..f262bb22 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -45,9 +45,21 @@ private String makeMessage(String targetToken, String title, String body) { FcmMessage fcmMessage = FcmMessage.builder() .validateOnly(false) .message(FcmMessage.Message.builder() - .notification(FcmMessage.Notification.builder() - .title(title) - .body(body) + .android(FcmMessage.Android.builder() + .data(FcmMessage.Data.builder() + .title(title) + .body(body) + .build()) + .build()) + .apns(FcmMessage.Apns.builder() + .payload(FcmMessage.Payload.builder() + .aps(FcmMessage.Aps.builder() + .alert(FcmMessage.Alert.builder() + .title(title) + .body(body) + .build()) + .build()) + .build()) .build()) .token(targetToken) .build()) diff --git a/src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java b/src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java index 51ab8580..f0caf374 100644 --- a/src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java +++ b/src/main/java/hous/server/service/firebase/dto/request/FcmMessage.java @@ -15,14 +15,51 @@ public class FcmMessage { @AllArgsConstructor @Getter public static class Message { - private Notification notification; + private Android android; + private Apns apns; private String token; } @Builder @AllArgsConstructor @Getter - public static class Notification { + public static class Android { + private Data data; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Data { + private String title; + private String body; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Apns { + private Payload payload; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Payload { + private Aps aps; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Aps { + private Alert alert; + } + + @Builder + @AllArgsConstructor + @Getter + public static class Alert { private String title; private String body; } From 8c3a0d983b84a73447cfafd3ac9b1684499d32ce Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 3 Nov 2022 11:36:27 +0900 Subject: [PATCH 240/301] =?UTF-8?q?#197=20[feat]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EC=84=A4=EC=A0=95=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 ++ .../user/UserRetrieveController.java | 23 ++++++++++-- .../service/user/UserRetrieveService.java | 10 +++-- .../dto/response/PushSettingResponse.java | 37 +++++++++++++++++++ 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/main/java/hous/server/service/user/dto/response/PushSettingResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index c1b9b370..c1c49cda 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -56,6 +56,9 @@ public enum SuccessCode { // 알림 GET_NOTIFICATIONS_INFO_SUCCESS(OK, "알림 목록 조회 성공입니다."), + // 설정 + GET_USER_PUSH_SETTING_SUCCESS(OK, "푸시 알림 설정 정보 조회 성공입니다."), + /** * 201 CREATED */ diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index d936bcb2..ea2b23cc 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -9,10 +9,7 @@ import hous.server.service.notification.NotificationRetrieveService; import hous.server.service.notification.dto.response.NotificationsInfoResponse; import hous.server.service.user.UserRetrieveService; -import hous.server.service.user.dto.response.MyBadgeInfoResponse; -import hous.server.service.user.dto.response.PersonalityInfoResponse; -import hous.server.service.user.dto.response.PersonalityTestInfoResponse; -import hous.server.service.user.dto.response.UserInfoResponse; +import hous.server.service.user.dto.response.*; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -66,6 +63,24 @@ public ResponseEntity> getHomieInfo(@ApiParam( return SuccessResponse.success(SuccessCode.GET_HOMIE_PROFILE_INFO_SUCCESS, userRetrieveService.getHomieInfo(homieId, userId)); } + @ApiOperation( + value = "[인증] 마이 페이지(설정) - 나의 푸시 알림 설정 정보를 조회합니다.", + notes = "푸시 알림 설정 정보를 조회합니다.\n" + + "Rules, Badge 설정으로는 ON, OFF 상태가 있습니다.\n" + + "Todo 관련 설정으로는 ON_ALL, ON_MY, OFF 상태가 있습니다." + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "푸시 알림 설정 정보 조회 성공입니다."), + @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @Auth + @GetMapping("/user/push") + public ResponseEntity> getUserPushSetting(@ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_USER_PUSH_SETTING_SUCCESS, userRetrieveService.getUserPushSetting(userId)); + } + @ApiOperation( value = "[인증] 룸메이트 정보 페이지(Hous 뷰에서 호미 카드 클릭) - 성향 정보를 확인합니다.", notes = "color 쿼리에 조회할 성향 색깔을 담아서 요청을 보냅니다.\n" + diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index cd7a34c6..67a6bacb 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -16,10 +16,7 @@ import hous.server.domain.user.User; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; -import hous.server.service.user.dto.response.MyBadgeInfoResponse; -import hous.server.service.user.dto.response.PersonalityInfoResponse; -import hous.server.service.user.dto.response.PersonalityTestInfoResponse; -import hous.server.service.user.dto.response.UserInfoResponse; +import hous.server.service.user.dto.response.*; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -54,6 +51,11 @@ public UserInfoResponse getHomieInfo(Long homieId, Long userId) { return getProfileInfoByUser(homie); } + public PushSettingResponse getUserPushSetting(Long userId) { + User user = UserServiceUtils.findUserById(userRepository, userId); + return PushSettingResponse.of(user.getSetting()); + } + public PersonalityInfoResponse getPersonalityInfo(PersonalityColor color) { UserServiceUtils.validatePersonalityColor(color); Personality personality = personalityRepository.findPersonalityByColor(color); diff --git a/src/main/java/hous/server/service/user/dto/response/PushSettingResponse.java b/src/main/java/hous/server/service/user/dto/response/PushSettingResponse.java new file mode 100644 index 00000000..9c1aa146 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/response/PushSettingResponse.java @@ -0,0 +1,37 @@ +package hous.server.service.user.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import hous.server.domain.user.PushStatus; +import hous.server.domain.user.Setting; +import hous.server.domain.user.TodoPushStatus; +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class PushSettingResponse { + private Boolean isPushNotification; + private PushStatus rulesPushStatus; + private TodoPushStatus newTodoPushStatus; + private TodoPushStatus todayTodoPushStatus; + private TodoPushStatus remindTodoPushStatus; + private PushStatus badgePushStatus; + + @JsonProperty("isPushNotification") + public Boolean isPushNotification() { + return isPushNotification; + } + + public static PushSettingResponse of(Setting setting) { + return PushSettingResponse.builder() + .isPushNotification(setting.isPushNotification()) + .rulesPushStatus(setting.getRulesPushStatus()) + .newTodoPushStatus(setting.getNewTodoPushStatus()) + .todayTodoPushStatus(setting.getTodayTodoPushStatus()) + .remindTodoPushStatus(setting.getRemindTodoPushStatus()) + .badgePushStatus(setting.getBadgePushStatus()) + .build(); + } +} From a7af865c4ee52e2014f0a96537a086c1ccbcc853 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Fri, 4 Nov 2022 23:35:04 +0900 Subject: [PATCH 241/301] =?UTF-8?q?#199=20[fix]=20room=20=EC=9D=98=20todo?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/room/Room.java | 4 ++++ src/main/java/hous/server/service/todo/TodoService.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/hous/server/domain/room/Room.java b/src/main/java/hous/server/domain/room/Room.java index fcca4f80..e7da2b7e 100644 --- a/src/main/java/hous/server/domain/room/Room.java +++ b/src/main/java/hous/server/domain/room/Room.java @@ -93,6 +93,10 @@ public void addTodo(Todo todo) { this.todosCnt += 1; } + public void updateTodo(Todo todo) { + this.todos.set(todos.indexOf(todo), todo); + } + public void deleteTodo(Todo todo) { this.todos.remove(todo); this.todosCnt -= 1; diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 461620ad..e280e38b 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -71,6 +71,7 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { public void updateTodo(Long todoId, TodoInfoRequestDto request) { Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); + Room room = todo.getRoom(); todo.getTakes().forEach(take -> { redoRepository.deleteAll(take.getRedos()); takeRepository.delete(take); @@ -86,6 +87,7 @@ public void updateTodo(Long todoId, TodoInfoRequestDto request) { takes.add(take); }); todo.updateTodo(request.getName(), request.isPushNotification(), takes); + room.updateTodo(todo); } public void checkTodo(Long todoId, CheckTodoRequestDto request, Long userId) { From f8388f3e36e8e4ec6a6717cbff4e8aa3edcc6a40 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Fri, 4 Nov 2022 23:59:28 +0900 Subject: [PATCH 242/301] =?UTF-8?q?#199=20[fix]=20todo=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=A1=B0=ED=9A=8C=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/todo/TodoServiceUtils.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index c543667f..45a1e0d4 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -17,7 +17,9 @@ import java.time.LocalDate; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import static hous.server.common.exception.ErrorCode.*; @@ -55,35 +57,35 @@ public static List toUserPersonalityInfoList(List filterDayOurTodos(LocalDate day, List todos) { - List dayOurTodosList = new ArrayList<>(); + Set dayOurTodosSet = new HashSet<>(); todos.forEach(todo -> { todo.getTakes().forEach(take -> { take.getRedos().forEach(redo -> { if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(day))) { - dayOurTodosList.add(todo); + dayOurTodosSet.add(todo); } }); }); }); - return dayOurTodosList; + return new ArrayList<>(dayOurTodosSet); } public static List filterAllDaysOurTodos(List todos) { - List allDaysOurTodosList = new ArrayList<>(); + Set allDaysOurTodosSet = new HashSet<>(); todos.forEach(todo -> todo.getTakes().forEach(take -> take.getRedos().forEach(redo -> - allDaysOurTodosList.add(todo)))); - return allDaysOurTodosList; + allDaysOurTodosSet.add(todo)))); + return new ArrayList<>(allDaysOurTodosSet); } public static List filterAllDaysUserTodos(List todos, Onboarding onboarding) { - List userTodosList = new ArrayList<>(); + Set userTodosSet = new HashSet<>(); todos.forEach(todo -> todo.getTakes().forEach(take -> { if (take.getOnboarding().getId().equals(onboarding.getId())) { - userTodosList.add(todo); + userTodosSet.add(todo); } })); - return userTodosList; + return new ArrayList<>(userTodosSet); } public static List filterAllDaysMyDones(Onboarding me, List dones) { @@ -109,15 +111,15 @@ public static List[] mapByDayOfWeekToList(List todos) { } public static List filterDayMyTodos(LocalDate day, Onboarding me, List todos) { - List dayMyTodosList = new ArrayList<>(); + Set dayMyTodosSet = new HashSet<>(); List dayOurTodosList = filterDayOurTodos(day, todos); dayOurTodosList.forEach(todo -> { todo.getTakes().forEach(take -> { if (take.getOnboarding().getId().equals(me.getId())) { - dayMyTodosList.add(todo); + dayMyTodosSet.add(todo); } }); }); - return dayMyTodosList; + return new ArrayList<>(dayMyTodosSet); } } From dbd8c2dde1cf2995c0f84bf4da24b4e175a9292d Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 6 Nov 2022 02:54:39 +0900 Subject: [PATCH 243/301] =?UTF-8?q?#201=20[fix]=20=EB=B0=A9=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/room/RoomService.java | 5 +++-- .../hous/server/service/room/RoomServiceUtils.java | 11 ++++++----- .../java/hous/server/service/user/UserService.java | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index 8fa05d20..f02cdf24 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -81,13 +81,14 @@ public void leaveRoom(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); Onboarding me = user.getOnboarding(); + Participate participate = me.getParticipates().get(0); List todos = room.getTodos(); List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); - RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room); - + RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate); + // 내 배지, 알림 목록, 프로필 작성 내역, 테스트 결과 초기화 if (me.getRepresent() != null) { representRepository.delete(me.getRepresent()); diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 346beabd..4c86b466 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -97,14 +97,15 @@ public static void deleteMyTodosTakeMe(TakeRepository takeRepository, DoneReposi }); } - public static void deleteParticipateUser(ParticipateRepository participateRepository, RoomRepository roomRepository, Onboarding me, Room room) { + public static void deleteParticipateUser(ParticipateRepository participateRepository, RoomRepository roomRepository, + Onboarding me, Room room, Participate participate) { List participates = room.getParticipates(); if (participates.size() > 1) { - room.deleteParticipate(participates.get(0)); - me.deleteParticipate(participates.get(0)); - participateRepository.delete(participates.get(0)); + room.deleteParticipate(participate); + me.deleteParticipate(participate); + participateRepository.delete(participate); } else { - me.deleteParticipate(participates.get(0)); + me.deleteParticipate(participate); roomRepository.delete(room); } } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 1c7ec748..bef7d426 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -158,11 +158,12 @@ public void deleteUser(Long userId) { List participates = me.getParticipates(); if (!participates.isEmpty()) { - Room room = participates.get(0).getRoom(); + Participate participate = participates.get(0); + Room room = participate.getRoom(); List todos = room.getTodos(); List myTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, me); RoomServiceUtils.deleteMyTodosTakeMe(takeRepository, doneRepository, todoRepository, myTodos, me, room); - RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room); + RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate); } userRepository.delete(user); From 0c49d0706085ad7117c6ce4e5fbba016c2449f5e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 6 Nov 2022 14:49:19 +0900 Subject: [PATCH 244/301] =?UTF-8?q?#203=20[fix]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=ED=83=88=ED=87=B4=20=EC=8B=9C=20feedback=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EA=B3=A0=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 8 ++-- .../hous/server/domain/feedback/Feedback.java | 32 +++++++++++++++ .../server/domain/feedback/FeedbackType.java | 21 ++++++++++ .../repository/FeedbackRepository.java | 7 ++++ .../repository/FeedbackRepositoryCustom.java | 4 ++ .../repository/FeedbackRepositoryImpl.java | 8 ++++ .../dto/response/UserDeleteResponse.java | 41 +++++++++++++++++++ .../hous/server/service/user/UserService.java | 11 ++--- .../dto/request/DeleteUserRequestDto.java | 21 ++++++++++ .../resources/messages/validation.properties | 1 + 10 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 src/main/java/hous/server/domain/feedback/Feedback.java create mode 100644 src/main/java/hous/server/domain/feedback/FeedbackType.java create mode 100644 src/main/java/hous/server/domain/feedback/repository/FeedbackRepository.java create mode 100644 src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryImpl.java create mode 100644 src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java create mode 100644 src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index e61e6a71..5f55e933 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -6,6 +6,7 @@ import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; import hous.server.service.user.UserService; +import hous.server.service.user.dto.request.DeleteUserRequestDto; import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; @@ -128,18 +129,19 @@ public ResponseEntity> updateRepresentBadge(@ApiParam(na @ApiOperation( value = "[인증] 마이 페이지(설정) - 회원 정보를 삭제합니다.", - notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다." + notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다. FeedbackType은 필수로 명시해야 합니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), + @ApiResponse(code = 400, message = "사유는 빈 값을 보낼 수 없습니다. (FeedbackType)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @DeleteMapping("/user") - public ResponseEntity> deleteUser(@ApiIgnore @UserId Long userId) { - userService.deleteUser(userId); + public ResponseEntity> deleteUser(@RequestBody DeleteUserRequestDto request, @ApiIgnore @UserId Long userId) { + userService.deleteUser(request, userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/domain/feedback/Feedback.java b/src/main/java/hous/server/domain/feedback/Feedback.java new file mode 100644 index 00000000..01bbdd11 --- /dev/null +++ b/src/main/java/hous/server/domain/feedback/Feedback.java @@ -0,0 +1,32 @@ +package hous.server.domain.feedback; + +import hous.server.domain.common.AuditingTimeEntity; +import lombok.*; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class Feedback extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, length = 30) + @Enumerated(EnumType.STRING) + private FeedbackType feedbackType; + + @Column(length = 300) + private String comment; + + public static Feedback newInstance(FeedbackType feedbackType, String comment) { + return Feedback.builder() + .feedbackType(feedbackType) + .comment(comment) + .build(); + } +} diff --git a/src/main/java/hous/server/domain/feedback/FeedbackType.java b/src/main/java/hous/server/domain/feedback/FeedbackType.java new file mode 100644 index 00000000..fff7cb33 --- /dev/null +++ b/src/main/java/hous/server/domain/feedback/FeedbackType.java @@ -0,0 +1,21 @@ +package hous.server.domain.feedback; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum FeedbackType { + DONE_LIVING_TOGETHER("공동생활이 끝나서"), + INCONVENIENT_TO_USE("이용이 불편하고 장애가 많아서"), + LOW_USAGE("사용 빈도가 낮아서"), + CONTENTS_UNSATISFACTORY("콘텐츠 불만"), + ETC("기타"); + + private final String value; + + public String getValue() { + return value; + } +} diff --git a/src/main/java/hous/server/domain/feedback/repository/FeedbackRepository.java b/src/main/java/hous/server/domain/feedback/repository/FeedbackRepository.java new file mode 100644 index 00000000..46287581 --- /dev/null +++ b/src/main/java/hous/server/domain/feedback/repository/FeedbackRepository.java @@ -0,0 +1,7 @@ +package hous.server.domain.feedback.repository; + +import hous.server.domain.feedback.Feedback; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FeedbackRepository extends JpaRepository, FeedbackRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryCustom.java b/src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryCustom.java new file mode 100644 index 00000000..a207fb8d --- /dev/null +++ b/src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryCustom.java @@ -0,0 +1,4 @@ +package hous.server.domain.feedback.repository; + +public interface FeedbackRepositoryCustom { +} diff --git a/src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryImpl.java b/src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryImpl.java new file mode 100644 index 00000000..8d5125ea --- /dev/null +++ b/src/main/java/hous/server/domain/feedback/repository/FeedbackRepositoryImpl.java @@ -0,0 +1,8 @@ +package hous.server.domain.feedback.repository; + +import lombok.RequiredArgsConstructor; + + +@RequiredArgsConstructor +public class FeedbackRepositoryImpl implements FeedbackRepositoryCustom { +} diff --git a/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java b/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java new file mode 100644 index 00000000..6e6e8018 --- /dev/null +++ b/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java @@ -0,0 +1,41 @@ +package hous.server.service.slack.dto.response; + + +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class UserDeleteResponse { + + private int totalDeleteUserCount; + private List totalDeleteUserList; + private String currentDeleteUserFeedbackType; + + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + @Builder(access = AccessLevel.PRIVATE) + public static class UserDelete { + private int cnt; + private String feedbackType; + + public static UserDelete of(int cnt, String feedbackType) { + return UserDelete.builder() + .cnt(cnt) + .feedbackType(feedbackType) + .build(); + } + } + + public static UserDeleteResponse of(int totalDeleteUserCount, List totalDeleteUserList, String currentDeleteUserFeedbackType) { + return UserDeleteResponse.builder() + .totalDeleteUserCount(totalDeleteUserCount) + .totalDeleteUserList(totalDeleteUserList) + .currentDeleteUserFeedbackType(currentDeleteUserFeedbackType) + .build(); + } +} diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index bef7d426..b2496f47 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -8,6 +8,8 @@ import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.common.RedisKey; +import hous.server.domain.feedback.Feedback; +import hous.server.domain.feedback.repository.FeedbackRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.repository.PersonalityRepository; @@ -31,10 +33,7 @@ import hous.server.service.badge.BadgeServiceUtils; import hous.server.service.room.RoomServiceUtils; import hous.server.service.todo.TodoServiceUtils; -import hous.server.service.user.dto.request.CreateUserRequestDto; -import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; -import hous.server.service.user.dto.request.UpdateTestScoreRequestDto; -import hous.server.service.user.dto.request.UpdateUserInfoRequestDto; +import hous.server.service.user.dto.request.*; import hous.server.service.user.dto.response.UpdatePersonalityColorResponse; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -63,6 +62,7 @@ public class UserService { private final TodoRepository todoRepository; private final RoomRepository roomRepository; private final ParticipateRepository participateRepository; + private final FeedbackRepository feedbackRepository; private final BadgeService badgeService; @@ -152,7 +152,7 @@ public void updateRepresentBadge(Long badgeId, Long userId) { me.updateRepresent(represent); } - public void deleteUser(Long userId) { + public void deleteUser(DeleteUserRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding me = user.getOnboarding(); List participates = me.getParticipates(); @@ -166,6 +166,7 @@ public void deleteUser(Long userId) { RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate); } + feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getConmment())); userRepository.delete(user); } diff --git a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java new file mode 100644 index 00000000..832b55b6 --- /dev/null +++ b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java @@ -0,0 +1,21 @@ +package hous.server.service.user.dto.request; + +import hous.server.domain.feedback.FeedbackType; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +import javax.validation.constraints.NotNull; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class DeleteUserRequestDto { + + @ApiModelProperty(value = "사유", example = "DONE_LIVING_TOGETHER") + @NotNull(message = "{user.delete.feedback.notNull}") + private FeedbackType feedbackType; + + @ApiModelProperty(value = "의견", example = "흠냐링 제법 괜찮았으나 안쓰게 되네요.") + private String conmment; +} diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 168e49f3..38344e4a 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -26,3 +26,4 @@ todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uB todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.notNull=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +user.delete.feedback.notNull=\uC0AC\uC720\uB294 \uBE48 \uAC12\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. From 5fae001f16819b2ffccf15f8ca744bfc7c51cdf1 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 6 Nov 2022 16:31:58 +0900 Subject: [PATCH 245/301] =?UTF-8?q?#203=20[fix]=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/domain/feedback/FeedbackType.java | 9 ++++++++- src/main/java/hous/server/service/user/UserService.java | 2 +- .../service/user/dto/request/DeleteUserRequestDto.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/domain/feedback/FeedbackType.java b/src/main/java/hous/server/domain/feedback/FeedbackType.java index fff7cb33..56993aee 100644 --- a/src/main/java/hous/server/domain/feedback/FeedbackType.java +++ b/src/main/java/hous/server/domain/feedback/FeedbackType.java @@ -1,12 +1,13 @@ package hous.server.domain.feedback; +import hous.server.common.model.EnumModel; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public enum FeedbackType { +public enum FeedbackType implements EnumModel { DONE_LIVING_TOGETHER("공동생활이 끝나서"), INCONVENIENT_TO_USE("이용이 불편하고 장애가 많아서"), LOW_USAGE("사용 빈도가 낮아서"), @@ -15,6 +16,12 @@ public enum FeedbackType { private final String value; + @Override + public String getKey() { + return name(); + } + + @Override public String getValue() { return value; } diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index b2496f47..da1522df 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -166,7 +166,7 @@ public void deleteUser(DeleteUserRequestDto request, Long userId) { RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate); } - feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getConmment())); + feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getComment())); userRepository.delete(user); } diff --git a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java index 832b55b6..1ffed7b6 100644 --- a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java @@ -17,5 +17,5 @@ public class DeleteUserRequestDto { private FeedbackType feedbackType; @ApiModelProperty(value = "의견", example = "흠냐링 제법 괜찮았으나 안쓰게 되네요.") - private String conmment; + private String comment; } From 9864934240692011e71b430d0f81ecf757153f39 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 6 Nov 2022 22:34:14 +0900 Subject: [PATCH 246/301] =?UTF-8?q?#203=20[fix]=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EC=8B=9C=20=ED=94=BC=EB=93=9C=EB=B0=B1=20=EA=B0=92=EC=9D=B4=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=ED=95=A0=20=EA=B2=BD=EC=9A=B0=EC=97=90?= =?UTF-8?q?=EB=A7=8C=20=EB=94=94=EB=B9=84=EC=97=90=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/user/UserController.java | 3 +-- src/main/java/hous/server/domain/feedback/Feedback.java | 2 +- src/main/java/hous/server/service/user/UserService.java | 4 +++- .../server/service/user/dto/request/DeleteUserRequestDto.java | 3 --- src/main/resources/messages/validation.properties | 1 - 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 5f55e933..c5a7ebcb 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -129,11 +129,10 @@ public ResponseEntity> updateRepresentBadge(@ApiParam(na @ApiOperation( value = "[인증] 마이 페이지(설정) - 회원 정보를 삭제합니다.", - notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다. FeedbackType은 필수로 명시해야 합니다." + notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), - @ApiResponse(code = 400, message = "사유는 빈 값을 보낼 수 없습니다. (FeedbackType)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) diff --git a/src/main/java/hous/server/domain/feedback/Feedback.java b/src/main/java/hous/server/domain/feedback/Feedback.java index 01bbdd11..48ef1f75 100644 --- a/src/main/java/hous/server/domain/feedback/Feedback.java +++ b/src/main/java/hous/server/domain/feedback/Feedback.java @@ -16,7 +16,7 @@ public class Feedback extends AuditingTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false, length = 30) + @Column(length = 30) @Enumerated(EnumType.STRING) private FeedbackType feedbackType; diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index da1522df..93b7e7e6 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -166,7 +166,9 @@ public void deleteUser(DeleteUserRequestDto request, Long userId) { RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate); } - feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getComment())); + if (request.getFeedbackType() != null || request.getComment() != null) { + feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getComment())); + } userRepository.delete(user); } diff --git a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java index 1ffed7b6..ed9efd3a 100644 --- a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java @@ -4,8 +4,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.*; -import javax.validation.constraints.NotNull; - @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -13,7 +11,6 @@ public class DeleteUserRequestDto { @ApiModelProperty(value = "사유", example = "DONE_LIVING_TOGETHER") - @NotNull(message = "{user.delete.feedback.notNull}") private FeedbackType feedbackType; @ApiModelProperty(value = "의견", example = "흠냐링 제법 괜찮았으나 안쓰게 되네요.") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 38344e4a..168e49f3 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -26,4 +26,3 @@ todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uB todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.notNull=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. -user.delete.feedback.notNull=\uC0AC\uC720\uB294 \uBE48 \uAC12\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. From 5e2e78f9dd64448743fd49efec9612836906c82f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Mon, 7 Nov 2022 01:11:31 +0900 Subject: [PATCH 247/301] =?UTF-8?q?#207=20[fix]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20=EC=8B=9C?= =?UTF-8?q?=20mbti,=20job,=20introduction=EB=8A=94=20=EC=83=9D=EB=9E=B5=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../java/hous/server/controller/user/UserController.java | 9 +++------ .../user/dto/request/UpdateUserInfoRequestDto.java | 3 --- src/main/resources/messages/validation.properties | 3 --- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index c5a7ebcb..755e6b56 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -39,12 +39,9 @@ public class UserController { + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" + "3. 생년월일을 입력해주세요. (birthday)\n" + "4. 생년월일을 공개 여부를 체크해주세요. (isPublic)\n" - + "5. mbti 를 입력해주세요. (mbti)\n" - + "6. mbti 는 4 글자 이내로 입력해주세요. (mbti)\n" - + "7. 직업을 입력해주세요. (job)\n" - + "8. 직업은 3 글자 이내로 입력해주세요. (job)\n" - + "9. 자기소개를 입력해주세요.(introduction)\n" - + "10. 자기소개는 40 글자 이내로 입력해주세요. (introduction)", + + "5. mbti 는 4 글자 이내로 입력해주세요. (mbti)\n" + + "6. 직업은 3 글자 이내로 입력해주세요. (job)\n" + + "7. 자기소개는 40 글자 이내로 입력해주세요. (introduction)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, diff --git a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java index 592563d7..d09acd54 100644 --- a/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/UpdateUserInfoRequestDto.java @@ -35,17 +35,14 @@ public class UpdateUserInfoRequestDto { private Boolean isPublic; @ApiModelProperty(value = "MBTI", example = "CUTE") - @NotBlank(message = "{onboarding.mbti.notBlank}") @Size(max = Constraint.ONBOARDING_MBTI_MAX, message = "{onboarding.mbti.max}") private String mbti; @ApiModelProperty(value = "직업", example = "대학생") - @NotBlank(message = "{onboarding.job.notBlank}") @Size(max = Constraint.ONBOARDING_JOB_MAX, message = "{onboarding.job.max}") private String job; @ApiModelProperty(value = "자기소개", example = "안녕하세요. 저는 혜조니입니다~") - @NotBlank(message = "{onboarding.introduction.notBlank}") @Size(max = Constraint.ONBOARDING_INTRODUCTION_MAX, message = "{onboarding.introduction.max}") private String introduction; diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 168e49f3..d8ef254a 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -9,11 +9,8 @@ onboarding.nickname.notBlank=\uB2C9\uB124\uC784\uC744 \uC785\uB825\uD574\uC8FC\u onboarding.nickname.max=\uB2C9\uB124\uC784\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.birthday.notNull=\uC0DD\uB144\uC6D4\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.isPublic.notNull=\uC0DD\uB144\uC6D4\uC77C \uACF5\uAC1C \uC5EC\uBD80\uB97C \uCCB4\uD06C\uD574\uC8FC\uC138\uC694. -onboarding.mbti.notBlank=mbti \uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.mbti.max=mbti \uB294 4 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.job.notBlank=\uC9C1\uC5C5\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.job.max=\uC9C1\uC5C5\uC740 3 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. -onboarding.introduction.notBlank=\uC790\uAE30\uC18C\uAC1C\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.introduction.max=\uC790\uAE30\uC18C\uAC1C\uB294 40 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. onboarding.testScore.size=\uC131\uD5A5 \uD14C\uC2A4\uD2B8\uC758 \uAC01 \uC131\uD5A5 \uC810\uC218\uB294 \uCD5C\uC18C 3\uC810, \uCD5C\uB300 9\uC810\uC785\uB2C8\uB2E4. room.name.notBlank=\uBC29 \uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694. From f0350283cbed1e1b3cae9fdbc56cdb64eb8d7e76 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Mon, 7 Nov 2022 01:11:55 +0900 Subject: [PATCH 248/301] =?UTF-8?q?#207=20[fix]=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=ED=99=88=EB=B7=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=83=9D=EB=85=84?= =?UTF-8?q?=EC=9B=94=EC=9D=BC=20yy.mm.dd=20=ED=98=95=ED=83=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=AC=B4=EC=A1=B0=EA=B1=B4=20=EC=A0=84=EB=8B=AC=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/DateUtils.java | 5 +++++ .../hous/server/controller/user/UserRetrieveController.java | 3 +-- .../server/service/user/dto/response/UserInfoResponse.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/common/util/DateUtils.java b/src/main/java/hous/server/common/util/DateUtils.java index 3706887d..0cad65e4 100644 --- a/src/main/java/hous/server/common/util/DateUtils.java +++ b/src/main/java/hous/server/common/util/DateUtils.java @@ -30,6 +30,11 @@ public static String parseMonthAndDay(LocalDate date) { return date.format(formatter); } + public static String parseYearAndMonthAndDay(LocalDate date) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy.MM.dd"); + return date.format(formatter); + } + public static String nowDayOfWeek(LocalDate now) { return now.getDayOfWeek().toString(); } diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index ea2b23cc..5130a013 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -29,8 +29,7 @@ public class UserRetrieveController { @ApiOperation( value = "[인증] 마이 페이지(프로필 뷰) - 나의 프로필 정보를 확인합니다.", - notes = "성공 시, 생년월일 공개 여부(birthdayPublic) false 일 경우, 생년월일(birthday)은 null 입니다.\n" + - "사용자가 아직 입력하지 않은 데이터의 경우 null 이 전달됩니다." + notes = "사용자가 아직 입력하지 않은 데이터의 경우 null 이 전달됩니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "나의 프로필 정보 조회 성공입니다."), diff --git a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java index d27d424f..7e867b6f 100644 --- a/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java +++ b/src/main/java/hous/server/service/user/dto/response/UserInfoResponse.java @@ -79,7 +79,7 @@ public static UserInfoResponse of(Onboarding onboarding, Represent represent) { .nickname(onboarding.getNickname()) .birthdayPublic(onboarding.isPublic()) .age(MathUtils.getAge(onboarding.getBirthday()) + "세") - .birthday(onboarding.isPublic() ? DateUtils.parseMonthAndDay(onboarding.getBirthday()) : null) + .birthday(DateUtils.parseYearAndMonthAndDay(onboarding.getBirthday())) .mbti(onboarding.getMbti()) .job(onboarding.getJob()) .mbti(onboarding.getMbti()) From 9051ae4596577088f80872aa6029739190f1e768 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Mon, 7 Nov 2022 01:16:43 +0900 Subject: [PATCH 249/301] =?UTF-8?q?#208=20[fix]=20=EB=A9=A4=EB=B2=84?= =?UTF-8?q?=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EA=B0=81=20?= =?UTF-8?q?=EB=A9=A4=EB=B2=84=EC=9D=98=20=EC=9A=94=EC=9D=BC=EB=B3=84=20?= =?UTF-8?q?=EA=B7=9C=EC=B9=99=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EC=9D=98=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EC=88=9C=EC=84=9C=EB=A5=BC=20=EA=B7=9C?= =?UTF-8?q?=EC=B9=99=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=EC=A0=90=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=95=EB=A0=AC=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/service/todo/TodoRetrieveService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 2c071ca0..4f23f57d 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -151,6 +151,7 @@ public List getTodoAllMemberInfo(Long userId) { for (int i = 1; i < allDayMemberTodos.length; i++) { String dayOfWeek = DayOfWeek.getValueByIndex(i); List thisDayTodosName = allDayMemberTodos[i].stream() + .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) .collect(Collectors.toList()); dayOfWeekTodos.add(DayOfWeekTodo.of(dayOfWeek, thisDayTodosName.size(), thisDayTodosName)); From d978d01a02111bca985799f1926f828b54dc2389 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 7 Nov 2022 01:37:13 +0900 Subject: [PATCH 250/301] =?UTF-8?q?#209=20[fix]=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20fcmToken=20=EC=A4=91=EB=B3=B5=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/auth/CommonAuthService.java | 10 ++++++++++ .../server/service/auth/CommonAuthServiceUtils.java | 9 --------- .../server/service/auth/impl/AppleAuthService.java | 7 +++++-- .../server/service/auth/impl/KakaoAuthService.java | 7 +++++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/hous/server/service/auth/CommonAuthService.java b/src/main/java/hous/server/service/auth/CommonAuthService.java index 1f326fa1..b8039463 100644 --- a/src/main/java/hous/server/service/auth/CommonAuthService.java +++ b/src/main/java/hous/server/service/auth/CommonAuthService.java @@ -6,6 +6,7 @@ import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @@ -22,4 +23,13 @@ public void logout(Long userId) { jwtProvider.expireRefreshToken(user.getId()); user.resetFcmToken(); } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void resetConflictFcmToken(String fcmToken) { + User conflictFcmTokenUser = userRepository.findUserByFcmToken(fcmToken); + if (conflictFcmTokenUser != null) { + jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); + conflictFcmTokenUser.resetFcmToken(); + } + } } diff --git a/src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java b/src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java index 31c82cf7..97ff14ad 100644 --- a/src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java +++ b/src/main/java/hous/server/service/auth/CommonAuthServiceUtils.java @@ -4,7 +4,6 @@ import hous.server.common.util.JwtUtils; import hous.server.domain.common.RedisKey; import hous.server.domain.user.User; -import hous.server.domain.user.repository.UserRepository; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -14,14 +13,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CommonAuthServiceUtils { - public static void resetConflictFcmToken(UserRepository userRepository, JwtUtils jwtProvider, String fcmToken) { - User conflictFcmTokenUser = userRepository.findUserByFcmToken(fcmToken); - if (conflictFcmTokenUser != null) { - jwtProvider.expireRefreshToken(conflictFcmTokenUser.getId()); - conflictFcmTokenUser.resetFcmToken(); - } - } - public static void validateUniqueLogin(RedisTemplate redisTemplate, User user) { String refreshToken = (String) redisTemplate.opsForValue().get(RedisKey.REFRESH_TOKEN + user.getId()); if (refreshToken != null) { diff --git a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java index cc853e93..060941ca 100644 --- a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java @@ -6,6 +6,7 @@ import hous.server.domain.user.repository.UserRepository; import hous.server.external.client.apple.AppleTokenProvider; import hous.server.service.auth.AuthService; +import hous.server.service.auth.CommonAuthService; import hous.server.service.auth.CommonAuthServiceUtils; import hous.server.service.auth.dto.request.LoginDto; import hous.server.service.auth.dto.request.SignUpDto; @@ -29,6 +30,8 @@ public class AppleAuthService implements AuthService { private final UserService userService; + private final CommonAuthService commonAuthService; + private final JwtUtils jwtProvider; private final RedisTemplate redisTemplate; @@ -43,7 +46,7 @@ public Long signUp(SignUpDto request) { public Long login(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); - CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + commonAuthService.resetConflictFcmToken(request.getFcmToken()); CommonAuthServiceUtils.validateUniqueLogin(redisTemplate, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); @@ -53,7 +56,7 @@ public Long login(LoginDto request) { public Long forceLogin(LoginDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, socialId, socialType); - CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + commonAuthService.resetConflictFcmToken(request.getFcmToken()); CommonAuthServiceUtils.forceLogoutUser(redisTemplate, jwtProvider, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); diff --git a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java index 467dae52..e0942318 100644 --- a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java @@ -8,6 +8,7 @@ import hous.server.external.client.kakao.KakaoApiClient; import hous.server.external.client.kakao.dto.response.KakaoProfileResponse; import hous.server.service.auth.AuthService; +import hous.server.service.auth.CommonAuthService; import hous.server.service.auth.CommonAuthServiceUtils; import hous.server.service.auth.dto.request.LoginDto; import hous.server.service.auth.dto.request.SignUpDto; @@ -31,6 +32,8 @@ public class KakaoAuthService implements AuthService { private final UserService userService; + private final CommonAuthService commonAuthService; + private final JwtUtils jwtProvider; private final RedisTemplate redisTemplate; @@ -45,7 +48,7 @@ public Long signUp(SignUpDto request) { public Long login(LoginDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); - CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + commonAuthService.resetConflictFcmToken(request.getFcmToken()); CommonAuthServiceUtils.validateUniqueLogin(redisTemplate, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); @@ -55,7 +58,7 @@ public Long login(LoginDto request) { public Long forceLogin(LoginDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); User user = UserServiceUtils.findUserBySocialIdAndSocialType(userRepository, response.getId(), socialType); - CommonAuthServiceUtils.resetConflictFcmToken(userRepository, jwtProvider, request.getFcmToken()); + commonAuthService.resetConflictFcmToken(request.getFcmToken()); CommonAuthServiceUtils.forceLogoutUser(redisTemplate, jwtProvider, user); user.updateFcmToken(request.getFcmToken()); return user.getId(); From fab01aff316dfe261c988f55a62de734a12c05c5 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 9 Nov 2022 04:03:21 +0900 Subject: [PATCH 251/301] =?UTF-8?q?#195=20[feat]=20=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/exception/ErrorCode.java | 23 ++++++- .../common/exception/ErrorStatusCode.java | 1 + .../exception/UpgradeRequiredException.java | 8 +++ .../server/config/interceptor/Version.java | 12 ++++ .../interceptor/VersionCheckHandler.java | 61 +++++++++++++++++++ .../interceptor/VersionInterceptor.java | 30 +++++++++ .../server/config/swagger/SwaggerConfig.java | 36 +++++++++-- .../hous/server/domain/deploy/Deploy.java | 27 ++++++++ .../deploy/repository/DeployRepository.java | 8 +++ .../repository/DeployRepositoryCustom.java | 8 +++ .../repository/DeployRepositoryImpl.java | 23 +++++++ 11 files changed, 229 insertions(+), 8 deletions(-) create mode 100644 src/main/java/hous/server/common/exception/UpgradeRequiredException.java create mode 100644 src/main/java/hous/server/config/interceptor/Version.java create mode 100644 src/main/java/hous/server/config/interceptor/VersionCheckHandler.java create mode 100644 src/main/java/hous/server/config/interceptor/VersionInterceptor.java create mode 100644 src/main/java/hous/server/domain/deploy/Deploy.java create mode 100644 src/main/java/hous/server/domain/deploy/repository/DeployRepository.java create mode 100644 src/main/java/hous/server/domain/deploy/repository/DeployRepositoryCustom.java create mode 100644 src/main/java/hous/server/domain/deploy/repository/DeployRepositoryImpl.java diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index b20672e5..5cbfd61e 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -1,11 +1,22 @@ package hous.server.common.exception; +import static hous.server.common.exception.ErrorStatusCode.BAD_GATEWAY; +import static hous.server.common.exception.ErrorStatusCode.BAD_REQUEST; +import static hous.server.common.exception.ErrorStatusCode.CONFLICT; +import static hous.server.common.exception.ErrorStatusCode.FORBIDDEN; +import static hous.server.common.exception.ErrorStatusCode.INTERNAL_SERVER; +import static hous.server.common.exception.ErrorStatusCode.METHOD_NOT_ALLOWED; +import static hous.server.common.exception.ErrorStatusCode.NOT_ACCEPTABLE; +import static hous.server.common.exception.ErrorStatusCode.NOT_FOUND; +import static hous.server.common.exception.ErrorStatusCode.SERVICE_UNAVAILABLE; +import static hous.server.common.exception.ErrorStatusCode.UNAUTHORIZED; +import static hous.server.common.exception.ErrorStatusCode.UNSUPPORTED_MEDIA_TYPE; +import static hous.server.common.exception.ErrorStatusCode.UPGRADE_REQUIRED; + import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; -import static hous.server.common.exception.ErrorStatusCode.*; - @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum ErrorCode { @@ -19,6 +30,8 @@ public enum ErrorCode { VALIDATION_WRONG_TYPE_EXCEPTION(BAD_REQUEST, "잘못된 타입이 입력되었습니다."), VALIDATION_SOCIAL_TYPE_EXCEPTION(BAD_REQUEST, "잘못된 소셜 프로바이더 입니다."), VALIDATION_SORT_TYPE_EXCEPTION(BAD_REQUEST, "허용하지 않는 정렬기준을 입력했습니다."), + VALIDATION_OS_EXCEPTION(BAD_REQUEST, "잘못된 OS 타입 요청입니다."), + VALIDATION_VERSION_EXCEPTION(BAD_REQUEST, "잘못된 버전 형식입니다."), VALIDATION_STATUS_EXCEPTION(BAD_REQUEST, "잘못된 상태로 요청했습니다."), VALIDATION_RULE_MAX_LENGTH_EXCEPTION(BAD_REQUEST, "규칙은 20 글자 이내로 입력해주세요."), VALIDATION_RULE_MIN_LENGTH_EXCEPTION(BAD_REQUEST, "규칙 내용을 입력해주세요."), @@ -45,6 +58,7 @@ public enum ErrorCode { * 404 Not Found */ NOT_FOUND_EXCEPTION(NOT_FOUND, "존재하지 않습니다."), + NOT_FOUND_OS_EXCEPTION(NOT_FOUND, "배포되지 않은 OS 입니다."), NOT_FOUND_USER_EXCEPTION(NOT_FOUND, "탈퇴했거나 존재하지 않는 유저입니다."), NOT_FOUND_REFRESH_TOKEN_EXCEPTION(NOT_FOUND, "만료된 리프레시 토큰입니다."), NOT_FOUND_ONBOARDING_EXCEPTION(NOT_FOUND, "유저의 온보딩 정보가 존재하지 않습니다."), @@ -78,6 +92,11 @@ public enum ErrorCode { */ UNSUPPORTED_MEDIA_TYPE_EXCEPTION(UNSUPPORTED_MEDIA_TYPE, "해당하는 미디어 타입을 지원하지 않습니다."), + /** + * 426 Upgrade Required + */ + UPGRADE_REQUIRED_EXCEPTION(UPGRADE_REQUIRED, "최신 버전으로 업그레이드가 필요합니다."), + /** * 500 Internal Server Exception */ diff --git a/src/main/java/hous/server/common/exception/ErrorStatusCode.java b/src/main/java/hous/server/common/exception/ErrorStatusCode.java index 334f9f3c..663646bf 100644 --- a/src/main/java/hous/server/common/exception/ErrorStatusCode.java +++ b/src/main/java/hous/server/common/exception/ErrorStatusCode.java @@ -19,6 +19,7 @@ public enum ErrorStatusCode { NOT_ACCEPTABLE(406), CONFLICT(409), UNSUPPORTED_MEDIA_TYPE(415), + UPGRADE_REQUIRED(426), INTERNAL_SERVER(500), BAD_GATEWAY(502), SERVICE_UNAVAILABLE(503); diff --git a/src/main/java/hous/server/common/exception/UpgradeRequiredException.java b/src/main/java/hous/server/common/exception/UpgradeRequiredException.java new file mode 100644 index 00000000..353175b7 --- /dev/null +++ b/src/main/java/hous/server/common/exception/UpgradeRequiredException.java @@ -0,0 +1,8 @@ +package hous.server.common.exception; + +public class UpgradeRequiredException extends HousException { + + public UpgradeRequiredException(String message) { + super(message, ErrorCode.UPGRADE_REQUIRED_EXCEPTION); + } +} diff --git a/src/main/java/hous/server/config/interceptor/Version.java b/src/main/java/hous/server/config/interceptor/Version.java new file mode 100644 index 00000000..2e7550f7 --- /dev/null +++ b/src/main/java/hous/server/config/interceptor/Version.java @@ -0,0 +1,12 @@ +package hous.server.config.interceptor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Version { + +} diff --git a/src/main/java/hous/server/config/interceptor/VersionCheckHandler.java b/src/main/java/hous/server/config/interceptor/VersionCheckHandler.java new file mode 100644 index 00000000..ab826aa8 --- /dev/null +++ b/src/main/java/hous/server/config/interceptor/VersionCheckHandler.java @@ -0,0 +1,61 @@ +package hous.server.config.interceptor; + +import hous.server.common.exception.ErrorCode; +import hous.server.common.exception.NotFoundException; +import hous.server.common.exception.UpgradeRequiredException; +import hous.server.common.exception.ValidationException; +import hous.server.domain.deploy.Deploy; +import hous.server.domain.deploy.repository.DeployRepository; +import javax.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@RequiredArgsConstructor +@Component +public class VersionCheckHandler { + + private final DeployRepository deployRepository; + + public void checkVersion(HttpServletRequest request) { + String requestOs = request.getHeader("HousOsType"); + String requestVersion = request.getHeader("HousVersion"); + validateRequestOs(requestOs); + validateRequestVersion(requestVersion); + Deploy deploy = deployRepository.findDeployByOs(requestOs); + if (deploy == null) { + throw new NotFoundException(String.format("배포되지 않은 OS (%s) 입니다.", requestOs), + ErrorCode.NOT_FOUND_OS_EXCEPTION); + } + String latestVersion = deploy.getVersion(); + if (isOutdated(requestVersion, latestVersion)) { + throw new UpgradeRequiredException( + String.format("업그레이드가 필요한 버전 (%s - %s) 입니다.", requestOs, requestVersion)); + } + } + + private void validateRequestOs(String requestOs) { + if (!requestOs.matches("iOS|AOS")) { + throw new ValidationException(String.format("잘못된 OS 타입 요청 (%s) 입니다.", requestOs), + ErrorCode.VALIDATION_OS_EXCEPTION); + } + } + + private void validateRequestVersion(String requestVersion) { + if (!requestVersion.matches("\\d+\\.\\d+\\.\\d+")) { + throw new ValidationException(String.format("잘못된 버전 형식 (%s) 입니다.", requestVersion), + ErrorCode.VALIDATION_VERSION_EXCEPTION); + } + } + + private boolean isOutdated(String requestVersion, String latestVersion) { + String[] request = requestVersion.split("\\."); + String[] latest = latestVersion.split("\\."); + if (Integer.parseInt(request[0]) < Integer.parseInt(latest[0])) { + return true; + } + if (Integer.parseInt(request[1]) < Integer.parseInt(latest[1])) { + return true; + } + return false; + } +} diff --git a/src/main/java/hous/server/config/interceptor/VersionInterceptor.java b/src/main/java/hous/server/config/interceptor/VersionInterceptor.java new file mode 100644 index 00000000..6df7c1cc --- /dev/null +++ b/src/main/java/hous/server/config/interceptor/VersionInterceptor.java @@ -0,0 +1,30 @@ +package hous.server.config.interceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.HandlerInterceptor; + +@RequiredArgsConstructor +@Component +public class VersionInterceptor implements HandlerInterceptor { + + private final VersionCheckHandler versionCheckHandler; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + if (!(handler instanceof HandlerMethod)) { + return true; + } + HandlerMethod handlerMethod = (HandlerMethod) handler; + Version version = handlerMethod.getMethodAnnotation(Version.class); + if (version == null) { + return true; + } + versionCheckHandler.checkVersion(request); + return true; + } +} diff --git a/src/main/java/hous/server/config/swagger/SwaggerConfig.java b/src/main/java/hous/server/config/swagger/SwaggerConfig.java index 35223dd4..88f528d9 100644 --- a/src/main/java/hous/server/config/swagger/SwaggerConfig.java +++ b/src/main/java/hous/server/config/swagger/SwaggerConfig.java @@ -1,6 +1,11 @@ package hous.server.config.swagger; import com.fasterxml.classmate.TypeResolver; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,23 +15,21 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.schema.AlternateTypeRules; +import springfox.documentation.schema.ModelRef; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.ApiKey; import springfox.documentation.service.AuthorizationScope; +import springfox.documentation.service.Parameter; import springfox.documentation.service.SecurityReference; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - @Configuration @EnableSwagger2 @EnableWebMvc @@ -54,16 +57,37 @@ public Docket api() { .consumes(getConsumeContentTypes()) .produces(getProduceContentTypes()) .useDefaultResponseMessages(false) - .alternateTypeRules(AlternateTypeRules.newRule(typeResolver.resolve(Pageable.class), typeResolver.resolve(MyPageable.class))) + .alternateTypeRules(AlternateTypeRules.newRule(typeResolver.resolve(Pageable.class), + typeResolver.resolve(MyPageable.class))) .apiInfo(apiInfo()) .securityContexts(Arrays.asList(securityContext())) .securitySchemes(Arrays.asList(apiKey())) + .globalOperationParameters(getGlobalParameterTypes()) .select() .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) .paths(PathSelectors.any()) .build(); } + private List getGlobalParameterTypes() { + List global = new ArrayList<>(); + global.add(new ParameterBuilder() + .name("HousOsType") + .description("iOS/AOS") + .parameterType("header") + .required(true) + .modelRef(new ModelRef("string")) + .build()); + global.add(new ParameterBuilder() + .name("HousVersion") + .description("ex) 1.0.0") + .parameterType("header") + .required(true) + .modelRef(new ModelRef("string")) + .build()); + return global; + } + private Set getConsumeContentTypes() { Set consumes = new HashSet<>(); consumes.add("application/json;charset=UTF-8"); diff --git a/src/main/java/hous/server/domain/deploy/Deploy.java b/src/main/java/hous/server/domain/deploy/Deploy.java new file mode 100644 index 00000000..d901df7e --- /dev/null +++ b/src/main/java/hous/server/domain/deploy/Deploy.java @@ -0,0 +1,27 @@ +package hous.server.domain.deploy; + +import hous.server.domain.common.AuditingTimeEntity; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Deploy extends AuditingTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, length = 30) + private String os; + + @Column(nullable = false, length = 30) + private String version; +} diff --git a/src/main/java/hous/server/domain/deploy/repository/DeployRepository.java b/src/main/java/hous/server/domain/deploy/repository/DeployRepository.java new file mode 100644 index 00000000..0da67b8c --- /dev/null +++ b/src/main/java/hous/server/domain/deploy/repository/DeployRepository.java @@ -0,0 +1,8 @@ +package hous.server.domain.deploy.repository; + +import hous.server.domain.deploy.Deploy; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DeployRepository extends JpaRepository, DeployRepositoryCustom { + +} diff --git a/src/main/java/hous/server/domain/deploy/repository/DeployRepositoryCustom.java b/src/main/java/hous/server/domain/deploy/repository/DeployRepositoryCustom.java new file mode 100644 index 00000000..e9d50b2f --- /dev/null +++ b/src/main/java/hous/server/domain/deploy/repository/DeployRepositoryCustom.java @@ -0,0 +1,8 @@ +package hous.server.domain.deploy.repository; + +import hous.server.domain.deploy.Deploy; + +public interface DeployRepositoryCustom { + + Deploy findDeployByOs(String os); +} diff --git a/src/main/java/hous/server/domain/deploy/repository/DeployRepositoryImpl.java b/src/main/java/hous/server/domain/deploy/repository/DeployRepositoryImpl.java new file mode 100644 index 00000000..73e6608e --- /dev/null +++ b/src/main/java/hous/server/domain/deploy/repository/DeployRepositoryImpl.java @@ -0,0 +1,23 @@ +package hous.server.domain.deploy.repository; + +import static hous.server.domain.deploy.QDeploy.deploy; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import hous.server.domain.deploy.Deploy; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class DeployRepositoryImpl implements DeployRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public Deploy findDeployByOs(String os) { + return queryFactory + .selectFrom(deploy) + .where( + deploy.os.eq(os) + ) + .fetchOne(); + } +} From 9eea1dc49b0e52260f5143787fefa4702efc3adf Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 10 Nov 2022 16:15:55 +0900 Subject: [PATCH 252/301] =?UTF-8?q?#214=20[fix]=20=ED=81=B4=EB=9D=BC=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9C=A0=20=EC=84=A0=ED=83=9D=20=EC=8B=9C=20NO=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/user/UserController.java | 4 +++- src/main/java/hous/server/domain/feedback/FeedbackType.java | 1 + src/main/java/hous/server/service/user/UserService.java | 3 ++- .../server/service/user/dto/request/DeleteUserRequestDto.java | 3 +++ src/main/resources/messages/validation.properties | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 755e6b56..9f119d9d 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -126,10 +126,12 @@ public ResponseEntity> updateRepresentBadge(@ApiParam(na @ApiOperation( value = "[인증] 마이 페이지(설정) - 회원 정보를 삭제합니다.", - notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다." + notes = "회원 정보 탈퇴 요청 시 해당 유저의 모든 정보를 삭제합니다.\n" + + "feedbackType을 NO를 보낸 경우, 사유가 없는 것으로 판단합니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), + @ApiResponse(code = 400, message = "사유를 선택 안한 경우, NO를 보내주세요. (feedbackType)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) diff --git a/src/main/java/hous/server/domain/feedback/FeedbackType.java b/src/main/java/hous/server/domain/feedback/FeedbackType.java index 56993aee..2f80cda5 100644 --- a/src/main/java/hous/server/domain/feedback/FeedbackType.java +++ b/src/main/java/hous/server/domain/feedback/FeedbackType.java @@ -8,6 +8,7 @@ @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum FeedbackType implements EnumModel { + NO("없음"), DONE_LIVING_TOGETHER("공동생활이 끝나서"), INCONVENIENT_TO_USE("이용이 불편하고 장애가 많아서"), LOW_USAGE("사용 빈도가 낮아서"), diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index 93b7e7e6..e440529e 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -9,6 +9,7 @@ import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.common.RedisKey; import hous.server.domain.feedback.Feedback; +import hous.server.domain.feedback.FeedbackType; import hous.server.domain.feedback.repository.FeedbackRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; @@ -166,7 +167,7 @@ public void deleteUser(DeleteUserRequestDto request, Long userId) { RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate); } - if (request.getFeedbackType() != null || request.getComment() != null) { + if (!request.getFeedbackType().equals(FeedbackType.NO) || request.getComment() != null) { feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getComment())); } userRepository.delete(user); diff --git a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java index ed9efd3a..7e5e5afe 100644 --- a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java @@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.*; +import javax.validation.constraints.NotNull; + @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -11,6 +13,7 @@ public class DeleteUserRequestDto { @ApiModelProperty(value = "사유", example = "DONE_LIVING_TOGETHER") + @NotNull(message = "{user.feedbackType.notNull}") private FeedbackType feedbackType; @ApiModelProperty(value = "의견", example = "흠냐링 제법 괜찮았으나 안쓰게 되네요.") diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index d8ef254a..6c208b7e 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -23,3 +23,4 @@ todo.dayOfWeeks.notEmpty=\uB2F4\uB2F9 \uC694\uC77C \uBAA9\uB85D\uC740 \uBE48 \uB todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.notNull=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. +user.feedbackType.notNull=\uC0AC\uC720\uB97C \uC120\uD0DD \uC548\uD55C \uACBD\uC6B0, NO\uB97C \uBCF4\uB0B4\uC8FC\uC138\uC694. From 09471e99224ac29f2ccd6dfdc1a292e9f2989ec6 Mon Sep 17 00:00:00 2001 From: Joon Date: Fri, 11 Nov 2022 15:21:37 +0900 Subject: [PATCH 253/301] =?UTF-8?q?#216=20[fix]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=EC=8B=9C=20fcmToken=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/auth/impl/AppleAuthService.java | 1 + .../java/hous/server/service/auth/impl/KakaoAuthService.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java index 060941ca..45dc8a03 100644 --- a/src/main/java/hous/server/service/auth/impl/AppleAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/AppleAuthService.java @@ -39,6 +39,7 @@ public class AppleAuthService implements AuthService { @Override public Long signUp(SignUpDto request) { String socialId = appleTokenDecoder.getSocialIdFromIdToken(request.getToken()); + commonAuthService.resetConflictFcmToken(request.getFcmToken()); return userService.registerUser(request.toCreateUserDto(socialId)); } diff --git a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java index e0942318..b9614d3c 100644 --- a/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java +++ b/src/main/java/hous/server/service/auth/impl/KakaoAuthService.java @@ -41,6 +41,7 @@ public class KakaoAuthService implements AuthService { @Override public Long signUp(SignUpDto request) { KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(HttpHeaderUtils.withBearerToken(request.getToken())); + commonAuthService.resetConflictFcmToken(request.getFcmToken()); return userService.registerUser(request.toCreateUserDto(response.getId())); } From 286441d63850343d1845001e4d409def5ee242c5 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 12 Nov 2022 11:24:57 +0900 Subject: [PATCH 254/301] =?UTF-8?q?#218=20[fix]=20=ED=99=88=EC=97=90?= =?UTF-8?q?=EC=84=9C=20response=20=EC=A4=91=20=EC=9C=A0=EC=A0=80=EC=9D=98?= =?UTF-8?q?=20id=20=EC=A0=84=EB=8B=AC=20=EC=8B=9C=20userId=EB=A5=BC=20?= =?UTF-8?q?=EC=A0=84=EB=8B=AC=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../hous/server/service/home/dto/response/HomeInfoResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java index 35769c82..5b7e8c10 100644 --- a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java +++ b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java @@ -65,7 +65,7 @@ public static HomeInfoResponse of(Onboarding me, Room room, LocalDate today, Lis .collect(Collectors.toList())) .homies(participants.stream() .map(onboarding -> HomieInfo.builder() - .homieId(onboarding.getId()) + .homieId(onboarding.getUser().getId()) .userNickname(onboarding.getNickname()) .color(onboarding.getPersonality().getColor()) .build()) From e41f02ed15a3cccd9c6250f2101deb5fede29291 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 12 Nov 2022 11:25:10 +0900 Subject: [PATCH 255/301] =?UTF-8?q?#218=20[fix]=20response=20=EC=A4=91=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EC=9D=98=20id=20=EC=A0=84=EB=8B=AC=20?= =?UTF-8?q?=EC=8B=9C=20userId=EB=A5=BC=20=EC=A0=84=EB=8B=AC=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/todo/dto/response/TodoInfoResponse.java | 2 +- .../service/todo/dto/response/UserPersonalityInfoResponse.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java index 10f52abd..68d3b1f2 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java @@ -46,7 +46,7 @@ private static List toTodoInfoList(Todo todo, List onb .filter(take -> take.getOnboarding().getId().equals(onboarding.getId())) .findFirst(); return TodoUserInfo.of( - onboarding.getId(), + onboarding.getUser().getId(), onboarding.getPersonality().getColor(), onboarding.getNickname(), myTake.isPresent(), diff --git a/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java index 217fc4aa..2cef09b3 100644 --- a/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java @@ -19,7 +19,7 @@ public static UserPersonalityInfoResponse of(List onboardings) { return UserPersonalityInfoResponse.builder() .users(onboardings.stream() .map(onboarding -> UserPersonalityInfo.of( - onboarding.getId(), + onboarding.getUser().getId(), onboarding.getPersonality().getColor(), onboarding.getNickname())) .collect(Collectors.toList())) From 05e0c4b0cb5af9c7858f2d0634c7f303e5d1c497 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 12 Nov 2022 11:30:24 +0900 Subject: [PATCH 256/301] =?UTF-8?q?#218=20[docs]=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=95=EB=B3=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20api=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20400=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=B5=9C=EB=8C=80=20?= =?UTF-8?q?=EC=88=AB=EC=9E=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 9f119d9d..8c800aeb 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -36,7 +36,7 @@ public class UserController { @ApiResponse( code = 400, message = "1. 닉네임을 입력해주세요. (nickname)\n" - + "2. 닉네임은 최대 5글자까지 가능합니다. (nickname)\n" + + "2. 닉네임은 최대 3글자까지 가능합니다. (nickname)\n" + "3. 생년월일을 입력해주세요. (birthday)\n" + "4. 생년월일을 공개 여부를 체크해주세요. (isPublic)\n" + "5. mbti 는 4 글자 이내로 입력해주세요. (mbti)\n" From de94a5696b7ec830eaca0aa71cd0a90345720dd9 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 12 Nov 2022 11:31:09 +0900 Subject: [PATCH 257/301] =?UTF-8?q?#218=20[fix]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=ED=83=88=ED=87=B4=20api=20=EC=A4=91=20=EC=9D=98=EA=B2=AC=20?= =?UTF-8?q?=EC=B5=9C=EB=8C=80=20=EA=B8=80=EC=9E=90=20200=EA=B9=8C=EC=A7=80?= =?UTF-8?q?=EB=A7=8C=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20val?= =?UTF-8?q?idate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/user/UserController.java | 5 ++++- src/main/java/hous/server/domain/common/Constraint.java | 1 + .../service/user/dto/request/DeleteUserRequestDto.java | 3 +++ src/main/resources/messages/validation.properties | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 8c800aeb..29ac0d5d 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -131,7 +131,10 @@ public ResponseEntity> updateRepresentBadge(@ApiParam(na ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), - @ApiResponse(code = 400, message = "사유를 선택 안한 경우, NO를 보내주세요. (feedbackType)", response = ErrorResponse.class), + @ApiResponse(code = 400, + message = "1. 사유를 선택 안한 경우, NO를 보내주세요. (feedbackType)\n" + + "2. 의견은 200 글자 이내로 입력해주세요. (comment)", + response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) diff --git a/src/main/java/hous/server/domain/common/Constraint.java b/src/main/java/hous/server/domain/common/Constraint.java index 6f1fb292..0dc1defb 100644 --- a/src/main/java/hous/server/domain/common/Constraint.java +++ b/src/main/java/hous/server/domain/common/Constraint.java @@ -15,4 +15,5 @@ public final class Constraint { public static final int RULE_NAME_MAX = 20; public static final int RULE_COUNT_MAX = 30; public static final int RULE_LIST_MIN = 1; + public static final int FEEDBACK_COMMENT_MAX = 200; } diff --git a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java index 7e5e5afe..a9ed108b 100644 --- a/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java +++ b/src/main/java/hous/server/service/user/dto/request/DeleteUserRequestDto.java @@ -1,10 +1,12 @@ package hous.server.service.user.dto.request; +import hous.server.domain.common.Constraint; import hous.server.domain.feedback.FeedbackType; import io.swagger.annotations.ApiModelProperty; import lombok.*; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; @ToString @Getter @@ -17,5 +19,6 @@ public class DeleteUserRequestDto { private FeedbackType feedbackType; @ApiModelProperty(value = "의견", example = "흠냐링 제법 괜찮았으나 안쓰게 되네요.") + @Size(max = Constraint.FEEDBACK_COMMENT_MAX, message = "{user.comment.max}") private String comment; } diff --git a/src/main/resources/messages/validation.properties b/src/main/resources/messages/validation.properties index 6c208b7e..6d3bc47e 100644 --- a/src/main/resources/messages/validation.properties +++ b/src/main/resources/messages/validation.properties @@ -24,3 +24,4 @@ todo.status.notNull=\uC694\uCCAD\uD560 \uCCB4\uD06C \uC0C1\uD0DC\uB97C \uC785\uB rule.list.notNull=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694. rule.list.min=\uADDC\uCE59 \uB9AC\uC2A4\uD2B8\uB294 \uBE48 \uBC30\uC5F4\uC744 \uBCF4\uB0BC \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. user.feedbackType.notNull=\uC0AC\uC720\uB97C \uC120\uD0DD \uC548\uD55C \uACBD\uC6B0, NO\uB97C \uBCF4\uB0B4\uC8FC\uC138\uC694. +user.comment.max=\uC758\uACAC\uC740 200 \uAE00\uC790 \uC774\uB0B4\uB85C \uC785\uB825\uD574\uC8FC\uC138\uC694. From 4992d420936b4a63d28a6656b5bfaef6408f8658 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 12 Nov 2022 18:23:31 +0900 Subject: [PATCH 258/301] =?UTF-8?q?#220=20[fix]=20=EC=98=A8=EB=B3=B4?= =?UTF-8?q?=EB=94=A9=20introduction=20=ED=95=84=EB=93=9C=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 --- src/main/java/hous/server/domain/user/Onboarding.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index b2e80fe6..46552388 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -37,7 +37,7 @@ public class Onboarding extends AuditingTimeEntity implements Comparable Date: Mon, 14 Nov 2022 01:00:34 +0900 Subject: [PATCH 259/301] =?UTF-8?q?#220=20[docs]=20api=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=EC=97=90=20404=EC=98=88=EC=99=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/controller/user/UserRetrieveController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 5130a013..4c3be09e 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -34,7 +34,10 @@ public class UserRetrieveController { @ApiResponses(value = { @ApiResponse(code = 200, message = "나의 프로필 정보 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 참가중인 방이 존재하지 않습니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth From 258d9dca022e5cea0d1ebae6e97b4f66ccf629a6 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Mon, 14 Nov 2022 01:01:01 +0900 Subject: [PATCH 260/301] =?UTF-8?q?#222=20[fix]=20=EC=9E=90=EA=B8=B0?= =?UTF-8?q?=EC=86=8C=EA=B0=9C=EC=97=90=EC=84=9C=20\n=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=20=EC=8B=9C=20=EA=B3=B5=EB=B0=B1=EC=9C=BC=EB=A1=9C=20=EC=B9=98?= =?UTF-8?q?=ED=99=98=ED=95=98=EC=97=AC=20=EC=A0=80=EC=9E=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/controller/user/UserController.java | 2 +- src/main/java/hous/server/domain/user/Onboarding.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 29ac0d5d..3a2677c5 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -29,7 +29,7 @@ public class UserController { @ApiOperation( value = "[인증] 마이 페이지(Profile 뷰) - 나의 프로필 정보를 수정합니다.", - notes = "프로필 정보 수정을 요청합니다." + notes = "프로필 정보 수정을 요청합니다. 자기소개에서 줄바꿈을 포함할 경우, ' '(공백)으로 변환하여 저장합니다." ) @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 46552388..595e2313 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -113,7 +113,7 @@ public void updateUserInfo(UpdateUserInfoRequestDto request) { this.birthday = request.getBirthday(); this.mbti = request.getMbti(); this.job = request.getJob(); - this.introduction = request.getIntroduction(); + this.introduction = request.getIntroduction().replaceAll("(\r\n|\r|\n|\n\r)", " "); } public void resetUserInfo() { From 1e00a7bd5ff4e65dc29b1086ec5926b272583c0e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 18 Nov 2022 22:20:25 +0900 Subject: [PATCH 261/301] =?UTF-8?q?#225=20[fix]=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EC=9B=8C=EB=94=A9=20=EC=A7=91=20Rules=20-?= =?UTF-8?q?>=20=EC=B2=AB=20Rules=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 --- src/main/java/hous/server/domain/badge/BadgeInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/badge/BadgeInfo.java b/src/main/java/hous/server/domain/badge/BadgeInfo.java index 2a361aa2..31631921 100644 --- a/src/main/java/hous/server/domain/badge/BadgeInfo.java +++ b/src/main/java/hous/server/domain/badge/BadgeInfo.java @@ -18,7 +18,7 @@ public enum BadgeInfo implements EnumModel { GOOD_JOB("참 잘했어요", "1주 동안 to-do\n모두 완료"), SINCERITY_KING_HOMIE("성실왕 호미", "2주 동안\nto-do 모두 완료"), TODO_MASTER("to-do 마스터", "3주 동안\nto-do 모두 완료"), - LETS_BUILD_A_POLE("기둥을 세우자", "우리 집 규칙에서\n집 Rules 등록"), + LETS_BUILD_A_POLE("기둥을 세우자", "우리 집 규칙에서\n첫 Rules 등록"), OUR_HOUSE_PILLAR_HOMIE("우리 집 기둥 호미", "우리 집 Rules\n5개 이상 등록"), FEEDBACK_ONE_STEP("피드백 한 걸음", "좋은 의견을\n호미 나라에 전달"); From 14c35b0d35819f6bf9a6df381e45b7190239672f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 18 Nov 2022 23:20:40 +0900 Subject: [PATCH 262/301] =?UTF-8?q?#227=20[fix]=20homieId=20->=20onboardin?= =?UTF-8?q?gId=20=EB=A1=9C=20=ED=86=B5=EC=9D=BC,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/user/UserRetrieveController.java | 8 ++++---- .../service/home/dto/response/HomeInfoResponse.java | 4 ++-- .../service/todo/dto/response/TodoInfoResponse.java | 2 +- .../todo/dto/response/UserPersonalityInfoResponse.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 4c3be09e..66231cd7 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -59,10 +59,10 @@ public ResponseEntity> getUserInfo(@ApiIgnore @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth - @GetMapping("/user/{homieId}") - public ResponseEntity> getHomieInfo(@ApiParam(name = "homieId", value = "조회할 호미의 id", required = true, example = "1") - @PathVariable Long homieId, @ApiIgnore @UserId Long userId) { - return SuccessResponse.success(SuccessCode.GET_HOMIE_PROFILE_INFO_SUCCESS, userRetrieveService.getHomieInfo(homieId, userId)); + @GetMapping("/user/{onboardingId}") + public ResponseEntity> getHomieInfo(@ApiParam(name = "onboardingId", value = "조회할 호미의 id", required = true, example = "1") + @PathVariable Long onboardingId, @ApiIgnore @UserId Long userId) { + return SuccessResponse.success(SuccessCode.GET_HOMIE_PROFILE_INFO_SUCCESS, userRetrieveService.getHomieInfo(onboardingId, userId)); } @ApiOperation( diff --git a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java index 5b7e8c10..05072747 100644 --- a/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java +++ b/src/main/java/hous/server/service/home/dto/response/HomeInfoResponse.java @@ -39,7 +39,7 @@ public class HomeInfoResponse { @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) public static class HomieInfo { - private Long homieId; + private Long onboardingId; private String userNickname; private PersonalityColor color; } @@ -65,7 +65,7 @@ public static HomeInfoResponse of(Onboarding me, Room room, LocalDate today, Lis .collect(Collectors.toList())) .homies(participants.stream() .map(onboarding -> HomieInfo.builder() - .homieId(onboarding.getUser().getId()) + .onboardingId(onboarding.getId()) .userNickname(onboarding.getNickname()) .color(onboarding.getPersonality().getColor()) .build()) diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java index 68d3b1f2..10f52abd 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoInfoResponse.java @@ -46,7 +46,7 @@ private static List toTodoInfoList(Todo todo, List onb .filter(take -> take.getOnboarding().getId().equals(onboarding.getId())) .findFirst(); return TodoUserInfo.of( - onboarding.getUser().getId(), + onboarding.getId(), onboarding.getPersonality().getColor(), onboarding.getNickname(), myTake.isPresent(), diff --git a/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java index 2cef09b3..217fc4aa 100644 --- a/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/UserPersonalityInfoResponse.java @@ -19,7 +19,7 @@ public static UserPersonalityInfoResponse of(List onboardings) { return UserPersonalityInfoResponse.builder() .users(onboardings.stream() .map(onboarding -> UserPersonalityInfo.of( - onboarding.getUser().getId(), + onboarding.getId(), onboarding.getPersonality().getColor(), onboarding.getNickname())) .collect(Collectors.toList())) From d46d0c957244445b193d95dbf748fd44c9639404 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 18 Nov 2022 23:33:21 +0900 Subject: [PATCH 263/301] =?UTF-8?q?#227=20[fix]=20=EC=9A=94=EC=9D=BC?= =?UTF-8?q?=EB=B3=84=EB=A1=9C=20todo=20=ED=95=84=ED=84=B0=EB=A7=81=20?= =?UTF-8?q?=EC=8B=9C=20List[]=20->=20Map>?= =?UTF-8?q?=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/todo/TodoRetrieveService.java | 24 +++++++++---------- .../server/service/todo/TodoServiceUtils.java | 17 ++++++------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 4f23f57d..486f0f7a 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -21,9 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -109,18 +107,18 @@ public List getTodoAllDayInfo(Long userId) { List myTodosList = TodoServiceUtils.filterAllDaysUserTodos(todos, user.getOnboarding()); // 요일별(index) todo list 형태로 가공 - List[] allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToList(ourTodosList); - List[] allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToList(myTodosList); + Map> allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToList(ourTodosList); + Map> allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToList(myTodosList); // List response dto 형태로 가공 List allDayTodosList = new ArrayList<>(); - for (int i = 1; i < 8; i++) { - String dayOfWeek = DayOfWeek.getValueByIndex(i); - List todoInfos = allDayMyTodosList[i].stream() + for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.FRIDAY.getIndex(); day++) { + String dayOfWeek = DayOfWeek.getValueByIndex(day); + List todoInfos = allDayMyTodosList.get(day).stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) .collect(Collectors.toList()); - List ourTodoInfos = allDayOurTodosList[i].stream() + List ourTodoInfos = allDayOurTodosList.get(day).stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> OurTodo.of(todo.getName(), todo.getTakes().stream() .map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))) @@ -144,13 +142,13 @@ public List getTodoAllMemberInfo(Long userId) { .forEach(participate -> { List memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); - List[] allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos); + Map> allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos); List dayOfWeekTodos = new ArrayList<>(); int totalTodoCnt = 0; - for (int i = 1; i < allDayMemberTodos.length; i++) { - String dayOfWeek = DayOfWeek.getValueByIndex(i); - List thisDayTodosName = allDayMemberTodos[i].stream() + for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.FRIDAY.getIndex(); day++) { + String dayOfWeek = DayOfWeek.getValueByIndex(day); + List thisDayTodosName = allDayMemberTodos.get(day).stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) .collect(Collectors.toList()); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 45a1e0d4..ec83708f 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -16,10 +16,7 @@ import lombok.NoArgsConstructor; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static hous.server.common.exception.ErrorCode.*; @@ -94,17 +91,17 @@ public static List filterAllDaysMyDones(Onboarding me, List dones) { .collect(Collectors.toList()); } - public static List[] mapByDayOfWeekToList(List todos) { - List[] todosList = new ArrayList[8]; + public static Map> mapByDayOfWeekToList(List todos) { + Map> todosList = new HashMap<>(); for (int index = 0; index < 8; index++) { - todosList[index] = new ArrayList<>(); + todosList.put(index, new HashSet<>()); } todos.forEach(todo -> todo.getTakes().forEach(take -> take.getRedos().forEach(redo -> { - if (!todosList[redo.getDayOfWeek().getIndex()].contains(todo)) { - todosList[redo.getDayOfWeek().getIndex()].add(todo); - } + Set todosByDayOfWeek = todosList.get(redo.getDayOfWeek().getIndex()); + todosByDayOfWeek.add(todo); + todosList.put(redo.getDayOfWeek().getIndex(), todosByDayOfWeek); }) )); return todosList; From 315cc8e65147795770210e252639d168585e26f4 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 18 Nov 2022 23:48:28 +0900 Subject: [PATCH 264/301] =?UTF-8?q?#227=20[fix]=20IntStream=20->=20fori?= =?UTF-8?q?=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 --- src/main/java/hous/server/service/rule/RuleService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index d6325efa..34cdf2ee 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -import java.util.stream.IntStream; @RequiredArgsConstructor @Service @@ -77,11 +76,11 @@ public void createRule(CreateRuleRequestDto request, Long userId) { public void updateRules(UpdateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - IntStream.range(0, request.getRules().size()).forEach(idx -> { + for (int idx = 0; idx < request.getRules().size(); idx++) { Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); rule.updateRule(request.getRules().get(idx).getName(), idx); room.updateRule(rule); - }); + } } public void deleteRules(DeleteRuleReqeustDto request, Long userId) { From a2221eb410505f3facedb3dfec59a859153362f2 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 19 Nov 2022 00:05:46 +0900 Subject: [PATCH 265/301] =?UTF-8?q?#227=20[fix]=20findOnboardingById=20uti?= =?UTF-8?q?l=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/todo/TodoService.java | 4 ++-- .../hous/server/service/user/UserRetrieveService.java | 10 ++++++---- .../hous/server/service/user/UserServiceUtils.java | 9 +++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index e280e38b..1ce508fc 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -50,7 +50,7 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { TodoServiceUtils.validateTodoCounts(room); Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); request.getTodoUsers().forEach(todoUser -> { - Onboarding onboarding = onboardingRepository.findOnboardingById(todoUser.getOnboardingId()); + Onboarding onboarding = UserServiceUtils.findOnboardingById(onboardingRepository, todoUser.getOnboardingId()); Take take = takeRepository.save(Take.newInstance(todo, onboarding)); todoUser.getDayOfWeeks().forEach(dayOfWeek -> { Redo redo = redoRepository.save(Redo.newInstance(take, dayOfWeek)); @@ -78,7 +78,7 @@ public void updateTodo(Long todoId, TodoInfoRequestDto request) { }); List takes = new ArrayList<>(); request.getTodoUsers().forEach(todoUser -> { - Onboarding onboarding = onboardingRepository.findOnboardingById(todoUser.getOnboardingId()); + Onboarding onboarding = UserServiceUtils.findOnboardingById(onboardingRepository, todoUser.getOnboardingId()); Take take = takeRepository.save(Take.newInstance(todo, onboarding)); todoUser.getDayOfWeeks().forEach(dayOfWeek -> { Redo redo = redoRepository.save(Redo.newInstance(take, dayOfWeek)); diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 67a6bacb..685ab7e8 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -14,6 +14,7 @@ import hous.server.domain.room.Room; import hous.server.domain.user.Onboarding; import hous.server.domain.user.User; +import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; import hous.server.service.user.dto.response.*; @@ -30,6 +31,7 @@ public class UserRetrieveService { private final UserRepository userRepository; + private final OnboardingRepository onboardingRepository; private final PersonalityRepository personalityRepository; private final PersonalityTestRepository personalityTestRepository; private final RepresentRepository representRepository; @@ -42,13 +44,13 @@ public UserInfoResponse getUserInfo(Long userId) { return getProfileInfoByUser(user); } - public UserInfoResponse getHomieInfo(Long homieId, Long userId) { + public UserInfoResponse getHomieInfo(Long homieOnboardingId, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); - User homie = UserServiceUtils.findUserById(userRepository, homieId); + Onboarding homieOnboarding = UserServiceUtils.findOnboardingById(onboardingRepository, homieOnboardingId); Room userRoom = RoomServiceUtils.findParticipatingRoom(user); - Room homieRoom = RoomServiceUtils.findParticipatingRoom(homie); + Room homieRoom = RoomServiceUtils.findParticipatingRoom(homieOnboarding.getUser()); RoomServiceUtils.checkParticipatingRoom(userRoom, homieRoom); - return getProfileInfoByUser(homie); + return getProfileInfoByUser(homieOnboarding.getUser()); } public PushSettingResponse getUserPushSetting(Long userId) { diff --git a/src/main/java/hous/server/service/user/UserServiceUtils.java b/src/main/java/hous/server/service/user/UserServiceUtils.java index 4e85387d..d4c7e956 100644 --- a/src/main/java/hous/server/service/user/UserServiceUtils.java +++ b/src/main/java/hous/server/service/user/UserServiceUtils.java @@ -10,6 +10,7 @@ import hous.server.domain.user.TestScore; import hous.server.domain.user.User; import hous.server.domain.user.UserSocialType; +import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; import lombok.AccessLevel; @@ -46,6 +47,14 @@ public static User findUserById(UserRepository userRepository, Long userId) { return user; } + public static Onboarding findOnboardingById(OnboardingRepository onboardingRepository, Long onboardingId) { + Onboarding onboarding = onboardingRepository.findOnboardingById(onboardingId); + if (onboarding == null) { + throw new NotFoundException(String.format("존재하지 않는 온보딩 정보 (%s) 입니다", onboardingId), NOT_FOUND_ONBOARDING_EXCEPTION); + } + return onboarding; + } + public static void validatePushSettingRequest(UpdatePushSettingRequestDto request, User user) { int notNullStatusCnt = 0; if (request.isPushNotification() != null) { From c23c0e6ece3b2bb566d950daa2088cdcf5c44a39 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 19 Nov 2022 00:21:24 +0900 Subject: [PATCH 266/301] =?UTF-8?q?#227=20[fix]=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/todo/TodoRetrieveService.java | 4 ++-- .../hous/server/service/todo/TodoServiceUtils.java | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 486f0f7a..b44eed77 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -112,7 +112,7 @@ public List getTodoAllDayInfo(Long userId) { // List response dto 형태로 가공 List allDayTodosList = new ArrayList<>(); - for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.FRIDAY.getIndex(); day++) { + for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.SUNDAY.getIndex(); day++) { String dayOfWeek = DayOfWeek.getValueByIndex(day); List todoInfos = allDayMyTodosList.get(day).stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) @@ -146,7 +146,7 @@ public List getTodoAllMemberInfo(Long userId) { List dayOfWeekTodos = new ArrayList<>(); int totalTodoCnt = 0; - for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.FRIDAY.getIndex(); day++) { + for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.SUNDAY.getIndex(); day++) { String dayOfWeek = DayOfWeek.getValueByIndex(day); List thisDayTodosName = allDayMemberTodos.get(day).stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index ec83708f..ef2e1e11 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -92,19 +92,16 @@ public static List filterAllDaysMyDones(Onboarding me, List dones) { } public static Map> mapByDayOfWeekToList(List todos) { - Map> todosList = new HashMap<>(); - for (int index = 0; index < 8; index++) { - todosList.put(index, new HashSet<>()); - } + Map> todosMapByDayOfWeek = new HashMap<>(); todos.forEach(todo -> todo.getTakes().forEach(take -> take.getRedos().forEach(redo -> { - Set todosByDayOfWeek = todosList.get(redo.getDayOfWeek().getIndex()); + Set todosByDayOfWeek = todosMapByDayOfWeek.getOrDefault(redo.getDayOfWeek().getIndex(), new HashSet<>()); todosByDayOfWeek.add(todo); - todosList.put(redo.getDayOfWeek().getIndex(), todosByDayOfWeek); + todosMapByDayOfWeek.put(redo.getDayOfWeek().getIndex(), todosByDayOfWeek); }) )); - return todosList; + return todosMapByDayOfWeek; } public static List filterDayMyTodos(LocalDate day, Onboarding me, List todos) { From 4aa2522a369daa41032f083ce8c318e00d699a74 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 19 Nov 2022 13:53:05 +0900 Subject: [PATCH 267/301] =?UTF-8?q?#229=20[fix]=20updateUserInfo=20introdu?= =?UTF-8?q?ction=20null=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EA=B3=A0=EB=A0=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/user/Onboarding.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index 595e2313..c4eaae61 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -113,7 +113,9 @@ public void updateUserInfo(UpdateUserInfoRequestDto request) { this.birthday = request.getBirthday(); this.mbti = request.getMbti(); this.job = request.getJob(); - this.introduction = request.getIntroduction().replaceAll("(\r\n|\r|\n|\n\r)", " "); + if (request.getIntroduction() != null) { + this.introduction = request.getIntroduction().replaceAll("(\r\n|\r|\n|\n\r)", " "); + } } public void resetUserInfo() { From 97e6c0c86dca1ca2abc0d5edf6cf5a6fafd6d25c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 19 Nov 2022 14:03:25 +0900 Subject: [PATCH 268/301] =?UTF-8?q?#229=20[fix]=20map=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/todo/TodoServiceUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index ef2e1e11..d2fc42af 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -6,6 +6,7 @@ import hous.server.common.util.DateUtils; import hous.server.domain.common.Constraint; import hous.server.domain.room.Room; +import hous.server.domain.todo.DayOfWeek; import hous.server.domain.todo.Done; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; @@ -93,10 +94,13 @@ public static List filterAllDaysMyDones(Onboarding me, List dones) { public static Map> mapByDayOfWeekToList(List todos) { Map> todosMapByDayOfWeek = new HashMap<>(); + for (int i = DayOfWeek.MONDAY.getIndex(); i <= DayOfWeek.SUNDAY.getIndex(); i++) { + todosMapByDayOfWeek.put(i, new HashSet<>()); + } todos.forEach(todo -> todo.getTakes().forEach(take -> take.getRedos().forEach(redo -> { - Set todosByDayOfWeek = todosMapByDayOfWeek.getOrDefault(redo.getDayOfWeek().getIndex(), new HashSet<>()); + Set todosByDayOfWeek = todosMapByDayOfWeek.get(redo.getDayOfWeek().getIndex()); todosByDayOfWeek.add(todo); todosMapByDayOfWeek.put(redo.getDayOfWeek().getIndex(), todosByDayOfWeek); }) From 39d08e04b669a64ff097c212be1b9b6e80b5f8ed Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 23 Nov 2022 13:18:19 +0900 Subject: [PATCH 269/301] =?UTF-8?q?#231=20[feat]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=ED=83=88=ED=87=B4=20=EC=8B=9C=20=EC=8A=AC=EB=9E=99?= =?UTF-8?q?=20=EC=95=8C=EB=A6=BC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advice/ControllerExceptionAdvice.java | 6 +- .../controller/user/UserController.java | 5 ++ .../server/service/slack/SlackService.java | 74 +++++++------------ .../service/slack/SlackServiceUtils.java | 74 +++++++++++++++++++ .../slack/dto/response/UserDelete.java | 26 +++++++ .../dto/response/UserDeleteResponse.java | 29 +++----- .../service/user/UserRetrieveService.java | 20 +++++ 7 files changed, 162 insertions(+), 72 deletions(-) create mode 100644 src/main/java/hous/server/service/slack/SlackServiceUtils.java create mode 100644 src/main/java/hous/server/service/slack/dto/response/UserDelete.java diff --git a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java index d5709891..be058c52 100644 --- a/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java +++ b/src/main/java/hous/server/controller/advice/ControllerExceptionAdvice.java @@ -43,7 +43,7 @@ protected ResponseEntity handleBaseException(HousException except log.warn(exception.getMessage(), exception); } else { log.error(exception.getMessage(), exception); - slackService.sendSlackMessage(exception); + slackService.sendSlackMessageProductError(exception); } return ResponseEntity.status(exception.getStatus()) .body(ErrorResponse.error(exception.getErrorCode())); @@ -58,7 +58,7 @@ protected ResponseEntity handleFeignClientException(final FeignCl log.warn(exception.getMessage(), exception); } else { log.error(exception.getMessage(), exception); - slackService.sendSlackMessage(exception); + slackService.sendSlackMessageProductError(exception); } if (exception.getStatus() == UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) { return ResponseEntity.status(UNAUTHORIZED_INVALID_TOKEN_EXCEPTION.getStatus()) @@ -177,7 +177,7 @@ protected ErrorResponse handleHttpMediaTypeException(final HttpMediaTypeExceptio @ExceptionHandler(Exception.class) protected ErrorResponse handleException(final Exception exception) { log.error(exception.getMessage(), exception); - slackService.sendSlackMessage(exception); + slackService.sendSlackMessageProductError(exception); return ErrorResponse.error(INTERNAL_SERVER_EXCEPTION); } } diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 3a2677c5..bec9d6bf 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -5,6 +5,8 @@ import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.Auth; import hous.server.config.resolver.UserId; +import hous.server.service.slack.SlackService; +import hous.server.service.user.UserRetrieveService; import hous.server.service.user.UserService; import hous.server.service.user.dto.request.DeleteUserRequestDto; import hous.server.service.user.dto.request.UpdatePushSettingRequestDto; @@ -26,6 +28,8 @@ public class UserController { private final UserService userService; + private final UserRetrieveService userRetrieveService; + private final SlackService slackService; @ApiOperation( value = "[인증] 마이 페이지(Profile 뷰) - 나의 프로필 정보를 수정합니다.", @@ -143,6 +147,7 @@ public ResponseEntity> updateRepresentBadge(@ApiParam(na @DeleteMapping("/user") public ResponseEntity> deleteUser(@RequestBody DeleteUserRequestDto request, @ApiIgnore @UserId Long userId) { userService.deleteUser(request, userId); + slackService.sendSlackMessageDeleteUser(userRetrieveService.getFeedback()); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java index 81ed5f39..c219f348 100644 --- a/src/main/java/hous/server/service/slack/SlackService.java +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -4,21 +4,16 @@ import com.slack.api.methods.SlackApiException; import com.slack.api.model.Attachment; import com.slack.api.model.block.LayoutBlock; -import com.slack.api.model.block.composition.TextObject; import hous.server.common.util.YamlPropertySourceFactory; +import hous.server.service.slack.dto.response.UserDeleteResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Service; import java.io.IOException; -import java.util.ArrayList; import java.util.List; -import static com.slack.api.model.block.Blocks.divider; -import static com.slack.api.model.block.Blocks.section; -import static com.slack.api.model.block.composition.BlockCompositions.markdownText; - @Slf4j @Service @PropertySource(value = "classpath:application-slack.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) @@ -29,63 +24,44 @@ public class SlackService { @Value(value = "${slack.token}") String token; @Value(value = "${slack.channel.monitor}") - String channel; + String channelProductError; + @Value(value = "${slack.channel.notification}") + String channelDeleteUserNotification; - private static final String SLACK_MESSAGE_TITLE = "🤯 *500 에러 발생*"; - private static final String ATTACHMENTS_COLOR = "#eb4034"; - private static final String FILTER_STRING = "hous.server"; - private static final String SLACK_ERROR_MESSAGE = "*Error Message:*\n"; - private static final String SLACK_ERROR_STACK = "*Error Stack:*\n"; + private static final String PROD_ERROR_MESSAGE_TITLE = "🤯 *500 에러 발생*"; + private static final String PROD_USER_DELETE_MESSAGE_TITLE = "🤯 *현재 사용자 탈퇴 현황*"; + private static final String ATTACHMENTS_ERROR_COLOR = "#eb4034"; + private static final String ATTACHMENTS_NOTIFICATION_COLOR = "#36a64f"; - public void sendSlackMessage(Exception exception) { + public void sendSlackMessageDeleteUser(UserDeleteResponse userDeleteResponse) { if (profile.equals("prod")) { try { Slack slack = Slack.getInstance(); - List attachments = createSlackAttachment(exception); + List layoutBlocks = SlackServiceUtils.createUserDeleteMessage(userDeleteResponse); + List attachments = SlackServiceUtils.createAttachments(ATTACHMENTS_NOTIFICATION_COLOR, layoutBlocks); slack.methods(token).chatPostMessage(req -> - req.channel(channel) + req.channel(channelDeleteUserNotification) .attachments(attachments) - .text(SLACK_MESSAGE_TITLE)); + .text(PROD_USER_DELETE_MESSAGE_TITLE)); } catch (SlackApiException | IOException e) { log.error(e.getMessage(), e); } } } - private List createSlackAttachment(Exception exception) { - List attachments = new ArrayList<>(); - Attachment attachment = new Attachment(); - attachment.setColor(ATTACHMENTS_COLOR); - attachment.setBlocks(createSlackMessage(exception)); - attachments.add(attachment); - return attachments; - } - - - private List createSlackMessage(Exception exception) { - StackTraceElement[] stacks = exception.getStackTrace(); - - List layoutBlockList = new ArrayList<>(); - - List sectionInFields = new ArrayList<>(); - sectionInFields.add(markdownText(SLACK_ERROR_MESSAGE + exception.getMessage())); - sectionInFields.add(markdownText(SLACK_ERROR_STACK + exception)); - layoutBlockList.add(section(section -> section.fields(sectionInFields))); - - layoutBlockList.add(divider()); - layoutBlockList.add(section(section -> section.text(markdownText(filterErrorStack(stacks))))); - return layoutBlockList; - } - - private String filterErrorStack(StackTraceElement[] stacks) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("```"); - for (StackTraceElement stack : stacks) { - if (stack.toString().contains(FILTER_STRING)) { - stringBuilder.append(stack).append("\n"); + public void sendSlackMessageProductError(Exception exception) { + if (profile.equals("prod")) { + try { + Slack slack = Slack.getInstance(); + List layoutBlocks = SlackServiceUtils.createProdErrorMessage(exception); + List attachments = SlackServiceUtils.createAttachments(ATTACHMENTS_ERROR_COLOR, layoutBlocks); + slack.methods(token).chatPostMessage(req -> + req.channel(channelProductError) + .attachments(attachments) + .text(PROD_ERROR_MESSAGE_TITLE)); + } catch (SlackApiException | IOException e) { + log.error(e.getMessage(), e); } } - stringBuilder.append("```"); - return stringBuilder.toString(); } } diff --git a/src/main/java/hous/server/service/slack/SlackServiceUtils.java b/src/main/java/hous/server/service/slack/SlackServiceUtils.java new file mode 100644 index 00000000..b0fcb700 --- /dev/null +++ b/src/main/java/hous/server/service/slack/SlackServiceUtils.java @@ -0,0 +1,74 @@ +package hous.server.service.slack; + +import com.slack.api.model.Attachment; +import com.slack.api.model.block.LayoutBlock; +import com.slack.api.model.block.composition.TextObject; +import hous.server.service.slack.dto.response.UserDelete; +import hous.server.service.slack.dto.response.UserDeleteResponse; + +import java.util.ArrayList; +import java.util.List; + +import static com.slack.api.model.block.Blocks.divider; +import static com.slack.api.model.block.Blocks.section; +import static com.slack.api.model.block.composition.BlockCompositions.markdownText; + +public class SlackServiceUtils { + + private static final String PROD_ERROR_MESSAGE = "*Error Message:*\n"; + private static final String PROD_ERROR_STACK = "*Error Stack:*\n"; + private static final String FILTER_STRING = "hous.server"; + private static final String PROD_USER_DELETE_TOTAL_COUNT_MESSAGE = "*총 탈퇴 인원:* "; + private static final String PROD_USER_DELETE_MESSAGE = "*유형별 탈퇴 인원:*\n"; + + public static List createAttachments(String color, List data) { + List attachments = new ArrayList<>(); + Attachment attachment = new Attachment(); + attachment.setColor(color); + attachment.setBlocks(data); + attachments.add(attachment); + return attachments; + } + + public static List createUserDeleteMessage(UserDeleteResponse userDeleteResponse) { + List layoutBlockList = new ArrayList<>(); + layoutBlockList.add(section(section -> + section.text(markdownText(PROD_USER_DELETE_TOTAL_COUNT_MESSAGE + userDeleteResponse.getTotalDeleteUserCount())))); + + StringBuilder stringBuilder = new StringBuilder(); + for (UserDelete userDelete : userDeleteResponse.getTotalDeleteUserList()) { + stringBuilder.append(userDelete.toString()); + stringBuilder.append('\n'); + } + layoutBlockList.add(section(section -> + section.text(markdownText(PROD_USER_DELETE_MESSAGE + stringBuilder.toString())))); + return layoutBlockList; + } + + public static List createProdErrorMessage(Exception exception) { + StackTraceElement[] stacks = exception.getStackTrace(); + + List layoutBlockList = new ArrayList<>(); + + List sectionInFields = new ArrayList<>(); + sectionInFields.add(markdownText(PROD_ERROR_MESSAGE + exception.getMessage())); + sectionInFields.add(markdownText(PROD_ERROR_STACK + exception)); + layoutBlockList.add(section(section -> section.fields(sectionInFields))); + + layoutBlockList.add(divider()); + layoutBlockList.add(section(section -> section.text(markdownText(filterErrorStack(stacks))))); + return layoutBlockList; + } + + private static String filterErrorStack(StackTraceElement[] stacks) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("```"); + for (StackTraceElement stack : stacks) { + if (stack.toString().contains(FILTER_STRING)) { + stringBuilder.append(stack).append("\n"); + } + } + stringBuilder.append("```"); + return stringBuilder.toString(); + } +} diff --git a/src/main/java/hous/server/service/slack/dto/response/UserDelete.java b/src/main/java/hous/server/service/slack/dto/response/UserDelete.java new file mode 100644 index 00000000..da9eb30a --- /dev/null +++ b/src/main/java/hous/server/service/slack/dto/response/UserDelete.java @@ -0,0 +1,26 @@ +package hous.server.service.slack.dto.response; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class UserDelete { + private long count; + private String feedbackType; + + public static UserDelete of(long count, String feedbackType) { + return UserDelete.builder() + .count(count) + .feedbackType(feedbackType) + .build(); + } + + @Override + public String toString() { + return String.format("- %s: %s명", feedbackType, count); + } +} diff --git a/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java b/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java index 6e6e8018..43ee491e 100644 --- a/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java +++ b/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java @@ -3,7 +3,9 @@ import lombok.*; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; @ToString @Getter @@ -12,30 +14,17 @@ @Builder(access = AccessLevel.PRIVATE) public class UserDeleteResponse { - private int totalDeleteUserCount; + private long totalDeleteUserCount; private List totalDeleteUserList; - private String currentDeleteUserFeedbackType; - @Getter - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @Builder(access = AccessLevel.PRIVATE) - public static class UserDelete { - private int cnt; - private String feedbackType; - - public static UserDelete of(int cnt, String feedbackType) { - return UserDelete.builder() - .cnt(cnt) - .feedbackType(feedbackType) - .build(); - } - } - - public static UserDeleteResponse of(int totalDeleteUserCount, List totalDeleteUserList, String currentDeleteUserFeedbackType) { + public static UserDeleteResponse of(long totalDeleteUserCount, List users) { return UserDeleteResponse.builder() .totalDeleteUserCount(totalDeleteUserCount) - .totalDeleteUserList(totalDeleteUserList) - .currentDeleteUserFeedbackType(currentDeleteUserFeedbackType) + .totalDeleteUserList(users.stream() + .map(user -> UserDelete.of(user.getCount(), user.getFeedbackType())) + .sorted(Comparator.comparing(userDelete -> userDelete.getFeedbackType().length())) + .collect(Collectors.toList()) + ) .build(); } } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 685ab7e8..35f98846 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -6,6 +6,9 @@ import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.BadgeRepository; import hous.server.domain.badge.repository.RepresentRepository; +import hous.server.domain.feedback.Feedback; +import hous.server.domain.feedback.FeedbackType; +import hous.server.domain.feedback.repository.FeedbackRepository; import hous.server.domain.personality.Personality; import hous.server.domain.personality.PersonalityColor; import hous.server.domain.personality.PersonalityTest; @@ -17,12 +20,16 @@ import hous.server.domain.user.repository.OnboardingRepository; import hous.server.domain.user.repository.UserRepository; import hous.server.service.room.RoomServiceUtils; +import hous.server.service.slack.dto.response.UserDelete; +import hous.server.service.slack.dto.response.UserDeleteResponse; import hous.server.service.user.dto.response.*; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -37,6 +44,7 @@ public class UserRetrieveService { private final RepresentRepository representRepository; private final BadgeRepository badgeRepository; private final AcquireRepository acquireRepository; + private final FeedbackRepository feedbackRepository; public UserInfoResponse getUserInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); @@ -92,6 +100,18 @@ public MyBadgeInfoResponse getMyBadgeList(Long userId) { return MyBadgeInfoResponse.of(represent, badges, myBadges, newBadges); } + public UserDeleteResponse getFeedback() { + Map> users = feedbackRepository.findAll().stream() + .collect(Collectors.groupingBy(Feedback::getFeedbackType)); + List userDeletes = new ArrayList<>(); + long totalCount = 0; + for (FeedbackType feedbackType : users.keySet()) { + totalCount += users.get(feedbackType).size(); + userDeletes.add(UserDelete.of(users.get(feedbackType).size(), feedbackType.getValue())); + } + return UserDeleteResponse.of(totalCount, userDeletes); + } + private UserInfoResponse getProfileInfoByUser(User user) { Onboarding onboarding = user.getOnboarding(); Represent represent = representRepository.findRepresentByOnboarding(onboarding); From 057d4dbdb4a56a39b79ab49c046ac243337dc274 Mon Sep 17 00:00:00 2001 From: Joon Date: Wed, 23 Nov 2022 16:35:42 +0900 Subject: [PATCH 270/301] =?UTF-8?q?#130=20[fix]=20jwt=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=20=EB=B0=B0=ED=8F=AC=EC=9A=A9=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/util/JwtUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index 103804b5..4ed33484 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -24,10 +24,10 @@ public class JwtUtils { private final RedisTemplate redisTemplate; - // private static final long ACCESS_TOKEN_EXPIRE_TIME = 30 * 60 * 1000L; // 30분 -// private static final long REFRESH_TOKEN_EXPIRE_TIME = 7 * 24 * 60 * 60 * 1000L; // 7일 - private static final long ACCESS_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 - private static final long REFRESH_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 + private static final long ACCESS_TOKEN_EXPIRE_TIME = 10 * 60 * 1000L; // 10분 + private static final long REFRESH_TOKEN_EXPIRE_TIME = 6 * 30 * 24 * 60 * 60 * 1000L; // 180일 + // private static final long ACCESS_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 + // private static final long REFRESH_TOKEN_EXPIRE_TIME = 365 * 24 * 60 * 60 * 1000L; // 1년 private static final long EXPIRED_TIME = 1L; private final Key secretKey; From 776b76434c809765b657b326aff08cd16a741132 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 26 Nov 2022 14:57:37 +0900 Subject: [PATCH 271/301] =?UTF-8?q?#234=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=8B=9C=20=EA=B7=9C=EC=B9=99=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20validate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/rule/RuleController.java | 6 ++++-- src/main/java/hous/server/service/rule/RuleService.java | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 71b48481..7fc88b57 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -67,8 +67,10 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse( code = 400, - message = "1. 규칙 리스트를 입력해주세요. (rules)\n" - + "2. 규칙 리스트는 빈 배열을 보낼 수 없습니다. (rules)", + message = "1. 규칙 내용을 입력해주세요.\n" + + "2. 규칙은 20 글자 이내로 입력해주세요.\n" + + "3. 규칙 리스트를 입력해주세요. (rules)\n" + + "4. 규칙 리스트는 빈 배열을 보낼 수 없습니다. (rules)", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse( diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index 34cdf2ee..ce435450 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -78,6 +78,7 @@ public void updateRules(UpdateRuleRequestDto request, Long userId) { Room room = RoomServiceUtils.findParticipatingRoom(user); for (int idx = 0; idx < request.getRules().size(); idx++) { Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); + RuleServiceUtils.validateRuleName(room, request.getRules().get(idx).getName()); rule.updateRule(request.getRules().get(idx).getName(), idx); room.updateRule(rule); } From 655a5c97824e0591659ca752e750217296d0c9c7 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 26 Nov 2022 16:26:46 +0900 Subject: [PATCH 272/301] =?UTF-8?q?#235=20[fix]=20=EB=A9=A4=EB=B2=84?= =?UTF-8?q?=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20todo=20Cnt=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/service/todo/TodoRetrieveService.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index b44eed77..b0becdc3 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -141,11 +141,11 @@ public List getTodoAllMemberInfo(Long userId) { .sorted(Participate::compareTo) .forEach(participate -> { List memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); + List memberUniqueTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); Map> allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos); List dayOfWeekTodos = new ArrayList<>(); - int totalTodoCnt = 0; for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.SUNDAY.getIndex(); day++) { String dayOfWeek = DayOfWeek.getValueByIndex(day); List thisDayTodosName = allDayMemberTodos.get(day).stream() @@ -153,16 +153,15 @@ public List getTodoAllMemberInfo(Long userId) { .map(todo -> TodoInfo.of(todo.getId(), todo.getName())) .collect(Collectors.toList()); dayOfWeekTodos.add(DayOfWeekTodo.of(dayOfWeek, thisDayTodosName.size(), thisDayTodosName)); - totalTodoCnt += thisDayTodosName.size(); } String userName = participate.getOnboarding().getNickname(); PersonalityColor color = participate.getOnboarding().getPersonality().getColor(); if (user.getOnboarding().equals(participate.getOnboarding())) { - allMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); + allMemberTodos.add(TodoAllMemberResponse.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); } else { - otherMemberTodos.add(TodoAllMemberResponse.of(userName, color, totalTodoCnt, dayOfWeekTodos)); + otherMemberTodos.add(TodoAllMemberResponse.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); } }); allMemberTodos.addAll(otherMemberTodos); From 58b50e0bf1f8767f042b001fbf8a32aa82f505e0 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 27 Nov 2022 15:38:31 +0900 Subject: [PATCH 273/301] =?UTF-8?q?#238=20[fix]=20ourtodoinfo=20=EA=B0=80?= =?UTF-8?q?=EA=B3=B5=20=EC=8B=9C=20sorted(Onboarding::compareTo)=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/todo/TodoRetrieveService.java | 3 ++- .../server/service/todo/dto/response/OurTodo.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index b0becdc3..ff89f185 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -121,7 +121,8 @@ public List getTodoAllDayInfo(Long userId) { List ourTodoInfos = allDayOurTodosList.get(day).stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> OurTodo.of(todo.getName(), todo.getTakes().stream() - .map(take -> take.getOnboarding().getNickname()).collect(Collectors.toSet()))) + .map(Take::getOnboarding) + .collect(Collectors.toSet()))) .collect(Collectors.toList()); allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, todoInfos, ourTodoInfos)); } diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java index 3eb6f97d..35613440 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java @@ -1,8 +1,11 @@ package hous.server.service.todo.dto.response; +import hous.server.domain.user.Onboarding; import lombok.*; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; @ToString @Getter @@ -12,12 +15,15 @@ public class OurTodo { private String todoName; - private Set nicknames; + private List nicknames; - public static OurTodo of(String todoName, Set nicknames) { + public static OurTodo of(String todoName, Set onboardings) { return OurTodo.builder() .todoName(todoName) - .nicknames(nicknames) + .nicknames(onboardings.stream() + .sorted(Onboarding::compareTo) + .map(Onboarding::getNickname) + .collect(Collectors.toList())) .build(); } } From 88eb53aacdd0ebc01fffd1c01750aed5433275f9 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 27 Nov 2022 17:26:31 +0900 Subject: [PATCH 274/301] =?UTF-8?q?#228=20[fix]=20=EC=9A=94=EC=9D=BC?= =?UTF-8?q?=EB=B3=84,=20=ED=88=AC=EB=91=90=20=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=97=90=EC=84=9C=20=EB=8B=B4=EB=8B=B9?= =?UTF-8?q?=EC=9E=90=20=EC=A0=95=EB=A0=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/home/HomeRetrieveService.java | 3 ++- .../server/service/todo/TodoRetrieveService.java | 7 ++++--- .../service/todo/dto/response/OurTodoInfo.java | 12 +++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index 6207178c..af7171b0 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -5,6 +5,7 @@ import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.rule.Rule; +import hous.server.domain.todo.Take; import hous.server.domain.todo.Todo; import hous.server.domain.todo.repository.DoneRepository; import hous.server.domain.user.Onboarding; @@ -53,7 +54,7 @@ public HomeInfoResponse getHomeInfo(Long userId) { todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() - .map(take -> take.getOnboarding().getNickname()) + .map(Take::getOnboarding) .collect(Collectors.toSet()))) .collect(Collectors.toList()); List rules = room.getRules(); diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index ff89f185..303bff2c 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -58,9 +58,10 @@ public TodoMainResponse getTodoMain(Long userId) { .collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() - .map(take -> take.getOnboarding().getNickname()) - .collect(Collectors.toSet()))) + .map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), + todo.getTakes().stream() + .map(Take::getOnboarding) + .collect(Collectors.toSet()))) .collect(Collectors.toList()); return TodoMainResponse.of(today, todayMyTodos, todayOurTodos); } diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java index 8b4b6e20..8714b063 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java @@ -1,9 +1,12 @@ package hous.server.service.todo.dto.response; import hous.server.domain.todo.OurTodoStatus; +import hous.server.domain.user.Onboarding; import lombok.*; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; @ToString @Getter @@ -13,16 +16,19 @@ public class OurTodoInfo extends OurTodo { private OurTodoStatus status; @Builder(access = AccessLevel.PRIVATE) - public OurTodoInfo(String todoName, Set nicknames, OurTodoStatus status) { + public OurTodoInfo(String todoName, List nicknames, OurTodoStatus status) { super(todoName, nicknames); this.status = status; } - public static OurTodoInfo of(String todoName, OurTodoStatus status, Set nicknames) { + public static OurTodoInfo of(String todoName, OurTodoStatus status, Set onboardings) { return OurTodoInfo.builder() .todoName(todoName) .status(status) - .nicknames(nicknames) + .nicknames(onboardings.stream() + .sorted(Onboarding::compareTo) + .map(Onboarding::getNickname) + .collect(Collectors.toList())) .build(); } } From a397b79b36e11ea19f0659dcf5be31faed8cfb8c Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 27 Nov 2022 18:37:01 +0900 Subject: [PATCH 275/301] =?UTF-8?q?#238=20[fix]=20=EB=82=98=EB=A5=BC=20?= =?UTF-8?q?=EB=A7=A8=20=EC=95=9E=EC=9C=BC=EB=A1=9C=20=EB=B9=BC=EA=B3=A0=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=ED=95=98=EB=8F=84=EB=A1=9D=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/service/home/HomeRetrieveService.java | 12 +++++++----- .../server/service/todo/TodoRetrieveService.java | 12 +++++++----- .../server/service/todo/dto/response/OurTodo.java | 8 +++++--- .../service/todo/dto/response/OurTodoInfo.java | 8 +++++--- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index af7171b0..1a01bc07 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -36,17 +36,18 @@ public class HomeRetrieveService { public HomeInfoResponse getHomeInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); LocalDate today = DateUtils.todayLocalDate(); List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterDayOurTodos(today, todos); - List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, user.getOnboarding(), todos); + List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, onboarding, todos); List todayMyTodos = todayMyTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> TodoDetailInfo.of( todo.getId(), todo.getName(), - doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))) + doneRepository.findTodayTodoCheckStatus(today, onboarding, todo))) .collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) @@ -55,14 +56,15 @@ public HomeInfoResponse getHomeInfo(Long userId) { doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() .map(Take::getOnboarding) - .collect(Collectors.toSet()))) + .collect(Collectors.toSet()), + onboarding)) .collect(Collectors.toList()); List rules = room.getRules(); List participants = room.getParticipates().stream() .map(Participate::getOnboarding) .sorted(Onboarding::compareTo) .collect(Collectors.toList()); - List meFirstList = UserServiceUtils.toMeFirstList(participants, user.getOnboarding()); - return HomeInfoResponse.of(user.getOnboarding(), room, today, todayMyTodos, todayOurTodos, rules, meFirstList); + List meFirstList = UserServiceUtils.toMeFirstList(participants, onboarding); + return HomeInfoResponse.of(onboarding, room, today, todayMyTodos, todayOurTodos, rules, meFirstList); } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 303bff2c..292e0a6f 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -47,21 +47,22 @@ public UserPersonalityInfoResponse getUsersInfo(Long userId) { public TodoMainResponse getTodoMain(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); LocalDate today = DateUtils.todayLocalDate(); List todos = room.getTodos(); List todayOurTodosList = TodoServiceUtils.filterDayOurTodos(today, todos); - List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, user.getOnboarding(), todos); + List todayMyTodosList = TodoServiceUtils.filterDayMyTodos(today, onboarding, todos); List todayMyTodos = todayMyTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> TodoDetailInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, user.getOnboarding(), todo))) + .map(todo -> TodoDetailInfo.of(todo.getId(), todo.getName(), doneRepository.findTodayTodoCheckStatus(today, onboarding, todo))) .collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() .map(Take::getOnboarding) - .collect(Collectors.toSet()))) + .collect(Collectors.toSet()), onboarding)) .collect(Collectors.toList()); return TodoMainResponse.of(today, todayMyTodos, todayOurTodos); } @@ -100,12 +101,13 @@ public TodoSummaryInfoResponse getTodoSummaryInfo(Long todoId, Long userId) { public List getTodoAllDayInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); + Onboarding onboarding = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); List todos = room.getTodos(); // 이 방의 모든 요일의 todo list 조회 List ourTodosList = TodoServiceUtils.filterAllDaysOurTodos(todos); - List myTodosList = TodoServiceUtils.filterAllDaysUserTodos(todos, user.getOnboarding()); + List myTodosList = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding); // 요일별(index) todo list 형태로 가공 Map> allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToList(ourTodosList); @@ -123,7 +125,7 @@ public List getTodoAllDayInfo(Long userId) { .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) .map(todo -> OurTodo.of(todo.getName(), todo.getTakes().stream() .map(Take::getOnboarding) - .collect(Collectors.toSet()))) + .collect(Collectors.toSet()), onboarding)) .collect(Collectors.toList()); allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, todoInfos, ourTodoInfos)); } diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java index 35613440..194d6a33 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java @@ -1,6 +1,7 @@ package hous.server.service.todo.dto.response; import hous.server.domain.user.Onboarding; +import hous.server.service.user.UserServiceUtils; import lombok.*; import java.util.List; @@ -17,11 +18,12 @@ public class OurTodo { private String todoName; private List nicknames; - public static OurTodo of(String todoName, Set onboardings) { + public static OurTodo of(String todoName, Set onboardings, Onboarding me) { + List sortByTestScore = onboardings.stream().sorted(Onboarding::compareTo).collect(Collectors.toList()); + List meFirstList = UserServiceUtils.toMeFirstList(sortByTestScore, me); return OurTodo.builder() .todoName(todoName) - .nicknames(onboardings.stream() - .sorted(Onboarding::compareTo) + .nicknames(meFirstList.stream() .map(Onboarding::getNickname) .collect(Collectors.toList())) .build(); diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java index 8714b063..26dee7dd 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java @@ -2,6 +2,7 @@ import hous.server.domain.todo.OurTodoStatus; import hous.server.domain.user.Onboarding; +import hous.server.service.user.UserServiceUtils; import lombok.*; import java.util.List; @@ -21,12 +22,13 @@ public OurTodoInfo(String todoName, List nicknames, OurTodoStatus status this.status = status; } - public static OurTodoInfo of(String todoName, OurTodoStatus status, Set onboardings) { + public static OurTodoInfo of(String todoName, OurTodoStatus status, Set onboardings, Onboarding me) { + List sortByTestScore = onboardings.stream().sorted(Onboarding::compareTo).collect(Collectors.toList()); + List meFirstList = UserServiceUtils.toMeFirstList(sortByTestScore, me); return OurTodoInfo.builder() .todoName(todoName) .status(status) - .nicknames(onboardings.stream() - .sorted(Onboarding::compareTo) + .nicknames(meFirstList.stream() .map(Onboarding::getNickname) .collect(Collectors.toList())) .build(); From 9957e71ccf6ecd05fb4994471c223521fb18f2b9 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 27 Nov 2022 23:01:40 +0900 Subject: [PATCH 276/301] =?UTF-8?q?#240=20[fix]=20=EC=9A=94=EC=9D=BC?= =?UTF-8?q?=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20OurTodo=EC=97=90?= =?UTF-8?q?=20todoId=EB=A5=BC=20=EB=84=98=EA=B2=A8=EC=A3=BC=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/home/HomeRetrieveService.java | 4 +--- .../server/service/todo/TodoRetrieveService.java | 2 +- .../server/service/todo/dto/response/OurTodo.java | 4 +++- .../service/todo/dto/response/OurTodoInfo.java | 12 +++++------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/hous/server/service/home/HomeRetrieveService.java b/src/main/java/hous/server/service/home/HomeRetrieveService.java index 1a01bc07..bc1314fd 100644 --- a/src/main/java/hous/server/service/home/HomeRetrieveService.java +++ b/src/main/java/hous/server/service/home/HomeRetrieveService.java @@ -51,9 +51,7 @@ public HomeInfoResponse getHomeInfo(Long userId) { .collect(Collectors.toList()); List todayOurTodos = todayOurTodosList.stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> OurTodoInfo.of( - todo.getName(), - doneRepository.findTodayOurTodoStatus(today, todo), + .map(todo -> OurTodoInfo.of(todo.getName(), doneRepository.findTodayOurTodoStatus(today, todo), todo.getTakes().stream() .map(Take::getOnboarding) .collect(Collectors.toSet()), diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 292e0a6f..1b9b2056 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -123,7 +123,7 @@ public List getTodoAllDayInfo(Long userId) { .collect(Collectors.toList()); List ourTodoInfos = allDayOurTodosList.get(day).stream() .sorted(Comparator.comparing(AuditingTimeEntity::getCreatedAt)) - .map(todo -> OurTodo.of(todo.getName(), todo.getTakes().stream() + .map(todo -> OurTodo.of(todo.getId(), todo.getName(), todo.getTakes().stream() .map(Take::getOnboarding) .collect(Collectors.toSet()), onboarding)) .collect(Collectors.toList()); diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java index 194d6a33..2bcb83f3 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodo.java @@ -15,13 +15,15 @@ @Builder(access = AccessLevel.PRIVATE) public class OurTodo { + private Long todoId; private String todoName; private List nicknames; - public static OurTodo of(String todoName, Set onboardings, Onboarding me) { + public static OurTodo of(Long todoId, String todoName, Set onboardings, Onboarding me) { List sortByTestScore = onboardings.stream().sorted(Onboarding::compareTo).collect(Collectors.toList()); List meFirstList = UserServiceUtils.toMeFirstList(sortByTestScore, me); return OurTodo.builder() + .todoId(todoId) .todoName(todoName) .nicknames(meFirstList.stream() .map(Onboarding::getNickname) diff --git a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java index 26dee7dd..a94b96e4 100644 --- a/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java +++ b/src/main/java/hous/server/service/todo/dto/response/OurTodoInfo.java @@ -12,16 +12,14 @@ @ToString @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class OurTodoInfo extends OurTodo { +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class OurTodoInfo { + private String todoName; + List nicknames; private OurTodoStatus status; - @Builder(access = AccessLevel.PRIVATE) - public OurTodoInfo(String todoName, List nicknames, OurTodoStatus status) { - super(todoName, nicknames); - this.status = status; - } - public static OurTodoInfo of(String todoName, OurTodoStatus status, Set onboardings, Onboarding me) { List sortByTestScore = onboardings.stream().sorted(Onboarding::compareTo).collect(Collectors.toList()); List meFirstList = UserServiceUtils.toMeFirstList(sortByTestScore, me); From 4190bd197bbff7d9d52fc56c1722fde5596006c7 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 29 Nov 2022 13:48:45 +0900 Subject: [PATCH 277/301] =?UTF-8?q?#242=20[fix]=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=9C=20todo=EC=9D=98=20=EC=95=8C=EB=A6=BC=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=97=AC=EB=B6=80=EB=8F=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/notification/NotificationService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/service/notification/NotificationService.java b/src/main/java/hous/server/service/notification/NotificationService.java index 09dfac0e..2ef10cd1 100644 --- a/src/main/java/hous/server/service/notification/NotificationService.java +++ b/src/main/java/hous/server/service/notification/NotificationService.java @@ -30,10 +30,10 @@ public class NotificationService { public void sendNewTodoNotification(User to, Todo todo, boolean isTake) { Notification notification = notificationRepository.save(Notification.newInstance(to.getOnboarding(), NotificationType.TODO, newTodoNotification(todo, isTake), false)); to.getOnboarding().addNotification(notification); - if (to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_ALL) { + if (todo.isPushNotification() && to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_ALL) { firebaseCloudMessageService.sendMessageTo(to, PushMessage.NEW_TODO.getTitle(), PushMessage.NEW_TODO.getBody()); } - if (to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { + if (todo.isPushNotification() && to.getSetting().isPushNotification() && to.getSetting().getNewTodoPushStatus() == TodoPushStatus.ON_MY && isTake) { firebaseCloudMessageService.sendMessageTo(to, PushMessage.NEW_TODO_TAKE.getTitle(), PushMessage.NEW_TODO_TAKE.getBody()); } } From 89a824ca1ae4bdb5fd94eb9f877e9996b1e3d74b Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 29 Nov 2022 15:21:19 +0900 Subject: [PATCH 278/301] =?UTF-8?q?#242=20[fix]=20todo=209=EC=8B=9C,=2010?= =?UTF-8?q?=EC=8B=9C=20=EC=8A=A4=EC=BC=80=EC=A4=84=20=EC=8B=9C=EC=97=90?= =?UTF-8?q?=EB=8F=84=20todo=EC=9D=98=20=EC=95=8C=EB=A6=BC=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/todo/TodoScheduledService.java | 8 +++--- .../server/service/todo/TodoServiceUtils.java | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoScheduledService.java b/src/main/java/hous/server/service/todo/TodoScheduledService.java index d637e5a8..c4e5547d 100644 --- a/src/main/java/hous/server/service/todo/TodoScheduledService.java +++ b/src/main/java/hous/server/service/todo/TodoScheduledService.java @@ -97,8 +97,8 @@ public void scheduledTodayTodos() { if (participates.size() != 0) { LocalDate today = DateUtils.todayLocalDate(); Room room = participates.get(0).getRoom(); - List todayOurTodos = TodoServiceUtils.filterDayOurTodos(today, room.getTodos()); - List todayMyTodos = TodoServiceUtils.filterDayMyTodos(today, onboarding, room.getTodos()); + List todayOurTodos = TodoServiceUtils.filterDayOurTodosByIsPushNotification(today, room.getTodos()); + List todayMyTodos = TodoServiceUtils.filterDayMyTodosByIsPushNotification(today, onboarding, room.getTodos()); if (!todayOurTodos.isEmpty()) { notificationService.sendTodayTodoNotification(user, !todayMyTodos.isEmpty()); } @@ -118,8 +118,8 @@ public void scheduledRemindTodos() { if (participates.size() != 0) { LocalDate today = DateUtils.todayLocalDate(); Room room = participates.get(0).getRoom(); - List todayOurTodos = TodoServiceUtils.filterDayOurTodos(today, room.getTodos()); - List todayMyTodos = TodoServiceUtils.filterDayMyTodos(today, onboarding, room.getTodos()); + List todayOurTodos = TodoServiceUtils.filterDayOurTodosByIsPushNotification(today, room.getTodos()); + List todayMyTodos = TodoServiceUtils.filterDayMyTodosByIsPushNotification(today, onboarding, room.getTodos()); List undoneTodayOurTodos = todayOurTodos.stream() .filter(todayOurTodo -> doneRepository.findTodayOurTodoStatus(today, todayOurTodo) != OurTodoStatus.FULL_CHECK) .collect(Collectors.toList()); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index d2fc42af..0307fea4 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -68,6 +68,20 @@ public static List filterDayOurTodos(LocalDate day, List todos) { return new ArrayList<>(dayOurTodosSet); } + public static List filterDayOurTodosByIsPushNotification(LocalDate day, List todos) { + Set dayOurTodosSet = new HashSet<>(); + todos.stream().filter(Todo::isPushNotification).forEach(todo -> + todo.getTakes().forEach(take -> + take.getRedos().forEach(redo -> { + if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(day))) { + dayOurTodosSet.add(todo); + } + }) + ) + ); + return new ArrayList<>(dayOurTodosSet); + } + public static List filterAllDaysOurTodos(List todos) { Set allDaysOurTodosSet = new HashSet<>(); todos.forEach(todo -> todo.getTakes().forEach(take -> @@ -120,4 +134,15 @@ public static List filterDayMyTodos(LocalDate day, Onboarding me, List(dayMyTodosSet); } + + public static List filterDayMyTodosByIsPushNotification(LocalDate day, Onboarding me, List todos) { + Set dayMyTodosSet = new HashSet<>(); + List dayOurTodosList = filterDayOurTodosByIsPushNotification(day, todos); + dayOurTodosList.forEach(todo -> todo.getTakes().forEach(take -> { + if (take.getOnboarding().getId().equals(me.getId())) { + dayMyTodosSet.add(todo); + } + })); + return new ArrayList<>(dayMyTodosSet); + } } From 0c730bd443c77a3336a1582421156f232978c2cc Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 30 Nov 2022 16:32:32 +0900 Subject: [PATCH 279/301] =?UTF-8?q?#244=20[fix]=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80/=EC=88=98=EC=A0=95=20=EC=8B=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=20=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8A=94=20name=20?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20409=EB=A5=BC=20=EB=8D=98?= =?UTF-8?q?=EC=A7=80=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/common/exception/ErrorCode.java | 16 +++------------- .../server/controller/rule/RuleController.java | 2 ++ .../hous/server/service/rule/RuleService.java | 3 +++ .../server/service/rule/RuleServiceUtils.java | 13 +++++++++++++ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index 5cbfd61e..ddef945f 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -1,22 +1,11 @@ package hous.server.common.exception; -import static hous.server.common.exception.ErrorStatusCode.BAD_GATEWAY; -import static hous.server.common.exception.ErrorStatusCode.BAD_REQUEST; -import static hous.server.common.exception.ErrorStatusCode.CONFLICT; -import static hous.server.common.exception.ErrorStatusCode.FORBIDDEN; -import static hous.server.common.exception.ErrorStatusCode.INTERNAL_SERVER; -import static hous.server.common.exception.ErrorStatusCode.METHOD_NOT_ALLOWED; -import static hous.server.common.exception.ErrorStatusCode.NOT_ACCEPTABLE; -import static hous.server.common.exception.ErrorStatusCode.NOT_FOUND; -import static hous.server.common.exception.ErrorStatusCode.SERVICE_UNAVAILABLE; -import static hous.server.common.exception.ErrorStatusCode.UNAUTHORIZED; -import static hous.server.common.exception.ErrorStatusCode.UNSUPPORTED_MEDIA_TYPE; -import static hous.server.common.exception.ErrorStatusCode.UPGRADE_REQUIRED; - import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; +import static hous.server.common.exception.ErrorStatusCode.*; + @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum ErrorCode { @@ -86,6 +75,7 @@ public enum ErrorCode { CONFLICT_USER_EXCEPTION(CONFLICT, "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), CONFLICT_LOGIN_EXCEPTION(CONFLICT, "이미 로그인 중인 유저입니다."), CONFLICT_JOINED_ROOM_EXCEPTION(CONFLICT, "이미 참가중인 방이 있습니다."), + CONFLICT_RULE_EXCEPTION(CONFLICT, "이미 존재하는 규칙입니다."), /** * 415 Unsupported Media Type diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 7fc88b57..9830c069 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -48,6 +48,7 @@ public class RuleController { message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @@ -79,6 +80,7 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr + "2. 존재하지 않는 방입니다.\n" + "3. 존재하지 않는 규칙입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index ce435450..ab68ae75 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -17,6 +17,7 @@ import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.DeleteRuleReqeustDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; +import hous.server.service.rule.dto.response.RuleInfo; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -47,6 +48,7 @@ public void createRule(CreateRuleRequestDto request, Long userId) { Onboarding me = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); RuleServiceUtils.validateRuleCounts(room, request.getRuleNames().size()); + RuleServiceUtils.existsRuleByRoomRules(room, request.getRuleNames()); AtomicInteger ruleIdx = new AtomicInteger(RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room)); List rules = request.getRuleNames().stream() .map(ruleName -> { @@ -76,6 +78,7 @@ public void createRule(CreateRuleRequestDto request, Long userId) { public void updateRules(UpdateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); + RuleServiceUtils.existsRuleByRoomRules(room, request.getRules().stream().map(RuleInfo::getName).collect(Collectors.toList())); for (int idx = 0; idx < request.getRules().size(); idx++) { Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); RuleServiceUtils.validateRuleName(room, request.getRules().get(idx).getName()); diff --git a/src/main/java/hous/server/service/rule/RuleServiceUtils.java b/src/main/java/hous/server/service/rule/RuleServiceUtils.java index 5ca224f3..aebc732e 100644 --- a/src/main/java/hous/server/service/rule/RuleServiceUtils.java +++ b/src/main/java/hous/server/service/rule/RuleServiceUtils.java @@ -1,5 +1,6 @@ package hous.server.service.rule; +import hous.server.common.exception.ConflictException; import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; import hous.server.common.exception.ValidationException; @@ -10,6 +11,9 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.List; +import java.util.stream.Collectors; + import static hous.server.common.exception.ErrorCode.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -44,4 +48,13 @@ public static Rule findRuleByIdAndRoom(RuleRepository ruleRepository, Long ruleI } return rule; } + + public static void existsRuleByRoomRules(Room room, List requestRules) { + List rules = room.getRules().stream().map(Rule::getName).collect(Collectors.toList()); + for (String ruleName : requestRules) { + if (rules.contains(ruleName)) { + throw new ConflictException(String.format("방 (%s) 에 이미 존재하는 todo (%s) 입니다.", room.getId(), ruleName), CONFLICT_RULE_EXCEPTION); + } + } + } } From 8b6a495b1c495120fc688b57be01003509bdae12 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 30 Nov 2022 16:32:41 +0900 Subject: [PATCH 280/301] =?UTF-8?q?#244=20[fix]=20todo=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80/=EC=88=98=EC=A0=95=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=20=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8A=94=20name=20=EC=9D=B8=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20409=EB=A5=BC=20=EB=8D=98=EC=A7=80=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/exception/ErrorCode.java | 1 + .../java/hous/server/controller/todo/TodoController.java | 2 ++ src/main/java/hous/server/service/todo/TodoService.java | 2 ++ .../java/hous/server/service/todo/TodoServiceUtils.java | 8 ++++++++ 4 files changed, 13 insertions(+) diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index ddef945f..d3ebac48 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -76,6 +76,7 @@ public enum ErrorCode { CONFLICT_LOGIN_EXCEPTION(CONFLICT, "이미 로그인 중인 유저입니다."), CONFLICT_JOINED_ROOM_EXCEPTION(CONFLICT, "이미 참가중인 방이 있습니다."), CONFLICT_RULE_EXCEPTION(CONFLICT, "이미 존재하는 규칙입니다."), + CONFLICT_TODO_EXCEPTION(CONFLICT, "이미 존재하는 todo 입니다."), /** * 415 Unsupported Media Type diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 6e5c7f58..46721d2a 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -46,6 +46,7 @@ public class TodoController { + "2. 참가중인 방이 존재하지 않습니다.\n" + "3. 유저의 온보딩 정보가 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "이미 존재하는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @@ -78,6 +79,7 @@ public ResponseEntity> createTodo(@Valid @RequestBody To + "3. 유저의 온보딩 정보가 존재하지 않습니다.\n" + "4. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "이미 존재하는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index 1ce508fc..a0e3f26b 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -48,6 +48,7 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); TodoServiceUtils.validateTodoCounts(room); + TodoServiceUtils.existsTodoByRoomTodos(room, request.getName()); Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); request.getTodoUsers().forEach(todoUser -> { Onboarding onboarding = UserServiceUtils.findOnboardingById(onboardingRepository, todoUser.getOnboardingId()); @@ -72,6 +73,7 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { public void updateTodo(Long todoId, TodoInfoRequestDto request) { Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); Room room = todo.getRoom(); + TodoServiceUtils.existsTodoByRoomTodos(room, request.getName()); todo.getTakes().forEach(take -> { redoRepository.deleteAll(take.getRedos()); takeRepository.delete(take); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 0307fea4..39b87009 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -1,5 +1,6 @@ package hous.server.service.todo; +import hous.server.common.exception.ConflictException; import hous.server.common.exception.ForbiddenException; import hous.server.common.exception.NotFoundException; import hous.server.common.exception.ValidationException; @@ -45,6 +46,13 @@ public static void validateTodoStatus(DoneRepository doneRepository, boolean sta } } + public static void existsTodoByRoomTodos(Room room, String requestTodo) { + List todos = room.getTodos().stream().map(Todo::getName).collect(Collectors.toList()); + if (todos.contains(requestTodo)) { + throw new ConflictException(String.format("방 (%s) 에 이미 존재하는 todo (%s) 입니다.", room.getId(), requestTodo), CONFLICT_TODO_EXCEPTION); + } + } + public static List toUserPersonalityInfoList(List onboardings) { return onboardings.stream() .map(onboarding -> UserPersonalityInfo.of( From 6d9fdf71dbf5cc573c35afafe6e8f8a191704cc3 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 1 Dec 2022 19:37:27 +0900 Subject: [PATCH 281/301] =?UTF-8?q?#247=20[comment]=20=EC=9D=B4=EB=B2=88?= =?UTF-8?q?=20=EB=A6=B4=EB=A6=AC=EC=A6=88=20=EB=95=8C=20=EA=B7=9C=EC=B9=99?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80/=EC=88=98=EC=A0=95=20=EC=8B=9C=20name=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=97=AC=EB=B6=80=EB=8A=94=20=EC=97=86?= =?UTF-8?q?=EC=95=A0=EA=B8=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD=EB=90=98?= =?UTF-8?q?=EC=96=B4=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/rule/RuleController.java | 4 ++-- src/main/java/hous/server/service/rule/RuleService.java | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 9830c069..2a65a849 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -48,7 +48,7 @@ public class RuleController { message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), +// @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth @@ -80,7 +80,7 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr + "2. 존재하지 않는 방입니다.\n" + "3. 존재하지 않는 규칙입니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), +// @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Auth diff --git a/src/main/java/hous/server/service/rule/RuleService.java b/src/main/java/hous/server/service/rule/RuleService.java index ab68ae75..b5abca13 100644 --- a/src/main/java/hous/server/service/rule/RuleService.java +++ b/src/main/java/hous/server/service/rule/RuleService.java @@ -17,7 +17,6 @@ import hous.server.service.rule.dto.request.CreateRuleRequestDto; import hous.server.service.rule.dto.request.DeleteRuleReqeustDto; import hous.server.service.rule.dto.request.UpdateRuleRequestDto; -import hous.server.service.rule.dto.response.RuleInfo; import hous.server.service.user.UserServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -48,7 +47,7 @@ public void createRule(CreateRuleRequestDto request, Long userId) { Onboarding me = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); RuleServiceUtils.validateRuleCounts(room, request.getRuleNames().size()); - RuleServiceUtils.existsRuleByRoomRules(room, request.getRuleNames()); +// RuleServiceUtils.existsRuleByRoomRules(room, request.getRuleNames()); //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 AtomicInteger ruleIdx = new AtomicInteger(RuleServiceUtils.findRuleIdxByRoomId(ruleRepository, room)); List rules = request.getRuleNames().stream() .map(ruleName -> { @@ -78,7 +77,7 @@ public void createRule(CreateRuleRequestDto request, Long userId) { public void updateRules(UpdateRuleRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); - RuleServiceUtils.existsRuleByRoomRules(room, request.getRules().stream().map(RuleInfo::getName).collect(Collectors.toList())); +// RuleServiceUtils.existsRuleByRoomRules(room, request.getRules().stream().map(RuleInfo::getName).collect(Collectors.toList())); //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 for (int idx = 0; idx < request.getRules().size(); idx++) { Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room); RuleServiceUtils.validateRuleName(room, request.getRules().get(idx).getName()); From 413334dffa22a9bd5b3c65b0ec27f5ba6cc30d50 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 3 Dec 2022 13:37:41 +0900 Subject: [PATCH 282/301] =?UTF-8?q?#245=20[refactor]=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/config/WebConfig.java | 2 +- .../hous/server/config/interceptor/{ => auth}/Auth.java | 2 +- .../config/interceptor/{ => auth}/AuthInterceptor.java | 2 +- .../config/interceptor/{ => auth}/LoginCheckHandler.java | 2 +- .../server/config/interceptor/{ => version}/Version.java | 2 +- .../interceptor/{ => version}/VersionCheckHandler.java | 5 +++-- .../interceptor/{ => version}/VersionInterceptor.java | 9 +++++---- .../java/hous/server/config/resolver/UserIdResolver.java | 2 +- .../java/hous/server/controller/auth/AuthController.java | 2 +- .../server/controller/home/HomeRetrieveController.java | 2 +- .../java/hous/server/controller/room/RoomController.java | 2 +- .../server/controller/room/RoomRetrieveController.java | 2 +- .../java/hous/server/controller/rule/RuleController.java | 2 +- .../server/controller/rule/RuleRetrieveController.java | 2 +- .../java/hous/server/controller/todo/TodoController.java | 2 +- .../server/controller/todo/TodoRetrieveController.java | 2 +- .../java/hous/server/controller/user/UserController.java | 2 +- .../server/controller/user/UserRetrieveController.java | 2 +- 18 files changed, 24 insertions(+), 22 deletions(-) rename src/main/java/hous/server/config/interceptor/{ => auth}/Auth.java (84%) rename src/main/java/hous/server/config/interceptor/{ => auth}/AuthInterceptor.java (95%) rename src/main/java/hous/server/config/interceptor/{ => auth}/LoginCheckHandler.java (95%) rename src/main/java/hous/server/config/interceptor/{ => version}/Version.java (84%) rename src/main/java/hous/server/config/interceptor/{ => version}/VersionCheckHandler.java (98%) rename src/main/java/hous/server/config/interceptor/{ => version}/VersionInterceptor.java (89%) diff --git a/src/main/java/hous/server/config/WebConfig.java b/src/main/java/hous/server/config/WebConfig.java index b8011409..9cbf951c 100644 --- a/src/main/java/hous/server/config/WebConfig.java +++ b/src/main/java/hous/server/config/WebConfig.java @@ -1,6 +1,6 @@ package hous.server.config; -import hous.server.config.interceptor.AuthInterceptor; +import hous.server.config.interceptor.auth.AuthInterceptor; import hous.server.config.resolver.UserIdResolver; import lombok.RequiredArgsConstructor; import org.springframework.context.MessageSource; diff --git a/src/main/java/hous/server/config/interceptor/Auth.java b/src/main/java/hous/server/config/interceptor/auth/Auth.java similarity index 84% rename from src/main/java/hous/server/config/interceptor/Auth.java rename to src/main/java/hous/server/config/interceptor/auth/Auth.java index 6f3d6367..9ee8eec5 100644 --- a/src/main/java/hous/server/config/interceptor/Auth.java +++ b/src/main/java/hous/server/config/interceptor/auth/Auth.java @@ -1,4 +1,4 @@ -package hous.server.config.interceptor; +package hous.server.config.interceptor.auth; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/hous/server/config/interceptor/AuthInterceptor.java b/src/main/java/hous/server/config/interceptor/auth/AuthInterceptor.java similarity index 95% rename from src/main/java/hous/server/config/interceptor/AuthInterceptor.java rename to src/main/java/hous/server/config/interceptor/auth/AuthInterceptor.java index ff791af8..48c9cec9 100644 --- a/src/main/java/hous/server/config/interceptor/AuthInterceptor.java +++ b/src/main/java/hous/server/config/interceptor/auth/AuthInterceptor.java @@ -1,4 +1,4 @@ -package hous.server.config.interceptor; +package hous.server.config.interceptor.auth; import hous.server.config.security.JwtConstants; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/hous/server/config/interceptor/LoginCheckHandler.java b/src/main/java/hous/server/config/interceptor/auth/LoginCheckHandler.java similarity index 95% rename from src/main/java/hous/server/config/interceptor/LoginCheckHandler.java rename to src/main/java/hous/server/config/interceptor/auth/LoginCheckHandler.java index 7824880e..74ad2361 100644 --- a/src/main/java/hous/server/config/interceptor/LoginCheckHandler.java +++ b/src/main/java/hous/server/config/interceptor/auth/LoginCheckHandler.java @@ -1,4 +1,4 @@ -package hous.server.config.interceptor; +package hous.server.config.interceptor.auth; import hous.server.common.exception.UnAuthorizedException; import hous.server.common.util.JwtUtils; diff --git a/src/main/java/hous/server/config/interceptor/Version.java b/src/main/java/hous/server/config/interceptor/version/Version.java similarity index 84% rename from src/main/java/hous/server/config/interceptor/Version.java rename to src/main/java/hous/server/config/interceptor/version/Version.java index 2e7550f7..4bcc3cd4 100644 --- a/src/main/java/hous/server/config/interceptor/Version.java +++ b/src/main/java/hous/server/config/interceptor/version/Version.java @@ -1,4 +1,4 @@ -package hous.server.config.interceptor; +package hous.server.config.interceptor.version; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/hous/server/config/interceptor/VersionCheckHandler.java b/src/main/java/hous/server/config/interceptor/version/VersionCheckHandler.java similarity index 98% rename from src/main/java/hous/server/config/interceptor/VersionCheckHandler.java rename to src/main/java/hous/server/config/interceptor/version/VersionCheckHandler.java index ab826aa8..9a6c32c4 100644 --- a/src/main/java/hous/server/config/interceptor/VersionCheckHandler.java +++ b/src/main/java/hous/server/config/interceptor/version/VersionCheckHandler.java @@ -1,4 +1,4 @@ -package hous.server.config.interceptor; +package hous.server.config.interceptor.version; import hous.server.common.exception.ErrorCode; import hous.server.common.exception.NotFoundException; @@ -6,10 +6,11 @@ import hous.server.common.exception.ValidationException; import hous.server.domain.deploy.Deploy; import hous.server.domain.deploy.repository.DeployRepository; -import javax.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import javax.servlet.http.HttpServletRequest; + @RequiredArgsConstructor @Component public class VersionCheckHandler { diff --git a/src/main/java/hous/server/config/interceptor/VersionInterceptor.java b/src/main/java/hous/server/config/interceptor/version/VersionInterceptor.java similarity index 89% rename from src/main/java/hous/server/config/interceptor/VersionInterceptor.java rename to src/main/java/hous/server/config/interceptor/version/VersionInterceptor.java index 6df7c1cc..8efdaac0 100644 --- a/src/main/java/hous/server/config/interceptor/VersionInterceptor.java +++ b/src/main/java/hous/server/config/interceptor/version/VersionInterceptor.java @@ -1,12 +1,13 @@ -package hous.server.config.interceptor; +package hous.server.config.interceptor.version; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @RequiredArgsConstructor @Component public class VersionInterceptor implements HandlerInterceptor { @@ -15,7 +16,7 @@ public class VersionInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, - Object handler) throws Exception { + Object handler) throws Exception { if (!(handler instanceof HandlerMethod)) { return true; } diff --git a/src/main/java/hous/server/config/resolver/UserIdResolver.java b/src/main/java/hous/server/config/resolver/UserIdResolver.java index e8c206b1..03e6e18c 100644 --- a/src/main/java/hous/server/config/resolver/UserIdResolver.java +++ b/src/main/java/hous/server/config/resolver/UserIdResolver.java @@ -1,7 +1,7 @@ package hous.server.config.resolver; import hous.server.common.exception.InternalServerException; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.security.JwtConstants; import org.jetbrains.annotations.NotNull; import org.springframework.core.MethodParameter; diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index dc99bfa2..1a68ee1d 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.controller.auth.dto.request.LoginRequestDto; import hous.server.controller.auth.dto.request.SignUpRequestDto; diff --git a/src/main/java/hous/server/controller/home/HomeRetrieveController.java b/src/main/java/hous/server/controller/home/HomeRetrieveController.java index d67ca878..6fac342b 100644 --- a/src/main/java/hous/server/controller/home/HomeRetrieveController.java +++ b/src/main/java/hous/server/controller/home/HomeRetrieveController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.home.HomeRetrieveService; import hous.server.service.home.dto.response.HomeInfoResponse; diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 9b22b64c..f6a32d7b 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.room.RoomService; import hous.server.service.room.dto.request.SetRoomNameRequestDto; diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index 733eea7c..65fdc2c8 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.room.RoomRetrieveService; import hous.server.service.room.dto.response.GetRoomInfoResponse; diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 2a65a849..3674b535 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -2,7 +2,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleService; import hous.server.service.rule.dto.request.CreateRuleRequestDto; diff --git a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java index 1de0102a..9a2b5762 100644 --- a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java +++ b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleRetrieveService; import hous.server.service.rule.dto.response.RuleInfoResponse; diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 46721d2a..9a69b0b0 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -2,7 +2,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; import hous.server.service.todo.dto.request.CheckTodoRequestDto; diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index cacbd627..030b1be3 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoRetrieveService; import hous.server.service.todo.dto.response.*; diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index bec9d6bf..dced298a 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.service.slack.SlackService; import hous.server.service.user.UserRetrieveService; diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 3b913f89..f61dfb1b 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -3,7 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; -import hous.server.config.interceptor.Auth; +import hous.server.config.interceptor.auth.Auth; import hous.server.config.resolver.UserId; import hous.server.domain.personality.PersonalityColor; import hous.server.service.notification.NotificationRetrieveService; From 8d606b10886b56d9371468f4088b01a1d77955f8 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 3 Dec 2022 13:37:59 +0900 Subject: [PATCH 283/301] =?UTF-8?q?#245=20[chore]=20spring=20aop=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 860a2955..aa6aa9ef 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-aop' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' From ceda697dea001f5cff39661abc52f78806c250a1 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 3 Dec 2022 14:02:14 +0900 Subject: [PATCH 284/301] =?UTF-8?q?#245=20[feat]=20Redis=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20api=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD=EC=9D=84=20=EB=A7=89=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aspect/PreventDuplicateRequest.java | 11 ++++++ .../server/common/aspect/RequestAspect.java | 37 +++++++++++++++++++ .../server/common/exception/ErrorCode.java | 1 + .../controller/todo/TodoController.java | 4 +- .../hous/server/domain/common/RedisKey.java | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/java/hous/server/common/aspect/PreventDuplicateRequest.java create mode 100644 src/main/java/hous/server/common/aspect/RequestAspect.java diff --git a/src/main/java/hous/server/common/aspect/PreventDuplicateRequest.java b/src/main/java/hous/server/common/aspect/PreventDuplicateRequest.java new file mode 100644 index 00000000..5a71243a --- /dev/null +++ b/src/main/java/hous/server/common/aspect/PreventDuplicateRequest.java @@ -0,0 +1,11 @@ +package hous.server.common.aspect; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface PreventDuplicateRequest { +} diff --git a/src/main/java/hous/server/common/aspect/RequestAspect.java b/src/main/java/hous/server/common/aspect/RequestAspect.java new file mode 100644 index 00000000..5bd8c5b1 --- /dev/null +++ b/src/main/java/hous/server/common/aspect/RequestAspect.java @@ -0,0 +1,37 @@ +package hous.server.common.aspect; + +import hous.server.common.exception.ConflictException; +import hous.server.domain.common.RedisKey; +import lombok.RequiredArgsConstructor; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import static hous.server.common.exception.ErrorCode.CONFLICT_REQUEST_EXCEPTION; + +@Component +@Aspect +@RequiredArgsConstructor +public class RequestAspect { + + private final RedisTemplate redisTemplate; + + @Before("@annotation(hous.server.common.aspect.PreventDuplicateRequest)") + public void beforeRequest(final JoinPoint joinPoint) { + Long userId = (Long) joinPoint.getArgs()[0]; + if (redisTemplate.opsForValue().get(RedisKey.DUPLICATE_REQUEST + userId) != null) { + throw new ConflictException(String.format("처리 중인 유저 (%s) 의 메서드 (%s) 입니다.", userId, joinPoint.getSignature().getName()), + CONFLICT_REQUEST_EXCEPTION); + } + redisTemplate.opsForValue().set(RedisKey.DUPLICATE_REQUEST + userId, Long.toString(userId)); + } + + @AfterReturning("@annotation(hous.server.common.aspect.PreventDuplicateRequest)") + public void afterReturningRequest(final JoinPoint joinPoint) { + Long userId = (Long) joinPoint.getArgs()[0]; + redisTemplate.opsForValue().getAndDelete(RedisKey.DUPLICATE_REQUEST + userId); + } +} diff --git a/src/main/java/hous/server/common/exception/ErrorCode.java b/src/main/java/hous/server/common/exception/ErrorCode.java index d3ebac48..8e81b8ba 100644 --- a/src/main/java/hous/server/common/exception/ErrorCode.java +++ b/src/main/java/hous/server/common/exception/ErrorCode.java @@ -72,6 +72,7 @@ public enum ErrorCode { * 409 Conflict */ CONFLICT_EXCEPTION(CONFLICT, "이미 존재합니다."), + CONFLICT_REQUEST_EXCEPTION(CONFLICT, "처리중인 요청입니다."), CONFLICT_USER_EXCEPTION(CONFLICT, "이미 해당 계정으로 회원가입하셨습니다.\n로그인 해주세요."), CONFLICT_LOGIN_EXCEPTION(CONFLICT, "이미 로그인 중인 유저입니다."), CONFLICT_JOINED_ROOM_EXCEPTION(CONFLICT, "이미 참가중인 방이 있습니다."), diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 9a69b0b0..e8ae87ef 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -3,6 +3,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.request.DuplicateRequest; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; import hous.server.service.todo.dto.request.CheckTodoRequestDto; @@ -49,11 +50,12 @@ public class TodoController { @ApiResponse(code = 409, message = "이미 존재하는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @DuplicateRequest @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/todo") public ResponseEntity> createTodo(@Valid @RequestBody TodoInfoRequestDto request, @ApiIgnore @UserId Long userId) { - todoService.createTodo(request, userId); +// todoService.createTodo(request, userId); return SuccessResponse.CREATED; } diff --git a/src/main/java/hous/server/domain/common/RedisKey.java b/src/main/java/hous/server/domain/common/RedisKey.java index d3d1ea8e..8f3cfe38 100644 --- a/src/main/java/hous/server/domain/common/RedisKey.java +++ b/src/main/java/hous/server/domain/common/RedisKey.java @@ -2,6 +2,7 @@ public final class RedisKey { + public static final String DUPLICATE_REQUEST = "DR:"; public static final String REFRESH_TOKEN = "RT:"; public static final String PERSONALITY_TEST_COUNT = "PTC:"; public static final String CREATE_RULE_COUNT = "CRC:"; From 7876e9b0bbcee985e4f855aca44508bfac234cbc Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 3 Dec 2022 15:17:32 +0900 Subject: [PATCH 285/301] =?UTF-8?q?#245=20[feat]=20api=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=9A=94=EC=B2=AD=20=EB=A7=89=EB=8A=94=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/auth/AuthController.java | 2 ++ .../controller/room/RoomController.java | 17 +++++++--- .../controller/rule/RuleController.java | 16 +++++---- .../controller/todo/TodoController.java | 34 ++++++++++++------- .../controller/user/UserController.java | 26 +++++++++----- .../hous/server/service/todo/TodoService.java | 6 ++-- 6 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 1a68ee1d..d734fd00 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -1,5 +1,6 @@ package hous.server.controller.auth; +import hous.server.common.aspect.PreventDuplicateRequest; import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; @@ -156,6 +157,7 @@ public ResponseEntity> reissue(@Valid @RequestB @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PostMapping("/auth/logout") public ResponseEntity> logout(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index f6a32d7b..91af6e6c 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -1,5 +1,6 @@ package hous.server.controller.room; +import hous.server.common.aspect.PreventDuplicateRequest; import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; @@ -42,10 +43,12 @@ public class RoomController { @ApiResponse(code = 409, message = "이미 참가중인 방이 있습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/room") - public ResponseEntity> createRoom(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> createRoom(@ApiIgnore @UserId Long userId, + @Valid @RequestBody SetRoomNameRequestDto request) { return SuccessResponse.success(SuccessCode.CREATE_ROOM_SUCCESS, roomService.createRoom(request, userId)); } @@ -66,11 +69,12 @@ public ResponseEntity> createRoom(@Valid @Requ @ApiResponse(code = 409, message = "이미 참가중인 방이 있습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PostMapping("/room/{roomId}/join") - public ResponseEntity> joinRoom(@ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") - @PathVariable Long roomId, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> joinRoom(@ApiIgnore @UserId Long userId, + @ApiParam(name = "roomId", value = "참가할 room 의 id", required = true, example = "1") + @PathVariable Long roomId) { return SuccessResponse.success(SuccessCode.JOIN_ROOM_SUCCESS, roomService.joinRoom(roomId, userId)); } @@ -93,9 +97,11 @@ public ResponseEntity> joinRoom(@ApiParam(name response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PutMapping("/room/name") - public ResponseEntity> updateRoomName(@Valid @RequestBody SetRoomNameRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateRoomName(@ApiIgnore @UserId Long userId, + @Valid @RequestBody SetRoomNameRequestDto request) { roomService.updateRoomName(request, userId); return SuccessResponse.OK; } @@ -114,6 +120,7 @@ public ResponseEntity> updateRoomName(@Valid @RequestBod response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @DeleteMapping("/room/leave") public ResponseEntity> leaveRoom(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 3674b535..51871ace 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -1,5 +1,6 @@ package hous.server.controller.rule; +import hous.server.common.aspect.PreventDuplicateRequest; import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.config.interceptor.auth.Auth; @@ -51,11 +52,12 @@ public class RuleController { // @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/rules") - public ResponseEntity> createRule(@Valid @RequestBody CreateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> createRule(@ApiIgnore @UserId Long userId, + @Valid @RequestBody CreateRuleRequestDto request) { ruleService.createRule(request, userId); return SuccessResponse.CREATED; } @@ -83,10 +85,11 @@ public ResponseEntity> createRule(@Valid @RequestBody Cr // @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PutMapping("/rules") - public ResponseEntity> updateRules(@Valid @RequestBody UpdateRuleRequestDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateRules(@ApiIgnore @UserId Long userId, + @Valid @RequestBody UpdateRuleRequestDto request) { ruleService.updateRules(request, userId); return SuccessResponse.OK; } @@ -111,10 +114,11 @@ public ResponseEntity> updateRules(@Valid @RequestBody U response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @DeleteMapping("/rules") - public ResponseEntity> deleteRules(@Valid @RequestBody DeleteRuleReqeustDto request, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> deleteRules(@ApiIgnore @UserId Long userId, + @Valid @RequestBody DeleteRuleReqeustDto request) { ruleService.deleteRules(request, userId); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index e8ae87ef..3d060f39 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -1,9 +1,9 @@ package hous.server.controller.todo; +import hous.server.common.aspect.PreventDuplicateRequest; import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.config.interceptor.auth.Auth; -import hous.server.config.interceptor.request.DuplicateRequest; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; import hous.server.service.todo.dto.request.CheckTodoRequestDto; @@ -50,12 +50,13 @@ public class TodoController { @ApiResponse(code = 409, message = "이미 존재하는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) - @DuplicateRequest + @PreventDuplicateRequest @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/todo") - public ResponseEntity> createTodo(@Valid @RequestBody TodoInfoRequestDto request, @ApiIgnore @UserId Long userId) { -// todoService.createTodo(request, userId); + public ResponseEntity> createTodo(@ApiIgnore @UserId Long userId, + @Valid @RequestBody TodoInfoRequestDto request) { + todoService.createTodo(request, userId); return SuccessResponse.CREATED; } @@ -84,12 +85,14 @@ public ResponseEntity> createTodo(@Valid @RequestBody To @ApiResponse(code = 409, message = "이미 존재하는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PutMapping("/todo/{todoId}") - public ResponseEntity> updateTodo(@ApiParam(name = "todoId", value = "수정할 todo 의 id", required = true, example = "1") + public ResponseEntity> updateTodo(@ApiIgnore @UserId Long userId, + @ApiParam(name = "todoId", value = "수정할 todo 의 id", required = true, example = "1") @PathVariable Long todoId, @Valid @RequestBody TodoInfoRequestDto request) { - todoService.updateTodo(todoId, request); + todoService.updateTodo(todoId, request, userId); return SuccessResponse.OK; } @@ -113,12 +116,13 @@ public ResponseEntity> updateTodo(@ApiParam(name = "todo response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PostMapping("/todo/{todoId}/check") - public ResponseEntity> checkTodo(@ApiParam(name = "todoId", value = "체크할 todo 의 id", required = true, example = "1") + public ResponseEntity> checkTodo(@ApiIgnore @UserId Long userId, + @ApiParam(name = "todoId", value = "체크할 todo 의 id", required = true, example = "1") @PathVariable Long todoId, - @Valid @RequestBody CheckTodoRequestDto request, - @ApiIgnore @UserId Long userId) { + @Valid @RequestBody CheckTodoRequestDto request) { todoService.checkTodo(todoId, request, userId); return SuccessResponse.OK; } @@ -130,14 +134,20 @@ public ResponseEntity> checkTodo(@ApiParam(name = "todoI @ApiResponses(value = { @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), - @ApiResponse(code = 404, message = "존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + + "2. 존재하지 않는 todo 입니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @DeleteMapping("/todo/{todoId}") - public ResponseEntity> deleteTodo(@ApiParam(name = "todoId", value = "삭제할 todo 의 id", required = true, example = "1") + public ResponseEntity> deleteTodo(@ApiIgnore @UserId Long userId, + @ApiParam(name = "todoId", value = "삭제할 todo 의 id", required = true, example = "1") @PathVariable Long todoId) { - todoService.deleteTodo(todoId); + todoService.deleteTodo(todoId, userId); return SuccessResponse.OK; } } diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index dced298a..f836931c 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -1,5 +1,6 @@ package hous.server.controller.user; +import hous.server.common.aspect.PreventDuplicateRequest; import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; @@ -54,9 +55,11 @@ public class UserController { response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PutMapping("/user") - public ResponseEntity> updateUserInfo(@Valid @RequestBody UpdateUserInfoRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateUserInfo(@ApiIgnore @UserId Long userId, + @Valid @RequestBody UpdateUserInfoRequestDto request) { userService.updateUserInfo(request, userId); return SuccessResponse.OK; } @@ -75,9 +78,11 @@ public ResponseEntity> updateUserInfo(@Valid @RequestBod @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PatchMapping("/user/push") - public ResponseEntity> updateUserPushSetting(@Valid @RequestBody UpdatePushSettingRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateUserPushSetting(@ApiIgnore @UserId Long userId, + @Valid @RequestBody UpdatePushSettingRequestDto request) { userService.updateUserPushSetting(request, userId); return SuccessResponse.OK; } @@ -97,10 +102,11 @@ public ResponseEntity> updateUserPushSetting(@Valid @Req response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PutMapping("/user/personality") - public ResponseEntity> updateUserTestScore( - @Valid @RequestBody UpdateTestScoreRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateUserTestScore(@ApiIgnore @UserId Long userId, + @Valid @RequestBody UpdateTestScoreRequestDto request) { return SuccessResponse.success(SuccessCode.UPDATE_PERSONALITY_TEST_SUCCESS, userService.updateUserTestScore(request, userId)); } @@ -119,11 +125,12 @@ public ResponseEntity> updateUse response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PutMapping("/user/badge/{badgeId}/represent") - public ResponseEntity> updateRepresentBadge(@ApiParam(name = "badgeId", value = "대표 배지로 설정할 badge 의 id", required = true, example = "1") - @PathVariable Long badgeId, - @ApiIgnore @UserId Long userId) { + public ResponseEntity> updateRepresentBadge(@ApiIgnore @UserId Long userId, + @ApiParam(name = "badgeId", value = "대표 배지로 설정할 badge 의 id", required = true, example = "1") + @PathVariable Long badgeId) { userService.updateRepresentBadge(badgeId, userId); return SuccessResponse.OK; } @@ -143,9 +150,11 @@ public ResponseEntity> updateRepresentBadge(@ApiParam(na @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @DeleteMapping("/user") - public ResponseEntity> deleteUser(@RequestBody DeleteUserRequestDto request, @ApiIgnore @UserId Long userId) { + public ResponseEntity> deleteUser(@ApiIgnore @UserId Long userId, + @RequestBody DeleteUserRequestDto request) { userService.deleteUser(request, userId); slackService.sendSlackMessageDeleteUser(userRetrieveService.getFeedback()); return SuccessResponse.OK; @@ -164,6 +173,7 @@ public ResponseEntity> deleteUser(@RequestBody DeleteUse response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @PreventDuplicateRequest @Auth @PostMapping("/user/feedback") public ResponseEntity> acquireFeedbackBadge(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index a0e3f26b..a13c9ff3 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -70,7 +70,8 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { }); } - public void updateTodo(Long todoId, TodoInfoRequestDto request) { + public void updateTodo(Long todoId, TodoInfoRequestDto request, Long userId) { + UserServiceUtils.findUserById(userRepository, userId); Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); Room room = todo.getRoom(); TodoServiceUtils.existsTodoByRoomTodos(room, request.getName()); @@ -109,7 +110,8 @@ public void checkTodo(Long todoId, CheckTodoRequestDto request, Long userId) { } } - public void deleteTodo(Long todoId) { + public void deleteTodo(Long todoId, Long userId) { + UserServiceUtils.findUserById(userRepository, userId); Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); Room room = todo.getRoom(); todo.getTakes().forEach(take -> { From d31820c76f682c8918980467a82dcd16d1c4143a Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sat, 3 Dec 2022 15:22:47 +0900 Subject: [PATCH 286/301] =?UTF-8?q?#245=20[docs]=20swagger=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/auth/AuthController.java | 1 + .../server/controller/room/RoomController.java | 14 ++++++++++++-- .../server/controller/rule/RuleController.java | 3 +++ .../server/controller/todo/TodoController.java | 14 ++++++++++++-- .../server/controller/user/UserController.java | 6 ++++++ 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index d734fd00..f46df47e 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -155,6 +155,7 @@ public ResponseEntity> reissue(@Valid @RequestB @ApiResponse(code = 200, message = "성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 91af6e6c..24f37ae6 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -40,7 +40,11 @@ public class RoomController { response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "이미 참가중인 방이 있습니다.", response = ErrorResponse.class), + @ApiResponse( + code = 409, + message = "1. 처리중인 요청입니다.\n" + + "2. 이미 참가중인 방이 있습니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -66,7 +70,11 @@ public ResponseEntity> createRoom(@ApiIgnore @ message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 존재하지 않는 방입니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "이미 참가중인 방이 있습니다.", response = ErrorResponse.class), + @ApiResponse( + code = 409, + message = "1. 처리중인 요청입니다.\n" + + "2. 이미 참가중인 방이 있습니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -95,6 +103,7 @@ public ResponseEntity> joinRoom(@ApiIgnore @Us message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -118,6 +127,7 @@ public ResponseEntity> updateRoomName(@ApiIgnore @UserId message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 51871ace..00895622 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -50,6 +50,7 @@ public class RuleController { + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), // @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -83,6 +84,7 @@ public ResponseEntity> createRule(@ApiIgnore @UserId Lon + "3. 존재하지 않는 규칙입니다.", response = ErrorResponse.class), // @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -112,6 +114,7 @@ public ResponseEntity> updateRules(@ApiIgnore @UserId Lo + "2. 존재하지 않는 방입니다.\n" + "3. 존재하지 않는 규칙입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 3d060f39..2104b93c 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -47,7 +47,11 @@ public class TodoController { + "2. 참가중인 방이 존재하지 않습니다.\n" + "3. 유저의 온보딩 정보가 존재하지 않습니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "이미 존재하는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse( + code = 409, + message = "1. 처리중인 요청입니다.\n" + + "2. 이미 존재하는 todo 입니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -82,7 +86,11 @@ public ResponseEntity> createTodo(@ApiIgnore @UserId Lon + "3. 유저의 온보딩 정보가 존재하지 않습니다.\n" + "4. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), - @ApiResponse(code = 409, message = "이미 존재하는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse( + code = 409, + message = "1. 처리중인 요청입니다.\n" + + "2. 이미 존재하는 todo 입니다.", + response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -114,6 +122,7 @@ public ResponseEntity> updateTodo(@ApiIgnore @UserId Lon message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -139,6 +148,7 @@ public ResponseEntity> checkTodo(@ApiIgnore @UserId Long message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index f836931c..a1af1819 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -53,6 +53,7 @@ public class UserController { message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + "2. 존재하지 않는 방입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -76,6 +77,7 @@ public ResponseEntity> updateUserInfo(@ApiIgnore @UserId @ApiResponse(code = 400, message = "잘못된 상태로 요청했습니다.", response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -100,6 +102,7 @@ public ResponseEntity> updateUserPushSetting(@ApiIgnore message = "1. 탈퇴했거나 존재하지 않는 유저입니다. \n" + "2. 같은 방에 참가하고 있지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -123,6 +126,7 @@ public ResponseEntity> updateUse + "2. 참가중인 방이 존재하지 않습니다. \n" + "3. 존재하지 않는 배지 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -148,6 +152,7 @@ public ResponseEntity> updateRepresentBadge(@ApiIgnore @ response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -171,6 +176,7 @@ public ResponseEntity> deleteUser(@ApiIgnore @UserId Lon message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest From 713eedd1b24f88d7849516682244960cca1c8d4f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 3 Dec 2022 15:44:36 +0900 Subject: [PATCH 287/301] =?UTF-8?q?#249=20[fix]=20=ED=87=B4=EC=82=AC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20todo=20=EB=B0=8F=20=EB=B0=A9=20=ED=87=B4?= =?UTF-8?q?=EC=82=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95,=20personal?= =?UTF-8?q?ity=20gray=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/room/RoomService.java | 4 ++ .../server/service/room/RoomServiceUtils.java | 38 +++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomService.java b/src/main/java/hous/server/service/room/RoomService.java index f02cdf24..b7ddc3be 100644 --- a/src/main/java/hous/server/service/room/RoomService.java +++ b/src/main/java/hous/server/service/room/RoomService.java @@ -4,6 +4,8 @@ import hous.server.domain.badge.repository.AcquireRepository; import hous.server.domain.badge.repository.RepresentRepository; import hous.server.domain.notification.repository.NotificationRepository; +import hous.server.domain.personality.PersonalityColor; +import hous.server.domain.personality.repository.PersonalityRepository; import hous.server.domain.room.Participate; import hous.server.domain.room.Room; import hous.server.domain.room.repository.ParticipateRepository; @@ -43,6 +45,7 @@ public class RoomService { private final RepresentRepository representRepository; private final TestScoreRepository testScoreRepository; private final NotificationRepository notificationRepository; + private final PersonalityRepository personalityRepository; private final BadgeService badgeService; @@ -97,6 +100,7 @@ public void leaveRoom(Long userId) { notificationRepository.deleteAll(me.getNotifications()); if (me.getTestScore() != null) { testScoreRepository.delete(me.getTestScore()); + me.updatePersonality(personalityRepository.findPersonalityByColor(PersonalityColor.GRAY)); } me.resetUserInfo(); me.resetBadge(); diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index 4c86b466..e98152c6 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -75,24 +75,22 @@ public static List findParticipatingUsersExceptMe(Room room, User me) { public static void deleteMyTodosTakeMe(TakeRepository takeRepository, DoneRepository doneRepository, TodoRepository todoRepository, List myTodos, Onboarding me, Room room) { myTodos.forEach(todo -> { - // todo 담당자가 여러명이면 나의 담당 해제 - if (todo.getTakes().size() > 1) { - Optional myTake = todo.getTakes().stream() - .filter(take -> take.getOnboarding().getId().equals(me.getId())) - .findFirst(); - if (myTake.isPresent()) { - List myDones = TodoServiceUtils.filterAllDaysMyDones(me, todo.getDones()); - takeRepository.delete(myTake.get()); - myDones.forEach(todo::deleteDone); - doneRepository.deleteAll(myDones); - todo.deleteTake(myTake.get()); - } - } - // todo 담당자가 나뿐이면 todo 삭제 - else { + if (todo.getTakes().size() == 1) { Todo myTodo = myTodos.get(0); room.deleteTodo(myTodo); todoRepository.delete(myTodo); + return; + } + // todo 담당자가 여러명이면 나의 담당 해제 + Optional myTake = todo.getTakes().stream() + .filter(take -> take.getOnboarding().getId().equals(me.getId())) + .findFirst(); + if (myTake.isPresent()) { + List myDones = TodoServiceUtils.filterAllDaysMyDones(me, todo.getDones()); + takeRepository.delete(myTake.get()); + myDones.forEach(todo::deleteDone); + doneRepository.deleteAll(myDones); + todo.deleteTake(myTake.get()); } }); } @@ -100,13 +98,13 @@ public static void deleteMyTodosTakeMe(TakeRepository takeRepository, DoneReposi public static void deleteParticipateUser(ParticipateRepository participateRepository, RoomRepository roomRepository, Onboarding me, Room room, Participate participate) { List participates = room.getParticipates(); - if (participates.size() > 1) { - room.deleteParticipate(participate); - me.deleteParticipate(participate); - participateRepository.delete(participate); - } else { + if (participates.size() == 1) { me.deleteParticipate(participate); roomRepository.delete(room); + return; } + room.deleteParticipate(participate); + me.deleteParticipate(participate); + participateRepository.delete(participate); } } From 1951af80b4841743f399d941a160de0be204bc5b Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 4 Dec 2022 15:34:10 +0900 Subject: [PATCH 288/301] =?UTF-8?q?#252=20[fix]=20AfterReturning=20->=20Af?= =?UTF-8?q?ter=20=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/common/aspect/RequestAspect.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hous/server/common/aspect/RequestAspect.java b/src/main/java/hous/server/common/aspect/RequestAspect.java index 5bd8c5b1..7a667c3b 100644 --- a/src/main/java/hous/server/common/aspect/RequestAspect.java +++ b/src/main/java/hous/server/common/aspect/RequestAspect.java @@ -4,7 +4,7 @@ import hous.server.domain.common.RedisKey; import lombok.RequiredArgsConstructor; import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.data.redis.core.RedisTemplate; @@ -29,7 +29,7 @@ public void beforeRequest(final JoinPoint joinPoint) { redisTemplate.opsForValue().set(RedisKey.DUPLICATE_REQUEST + userId, Long.toString(userId)); } - @AfterReturning("@annotation(hous.server.common.aspect.PreventDuplicateRequest)") + @After("@annotation(hous.server.common.aspect.PreventDuplicateRequest)") public void afterReturningRequest(final JoinPoint joinPoint) { Long userId = (Long) joinPoint.getArgs()[0]; redisTemplate.opsForValue().getAndDelete(RedisKey.DUPLICATE_REQUEST + userId); From 03df6bacbd453616680947b869c54a65934147f7 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 4 Dec 2022 15:51:25 +0900 Subject: [PATCH 289/301] =?UTF-8?q?#254=20[fix]=20todo=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=8B=9C=20=EC=88=98=EC=A0=95=ED=95=98=EB=8A=94=20tod?= =?UTF-8?q?o=20=EC=A0=9C=EC=99=B8=ED=95=98=EA=B3=A0=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EA=B2=80=EC=82=AC=ED=95=98=EB=8F=84=EB=A1=9D=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 --- src/main/java/hous/server/service/todo/TodoService.java | 4 ++-- src/main/java/hous/server/service/todo/TodoServiceUtils.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoService.java b/src/main/java/hous/server/service/todo/TodoService.java index a13c9ff3..a559196e 100644 --- a/src/main/java/hous/server/service/todo/TodoService.java +++ b/src/main/java/hous/server/service/todo/TodoService.java @@ -48,7 +48,7 @@ public void createTodo(TodoInfoRequestDto request, Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); TodoServiceUtils.validateTodoCounts(room); - TodoServiceUtils.existsTodoByRoomTodos(room, request.getName()); + TodoServiceUtils.existsTodoByRoomTodos(room, request.getName(), null); Todo todo = todoRepository.save(Todo.newInstance(room, request.getName(), request.isPushNotification())); request.getTodoUsers().forEach(todoUser -> { Onboarding onboarding = UserServiceUtils.findOnboardingById(onboardingRepository, todoUser.getOnboardingId()); @@ -74,7 +74,7 @@ public void updateTodo(Long todoId, TodoInfoRequestDto request, Long userId) { UserServiceUtils.findUserById(userRepository, userId); Todo todo = TodoServiceUtils.findTodoById(todoRepository, todoId); Room room = todo.getRoom(); - TodoServiceUtils.existsTodoByRoomTodos(room, request.getName()); + TodoServiceUtils.existsTodoByRoomTodos(room, request.getName(), todo); todo.getTakes().forEach(take -> { redoRepository.deleteAll(take.getRedos()); takeRepository.delete(take); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 39b87009..1d172b59 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -46,8 +46,11 @@ public static void validateTodoStatus(DoneRepository doneRepository, boolean sta } } - public static void existsTodoByRoomTodos(Room room, String requestTodo) { + public static void existsTodoByRoomTodos(Room room, String requestTodo, Todo todo) { List todos = room.getTodos().stream().map(Todo::getName).collect(Collectors.toList()); + if (todo != null) { + todos.remove(todo.getName()); + } if (todos.contains(requestTodo)) { throw new ConflictException(String.format("방 (%s) 에 이미 존재하는 todo (%s) 입니다.", room.getId(), requestTodo), CONFLICT_TODO_EXCEPTION); } From 0fcae77babb6181dce0b837d6a464ac3d668b7d3 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Sun, 4 Dec 2022 18:27:37 +0900 Subject: [PATCH 290/301] =?UTF-8?q?#256=20[fix]=20Todo=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=EB=B3=84,=20=EC=9A=94=EC=9D=BC=EB=B3=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=97=90=20=EB=B0=A9=20=EC=B4=9D=20todo=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/TodoRetrieveController.java | 6 ++-- .../service/todo/TodoRetrieveService.java | 20 ++++++------- .../todo/dto/response/TodoAllDayInfo.java | 27 ++++++++++++++++++ .../todo/dto/response/TodoAllDayResponse.java | 14 ++++------ .../todo/dto/response/TodoAllMemberInfo.java | 28 +++++++++++++++++++ .../dto/response/TodoAllMemberResponse.java | 15 ++++------ 6 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 src/main/java/hous/server/service/todo/dto/response/TodoAllDayInfo.java create mode 100644 src/main/java/hous/server/service/todo/dto/response/TodoAllMemberInfo.java diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 030b1be3..beb1fead 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -16,8 +16,6 @@ import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; -import java.util.List; - @Api(tags = "Todo") @RestController @RequestMapping("/v1") @@ -128,7 +126,7 @@ public ResponseEntity> getTodoSummaryIn }) @Auth @GetMapping("/todos/day") - public ResponseEntity>> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_ALL_DAY_SUCCESS, todoRetrieveService.getTodoAllDayInfo(userId)); } @@ -149,7 +147,7 @@ public ResponseEntity>> getTodoAllDayIn }) @Auth @GetMapping("/todos/member") - public ResponseEntity>> getTodoAllMemberInfo(@ApiIgnore @UserId Long userId) { + public ResponseEntity> getTodoAllMemberInfo(@ApiIgnore @UserId Long userId) { return SuccessResponse.success(SuccessCode.GET_TODO_ALL_MEMBER_SUCCESS, todoRetrieveService.getTodoAllMemberInfo(userId)); } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index 1b9b2056..bd06bd44 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -99,7 +99,7 @@ public TodoSummaryInfoResponse getTodoSummaryInfo(Long todoId, Long userId) { return TodoSummaryInfoResponse.of(todo, userPersonalityInfos, user.getOnboarding()); } - public List getTodoAllDayInfo(Long userId) { + public TodoAllDayResponse getTodoAllDayInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); @@ -114,7 +114,7 @@ public List getTodoAllDayInfo(Long userId) { Map> allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToList(myTodosList); // List response dto 형태로 가공 - List allDayTodosList = new ArrayList<>(); + List allDayTodosList = new ArrayList<>(); for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.SUNDAY.getIndex(); day++) { String dayOfWeek = DayOfWeek.getValueByIndex(day); List todoInfos = allDayMyTodosList.get(day).stream() @@ -127,18 +127,18 @@ public List getTodoAllDayInfo(Long userId) { .map(Take::getOnboarding) .collect(Collectors.toSet()), onboarding)) .collect(Collectors.toList()); - allDayTodosList.add(TodoAllDayResponse.of(dayOfWeek, todoInfos, ourTodoInfos)); + allDayTodosList.add(TodoAllDayInfo.of(dayOfWeek, todoInfos, ourTodoInfos)); } - return allDayTodosList; + return TodoAllDayResponse.of(room.getTodosCnt(), allDayTodosList); } - public List getTodoAllMemberInfo(Long userId) { + public TodoAllMemberResponse getTodoAllMemberInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Room room = RoomServiceUtils.findParticipatingRoom(user); List todos = room.getTodos(); - List allMemberTodos = new ArrayList<>(); - List otherMemberTodos = new ArrayList<>(); + List allMemberTodos = new ArrayList<>(); + List otherMemberTodos = new ArrayList<>(); // 성향테스트 참여 순서로 정렬 room.getParticipates().stream() @@ -163,14 +163,14 @@ public List getTodoAllMemberInfo(Long userId) { PersonalityColor color = participate.getOnboarding().getPersonality().getColor(); if (user.getOnboarding().equals(participate.getOnboarding())) { - allMemberTodos.add(TodoAllMemberResponse.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); + allMemberTodos.add(TodoAllMemberInfo.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); } else { - otherMemberTodos.add(TodoAllMemberResponse.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); + otherMemberTodos.add(TodoAllMemberInfo.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); } }); allMemberTodos.addAll(otherMemberTodos); - return allMemberTodos; + return TodoAllMemberResponse.of(room.getTodosCnt(), allMemberTodos); } public MyTodoInfoResponse getMyTodoInfo(Long userId) { diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayInfo.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayInfo.java new file mode 100644 index 00000000..e0b8af2f --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayInfo.java @@ -0,0 +1,27 @@ +package hous.server.service.todo.dto.response; + +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class TodoAllDayInfo { + + private String dayOfWeek; + private int ourTodosCnt; + private List myTodos; + private List ourTodos; + + public static TodoAllDayInfo of(String dayOfWeek, List myTodos, List ourTodos) { + return TodoAllDayInfo.builder() + .dayOfWeek(dayOfWeek) + .ourTodosCnt(ourTodos.size()) + .myTodos(myTodos) + .ourTodos(ourTodos) + .build(); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java index 5f5b64cc..ff145bd5 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllDayResponse.java @@ -11,17 +11,13 @@ @Builder(access = AccessLevel.PRIVATE) public class TodoAllDayResponse { - private String dayOfWeek; - private int ourTodosCnt; - private List myTodos; - private List ourTodos; + private int totalRoomTodoCnt; + private List todos; - public static TodoAllDayResponse of(String dayOfWeek, List myTodos, List ourTodos) { + public static TodoAllDayResponse of(int totalRoomTodoCnt, List todos) { return TodoAllDayResponse.builder() - .dayOfWeek(dayOfWeek) - .ourTodosCnt(ourTodos.size()) - .myTodos(myTodos) - .ourTodos(ourTodos) + .totalRoomTodoCnt(totalRoomTodoCnt) + .todos(todos) .build(); } } diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberInfo.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberInfo.java new file mode 100644 index 00000000..352e11c7 --- /dev/null +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberInfo.java @@ -0,0 +1,28 @@ +package hous.server.service.todo.dto.response; + +import hous.server.domain.personality.PersonalityColor; +import lombok.*; + +import java.util.List; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class TodoAllMemberInfo { + + private String userName; + private PersonalityColor color; + private int totalTodoCnt; + private List dayOfWeekTodos; + + public static TodoAllMemberInfo of(String userName, PersonalityColor color, int totalTodoCnt, List dayOfWeekTodos) { + return TodoAllMemberInfo.builder() + .userName(userName) + .color(color) + .totalTodoCnt(totalTodoCnt) + .dayOfWeekTodos(dayOfWeekTodos) + .build(); + } +} diff --git a/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java index 4380dfd7..7afcae1c 100644 --- a/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java +++ b/src/main/java/hous/server/service/todo/dto/response/TodoAllMemberResponse.java @@ -1,6 +1,5 @@ package hous.server.service.todo.dto.response; -import hous.server.domain.personality.PersonalityColor; import lombok.*; import java.util.List; @@ -12,17 +11,13 @@ @Builder(access = AccessLevel.PRIVATE) public class TodoAllMemberResponse { - private String userName; - private PersonalityColor color; - private int totalTodoCnt; - private List dayOfWeekTodos; + private int totalRoomTodoCnt; + private List todos; - public static TodoAllMemberResponse of(String userName, PersonalityColor color, int totalTodoCnt, List dayOfWeekTodos) { + public static TodoAllMemberResponse of(int totalRoomTodoCnt, List todos) { return TodoAllMemberResponse.builder() - .userName(userName) - .color(color) - .totalTodoCnt(totalTodoCnt) - .dayOfWeekTodos(dayOfWeekTodos) + .totalRoomTodoCnt(totalRoomTodoCnt) + .todos(todos) .build(); } } From 05ba22d5e81b52ef04857ae96ad504b58f8fad20 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 5 Dec 2022 14:22:58 +0900 Subject: [PATCH 291/301] =?UTF-8?q?#258=20[feat]=20=EA=B0=95=EC=A0=9C=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EA=B4=80=EB=A0=A8=20api?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/success/SuccessCode.java | 3 ++ .../version/VersionCheckHandler.java | 42 ++-------------- .../version/VersionRetrieveController.java | 47 ++++++++++++++++++ .../hous/server/domain/deploy/Deploy.java | 10 ++-- .../version/VersionRetrieveService.java | 25 ++++++++++ .../service/version/VersionServiceUtils.java | 48 +++++++++++++++++++ .../dto/response/VersionInfoResponse.java | 21 ++++++++ 7 files changed, 154 insertions(+), 42 deletions(-) create mode 100644 src/main/java/hous/server/controller/version/VersionRetrieveController.java create mode 100644 src/main/java/hous/server/service/version/VersionRetrieveService.java create mode 100644 src/main/java/hous/server/service/version/VersionServiceUtils.java create mode 100644 src/main/java/hous/server/service/version/dto/response/VersionInfoResponse.java diff --git a/src/main/java/hous/server/common/success/SuccessCode.java b/src/main/java/hous/server/common/success/SuccessCode.java index c1c49cda..078c9c7b 100644 --- a/src/main/java/hous/server/common/success/SuccessCode.java +++ b/src/main/java/hous/server/common/success/SuccessCode.java @@ -16,6 +16,9 @@ public enum SuccessCode { */ OK_SUCCESS(OK, "성공입니다."), + // 버전 + GET_VERSION_INFO_SUCCESS(OK, "강제 업데이트 필요 여부 조회 성공입니다."), + // 인증 SIGNUP_SUCCESS(OK, "회원가입 성공입니다."), LOGIN_SUCCESS(OK, "로그인 성공입니다."), diff --git a/src/main/java/hous/server/config/interceptor/version/VersionCheckHandler.java b/src/main/java/hous/server/config/interceptor/version/VersionCheckHandler.java index 9a6c32c4..70a6dfa9 100644 --- a/src/main/java/hous/server/config/interceptor/version/VersionCheckHandler.java +++ b/src/main/java/hous/server/config/interceptor/version/VersionCheckHandler.java @@ -1,11 +1,9 @@ package hous.server.config.interceptor.version; -import hous.server.common.exception.ErrorCode; -import hous.server.common.exception.NotFoundException; import hous.server.common.exception.UpgradeRequiredException; -import hous.server.common.exception.ValidationException; import hous.server.domain.deploy.Deploy; import hous.server.domain.deploy.repository.DeployRepository; +import hous.server.service.version.VersionServiceUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -20,43 +18,13 @@ public class VersionCheckHandler { public void checkVersion(HttpServletRequest request) { String requestOs = request.getHeader("HousOsType"); String requestVersion = request.getHeader("HousVersion"); - validateRequestOs(requestOs); - validateRequestVersion(requestVersion); - Deploy deploy = deployRepository.findDeployByOs(requestOs); - if (deploy == null) { - throw new NotFoundException(String.format("배포되지 않은 OS (%s) 입니다.", requestOs), - ErrorCode.NOT_FOUND_OS_EXCEPTION); - } + VersionServiceUtils.validateRequestOs(requestOs); + VersionServiceUtils.validateRequestVersion(requestVersion); + Deploy deploy = VersionServiceUtils.findDeployByOs(deployRepository, requestOs); String latestVersion = deploy.getVersion(); - if (isOutdated(requestVersion, latestVersion)) { + if (VersionServiceUtils.isOutdated(requestVersion, latestVersion)) { throw new UpgradeRequiredException( String.format("업그레이드가 필요한 버전 (%s - %s) 입니다.", requestOs, requestVersion)); } } - - private void validateRequestOs(String requestOs) { - if (!requestOs.matches("iOS|AOS")) { - throw new ValidationException(String.format("잘못된 OS 타입 요청 (%s) 입니다.", requestOs), - ErrorCode.VALIDATION_OS_EXCEPTION); - } - } - - private void validateRequestVersion(String requestVersion) { - if (!requestVersion.matches("\\d+\\.\\d+\\.\\d+")) { - throw new ValidationException(String.format("잘못된 버전 형식 (%s) 입니다.", requestVersion), - ErrorCode.VALIDATION_VERSION_EXCEPTION); - } - } - - private boolean isOutdated(String requestVersion, String latestVersion) { - String[] request = requestVersion.split("\\."); - String[] latest = latestVersion.split("\\."); - if (Integer.parseInt(request[0]) < Integer.parseInt(latest[0])) { - return true; - } - if (Integer.parseInt(request[1]) < Integer.parseInt(latest[1])) { - return true; - } - return false; - } } diff --git a/src/main/java/hous/server/controller/version/VersionRetrieveController.java b/src/main/java/hous/server/controller/version/VersionRetrieveController.java new file mode 100644 index 00000000..78c6afab --- /dev/null +++ b/src/main/java/hous/server/controller/version/VersionRetrieveController.java @@ -0,0 +1,47 @@ +package hous.server.controller.version; + +import hous.server.common.dto.ErrorResponse; +import hous.server.common.dto.SuccessResponse; +import hous.server.common.success.SuccessCode; +import hous.server.service.version.VersionRetrieveService; +import hous.server.service.version.dto.response.VersionInfoResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "Version") +@RequiredArgsConstructor +@RestController +@RequestMapping("/v1") +public class VersionRetrieveController { + + private final VersionRetrieveService versionRetrieveService; + + @ApiOperation( + value = "버전 확인 - 강제 업데이트 필요 여부를 확인합니다.", + notes = "iOS/AOS 별로 강제 업데이트 필요 여부, 마켓 링크를 전달합니다.\n" + + "헤더에 HousOsType, HousVersion 을 담아서 보내주세요." + + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "강제 업데이트 필요 여부 조회 성공입니다."), + @ApiResponse(code = 400, + message = "1. 잘못된 OS 타입 요청입니다.\n" + + "2. 잘못된 버전 형식입니다.", + response = ErrorResponse.class), + @ApiResponse(code = 404, message = "배포되지 않은 OS 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) + }) + @GetMapping("/version") + public ResponseEntity> getVersionInfo(@RequestHeader("HousOsType") String requestOs, + @RequestHeader("HousVersion") String requestVersion) { + return SuccessResponse.success(SuccessCode.GET_VERSION_INFO_SUCCESS, versionRetrieveService.getVersionInfo(requestOs, requestVersion)); + } +} diff --git a/src/main/java/hous/server/domain/deploy/Deploy.java b/src/main/java/hous/server/domain/deploy/Deploy.java index d901df7e..ffe3bf00 100644 --- a/src/main/java/hous/server/domain/deploy/Deploy.java +++ b/src/main/java/hous/server/domain/deploy/Deploy.java @@ -1,15 +1,12 @@ package hous.server.domain.deploy; import hous.server.domain.common.AuditingTimeEntity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.*; + @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -24,4 +21,7 @@ public class Deploy extends AuditingTimeEntity { @Column(nullable = false, length = 30) private String version; + + @Column(nullable = false, length = 300) + private String marketUrl; } diff --git a/src/main/java/hous/server/service/version/VersionRetrieveService.java b/src/main/java/hous/server/service/version/VersionRetrieveService.java new file mode 100644 index 00000000..76b60eb7 --- /dev/null +++ b/src/main/java/hous/server/service/version/VersionRetrieveService.java @@ -0,0 +1,25 @@ +package hous.server.service.version; + +import hous.server.domain.deploy.Deploy; +import hous.server.domain.deploy.repository.DeployRepository; +import hous.server.service.version.dto.response.VersionInfoResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional(readOnly = true) +public class VersionRetrieveService { + + private final DeployRepository deployRepository; + + public VersionInfoResponse getVersionInfo(String requestOs, String requestVersion) { + VersionServiceUtils.validateRequestOs(requestOs); + VersionServiceUtils.validateRequestVersion(requestVersion); + Deploy deploy = VersionServiceUtils.findDeployByOs(deployRepository, requestOs); + String latestVersion = deploy.getVersion(); + boolean needsForceUpdate = VersionServiceUtils.isOutdated(requestVersion, latestVersion); + return VersionInfoResponse.of(needsForceUpdate, deploy.getMarketUrl()); + } +} diff --git a/src/main/java/hous/server/service/version/VersionServiceUtils.java b/src/main/java/hous/server/service/version/VersionServiceUtils.java new file mode 100644 index 00000000..2dbe6ef6 --- /dev/null +++ b/src/main/java/hous/server/service/version/VersionServiceUtils.java @@ -0,0 +1,48 @@ +package hous.server.service.version; + +import hous.server.common.exception.ErrorCode; +import hous.server.common.exception.NotFoundException; +import hous.server.common.exception.ValidationException; +import hous.server.domain.deploy.Deploy; +import hous.server.domain.deploy.repository.DeployRepository; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class VersionServiceUtils { + + public static Deploy findDeployByOs(DeployRepository deployRepository, String os) { + Deploy deploy = deployRepository.findDeployByOs(os); + if (deploy == null) { + throw new NotFoundException(String.format("배포되지 않은 OS (%s) 입니다.", os), + ErrorCode.NOT_FOUND_OS_EXCEPTION); + } + return deploy; + } + + public static void validateRequestOs(String requestOs) { + if (!requestOs.matches("iOS|AOS")) { + throw new ValidationException(String.format("잘못된 OS 타입 요청 (%s) 입니다.", requestOs), + ErrorCode.VALIDATION_OS_EXCEPTION); + } + } + + public static void validateRequestVersion(String requestVersion) { + if (!requestVersion.matches("\\d+\\.\\d+\\.\\d+")) { + throw new ValidationException(String.format("잘못된 버전 형식 (%s) 입니다.", requestVersion), + ErrorCode.VALIDATION_VERSION_EXCEPTION); + } + } + + public static boolean isOutdated(String requestVersion, String latestVersion) { + String[] request = requestVersion.split("\\."); + String[] latest = latestVersion.split("\\."); + if (Integer.parseInt(request[0]) < Integer.parseInt(latest[0])) { + return true; + } + if (Integer.parseInt(request[1]) < Integer.parseInt(latest[1])) { + return true; + } + return false; + } +} diff --git a/src/main/java/hous/server/service/version/dto/response/VersionInfoResponse.java b/src/main/java/hous/server/service/version/dto/response/VersionInfoResponse.java new file mode 100644 index 00000000..b62d145b --- /dev/null +++ b/src/main/java/hous/server/service/version/dto/response/VersionInfoResponse.java @@ -0,0 +1,21 @@ +package hous.server.service.version.dto.response; + +import lombok.*; + +@ToString +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +public class VersionInfoResponse { + + private boolean needsForceUpdate; + private String marketUrl; + + public static VersionInfoResponse of(boolean needsForceUpdate, String marketUrl) { + return VersionInfoResponse.builder() + .needsForceUpdate(needsForceUpdate) + .marketUrl(marketUrl) + .build(); + } +} From 1f7f380a671b0446d4a9eb64903cebf4fa270e36 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 5 Dec 2022 15:27:19 +0900 Subject: [PATCH 292/301] =?UTF-8?q?#260=20[fix]=20=EB=B0=A9=ED=87=B4?= =?UTF-8?q?=EC=82=AC,=20=ED=83=88=ED=87=B4=EC=8B=9C=20=EB=82=98=EC=9D=98?= =?UTF-8?q?=20todo=20=EC=82=AD=EC=A0=9C=20=EA=B4=80=EB=A0=A8=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 --- src/main/java/hous/server/service/room/RoomServiceUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/hous/server/service/room/RoomServiceUtils.java b/src/main/java/hous/server/service/room/RoomServiceUtils.java index e98152c6..c8b3bec5 100644 --- a/src/main/java/hous/server/service/room/RoomServiceUtils.java +++ b/src/main/java/hous/server/service/room/RoomServiceUtils.java @@ -76,9 +76,8 @@ public static void deleteMyTodosTakeMe(TakeRepository takeRepository, DoneReposi List myTodos, Onboarding me, Room room) { myTodos.forEach(todo -> { if (todo.getTakes().size() == 1) { - Todo myTodo = myTodos.get(0); - room.deleteTodo(myTodo); - todoRepository.delete(myTodo); + room.deleteTodo(todo); + todoRepository.delete(todo); return; } // todo 담당자가 여러명이면 나의 담당 해제 From 734beeb98d4654f71d37c209ef29a9bd5d5ddbb2 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Thu, 8 Dec 2022 16:25:18 +0900 Subject: [PATCH 293/301] =?UTF-8?q?#262=20[fix]=20=EA=B0=9C=EB=B0=9C?= =?UTF-8?q?=ED=99=98=EA=B2=BD,=20=EB=B0=B0=ED=8F=AC=ED=99=98=EA=B2=BD=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=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 --- .../workflows/{deploy.yml => deploy-dev.yml} | 29 ++++++------------- .../{pr-check.yml => pr-check-dev.yml} | 21 ++++---------- .gitignore | 5 +--- scripts/run_new_was.sh | 13 +++++++-- .../hous/server/common/util/JwtUtils.java | 2 -- .../java/hous/server/config/s3/S3Config.java | 3 -- .../firebase/FirebaseCloudMessageService.java | 3 -- .../server/service/slack/SlackService.java | 8 ++--- 8 files changed, 28 insertions(+), 56 deletions(-) rename .github/workflows/{deploy.yml => deploy-dev.yml} (62%) rename .github/workflows/{pr-check.yml => pr-check-dev.yml} (59%) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy-dev.yml similarity index 62% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy-dev.yml index 588506aa..5903f7ba 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy-dev.yml @@ -7,9 +7,6 @@ on: push: branches: [ develop ] -env: - S3_BUCKET_NAME: hous-build - jobs: build: runs-on: ubuntu-18.04 @@ -21,24 +18,16 @@ jobs: - name: create secret files working-directory: ./src/main/resources env: - AWS_S3_ACCESS_KEY: ${{ secrets.AWS_S3_ACCESS_KEY }} - AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} - AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} + AWS_S3_ACCESS_KEY: ${{ secrets.AWS_S3_ACCESS_KEY_DEV }} + AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY_DEV }} + AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME_DEV }} AWS_REGION: ${{ secrets.AWS_REGION }} run: | touch application.yml - touch application-prod.yml - touch application-aws.yml - touch application-firebase.yml - touch application-jwt.yml - touch application-slack.yml + touch application-dev.yml echo "${{ secrets.APPLICATION_YML }}" >> application.yml - echo "${{ secrets.APPLICATION_PROD_YML }}" >> application-prod.yml - echo "${{ secrets.APPLICATION_AWS_YML }}" >> application-aws.yml - echo "${{ secrets.APPLICATION_FIREBASE_YML }}" >> application-firebase.yml - echo "${{ secrets.APPLICATION_JWT_YML }}" >> application-jwt.yml - echo "${{ secrets.APPLICATION_SLACK_YML }}" >> application-slack.yml + echo "${{ secrets.APPLICATION_DEV_YML }}" >> application-dev.yml mkdir firebase touch ./firebase/firebase_service_key.json @@ -69,16 +58,16 @@ jobs: - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: - aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY }} - aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY }} + aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_DEV }} + aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY_DEV }} aws-region: ${{ secrets.AWS_REGION }} - name: Upload to S3 - run: aws s3 cp --region ap-northeast-2 ./code-deploy.zip s3://$S3_BUCKET_NAME/code-deploy.zip + run: aws s3 cp --region ap-northeast-2 ./code-deploy.zip s3://$AWS_S3_BUCKET_NAME/code-deploy.zip - name: Code Deploy run: aws deploy create-deployment --application-name hous-codedeploy --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name GROUP - --s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=code-deploy.zip + --s3-location bucket=$AWS_S3_BUCKET_NAME,bundleType=zip,key=code-deploy.zip diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check-dev.yml similarity index 59% rename from .github/workflows/pr-check.yml rename to .github/workflows/pr-check-dev.yml index d25a081e..f8ddf3af 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check-dev.yml @@ -7,9 +7,6 @@ on: pull_request: branches: [ develop ] -env: - S3_BUCKET_NAME: hous-build - jobs: build: runs-on: ubuntu-18.04 @@ -21,24 +18,16 @@ jobs: - name: create secret files working-directory: ./src/main/resources env: - AWS_S3_ACCESS_KEY: ${{ secrets.AWS_S3_ACCESS_KEY }} - AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY }} - AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} + AWS_S3_ACCESS_KEY: ${{ secrets.AWS_S3_ACCESS_KEY_DEV }} + AWS_S3_SECRET_KEY: ${{ secrets.AWS_S3_SECRET_KEY_DEV }} + AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME_DEV }} AWS_REGION: ${{ secrets.AWS_REGION }} run: | touch application.yml - touch application-prod.yml - touch application-aws.yml - touch application-firebase.yml - touch application-jwt.yml - touch application-slack.yml + touch application-dev.yml echo "${{ secrets.APPLICATION_YML }}" >> application.yml - echo "${{ secrets.APPLICATION_PROD_YML }}" >> application-prod.yml - echo "${{ secrets.APPLICATION_AWS_YML }}" >> application-aws.yml - echo "${{ secrets.APPLICATION_FIREBASE_YML }}" >> application-firebase.yml - echo "${{ secrets.APPLICATION_JWT_YML }}" >> application-jwt.yml - echo "${{ secrets.APPLICATION_SLACK_YML }}" >> application-slack.yml + echo "${{ secrets.APPLICATION_DEV_YML }}" >> application-dev.yml mkdir firebase touch ./firebase/firebase_service_key.json diff --git a/.gitignore b/.gitignore index a552c44f..bdadb9fa 100644 --- a/.gitignore +++ b/.gitignore @@ -39,11 +39,8 @@ out/ /src/main/resources/firebase/firebase_service_key.json application.yml application-local.yml +application-dev.yml application-prod.yml -application-aws.yml -application-jwt.yml -application-firebase.yml -application-slack.yml ### log 파일 ### logs diff --git a/scripts/run_new_was.sh b/scripts/run_new_was.sh index 2d9d03e6..1d7f684a 100644 --- a/scripts/run_new_was.sh +++ b/scripts/run_new_was.sh @@ -1,5 +1,6 @@ NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" +HOST_NAME=$(cat /etc/hostname) CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1) TARGET_PORT=0 @@ -20,6 +21,12 @@ if [ ! -z ${TARGET_PID} ]; then sudo kill ${TARGET_PID} fi -nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/hous/build/libs/*.jar >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & -echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/hous/deploy.log -exit 0 +if [ ${HOST_NAME} == "hous-prod-server" ]; then + nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod /home/ubuntu/hous/build/libs/*.jar >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & + echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/hous/deploy.log + exit 0 +else + nohup java -jar -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev /home/ubuntu/hous/build/libs/*.jar >> /home/ubuntu/hous/deploy.log 2>/home/ubuntu/hous/deploy_err.log & + echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/hous/deploy.log + exit 0 +fi diff --git a/src/main/java/hous/server/common/util/JwtUtils.java b/src/main/java/hous/server/common/util/JwtUtils.java index 4ed33484..7d9b046e 100644 --- a/src/main/java/hous/server/common/util/JwtUtils.java +++ b/src/main/java/hous/server/common/util/JwtUtils.java @@ -9,7 +9,6 @@ import io.jsonwebtoken.security.Keys; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.PropertySource; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; @@ -19,7 +18,6 @@ @Component @Slf4j -@PropertySource(value = "classpath:application-jwt.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) public class JwtUtils { private final RedisTemplate redisTemplate; diff --git a/src/main/java/hous/server/config/s3/S3Config.java b/src/main/java/hous/server/config/s3/S3Config.java index 2051d897..c4630de9 100644 --- a/src/main/java/hous/server/config/s3/S3Config.java +++ b/src/main/java/hous/server/config/s3/S3Config.java @@ -4,14 +4,11 @@ import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import hous.server.common.util.YamlPropertySourceFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; @Configuration -@PropertySource(value = "classpath:application-aws.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) public class S3Config { @Value("${cloud.aws.credentials.accessKey}") diff --git a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java index af89b0d8..b7f6e3b0 100644 --- a/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java +++ b/src/main/java/hous/server/service/firebase/FirebaseCloudMessageService.java @@ -5,14 +5,12 @@ import hous.server.common.exception.InternalServerException; import hous.server.common.util.HttpHeaderUtils; import hous.server.common.util.JwtUtils; -import hous.server.common.util.YamlPropertySourceFactory; import hous.server.domain.user.User; import hous.server.external.client.firebase.FirebaseApiClient; import hous.server.service.firebase.dto.request.FcmMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.PropertySource; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; @@ -23,7 +21,6 @@ @Slf4j @RequiredArgsConstructor @Service -@PropertySource(value = "classpath:application-firebase.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) public class FirebaseCloudMessageService { @Value("${cloud.firebase.config.path}") diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java index 96ccb9ac..0b001ba3 100644 --- a/src/main/java/hous/server/service/slack/SlackService.java +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -4,11 +4,9 @@ import com.slack.api.methods.SlackApiException; import com.slack.api.model.Attachment; import com.slack.api.model.block.LayoutBlock; -import hous.server.common.util.YamlPropertySourceFactory; import hous.server.service.slack.dto.response.UserDeleteResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Service; import java.io.IOException; @@ -16,7 +14,6 @@ @Slf4j @Service -@PropertySource(value = "classpath:application-slack.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) public class SlackService { @Value(value = "${spring.profiles.default}") @@ -28,13 +25,14 @@ public class SlackService { @Value(value = "${slack.channel.notification}") String channelDeleteUserNotification; + private static final String LOCAL = "local"; private static final String PROD_ERROR_MESSAGE_TITLE = "🤯 *500 에러 발생*"; private static final String PROD_USER_DELETE_MESSAGE_TITLE = "🤯 *현재 사용자 탈퇴 현황*"; private static final String ATTACHMENTS_ERROR_COLOR = "#eb4034"; private static final String ATTACHMENTS_NOTIFICATION_COLOR = "#36a64f"; public void sendSlackMessageDeleteUser(UserDeleteResponse userDeleteResponse) { - if (profile.equals("prod") && userDeleteResponse.getTotalDeleteUserList().isEmpty()) { + if (!profile.equals(LOCAL) && userDeleteResponse.getTotalDeleteUserList().isEmpty()) { try { Slack slack = Slack.getInstance(); List layoutBlocks = SlackServiceUtils.createUserDeleteMessage(userDeleteResponse); @@ -50,7 +48,7 @@ public void sendSlackMessageDeleteUser(UserDeleteResponse userDeleteResponse) { } public void sendSlackMessageProductError(Exception exception) { - if (profile.equals("prod")) { + if (!profile.equals(LOCAL)) { try { Slack slack = Slack.getInstance(); List layoutBlocks = SlackServiceUtils.createProdErrorMessage(exception); From 619cca73bb80bc6c9faaed755821d7f1838608a5 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 10 Dec 2022 23:44:17 +0900 Subject: [PATCH 294/301] =?UTF-8?q?#264=20[chore]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20dependency=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.gradle b/build.gradle index aa6aa9ef..4fbd7f4e 100644 --- a/build.gradle +++ b/build.gradle @@ -26,9 +26,6 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation group: 'org.postgresql', name: 'postgresql', version: '42.4.0' - runtimeOnly 'org.postgresql:postgresql' - runtimeOnly 'mysql:mysql-connector-java' implementation 'org.springframework.boot:spring-boot-starter-data-redis' From 896f4dbc14cde982386f872316dff7585381333f Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sat, 10 Dec 2022 23:44:28 +0900 Subject: [PATCH 295/301] =?UTF-8?q?#264=20[fix]=20.size()=20!=3D=200=20->?= =?UTF-8?q?=20isEmpty()=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hous/server/service/todo/TodoScheduledService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/hous/server/service/todo/TodoScheduledService.java b/src/main/java/hous/server/service/todo/TodoScheduledService.java index c4e5547d..912267b2 100644 --- a/src/main/java/hous/server/service/todo/TodoScheduledService.java +++ b/src/main/java/hous/server/service/todo/TodoScheduledService.java @@ -50,7 +50,7 @@ public void scheduledDoneMyTodos() { users.forEach(user -> { Onboarding onboarding = user.getOnboarding(); List participates = onboarding.getParticipates(); - if (participates.size() != 0) { + if (!participates.isEmpty()) { LocalDate yesterday = DateUtils.yesterdayLocalDate(); Room room = participates.get(0).getRoom(); if (!BadgeServiceUtils.hasBadge(badgeRepository, acquireRepository, BadgeInfo.TODO_MASTER, onboarding)) { @@ -60,7 +60,7 @@ public void scheduledDoneMyTodos() { int yesterdayDoneMyTodosCnt = (int) yesterdayMyTodos.stream() .filter(todo -> doneRepository.existsDayDoneByOnboardingAndTodo(yesterday, onboarding, todo)) .count(); - if (allDayMyTodos.size() > 0 && yesterdayMyTodos.size() == yesterdayDoneMyTodosCnt) { + if (!allDayMyTodos.isEmpty() && yesterdayMyTodos.size() == yesterdayDoneMyTodosCnt) { String todoCompleteCountString = (String) redisTemplate.opsForValue().get(RedisKey.TODO_COMPLETE_COUNT + user.getId()); if (todoCompleteCountString == null) { redisTemplate.opsForValue().set(RedisKey.TODO_COMPLETE_COUNT + user.getId(), Integer.toString(1)); @@ -94,7 +94,7 @@ public void scheduledTodayTodos() { users.forEach(user -> { Onboarding onboarding = user.getOnboarding(); List participates = onboarding.getParticipates(); - if (participates.size() != 0) { + if (!participates.isEmpty()) { LocalDate today = DateUtils.todayLocalDate(); Room room = participates.get(0).getRoom(); List todayOurTodos = TodoServiceUtils.filterDayOurTodosByIsPushNotification(today, room.getTodos()); @@ -115,7 +115,7 @@ public void scheduledRemindTodos() { users.forEach(user -> { Onboarding onboarding = user.getOnboarding(); List participates = onboarding.getParticipates(); - if (participates.size() != 0) { + if (!participates.isEmpty()) { LocalDate today = DateUtils.todayLocalDate(); Room room = participates.get(0).getRoom(); List todayOurTodos = TodoServiceUtils.filterDayOurTodosByIsPushNotification(today, room.getTodos()); From 76d79f9e01890676533a23f621255c3f751d0cd2 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 12 Dec 2022 16:25:58 +0900 Subject: [PATCH 296/301] =?UTF-8?q?#266=20[feat]=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=B4=EB=91=94=20@Version=20=EC=96=B4=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/config/WebConfig.java | 4 +++- .../java/hous/server/controller/auth/AuthController.java | 6 ++++++ .../server/controller/home/HomeRetrieveController.java | 2 ++ .../java/hous/server/controller/room/RoomController.java | 5 +++++ .../server/controller/room/RoomRetrieveController.java | 3 +++ .../java/hous/server/controller/rule/RuleController.java | 4 ++++ .../server/controller/rule/RuleRetrieveController.java | 2 ++ .../java/hous/server/controller/todo/TodoController.java | 5 +++++ .../server/controller/todo/TodoRetrieveController.java | 8 ++++++++ .../java/hous/server/controller/user/UserController.java | 7 +++++++ .../server/controller/user/UserRetrieveController.java | 8 ++++++++ 11 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main/java/hous/server/config/WebConfig.java b/src/main/java/hous/server/config/WebConfig.java index 9cbf951c..c8c949b0 100644 --- a/src/main/java/hous/server/config/WebConfig.java +++ b/src/main/java/hous/server/config/WebConfig.java @@ -1,6 +1,7 @@ package hous.server.config; import hous.server.config.interceptor.auth.AuthInterceptor; +import hous.server.config.interceptor.version.VersionInterceptor; import hous.server.config.resolver.UserIdResolver; import lombok.RequiredArgsConstructor; import org.springframework.context.MessageSource; @@ -19,12 +20,13 @@ @Configuration public class WebConfig implements WebMvcConfigurer { + private final VersionInterceptor versionInterceptor; private final AuthInterceptor authInterceptor; - private final UserIdResolver userIdResolver; @Override public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(versionInterceptor); registry.addInterceptor(authInterceptor); } diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index f46df47e..5dff5da1 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -5,6 +5,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.controller.auth.dto.request.LoginRequestDto; import hous.server.controller.auth.dto.request.SignUpRequestDto; @@ -63,6 +64,7 @@ public class AuthController { @ApiResponse(code = 409, message = "이미 해당 계정으로 회원가입하셨습니다.\n 로그인 해주세요.\n", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @PostMapping("/auth/signup") public ResponseEntity> signUp(@Valid @RequestBody SignUpRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); @@ -90,6 +92,7 @@ public ResponseEntity> signUp(@Valid @RequestBody @ApiResponse(code = 409, message = "이미 로그인 중인 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @PostMapping("/auth/login") public ResponseEntity> login(@Valid @RequestBody LoginRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); @@ -117,6 +120,7 @@ public ResponseEntity> login(@Valid @RequestBody @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @PostMapping("/auth/login/force") public ResponseEntity> forceLogin(@Valid @RequestBody LoginRequestDto request) { AuthService authService = authServiceProvider.getAuthService(request.getSocialType()); @@ -142,6 +146,7 @@ public ResponseEntity> forceLogin(@Valid @Request @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @PostMapping("/auth/refresh") public ResponseEntity> reissue(@Valid @RequestBody TokenRequestDto request) { return SuccessResponse.success(SuccessCode.REISSUE_TOKEN_SUCCESS, createTokenService.reissueToken(request)); @@ -159,6 +164,7 @@ public ResponseEntity> reissue(@Valid @RequestB @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PostMapping("/auth/logout") public ResponseEntity> logout(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/home/HomeRetrieveController.java b/src/main/java/hous/server/controller/home/HomeRetrieveController.java index 6fac342b..869e10b2 100644 --- a/src/main/java/hous/server/controller/home/HomeRetrieveController.java +++ b/src/main/java/hous/server/controller/home/HomeRetrieveController.java @@ -4,6 +4,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.home.HomeRetrieveService; import hous.server.service.home.dto.response.HomeInfoResponse; @@ -40,6 +41,7 @@ public class HomeRetrieveController { response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/home") public ResponseEntity> getHomeInfo(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index 24f37ae6..befe65cc 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -5,6 +5,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.room.RoomService; import hous.server.service.room.dto.request.SetRoomNameRequestDto; @@ -48,6 +49,7 @@ public class RoomController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/room") @@ -78,6 +80,7 @@ public ResponseEntity> createRoom(@ApiIgnore @ @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PostMapping("/room/{roomId}/join") public ResponseEntity> joinRoom(@ApiIgnore @UserId Long userId, @@ -107,6 +110,7 @@ public ResponseEntity> joinRoom(@ApiIgnore @Us @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PutMapping("/room/name") public ResponseEntity> updateRoomName(@ApiIgnore @UserId Long userId, @@ -131,6 +135,7 @@ public ResponseEntity> updateRoomName(@ApiIgnore @UserId @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @DeleteMapping("/room/leave") public ResponseEntity> leaveRoom(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index 65fdc2c8..59d132ae 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -4,6 +4,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.room.RoomRetrieveService; import hous.server.service.room.dto.response.GetRoomInfoResponse; @@ -36,6 +37,7 @@ public class RoomRetrieveController { @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/room") public ResponseEntity> getRoom(@ApiIgnore @UserId Long userId) { @@ -52,6 +54,7 @@ public ResponseEntity> getRoom(@ApiIgnore @User @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/room/info") public ResponseEntity> getRoomInfo(@ApiParam(name = "code", value = "참가하려는 방 코드", required = true, example = "PNO6VN6A") diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 00895622..546fa4ad 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -4,6 +4,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleService; import hous.server.service.rule.dto.request.CreateRuleRequestDto; @@ -54,6 +55,7 @@ public class RuleController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/rules") @@ -88,6 +90,7 @@ public ResponseEntity> createRule(@ApiIgnore @UserId Lon @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PutMapping("/rules") public ResponseEntity> updateRules(@ApiIgnore @UserId Long userId, @@ -118,6 +121,7 @@ public ResponseEntity> updateRules(@ApiIgnore @UserId Lo @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @DeleteMapping("/rules") public ResponseEntity> deleteRules(@ApiIgnore @UserId Long userId, diff --git a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java index 9a2b5762..ac01b0d6 100644 --- a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java +++ b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java @@ -4,6 +4,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.rule.RuleRetrieveService; import hous.server.service.rule.dto.response.RuleInfoResponse; @@ -35,6 +36,7 @@ public class RuleRetrieveController { @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/rules") public ResponseEntity> getRulesInfo(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 2104b93c..19baa46e 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -4,6 +4,7 @@ import hous.server.common.dto.ErrorResponse; import hous.server.common.dto.SuccessResponse; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoService; import hous.server.service.todo.dto.request.CheckTodoRequestDto; @@ -55,6 +56,7 @@ public class TodoController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @ResponseStatus(HttpStatus.CREATED) @PostMapping("/todo") @@ -94,6 +96,7 @@ public ResponseEntity> createTodo(@ApiIgnore @UserId Lon @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PutMapping("/todo/{todoId}") public ResponseEntity> updateTodo(@ApiIgnore @UserId Long userId, @@ -126,6 +129,7 @@ public ResponseEntity> updateTodo(@ApiIgnore @UserId Lon @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PostMapping("/todo/{todoId}/check") public ResponseEntity> checkTodo(@ApiIgnore @UserId Long userId, @@ -152,6 +156,7 @@ public ResponseEntity> checkTodo(@ApiIgnore @UserId Long @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @DeleteMapping("/todo/{todoId}") public ResponseEntity> deleteTodo(@ApiIgnore @UserId Long userId, diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index beb1fead..851379be 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -4,6 +4,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.todo.TodoRetrieveService; import hous.server.service.todo.dto.response.*; @@ -38,6 +39,7 @@ public class TodoRetrieveController { response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/todo") public ResponseEntity> getUsersInfo(@ApiIgnore @UserId Long userId) { @@ -58,6 +60,7 @@ public ResponseEntity> getUsersInfo response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/todos") public ResponseEntity> getTodoMain(@ApiIgnore @UserId Long userId) { @@ -79,6 +82,7 @@ public ResponseEntity> getTodoMain(@ApiIgnore response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/todo/{todoId}") public ResponseEntity> getTodoInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") @@ -101,6 +105,7 @@ public ResponseEntity> getTodoInfo(@ApiParam(n response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/todo/{todoId}/summary") public ResponseEntity> getTodoSummaryInfo(@ApiParam(name = "todoId", value = "조회할 todo 의 id", required = true, example = "1") @@ -124,6 +129,7 @@ public ResponseEntity> getTodoSummaryIn response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/todos/day") public ResponseEntity> getTodoAllDayInfo(@ApiIgnore @UserId Long userId) { @@ -145,6 +151,7 @@ public ResponseEntity> getTodoAllDayInfo(@Ap response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/todos/member") public ResponseEntity> getTodoAllMemberInfo(@ApiIgnore @UserId Long userId) { @@ -165,6 +172,7 @@ public ResponseEntity> getTodoAllMemberIn response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/todos/me") public ResponseEntity> getMyTodoInfo(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index a1af1819..de63d693 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -5,6 +5,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.service.slack.SlackService; import hous.server.service.user.UserRetrieveService; @@ -57,6 +58,7 @@ public class UserController { @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PutMapping("/user") public ResponseEntity> updateUserInfo(@ApiIgnore @UserId Long userId, @@ -81,6 +83,7 @@ public ResponseEntity> updateUserInfo(@ApiIgnore @UserId @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PatchMapping("/user/push") public ResponseEntity> updateUserPushSetting(@ApiIgnore @UserId Long userId, @@ -106,6 +109,7 @@ public ResponseEntity> updateUserPushSetting(@ApiIgnore @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PutMapping("/user/personality") public ResponseEntity> updateUserTestScore(@ApiIgnore @UserId Long userId, @@ -130,6 +134,7 @@ public ResponseEntity> updateUse @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PutMapping("/user/badge/{badgeId}/represent") public ResponseEntity> updateRepresentBadge(@ApiIgnore @UserId Long userId, @@ -156,6 +161,7 @@ public ResponseEntity> updateRepresentBadge(@ApiIgnore @ @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @DeleteMapping("/user") public ResponseEntity> deleteUser(@ApiIgnore @UserId Long userId, @@ -180,6 +186,7 @@ public ResponseEntity> deleteUser(@ApiIgnore @UserId Lon @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest + @Version @Auth @PostMapping("/user/feedback") public ResponseEntity> acquireFeedbackBadge(@ApiIgnore @UserId Long userId) { diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index f61dfb1b..587058e9 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -4,6 +4,7 @@ import hous.server.common.dto.SuccessResponse; import hous.server.common.success.SuccessCode; import hous.server.config.interceptor.auth.Auth; +import hous.server.config.interceptor.version.Version; import hous.server.config.resolver.UserId; import hous.server.domain.personality.PersonalityColor; import hous.server.service.notification.NotificationRetrieveService; @@ -40,6 +41,7 @@ public class UserRetrieveController { response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/user") public ResponseEntity> getUserInfo(@ApiIgnore @UserId Long userId) { @@ -57,6 +59,7 @@ public ResponseEntity> getUserInfo(@ApiIgnore @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/user/{onboardingId}") public ResponseEntity> getHomieInfo(@ApiParam(name = "onboardingId", value = "조회할 호미의 id", required = true, example = "1") @@ -79,6 +82,7 @@ public ResponseEntity> getHomieInfo(@ApiParam( response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/user/push") public ResponseEntity> getUserPushSetting(@ApiIgnore @UserId Long userId) { @@ -96,6 +100,7 @@ public ResponseEntity> getUserPushSetting(@ @ApiResponse(code = 404, message = "GRAY 에 대한 성향 정보는 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/user/personality") public ResponseEntity> getPersonalityInfo(@ApiParam(name = "color", value = "조회할 성향 색깔", required = true, example = "RED") @@ -112,6 +117,7 @@ public ResponseEntity> getPersonalityIn @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/user/personality/test") public ResponseEntity>> getPersonalityTestInfo() { @@ -134,6 +140,7 @@ public ResponseEntity>> getPer response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/user/badges") public ResponseEntity> getMyBadgeList(@ApiIgnore @UserId Long userId) { @@ -154,6 +161,7 @@ public ResponseEntity> getMyBadgeList(@ApiI @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) + @Version @Auth @GetMapping("/user/notifications") public ResponseEntity> getNotificationsInfo(@ApiParam(name = "size", value = "스크롤 1회당 조회할 개수", required = true, example = "10") From af6aeef18f62d0490483784248f9061ec5b2013c Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Mon, 12 Dec 2022 16:32:22 +0900 Subject: [PATCH 297/301] =?UTF-8?q?#266=20[docs]=20swagger=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=EC=97=90=20426=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hous/server/controller/auth/AuthController.java | 5 +++++ .../server/controller/home/HomeRetrieveController.java | 1 + .../java/hous/server/controller/room/RoomController.java | 4 ++++ .../server/controller/room/RoomRetrieveController.java | 2 ++ .../java/hous/server/controller/rule/RuleController.java | 3 +++ .../server/controller/rule/RuleRetrieveController.java | 1 + .../java/hous/server/controller/todo/TodoController.java | 4 ++++ .../server/controller/todo/TodoRetrieveController.java | 7 +++++++ .../java/hous/server/controller/user/UserController.java | 6 ++++++ .../server/controller/user/UserRetrieveController.java | 7 +++++++ 10 files changed, 40 insertions(+) diff --git a/src/main/java/hous/server/controller/auth/AuthController.java b/src/main/java/hous/server/controller/auth/AuthController.java index 5dff5da1..d0ab13c7 100644 --- a/src/main/java/hous/server/controller/auth/AuthController.java +++ b/src/main/java/hous/server/controller/auth/AuthController.java @@ -62,6 +62,7 @@ public class AuthController { response = ErrorResponse.class), @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "이미 해당 계정으로 회원가입하셨습니다.\n 로그인 해주세요.\n", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -90,6 +91,7 @@ public ResponseEntity> signUp(@Valid @RequestBody @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "이미 로그인 중인 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -118,6 +120,7 @@ public ResponseEntity> login(@Valid @RequestBody response = ErrorResponse.class), @ApiResponse(code = 401, message = "유효하지 않은 토큰입니다.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -144,6 +147,7 @@ public ResponseEntity> forceLogin(@Valid @Request response = ErrorResponse.class), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -161,6 +165,7 @@ public ResponseEntity> reissue(@Valid @RequestB @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/home/HomeRetrieveController.java b/src/main/java/hous/server/controller/home/HomeRetrieveController.java index 869e10b2..7b804ead 100644 --- a/src/main/java/hous/server/controller/home/HomeRetrieveController.java +++ b/src/main/java/hous/server/controller/home/HomeRetrieveController.java @@ -39,6 +39,7 @@ public class HomeRetrieveController { message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version diff --git a/src/main/java/hous/server/controller/room/RoomController.java b/src/main/java/hous/server/controller/room/RoomController.java index befe65cc..2f730949 100644 --- a/src/main/java/hous/server/controller/room/RoomController.java +++ b/src/main/java/hous/server/controller/room/RoomController.java @@ -46,6 +46,7 @@ public class RoomController { message = "1. 처리중인 요청입니다.\n" + "2. 이미 참가중인 방이 있습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -77,6 +78,7 @@ public ResponseEntity> createRoom(@ApiIgnore @ message = "1. 처리중인 요청입니다.\n" + "2. 이미 참가중인 방이 있습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -107,6 +109,7 @@ public ResponseEntity> joinRoom(@ApiIgnore @Us + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -132,6 +135,7 @@ public ResponseEntity> updateRoomName(@ApiIgnore @UserId + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/room/RoomRetrieveController.java b/src/main/java/hous/server/controller/room/RoomRetrieveController.java index 59d132ae..542ab66b 100644 --- a/src/main/java/hous/server/controller/room/RoomRetrieveController.java +++ b/src/main/java/hous/server/controller/room/RoomRetrieveController.java @@ -35,6 +35,7 @@ public class RoomRetrieveController { @ApiResponse(code = 200, message = "참가중인 방 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -52,6 +53,7 @@ public ResponseEntity> getRoom(@ApiIgnore @User @ApiResponses(value = { @ApiResponse(code = 200, message = "참가하려는 방 정보 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version diff --git a/src/main/java/hous/server/controller/rule/RuleController.java b/src/main/java/hous/server/controller/rule/RuleController.java index 546fa4ad..8e6cf322 100644 --- a/src/main/java/hous/server/controller/rule/RuleController.java +++ b/src/main/java/hous/server/controller/rule/RuleController.java @@ -52,6 +52,7 @@ public class RuleController { response = ErrorResponse.class), // @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -87,6 +88,7 @@ public ResponseEntity> createRule(@ApiIgnore @UserId Lon response = ErrorResponse.class), // @ApiResponse(code = 409, message = "이미 존재하는 규칙입니다.", response = ErrorResponse.class), //TODO 다음 릴리즈 때 클라에서 추가할 예정이라 우선 주석 처리 @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -118,6 +120,7 @@ public ResponseEntity> updateRules(@ApiIgnore @UserId Lo + "3. 존재하지 않는 규칙입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java index ac01b0d6..fbf21c61 100644 --- a/src/main/java/hous/server/controller/rule/RuleRetrieveController.java +++ b/src/main/java/hous/server/controller/rule/RuleRetrieveController.java @@ -34,6 +34,7 @@ public class RuleRetrieveController { @ApiResponse(code = 200, message = "규칙 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version diff --git a/src/main/java/hous/server/controller/todo/TodoController.java b/src/main/java/hous/server/controller/todo/TodoController.java index 19baa46e..f548d6f4 100644 --- a/src/main/java/hous/server/controller/todo/TodoController.java +++ b/src/main/java/hous/server/controller/todo/TodoController.java @@ -53,6 +53,7 @@ public class TodoController { message = "1. 처리중인 요청입니다.\n" + "2. 이미 존재하는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -93,6 +94,7 @@ public ResponseEntity> createTodo(@ApiIgnore @UserId Lon message = "1. 처리중인 요청입니다.\n" + "2. 이미 존재하는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -126,6 +128,7 @@ public ResponseEntity> updateTodo(@ApiIgnore @UserId Lon + "2. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -153,6 +156,7 @@ public ResponseEntity> checkTodo(@ApiIgnore @UserId Long + "2. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java index 851379be..54f76f17 100644 --- a/src/main/java/hous/server/controller/todo/TodoRetrieveController.java +++ b/src/main/java/hous/server/controller/todo/TodoRetrieveController.java @@ -37,6 +37,7 @@ public class TodoRetrieveController { message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -58,6 +59,7 @@ public ResponseEntity> getUsersInfo message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -80,6 +82,7 @@ public ResponseEntity> getTodoMain(@ApiIgnore + "2. 참가중인 방이 존재하지 않습니다.\n" + "3. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -103,6 +106,7 @@ public ResponseEntity> getTodoInfo(@ApiParam(n message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 존재하지 않는 todo 입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -127,6 +131,7 @@ public ResponseEntity> getTodoSummaryIn + "2. 존재하지 않는 todo 입니다.\n" + "3. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -149,6 +154,7 @@ public ResponseEntity> getTodoAllDayInfo(@Ap + "2. 존재하지 않는 todo 입니다.\n" + "3. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -170,6 +176,7 @@ public ResponseEntity> getTodoAllMemberIn message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index de63d693..47f771f3 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -55,6 +55,7 @@ public class UserController { + "2. 존재하지 않는 방입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -80,6 +81,7 @@ public ResponseEntity> updateUserInfo(@ApiIgnore @UserId @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -106,6 +108,7 @@ public ResponseEntity> updateUserPushSetting(@ApiIgnore + "2. 같은 방에 참가하고 있지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -131,6 +134,7 @@ public ResponseEntity> updateUse + "3. 존재하지 않는 배지 입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -158,6 +162,7 @@ public ResponseEntity> updateRepresentBadge(@ApiIgnore @ @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest @@ -183,6 +188,7 @@ public ResponseEntity> deleteUser(@ApiIgnore @UserId Lon + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 409, message = "처리중인 요청입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @PreventDuplicateRequest diff --git a/src/main/java/hous/server/controller/user/UserRetrieveController.java b/src/main/java/hous/server/controller/user/UserRetrieveController.java index 587058e9..073195be 100644 --- a/src/main/java/hous/server/controller/user/UserRetrieveController.java +++ b/src/main/java/hous/server/controller/user/UserRetrieveController.java @@ -39,6 +39,7 @@ public class UserRetrieveController { message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -57,6 +58,7 @@ public ResponseEntity> getUserInfo(@ApiIgnore @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 403, message = "같은 방에 참가하고 있지 않습니다.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -80,6 +82,7 @@ public ResponseEntity> getHomieInfo(@ApiParam( message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 유저의 온보딩 정보가 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -98,6 +101,7 @@ public ResponseEntity> getUserPushSetting(@ @ApiResponse(code = 200, message = "성향 정보 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "GRAY 에 대한 성향 정보는 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -115,6 +119,7 @@ public ResponseEntity> getPersonalityIn @ApiResponses(value = { @ApiResponse(code = 200, message = "성향테스트 정보 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -138,6 +143,7 @@ public ResponseEntity>> getPer message = "1. 탈퇴했거나 존재하지 않는 유저입니다.\n" + "2. 참가중인 방이 존재하지 않습니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version @@ -159,6 +165,7 @@ public ResponseEntity> getMyBadgeList(@ApiI @ApiResponse(code = 200, message = "알림 목록 조회 성공입니다."), @ApiResponse(code = 401, message = "토큰이 만료되었습니다. 다시 로그인 해주세요.", response = ErrorResponse.class), @ApiResponse(code = 404, message = "탈퇴했거나 존재하지 않는 유저입니다.", response = ErrorResponse.class), + @ApiResponse(code = 426, message = "최신 버전으로 업그레이드가 필요합니다.", response = ErrorResponse.class), @ApiResponse(code = 500, message = "예상치 못한 서버 에러가 발생하였습니다.", response = ErrorResponse.class) }) @Version From e6f1da371c7a201849d38c0edafcbfc3e00fb6eb Mon Sep 17 00:00:00 2001 From: hyejungg Date: Tue, 13 Dec 2022 19:53:19 +0900 Subject: [PATCH 298/301] =?UTF-8?q?#268=20[fix]=20=EC=9E=90=EA=B8=B0?= =?UTF-8?q?=EC=86=8C=EA=B0=9C=20=EB=B9=88=20=EA=B0=92=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=ED=95=A0=20=EA=B2=BD=EC=9A=B0,=20null=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/hous/server/domain/user/Onboarding.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/hous/server/domain/user/Onboarding.java b/src/main/java/hous/server/domain/user/Onboarding.java index c4eaae61..403d7c4a 100644 --- a/src/main/java/hous/server/domain/user/Onboarding.java +++ b/src/main/java/hous/server/domain/user/Onboarding.java @@ -113,6 +113,7 @@ public void updateUserInfo(UpdateUserInfoRequestDto request) { this.birthday = request.getBirthday(); this.mbti = request.getMbti(); this.job = request.getJob(); + this.introduction = request.getIntroduction(); if (request.getIntroduction() != null) { this.introduction = request.getIntroduction().replaceAll("(\r\n|\r|\n|\n\r)", " "); } From 12cb487a91e5a7d82511038f503fe7608bd291b6 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Fri, 16 Dec 2022 16:37:27 +0900 Subject: [PATCH 299/301] =?UTF-8?q?#262=20[feat]=20prod=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=EB=B0=B0=ED=8F=AC=EC=9A=A9=20yml=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-prod.yml | 70 +++++++++++++++++++++++++++++ .github/workflows/pr-check-prod.yml | 46 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 .github/workflows/deploy-prod.yml create mode 100644 .github/workflows/pr-check-prod.yml diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 00000000..d9f4297d --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,70 @@ +# This is a basic workflow to help you get started with Actions + +name: CICD + +# Controls when the workflow will run +on: + push: + branches: [ main ] + +env: + AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME_PROD }} + +jobs: + build: + runs-on: ubuntu-18.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: create secret files + working-directory: ./src/main/resources + run: | + touch application.yml + touch application-prod.yml + echo "${{ secrets.APPLICATION_YML }}" >> application.yml + echo "${{ secrets.APPLICATION_PROD_YML }}" >> application-prod.yml + + mkdir firebase + touch ./firebase/firebase_service_key.json + echo "${{ secrets.FIREBASE_SERVICE_KEY_JSON }}" >> ./firebase/firebase_service_key.json + sed -i 's/#/"/g' ./firebase/firebase_service_key.json + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: '11' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + shell: bash + + # - name: Test with Gradle + # run: ./gradlew test + + - name: Build with Gradle + run: ./gradlew build -x test + shell: bash + + - name: Make zip file + run: zip -r ./code-deploy.zip . + shell: bash + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_PROD }} + aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY_PROD }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Upload to S3 + run: aws s3 cp --region ap-northeast-2 ./code-deploy.zip s3://$AWS_S3_BUCKET_NAME/code-deploy.zip + + - name: Code Deploy + run: aws deploy create-deployment + --application-name hous-codedeploy + --deployment-config-name CodeDeployDefault.OneAtATime + --deployment-group-name API + --s3-location bucket=$AWS_S3_BUCKET_NAME,bundleType=zip,key=code-deploy.zip diff --git a/.github/workflows/pr-check-prod.yml b/.github/workflows/pr-check-prod.yml new file mode 100644 index 00000000..5a3c6e7c --- /dev/null +++ b/.github/workflows/pr-check-prod.yml @@ -0,0 +1,46 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-18.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: create secret files + working-directory: ./src/main/resources + run: | + touch application.yml + touch application-prod.yml + echo "${{ secrets.APPLICATION_YML }}" >> application.yml + echo "${{ secrets.APPLICATION_PROD_YML }}" >> application-prod.yml + + mkdir firebase + touch ./firebase/firebase_service_key.json + echo "${{ secrets.FIREBASE_SERVICE_KEY_JSON }}" >> ./firebase/firebase_service_key.json + sed -i 's/#/"/g' ./firebase/firebase_service_key.json + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: '11' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + shell: bash + + # - name: Test with Gradle + # run: ./gradlew test + + - name: Build with Gradle + run: ./gradlew build -x test + shell: bash From abc4fe3bcb029f2f2f194e2dae7d7af7c1ca1671 Mon Sep 17 00:00:00 2001 From: HyeokJoon Kong Date: Fri, 16 Dec 2022 16:53:56 +0900 Subject: [PATCH 300/301] =?UTF-8?q?#262=20[fix]=20Github=20Actions=20?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=20=ED=94=8C=EB=A1=9C=EC=9A=B0=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 2 +- .github/workflows/deploy-prod.yml | 2 +- .github/workflows/pr-check-dev.yml | 2 +- .github/workflows/pr-check-prod.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 11ab96ad..4b4d5ac9 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CICD +name: deploy-dev # Controls when the workflow will run on: diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index d9f4297d..a083010f 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CICD +name: deploy-prod # Controls when the workflow will run on: diff --git a/.github/workflows/pr-check-dev.yml b/.github/workflows/pr-check-dev.yml index 236c966b..b3e0e442 100644 --- a/.github/workflows/pr-check-dev.yml +++ b/.github/workflows/pr-check-dev.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CI +name: pr-check-dev # Controls when the workflow will run on: diff --git a/.github/workflows/pr-check-prod.yml b/.github/workflows/pr-check-prod.yml index 5a3c6e7c..e1874cec 100644 --- a/.github/workflows/pr-check-prod.yml +++ b/.github/workflows/pr-check-prod.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CI +name: pr-check-prod # Controls when the workflow will run on: From 0918a424d7293c27f19fa20dbeb6b88a4da1ebbd Mon Sep 17 00:00:00 2001 From: hyejungg Date: Fri, 16 Dec 2022 17:16:59 +0900 Subject: [PATCH 301/301] =?UTF-8?q?#271=20[fix]=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=95=8C=EB=A6=BC=20=EC=8A=AC=EB=9E=99?= =?UTF-8?q?=EC=97=90=20=EC=9D=98=EA=B2=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/user/UserController.java | 4 ++-- .../hous/server/service/slack/SlackService.java | 2 +- .../server/service/slack/SlackServiceUtils.java | 7 +++++++ .../slack/dto/response/UserDeleteResponse.java | 14 +++++++++++++- .../server/service/user/UserRetrieveService.java | 4 ++-- .../java/hous/server/service/user/UserService.java | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/hous/server/controller/user/UserController.java b/src/main/java/hous/server/controller/user/UserController.java index 47f771f3..089a4b61 100644 --- a/src/main/java/hous/server/controller/user/UserController.java +++ b/src/main/java/hous/server/controller/user/UserController.java @@ -170,9 +170,9 @@ public ResponseEntity> updateRepresentBadge(@ApiIgnore @ @Auth @DeleteMapping("/user") public ResponseEntity> deleteUser(@ApiIgnore @UserId Long userId, - @RequestBody DeleteUserRequestDto request) { + @Valid @RequestBody DeleteUserRequestDto request) { userService.deleteUser(request, userId); - slackService.sendSlackMessageDeleteUser(userRetrieveService.getFeedback()); + slackService.sendSlackMessageDeleteUser(userRetrieveService.getFeedback(request.getComment())); return SuccessResponse.OK; } diff --git a/src/main/java/hous/server/service/slack/SlackService.java b/src/main/java/hous/server/service/slack/SlackService.java index 0b001ba3..f198a2cd 100644 --- a/src/main/java/hous/server/service/slack/SlackService.java +++ b/src/main/java/hous/server/service/slack/SlackService.java @@ -32,7 +32,7 @@ public class SlackService { private static final String ATTACHMENTS_NOTIFICATION_COLOR = "#36a64f"; public void sendSlackMessageDeleteUser(UserDeleteResponse userDeleteResponse) { - if (!profile.equals(LOCAL) && userDeleteResponse.getTotalDeleteUserList().isEmpty()) { + if (!profile.equals(LOCAL) && !userDeleteResponse.getTotalDeleteUserList().isEmpty()) { try { Slack slack = Slack.getInstance(); List layoutBlocks = SlackServiceUtils.createUserDeleteMessage(userDeleteResponse); diff --git a/src/main/java/hous/server/service/slack/SlackServiceUtils.java b/src/main/java/hous/server/service/slack/SlackServiceUtils.java index 77229180..b67089ef 100644 --- a/src/main/java/hous/server/service/slack/SlackServiceUtils.java +++ b/src/main/java/hous/server/service/slack/SlackServiceUtils.java @@ -20,6 +20,7 @@ public class SlackServiceUtils { private static final String FILTER_STRING = "hous.server"; private static final String PROD_USER_DELETE_TOTAL_COUNT_MESSAGE = "*피드백을 남긴 총 탈퇴 인원:* "; private static final String PROD_USER_DELETE_MESSAGE = "*피드백 유형별 탈퇴 인원:*\n"; + private static final String PROD_NOW_USER_DELETE_COMMENT = "*지금 탈퇴한 유저의 의견:*\n"; public static List createAttachments(String color, List data) { List attachments = new ArrayList<>(); @@ -42,6 +43,12 @@ public static List createUserDeleteMessage(UserDeleteResponse userD } layoutBlockList.add(section(section -> section.text(markdownText(PROD_USER_DELETE_MESSAGE + stringBuilder.toString())))); + + if (userDeleteResponse.getComment() != null) { + layoutBlockList.add(section(section -> + section.text(markdownText(PROD_NOW_USER_DELETE_COMMENT + userDeleteResponse.getComment())))); + } + return layoutBlockList; } diff --git a/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java b/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java index 43ee491e..e2b8285c 100644 --- a/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java +++ b/src/main/java/hous/server/service/slack/dto/response/UserDeleteResponse.java @@ -16,8 +16,19 @@ public class UserDeleteResponse { private long totalDeleteUserCount; private List totalDeleteUserList; + private String comment; - public static UserDeleteResponse of(long totalDeleteUserCount, List users) { + public static UserDeleteResponse of(long totalDeleteUserCount, List users, String comment) { + if (comment == null) { + return UserDeleteResponse.builder() + .totalDeleteUserCount(totalDeleteUserCount) + .totalDeleteUserList(users.stream() + .map(user -> UserDelete.of(user.getCount(), user.getFeedbackType())) + .sorted(Comparator.comparing(userDelete -> userDelete.getFeedbackType().length())) + .collect(Collectors.toList()) + ) + .build(); + } return UserDeleteResponse.builder() .totalDeleteUserCount(totalDeleteUserCount) .totalDeleteUserList(users.stream() @@ -25,6 +36,7 @@ public static UserDeleteResponse of(long totalDeleteUserCount, List .sorted(Comparator.comparing(userDelete -> userDelete.getFeedbackType().length())) .collect(Collectors.toList()) ) + .comment(comment) .build(); } } diff --git a/src/main/java/hous/server/service/user/UserRetrieveService.java b/src/main/java/hous/server/service/user/UserRetrieveService.java index 35f98846..f82419d9 100644 --- a/src/main/java/hous/server/service/user/UserRetrieveService.java +++ b/src/main/java/hous/server/service/user/UserRetrieveService.java @@ -100,7 +100,7 @@ public MyBadgeInfoResponse getMyBadgeList(Long userId) { return MyBadgeInfoResponse.of(represent, badges, myBadges, newBadges); } - public UserDeleteResponse getFeedback() { + public UserDeleteResponse getFeedback(String comment) { Map> users = feedbackRepository.findAll().stream() .collect(Collectors.groupingBy(Feedback::getFeedbackType)); List userDeletes = new ArrayList<>(); @@ -109,7 +109,7 @@ public UserDeleteResponse getFeedback() { totalCount += users.get(feedbackType).size(); userDeletes.add(UserDelete.of(users.get(feedbackType).size(), feedbackType.getValue())); } - return UserDeleteResponse.of(totalCount, userDeletes); + return UserDeleteResponse.of(totalCount, userDeletes, comment); } private UserInfoResponse getProfileInfoByUser(User user) { diff --git a/src/main/java/hous/server/service/user/UserService.java b/src/main/java/hous/server/service/user/UserService.java index fdd1f02d..19b0b373 100644 --- a/src/main/java/hous/server/service/user/UserService.java +++ b/src/main/java/hous/server/service/user/UserService.java @@ -167,7 +167,7 @@ public void deleteUser(DeleteUserRequestDto request, Long userId) { RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate); } - if (!request.getFeedbackType().equals(FeedbackType.NO) && request.getComment() != null) { + if (!(request.getFeedbackType().equals(FeedbackType.NO) && request.getComment() == null)) { feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getComment())); } userRepository.delete(user);