diff --git a/src/main/java/com/twentythree/peech/common/utils/ScriptUtils.java b/src/main/java/com/twentythree/peech/common/utils/ScriptUtils.java index 3041091..d44a7e0 100644 --- a/src/main/java/com/twentythree/peech/common/utils/ScriptUtils.java +++ b/src/main/java/com/twentythree/peech/common/utils/ScriptUtils.java @@ -4,14 +4,14 @@ public class ScriptUtils { public static LocalTime calculateExpectedTime(String text) { + final int DEFAULT_SPM = 355; - final float DEFAULT_TIME_PER_WORD_SECOND = 1.75F; //LocalTime.of(0,0,1, 750000000); + long count = text.chars().filter(ch -> ch == '.').count(); - String[] words = text.split(" "); - int wordsCount = words.length; + String noSpaceText = text.replaceAll("[^가-힣]", ""); + int SyllableFromText = noSpaceText.length(); + float expectedTimeToSecond = (float) SyllableFromText / DEFAULT_SPM * 60 + count * 1; - float expectedTimeToSecond = wordsCount * DEFAULT_TIME_PER_WORD_SECOND; - expectedTimeToSecond /= 3f; LocalTime expectedTime = transferSeoondToLocalTime(expectedTimeToSecond); return expectedTime; diff --git a/src/main/java/com/twentythree/peech/feedback/application/FeedbackService.java b/src/main/java/com/twentythree/peech/feedback/application/FeedbackService.java new file mode 100644 index 0000000..1337b45 --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/application/FeedbackService.java @@ -0,0 +1,28 @@ +package com.twentythree.peech.feedback.application; + +import com.twentythree.peech.auth.service.SecurityContextHolder; +import com.twentythree.peech.feedback.domain.FeedbackDomain; +import com.twentythree.peech.feedback.domain.FeedbackMapper; +import com.twentythree.peech.script.service.ThemeService; +import com.twentythree.peech.user.entity.UserEntity; +import com.twentythree.peech.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class FeedbackService { + + private final FeedbackMapper feedbackMapper; + private final ThemeService themeService; + private final UserRepository userRepository; + + public void createFeedback(String message) { + Long userId = SecurityContextHolder.getUserId(); + UserEntity user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("User not found")); + + FeedbackDomain feedbackDomain = FeedbackDomain.of(null, message, userId, user.getAuthorizationServer(), user.getFirstName(), user.getLastName(), user.getBirth(), user.getGender(), user.getEmail(), user.getNickName(), user.getRole(), user.getSignUpFinished(), user.getUserStatus()); + + feedbackMapper.insertFeedback(feedbackDomain); + } +} diff --git a/src/main/java/com/twentythree/peech/feedback/domain/FeedbackDomain.java b/src/main/java/com/twentythree/peech/feedback/domain/FeedbackDomain.java new file mode 100644 index 0000000..f9ec225 --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/domain/FeedbackDomain.java @@ -0,0 +1,29 @@ +package com.twentythree.peech.feedback.domain; + + +import com.twentythree.peech.user.value.*; +import lombok.*; + +import javax.annotation.Nullable; +import java.time.LocalDate; + +@Getter +@Setter(AccessLevel.PACKAGE) +@AllArgsConstructor(staticName = "of") +public class FeedbackDomain { + + private Long feedbackId; + private String feedbackMessage; + + private Long userId; + private AuthorizationServer authorizationServer; + private String firstName; + private String lastName; + private LocalDate birth; + private UserGender gender; + private String email; + private String nickName; + private UserRole role; + private SignUpFinished signUpFinished; + private UserStatus userStatus; +} diff --git a/src/main/java/com/twentythree/peech/feedback/domain/FeedbackMapper.java b/src/main/java/com/twentythree/peech/feedback/domain/FeedbackMapper.java new file mode 100644 index 0000000..c7263b6 --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/domain/FeedbackMapper.java @@ -0,0 +1,6 @@ +package com.twentythree.peech.feedback.domain; + + +public interface FeedbackMapper { + void insertFeedback(FeedbackDomain feedbackDomain); +} diff --git a/src/main/java/com/twentythree/peech/feedback/entity/Feedback.java b/src/main/java/com/twentythree/peech/feedback/entity/Feedback.java new file mode 100644 index 0000000..d70a0af --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/entity/Feedback.java @@ -0,0 +1,30 @@ +package com.twentythree.peech.feedback.entity; + + +import com.twentythree.peech.user.entity.UserEntity; +import jakarta.persistence.*; +import lombok.*; + +@Getter +@Builder +@AllArgsConstructor(staticName = "of") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "FEEDBACK") +@Entity +public class Feedback { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "feedback_id") + private Long feedbackId; + + @JoinColumn(name = "userId", nullable = false) + @ManyToOne(fetch = FetchType.LAZY) + private UserEntity user; + + @Column(name = "feedback_message", nullable = false) + private String feedbackMessage; + + public static Feedback ofJpa(UserEntity user, String feedbackMessage) { + return Feedback.builder().user(user).feedbackMessage(feedbackMessage).build(); + } +} diff --git a/src/main/java/com/twentythree/peech/feedback/infrastructure/FeedbackMapperImpl.java b/src/main/java/com/twentythree/peech/feedback/infrastructure/FeedbackMapperImpl.java new file mode 100644 index 0000000..ff91534 --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/infrastructure/FeedbackMapperImpl.java @@ -0,0 +1,28 @@ +package com.twentythree.peech.feedback.infrastructure; + +import com.twentythree.peech.feedback.domain.FeedbackDomain; +import com.twentythree.peech.feedback.domain.FeedbackMapper; +import com.twentythree.peech.feedback.entity.Feedback; +import com.twentythree.peech.user.entity.UserEntity; +import com.twentythree.peech.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@RequiredArgsConstructor +@Repository +public class FeedbackMapperImpl implements FeedbackMapper { + + private final JpaFeedbackRepository feedbackRepository; + private final UserRepository userRepository; + + @Override + @Transactional + public void insertFeedback(FeedbackDomain feedbackDomain) { + + UserEntity userEntity = userRepository.findById(feedbackDomain.getUserId()).orElseThrow(() -> new IllegalArgumentException("잘못된 사용자 입니다.")); + + feedbackRepository.save(Feedback.ofJpa(userEntity, feedbackDomain.getFeedbackMessage())); + } +} diff --git a/src/main/java/com/twentythree/peech/feedback/infrastructure/JpaFeedbackRepository.java b/src/main/java/com/twentythree/peech/feedback/infrastructure/JpaFeedbackRepository.java new file mode 100644 index 0000000..f169229 --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/infrastructure/JpaFeedbackRepository.java @@ -0,0 +1,9 @@ +package com.twentythree.peech.feedback.infrastructure; + +import com.twentythree.peech.feedback.entity.Feedback; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface JpaFeedbackRepository extends JpaRepository { +} diff --git a/src/main/java/com/twentythree/peech/feedback/presentation/FeedbackController.java b/src/main/java/com/twentythree/peech/feedback/presentation/FeedbackController.java new file mode 100644 index 0000000..958f2d7 --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/presentation/FeedbackController.java @@ -0,0 +1,20 @@ +package com.twentythree.peech.feedback.presentation; + +import com.twentythree.peech.feedback.application.FeedbackService; +import com.twentythree.peech.feedback.value.request.CreateFeedbackRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RestController +public class FeedbackController { + + private final FeedbackService feedbackService; + + @PostMapping("api/v1.1/users/feedbacks") + public void createFeedback(@RequestBody CreateFeedbackRequestDTO message) { + feedbackService.createFeedback(message.getMessage()); + } +} diff --git a/src/main/java/com/twentythree/peech/feedback/value/request/CreateFeedbackRequestDTO.java b/src/main/java/com/twentythree/peech/feedback/value/request/CreateFeedbackRequestDTO.java new file mode 100644 index 0000000..92f3d85 --- /dev/null +++ b/src/main/java/com/twentythree/peech/feedback/value/request/CreateFeedbackRequestDTO.java @@ -0,0 +1,12 @@ +package com.twentythree.peech.feedback.value.request; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class CreateFeedbackRequestDTO { + private String message; +}