Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#53-seed-scrap-patch-api
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 authored Jan 4, 2024
2 parents e685cf2 + 2d112f0 commit 56299f2
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 22 deletions.
2 changes: 1 addition & 1 deletion growthookServer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ out/

resources
../.DS_Store
.DS_Store
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.example.growthookserver.api.actionplan.dto.request.ActionPlanCreateRequestDto;
import com.example.growthookserver.api.actionplan.dto.request.ActionPlanUpdateRequestDto;
import com.example.growthookserver.api.actionplan.dto.response.ActionPlanCreateResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.ActionPlanGetResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.DoingActionPlanGetResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.FinishedActionPlanGetResponseDto;
Expand All @@ -27,8 +26,9 @@ public class ActionPlanController {
@PostMapping("seed/{seedId}/actionPlan")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "ActionPlanPost",description = "액션 플랜 생성 API입니다.")
public ApiResponse<ActionPlanCreateResponseDto> createActionPlan(@PathVariable("seedId")Long seedId, @Valid @RequestBody ActionPlanCreateRequestDto actionPlanCreateRequestDto) {
return ApiResponse.success(SuccessStatus.POST_ACTIONPLAN_SUCCESS, actionPlanService.createActionPlan(seedId, actionPlanCreateRequestDto));
public ApiResponse createActionPlan(@PathVariable("seedId")Long seedId, @Valid @RequestBody ActionPlanCreateRequestDto actionPlanCreateRequestDto) {
actionPlanService.createActionPlan(seedId, actionPlanCreateRequestDto);
return ApiResponse.success(SuccessStatus.POST_ACTIONPLAN_SUCCESS.getStatusCode(), SuccessStatus.POST_ACTIONPLAN_SUCCESS.getMessage());
}

@GetMapping("seed/{seedId}/actionPlan")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.example.growthookserver.api.actionplan.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ActionPlanCreateRequestDto {
@NotBlank
@NotNull
@Size(max = 40)
private String content;
private List<String> contents;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.example.growthookserver.api.actionplan.dto.request.ActionPlanCreateRequestDto;
import com.example.growthookserver.api.actionplan.dto.request.ActionPlanUpdateRequestDto;
import com.example.growthookserver.api.actionplan.dto.response.ActionPlanCreateResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.ActionPlanGetResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.DoingActionPlanGetResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.FinishedActionPlanGetResponseDto;
Expand All @@ -11,7 +10,7 @@

public interface ActionPlanService {
//* 액션플랜 생성
ActionPlanCreateResponseDto createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto);
void createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto);

//* 씨앗 별 액션 플랜 조회
List<ActionPlanGetResponseDto> getActionPlan(Long seedId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import com.example.growthookserver.api.actionplan.domain.ActionPlan;
import com.example.growthookserver.api.actionplan.dto.request.ActionPlanCreateRequestDto;
import com.example.growthookserver.api.actionplan.dto.request.ActionPlanUpdateRequestDto;
import com.example.growthookserver.api.actionplan.dto.response.ActionPlanCreateResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.ActionPlanGetResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.DoingActionPlanGetResponseDto;
import com.example.growthookserver.api.actionplan.dto.response.FinishedActionPlanGetResponseDto;
import com.example.growthookserver.api.actionplan.repository.ActionPlanRepository;
import com.example.growthookserver.api.actionplan.service.ActionPlanService;
import com.example.growthookserver.api.member.domain.Member;
import com.example.growthookserver.api.seed.domain.Seed;
import com.example.growthookserver.api.seed.repository.SeedRepository;
import com.example.growthookserver.common.exception.BadRequestException;
import com.example.growthookserver.common.response.ErrorStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -30,14 +32,14 @@ public class ActionPlanServiceImpl implements ActionPlanService {

@Override
@Transactional
public ActionPlanCreateResponseDto createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto){
public void createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto){
Seed seed = seedRepository.findSeedByIdOrThrow(seedId);
ActionPlan actionPlan = ActionPlan.builder()
.content(actionPlanCreateRequestDto.getContent())
.seed(seed)
.build();
ActionPlan savedActionPlan = actionPlanRepository.save(actionPlan);
return ActionPlanCreateResponseDto.of(savedActionPlan.getId());

List<String> contents = actionPlanCreateRequestDto.getContents();

contents.stream()
.map(content -> ActionPlan.builder().content(content).seed(seed).build())
.forEach(actionPlanRepository::save);
}

@Override
Expand Down Expand Up @@ -67,7 +69,13 @@ public void deleteActionPlan(Long actionPlanId) {
@Transactional
public void completeActionPlan(Long actionPlanId) {
ActionPlan existinActionPlan = actionPlanRepository.findActionPlanByIdOrThrow(actionPlanId);
if(existinActionPlan.getIsFinished()) {
throw new BadRequestException(ErrorStatus.ALREADY_COMPLETE_ACTIONPLAN.getMessage());
}
existinActionPlan.completeActionPlan(true);

Member member = existinActionPlan.getSeed().getCave().getMember();
member.incrementGatheredSsuk();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public Member(String nickname, String email, SocialPlatform socialPlatform, Bool
this.usedSsuk = usedSsuk;
this.gatheredSsuk = gatheredSsuk;
}

@Builder
public void incrementGatheredSsuk() {
this.gatheredSsuk = (this.gatheredSsuk == null ? 0 : this.gatheredSsuk) + 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.growthookserver.api.seed.dto.request.SeedMoveRequestDto;
import com.example.growthookserver.api.seed.dto.request.SeedCreateRequestDto;
import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto;
import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedCreateResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedDetailGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedListGetResponseDto;
Expand Down Expand Up @@ -86,4 +87,11 @@ public ApiResponse toggleSeedScrapStatus(@PathVariable Long seedId) {
return ApiResponse.success(SuccessStatus.TOGGLE_SEED_SCRAP_STATUS.getStatusCode(), SuccessStatus.TOGGLE_SEED_SCRAP_STATUS.getMessage());
}

@GetMapping("member/{memberId}/alarm")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "SeedAlarm", description = "기한이 3일 이내로 남은 씨앗에 대한 알림을 조회하는 API입니다.")
public ApiResponse<SeedAlarmGetResponseDto> getSeedAlarm(@PathVariable Long memberId) {
return ApiResponse.success(SuccessStatus.GET_SEED_ALARM, seedService.getSeedAlarm(memberId));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.growthookserver.api.actionplan.dto.response;
package com.example.growthookserver.api.seed.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -8,7 +8,6 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(staticName = "of")
public class ActionPlanCreateResponseDto {

private Long actionPlanId;
public class SeedAlarmGetResponseDto {
private int seedCount;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.example.growthookserver.api.seed.repository;

import com.example.growthookserver.api.cave.domain.Cave;
import com.example.growthookserver.api.seed.domain.Seed;
import com.example.growthookserver.common.exception.NotFoundException;
import com.example.growthookserver.common.response.ErrorStatus;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -18,4 +18,6 @@ default Seed findSeedByIdOrThrow(Long seedId) {
return findSeedById(seedId)
.orElseThrow(()-> new NotFoundException(ErrorStatus.NOT_FOUND_SEED.getMessage()));
}

List<Seed> findByCave_MemberIdAndLockDateBetween(Long memberId, LocalDate now, LocalDate threeDaysLater);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.example.growthookserver.api.seed.dto.request.SeedCreateRequestDto;
import com.example.growthookserver.api.seed.dto.request.SeedMoveRequestDto;
import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto;
import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedCreateResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedDetailGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedListGetResponseDto;
Expand All @@ -17,11 +18,14 @@
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -97,6 +101,22 @@ public List<SeedListGetResponseDto> getSeedList(Long memberId) {
seed.getIsLocked(), seed.getIsScraped(), checkHasActionPlan(seed)))
.collect(Collectors.toList());
}

@Override
public SeedAlarmGetResponseDto getSeedAlarm(Long memberId) {
LocalDate now = LocalDate.now();
LocalDate threeDaysLater = now.plusDays(3);

List<Seed> seeds = seedRepository.findByCave_MemberIdAndLockDateBetween(memberId, now, threeDaysLater);

if(seeds.isEmpty()) {
return SeedAlarmGetResponseDto.of(0);
}

int seedCount = seeds.size();

return SeedAlarmGetResponseDto.of(seedCount);
}

@Override
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.example.growthookserver.api.seed.dto.request.SeedCreateRequestDto;
import com.example.growthookserver.api.seed.dto.request.SeedMoveRequestDto;
import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto;
import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedCreateResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedDetailGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedListGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto;
import java.util.List;

import java.time.LocalDate;

public interface SeedService {
//* 씨앗 생성
SeedCreateResponseDto createSeed(Long caveId, SeedCreateRequestDto seedCreateRequestDto);
Expand All @@ -33,4 +36,8 @@ public interface SeedService {

//* 씨앗 스크랩 상태 변경
void toggleSeedScrapStatus(Long seedId);

//* 씨앗 알림 조회
SeedAlarmGetResponseDto getSeedAlarm(Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum ErrorStatus {
NO_TOKEN("토큰을 넣어주세요."),
INVALID_MEMBER("유효하지 않은 유저입니다."),
ANOTHER_ACCESS_TOKEN("지원하지 않는 소셜 플랫폼입니다."),
ALREADY_COMPLETE_ACTIONPLAN("이미 완료된 액션 플랜입니다."),

/**
* 401 UNAUTHORIZED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum SuccessStatus {
GET_SEED_LIST_BY_CAVE(HttpStatus.OK, "보관함별로 씨앗 리스트 조회 성공"),
GET_SEED_LIST(HttpStatus.OK, "전체 씨앗 리스트 조회 성공" ),
TOGGLE_SEED_SCRAP_STATUS(HttpStatus.OK, "씨앗 스크랩 여부 토글 전환 성공"),
GET_SEED_ALARM(HttpStatus.OK,"씨앗 알람 조회 성공"),

/**
* actionplan
Expand Down

0 comments on commit 56299f2

Please sign in to comment.