Skip to content

Commit

Permalink
Merge pull request #33 from Mojacknong/feature_16/History-도메인-개발
Browse files Browse the repository at this point in the history
Feature 16/history 도메인 개발
  • Loading branch information
MinchoGreenT authored Jul 25, 2024
2 parents 07e2f47 + 4f30d03 commit d314b94
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.modernfarmer.farmusspring.domain.history.controller;

import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser;
import com.modernfarmer.farmusspring.domain.history.service.HistoryService;
import com.modernfarmer.farmusspring.global.response.BaseResponseDto;
import com.modernfarmer.farmusspring.global.response.SuccessCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@Slf4j
Expand All @@ -19,20 +21,34 @@ public class HistoryController {
public BaseResponseDto<?> getUserHistory(
@PathVariable Long id
) {
return BaseResponseDto.of(SuccessCode.SUCCESS ,historyService.getUserHistory(id));
return BaseResponseDto.of(SuccessCode.SUCCESS, historyService.getUserHistory(id));
}

@GetMapping("/farmclub/{id}")
public void getFarmClubHistory(
@PathVariable Long id
@GetMapping("/farmclub")
public BaseResponseDto<?> getFarmClubHistories(
@AuthenticationPrincipal CustomUser user
) {
return ;
return BaseResponseDto.of(SuccessCode.SUCCESS, historyService.getFarmClubHistories(user.getUserId()));
}

@GetMapping("/veggie/{id}")
public void getVeggieHistory(
@PathVariable Long id
@GetMapping("/farmclub/{detailId}")
public BaseResponseDto<?> getFarmClubHistoryDetail(
@PathVariable String detailId
) {
return BaseResponseDto.of(SuccessCode.SUCCESS, historyService.getFarmClubHistoryDetail(detailId));
}

@GetMapping("/veggie")
public BaseResponseDto<?> getVeggieHistories(
@AuthenticationPrincipal CustomUser user
) {
return BaseResponseDto.of(SuccessCode.SUCCESS, historyService.getVeggieHistories(user.getUserId()));
}

@GetMapping("/veggie/{detailId}")
public BaseResponseDto<?> getVeggieHistoryDetail(
@PathVariable String detailId
) {
return ;
return BaseResponseDto.of(SuccessCode.SUCCESS, historyService.getVeggieHistoryDetail(detailId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,29 @@ public class History extends BaseDocument {
private ObjectId id;

private Long userId;

private List<Icon> veggieHistoryIcons;
private List<Icon> farmClubHistoryIcons;

private List<Detail> veggieHistoryDetails;
private List<Detail> farmClubHistoryDetails;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
public static class Icon {
private String url;
private String backgroundColor;

public static Icon createIcon(String url, String backgroundColor) {
return Icon.builder()
.url(url)
.backgroundColor(backgroundColor)
.build();
}
}

@AllArgsConstructor
@NoArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.modernfarmer.farmusspring.domain.history.dto.res;

import com.modernfarmer.farmusspring.domain.history.document.HistoryFarmClubDetail;
import lombok.AccessLevel;
import lombok.Builder;

import java.util.List;

@Builder(access = AccessLevel.PRIVATE)
public record FarmClubHistoryDetailResponseDto(
List<HistoryFarmClubDetail.HistoryClubPost> missionPosts
) {
public static FarmClubHistoryDetailResponseDto of(List<HistoryFarmClubDetail.HistoryClubPost> missionPosts) {
return builder()
.missionPosts(missionPosts)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.modernfarmer.farmusspring.domain.history.dto.res;

import com.modernfarmer.farmusspring.domain.history.document.History;
import lombok.AccessLevel;
import lombok.Builder;

import java.util.List;

@Builder(access = AccessLevel.PRIVATE)
public record FarmClubHistoryListResponseDto(
List<History.Detail> farmClubHistoryList
) {
public static FarmClubHistoryListResponseDto of(List<History.Detail> farmClubHistoryList) {
return builder()
.farmClubHistoryList(farmClubHistoryList)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

@Builder(access = AccessLevel.PRIVATE)
public record HistoryResponseDto(
List<History.Detail> veggieHistoryList,
List<History.Detail> farmClubHistoryList
String historyId,
int veggieHistoryCount,
int farmClubHistoryCount,
List<History.Icon> veggieHistoryIcons,
List<History.Icon> farmClubHistoryIcons
) {
public static HistoryResponseDto of(History history) {
return HistoryResponseDto.builder()
.veggieHistoryList(history.getVeggieHistoryDetails())
.farmClubHistoryList(history.getFarmClubHistoryDetails())
return builder()
.historyId(history.getId().toHexString())
.veggieHistoryCount(history.getVeggieHistoryDetails().size())
.farmClubHistoryCount(history.getFarmClubHistoryDetails().size())
.veggieHistoryIcons(history.getVeggieHistoryIcons())
.farmClubHistoryIcons(history.getFarmClubHistoryIcons())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.modernfarmer.farmusspring.domain.history.dto.res;

import com.modernfarmer.farmusspring.domain.history.document.HistoryVeggieDetail;
import lombok.AccessLevel;
import lombok.Builder;

import java.util.List;

@Builder(access = AccessLevel.PRIVATE)
public record VeggieHistoryDetailResponseDto(
List<HistoryVeggieDetail.HistoryPost> diaries,
HistoryVeggieDetail.HistoryPost farmResult
) {
public static VeggieHistoryDetailResponseDto of(List<HistoryVeggieDetail.HistoryPost> diaries, HistoryVeggieDetail.HistoryPost farmResult) {
return builder()
.diaries(diaries)
.farmResult(farmResult)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.modernfarmer.farmusspring.domain.history.dto.res;

import com.modernfarmer.farmusspring.domain.history.document.History;
import lombok.AccessLevel;
import lombok.Builder;

import java.util.List;

@Builder(access = AccessLevel.PRIVATE)
public record VeggieHistoryListResponseDto(
List<History.Detail> veggieHistoryList
) {
public static VeggieHistoryListResponseDto of(List<History.Detail> veggieHistoryList) {
return builder()
.veggieHistoryList(veggieHistoryList)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public History getUserHistory(Long userId) {
.orElseThrow(() -> new HistoryEntityNotFoundException("해당 유저의 히스토리가 존재하지 않습니다.", HistoryErrorCode.ENTITY_NOT_FOUND));
}

public HistoryFarmClubDetail getFarmClubHistoryDetail(ObjectId farmClubDetailId) {
return historyFarmClubDetailRepository.findById(farmClubDetailId)
public HistoryFarmClubDetail getFarmClubHistoryDetail(String farmClubDetailId) {
return historyFarmClubDetailRepository.findById(new ObjectId(farmClubDetailId))
.orElseThrow(() -> new HistoryEntityNotFoundException("해당 팜클럽 히스토리가 존재하지 않습니다.", HistoryErrorCode.ENTITY_NOT_FOUND));
}

public HistoryVeggieDetail getVeggieHistoryDetail(ObjectId veggieDetailId) {
return historyVeggieDetailRepository.findById(veggieDetailId)
public HistoryVeggieDetail getVeggieHistoryDetail(String veggieDetailId) {
return historyVeggieDetailRepository.findById(new ObjectId(veggieDetailId))
.orElseThrow(() -> new HistoryEntityNotFoundException("해당 채소 히스토리가 존재하지 않습니다.", HistoryErrorCode.ENTITY_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.modernfarmer.farmusspring.domain.history.service;

import com.modernfarmer.farmusspring.domain.history.document.History;
import com.modernfarmer.farmusspring.domain.history.dto.res.HistoryResponseDto;
import com.modernfarmer.farmusspring.domain.history.document.HistoryFarmClubDetail;
import com.modernfarmer.farmusspring.domain.history.document.HistoryVeggieDetail;
import com.modernfarmer.farmusspring.domain.history.dto.res.*;
import com.modernfarmer.farmusspring.domain.history.helper.HistoryHelper;
import com.modernfarmer.farmusspring.domain.history.repository.HistoryRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
@Slf4j
@RequiredArgsConstructor
Expand All @@ -20,4 +24,24 @@ public HistoryResponseDto getUserHistory(Long userId) {
History history = historyHelper.getUserHistory(userId);
return HistoryResponseDto.of(history);
}

public VeggieHistoryDetailResponseDto getVeggieHistoryDetail(String detailId) {
HistoryVeggieDetail historyVeggieDetail = historyHelper.getVeggieHistoryDetail(detailId);
return VeggieHistoryDetailResponseDto.of(historyVeggieDetail.getDiaryPosts(), historyVeggieDetail.getFarmResult());
}

public VeggieHistoryListResponseDto getVeggieHistories(Long userId) {
History history = historyHelper.getUserHistory(userId);
return VeggieHistoryListResponseDto.of(history.getVeggieHistoryDetails());
}

public FarmClubHistoryDetailResponseDto getFarmClubHistoryDetail(String detailId) {
HistoryFarmClubDetail historyFarmClubDetail = historyHelper.getFarmClubHistoryDetail(detailId);
return FarmClubHistoryDetailResponseDto.of(historyFarmClubDetail.getMissionPostList());
}

public FarmClubHistoryListResponseDto getFarmClubHistories(Long userId) {
History history = historyHelper.getUserHistory(userId);
return FarmClubHistoryListResponseDto.of(history.getFarmClubHistoryDetails());
}
}

0 comments on commit d314b94

Please sign in to comment.