Skip to content

Commit

Permalink
Merge pull request #7 from f-lab-edu/6-create-user-and-partner
Browse files Browse the repository at this point in the history
[6] 일반 회원, 파트너 생성
  • Loading branch information
ohsuha authored Aug 30, 2024
2 parents 6e0b004 + bb32ce9 commit 15fcde0
Show file tree
Hide file tree
Showing 25 changed files with 456 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication (exclude = SecurityAutoConfiguration.class)
@EnableJpaAuditing
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
public class CommerceSiteApplication {
public static void main(String[] args) {
SpringApplication.run(CommerceSiteApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example.commerce_site.application.partner;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.commerce_site.application.partner.dto.PartnerRequestDto;
import org.example.commerce_site.application.partner.dto.PartnerResponseDto;
import org.example.commerce_site.infrastructure.PartnerRepository;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class PartnerService {
private final PartnerRepository partnerRepository;

public PartnerResponseDto.Create create(PartnerRequestDto.Create dto) {
return PartnerResponseDto.Create.of(partnerRepository.save(PartnerRequestDto.Create.toEntity(dto)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.example.commerce_site.application.partner.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.example.commerce_site.attribute.PartnerStatus;
import org.example.commerce_site.domain.Partner;

public class PartnerRequestDto {
@Getter
@Builder
@ToString
public static class Create {
private String name;
private String email;
private String password;
private String businessNumber;

public static Partner toEntity(PartnerRequestDto.Create dto) {
return Partner.builder()
.name(dto.getName())
.email(dto.getEmail())
.password(dto.getPassword())
.status(PartnerStatus.ACTIVE)
.businessNumber(dto.getBusinessNumber())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.example.commerce_site.application.partner.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.example.commerce_site.domain.Partner;

public class PartnerResponseDto {
@Builder
@Getter
@ToString
public static class Create {
private String name;
private String email;
private String businessNumber;

public static PartnerResponseDto.Create of(Partner partner) {
return Create.builder()
.name(partner.getName())
.email(partner.getEmail())
.businessNumber(partner.getBusinessNumber())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example.commerce_site.application.user;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.commerce_site.application.user.dto.UserRequestDto;
import org.example.commerce_site.application.user.dto.UserResponseDto;
import org.example.commerce_site.infrastructure.UserRepository;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;

public UserResponseDto.Create create(UserRequestDto.Create dto) {
return UserResponseDto.Create.of(userRepository.save(UserRequestDto.Create.toEntity(dto)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.example.commerce_site.application.user.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.example.commerce_site.attribute.UserStatus;
import org.example.commerce_site.domain.User;

public class UserRequestDto {
@Getter
@Builder
@ToString
public static class Create {
private String name;
private String email;
private String password;

public static User toEntity(UserRequestDto.Create dto) {
return User.builder()
.name(dto.getName())
.email(dto.getEmail())
.password(dto.getPassword())
.status(UserStatus.ACTIVE)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example.commerce_site.application.user.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.example.commerce_site.domain.User;

public class UserResponseDto {
@Builder
@Getter
@ToString
public static class Create {
private String name;
private String email;

public static UserResponseDto.Create of(User user) {
return Create.builder()
.name(user.getName())
.email(user.getEmail())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.commerce_site.attribute;

public enum PartnerStatus {
ACTIVE,
INACTIVE,
DORMANT,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.commerce_site.attribute;

public enum UserStatus {
ACTIVE,
INACTIVE,
DORMANT,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.example.commerce_site.common.domain;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class BaseTimeEntity extends IdKeyEntity {
@CreatedDate
@Column(name = "created_at")
protected LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "updated_at")
protected LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.example.commerce_site.common.domain;

import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@MappedSuperclass
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public abstract class IdKeyEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.example.commerce_site.common.util;

public class PasswordUtil {
}
27 changes: 27 additions & 0 deletions src/main/java/org/example/commerce_site/domain/Partner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.example.commerce_site.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.example.commerce_site.attribute.PartnerStatus;
import org.example.commerce_site.common.domain.BaseTimeEntity;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "partners")
public class Partner extends BaseTimeEntity {
private String name;
private String businessNumber;
private String password;
private String email;
@Enumerated(EnumType.STRING)
private PartnerStatus status;
}
26 changes: 26 additions & 0 deletions src/main/java/org/example/commerce_site/domain/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.example.commerce_site.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.example.commerce_site.attribute.UserStatus;
import org.example.commerce_site.common.domain.BaseTimeEntity;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "users")
public class User extends BaseTimeEntity {
private String name;
private String email;
private String password;
@Enumerated(EnumType.STRING)
private UserStatus status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.commerce_site.infrastructure;

import org.example.commerce_site.domain.Partner;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PartnerRepository extends JpaRepository<Partner, Integer> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example.commerce_site.infrastructure;

import org.example.commerce_site.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.example.commerce_site.representation.partner;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.commerce_site.application.partner.PartnerService;
import org.example.commerce_site.representation.partner.request.PartnerRequest;
import org.example.commerce_site.representation.partner.response.PartnerResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/partner")
public class PartnerController {
private final PartnerService partnerService;

@PostMapping()
public PartnerResponse.Create createPartner(@Valid @RequestBody PartnerRequest.Create request) {
return PartnerResponse.Create.of(partnerService.create(PartnerRequest.Create.toDTO(request)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.example.commerce_site.representation.partner.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.ToString;
import org.example.commerce_site.application.partner.dto.PartnerRequestDto;

public class PartnerRequest {
@Getter
@ToString
public static class Create {
@NotBlank
private String name;

@NotBlank
//TODO email 형식 체크
private String email;

@NotBlank
//TODO 패스워드 형식 체크 (8자리 이상 20자리 이하 영문 + 숫자)
private String password;

@NotBlank
private String businessNumber;

public static PartnerRequestDto.Create toDTO(PartnerRequest.Create request) {
return PartnerRequestDto.Create.builder()
.name(request.getName())
.email(request.getEmail())
//TODO PWD 암호화
.password(request.getPassword())
.businessNumber(request.getBusinessNumber())
.build();
}
}
}
Loading

0 comments on commit 15fcde0

Please sign in to comment.