feat(user-service): 점주 회원가입 로직 구현
- request validation 구현
This commit is contained in:
@@ -2,12 +2,8 @@ package com.justpickup.userservice.domain.user.service;
|
||||
|
||||
import com.justpickup.userservice.domain.user.dto.CustomerDto;
|
||||
import com.justpickup.userservice.domain.user.dto.StoreOwnerDto;
|
||||
import com.justpickup.userservice.domain.user.entity.StoreOwner;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
|
||||
CustomerDto findCustomerByUserId(Long userId);
|
||||
StoreOwner saveStoreOwner(StoreOwnerDto storeOwnerDto);
|
||||
|
||||
void saveStoreOwner(StoreOwnerDto storeOwnerDto);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ public class UserServiceImpl implements UserService, UserDetailsService {
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
User user = userRepository.findByEmail(username)
|
||||
@@ -54,12 +52,13 @@ public class UserServiceImpl implements UserService, UserDetailsService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public StoreOwner saveStoreOwner(StoreOwnerDto storeOwnerDto) {
|
||||
public void saveStoreOwner(StoreOwnerDto storeOwnerDto) {
|
||||
String encode = passwordEncoder.encode(storeOwnerDto.getPassword());
|
||||
|
||||
StoreOwner storeOwner = new StoreOwner(storeOwnerDto.getEmail(), encode, storeOwnerDto.getName(),
|
||||
storeOwnerDto.getPhoneNumber(), storeOwnerDto.getBusinessNumber());
|
||||
|
||||
return userRepository.save(storeOwner);
|
||||
StoreOwner save = userRepository.save(storeOwner);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
package com.justpickup.userservice.domain.user.web;
|
||||
|
||||
import com.justpickup.userservice.domain.user.dto.CustomerDto;
|
||||
import com.justpickup.userservice.domain.user.entity.Customer;
|
||||
import com.justpickup.userservice.domain.user.dto.StoreOwnerDto;
|
||||
import com.justpickup.userservice.domain.user.service.UserService;
|
||||
import com.justpickup.userservice.global.dto.Result;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -51,6 +48,36 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/store/join")
|
||||
public ResponseEntity<Result> joinStoreOwner(@Valid @RequestBody JoinStoreOwnerRequest joinRequest) {
|
||||
// 회원 가입
|
||||
userService.saveStoreOwner(joinRequest.toStoreOwnerDto());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(Result.createSuccessResult(null));
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor @AllArgsConstructor
|
||||
static class JoinStoreOwnerRequest {
|
||||
@Email(message = "email 형식이 아닙니다.")
|
||||
@NotEmpty
|
||||
private String email;
|
||||
@NotEmpty
|
||||
private String password;
|
||||
@NotEmpty
|
||||
private String name;
|
||||
@NotEmpty
|
||||
private String phoneNumber;
|
||||
@NotEmpty
|
||||
private String businessNumber;
|
||||
|
||||
public StoreOwnerDto toStoreOwnerDto() {
|
||||
return StoreOwnerDto.builder()
|
||||
.email(email).password(password).name(name)
|
||||
.password(password).businessNumber(businessNumber)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user