Skip to content

Commit

Permalink
✨ [Feature] 개인일정 추가 API 작성 #1049 (#1082)
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
3 people authored Dec 27, 2024
1 parent 81155a5 commit 4fb7a09
Show file tree
Hide file tree
Showing 22 changed files with 364 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import java.time.LocalDateTime;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import gg.agenda.api.user.agenda.controller.request.AgendaCreateReqDto;
import gg.auth.UserDto;
import gg.data.agenda.Agenda;
import gg.utils.annotation.UnitTest;
import gg.utils.exception.custom.InvalidParameterException;

@UnitTest
class AgendaCreateReqDtoTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ void createAgendaSimpleResponseDtoSuccess(boolean value) {
assertThat(dto.getIsOfficial()).isEqualTo(value);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
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.admin.schedule.publicschedule.controller.request.PublicScheduleAdminCreateReqDto;
import gg.calendar.api.admin.schedule.publicschedule.service.PublicScheduleAdminService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/calendar/public")
Expand All @@ -28,10 +21,8 @@ public class PublicScheduleAdminController {
private final PublicScheduleAdminService publicScheduleAdminService;

@PostMapping
public ResponseEntity<Void> createPublicSchedule(
@RequestBody @Valid PublicScheduleAdminCreateReqDto publicScheduleAdminCreateReqDto,
@Login @Parameter(hidden = true) UserDto userDto) {
String intraId = userDto.getIntraId();
public ResponseEntity<Void> publicScheduleCreate(
@RequestBody @Valid PublicScheduleAdminCreateReqDto publicScheduleAdminCreateReqDto) {
publicScheduleAdminService.createPublicSchedule(publicScheduleAdminCreateReqDto);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import gg.admin.repo.calendar.PublicScheduleAdminRepository;
import gg.calendar.api.admin.schedule.publicschedule.controller.request.PublicScheduleAdminCreateReqDto;
import gg.data.calendar.PublicSchedule;
import gg.data.calendar.type.EventTag;
import gg.data.calendar.type.JobTag;
import gg.data.calendar.type.TechTag;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.CustomRuntimeException;
import lombok.RequiredArgsConstructor;
Expand Down
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();
}
}
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();
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
import gg.calendar.api.user.schedule.publicschedule.service.PublicScheduleService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/calendar/public")
public class PublicScheduleController {
private final PublicScheduleService publicScheduleService;

@PostMapping
public ResponseEntity<Void> createPublicSchedule(@RequestBody @Valid PublicScheduleCreateReqDto req,
public ResponseEntity<Void> publicScheduleCreate(@RequestBody @Valid PublicScheduleCreateReqDto req,
@Login @Parameter(hidden = true) UserDto userDto) {
publicScheduleService.createPublicSchedule(req, userDto.getId());
return ResponseEntity.status(HttpStatus.CREATED).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class PublicScheduleService {
private final PublicScheduleRepository publicScheduleRepository;
private final UserRepository userRepository;

@Transactional
public PublicSchedule createPublicSchedule(PublicScheduleCreateReqDto req, Long userId) {
public void createPublicSchedule(PublicScheduleCreateReqDto req, Long userId) {
User user = userRepository.getById(userId);
if (!user.getIntraId().equals(req.getAuthor())) {
throw new CustomRuntimeException(ErrorCode.CALENDAR_AUTHOR_NOT_MATCH);
}

PublicSchedule publicSchedule = PublicScheduleCreateReqDto.toEntity(user.getIntraId(), req);
return publicScheduleRepository.save(publicSchedule);
publicScheduleRepository.save(publicSchedule);
}
}
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);
}
}
Loading

0 comments on commit 4fb7a09

Please sign in to comment.