Skip to content

Commit

Permalink
Merge pull request #10 from STUDIO-EYE/feat/#9-myTodo-mySchedule
Browse files Browse the repository at this point in the history
Feat/#9 my todo my schedule
  • Loading branch information
phonil authored Apr 20, 2024
2 parents 54d19f1 + 4c7050c commit c278c0d
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ public CommonResult deleteSchedule(@PathVariable Long scheduleId) {
scheduleService.deleteSchedule(scheduleId);
return responseService.getSuccessfulResult();
}

//일정 완료
// @Operation(summary = "일정 완료하기", description = "일정을 완료하는 API")
// @ResponseStatus(OK)
// @DeleteMapping("/schedules/finish/{scheduleId}")
// public CommonResult finishSchedule(@PathVariable Long scheduleId) {
// scheduleService.finishSchedule(scheduleId);
// return responseService.getSuccessfulResult();
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.mju.management.domain.schedule.controller;

import com.mju.management.domain.schedule.dto.reqeust.CreateScheduleRequestDto;
import com.mju.management.domain.schedule.dto.response.GetScheduleResponseDto;
import com.mju.management.domain.schedule.dto.response.GetUserScheduleRes;
import com.mju.management.domain.schedule.infrastructure.UserSchedule;
import com.mju.management.domain.schedule.service.UserScheduleService;
import com.mju.management.global.config.jwtInterceptor.JwtContextHolder;
import com.mju.management.global.model.Result.CommonResult;
import com.mju.management.global.service.ResponseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.springframework.http.HttpStatus.OK;

