Skip to content

Commit

Permalink
Merge pull request #105 from kakao-tech-campus-2nd-step3/weekly
Browse files Browse the repository at this point in the history
w10 weekly2develop
  • Loading branch information
sunandrabbit authored Nov 8, 2024
2 parents a21d78e + a9fde93 commit 50fa744
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 43 deletions.
25 changes: 13 additions & 12 deletions src/main/java/team1/BE/seamless/DTO/TaskDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import team1.BE.seamless.entity.MemberEntity;
import team1.BE.seamless.entity.TaskEntity;
import team1.BE.seamless.entity.enums.Priority;
import team1.BE.seamless.entity.enums.Status;
import team1.BE.seamless.util.errorException.BaseHandler;
import team1.BE.seamless.util.page.PageParam;

Expand All @@ -31,7 +32,7 @@ public static class TaskCreate {
private Long ownerId;

@NotNull(message = "진행 상태(status)는 필수 입력 사항입니다.")
private Integer status;
private Status status;

@NotNull(message = "중요도(priority)는 필수 입력 사항입니다.")
private Priority priority;
Expand All @@ -48,7 +49,7 @@ public static class TaskCreate {
private LocalDateTime endDate;

public TaskCreate(String name, String description, Long ownerId, LocalDateTime startDate,
LocalDateTime endDate, Priority priority, Integer status, Integer progress) {
LocalDateTime endDate, Priority priority, Status status, Integer progress) {
if (endDate.isBefore(startDate)) {
throw new BaseHandler(HttpStatus.BAD_REQUEST, "종료시간은 시작시간보다 이전일 수 없습니다.");
}
Expand Down Expand Up @@ -93,7 +94,7 @@ public Priority getPriority() {
return priority;
}

public Integer getStatus() {
public Status getStatus() {
return status;
}
}
Expand All @@ -110,7 +111,7 @@ public static class TaskUpdate {
@Max(value = 100, message = "진행도(progress)는 최대 100이어야 합니다.")
private Integer progress;

private Integer status;
private Status status;

private Priority priority;

Expand All @@ -120,7 +121,7 @@ public static class TaskUpdate {

public TaskUpdate(String name, String description, Integer progress, Long ownerId,
LocalDateTime startDate,
LocalDateTime endDate, Priority priority, Integer status) {
LocalDateTime endDate, Priority priority, Status status) {
if (endDate.isBefore(startDate)) {
throw new BaseHandler(HttpStatus.BAD_REQUEST, "종료시간은 시작시간보다 이전일 수 없습니다.");
}
Expand Down Expand Up @@ -158,7 +159,7 @@ public LocalDateTime getEndDate() {
return endDate;
}

public Integer getStatus() {
public Status getStatus() {
return status;
}

Expand All @@ -185,11 +186,11 @@ public static class TaskDetail {

private Priority priority;

private Integer status;
private Status status;

public TaskDetail(Long id, String name, String description, Long ownerId, Integer progress,
LocalDateTime startDate, LocalDateTime endDate, Priority priority,
Integer status) {
Status status) {
this.id = id;
this.name = name;
this.description = description;
Expand Down Expand Up @@ -246,7 +247,7 @@ public Priority getPriority() {
return priority;
}

public Integer getStatus() {
public Status getStatus() {
return status;
}
}
Expand All @@ -269,11 +270,11 @@ public static class TaskWithOwnerDetail {

private Priority priority;

private Integer status;
private Status status;

public TaskWithOwnerDetail(Long id, String name, String description, MemberEntity owner,
Integer progress,
LocalDateTime startDate, LocalDateTime endDate, Priority priority, Integer status) {
LocalDateTime startDate, LocalDateTime endDate, Priority priority, Status status) {
this.id = id;
this.name = name;
this.description = description;
Expand Down Expand Up @@ -317,7 +318,7 @@ public Priority getPriority() {
return priority;
}

public Integer getStatus() {
public Status getStatus() {
return status;
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/team1/BE/seamless/entity/TaskEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
import jakarta.persistence.ManyToOne;
import java.time.LocalDateTime;
import team1.BE.seamless.entity.enums.Priority;
import team1.BE.seamless.entity.enums.Status;

@Entity(name = "taskss")
public class TaskEntity {

public TaskEntity(String name, String description, Priority priority, ProjectEntity project, MemberEntity member, LocalDateTime startDate, LocalDateTime endDate, Integer progress, Integer status) {
public TaskEntity(
String name,
String description,
Priority priority,
ProjectEntity project,
MemberEntity member,
LocalDateTime startDate,
LocalDateTime endDate,
Integer progress,
Status status) {
this.name = name;
this.description = description;
this.progress = progress;
this.status = status;
this.status = Status.PENDING;
this.priority = priority;
this.isDeleted = false;
this.projectEntity = project;
Expand All @@ -47,8 +57,9 @@ public TaskEntity() {
@Column(name = "progress")
private Integer progress = 0;

@Enumerated(EnumType.STRING)
@Column(name = "status")
private Integer status = 0;
private Status status;

@Enumerated(EnumType.STRING)
@Column(name = "priority")
Expand Down Expand Up @@ -87,7 +98,7 @@ public Integer getProgress() {
return progress;
}

public Integer getStatus() {
public Status getStatus() {
return status;
}

Expand Down Expand Up @@ -143,7 +154,7 @@ public void setDeleted(Boolean deleted) {
isDeleted = deleted;
}

public void setStatus(Integer status) {
public void setStatus(Status status) {
this.status = status;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/team1/BE/seamless/entity/enums/Status.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team1.BE.seamless.entity.enums;

public enum Status {

PENDING, IN_PROGRESS, COMPLETED
}
3 changes: 2 additions & 1 deletion src/main/java/team1/BE/seamless/init/TaskCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.stereotype.Component;
import team1.BE.seamless.DTO.TaskDTO.TaskCreate;
import team1.BE.seamless.entity.enums.Priority;
import team1.BE.seamless.entity.enums.Status;
import team1.BE.seamless.service.TaskService;

@Component
Expand All @@ -21,7 +22,7 @@ public void creator() {

TaskCreate task1 = new TaskCreate("태스크1", "첫번째 태스크입니다.", 1L,
LocalDateTime.of(2024, 10, 10, 0, 0),
LocalDateTime.of(2025, 9, 3, 0, 0), Priority.HIGH, 50, 1);
LocalDateTime.of(2025, 9, 3, 0, 0), Priority.HIGH, Status.IN_PROGRESS, 1);

taskService.createTask(1L, task1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface TaskRepository extends JpaRepository<TaskEntity, Long> {
Optional<TaskEntity> findByIdAndProjectEntityUserEntityEmail(Long id, String email);

@Query(value = "SELECT * FROM taskss t WHERE t.project_id = :projectId " +
"AND (t.is_deleted = false) " +
"AND (:status IS NULL OR t.status = :status) " +
"AND (:priority IS NULL OR t.priority = :priority) " +
"AND (:memberId IS NULL OR t.member_id = :memberId)",
Expand Down
25 changes: 2 additions & 23 deletions src/main/java/team1/BE/seamless/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package team1.BE.seamless.service;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import java.util.List;
import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -20,15 +17,12 @@
import team1.BE.seamless.mapper.MemberMapper;
import team1.BE.seamless.repository.MemberRepository;
import team1.BE.seamless.repository.ProjectRepository;
import team1.BE.seamless.util.Email.EmailSend;
import team1.BE.seamless.util.MailSend;
import team1.BE.seamless.util.Util;
import team1.BE.seamless.util.auth.AesEncrypt;
import team1.BE.seamless.util.auth.ParsingPram;
import team1.BE.seamless.util.errorException.BaseHandler;

import java.time.LocalDateTime;

@Service
public class MemberService {

Expand Down Expand Up @@ -92,22 +86,7 @@ public Page<MemberResponseDTO> getMemberList(Long projectId,
throw new BaseHandler(HttpStatus.UNAUTHORIZED,"권한이 없습니다.");
}

ProjectEntity project = projectRepository.findById(projectId)
.orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트가 존재하지 않습니다."));

if (project.getEndDate().isBefore(LocalDateTime.now())) {
throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다.");
}

// return memberRepository.findAllByProjectEntityIdAndIsDeleteFalse(projectId, memberList.toPageable())
// .map(memberMapper::toGetResponseDTO);

int start = memberList.getPage() * memberList.getSize();
int end = Math.min((start + memberList.getSize()), project.getMemberEntities().size());
List<MemberEntity> memberEntities = project.getMemberEntities().subList(start, end);

return new PageImpl<>(memberEntities,memberList.toPageable(), project.getMemberEntities().size())
.map(memberMapper::toGetResponseDTO);
return memberRepository.findAllByProjectEntityIdAndIsDeleteFalse(projectId,memberList.toPageable()).map(memberMapper::toGetResponseDTO);

}

Expand Down
11 changes: 9 additions & 2 deletions src/test/java/team1/BE/seamless/e2e/TaskServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;
import team1.BE.seamless.DTO.TaskDTO.TaskCreate;
import team1.BE.seamless.entity.enums.Priority;
import team1.BE.seamless.entity.enums.Status;
import team1.BE.seamless.service.ProjectService;
import team1.BE.seamless.service.TaskService;

Expand Down Expand Up @@ -64,7 +65,10 @@ public void setUp() {

@Test
public void 태스크_시작_시간이_프로젝트_일정_범위보다_이를_경우_실패() {
TaskCreate body = new TaskCreate("태스크1", "첫번째 태스크입니다.", 1L, LocalDateTime.of(2001, 10, 10, 0, 0), LocalDateTime.of(2025, 5, 3, 1, 0, 0), Priority.HIGH, 50, 1);
TaskCreate body = new TaskCreate("태스크1", "첫번째 태스크입니다.",
1L, LocalDateTime.of(2001, 10, 10, 0, 0),
LocalDateTime.of(2025, 5, 3, 1, 0, 0),
Priority.HIGH, Status.IN_PROGRESS, 1);

HttpEntity<Long> requestEntity = new HttpEntity(body, headers);

Expand All @@ -75,7 +79,10 @@ public void setUp() {

@Test
public void 태스크_마감_시간이_프로젝트_일정_범위보다_늦을_경우_실패() {
TaskCreate body = new TaskCreate("태스크1", "첫번째 태스크입니다.", 1L, LocalDateTime.of(2024, 12, 1, 0, 0), LocalDateTime.of(2100, 5, 3, 1, 0, 0), Priority.HIGH, 50, 1);
TaskCreate body = new TaskCreate("태스크1", "첫번째 태스크입니다.",
1L, LocalDateTime.of(2024, 12, 1, 0, 0),
LocalDateTime.of(2100, 5, 3, 1, 0, 0),
Priority.HIGH, Status.IN_PROGRESS, 1);

HttpEntity<Long> requestEntity = new HttpEntity(body, headers);

Expand Down

0 comments on commit 50fa744

Please sign in to comment.