Skip to content

Commit

Permalink
Merge pull request #21 from goormthon-Univ/dev
Browse files Browse the repository at this point in the history
[Feat] 송금정보 조회 컨트롤러 구현
  • Loading branch information
namkikim0718 authored Mar 23, 2024
2 parents b32afb6 + 12ad0d3 commit 24a965d
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 56 deletions.
5 changes: 1 addition & 4 deletions src/main/java/com/groom/wisebab/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
import com.groom.wisebab.jwt.JWTFilter;
import com.groom.wisebab.jwt.JWTUtil;
import com.groom.wisebab.jwt.LoginFilter;
import com.groom.wisebab.service.MemberService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.SecurityBuilder;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/groom/wisebab/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.groom.wisebab.dto.email.EmailCertifyDTO;
import com.groom.wisebab.dto.member.MemberResponseDTO;
import com.groom.wisebab.dto.member.SignUpDTO;
import com.groom.wisebab.jwt.JWTUtil;
import com.groom.wisebab.service.MemberService;
import com.univcert.api.UnivCert;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,6 +26,7 @@ public class MemberController {

private final MemberService memberService;
private final String UnivCertKEY = "48ad7af1-31bc-4c1f-ad01-f06001a618da";
private final JWTUtil jwtUtil;

@PostMapping("/signup")
public Long signUp(SignUpDTO signUpDTO) {
Expand All @@ -47,12 +49,22 @@ public ResponseEntity<MemberResponseDTO> findMemberById(@PathVariable Long membe
return ResponseEntity.ok(memberResponseDTO);
}

@GetMapping("/members/{memberUsername}")
public ResponseEntity<MemberResponseDTO> findMemberByUsername(@PathVariable String memberUsername) {
Member member = memberService.findMemberByUsername(memberUsername);
MemberResponseDTO memberResponseDTO = new MemberResponseDTO(member.getId(), member.getUsername(), member.getNickname());

return ResponseEntity.ok(memberResponseDTO);
}


// UnivCert API를 통해 가입하려는 회원의 대학교 이메일로 인증 코드 전송
@PostMapping("/verification")
public Map<String, Object> emailVerification(@RequestBody EmailCertifyDTO emailCertifyDTO) throws IOException {
return UnivCert.certify(UnivCertKEY, emailCertifyDTO.getEmail(), emailCertifyDTO.getUnivName(), true);
}

// 이메일로 보낸 인증코드와 사용자가 입력한 코드가 일치하는지 검증
@PostMapping("/verificationCode")
public Map<String, Object> emailCodeVerification(@RequestBody EmailCertifyCodeDTO emailCertifyCodeDTO) throws IOException {
return UnivCert.certifyCode(UnivCertKEY, emailCertifyCodeDTO.getEmail(), emailCertifyCodeDTO.getUnivName(), emailCertifyCodeDTO.getCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequiredArgsConstructor
Expand All @@ -24,6 +23,7 @@ public class PreferTimetableController {
private final MemberService memberService;
private final PromiseService promiseService;

// 약속 선호 시간 생성
@PostMapping("/promises/{promiseId}/members/{memberId}")
public Long createPreferTimetable(@PathVariable Long promiseId, @PathVariable Long memberId, @RequestBody List<PreferTimetableDTO> preferTimetableDTOS) {
Promise promise = promiseService.findPromiseById(promiseId)
Expand All @@ -38,6 +38,7 @@ public Long createPreferTimetable(@PathVariable Long promiseId, @PathVariable Lo
return preferTimetableService.createPreferTimetable(promise, member, preferTimetableDTOS);
}

// 약속에서 해당 회원이 제출한 선호 시간표 조회
@GetMapping("/promises/{promiseId}/members/{memberId}")
public ResponseEntity<List<PreferTimetableDTO>> findTimetableByPromiseAndMember(@PathVariable Long promiseId, @PathVariable Long memberId) {
log.info("컨트롤러 진입");
Expand All @@ -52,7 +53,7 @@ public ResponseEntity<List<PreferTimetableDTO>> findTimetableByPromiseAndMember(
);
log.info("회원 조회 완료");
List<PreferTimetableDTO> preferTimetableDTOS = preferTimetableService.findTimetableByPromiseAndMember(promise, member);
log.info("리턴 직전");
log.info("DTO에 담기 성공");
return ResponseEntity.ok(preferTimetableDTOS);
}
}
14 changes: 12 additions & 2 deletions src/main/java/com/groom/wisebab/controller/PromiseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import com.groom.wisebab.service.PromiseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.Response;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@RestController
Expand Down Expand Up @@ -56,16 +54,19 @@ public ResponseEntity<List<PromiseListResponseDTO>> findAllPromiseByMemberAndSta
return ResponseEntity.ok(promiseListResponseDTOList);
}

// 대기중인 약속 -> 확정된 약속
@PatchMapping("/promises/{promiseId}/confirmation")
public Long updateToConfirmed(@PathVariable Long promiseId, @RequestBody UpdateToConfirmedDTO updateToConfirmedDTO) {
return promiseService.changeStatusToConfirmed(promiseId, updateToConfirmedDTO);
}

// 확정된 약속 -> 만료된 약속
@PatchMapping("/promises/{promiseId}/termination")
public Long updateToExpired(@PathVariable Long promiseId, @RequestBody UpdateToExpiredDTO updateToExpiredDTO) {
return promiseService.changeStatusToExpired(promiseId, updateToExpiredDTO);
}

// 약속의 초대 링크 조회
@GetMapping("/promises/{promiseId}/link")
public ResponseEntity<PromiseLinkDTO> getPromiseLink(@PathVariable Long promiseId) {
Promise promise = promiseService.findPromiseById(promiseId)
Expand All @@ -79,6 +80,7 @@ public ResponseEntity<PromiseLinkDTO> getPromiseLink(@PathVariable Long promiseI
return ResponseEntity.ok(promiseLinkDTO);
}

// uuid로 이루어진 초대링크를 접속하면 그 회원을 약속 파티원으로 추가
@PostMapping("/members/{memberId}/promises/{uuid}")
public Long memberParticipation(@PathVariable Long memberId, @PathVariable UUID uuid) {
Member member = memberService.findMemberById(memberId)
Expand All @@ -88,4 +90,12 @@ public Long memberParticipation(@PathVariable Long memberId, @PathVariable UUID
return promiseService.memberParticipation(member, uuid);
}

// 약속의 송금 정보 조회
@GetMapping("/promises/{promiseId}/payment")
public ResponseEntity<PromisePaymentResponseDTO> getPaymentInfo(@PathVariable Long promiseId) {
PromisePaymentResponseDTO promisePaymentResponseDTO = promiseService.getPaymentInfo(promiseId);

return ResponseEntity.ok(promisePaymentResponseDTO);
}

}
6 changes: 0 additions & 6 deletions src/main/java/com/groom/wisebab/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public class Member {
//member이 연관관계 주인
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<PromiseMember> promises = new ArrayList<>();
/*
//member이 연관관계 주인
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Promise> ownerPromises = new ArrayList<>();
*/

public Member(String username, String password, String nickname, String role) {
this.username = username;
Expand Down
22 changes: 9 additions & 13 deletions src/main/java/com/groom/wisebab/domain/Promise.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ public class Promise {
private Long id;

private String title;
/*
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member owner;
*/

private Long ownerId;

//promise가 연관관계 주인
Expand All @@ -38,13 +34,6 @@ public class Promise {

private String locAddress;

/*
//컬렉션 객체로 저장
@ElementCollection
@CollectionTable(name = "confirmed_time", joinColumns = @JoinColumn(name = "promise_id"))
private List<Integer> confirmedTime = new ArrayList<>();
*/

private LocalDate confirmedDate;

private String confirmedTime;
Expand All @@ -57,29 +46,36 @@ public class Promise {

private LocalDate startDate;

private LocalDate endDate;

private String memo;

@Column(columnDefinition = "BINARY(16)")
private UUID uuid;

public Promise(String title, Long ownerId, String locName, String locAddress, LocalDate startDate, String memo) {
//생성자
public Promise(String title, Long ownerId, String locName, String locAddress, LocalDate startDate, LocalDate endDate, String memo) {
this.title = title;
this.ownerId = ownerId;
this.state = State.PENDING;
this.locName = locName;
this.locAddress = locAddress;
this.startDate = startDate;
this.endDate = endDate;
this.memo = memo;
this.uuid = UUID.randomUUID();
}

//대기중인 약속 -> 확정된 약속으로 변경하는 메서드
public void updateToConfirmed(LocalDate confirmedDate, String confirmedTime) {
this.state = State.CONFIRMED;
this.confirmedDate = confirmedDate;
this.confirmedTime = confirmedTime;
}

//확정된 약속 -> 만료된 약속으로 변경하는 메서드
public void updateToExpired(String bankAccount, String kakaopayLink, String payMemo) {
this.state = State.EXPIRED;
this.bankAccount = bankAccount;
this.kakaopayLink = kakaopayLink;
this.payMemo = payMemo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.groom.wisebab.dto.member;

import com.groom.wisebab.domain.Member;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
@AllArgsConstructor
public class MemberResponseDTO {

/**
* 멤버 정보 조회 DTO
*/

private Long id;

private String username;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/groom/wisebab/dto/promise/PromiseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public class PromiseDTO {

private LocalDate startDate;

private LocalDate endDate;

private String memo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.groom.wisebab.domain.State;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -38,6 +36,10 @@ public class PromiseDetailResponseDTO {

private String locAddress;

private LocalDate startDate;

private LocalDate endDate;

private String memo;

private List<PromiseMembersInnerResponseDTO> participants;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.groom.wisebab.dto.promise;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class PromisePaymentResponseDTO {

/**
* 송금 정보 조회
*/

private String payMemo;

private String kakaopayLink;

private String bankAccount;
}
10 changes: 4 additions & 6 deletions src/main/java/com/groom/wisebab/jwt/LoginFilter.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.groom.wisebab.jwt;

import com.groom.wisebab.domain.Member;
import com.groom.wisebab.dto.member.CustomUserDetails;
import com.groom.wisebab.service.MemberService;
import jakarta.servlet.FilterChain;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand All @@ -14,17 +17,12 @@
import java.util.Collection;
import java.util.Iterator;

@RequiredArgsConstructor
public class LoginFilter extends UsernamePasswordAuthenticationFilter {

private final AuthenticationManager authenticationManager;
private final JWTUtil jwtUtil;

public LoginFilter(AuthenticationManager authenticationManager, JWTUtil jwtUtil) {

this.authenticationManager = authenticationManager;
this.jwtUtil = jwtUtil;
}

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, Long> {
Member findByUsername(String username);
Optional<Member> findByUsername(String username);

Member findByNickname(String nickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class CustomUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

Member userData = memberRepository.findByUsername(username);
Member userData = memberRepository.findByUsername(username)
.orElseThrow(
NullPointerException::new
);

if (userData != null) {
return new CustomUserDetails(userData);
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/groom/wisebab/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,18 @@ public Long createMember(SignUpDTO signUpDTO) {
return member.getId();
}



public Member findMemberByUsername(String username) {
return memberRepository.findByUsername(username);
}

public Member findMemberByNickname(String nickname) {
return memberRepository.findByNickname(nickname);
}

public Optional<Member> findMemberById(Long id) {
return memberRepository.findById(id);
}

public MemberResponseDTO convertToDTO(Member member) {
return new MemberResponseDTO(member.getId(), member.getUsername(), member.getNickname());
}

public Member findMemberByUsername(String username) {
return memberRepository.findByUsername(username)
.orElseThrow(
NullPointerException::new
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PreferTimetableService {

private final PreferTimetableRepository preferTimetableRepository;

// 선호 시간표 제출 시 preferTimeTable 생성
@Transactional
public Long createPreferTimetable(Promise promise, Member member, List<PreferTimetableDTO> timetableDTOS) {
List<Integer> timetables = flatPreferTimetable(timetableDTOS);
Expand All @@ -31,6 +32,7 @@ public Long createPreferTimetable(Promise promise, Member member, List<PreferTim
return preferTimetable.getId();
}

// 약속에서 멤버별 선호시간을 반환
public List<PreferTimetableDTO> findTimetableByPromiseAndMember(Promise promise, Member member) {
PreferTimetable preferTimeTable = preferTimetableRepository.findPreferTimeTableByPromiseAndMember(promise, member);
return unflatPreferTimetable(promise.getStartDate(), preferTimeTable.getPreferTime());
Expand Down
Loading

0 comments on commit 24a965d

Please sign in to comment.