diff --git a/src/main/java/com/arom/with_travel/domain/community/Community.java b/src/main/java/com/arom/with_travel/domain/community/Community.java index 0c2b5c6..d1343c0 100644 --- a/src/main/java/com/arom/with_travel/domain/community/Community.java +++ b/src/main/java/com/arom/with_travel/domain/community/Community.java @@ -40,7 +40,7 @@ public class Community extends BaseEntity { @JoinColumn(name = "member_id", nullable = false) private Member member; - @OneToMany(mappedBy = "community") + @OneToMany(mappedBy = "community", orphanRemoval = true) private List communityReplies = new ArrayList<>(); @OneToMany(mappedBy = "community") @@ -59,14 +59,32 @@ public static Community create(Member writer, String title, String content, .country(country) .city(city) .build(); + c.changeMember(writer); return c; } + public void changeMember(Member newMember) { + if (this.member != null) { + this.member.getCommunities().remove(this); + } + this.member = newMember; + if (newMember != null && !newMember.getCommunities().contains(this)) { + newMember.getCommunities().add(this); + } + } + + public void addReply(CommunityReply reply) { + this.communityReplies.add(reply); + if (reply.getCommunity() != this) { + reply.setCommunity(this); + } + } + public void update(String title, String content, String continent, String country, String city) { - if (title != null) this.title = title; - if (content != null) this.content = content; - if (continent != null) this.continent = continent; - if (country != null) this.country = country; - if (city != null) this.city = city; + this.title = title; + this.content = content; + this.continent = continent; + this.country = country; + this.city = city; } } diff --git a/src/main/java/com/arom/with_travel/domain/community/service/CommunityService.java b/src/main/java/com/arom/with_travel/domain/community/service/CommunityService.java index d6c1605..3bd4d76 100644 --- a/src/main/java/com/arom/with_travel/domain/community/service/CommunityService.java +++ b/src/main/java/com/arom/with_travel/domain/community/service/CommunityService.java @@ -70,10 +70,17 @@ private static String requireUrl(String url) { @Transactional public CommunityDetailResponse readAndIncreaseView(Long id) { - communityRepository.increaseViewCount(id); + if (!communityRepository.existsById(id)) { + throw BaseException.from(ErrorCode.COMMUNITY_NOT_FOUND); + } + + int updated = communityRepository.increaseViewCount(id); + Community c = communityRepository.findDetailById(id); - if (c == null) throw BaseException.from(ErrorCode.COMMUNITY_NOT_FOUND); - List urls = c.getImages().stream().map(Image::getImageUrl).collect(Collectors.toList()); + if (c == null) { throw BaseException.from(ErrorCode.COMMUNITY_NOT_FOUND);} + + List urls = c.getImages().stream().map(Image::getImageUrl).toList(); + return new CommunityDetailResponse( c.getId(), c.getTitle(), c.getContent(), c.getContinent(), c.getCountry(), c.getCity(), diff --git a/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReply.java b/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReply.java index ea05143..64a5e3a 100644 --- a/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReply.java +++ b/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReply.java @@ -9,7 +9,11 @@ import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLRestriction; +import java.util.ArrayList; +import java.util.List; + @Getter +@Setter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Builder @@ -33,6 +37,9 @@ public class CommunityReply extends BaseEntity { @JoinColumn(name = "member_id", nullable = false) private Member member; + @OneToMany(mappedBy = "reply", orphanRemoval = true) + private List likes = new ArrayList<>(); + public static CommunityReply create(Community community, Member writer, String content) { return CommunityReply.builder() .community(community) @@ -45,5 +52,11 @@ public void changeContent(String content) { this.content = content; } + public void addLike(CommunityReplyLike like) { + this.likes.add(like); + if (like.getReply() != this) { + like.setReply(this); + } + } } diff --git a/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReplyLike.java b/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReplyLike.java index 5b692a4..32edead 100644 --- a/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReplyLike.java +++ b/src/main/java/com/arom/with_travel/domain/community_reply/CommunityReplyLike.java @@ -5,6 +5,7 @@ import lombok.*; @Getter +@Setter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/src/main/java/com/arom/with_travel/domain/member/Member.java b/src/main/java/com/arom/with_travel/domain/member/Member.java index 9a894c8..1542018 100644 --- a/src/main/java/com/arom/with_travel/domain/member/Member.java +++ b/src/main/java/com/arom/with_travel/domain/member/Member.java @@ -6,6 +6,7 @@ import com.arom.with_travel.domain.chat.model.ChatPart; import com.arom.with_travel.domain.community.Community; import com.arom.with_travel.domain.community_reply.CommunityReply; +import com.arom.with_travel.domain.community_reply.CommunityReplyLike; import com.arom.with_travel.domain.image.Image; import com.arom.with_travel.domain.likes.Likes; import com.arom.with_travel.domain.shorts.Shorts; @@ -38,6 +39,7 @@ public class Member extends BaseEntity { private String oauthId; private String email; + @Column(length = 255) private String password; private LocalDate birth; @Enumerated(EnumType.STRING) private Gender gender; @@ -105,6 +107,9 @@ public static Member create(String memberName, String email, String oauthId) { @OneToMany(mappedBy = "member") private List communities = new ArrayList<>(); + @OneToMany(mappedBy = "member", orphanRemoval = true) + private List replyLikes = new ArrayList<>(); + @OneToMany(mappedBy = "member") private List communityReplies = new ArrayList<>(); @@ -125,15 +130,16 @@ public static Member create(String memberName, String email, String oauthId) { private Image image; @Builder - public Member(Long id, String oauthId, String email, String name, LocalDate birth, Gender gender, - String phone, LoginType loginType, String nickname, String introduction, - TravelType travelType, Role role) { + public Member(Long id, String oauthId, String email, String password, String name, + LocalDate birth, Gender gender, String phone, LoginType loginType, + String nickname, String introduction, TravelType travelType, Role role) { this.id = id; this.oauthId = oauthId; this.email = email; + this.password = password; + this.name = name; this.birth = birth; this.gender = gender; - this.name = name; this.phone = phone; this.loginType = loginType; this.nickname = nickname; @@ -179,4 +185,23 @@ public void uploadImage(Image image){ public void setSurvey(Survey survey) { this.survey = survey; } + + public void addCommunity(Community community) { + if (community == null) return; + community.changeMember(this); + } + + public void addReply(CommunityReply reply) { + this.communityReplies.add(reply); + if (reply.getMember() != this) { + reply.setMember(this); + } + } + + public void addReplyLike(CommunityReplyLike like) { + this.replyLikes.add(like); + if (like.getMember() != this) { + like.setMember(this); + } + } } \ No newline at end of file diff --git a/src/main/java/com/arom/with_travel/domain/member/dto/request/MemberSignupRequestDto.java b/src/main/java/com/arom/with_travel/domain/member/dto/request/MemberSignupRequestDto.java index 7bb8271..b7598c0 100644 --- a/src/main/java/com/arom/with_travel/domain/member/dto/request/MemberSignupRequestDto.java +++ b/src/main/java/com/arom/with_travel/domain/member/dto/request/MemberSignupRequestDto.java @@ -3,9 +3,7 @@ import com.arom.with_travel.domain.member.Member.Gender; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.*; import lombok.Getter; import lombok.Setter; @@ -32,4 +30,23 @@ public class MemberSignupRequestDto { @NotEmpty(message = "자기소개란을 작성해주세요") @Schema(description = "짧은 자기소개", example = "안녕하세요") private String introduction; + + @NotBlank(message = "이메일을 입력해주세요.") + @Email(message = "올바른 이메일 형식이 아닙니다.") + @Schema(description = "로그인용 이메일", example = "pikachu@example.com") + private String email; + + @NotBlank(message = "비밀번호를 입력해주세요.") + @Size(min = 8, max = 64, message = "비밀번호는 8~64자여야 합니다.") + @Schema(description = "로그인 비밀번호(서버에서 해시 저장)", example = "pika1234!") + private String password; + + @NotBlank(message = "이름(실명)을 입력해주세요.") + @Schema(description = "이름(실명)", example = "한지우") + private String name; + + @NotBlank(message = "전화번호를 입력해주세요.") + @Pattern(regexp = "^[0-9\\-]{8,15}$", message = "전화번호 형식이 올바르지 않습니다.") + @Schema(description = "전화번호", example = "010-1234-5678") + private String phone; }