Skip to content

Commit

Permalink
Merge pull request #361 from twenty-three-23/dev
Browse files Browse the repository at this point in the history
v 1.1.1
  • Loading branch information
snacktime81 authored Sep 7, 2024
2 parents 91e18ad + 65e96fa commit 371d221
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.twentythree.peech.feedback.domain;


public interface FeedbackMapper {
void insertFeedback(FeedbackDomain feedbackDomain);
}
30 changes: 30 additions & 0 deletions src/main/java/com/twentythree/peech/feedback/entity/Feedback.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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<Feedback, Long> {
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 371d221

Please sign in to comment.