-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feature] ๋ฆฌ๋ง์ธ๋ ๊ด๋ จ API ๊ฐ๋ฐ
- Loading branch information
Showing
16 changed files
with
453 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
linkmind/src/main/java/com/app/toaster/controller/TimerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
linkmind/src/main/java/com/app/toaster/controller/request/timer/CreateTimerRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | ||
} |
4 changes: 4 additions & 0 deletions
4
linkmind/src/main/java/com/app/toaster/controller/request/timer/UpdateTimerCommentDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
6 changes: 6 additions & 0 deletions
6
linkmind/src/main/java/com/app/toaster/controller/request/timer/UpdateTimerDateTimeDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
13 changes: 13 additions & 0 deletions
13
linkmind/src/main/java/com/app/toaster/controller/response/timer/CompletedTimerDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...mind/src/main/java/com/app/toaster/controller/response/timer/GetTimerPageResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
17 changes: 17 additions & 0 deletions
17
linkmind/src/main/java/com/app/toaster/controller/response/timer/GetTimerResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
linkmind/src/main/java/com/app/toaster/controller/response/timer/WaitingTimerDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
linkmind/src/main/java/com/app/toaster/domain/BaseTimeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
linkmind/src/main/java/com/app/toaster/domain/IntegerListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
linkmind/src/main/java/com/app/toaster/infrastructure/TimerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.