Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 12/팜클럽 리팩토링 #19

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/com/example/farmusfarm/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ public static String dateTimeFormat(String dateTime) {

return month + "/" + day + " " + hour + ":" + minute;
}

// mm/dd/yy, hh:mm PM -> yyyy년 mm월 dd일
public static String dateTimeToDateFormat(String dateTime) {
String[] dateTimeArr = dateTime.split(" ");
String[] dateArr = dateTimeArr[0].split("/");

String month = dateArr[0];
String day = dateArr[1];
String year = dateArr[2].substring(0, 2);


return "20" + year + "년 " + month + "월 " + day + "일";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public BaseResponseDto<?> createRegistration(

@PostMapping("/mission")
public BaseResponseDto<?> createMissionPost(
@RequestPart("image") MultipartFile image,
@RequestParam("registrationId") Long registrationId,
@RequestParam("content") String content,
@RequestPart("image") MultipartFile image
@RequestParam("content") String content
) {
return BaseResponseDto.of(SuccessMessage.CREATED, missionPostService.createMissionPost(registrationId, content, image));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Getter
public class GetChallengeInfoResponse {

private Long challengeId;
private String veggieInfoId;

private String challengeName;
Expand All @@ -30,5 +31,5 @@ public class GetChallengeInfoResponse {
private String stepTip;
private List<String> stepImages;

private List<GetDiaryResponseDto> diaries;
private Boolean isRegistered;
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public GetChallengeInfoResponse getMyChallengeInfo(Long userId, Long challengeId
String tip = response.get(registration.getCurrentStep()).getTip();

return GetChallengeInfoResponse.of(
challengeId,
challenge.getVeggieInfoId(),
challenge.getChallengeName(),
challenge.getVeggieName(),
Expand All @@ -273,7 +274,7 @@ public GetChallengeInfoResponse getMyChallengeInfo(Long userId, Long challengeId
registration.getCurrentStepName(),
tip,
imageList,
getDiaryListByChallenge(challengeId)
true
);
}

Expand All @@ -293,6 +294,7 @@ public GetChallengeInfoResponse getOtherChallengeInfo(Long challengeId, String t
});

return GetChallengeInfoResponse.of(
challengeId,
challenge.getVeggieInfoId(),
challenge.getChallengeName(),
challenge.getVeggieName(),
Expand All @@ -307,7 +309,7 @@ public GetChallengeInfoResponse getOtherChallengeInfo(Long challengeId, String t
"준비물을 챙겨요",
tip,
imageList,
null
false
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public BaseResponseDto<?> createRoutine(

@PostMapping("/diary")
public BaseResponseDto<?> createDiary(
@RequestPart("content") final CreateDiaryRequestDto requestDto,
@RequestPart("image") final MultipartFile image
@RequestPart("image") final MultipartFile image,
@RequestParam("veggieId") final Long veggieId,
@RequestParam("content") final String content,
@RequestParam("isOpen") final Boolean isOpen
) {
return BaseResponseDto.of(SuccessMessage.CREATED, diaryService.createDiary(requestDto, image));
return BaseResponseDto.of(SuccessMessage.CREATED, diaryService.createDiary(veggieId, content, isOpen, image));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
public class CreateRoutineResponseDto {

private Long id;
private String date;
private String content;
private int period;
private Boolean isDone;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class GetMyDiaryResponseDto {
private Long diaryId;
private String content;
private String image;
private String date;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void updatePeriod(int period) {
}

public void updateDone() {
this.isDone = !this.isDone;
this.isDone = true;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.farmusfarm.domain.veggie.service;

import com.example.farmusfarm.common.S3Service;
import com.example.farmusfarm.common.Utils;
import com.example.farmusfarm.domain.challenge.dto.res.LikeMissionPostResponseDto;
import com.example.farmusfarm.domain.challenge.entity.MissionPost;
import com.example.farmusfarm.domain.challenge.entity.MissionPostLike;
Expand Down Expand Up @@ -38,15 +39,15 @@ public class DiaryService {
private final S3Service s3Service;

// 일기 생성
public CreateDiaryResponseDto createDiary(CreateDiaryRequestDto requestDto, MultipartFile image) {
Veggie veggie = veggieRepository.findById(requestDto.getVeggieId())
public CreateDiaryResponseDto createDiary(Long veggieId, String content, Boolean isOpen, MultipartFile image) {
Veggie veggie = veggieRepository.findById(veggieId)
.orElseThrow(()-> new IllegalArgumentException("채소가 존재하지 않습니다."));

Diary diary;
if (veggie.getRegistration() != null && requestDto.getIsOpen()) {
diary = Diary.createDiaryWithChallenge(requestDto.getContent(), true, veggie, veggie.getRegistration().getChallenge());
if (veggie.getRegistration() != null && isOpen) {
diary = Diary.createDiaryWithChallenge(content, true, veggie, veggie.getRegistration().getChallenge());
} else {
diary = Diary.createDiary(requestDto.getContent(), veggie);
diary = Diary.createDiary(content, veggie);
}
Diary newDiary = diaryRepository.save(diary);

Expand All @@ -60,7 +61,12 @@ public CreateDiaryResponseDto createDiary(CreateDiaryRequestDto requestDto, Mult
public List<GetMyDiaryResponseDto> getVeggieDiaryList(Long veggieId) {
List<Diary> diaries = getDiaryByVeggieId(veggieId);
return diaries.stream()
.map(diary -> GetMyDiaryResponseDto.of(diary.getId(), diary.getContent(), diary.getDiaryImages().get(0).getImageUrl()))
.map(diary -> GetMyDiaryResponseDto.of(
diary.getId(),
diary.getContent(),
diary.getDiaryImages().get(0).getImageUrl(),
Utils.dateTimeToDateFormat(diary.getCreatedDate())
))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CreateRoutineResponseDto createNewRoutine(CreateRoutineRequestDto request
Veggie veggie = getVeggie(requestDto.getVeggieId());
Routine newRoutine = createRoutine(requestDto.getDate(), requestDto.getContent(), 0, veggie);

return CreateRoutineResponseDto.of(newRoutine.getId());
return CreateRoutineResponseDto.of(newRoutine.getId(), newRoutine.getDate().toString(), newRoutine.getContent(), newRoutine.getPeriod(), false);
}

// 채소 정보 조회
Expand Down Expand Up @@ -148,6 +148,16 @@ public CheckRoutineResponseDto checkRoutine(CheckRoutineRequestDto requestDto) {
Routine routine = getRoutine(requestDto.getRoutineId());
routine.updateDone();

if (routine.getPeriod() != 0) {
Routine newRoutine = createRoutine(
LocalDate.now().plusDays(routine.getPeriod()).toString(),
routine.getContent(),
routine.getPeriod(),
routine.getVeggie()
);
routineRepository.save(newRoutine);
}

return CheckRoutineResponseDto.of(routine.getId(), routine.getIsDone());
}

Expand Down
Loading