-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
✨ FEAT. User 기능 추가
- Loading branch information
Showing
35 changed files
with
1,171 additions
and
36 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
9 changes: 6 additions & 3 deletions
9
src/main/java/fairytale/tbd/domain/user/converter/UserConverter.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
39 changes: 39 additions & 0 deletions
39
src/main/java/fairytale/tbd/domain/user/entity/Authority.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,39 @@ | ||
package fairytale.tbd.domain.user.entity; | ||
|
||
import fairytale.tbd.domain.user.enums.Role; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Authority { | ||
@Id | ||
@GeneratedValue(strategy= GenerationType.IDENTITY) | ||
@Column(name = "authority_id") | ||
private Long id; | ||
|
||
@Column(name = "authority_role") | ||
private Role role; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
// 연관 관계 편의 메서드 | ||
public void setUser(User user){ | ||
this.user = user; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fairytale.tbd.domain.user.enums; | ||
|
||
public enum Role { | ||
ROLE_USER, ROLE_ADMIN, ROLE_GUEST | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/fairytale/tbd/domain/user/exception/UserNotExistException.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,10 @@ | ||
package fairytale.tbd.domain.user.exception; | ||
|
||
import fairytale.tbd.global.enums.statuscode.BaseCode; | ||
import fairytale.tbd.global.exception.GeneralException; | ||
|
||
public class UserNotExistException extends GeneralException { | ||
public UserNotExistException(BaseCode errorStatus) { | ||
super(errorStatus); | ||
} | ||
} |
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
13 changes: 11 additions & 2 deletions
13
src/main/java/fairytale/tbd/domain/user/service/UserCommandServiceImpl.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 |
---|---|---|
@@ -1,25 +1,34 @@ | ||
package fairytale.tbd.domain.user.service; | ||
|
||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import fairytale.tbd.domain.user.converter.UserConverter; | ||
import fairytale.tbd.domain.user.entity.Authority; | ||
import fairytale.tbd.domain.user.entity.User; | ||
import fairytale.tbd.domain.user.enums.Role; | ||
import fairytale.tbd.domain.user.repository.UserRepository; | ||
import fairytale.tbd.domain.user.web.dto.UserRequestDTO; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class UserCommandServiceImpl implements UserCommandService{ | ||
public class UserCommandServiceImpl implements UserCommandService { | ||
|
||
private final UserRepository userRepository; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
@Transactional | ||
@Override | ||
public User addUser(UserRequestDTO.AddUserDTO request) { | ||
User user = UserConverter.toUser(request); | ||
String encodedPassword = passwordEncoder.encode(request.getPassword()); | ||
User user = UserConverter.toUser(request, encodedPassword); | ||
Authority authority = Authority.builder() | ||
.role(Role.ROLE_USER) | ||
.build(); | ||
user.addAuthority(authority); | ||
return userRepository.save(user); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/fairytale/tbd/domain/user/service/UserQueryService.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,12 @@ | ||
package fairytale.tbd.domain.user.service; | ||
|
||
import java.util.Optional; | ||
|
||
import fairytale.tbd.domain.user.entity.User; | ||
|
||
public interface UserQueryService { | ||
|
||
Optional<User> getUserWithAuthorities(String loginId); | ||
|
||
void updateRefreshToken(User user, String reIssuedRefreshToken); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/fairytale/tbd/domain/user/service/UserQueryServiceImpl.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,33 @@ | ||
package fairytale.tbd.domain.user.service; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import fairytale.tbd.domain.user.entity.User; | ||
import fairytale.tbd.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class UserQueryServiceImpl implements UserQueryService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public Optional<User> getUserWithAuthorities(String loginId) { | ||
User user = userRepository.findByLoginId(loginId).orElse(null); | ||
user.getAuthorityList().size(); | ||
return Optional.ofNullable(user); | ||
} | ||
|
||
@Transactional | ||
@Override | ||
public void updateRefreshToken(User user, String reIssuedRefreshToken) { | ||
user.updateRefreshToken(reIssuedRefreshToken); | ||
userRepository.saveAndFlush(user); | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/fairytale/tbd/domain/voice/entity/Fairytale.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,42 @@ | ||
package fairytale.tbd.domain.voice.entity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import fairytale.tbd.global.entity.BaseEntity; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToMany; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Fairytale extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "fairytale_id") | ||
private Long id; | ||
|
||
@Column(name = "fairytale_name", nullable = false) | ||
private String name; | ||
|
||
@OneToMany(mappedBy = "fairytale", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<Segment> segmentList = new ArrayList<>(); | ||
|
||
// 연관 관계 편의 메서드 | ||
public void addSegment(Segment segment) { | ||
segmentList.add(segment); | ||
segment.setFairytale(this); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/fairytale/tbd/domain/voice/entity/Segment.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,69 @@ | ||
package fairytale.tbd.domain.voice.entity; | ||
|
||
import fairytale.tbd.domain.voice.enums.VoiceType; | ||
import fairytale.tbd.global.entity.BaseEntity; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "fairytale_segment") | ||
public class Segment extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "fariytale_segment_id") | ||
private Long id; | ||
|
||
@Column(name = "segment_context", nullable = false) | ||
private String context; | ||
|
||
@Column(name = "is_main_character", nullable = false) | ||
private boolean isMainCharacter; | ||
|
||
@Column(name = "voice_type", nullable = false) | ||
private VoiceType voiceType; | ||
|
||
@Column(name = "segment_num", nullable = false) | ||
private Long num; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "fairytale_id", nullable = false) | ||
private Fairytale fairytale; | ||
|
||
@OneToOne(mappedBy = "segment", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private TTSSegment ttsSegment; | ||
|
||
@OneToOne(mappedBy = "segment", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private UserTTSSegment userTTSSegment; | ||
|
||
// 연관 관계 편의 메서드 | ||
|
||
public void setFairytale(Fairytale fairytale) { | ||
this.fairytale = fairytale; | ||
} | ||
|
||
public void setTtsSegment(TTSSegment ttsSegment) { | ||
this.ttsSegment = ttsSegment; | ||
} | ||
|
||
public void setUserTTSSegment(UserTTSSegment userTTSSegment) { | ||
this.userTTSSegment = userTTSSegment; | ||
} | ||
|
||
} |
Oops, something went wrong.