Skip to content

Commit

Permalink
Merge pull request #106 from UMC-CommonPlant/feat/#74_Calendar
Browse files Browse the repository at this point in the history
[Feat] Calendar: 월별 조회
  • Loading branch information
sonshn authored Aug 28, 2024
2 parents 2a2a94c + 5e6c5a9 commit e97e9a0
Show file tree
Hide file tree
Showing 11 changed files with 602 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ dependencies {
//validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

//envers
implementation 'org.springframework.data:spring-data-envers'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.umc.commonplant.domain.calendar.controller;

import com.umc.commonplant.domain.Jwt.JwtService;
import com.umc.commonplant.domain.calendar.dto.CalendarDto;
import com.umc.commonplant.domain.calendar.service.CalendarService;
import com.umc.commonplant.domain.memo.dto.MemoDto;
import com.umc.commonplant.domain.place.dto.PlaceDto;
import com.umc.commonplant.domain.plant.dto.PlantDto;
import com.umc.commonplant.domain.user.entity.User;
import com.umc.commonplant.domain.user.service.UserService;
import com.umc.commonplant.global.dto.JsonResponse;
import io.swagger.v3.core.util.Json;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/calendar")
@RequiredArgsConstructor
@RestController
public class CalendarController {

private final CalendarService calendarService;
private final JwtService jwtService;
private final UserService userService;

@GetMapping
public ResponseEntity<JsonResponse> getCalendarByDate(@RequestParam("year") String year,
@RequestParam("month") String month,
@RequestParam("day") String day) {

return ResponseEntity.ok(new JsonResponse(true, 200, "getCalendarByDate", null));
}

@GetMapping("/monthly")
public ResponseEntity<JsonResponse> getCalendarByMonth(@RequestParam("year") String year,
@RequestParam("month") String month) {
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

CalendarDto.getMyCalendarRes monthlyCalendar = calendarService.getMyCalendar(user, year, month);

return ResponseEntity.ok(new JsonResponse(true, 200, "getCalendarByMonth", monthlyCalendar));
}

@GetMapping("/place")
public ResponseEntity<JsonResponse> getCalendarByPlace() {
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

List<CalendarDto.getMyCalendarPlaceListRes> placeList = calendarService.getPlaceNameListByUser(user);

return ResponseEntity.ok(new JsonResponse(true, 200, "getPlaceList", placeList));
}

@GetMapping("/place/plant")
public ResponseEntity<JsonResponse> getCalendarByPlaceAndPlant(@RequestParam("code") String code) {
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

List<CalendarDto.getMyCalendarPlantListRes> plantList = calendarService.getPlantListByPlace(user, code);

return ResponseEntity.ok(new JsonResponse(true, 200, "getPlantList", plantList));
}

@GetMapping("/place/plant/memo")
public ResponseEntity<JsonResponse> getCalendarByPlaceAndPlantAndMemo(@RequestParam("code") String code,
@RequestParam("plant") Long plantIdx) {
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

List<CalendarDto.getMyCalendarMemoRes> memoList = calendarService.getAllMemoByPlant(plantIdx);

return ResponseEntity.ok(new JsonResponse(true, 200, "getMemoList", memoList));
}

}
107 changes: 107 additions & 0 deletions src/main/java/com/umc/commonplant/domain/calendar/dto/CalendarDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.umc.commonplant.domain.calendar.dto;

import com.umc.commonplant.domain.plant.entity.Plant;
import lombok.*;

import java.time.LocalDateTime;
import java.util.List;

public class CalendarDto {

/**
* 최종 My Calendar Response
*/
@NoArgsConstructor
@Getter
public static class getMyCalendarRes{
private String year;
private String month;

private List<getMyCalendarEventRes> dateList;

@Builder
public getMyCalendarRes(String year, String month, List<getMyCalendarEventRes> dateList) {
this.year = year;
this.month = month;
this.dateList = dateList;
}
}

/**
* 날짜 별로 불러오는 My Calendar 정보
*/
@NoArgsConstructor
@Getter
public static class getMyCalendarEventRes {
private int parsedDate;
// @JsonFormat(pattern = "yyyy.MM.dd")
// private LocalDateTime date;

private boolean nextWatered;
private boolean prevWatered;
private boolean joinPlant;
private boolean writeMemo;

@Builder
public getMyCalendarEventRes(int parsedDate, boolean nextWatered, boolean prevWatered,
boolean joinPlant, boolean writeMemo) {
this.parsedDate = parsedDate;
this.nextWatered = nextWatered;
this.prevWatered = prevWatered;
this.joinPlant = joinPlant;
this.writeMemo = writeMemo;
}
}

/**
* My Calendar에 보여줄 Place 리스트
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
public static class getMyCalendarPlaceListRes{
private String name;
}

/**
* My Calendar에 보여줄 Plant 리스트
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
public static class getMyCalendarPlantListRes{
private String plantName;
private String nickname;
private String imgUrl;

@Builder
public getMyCalendarPlantListRes(Plant plant){
this.plantName = plant.getPlantName();
this.nickname = plant.getNickname();
this.imgUrl = plant.getImgUrl();
}
}

/**
* My Calendar에 보여줄 Memo 리스트
*/
@NoArgsConstructor
@Getter
public static class getMyCalendarMemoRes {
private Long memo_idx;
private String content;
private String imgUrl;
private String writer;
private LocalDateTime created_at;

@Builder
public getMyCalendarMemoRes(Long memo_idx, String content, String imgUrl, String writer, LocalDateTime created_at) {
this.memo_idx = memo_idx;
this.content = content;
this.imgUrl = imgUrl;
this.writer = writer;
this.created_at = created_at;
}
}

}
Loading

0 comments on commit e97e9a0

Please sign in to comment.