-
Notifications
You must be signed in to change notification settings - Fork 2
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 #361 from twenty-three-23/dev
v 1.1.1
- Loading branch information
Showing
9 changed files
with
167 additions
and
5 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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/twentythree/peech/feedback/application/FeedbackService.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,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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/twentythree/peech/feedback/domain/FeedbackDomain.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 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; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/twentythree/peech/feedback/domain/FeedbackMapper.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,6 @@ | ||
package com.twentythree.peech.feedback.domain; | ||
|
||
|
||
public interface FeedbackMapper { | ||
void insertFeedback(FeedbackDomain feedbackDomain); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/twentythree/peech/feedback/entity/Feedback.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,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(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/twentythree/peech/feedback/infrastructure/FeedbackMapperImpl.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,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())); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/twentythree/peech/feedback/infrastructure/JpaFeedbackRepository.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 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> { | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/twentythree/peech/feedback/presentation/FeedbackController.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 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()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/twentythree/peech/feedback/value/request/CreateFeedbackRequestDTO.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 com.twentythree.peech.feedback.value.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CreateFeedbackRequestDTO { | ||
private String message; | ||
} |