Skip to content

Commit

Permalink
Merge pull request #23 from Journey-Together/feature/#15
Browse files Browse the repository at this point in the history
Feature/#15
  • Loading branch information
sycuuui authored Jun 3, 2024
2 parents e495f66 + 7c40fe6 commit a459bfa
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Journey.Together.domain.member.controller;

import Journey.Together.domain.member.dto.InterestDto;
import Journey.Together.domain.member.dto.MemberReq;
import Journey.Together.domain.member.dto.MemberRes;
import Journey.Together.domain.member.service.MemberService;
Expand Down Expand Up @@ -29,4 +30,16 @@ public ApiResponse<MemberRes> findMemberInfo(@AuthenticationPrincipal PrincipalD
MemberRes memberRes = memberService.findMemberInfo(principalDetails.getMember());
return ApiResponse.success(Success.GET_MYPAGE_SUCCESS,memberRes);
}

@PatchMapping("/interest-type")
public ApiResponse updateInterestType(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestBody InterestDto interestDto) {
memberService.updateMemberInterest(principalDetails.getMember(),interestDto);
return ApiResponse.success(Success.UPDATE_USER_INFO_SUCCESS);
}

@GetMapping("/interest-type")
public ApiResponse<InterestDto> findInterestType(@AuthenticationPrincipal PrincipalDetails principalDetails) {
InterestDto interestDto = memberService.findMemberInterest(principalDetails.getMember());
return ApiResponse.success(Success.GET_USER_INTEREST_SUCCESS,interestDto);
}
}
30 changes: 30 additions & 0 deletions src/main/java/Journey/Together/domain/member/dto/InterestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Journey.Together.domain.member.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.validation.constraints.Null;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public record InterestDto (
Boolean isPysical,
Boolean isHear,
Boolean isVisual,
Boolean isElderly,
Boolean isChild
){
public static InterestDto of( Boolean isPysical,
Boolean isHear,
Boolean isVisual,
Boolean isElderly,
Boolean isChild){
return InterestDto.builder()
.isPysical(isPysical)
.isHear(isHear)
.isChild(isChild)
.isElderly(isElderly)
.isVisual(isVisual)
.build();
}

}
56 changes: 56 additions & 0 deletions src/main/java/Journey/Together/domain/member/entity/Interest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package Journey.Together.domain.member.entity;

import Journey.Together.domain.member.dto.InterestDto;
import Journey.Together.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;

@Setter
@Getter
@Entity
@Table(name = "interest")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Interest extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "interest_id", columnDefinition = "bigint")
private Long interestId;

