Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/main/java/com/arom/with_travel/domain/community/Community.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommunityReply> communityReplies = new ArrayList<>();

@OneToMany(mappedBy = "community")
Expand All @@ -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;
Comment on lines +84 to +88
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing null checks in the update method could lead to unintended data loss if null values are passed. Consider either restoring the null checks or documenting that all parameters must be non-null, and add validation at the service layer.

Copilot uses AI. Check for mistakes.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated variable is assigned but never used. Either remove this variable or add validation to ensure the update was successful (e.g., if (updated == 0) throw exception).

Suggested change
int updated = communityRepository.increaseViewCount(id);
int updated = communityRepository.increaseViewCount(id);
if (updated == 0) {
throw BaseException.from(ErrorCode.COMMUNITY_NOT_FOUND);
}

Copilot uses AI. Check for mistakes.

Community c = communityRepository.findDetailById(id);
if (c == null) throw BaseException.from(ErrorCode.COMMUNITY_NOT_FOUND);
List<String> urls = c.getImages().stream().map(Image::getImageUrl).collect(Collectors.toList());
if (c == null) { throw BaseException.from(ErrorCode.COMMUNITY_NOT_FOUND);}

List<String> urls = c.getImages().stream().map(Image::getImageUrl).toList();

return new CommunityDetailResponse(
c.getId(), c.getTitle(), c.getContent(),
c.getContinent(), c.getCountry(), c.getCity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CommunityReplyLike> likes = new ArrayList<>();

public static CommunityReply create(Community community, Member writer, String content) {
return CommunityReply.builder()
.community(community)
Expand All @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.*;

@Getter
@Setter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/com/arom/with_travel/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +39,7 @@
private String oauthId;

private String email;
@Column(length = 255) private String password;
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing passwords as plain text is a security vulnerability. The password field should be annotated to indicate it will store hashed values, and the application should ensure passwords are properly hashed before storage.

Copilot uses AI. Check for mistakes.

private LocalDate birth;
@Enumerated(EnumType.STRING) private Gender gender;
Expand Down Expand Up @@ -105,6 +107,9 @@
@OneToMany(mappedBy = "member")
private List<Community> communities = new ArrayList<>();

@OneToMany(mappedBy = "member", orphanRemoval = true)
private List<CommunityReplyLike> replyLikes = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<CommunityReply> communityReplies = new ArrayList<>();

Expand All @@ -125,15 +130,16 @@
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,

Check warning on line 133 in src/main/java/com/arom/with_travel/domain/member/Member.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/java/com/arom/with_travel/domain/member/Member.java#L133

Avoid long parameter lists.

Check warning on line 133 in src/main/java/com/arom/with_travel/domain/member/Member.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/java/com/arom/with_travel/domain/member/Member.java#L133

Method LoginType::Member has 13 parameters (limit is 8)
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;
Expand Down Expand Up @@ -179,4 +185,23 @@
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 = "전화번호 형식이 올바르지 않습니다.")
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phone number regex pattern ^[0-9\\-]{8,15}$ is too restrictive and may not accommodate international phone number formats. Consider using a more flexible pattern that supports parentheses, spaces, and plus signs for international numbers.

Suggested change
@Pattern(regexp = "^[0-9\\-]{8,15}$", message = "전화번호 형식이 올바르지 않습니다.")
@Pattern(regexp = "^\\+?[0-9\\-\\s\\(\\)]{8,20}$", message = "전화번호 형식이 올바르지 않습니다.")

Copilot uses AI. Check for mistakes.
@Schema(description = "전화번호", example = "010-1234-5678")
private String phone;
}