-
Notifications
You must be signed in to change notification settings - Fork 9
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
Co-authored-by: taehyeon <kth0373@naver.com> Co-authored-by: seykim <kksy0917@gmail.com>
- Loading branch information
1 parent
81155a5
commit 4fb7a09
Showing
22 changed files
with
364 additions
and
64 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
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
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
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
22 changes: 19 additions & 3 deletions
22
...a/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.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 |
---|---|---|
@@ -1,15 +1,31 @@ | ||
package gg.calendar.api.user.schedule.privateschedule.controller; | ||
|
||
import javax.validation.Valid; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
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.service.PrivateScheduleService; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/private") | ||
@RequestMapping("/calendar/private") | ||
public class PrivateScheduleController { | ||
private final PrivateScheduleService privateScheduleService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> privateScheduleCreate(@Login @Parameter(hidden = true) UserDto userDto, | ||
@Valid @RequestBody PrivateScheduleCreateReqDto privateScheduleCreateReqDto) { | ||
privateScheduleService.createPrivateSchedule(userDto, privateScheduleCreateReqDto); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...dar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.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 |
---|---|---|
@@ -1,11 +1,89 @@ | ||
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.PublicSchedule; | ||
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 PrivateScheduleCreateReqDto { | ||
|
||
@NotNull | ||
private DetailClassification classification; | ||
|
||
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; | ||
|
||
private ScheduleStatus status; | ||
|
||
@NotNull | ||
private LocalDateTime startTime; | ||
|
||
@NotNull | ||
private LocalDateTime endTime; | ||
|
||
@NotNull | ||
private boolean alarm; | ||
|
||
@NotNull | ||
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, | ||
ScheduleStatus status) { | ||
this.classification = classification; | ||
this.eventTag = eventTag; | ||
this.jobTag = jobTag; | ||
this.techTag = techTag; | ||
this.title = title; | ||
this.content = content; | ||
this.link = link; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.alarm = alarm; | ||
this.groupId = groupId; | ||
this.status = status; | ||
} | ||
|
||
public static PublicSchedule toEntity(String intraId, PrivateScheduleCreateReqDto privateScheduleCreateReqDto) { | ||
return PublicSchedule.builder() | ||
.classification(privateScheduleCreateReqDto.classification) | ||
.eventTag(privateScheduleCreateReqDto.eventTag) | ||
.jobTag(privateScheduleCreateReqDto.jobTag) | ||
.techTag(privateScheduleCreateReqDto.techTag) | ||
.author(intraId).title(privateScheduleCreateReqDto.title) | ||
.content(privateScheduleCreateReqDto.content) | ||
.link(privateScheduleCreateReqDto.link) | ||
.startTime(privateScheduleCreateReqDto.startTime) | ||
.endTime(privateScheduleCreateReqDto.endTime) | ||
.status(privateScheduleCreateReqDto.status) | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...in/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.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 |
---|---|---|
@@ -1,14 +1,51 @@ | ||
package gg.calendar.api.user.schedule.privateschedule.service; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import gg.auth.UserDto; | ||
import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleCreateReqDto; | ||
import gg.data.calendar.PrivateSchedule; | ||
import gg.data.calendar.PublicSchedule; | ||
import gg.data.calendar.ScheduleGroup; | ||
import gg.data.user.User; | ||
import gg.repo.calendar.PrivateScheduleRepository; | ||
import gg.repo.calendar.PublicScheduleRepository; | ||
import gg.repo.calendar.ScheduleGroupRepository; | ||
import gg.repo.user.UserRepository; | ||
import gg.utils.exception.ErrorCode; | ||
import gg.utils.exception.custom.InvalidParameterException; | ||
import gg.utils.exception.custom.NotExistException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class PrivateScheduleService { | ||
private final PrivateScheduleRepository privateScheduleRepository; | ||
private final PublicScheduleRepository publicScheduleRepository; | ||
private final ScheduleGroupRepository scheduleGroupRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public void createPrivateSchedule(UserDto userDto, PrivateScheduleCreateReqDto privateScheduleCreateReqDto) { | ||
validateTimeRange(privateScheduleCreateReqDto.getStartTime(), privateScheduleCreateReqDto.getEndTime()); | ||
PublicSchedule publicSchedule = PrivateScheduleCreateReqDto.toEntity(userDto.getIntraId(), | ||
privateScheduleCreateReqDto); | ||
publicScheduleRepository.save(publicSchedule); | ||
ScheduleGroup scheduleGroup = scheduleGroupRepository.findById(privateScheduleCreateReqDto.getGroupId()) | ||
.orElseThrow(() -> new NotExistException(ErrorCode.SCHEDULE_GROUP_NOT_FOUND)); | ||
User user = userRepository.getById(userDto.getId()); | ||
PrivateSchedule privateSchedule = new PrivateSchedule(user, publicSchedule, | ||
privateScheduleCreateReqDto.isAlarm(), scheduleGroup.getId()); | ||
privateScheduleRepository.save(privateSchedule); | ||
} | ||
|
||
public void validateTimeRange(LocalDateTime startTime, LocalDateTime endTime) { | ||
if (endTime.isBefore(startTime)) { | ||
throw new InvalidParameterException(ErrorCode.CALENDAR_BEFORE_DATE); | ||
} | ||
} | ||
} |
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
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
47 changes: 47 additions & 0 deletions
47
.../src/test/java/gg/calendar/api/user/schedule/privateschedule/PrivateScheduleMockData.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,47 @@ | ||
package gg.calendar.api.user.schedule.privateschedule; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
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.PublicScheduleRepository; | ||
import gg.repo.calendar.ScheduleGroupRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class PrivateScheduleMockData { | ||
private final PublicScheduleRepository publicScheduleRepository; | ||
private final ScheduleGroupRepository scheduleGroupRepository; | ||
|
||
public PublicSchedule createPublicSchedule() { | ||
PublicSchedule publicSchedule = PublicSchedule.builder() | ||
.classification(DetailClassification.EVENT) | ||
.eventTag(null) | ||
.jobTag(null) | ||
.techTag(null) | ||
.title("Test Schedule") | ||
.author("author") | ||
.content("Test Content") | ||
.link("http://test.com") | ||
.status(ScheduleStatus.ACTIVATE) | ||
.startTime(LocalDateTime.now()) | ||
.endTime(LocalDateTime.now().plusDays(1)) | ||
.build(); | ||
return publicScheduleRepository.save(publicSchedule); | ||
} | ||
|
||
public ScheduleGroup createScheduleGroup(User user) { | ||
ScheduleGroup scheduleGroup = ScheduleGroup.builder() | ||
.user(user) | ||
.title("title") | ||
.backgroundColor("") | ||
.build(); | ||
return scheduleGroupRepository.save(scheduleGroup); | ||
} | ||
} |
Oops, something went wrong.