@ManyToOne(targetEntity = Member.class, fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@Column(name = "pysical")
private Boolean isPysical;

@Column(name = "hear")
private Boolean isHear;

@Column(name = "visual")
private Boolean isVisual;

@Column(name = "child")
private Boolean isChild;

@Column(name = "elderly")
private Boolean isElderly;

public void update(InterestDto interestDto) {
this.isPysical=interestDto.isPysical();
this.isHear=interestDto.isHear();
this.isVisual=interestDto.isVisual();
this.isChild=interestDto.isChild();
this.isElderly = interestDto.isElderly();
}

@Builder
public Interest(Member member, Boolean isPysical, Boolean isHear, Boolean isVisual, Boolean isElderly, Boolean isChild){
this.member = member;
this.isPysical=isPysical;
this.isHear=isHear;
this.isVisual=isVisual;
this.isChild=isChild;
this.isElderly = isElderly;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Journey.Together.domain.member.repository;

import Journey.Together.domain.member.entity.Interest;
import Journey.Together.domain.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface InterestRepository extends JpaRepository<Interest,Long> {
Interest findByMemberAndDeletedAtIsNull(Member member);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import Journey.Together.domain.member.dto.LoginReq;
import Journey.Together.domain.member.dto.LoginRes;
import Journey.Together.domain.member.entity.Interest;
import Journey.Together.domain.member.entity.Member;
import Journey.Together.domain.member.enumerate.LoginType;
import Journey.Together.domain.member.enumerate.MemberType;
import Journey.Together.domain.member.repository.InterestRepository;
import Journey.Together.domain.member.repository.MemberRepository;
import Journey.Together.global.common.CustomMultipartFile;
import Journey.Together.global.exception.ApplicationException;
Expand Down Expand Up @@ -40,6 +42,7 @@ public class AuthService {
private final KakaoClient kakaoClient;
private final TokenProvider tokenProvider;
private final MemberRepository memberRepository;
private final InterestRepository interestRepository;
private final S3Client s3Client;

private final RestTemplate restTemplate = new RestTemplate();
Expand Down Expand Up @@ -68,6 +71,15 @@ public LoginRes signIn(String token, LoginReq loginReq) throws IOException {
.loginType(LoginType.valueOf("KAKAO"))
.build();
member = memberRepository.save(newMember);
Interest interest = Interest.builder()
.member(member)
.isHear(false)
.isChild(false)
.isPysical(false)
.isVisual(false)
.isElderly(false)
.build();
interestRepository.save(interest);
}
tokenDto = tokenProvider.createToken(member);
member.setRefreshToken(tokenDto.refreshToken());
Expand All @@ -92,6 +104,15 @@ public LoginRes signIn(String token, LoginReq loginReq) throws IOException {
.build();

member = memberRepository.save(newMember);
Interest interest = Interest.builder()
.member(member)
.isHear(false)
.isChild(false)
.isPysical(false)
.isVisual(false)
.isElderly(false)
.build();
interestRepository.save(interest);
}

tokenDto = tokenProvider.createToken(member);
Expand Down Expand Up @@ -132,7 +153,7 @@ public void withdrawal(Member member) {

// Response
}

@Transactional
public TokenDto reissue(String token, Member member) {
System.out.println(token);
// Validation - RefreshToken 유효성 검증
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package Journey.Together.domain.member.service;

import Journey.Together.domain.member.dto.InterestDto;
import Journey.Together.domain.member.dto.MemberReq;
import Journey.Together.domain.member.dto.MemberRes;
import Journey.Together.domain.member.entity.Interest;
import Journey.Together.domain.member.entity.Member;
import Journey.Together.domain.member.repository.InterestRepository;
import Journey.Together.domain.member.repository.MemberRepository;
import Journey.Together.global.exception.ApplicationException;
import Journey.Together.global.exception.ErrorCode;
import Journey.Together.global.util.S3Client;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class MemberService {

private final MemberRepository memberRepository;
private final InterestRepository interestRepository;
private final S3Client s3Client;

@Transactional
Expand Down Expand Up @@ -62,9 +65,9 @@ public void saveInfo(Member member,MemberReq memberReq){
if (memberReq.part2_phone() != null) {
member.setPart2Phone(memberReq.part2_phone());
}

memberRepository.save(member);
}

@Transactional
public MemberRes findMemberInfo(Member member){
// Validation
memberRepository.findMemberByEmailAndDeletedAtIsNull(member.getEmail()).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION));
Expand All @@ -73,5 +76,29 @@ public MemberRes findMemberInfo(Member member){
//Response
return memberRes;
}
@Transactional
public void updateMemberInterest(Member member, InterestDto interestDto){
// Validation
memberRepository.findMemberByEmailAndDeletedAtIsNull(member.getEmail()).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION));
Interest interest = interestRepository.findByMemberAndDeletedAtIsNull(member);
//Business
interest.update(interestDto);
}
@Transactional
public InterestDto findMemberInterest(Member member){
// Validation
memberRepository.findMemberByEmailAndDeletedAtIsNull(member.getEmail()).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION));
Interest interest = interestRepository.findByMemberAndDeletedAtIsNull(member);
//Business
InterestDto interestDto = InterestDto.of(
interest.getIsPysical(),
interest.getIsHear(),
interest.getIsVisual(),
interest.getIsElderly(),
interest.getIsChild()
);
//Response
return interestDto;
}

}
2 changes: 2 additions & 0 deletions src/main/java/Journey/Together/global/exception/Success.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public enum Success {
/**
* 200 OK
*/

GET_USER_INTEREST_SUCCESS(HttpStatus.OK, "사용자 관심 유형 정보 조회 성공"),
GET_MAIN_SUCCESS(HttpStatus.OK, "메인 페이지 정보 조회 성공"),
GET_PLACE_DETAIL_SUCCESS(HttpStatus.OK, "여행지 상세정보 조회 성공"),
GET_MYPAGE_SUCCESS(HttpStatus.OK, "마이 페이지 조회 성공"),
Expand Down

0 comments on commit a459bfa

Please sign in to comment.