Skip to content

Commit

Permalink
Merge pull request #202 from prgrms-web-devcourse-final-project/develop
Browse files Browse the repository at this point in the history
qovh
  • Loading branch information
Dom1046 authored Dec 6, 2024
2 parents 8ae05c3 + b955a73 commit 8615021
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mallangs.domain.member.dto.*;
import com.mallangs.domain.member.dto.request.LoginRequest;
import com.mallangs.domain.member.dto.response.MemberGetByOtherResponse;
import com.mallangs.domain.member.entity.Member;
import com.mallangs.domain.member.entity.MemberRole;
import com.mallangs.domain.member.entity.embadded.UserId;
Expand Down Expand Up @@ -91,6 +92,16 @@ public ResponseEntity<MemberGetResponse> get(Authentication authentication) {
String userId = authentication.getName();
return ResponseEntity.status(HttpStatus.CREATED).body(memberUserService.get(userId));
}
@GetMapping("/other/{userId}")
@Operation(summary = "(타인)회원 프로필 조회", description = "(타인)회원 프로필 조회 요청 API")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "회원 조회 성공"),
@ApiResponse(responseCode = "404", description = "회원을 찾을 수 없습니다."),
@ApiResponse(responseCode = "406", description = "차단된 계정입니다.")
})
public ResponseEntity<MemberGetByOtherResponse> getByOther(@PathVariable("userId") String userId) {
return ResponseEntity.status(HttpStatus.CREATED).body(memberUserService.getByOther(userId));
}

