-
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 #30 from survey-mate/feat/28
feat: Data 도메인 및 DataService 일부 구현 #28
- Loading branch information
Showing
11 changed files
with
182 additions
and
7 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/uk/jinhy/survey_mate_api/data/application/dto/DataServiceDTO.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,24 @@ | ||
package uk.jinhy.survey_mate_api.data.application.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
public class DataServiceDTO { | ||
@Builder | ||
@Getter | ||
public static class CreateDataDTO { | ||
private String title; | ||
private String description; | ||
private Long price; | ||
private String fileUrl; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
public static class EditDataDTO { | ||
private Long dataId; | ||
private String title; | ||
private String description; | ||
private String fileUrl; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/uk/jinhy/survey_mate_api/data/application/service/DataService.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,78 @@ | ||
package uk.jinhy.survey_mate_api.data.application.service; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import uk.jinhy.survey_mate_api.data.application.dto.DataServiceDTO; | ||
import uk.jinhy.survey_mate_api.data.domain.entity.Data; | ||
import uk.jinhy.survey_mate_api.data.domain.entity.PurchaseHistory; | ||
import uk.jinhy.survey_mate_api.data.domain.repository.DataRepository; | ||
import uk.jinhy.survey_mate_api.member.Member; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class DataService { | ||
private final DataRepository dataRepository; | ||
|
||
public Data createData(Member seller, DataServiceDTO.CreateDataDTO dto) { | ||
Data data = Data.builder() | ||
.seller(seller) | ||
.fileUrl(dto.getFileUrl()) | ||
.title(dto.getTitle()) | ||
.description(dto.getDescription()) | ||
.price(dto.getPrice()) | ||
.seller(seller) | ||
.build(); | ||
dataRepository.save(data); | ||
return data; | ||
} | ||
|
||
@Transactional | ||
public void editData(Member seller, DataServiceDTO.EditDataDTO dto) { | ||
Long dataId = dto.getDataId(); | ||
|
||
Data data = dataRepository.findByDataId(dataId).get(); | ||
if(!data.getSeller().equals(seller)) { return; } | ||
|
||
String newTitle = dto.getTitle(); | ||
if(newTitle != null) { data.updateTitle(newTitle); } | ||
|
||
String newDescription = dto.getDescription(); | ||
if(newDescription != null) { data.updateDescription(newDescription); } | ||
|
||
String newFileUrl = dto.getFileUrl(); | ||
if(newFileUrl != null) { data.updateFileUrl(newFileUrl); } | ||
|
||
dataRepository.save(data); | ||
} | ||
|
||
@Transactional | ||
public void deleteData(Member seller, Long dataId) { | ||
Data data = dataRepository.findByDataId(dataId).get(); | ||
if(data.getSeller().equals(seller)) { | ||
dataRepository.deleteById(dataId); | ||
} | ||
} | ||
|
||
@Transactional | ||
public void buyData(Member buyer, Long dataId) { | ||
Data data = dataRepository.findByDataId(dataId).get(); | ||
|
||
PurchaseHistory purchaseHistory = PurchaseHistory.builder() | ||
.data(data) | ||
.buyer(buyer) | ||
.build(); | ||
data.addPurchaseHistory(purchaseHistory); | ||
dataRepository.save(data); | ||
} | ||
|
||
public Data getData(Long dataId) { return dataRepository.findByDataId(dataId).get(); } | ||
|
||
public List<Data> getDataListAsBuyer(Member buyer) { return dataRepository.findByBuyer(buyer); } | ||
|
||
public List<Data> getDataListAsSeller(Member seller) { return dataRepository.findByBuyer(seller); } | ||
|
||
public List<Data> getRecentDataList() { return dataRepository.findRecentData(); } | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/uk/jinhy/survey_mate_api/data/application/service/DataServiceFacade.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,21 @@ | ||
package uk.jinhy.survey_mate_api.data.application.service; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import uk.jinhy.survey_mate_api.data.application.dto.DataServiceDTO; | ||
import uk.jinhy.survey_mate_api.member.Member; | ||
import uk.jinhy.survey_mate_api.survey.application.dto.SurveyServiceDTO; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class DataServiceFacade { | ||
private final DataService dataService; | ||
|
||
@Transactional | ||
public void buyData(Member buyer, Long dataId) { | ||
// TODO | ||
// Point 결제 로직 필요 | ||
dataService.buyData(buyer, dataId); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/uk/jinhy/survey_mate_api/data/domain/repository/DataRepository.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,18 @@ | ||
package uk.jinhy.survey_mate_api.data.domain.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import uk.jinhy.survey_mate_api.data.domain.entity.Data; | ||
import uk.jinhy.survey_mate_api.member.Member; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface DataRepository extends JpaRepository<Data, Long> { | ||
Optional<Data> findByDataId(Long id); | ||
List<Data> findBySeller(Member member); | ||
@Query("select data from Data data join PurchaseHistory purchase_history on data = purchase_history.data where purchase_history.buyer = :member") | ||
List<Data> findByBuyer(Member member); | ||
@Query("select data from Data data order by data.createdAt limit 15") | ||
List<Data> findRecentData(); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/uk/jinhy/survey_mate_api/data/presentation/DataController.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.data.presentation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import uk.jinhy.survey_mate_api.data.application.service.DataService; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/data") | ||
@Controller | ||
public class DataController { | ||
private final DataService dataService; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/uk/jinhy/survey_mate_api/data/presentation/converter/DataConverter.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.data.presentation.converter; | ||
|
||
public class DataConverter { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/uk/jinhy/survey_mate_api/data/presentation/dto/DataControllerDTO.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.data.presentation.dto; | ||
|
||
public class DataControllerDTO { | ||
} |
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