-
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.
Merge pull request #27 from survey-mate/feat/19
feat: Survey 도메인 및 SurveyService 일부 구현
- Loading branch information
Showing
12 changed files
with
248 additions
and
34 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
15 changes: 0 additions & 15 deletions
15
src/main/java/uk/jinhy/survey_mate_api/survey/SurveyStatus.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/main/java/uk/jinhy/survey_mate_api/survey/application/dto/SurveyServiceDTO.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,25 @@ | ||
package uk.jinhy.survey_mate_api.survey.application.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
public class SurveyServiceDTO { | ||
@Builder | ||
@Getter | ||
public static class CreateSurveyDTO { | ||
private String linkUrl; | ||
private String title; | ||
private String description; | ||
private Long reward; | ||
private Long period; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
public static class EditSurveyDTO { | ||
private Long surveyId; | ||
private String linkUrl; | ||
private String title; | ||
private String description; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/main/java/uk/jinhy/survey_mate_api/survey/application/service/SurveyService.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,105 @@ | ||
package uk.jinhy.survey_mate_api.survey.application.service; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import uk.jinhy.survey_mate_api.common.util.Util; | ||
import uk.jinhy.survey_mate_api.member.Member; | ||
import uk.jinhy.survey_mate_api.survey.application.dto.SurveyServiceDTO; | ||
import uk.jinhy.survey_mate_api.survey.domain.entity.Answer; | ||
import uk.jinhy.survey_mate_api.survey.domain.entity.Survey; | ||
import uk.jinhy.survey_mate_api.survey.domain.repository.SurveyRepository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
// TODO | ||
// Exception 구현 시 예외 처리 추가 | ||
@RequiredArgsConstructor | ||
@Service | ||
public class SurveyService { | ||
private final SurveyRepository surveyRepository; | ||
|
||
public Survey createSurvey(Member registrant, SurveyServiceDTO.CreateSurveyDTO dto) { | ||
Survey survey = Survey.builder() | ||
.reward(dto.getReward()) | ||
.endedAt(LocalDateTime.now().plusDays(dto.getPeriod())) | ||
.linkUrl(dto.getLinkUrl()) | ||
.rewardUrl(Util.generateRandomString()) | ||
.title(dto.getTitle()) | ||
.description(dto.getDescription()) | ||
.registrant(registrant) | ||
.build(); | ||
surveyRepository.save(survey); | ||
return survey; | ||
} | ||
|
||
@Transactional | ||
public void editSurvey(Member registrant, SurveyServiceDTO.EditSurveyDTO dto) { | ||
Long surveyId = dto.getSurveyId(); | ||
Survey survey = surveyRepository.findBySurveyId(surveyId).get(); | ||
|
||
if (!survey.getRegistrant().equals(registrant)) { | ||
return; | ||
} | ||
|
||
String newTitle = dto.getTitle(); | ||
if (newTitle != null) { | ||
survey.updateTitle(newTitle); | ||
} | ||
|
||
String newDescription = dto.getDescription(); | ||
if (newDescription != null) { | ||
survey.updateDescription(newDescription); | ||
} | ||
|
||
String newLinkUrl = dto.getLinkUrl(); | ||
if (newLinkUrl != null) { | ||
survey.updateLinkUrl(newLinkUrl); | ||
} | ||
} | ||
|
||
@Transactional | ||
public void deleteSurvey(Member registrant, Long surveyId) { | ||
Survey survey = surveyRepository.findBySurveyId(surveyId).get(); | ||
if (survey.getRegistrant().equals(registrant)) { | ||
surveyRepository.deleteById(surveyId); | ||
} | ||
} | ||
|
||
public void addAnswer(Member respondent, Long surveyId) { | ||
Survey survey = surveyRepository.findBySurveyId(surveyId).get(); | ||
if (!survey.isAnswered(respondent)) { | ||
return; | ||
} | ||
Answer answer = Answer.builder() | ||
.survey(survey) | ||
.respondent(respondent) | ||
.build(); | ||
survey.addAnswer(answer); | ||
surveyRepository.save(survey); | ||
} | ||
|
||
public Survey getSurvey(Long surveyId) { | ||
return surveyRepository.findBySurveyId(surveyId).get(); | ||
} | ||
|
||
public List<Survey> getSurveyList(int pageNumber) { | ||
Pageable pageable = PageRequest.of(pageNumber, 10); | ||
return surveyRepository.findByEndedAtIsBefore(pageable, LocalDateTime.now()); | ||
} | ||
|
||
public List<Survey> getMySurveyList(Member registrant) { | ||
return surveyRepository.findByRegistrant(registrant); | ||
} | ||
|
||
public List<Survey> getAnsweredSurveyList(Member respondent) { | ||
return surveyRepository.findByRespondent(respondent); | ||
} | ||
|
||
public List<Survey> getRecentSurveyList() { | ||
return surveyRepository.findRecentSurvey(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/uk/jinhy/survey_mate_api/survey/application/service/SurveyServiceFacade.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,27 @@ | ||
package uk.jinhy.survey_mate_api.survey.application.service; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import uk.jinhy.survey_mate_api.member.Member; | ||
import uk.jinhy.survey_mate_api.survey.application.dto.SurveyServiceDTO; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class SurveyServiceFacade { | ||
private final SurveyService surveyService; | ||
|
||
@Transactional | ||
public void createSurvey(Member registrant, SurveyServiceDTO.CreateSurveyDTO dto) { | ||
// TODO | ||
// Point 지불하는 로직 필요 | ||
surveyService.createSurvey(registrant, dto); | ||
} | ||
|
||
@Transactional | ||
public void answerSurvey(Member respondent, Long surveyId) { | ||
// TODO | ||
// Point 지급하는 로직 필요 | ||
surveyService.addAnswer(respondent, surveyId); | ||
} | ||
} |
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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/uk/jinhy/survey_mate_api/survey/domain/repository/SurveyRepository.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,22 @@ | ||
package uk.jinhy.survey_mate_api.survey.domain.repository; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import uk.jinhy.survey_mate_api.member.Member; | ||
import uk.jinhy.survey_mate_api.survey.domain.entity.Survey; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface SurveyRepository extends JpaRepository<Survey, Long> { | ||
List<Survey> findByEndedAtIsBefore(Pageable pageable, LocalDateTime time); | ||
Optional<Survey> findBySurveyId(Long id); | ||
Optional<Survey> findByRewardUrl(String url); | ||
@Query("select survey from Survey survey order by survey.createdAt limit 15") | ||
List<Survey> findRecentSurvey(); | ||
List<Survey> findByRegistrant(Member member); | ||
@Query("select survey from Survey survey join Answer answer on survey = answer.survey where answer.respondent = :member") | ||
List<Survey> findByRespondent(Member member); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/uk/jinhy/survey_mate_api/survey/presentation/SurveyController.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,13 @@ | ||
package uk.jinhy.survey_mate_api.survey.presentation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import uk.jinhy.survey_mate_api.survey.application.service.SurveyService; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/survey") | ||
@Controller | ||
public class SurveyController { | ||
private final SurveyService surveyService; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/uk/jinhy/survey_mate_api/survey/presentation/converter/SurveyConverter.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,4 @@ | ||
package uk.jinhy.survey_mate_api.survey.presentation.converter; | ||
|
||
public class SurveyConverter { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/uk/jinhy/survey_mate_api/survey/presentation/dto/SurveyControllerDTO.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,4 @@ | ||
package uk.jinhy.survey_mate_api.survey.presentation.dto; | ||
|
||
public class SurveyControllerDTO { | ||
} |