Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into feature/#4-face
  • Loading branch information
ghvfgfcht committed May 3, 2024
2 parents 9ca1724 + e8c82c8 commit 42fdabb
Show file tree
Hide file tree
Showing 25 changed files with 347 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fairytale.tbd.domain.fairytale.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -8,4 +10,6 @@
@Repository
public interface FairytaleRepository extends JpaRepository<Fairytale, Long> {
boolean existsByName(String name);

Optional<Fairytale> findByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
public class FairytaleCommandServiceImpl implements FairytaleCommandService {
private final FairytaleRepository fairytaleRepository;

/**
* 동화 추가 서비스 로직
*/
@Override
@Transactional
public Fairytale saveFairytale(FairytaleRequestDTO.AddFairytaleRequestDTO request) {
// TODO BEAN VALIDATION
if (fairytaleRepository.existsByName(request.getName())) {
throw new GeneralException(ErrorStatus._FAIRYTALE_EXIST_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
public class FairytaleRestController {
private final FairytaleCommandService fairytaleCommandService;

/**
* 동화 추가 메서드
*/
@PostMapping("")
public ApiResponse<FairytaleResponseDTO.AddFairytaleResultDTO> addFairytale(@Valid @RequestBody
FairytaleRequestDTO.AddFairytaleRequestDTO request) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/fairytale/tbd/domain/user/enums/Gender.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fairytale.tbd.domain.user.enums;

/**
* 사용자 성별
*/
public enum Gender {
MALE, FEMALE;
}
3 changes: 3 additions & 0 deletions src/main/java/fairytale/tbd/domain/user/enums/Role.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fairytale.tbd.domain.user.enums;

/**
* 권한 역할
*/
public enum Role {
ROLE_USER, ROLE_ADMIN, ROLE_GUEST
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class UserCommandServiceImpl implements UserCommandService {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;

/**
* 사용자가 회원가입에서 입력한 PLANE TEXT를
* 암호화 하고, 유저의 권한을 추가 한 후, 데이터베이스에 저장
*/
@Transactional
@Override
public User addUser(UserRequestDTO.AddUserDTO request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ 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);
}

/**
* 사용자의 RefreshToken을 데이터베이스에 업데이트
*/
@Transactional
@Override
public void updateRefreshToken(User user, String reIssuedRefreshToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class UserRestController {
private final UserCommandService userCommandService;
private static final Logger LOGGER = LogManager.getLogger(UserRestController.class);

/**
* 회원 가입
*/
@PostMapping("/signup")
public ApiResponse<UserResponseDTO.AddUserResultDTO> join(@Valid @RequestBody UserRequestDTO.AddUserDTO request) {
LOGGER.info("request = {}", request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static Segment toSegment(VoiceRequestDTO.AddSegmentDTO request) {
.isMainCharacter(request.isMainCharacter())
.voiceType(request.getVoiceType())
.num(request.getSegmentNum())
.userTTSSegmentList(new ArrayList<>())
.pageNum(request.getPageNum())
.build();
}

Expand Down
34 changes: 27 additions & 7 deletions src/main/java/fairytale/tbd/domain/voice/entity/Segment.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package fairytale.tbd.domain.voice.entity;

import java.util.List;

import fairytale.tbd.domain.fairytale.entity.Fairytale;
import fairytale.tbd.domain.voice.enums.VoiceType;
import fairytale.tbd.global.entity.BaseEntity;
Expand All @@ -11,6 +14,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
Expand All @@ -24,7 +28,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "fairytale_segment")
public class Segment extends BaseEntity {
public class Segment extends BaseEntity implements Comparable<Segment> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "fairytale_segment_id")
Expand All @@ -40,7 +44,10 @@ public class Segment extends BaseEntity {
private VoiceType voiceType;

@Column(name = "segment_num", nullable = false)
private Long num;
private Double num;

@Column(name = "page_num", nullable = false)
private Long pageNum;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fairytale_id", nullable = false)
Expand All @@ -49,8 +56,21 @@ public class Segment extends BaseEntity {
@OneToOne(mappedBy = "segment", cascade = CascadeType.ALL, orphanRemoval = true)
private TTSSegment ttsSegment;

@OneToOne(mappedBy = "segment", cascade = CascadeType.ALL, orphanRemoval = true)
private UserTTSSegment userTTSSegment;
@OneToMany(mappedBy = "segment", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UserTTSSegment> userTTSSegmentList;

@Override
public int compareTo(Segment segment) {
if (this.pageNum == segment.pageNum) {
if (this.num < segment.num) {
return -1;
} else if (this.num == segment.num) {
return 0;
} else
return 1;
}
return 1;
}

// 연관 관계 편의 메서드

Expand All @@ -62,8 +82,8 @@ public void setTtsSegment(TTSSegment ttsSegment) {
this.ttsSegment = ttsSegment;
}

public void setUserTTSSegment(UserTTSSegment userTTSSegment) {
this.userTTSSegment = userTTSSegment;
public void addUserTTSSegment(UserTTSSegment userTTSSegment) {
userTTSSegmentList.add(userTTSSegment);
userTTSSegment.setSegment(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class TTSSegment extends BaseEntity {
@Column(name = "text_to_speech_segment_url")
private String url;

@Column(name = "history_id")
private String historyId;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fairytale_segment_id")
private Segment segment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand All @@ -29,17 +28,14 @@ public class UserTTSSegment extends BaseEntity {
@Column(name = "uset_text_to_speech_segment_id")
private Long id;

@Column(name = "history_id", nullable = false)
private String historyId;

@Column(name = "user_text_to_speech_segment_url")
private String url;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@OneToOne(fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fairytale_segment_id")
private Segment segment;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fairytale.tbd.domain.voice.exception;

import fairytale.tbd.global.enums.statuscode.BaseCode;
import fairytale.tbd.global.exception.GeneralException;

public class VoiceNotFoundException extends GeneralException {
public VoiceNotFoundException(BaseCode errorStatus) {
super(errorStatus);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package fairytale.tbd.domain.voice.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import fairytale.tbd.domain.voice.entity.TTSSegment;

@Repository
public interface TTSSegmentRepository extends JpaRepository<TTSSegment, Long> {
Optional<TTSSegment> findBySegmentId(Long segmentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fairytale.tbd.domain.voice.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import fairytale.tbd.domain.user.entity.User;
import fairytale.tbd.domain.voice.entity.Segment;
import fairytale.tbd.domain.voice.entity.UserTTSSegment;

@Repository
public interface UserTTSSegmentRepository extends JpaRepository<UserTTSSegment, Long> {
Optional<UserTTSSegment> findByUserAndSegment(User user, Segment segment);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package fairytale.tbd.domain.voice.service;

import fairytale.tbd.domain.user.entity.User;
import fairytale.tbd.domain.voice.entity.Segment;
import fairytale.tbd.domain.voice.entity.TTSSegment;
import fairytale.tbd.domain.voice.entity.UserTTSSegment;
import fairytale.tbd.domain.voice.entity.Voice;
import fairytale.tbd.domain.voice.web.dto.VoiceRequestDTO;
import fairytale.tbd.domain.voice.web.dto.VoiceResponseDTO;
Expand All @@ -9,4 +12,8 @@ public interface VoiceCommandService {
Voice uploadVoice(VoiceRequestDTO.AddVoiceDTO request, User user);

VoiceResponseDTO.AddTTSSegmentResultDTO addTTSSegment(VoiceRequestDTO.AddSegmentDTO request);

TTSSegment saveTTSSegment(Segment segment);

UserTTSSegment saveUserTTSSegment(User user, Segment segment);
}
Loading

0 comments on commit 42fdabb

Please sign in to comment.