Skip to content

Commit

Permalink
Feat[#32] 태스크생성 API 구현 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
eunseo5343 authored Jul 10, 2024
2 parents d95d191 + 245e891 commit 17a60ce
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import jakarta.persistence.*;
import lombok.*;
import org.sopt.jaksim.global.common.BaseTimeEntity;
import org.sopt.jaksim.task.domain.Task;

import java.time.LocalDate;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand All @@ -19,4 +22,13 @@ public class CategoryTask extends BaseTimeEntity {
private Long taskId;
@Column(nullable = false)
private Long categoryId;

public static CategoryTask create(Long categoryId, Long taskId) {
return CategoryTask.builder()
.categoryId(categoryId)
.taskId(taskId)
.build();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public abstract class BaseTimeEntity {

@CreatedDate
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import org.sopt.jaksim.global.exception.IOException;
import org.sopt.jaksim.global.message.ErrorMessage;
import org.sopt.jaksim.global.message.SuccessMessage;
import org.sopt.jaksim.task.domain.Task;
import org.sopt.jaksim.task.dto.FetchTitleRequest;
import org.sopt.jaksim.task.dto.FetchTitleResponse;
import org.sopt.jaksim.task.dto.TaskCreateRequest;
import org.sopt.jaksim.task.service.TaskService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -36,4 +38,11 @@ public ResponseEntity<BaseResponse<?>> fetchTitle(@RequestParam("requestUrl") St
throw new IOException(ErrorMessage.INVALID_URL);
}
}

@PostMapping("/categories/{categoryId}")
public ResponseEntity<BaseResponse<?>> create(@PathVariable("categoryId") Long categoryId,
@RequestBody TaskCreateRequest taskCreateRequest) {
taskService.create(categoryId, taskCreateRequest);
return ApiResponseUtil.success(SuccessMessage.SUCCESS);
}
}
11 changes: 10 additions & 1 deletion jaksim/src/main/java/org/sopt/jaksim/task/domain/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ public class Task extends BaseTimeEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false)
private boolean isEnd;
private boolean isComplete;
@Column(nullable = false)
private LocalDate startDate;
private LocalDate endDate;

public static Task create(String name, LocalDate startDate, LocalDate endDate) {
return Task.builder()
.name(name)
.isComplete(false)
.startDate(startDate)
.endDate(endDate)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.jaksim.task.dto;

import java.time.LocalDate;

public record TaskCreateRequest (
String name,
LocalDate startDate,
LocalDate endDate
)
{

}
21 changes: 18 additions & 3 deletions jaksim/src/main/java/org/sopt/jaksim/task/service/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sopt.jaksim.category.domain.Category;
import org.sopt.jaksim.category.domain.CategoryTask;
import org.sopt.jaksim.category.repository.CategoryTaskRepository;
import org.sopt.jaksim.global.exception.NotFoundException;
import org.sopt.jaksim.global.message.ErrorMessage;
import org.sopt.jaksim.task.domain.Task;

import org.sopt.jaksim.task.dto.TaskCreateRequest;
import org.sopt.jaksim.task.repository.TaskRepository;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
@RequiredArgsConstructor
public class TaskService {
private final TaskRepository taskRepository;
private final CategoryTaskRepository categoryTaskRepository;

public Task getTaskById(Long taskId) {
return taskRepository.findById(taskId).orElseThrow(
Expand All @@ -31,4 +32,18 @@ public boolean isContains(Task task, LocalDate idxDate) {
task.getEndDate().equals(idxDate) || // endDate = idxDate
(task.getStartDate().isBefore(idxDate) && task.getEndDate().isAfter(idxDate)); // startDate, endDate가 idxDate를 포함
}
public void create(Long categoryId, TaskCreateRequest taskCreateRequest) {
Task task = Task.create(
taskCreateRequest.name(),
taskCreateRequest.startDate(),
taskCreateRequest.endDate());

taskRepository.save(task);

CategoryTask categoryTask = CategoryTask.create(
categoryId,
task.getId());

categoryTaskRepository.save(categoryTask);
}
}

0 comments on commit 17a60ce

Please sign in to comment.