@PutMapping("/{memberId}")
@PreAuthorize("hasRole('USER') or hasRole('ADMIN')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,21 @@
@ToString
public class MemberAddressRequest {
// 주소
@NotNull(message = "주소 이름은 필수입니다.")
private String addressName;
@NotNull(message = "주소 유형은 필수입니다.")
private String addressType;
@NotNull(message = "시는 필수입니다.")
private String region1depthName;
@NotNull(message = "군은 필수입니다.")
private String region2depthName;
@NotNull(message = "읍/면/리는 필수입니다.")
private String region3depthName;
@NotNull(message = "행정이름은 필수입니다.")
private String region3depthHName;
@NotNull(message = "주소 번호는 필수입니다.")
private String mainAddressNo;
@NotNull(message = "보조 주소 번호는 필수입니다.")
private String subAddressNo;
@NotNull(message = "도로명은 필수입니다.")
private String roadName;
@NotNull(message = "주 건물번호는 필수입니다.")
private String mainBuildingNo;
@NotNull(message = "보조 건물번호는 필수입니다.")
private String subBuildingNo;
@NotNull(message = "건물명은 필수입니다.")
private String buildingName;
@NotNull(message = "우편번호는 필수입니다.")
private String zoneNo;
@NotNull(message = "산악지역은 필수입력 값 입니다.")
private String mountainYn;
@NotNull(message = "경도는 필수입니다.")
private Double longitude;
@NotNull(message = "위도는 필수입니다.")
private Double latitude; //y


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class MemberUpdateRequest {
private String nickname;
@Pattern(regexp = Email.REGEX, message = Email.ERR_MSG)
private String email;
@Pattern(regexp = "([^\\s]+(\\.(?i)(jpg|jpeg|png|gif|bmp|tiff|webp|svg|ico|heic|heif|avif))$)",
message = "유효한 이미지 파일을 업로드해주세요. (jpg, jpeg, png, gif, bmp, tiff, webp, svg, ico, heic, heif, avif)")
private String profileImage;
@Pattern(regexp = Password.REGEX, message = Password.ERR_MSG)
private String password;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mallangs.domain.member.dto.response;

import com.mallangs.domain.member.entity.Member;
import com.mallangs.domain.pet.dto.PetMemberProfileResponse;
import lombok.Getter;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@ToString
public class MemberGetByOtherResponse {

private Long memberId;
private String userId;
private String nickname;
private String email;
private String profileImage;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private List<PetMemberProfileResponse> pets;

public MemberGetByOtherResponse(Member member) {
this.memberId = member.getMemberId();
this.userId = member.getUserId().getValue();
this.nickname = member.getNickname().getValue();
this.email = member.getEmail().getValue();
this.profileImage = member.getProfileImage();
this.createdAt = member.getCreatedAt();
this.updatedAt = member.getUpdatedAt();

if (!member.getPets().isEmpty()) {
this.pets = member.getPets().stream()
.map(PetMemberProfileResponse::new)
.collect(Collectors.toList());
} else {
this.pets = new ArrayList<>();
}

}
}
3 changes: 1 addition & 2 deletions src/main/java/com/mallangs/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ public Member(String userId, String nickname, Password password, String email, S
}

//수정
public void change(String nickname,String password, String email, String profileImage, PasswordEncoder passwordEncoder){
public void change(String nickname,String password, String email, PasswordEncoder passwordEncoder){
this.nickname = new Nickname(nickname);
this.password = new Password(password, passwordEncoder);
this.email = new Email(email);
this.profileImage = profileImage;
}

public void changeIsActive(Boolean isActive){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByPassword(@Param("password")String password);

//단일 회원조회 - 아이디
@Query("SELECT m FROM Member m join fetch m.addresses WHERE m.memberId =:memberId")
@Query("SELECT m FROM Member m LEFT join fetch m.addresses WHERE m.memberId =:memberId")
Optional<Member> findByMemberId(@Param("memberId") Long memberId);

//단일 회원조회 - 이메일
@Query("SELECT m FROM Member m join fetch m.addresses WHERE m.email =:email")
@Query("SELECT m FROM Member m LEFT join fetch m.addresses WHERE m.email =:email")
Optional<Member> findByEmail(@Param("email") Email email);

//단일 회원조회 - 유저아이디
@Query(" SELECT m FROM Member m JOIN FETCH m.addresses " +
@Query(" SELECT m FROM Member m LEFT JOIN FETCH m.addresses " +
" WHERE m.userId =:userId ")
Optional<Member> findByUserId(@Param("userId") UserId userId);

Expand All @@ -52,12 +52,12 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByUserIdForProfile(@Param("userId") UserId userId);

//단일 회원조회 - 아이디 찾기
@Query("SELECT m FROM Member m join fetch m.addresses " +
@Query("SELECT m FROM Member m LEFT join fetch m.addresses " +
"WHERE m.email =:email AND m.nickname =:nickname")
Optional<Member> findByEmailAndNickname(@Param("email") Email email, @Param("nickname") Nickname nickname);

//단일 회원조회 - 비밀번호 찾기
@Query("SELECT m FROM Member m join fetch m.addresses " +
@Query("SELECT m FROM Member m left join fetch m.addresses " +
"WHERE m.email =:email AND m.userId =:userId")
Optional<Member> findByEmailAndUserId(@Param("email") Email email, @Param("userId") UserId userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public AddressCreateSuccessResponse create(String userId, MemberAddressRequest m
return new AddressCreateSuccessResponse(foundMember.getUserId().getValue());
} catch (Exception e) {
log.error("주소 추가에 실패하였습니다. {}", e.getMessage());
throw new MallangsCustomException(ErrorCode.FAILURE_REQUEST);
throw new MallangsCustomException(ErrorCode.FAILURE);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mallangs.domain.member.service;

import com.mallangs.domain.member.dto.*;
import com.mallangs.domain.member.dto.response.MemberGetByOtherResponse;
import com.mallangs.domain.member.entity.Address;
import com.mallangs.domain.member.entity.Member;
import com.mallangs.domain.member.entity.embadded.Email;
Expand Down Expand Up @@ -77,6 +78,18 @@ public MemberGetResponse get(String userId) {
return new MemberGetResponse(foundMember);
}

//회원조회(타인)
public MemberGetByOtherResponse getByOther(String userId) {
Member foundMember = memberRepository.findByUserIdForProfile(new UserId(userId))
.orElseThrow(() -> new MallangsCustomException(ErrorCode.MEMBER_NOT_FOUND));

if (foundMember.getIsActive().equals(false)) {
throw new MallangsCustomException(ErrorCode.BANNED_MEMBER);
}

return new MemberGetByOtherResponse(foundMember);
}

//회원정보 수정
public MemberGetResponse update(MemberUpdateRequest memberUpdateRequest, Long memberId) {
Member foundMember = memberRepository.findById(memberId)
Expand All @@ -89,7 +102,6 @@ public MemberGetResponse update(MemberUpdateRequest memberUpdateRequest, Long me
memberUpdateRequest.getNickname(),
memberUpdateRequest.getPassword(),
memberUpdateRequest.getEmail(),
memberUpdateRequest.getProfileImage(),
passwordEncoder
);
Member save = memberRepository.save(foundMember);
Expand Down Expand Up @@ -137,14 +149,15 @@ public MemberCheckPasswordResponse checkPassword(PasswordDTO passwordDTO, String

//회원 비밀번호 찾기 -> 임시비밀번호 변경, 메일 메세지 생성
public MemberSendMailResponse findPassword(MemberFindPasswordRequest memberFindPasswordRequest) {
try {
Email email = new Email(memberFindPasswordRequest.getEmail());
UserId userId = new UserId(memberFindPasswordRequest.getUserId());

//입력된 정보로 회원 확인
Member foundMember = memberRepository.findByEmailAndUserId(email, userId)
.orElseThrow(() -> new MallangsCustomException(ErrorCode.MEMBER_NOT_FOUND));

try {
log.info("회우너정보{}",foundMember);
//임시비밀번호 만들기
String tempPassword = PasswordGenerator.generatePassword();

Expand All @@ -156,7 +169,7 @@ public MemberSendMailResponse findPassword(MemberFindPasswordRequest memberFindP
return writeMessage(email.getValue(), tempPassword);
} catch (Exception e) {
log.error("회원 비밀번호 찾기에 실패하였습니다. {}", e.getMessage());
throw new MallangsCustomException(ErrorCode.FAILURE_REQUEST);
throw new MallangsCustomException(ErrorCode.DATABASE_ERROR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
.requestMatchers("/api/v1/member/**").permitAll() //회원
.requestMatchers("/api/v1/address/**").permitAll() //주소
.requestMatchers("/api/v1/pets/**").permitAll() //반려동물
.requestMatchers("/api/v1/image/**").permitAll() //이미지
.requestMatchers("/api/v1/chat-room/**").permitAll() //채팅방
.requestMatchers("/api/v1/chat/**").permitAll() //채팅
.requestMatchers("/api/chat/**").permitAll() //채팅
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mallangs/global/jwt/filter/JWTFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
String method = request.getMethod();
//패턴 매처
AntPathMatcher pathMatcher = new AntPathMatcher();
//PathVariable 주소
String path = request.getServletPath();

Map<String, String> patternVariableMap = new HashMap<>();
patternVariableMap.put("/api/v1/board/community/category/{categoryId}", "categoryId");
Expand Down Expand Up @@ -113,6 +115,9 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
//TOKEN
("POST".equals(method) && uri.startsWith("/api/v1/token")) ||

//회원
uri.contains("/api/v1/member/other/") ||

//반려동물
("GET".equals(method) && uri.startsWith("/api/v1/pets/nearby"))) {
filterChain.doFilter(request, response);
Expand Down

0 comments on commit 8615021

Please sign in to comment.