-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feat/#9 my todo my schedule
- Loading branch information
Showing
18 changed files
with
568 additions
and
0 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
78 changes: 78 additions & 0 deletions
78
src/main/java/com/mju/management/domain/schedule/controller/UserScheduleController.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,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(); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/mju/management/domain/schedule/dto/response/GetUserScheduleRes.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,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(); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/mju/management/domain/schedule/infrastructure/UserSchedule.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,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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/mju/management/domain/schedule/infrastructure/UserScheduleRepository.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,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); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mju/management/domain/schedule/service/UserScheduleService.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,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); | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/mju/management/domain/schedule/service/UserScheduleServiceImpl.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,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); | ||
} | ||
|
||
} |
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
Oops, something went wrong.