Skip to content

Commit

Permalink
Merge pull request #26 from Link-MIND/feature/#23
Browse files Browse the repository at this point in the history
[Feature] ๋ฆฌ๋งˆ์ธ๋“œ ๊ด€๋ จ API ๊ฐœ๋ฐœ
  • Loading branch information
mmihye authored Jan 9, 2024
2 parents ec1387b + 1bd0c95 commit d14ff27
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 11 deletions.
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
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

0 comments on commit d14ff27

Please sign in to comment.