Skip to content

Commit

Permalink
Feature/change password #385
Browse files Browse the repository at this point in the history
  • Loading branch information
hocaron authored Dec 6, 2023
2 parents 23d36a6 + a0dc70e commit 667b2d1
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package kr.mashup.branding.service.member;

import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import kr.mashup.branding.domain.ResultCode;
import kr.mashup.branding.domain.exception.BadRequestException;
import kr.mashup.branding.domain.exception.GenerationIntegrityFailException;
Expand All @@ -23,16 +34,6 @@
import kr.mashup.branding.util.DateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
Expand Down Expand Up @@ -217,6 +218,10 @@ public Long getTotalCountByPlatformAndGeneration(
return memberRepository.countActiveByPlatformAndGeneration(platform, generation);
}

public boolean existsIdentification(String identification) {
return memberRepository.existsByIdentification(identification);
}

private void checkAllActiveStatus(List<Member> members) {
for(Member member : members){
if (member.getStatus() != MemberStatus.ACTIVE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package kr.mashup.branding.facade.member;

import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import kr.mashup.branding.domain.exception.GenerationIntegrityFailException;
import kr.mashup.branding.domain.generation.Generation;
import kr.mashup.branding.domain.invite.Invite;
Expand All @@ -14,15 +21,19 @@
import kr.mashup.branding.service.invite.InviteService;
import kr.mashup.branding.service.member.MemberService;
import kr.mashup.branding.service.scorehistory.ScoreHistoryService;
import kr.mashup.branding.ui.member.request.*;
import kr.mashup.branding.ui.member.response.*;
import kr.mashup.branding.ui.member.request.LoginRequest;
import kr.mashup.branding.ui.member.request.MemberGenerationRequest;
import kr.mashup.branding.ui.member.request.MemberPasswordChangeRequest;
import kr.mashup.branding.ui.member.request.PushNotificationRequest;
import kr.mashup.branding.ui.member.request.SignUpRequest;
import kr.mashup.branding.ui.member.request.ValidInviteRequest;
import kr.mashup.branding.ui.member.response.AccessResponse;
import kr.mashup.branding.ui.member.response.ExistsResponse;
import kr.mashup.branding.ui.member.response.MemberGenerationsResponse;
import kr.mashup.branding.ui.member.response.MemberInfoResponse;
import kr.mashup.branding.ui.member.response.TokenResponse;
import kr.mashup.branding.ui.member.response.ValidResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;


@Service
Expand Down Expand Up @@ -121,6 +132,12 @@ public ValidResponse checkDuplicatedIdentification(String identification) {
return ValidResponse.of(!isExist);
}

@Transactional(readOnly = true)
public ExistsResponse existsIdentification(String identification) {
boolean isExist = memberService.existsIdentification(identification);
return ExistsResponse.of(isExist);
}

@Transactional
public Boolean updatePushNotificationAgreed(Long memberId, PushNotificationRequest request) {
Member member = memberService.getActiveOrThrowById(memberId);
Expand Down Expand Up @@ -150,6 +167,14 @@ public Boolean updateMemberGenerationById(
return true;
}

@Transactional
public void changePassword(
String identification,
MemberPasswordChangeRequest request
) {
memberService.resetPassword(identification, request.getNewPassword());
}

private MemberGeneration getLatestMemberGeneration(Member member) {
return member.getMemberGenerations().stream().min(Comparator.comparing(
memberGeneration -> memberGeneration.getGeneration().getNumber()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package kr.mashup.branding.ui.member;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import kr.mashup.branding.facade.member.MemberFacadeService;
import kr.mashup.branding.security.MemberAuth;
import kr.mashup.branding.ui.ApiResponse;
import kr.mashup.branding.ui.EmptyResponse;
import kr.mashup.branding.ui.member.request.*;
import kr.mashup.branding.ui.member.response.*;
import kr.mashup.branding.ui.member.request.LoginRequest;
import kr.mashup.branding.ui.member.request.MemberPasswordChangeRequest;
import kr.mashup.branding.ui.member.request.PushNotificationRequest;
import kr.mashup.branding.ui.member.request.SignUpRequest;
import kr.mashup.branding.ui.member.request.ValidInviteRequest;
import kr.mashup.branding.ui.member.response.AccessResponse;
import kr.mashup.branding.ui.member.response.ExistsResponse;
import kr.mashup.branding.ui.member.response.MemberInfoResponse;
import kr.mashup.branding.ui.member.response.TokenResponse;
import kr.mashup.branding.ui.member.response.ValidResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@RestController
@RequestMapping("api/v1/members")
@RequiredArgsConstructor
Expand Down Expand Up @@ -103,4 +120,26 @@ public ApiResponse<Boolean> updatePushNotificationAgreed(

return ApiResponse.success(updatePushNotificationAgreedResponse);
}

@ApiOperation("ID 존재 여부 조회")
@GetMapping("{id}/exists")
public ApiResponse<ExistsResponse> existsIdentification(
@PathVariable String id
) {
final ExistsResponse response
= memberFacadeService.existsIdentification(id);

return ApiResponse.success(response);
}

@ApiOperation("비밀번호 변경")
@PutMapping("/{id}/password")
public ApiResponse<EmptyResponse> changePassword(
@PathVariable String id,
@RequestBody MemberPasswordChangeRequest request
){
memberFacadeService.changePassword(id, request);

return ApiResponse.success();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kr.mashup.branding.ui.member.request;

import lombok.Getter;

@Getter
public class MemberPasswordChangeRequest {
private String newPassword;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kr.mashup.branding.ui.member.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(staticName = "of")
public class ExistsResponse {
private boolean exists;
}

0 comments on commit 667b2d1

Please sign in to comment.