Skip to content

Commit

Permalink
Merge pull request #15 from With-Mate/fix/journey/sh
Browse files Browse the repository at this point in the history
Relation 생성 시에 Journey, Week도 생성
  • Loading branch information
seohyun-lee authored Feb 15, 2024
2 parents 828d27c + c4bdb05 commit 8f4aabc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -56,28 +57,32 @@ public String memberSignUp(SignUpReqDto signUpReqDto) { //회원가입
@Transactional
public String memberLogin(LoginReqDto loginRequestDto) { // 기본 로그인
// 사용자가 입력한 아이디, 비밀번호
log.info("아이디 비번 get");
String userName = loginRequestDto.getUserName();
String password = loginRequestDto.getPasswd();
log.info("토큰");
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userName, password);
// 사용자 인증
log.info("사용자 인증 진행");
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
// 사용자 인증이 완료된 경우
if (authentication.isAuthenticated()) {
log.info("사용자 인증 완료");
/* 사용자가 인증되면 AuthDetails 객체가 생성되어 Authentication 객체에 포함되고,
* 이 AuthDetails 객체를 통해서 인증된 사용자의 정보를 확인 가능 */
AuthDetails authDetails = (AuthDetails) authentication.getPrincipal();
Member member = authDetails.getMember();
Long authenticatedId = member.getId();
String authenticatedUserName = member.getUserName();
// 로그인 시간 업데이트
memberRepository.save(member.updateLoginDate());
// JWT 토큰 반환
log.info("JWT 토큰 반환");
return jwtTokenProvider.generateJwtToken(authenticatedId, authenticatedUserName);
try {
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
// 사용자 인증이 완료된 경우
if (authentication.isAuthenticated()) {
log.info("사용자 인증 완료");
/* 사용자가 인증되면 AuthDetails 객체가 생성되어 Authentication 객체에 포함되고,
* 이 AuthDetails 객체를 통해서 인증된 사용자의 정보를 확인 가능 */
AuthDetails authDetails = (AuthDetails) authentication.getPrincipal();
Member member = authDetails.getMember();
Long authenticatedId = member.getId();
String authenticatedUserName = member.getUserName();
// 로그인 시간 업데이트
memberRepository.save(member.updateLoginDate());
// JWT 토큰 반환
log.info("JWT 토큰 반환");
return jwtTokenProvider.generateJwtToken(authenticatedId, authenticatedUserName);
}
} catch(AuthenticationException e){
// 인증 실패 시 예외 처리
log.error("사용자 인증 실패: {}", e.getMessage());
return null;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.gdscewha.withmate.common.response.exception.CategoryException;
import com.gdscewha.withmate.common.response.exception.ErrorCode;
import com.gdscewha.withmate.common.response.exception.MatchingException;
import com.gdscewha.withmate.domain.journey.entity.Journey;
import com.gdscewha.withmate.domain.journey.service.JourneyService;
import com.gdscewha.withmate.domain.matching.dto.MatchedResultDto;
import com.gdscewha.withmate.domain.matching.dto.MatchingInputDto;
import com.gdscewha.withmate.domain.matching.dto.MatchingResDto;
Expand All @@ -15,6 +17,9 @@
import com.gdscewha.withmate.domain.model.Category;
import com.gdscewha.withmate.domain.relation.entity.Relation;
import com.gdscewha.withmate.domain.relation.service.RelationMateService;
import com.gdscewha.withmate.domain.sticker.service.StickerService;
import com.gdscewha.withmate.domain.week.entity.Week;
import com.gdscewha.withmate.domain.week.service.WeekService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -33,6 +38,10 @@ public class MatchingService {
private final MemberService memberService;
private final MemberRelationService memberRelationService;
private final RelationMateService relationMateService;
// Relation 만들 때 필요한 Service들
private final JourneyService journeyService;
private final WeekService weekService;
private final StickerService stickerService;


// 내 매칭 받아오기 (MatchingResDto 반환, 존재하지 않으면 null 반환)
Expand Down Expand Up @@ -154,16 +163,19 @@ public List<Matching> relateMatesByCategory(Category category, Matching myMatchi
memberList.add(me);

// Relation 생성, MemberRelationPair 생성
Relation pairRelation = relationMateService.createRelation();
memberRelationService.createMemberRelationPair(mateList, memberList, pairRelation);
// Matching 삭제
//matchingRepository.deleteAll(matchingList);
Relation relation = relationMateService.createRelation();
memberRelationService.createMemberRelationPair(mateList, memberList, relation);

// 첫번째 Journey 생성
Journey journey = journeyService.createJourney(relation);
// 첫번째 Week 생성
Week week = weekService.createWeek();

// Member들의 isRelationed를 true로 업데이트 후 저장
mate.setIsRelationed(true);
me.setIsRelationed(true);

// 각 멤버에 Matching null로
// 각 멤버에 Matching null로, Matching 삭제
memberRepository.save(deleteMatching(mate));
memberRepository.save(deleteMatching(me));
// 수정된 Matching 리스트 반환
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public RelationManageDto getRelationManageInfo() {

return RelationManageDto.builder()
.startDate(relation.getStartDate().toString())
.proceedingTime(daysDifference)
.proceedingTime(daysDifference + 1) // 차이에서 하루를 더한 날짜
.myMessage(myMR.getMessage())
.mateName(mateMR.getMember().getNickname())
.mateCategory(mateMR.getCategory().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Sticker createSticker(StickerCreateDTO stickerCreateDTO) {
Member member = memberService.getCurrentMember();
Week currentWeek = weekService.updateStickerCountOfCurrentWeek(1L);
Sticker sticker = Sticker.builder()
.stickerNum(currentWeek.getStickerCount() + 1)
.stickerNum(currentWeek.getStickerCount() + 1) // 처음에 1L
.title(stickerCreateDTO.getTitle())
.creationTime(LocalDate.now())
.stickerColor(stickerCreateDTO.getStickerColor())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Week createWeek() {
if (journey == null)
throw new WeekException(ErrorCode.JOURNEY_NOT_FOUND);
Week week = Week.builder()
.weekNum(journey.getWeekCount() + 1) // 처음에 1L
.weekNum(journey.getWeekCount()) // 처음에 1L (위에서 업데이트)
.weekStartDate(LocalDate.now())
.stickerCount(0L) // 처음에 0L
.journey(journey)
Expand Down

0 comments on commit 8f4aabc

Please sign in to comment.