@Tag(name = "내 일정 CRUD API", description = "내 일정 CRUD API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/userSchedules")
@CrossOrigin("*")
public class UserScheduleController {

private final UserScheduleService userScheduleService;
private final ResponseService responseService;

//일정 등록
@Operation(summary = "내 일정 등록", description = "내 일정 등록 API")
@ResponseStatus(OK)
@PostMapping
public CommonResult createMySchedule(@Valid @RequestBody CreateScheduleRequestDto createScheduleRequestDto){
userScheduleService.createMySchedule(JwtContextHolder.getUserId(), createScheduleRequestDto);
return responseService.getSuccessfulResult();
}

// 내 일정 하나 조회
@Operation(summary = "내 일정 하나 조회", description = "내 일정 하나 조회 API")
@ResponseStatus(OK)
@GetMapping("/{userScheduleId}")
public CommonResult getMyScheduleOne(@PathVariable Long userScheduleId) {
GetUserScheduleRes schedule = userScheduleService.getMyScheduleOne(userScheduleId);
return responseService.getSingleResult(schedule);
}

// 내 일정 목록 조회
@Operation(summary = "내 일정 목록 조회", description = "내 일정 목록 조회 API")
@ResponseStatus(OK)
@GetMapping
public CommonResult getMySchedule() {
List<UserSchedule> userScheduleList = userScheduleService.getMySchedule(JwtContextHolder.getUserId());
return responseService.getListResult(userScheduleList);
}

// 내 일정 수정
@Operation(summary = "내 일정 수정", description = "내 일정 수정 API")
@ResponseStatus(OK)
@PutMapping("/{userScheduleId}")
public CommonResult updateMySchedule(
@PathVariable Long userScheduleId,
@Valid @RequestBody CreateScheduleRequestDto updateScheduleRequestDto
) {
userScheduleService.updateMySchedule(JwtContextHolder.getUserId(), userScheduleId, updateScheduleRequestDto);
return responseService.getSuccessfulResult();
}

// 내 일정 삭제
@DeleteMapping("/{userScheduleId}")
@Operation(summary = "내 일정 삭제", description = "내 일정 삭제 api")
public CommonResult deleteMyToDo(@PathVariable Long userScheduleId) {
userScheduleService.deleteMyToDo(JwtContextHolder.getUserId(), userScheduleId);
return responseService.getSuccessfulResult();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mju.management.domain.schedule.dto.response;

import com.mju.management.domain.schedule.infrastructure.Schedule;
import com.mju.management.domain.schedule.infrastructure.UserSchedule;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetUserScheduleRes {

private Long scheduleId;
private Long userId;
private String content;
private LocalDate startDate;
private LocalDate endDate;

public static GetUserScheduleRes from(UserSchedule userSchedule){
return GetUserScheduleRes.builder()
.scheduleId(userSchedule.getUserScheduleId())
.userId(userSchedule.getUserId())
.content(userSchedule.getContent())
.startDate(userSchedule.getStartDate())
.endDate(userSchedule.getEndDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class Schedule {
@Column(name = "end_date", nullable = false)
private LocalDate endDate;

@Column(name = "is_checked")
private boolean isChecked;

public void update(CreateScheduleRequestDto updateScheduleRequestDto) {
this.content = updateScheduleRequestDto.getContent();
this.startDate = updateScheduleRequestDto.readStartDateAsLocalDateType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.mju.management.domain.schedule.infrastructure;

import com.mju.management.domain.project.infrastructure.Project;
import com.mju.management.domain.schedule.dto.reqeust.CreateScheduleRequestDto;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Getter
@NoArgsConstructor
@Entity
public class UserSchedule {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_schedule_id")
private Long userScheduleId;

@Column(name = "user_id")
private Long userId;

@Column(name = "content", nullable = false)
private String content;

@Column(name = "start_date", nullable = false)
private LocalDate startDate;

@Column(name = "end_date", nullable = false)
private LocalDate endDate;

@Column(name = "is_checked")
private boolean isChecked;

public void update(CreateScheduleRequestDto updateScheduleRequestDto) {
this.content = updateScheduleRequestDto.getContent();
this.startDate = updateScheduleRequestDto.readStartDateAsLocalDateType();
this.endDate = updateScheduleRequestDto.readEndDateAsLocalDateType();
}

@Builder
public UserSchedule(Long userScheduleId, Long userId, String content, LocalDate startDate, LocalDate endDate, boolean isChecked) {
this.userScheduleId = userScheduleId;
this.userId = userId;
this.content = content;
this.startDate = startDate;
this.endDate = endDate;
this.isChecked = isChecked;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mju.management.domain.schedule.infrastructure;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserScheduleRepository extends JpaRepository<UserSchedule, Long> {

List<UserSchedule> findAllByUserId(Long userId);

Optional<UserSchedule> findByUserScheduleIdAndUserId(Long userScheduleId, Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mju.management.domain.schedule.service;

import com.mju.management.domain.schedule.dto.reqeust.CreateScheduleRequestDto;
import com.mju.management.domain.schedule.dto.response.GetUserScheduleRes;
import com.mju.management.domain.schedule.infrastructure.UserSchedule;

import java.util.List;

public interface UserScheduleService {
void createMySchedule(Long userId, CreateScheduleRequestDto createScheduleRequestDto);

List<UserSchedule> getMySchedule(Long userId);

void updateMySchedule(Long userId, Long userScheduleId, CreateScheduleRequestDto updateScheduleRequestDto);

void deleteMyToDo(Long userId, Long userScheduleId);

GetUserScheduleRes getMyScheduleOne(Long userScheduleId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.mju.management.domain.schedule.service;

import com.mju.management.domain.schedule.dto.reqeust.CreateScheduleRequestDto;
import com.mju.management.domain.schedule.dto.response.GetUserScheduleRes;
import com.mju.management.domain.schedule.infrastructure.UserSchedule;
import com.mju.management.domain.schedule.infrastructure.UserScheduleRepository;
import com.mju.management.global.model.Exception.ExceptionList;
import com.mju.management.global.model.Exception.NonExistentException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class UserScheduleServiceImpl implements UserScheduleService{

private final UserScheduleRepository userScheduleRepository;
@Override
@Transactional
public void createMySchedule(Long userId, CreateScheduleRequestDto createScheduleRequestDto) {

UserSchedule userSchedule = UserSchedule.builder()
.userId(userId)
.content(createScheduleRequestDto.getContent())
.startDate(createScheduleRequestDto.readStartDateAsLocalDateType())
.endDate(createScheduleRequestDto.readEndDateAsLocalDateType())
.isChecked(false)
.build();

userScheduleRepository.save(userSchedule);
}

@Override
public List<UserSchedule> getMySchedule(Long userId) {

List<UserSchedule> allByUserId = userScheduleRepository.findAllByUserId(userId);
if (!allByUserId.isEmpty())
return allByUserId;
else
throw new NonExistentException(ExceptionList.NON_EXISTENT_CHECKLIST);
}

@Override
@Transactional
public void updateMySchedule(Long userId, Long userScheduleId, CreateScheduleRequestDto updateScheduleRequestDto) {
Optional<UserSchedule> findUserSchedule = userScheduleRepository.findByUserScheduleIdAndUserId(userScheduleId, userId);
if (findUserSchedule.isPresent()) {
UserSchedule userSchedule = findUserSchedule.get();
userSchedule.update(updateScheduleRequestDto);
} else
throw new NonExistentException(ExceptionList.NON_EXISTENT_PROJECT);

}

@Override
@Transactional
public void deleteMyToDo(Long userId, Long userScheduleId) {

Optional<UserSchedule> findUserSchedule = userScheduleRepository.findByUserScheduleIdAndUserId(userScheduleId, userId);
if (findUserSchedule.isPresent()) {
UserSchedule userSchedule = findUserSchedule.get();
userScheduleRepository.delete(userSchedule);
} else
throw new NonExistentException(ExceptionList.NON_EXISTENT_PROJECT);

}

@Override
public GetUserScheduleRes getMyScheduleOne(Long userScheduleId) {

UserSchedule userSchedule = userScheduleRepository.findById(userScheduleId)
.orElseThrow(()-> new NonExistentException(ExceptionList.NON_EXISTENT_SCHEDULE));
return GetUserScheduleRes.from(userSchedule);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mju.management.domain.todo.dto.ToDoRequestDto;
import com.mju.management.domain.todo.infrastructure.ToDoEntity;
import com.mju.management.domain.todo.service.ToDoService;
import com.mju.management.global.config.jwtInterceptor.JwtContextHolder;
import com.mju.management.global.model.Result.CommonResult;
import com.mju.management.global.service.ResponseService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -43,6 +44,16 @@ public CommonResult showToDo(@PathVariable Long projectId) {
CommonResult commonResult = responseService.getListResult(toDoEntity);
return commonResult;
}

// // 내 할 일 조회
// @GetMapping("/my/todo")
// @Operation(summary = "내 할 일 조회", description = "내 할 일 조회 api")
// public CommonResult showMyToDo() {
// List<ToDoEntity> toDoEntity = toDoService.getMyToDo(JwtContextHolder.getUserId());
// CommonResult commonResult = responseService.getListResult(toDoEntity);
// return commonResult;
// }

//체크박스 하나만 선택
@GetMapping("/todo/{todoIndex}")
@Operation(summary = "할일 선택 조회", description = "할일 선택 조회 api")
Expand Down
Loading

0 comments on commit c278c0d

Please sign in to comment.