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] 리마인드 관련 API 개발 #26

Merged
merged 12 commits into from
Jan 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.app.toaster.controller.response.category.GetCategoryResponseDto;
import com.app.toaster.exception.Success;
import com.app.toaster.service.category.CategoryService;
import com.app.toaster.service.search.SearchService;
import jakarta.websocket.server.PathParam;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -20,6 +21,7 @@
public class CategoryController {

private final CategoryService categoryService;
private final SearchService searchService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.app.toaster.controller;

import com.app.toaster.common.dto.ApiResponse;
import com.app.toaster.controller.request.timer.CreateTimerRequestDto;
import com.app.toaster.controller.request.timer.UpdateTimerCommentDto;
import com.app.toaster.controller.request.timer.UpdateTimerDateTimeDto;
import com.app.toaster.controller.response.timer.GetTimerResponseDto;
import com.app.toaster.exception.Success;
import com.app.toaster.service.Timer.TimerService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/timer")
public class TimerController {

private final TimerService timerService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ApiResponse createTimer(
@RequestHeader("userId") Long userId,
@RequestBody CreateTimerRequestDto createTimerRequestDto
){
timerService.createTimer(userId, createTimerRequestDto);
return ApiResponse.success(Success.CREATE_TIMER_SUCCESS);
}

@GetMapping("/{timerId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<GetTimerResponseDto> getTimer(
@RequestHeader("userId") Long userId,
@PathVariable Long timerId) {

return ApiResponse.success(Success.GET_TIMER_SUCCESS,timerService.getTimer(userId, timerId) );
}

@PatchMapping("/datetime/{timerId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponse updateTimerDatetime(
@RequestHeader("userId") Long userId,
@PathVariable Long timerId,
@RequestBody UpdateTimerDateTimeDto updateTimerDateTimeDto){

timerService.updateTimerDatetime(userId,timerId, updateTimerDateTimeDto);
return ApiResponse.success(Success.UPDATE_TIMER_DATETIME_SUCCESS);
}

@PatchMapping("/comment/{timerId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponse updateTimerComment(
@RequestHeader("userId") Long userId,
@PathVariable Long timerId,
@RequestBody UpdateTimerCommentDto updateTimerCommentDto){

timerService.updateTimerComment(userId,timerId, updateTimerCommentDto);
return ApiResponse.success(Success.UPDATE_TIMER_COMMENT_SUCCESS);
}

@DeleteMapping("/{timerId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponse deleteTimer(
@RequestHeader("userId") Long userId,
@PathVariable Long timerId){
timerService.deleteTimer(userId,timerId);
return ApiResponse.success(Success.DELETE_TIMER_SUCCESS);
}
@GetMapping("/main")
@ResponseStatus(HttpStatus.OK)
public ApiResponse getTimerPage(
@RequestHeader("userId") Long userId){
return ApiResponse.success(Success.GET_TIMER_PAGE_SUCCESS, timerService.getTimerPage(userId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.app.toaster.controller.request.timer;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;


public record CreateTimerRequestDto(
Long categoryId,
String remindTime,
ArrayList<Integer> remindDates){
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.app.toaster.controller.request.timer;

public record UpdateTimerCommentDto(String newComment) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.app.toaster.controller.request.timer;

import java.util.ArrayList;

public record UpdateTimerDateTimeDto(String remindTime, ArrayList<Integer> remindDate) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.app.toaster.controller.response.timer;

import com.app.toaster.controller.response.search.CategoryResult;
import com.app.toaster.controller.response.search.SearchCategoryResult;
import com.app.toaster.domain.Reminder;

import java.util.List;

public record CompletedTimerDto(Long timerId, Long categoryId, String remindTime, String remindDate, String comment) {
public static CompletedTimerDto of(Reminder timer,String remindTime, String remindDate){
return new CompletedTimerDto(timer.getId(), timer.getCategory().getCategoryId(), remindTime, remindDate, timer.getComment() );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.app.toaster.controller.response.timer;

import lombok.Builder;

import java.util.List;

@Builder
public record GetTimerPageResponseDto(List<CompletedTimerDto> completedTimerList, List<WaitingTimerDto> waitingTimerList) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.app.toaster.controller.response.timer;

import com.app.toaster.controller.response.search.CategoryResult;
import com.app.toaster.controller.response.search.SearchMainResult;
import com.app.toaster.controller.response.search.ToastResult;
import com.app.toaster.domain.Reminder;

import java.util.ArrayList;
import java.util.List;

public record GetTimerResponseDto (String categoryName,
String remindTime,
ArrayList<Integer> remindDates) {
public static GetTimerResponseDto of(Reminder reminder){
return new GetTimerResponseDto(reminder.getCategory().getTitle(), reminder.getRemindTime().toString(), reminder.getRemindDates());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.app.toaster.controller.response.timer;

import com.app.toaster.domain.Reminder;

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

public record WaitingTimerDto(Long timerId, String remindTime, String remindDates, Boolean isAlarm, LocalDateTime updateAt) {
public static WaitingTimerDto of(Reminder timer, String remindTime, String remindDates) {
return new WaitingTimerDto(timer.getId(), remindTime, remindDates, timer.getIsAlarm(), timer.getUpdateAt());
}
}
28 changes: 28 additions & 0 deletions linkmind/src/main/java/com/app/toaster/domain/BaseTimeEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.app.toaster.domain;


import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.awt.print.Book;
import java.time.LocalDateTime;
import java.time.LocalTime;

@MappedSuperclass
@Getter
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {

@CreatedDate // 현재시각으로 초기화해줌
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updateAt;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.app.toaster.domain;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.util.ArrayList;

@Converter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converter라는 어노테이션을 써본적없었는데 이렇게 활용할 수 있군용..! ☺️ 덕분에 저도 많이 배웁니다 ㅎㅎ.

public class IntegerListConverter implements AttributeConverter<ArrayList<Integer>, String> {

@Override
public String convertToDatabaseColumn(ArrayList<Integer> attribute) {
if (attribute == null || attribute.isEmpty()) {
return null;
}
return String.join(",", attribute.stream().map(String::valueOf).toArray(String[]::new));
}

@Override
public ArrayList<Integer> convertToEntityAttribute(String dbData) {
if (dbData == null || dbData.isEmpty()) {
return new ArrayList<>();
}
String[] values = dbData.split(",");
ArrayList<Integer> result = new ArrayList<>();
for (String value : values) {
result.add(Integer.valueOf(value));
}
return result;
}
}
42 changes: 32 additions & 10 deletions linkmind/src/main/java/com/app/toaster/domain/Reminder.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.app.toaster.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.cglib.core.Local;

import java.time.LocalTime;
import java.util.ArrayList;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Reminder {
public class Reminder extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
Expand All @@ -28,10 +26,34 @@ public class Reminder {
@JoinColumn(name = "category")
private Category category;

private LocalTime remindTime;

@Convert(converter = IntegerListConverter.class)
private ArrayList<Integer> remindDates;

private String comment;

private Boolean isAlarm;

@Builder
public Reminder(User user, Category category, String title) {
public Reminder(User user, Category category, String comment, LocalTime remindTime, ArrayList<Integer> remindDates, Boolean isAlarm) {
this.user = user;
this.category = category;
this.comment = comment;
this.remindDates = remindDates;
this.remindTime = remindTime;
this.isAlarm = isAlarm;
}

public void updateRemindTime(String remindTime){
this.remindTime = LocalTime.parse(remindTime);
}

public void updateRemindDates(ArrayList<Integer> remindDates){
this.remindDates = remindDates;
}

public void updateComment(String comment){
this.comment = comment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Error {
NOT_FOUND_TOAST_EXCEPTION(HttpStatus.NOT_FOUND, "찾을 수 없는 토스트 입니다."),
NOT_FOUND_IMAGE_EXCEPTION(HttpStatus.NOT_FOUND, "s3 서비스에서 이미지를 찾을 수 없습니다."),
NOT_FOUND_TOAST_FILTER(HttpStatus.NOT_FOUND, "유효하지 않은 필터입니다."),
NOT_FOUND_TIMER(HttpStatus.NOT_FOUND, "찾을 수 없는 타이머입니다."),

/**
* 400 BAD REQUEST EXCEPTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@ public enum Success {
*/
CREATE_TOAST_SUCCESS(HttpStatus.CREATED, "토스트 저장이 완료 되었습니다."),
CREATE_CATEGORY_SUCCESS(HttpStatus.CREATED, "새 카테고리 추가 성공"),

CREATE_TIMER_SUCCESS(HttpStatus.CREATED, "새 타이머 생성 성공"),

/**
* 200 OK
*/
GET_MAIN_SUCCESS(HttpStatus.OK, "메인 페이지 조회 성공"),
GET_CATEORIES_SUCCESS(HttpStatus.OK, "전체 카테고리 조회 성공"),
GET_CATEORY_SUCCESS(HttpStatus.OK, "세부 카테고리 조회 성공"),
GET_TIMER_SUCCESS(HttpStatus.OK, "타이머 조회 성공"),
GET_TIMER_PAGE_SUCCESS(HttpStatus.OK, "타이머 페이지 조회 성공"),

LOGIN_SUCCESS(HttpStatus.OK, "로그인 성공"),
RE_ISSUE_TOKEN_SUCCESS(HttpStatus.OK, "토큰 재발급 성공"),
SIGNOUT_SUCCESS(HttpStatus.OK, "로그아웃 성공"),
DELETE_USER_SUCCESS(HttpStatus.OK, "유저 삭제 성공"),
DELETE_TOAST_SUCCESS(HttpStatus.OK, "토스트 삭제 성공"),
DELETE_CATEGORY_SUCCESS(HttpStatus.OK, "카테고리 삭제 성공"),
DELETE_TIMER_SUCCESS(HttpStatus.OK, "타이머 삭제 성공"),
SEARCH_SUCCESS(HttpStatus.OK, "검색 성공"),
PARSING_OG_SUCCESS(HttpStatus.OK, "og 데이터 파싱 결과입니다. 크롤링을 막은 페이지는 기본이미지가 나옵니다."),


UPDATE_ISREAD_SUCCESS(HttpStatus.OK, "열람여부 수정 완료"),
UPDATE_CATEGORY_TITLE_SUCCESS(HttpStatus.OK, "카테고리 수정 완료"),
UPDATE_TIMER_DATETIME_SUCCESS(HttpStatus.OK, "타이머 시간/날짜 수정 완료"),
UPDATE_TIMER_COMMENT_SUCCESS(HttpStatus.OK, "타이머 코멘트 수정 완료"),


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.app.toaster.infrastructure;

import com.app.toaster.domain.Reminder;
import com.app.toaster.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.ArrayList;

public interface TimerRepository extends JpaRepository<Reminder, Long> {

ArrayList<Reminder> findAllByUser(User user);
}
Loading