Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Feature] 개인일정 수정 api #1057 #1087

Merged
merged 6 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleCreateReqDto;
import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleUpdateReqDto;
import gg.calendar.api.user.schedule.privateschedule.controller.response.PrivateScheduleUpdateResDto;
import gg.calendar.api.user.schedule.privateschedule.service.PrivateScheduleService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,4 +32,14 @@ public ResponseEntity<Void> privateScheduleCreate(@Login @Parameter(hidden = tru
privateScheduleService.createPrivateSchedule(userDto, privateScheduleCreateReqDto);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@PutMapping("/{id}")
public ResponseEntity<PrivateScheduleUpdateResDto> privateScheduleUpdate(
@Login @Parameter(hidden = true) UserDto userDto,
@Valid @RequestBody PrivateScheduleUpdateReqDto privateScheduleUpdateReqDto,
@PathVariable Long id) {
PrivateScheduleUpdateResDto privateScheduleUpdateResDto = privateScheduleService.updatePrivateSchedule(userDto,
privateScheduleUpdateReqDto, id);
return ResponseEntity.status(HttpStatus.OK).body(privateScheduleUpdateResDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PrivateScheduleCreateReqDto {

@NotNull
private DetailClassification classification;

private EventTag eventTag;

private JobTag jobTag;
Expand All @@ -39,6 +36,7 @@ public class PrivateScheduleCreateReqDto {

private String link;

@NotNull
private ScheduleStatus status;

@NotNull
Expand All @@ -54,11 +52,9 @@ public class PrivateScheduleCreateReqDto {
private Long groupId;

@Builder
private PrivateScheduleCreateReqDto(DetailClassification classification, EventTag eventTag, JobTag jobTag,
TechTag techTag, String title, String content, String link,
LocalDateTime startTime, LocalDateTime endTime, boolean alarm, Long groupId,
private PrivateScheduleCreateReqDto(EventTag eventTag, JobTag jobTag, TechTag techTag, String title, String content,
String link, LocalDateTime startTime, LocalDateTime endTime, boolean alarm, Long groupId,
ScheduleStatus status) {
this.classification = classification;
this.eventTag = eventTag;
this.jobTag = jobTag;
this.techTag = techTag;
Expand All @@ -74,11 +70,12 @@ private PrivateScheduleCreateReqDto(DetailClassification classification, EventTa

public static PublicSchedule toEntity(String intraId, PrivateScheduleCreateReqDto privateScheduleCreateReqDto) {
return PublicSchedule.builder()
.classification(privateScheduleCreateReqDto.classification)
.classification(DetailClassification.PRIVATE_SCHEDULE)
.eventTag(privateScheduleCreateReqDto.eventTag)
.jobTag(privateScheduleCreateReqDto.jobTag)
.techTag(privateScheduleCreateReqDto.techTag)
.author(intraId).title(privateScheduleCreateReqDto.title)
.author(intraId)
.title(privateScheduleCreateReqDto.title)
.content(privateScheduleCreateReqDto.content)
.link(privateScheduleCreateReqDto.link)
.startTime(privateScheduleCreateReqDto.startTime)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,66 @@
package gg.calendar.api.user.schedule.privateschedule.controller.request;

import java.time.LocalDateTime;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import gg.data.calendar.type.EventTag;
import gg.data.calendar.type.JobTag;
import gg.data.calendar.type.ScheduleStatus;
import gg.data.calendar.type.TechTag;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class PrivateScheduleUpdateReqDto {
private EventTag eventTag;

private JobTag jobTag;

private TechTag techTag;

@NotBlank
@Size(max = 50)
private String title;

@Size(max = 2000)
private String content;

private String link;

@NotNull
private ScheduleStatus status;

@NotNull
private LocalDateTime startTime;

@NotNull
private LocalDateTime endTime;

@NotNull
private boolean alarm;

@NotNull
private Long groupId;

@Builder
public PrivateScheduleUpdateReqDto(EventTag eventTag, JobTag jobTag, TechTag techTag, String title, String content,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@builder가 들어간 생성자의 타입을 private으로 통일하기로 해서 수정요청드립니다!

String link, ScheduleStatus status, LocalDateTime startTime, LocalDateTime endTime, boolean alarm,
Long groupId) {
this.eventTag = eventTag;
this.jobTag = jobTag;
this.techTag = techTag;
this.title = title;
this.content = content;
this.link = link;
this.status = status;
this.startTime = startTime;
this.endTime = endTime;
this.alarm = alarm;
this.groupId = groupId;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,85 @@
package gg.calendar.api.user.schedule.privateschedule.controller.response;

import java.time.LocalDateTime;

import gg.data.calendar.PrivateSchedule;
import gg.data.calendar.type.DetailClassification;
import gg.data.calendar.type.EventTag;
import gg.data.calendar.type.JobTag;
import gg.data.calendar.type.ScheduleStatus;
import gg.data.calendar.type.TechTag;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PrivateScheduleUpdateResDto {
private Long id;

private DetailClassification classification;

private EventTag eventTag;

private JobTag jobTag;

private TechTag techTag;

private String author;

private String title;

private String content;

private String link;

private ScheduleStatus status;

private LocalDateTime startTime;

private LocalDateTime endTime;

private boolean alarm;

private Long groupId;

@Builder
private PrivateScheduleUpdateResDto(Long id, DetailClassification classification, EventTag eventTag, JobTag jobTag,
TechTag techTag, String author, String title, String content, String link, ScheduleStatus status,
LocalDateTime startTime, LocalDateTime endTime, boolean alarm, Long groupId) {
this.id = id;
this.classification = classification;
this.eventTag = eventTag;
this.jobTag = jobTag;
this.techTag = techTag;
this.author = author;
this.title = title;
this.content = content;
this.link = link;
this.status = status;
this.startTime = startTime;
this.endTime = endTime;
this.alarm = alarm;
this.groupId = groupId;
}

public static PrivateScheduleUpdateResDto toDto(PrivateSchedule privateSchedule) {
return PrivateScheduleUpdateResDto.builder()
.id(privateSchedule.getId())
.classification(privateSchedule.getPublicSchedule().getClassification())
.eventTag(privateSchedule.getPublicSchedule().getEventTag())
.jobTag(privateSchedule.getPublicSchedule().getJobTag())
.techTag(privateSchedule.getPublicSchedule().getTechTag())
.author(privateSchedule.getPublicSchedule().getAuthor())
.title(privateSchedule.getPublicSchedule().getTitle())
.content(privateSchedule.getPublicSchedule().getContent())
.link(privateSchedule.getPublicSchedule().getLink())
.status(privateSchedule.getStatus())
.startTime(privateSchedule.getPublicSchedule().getStartTime())
.endTime(privateSchedule.getPublicSchedule().getEndTime())
.alarm(privateSchedule.isAlarm())
.groupId(privateSchedule.getGroupId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import gg.auth.UserDto;
import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleCreateReqDto;
import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleUpdateReqDto;
import gg.calendar.api.user.schedule.privateschedule.controller.response.PrivateScheduleUpdateResDto;
import gg.data.calendar.PrivateSchedule;
import gg.data.calendar.PublicSchedule;
import gg.data.calendar.ScheduleGroup;
Expand All @@ -16,6 +18,7 @@
import gg.repo.calendar.ScheduleGroupRepository;
import gg.repo.user.UserRepository;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.ForbiddenException;
import gg.utils.exception.custom.InvalidParameterException;
import gg.utils.exception.custom.NotExistException;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -43,9 +46,34 @@ public void createPrivateSchedule(UserDto userDto, PrivateScheduleCreateReqDto p
privateScheduleRepository.save(privateSchedule);
}

@Transactional
public PrivateScheduleUpdateResDto updatePrivateSchedule(UserDto userDto,
PrivateScheduleUpdateReqDto privateScheduleUpdateReqDto, Long privateScheduleId) {
validateTimeRange(privateScheduleUpdateReqDto.getStartTime(), privateScheduleUpdateReqDto.getEndTime());
PrivateSchedule privateSchedule = privateScheduleRepository.findById(privateScheduleId)
.orElseThrow(() -> new NotExistException(ErrorCode.PRIVATE_SCHEDULE_NOT_FOUND));
validateAuthor(userDto.getIntraId(), privateSchedule.getPublicSchedule().getAuthor());
scheduleGroupRepository.findById(privateScheduleUpdateReqDto.getGroupId())
.orElseThrow(() -> new NotExistException(ErrorCode.SCHEDULE_GROUP_NOT_FOUND));

privateSchedule.update(privateScheduleUpdateReqDto.getEventTag(), privateScheduleUpdateReqDto.getJobTag(),
privateScheduleUpdateReqDto.getTechTag(), privateScheduleUpdateReqDto.getTitle(),
privateScheduleUpdateReqDto.getContent(), privateScheduleUpdateReqDto.getLink(),
privateScheduleUpdateReqDto.getStatus(), privateScheduleUpdateReqDto.getStartTime(),
privateScheduleUpdateReqDto.getEndTime(), privateScheduleUpdateReqDto.isAlarm(),
privateScheduleUpdateReqDto.getGroupId());
return PrivateScheduleUpdateResDto.toDto(privateSchedule);
}

public void validateTimeRange(LocalDateTime startTime, LocalDateTime endTime) {
if (endTime.isBefore(startTime)) {
throw new InvalidParameterException(ErrorCode.CALENDAR_BEFORE_DATE);
}
}

public void validateAuthor(String intraId, String author) {
if (!intraId.equals(author)) {
throw new ForbiddenException(ErrorCode.CALENDAR_AUTHOR_NOT_MATCH);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import org.springframework.stereotype.Component;

import gg.data.calendar.PrivateSchedule;
import gg.data.calendar.PublicSchedule;
import gg.data.calendar.ScheduleGroup;
import gg.data.calendar.type.DetailClassification;
import gg.data.calendar.type.ScheduleStatus;
import gg.data.user.User;
import gg.repo.calendar.PrivateScheduleRepository;
import gg.repo.calendar.PublicScheduleRepository;
import gg.repo.calendar.ScheduleGroupRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,15 +20,16 @@
public class PrivateScheduleMockData {
private final PublicScheduleRepository publicScheduleRepository;
private final ScheduleGroupRepository scheduleGroupRepository;
private final PrivateScheduleRepository privateScheduleRepository;

public PublicSchedule createPublicSchedule() {
public PublicSchedule createPublicSchedule(String author) {
PublicSchedule publicSchedule = PublicSchedule.builder()
.classification(DetailClassification.EVENT)
.eventTag(null)
.jobTag(null)
.techTag(null)
.title("Test Schedule")
.author("author")
.author(author)
.content("Test Content")
.link("http://test.com")
.status(ScheduleStatus.ACTIVATE)
Expand All @@ -44,4 +47,10 @@ public ScheduleGroup createScheduleGroup(User user) {
.build();
return scheduleGroupRepository.save(scheduleGroup);
}

public PrivateSchedule createPrivateSchedule(PublicSchedule publicSchedule, ScheduleGroup scheduleGroup) {
PrivateSchedule privateSchedule = new PrivateSchedule(scheduleGroup.getUser(), publicSchedule, false,
scheduleGroup.getId());
return privateScheduleRepository.save(privateSchedule);
}
}
Loading
Loading