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 34/rountine api 2 #35

Merged
merged 6 commits into from
Jul 25, 2024
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.controller;

import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.MyRoutineCheck;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggieRoutineReqeuest;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineCheck;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineDelete;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineUpdate;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.RoutineSetting;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyRoutineList;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyVeggieRoutine;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.RoutineMonthChecking;
import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie;
import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine;
import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieRoutineService;
import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager;
import com.modernfarmer.farmusspring.domain.user.entity.User;
import com.modernfarmer.farmusspring.global.response.BaseResponseDto;
import com.modernfarmer.farmusspring.global.response.SuccessCode;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,6 +20,8 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;


Expand All @@ -27,18 +33,31 @@ public class MyVeggieRoutineController {

private final MyVeggieRoutineService myVeggieRoutineService;

@PostMapping(value = "")
public BaseResponseDto<Void> settingMyVeggieRoutine(
@Validated @RequestBody SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest
) {
return myVeggieRoutineService.settingMyVeggieRoutine(settingMyVeggieRoutineReqeuest);
@PostMapping()
public BaseResponseDto<?> settingVeggieRoutine(@Validated @RequestBody RoutineSetting settingRoutine) {
myVeggieRoutineService.settingVeggieRoutine(settingRoutine.getMyVeggieId(), settingRoutine.getContent(), settingRoutine.getPeriod());
log.info("루틴 추가 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS,null);
}

@PatchMapping()
public BaseResponseDto<?> modifyRoutine(@Validated @RequestBody RoutineUpdate routineUpdate) {
myVeggieRoutineService.modifyRoutine(routineUpdate);
log.info("루틴 수정 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS,null);
}

@DeleteMapping
public BaseResponseDto<?> eraseRoutine(@Validated @RequestBody RoutineDelete routineDelete) {
myVeggieRoutineService.eraseRoutine(routineDelete);
log.info("루틴 삭제 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS,null);
}

@PostMapping(value = "/check")
public BaseResponseDto<?> checkMyVeggieRoutine(
@Validated @RequestBody MyRoutineCheck myRoutineCheck
) {
myVeggieRoutineService.checkMyVeggieRoutine(myRoutineCheck.getRoutineId());
public BaseResponseDto<?> checkVeggieRoutine(@Validated @RequestBody RoutineCheck routineCheck) {
myVeggieRoutineService.checkVeggieRoutine(routineCheck.getRoutineId());
log.info("루틴 체킹 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS, null);
}

Expand All @@ -48,17 +67,39 @@ public BaseResponseDto<?> selectMyVeggieRoutineById(
) {
MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build();
List<MyVeggieRoutine> result = myVeggieRoutineService.selectMyVeggieRoutineById(myVeggie);

return BaseResponseDto.of(SuccessCode.SUCCESS, result);
}

@GetMapping(value = "/list")
public BaseResponseDto<?> selectMyVeggieRoutine(
@AuthenticationPrincipal CustomUser user
) {
// @GetMapping(value = "/list")
// public BaseResponseDto<?> selectMyVeggieRoutine(
// @AuthenticationPrincipal CustomUser user
// ) {
// List<MyRoutineList> result = myVeggieRoutineService.selectMyVeggieRoutine(user.getUserId());
// log.info("채소별 리스트 조회 종료");
// return BaseResponseDto.of(SuccessCode.SUCCESS, result);
// }

List<MyRoutineList> result = myVeggieRoutineService.selectMyVeggieRoutine(user.getUserId());
log.info("채소별 리스트 조회 종료");
return BaseResponseDto.of(SuccessCode.SUCCESS, result);
@GetMapping("/month/{month}")
public BaseResponseDto<?> selectRoutineCheckingAccordingToMonth(
@AuthenticationPrincipal CustomUser user,
@PathVariable("month") String month
) throws ParseException {
User userObject = User.builder().id(user.getUserId()).build();
Date parsingDate = DateManager.formatMonthStringToDate(month);
RoutineMonthChecking routineMonthChecking = myVeggieRoutineService.selectRoutineCheckingAccordingToMonth(userObject,parsingDate);
log.info("월 기준 날짜 체킹 상태 조회 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS, routineMonthChecking);
}


@GetMapping("/date/{date}")
public BaseResponseDto<?> selectRoutineAccordingToDate(
@AuthenticationPrincipal CustomUser user,
@PathVariable("date") String date) throws ParseException {
User userObject = User.builder().id(user.getUserId()).build();
Date parsingDate = DateManager.formatDayStringToDate(date);
List<MyRoutineList> myRoutineLists = myVeggieRoutineService.selectRoutineAccordingToDate(userObject, parsingDate);
log.info("날짜별 루틴 조회 완료");
return BaseResponseDto.of(SuccessCode.SUCCESS, myRoutineLists);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor

public class MyRoutineCheck {
public class RoutineCheck {

@NotNull(message = "null 값을 가지면 안됩니다.")
private Long routineId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request;


import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class RoutineDelete {

@NotNull(message = "null 값을 가지면 안됩니다.")
private Long routineId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SettingMyVeggieRoutineReqeuest {
public class RoutineSetting {

@NotNull(message = "null 값을 가지면 안됩니다.")
private String content;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class RoutineUpdate {

@NotNull(message = "null 값을 가지면 안됩니다.")
private String content;


private int period;

@NotNull(message = "null 값을 가지면 안됩니다.")
private Long routineId;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response;

import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie;
import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine;
import lombok.AllArgsConstructor;
Expand All @@ -23,18 +22,17 @@ public class MyRoutineList {

private String nickname;
private String veggieName;
private Long myVeggieId;
private List<MyVeggieRoutine> myVeggieRoutineList;


public static MyRoutineList of(MyVeggie myVeggie, List<MyVeggieRoutine> myVeggieRoutineList){
return new MyRoutineList(
myVeggie.getNickname(),
myVeggie.getVeggieName(),
myVeggieRoutineList
);
myVeggie.getId(),
myVeggieRoutineList);
}


public static List<MyRoutineList> processData(List<MyVeggie> myVeggieList){
return myVeggieList.stream()
.map(myVeggie -> {
Expand All @@ -44,33 +42,18 @@ public static List<MyRoutineList> processData(List<MyVeggie> myVeggieList){
}

private static List<MyVeggieRoutine> checkRoutine(MyVeggie myVeggie){

if(myVeggie.getRoutines().isEmpty()){
return new ArrayList<>();
}
return myVeggie.getRoutines().stream()
.map(routine -> {
boolean check;
check = signRoutineCheck(routine.getDate());
// check = signRoutineCheck(routine.getDate());
check = true;
return new MyVeggieRoutine(check, routine.getContent(), routine.getPeriod(), routine.getId() );
})
})
.toList();
}

private static Boolean signRoutineCheck(Date date){
boolean check = true;
String date1 = String.valueOf(date);
LocalDate currentDate = LocalDate.now();
LocalTime fixedTime = LocalTime.of(0, 0, 0, 0);
LocalDateTime dateTime = LocalDateTime.of(currentDate, fixedTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
String formattedDateTime = dateTime.format(formatter);
if (date1.equals(formattedDateTime)) {
check = false;
}
log.info(String.valueOf(date1));
log.info(String.valueOf(formattedDateTime));
return check;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,25 @@
@Slf4j
public class MyVeggieRoutine {

private Boolean check;
private Boolean complete;
private String content;
private int period;
private Long routineId;


public static MyVeggieRoutine of(Routine routine, Boolean check){
public static MyVeggieRoutine of(Routine routine){
return new MyVeggieRoutine(
check,
routine.isComplete(),
routine.getContent(),
routine.getPeriod(),
routine.getId()
);
routine.getId());
}



public static List<MyVeggieRoutine> processData(List<Routine> routineList){
return routineList.stream()
.map(routine -> {
boolean check;
log.info(String.valueOf(routine.getDate()));
log.info("true/false 체크");
check = signRoutineCheck(routine.getDate());
return MyVeggieRoutine.of(routine, check);
return MyVeggieRoutine.of(routine);
})
.toList();
}


private static Boolean signRoutineCheck(Date date){
boolean check = true;
String date1 = String.valueOf(date);
LocalDate currentDate = LocalDate.now();
LocalTime fixedTime = LocalTime.of(0, 0, 0, 0);
LocalDateTime dateTime = LocalDateTime.of(currentDate, fixedTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
String formattedDateTime = dateTime.format(formatter);
if (date1.equals(formattedDateTime)) {
check = false;
}
log.info(String.valueOf(date1));
log.info(String.valueOf(formattedDateTime));
return check;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response;

import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Slf4j
public class RoutineMonthChecking {

private List<Date> date;

public static RoutineMonthChecking of(List<Date> date){
return new RoutineMonthChecking(date);
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class Routine extends BaseEntity {
@Column(name = "routine_id")
private Long id;

@Column(name = "date")
@Temporal(TemporalType.DATE)
@Column(name = "date", columnDefinition = "DATE")
private Date date;

@Column(name = "content")
Expand All @@ -35,22 +36,22 @@ public class Routine extends BaseEntity {
@Column(name = "period")
private int period;

@Column(name = "notify")
private boolean notify;
@Column(name = "complete")
private boolean complete;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "my_veggie_id")
private MyVeggie myVeggie;


public static Routine createRoutine(Date date, String content, int period, MyVeggie myVeggie, boolean notify){
public static Routine createRoutine(Date date, String content, int period, MyVeggie myVeggie, boolean complete){
Routine newRoutine = Routine.builder()
.date(date)
.content(content)
.period(period)
.myVeggie(myVeggie)
.notify(notify)
.complete(complete)
.build();

myVeggie.addRoutine(newRoutine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom.MyVeggieGardenBaseException;
import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom.RoutineNotFoundException;
import com.modernfarmer.farmusspring.domain.test.exception.TestException;
import com.modernfarmer.farmusspring.global.response.BaseResponseDto;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -13,8 +14,8 @@
@RestControllerAdvice(basePackages = "com.modernfarmer.farmusspring.domain.myveggiegarden.controller")
public class MyVeggieGardenExceptionHandler {

@ExceptionHandler(RoutineNotFountException.class)
public BaseResponseDto<?> handleRoutineNotFoundException(RoutineNotFountException e, HttpServletRequest request) {
@ExceptionHandler(RoutineNotFoundException.class)
public BaseResponseDto<?> handleRoutineNotFoundException(RoutineNotFoundException e, HttpServletRequest request) {
log.error("RoutineException : {} {} errMessage={}\n",
request.getMethod(),
request.getRequestURI(),
Expand Down
Loading
Loading