-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from f-lab-edu/6-create-user-and-partner
[6] 일반 회원, 파트너 생성
- Loading branch information
Showing
25 changed files
with
456 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/org/example/commerce_site/application/partner/PartnerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/example/commerce_site/application/partner/dto/PartnerRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/example/commerce_site/application/partner/dto/PartnerResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/example/commerce_site/application/user/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/example/commerce_site/application/user/dto/UserRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/example/commerce_site/application/user/dto/UserResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/example/commerce_site/attribute/PartnerStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/example/commerce_site/attribute/UserStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/example/commerce_site/common/domain/BaseTimeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/example/commerce_site/common/domain/IdKeyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/example/commerce_site/common/util/PasswordUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
src/main/java/org/example/commerce_site/domain/Partner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/example/commerce_site/infrastructure/PartnerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/example/commerce_site/infrastructure/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/example/commerce_site/representation/partner/PartnerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/org/example/commerce_site/representation/partner/request/PartnerRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.