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] Admin 공유일정 수정 API 및 테스트 코드 작성 #1059 #1086

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -16,4 +16,6 @@ public interface PublicScheduleAdminRepository extends JpaRepository<PublicSched
List<PublicSchedule> findByAuthor(String author);

Page<PublicSchedule> findAllByClassification(DetailClassification detailClassification, Pageable pageable);

List<PublicSchedule> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import org.springframework.web.bind.annotation.ModelAttribute;
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.calendar.api.admin.schedule.publicschedule.controller.request.PublicScheduleAdminCreateReqDto;
import gg.calendar.api.admin.schedule.publicschedule.controller.request.PublicScheduleAdminUpdateReqDto;
import gg.calendar.api.admin.schedule.publicschedule.controller.response.PublicScheduleAdminResDto;
import gg.calendar.api.admin.schedule.publicschedule.controller.response.PublicScheduleAdminUpdateResDto;
import gg.calendar.api.admin.schedule.publicschedule.service.PublicScheduleAdminService;
import gg.data.calendar.type.DetailClassification;
import gg.utils.dto.PageRequestDto;
Expand All @@ -36,7 +39,7 @@ public ResponseEntity<Void> publicScheduleCreate(

@GetMapping("/list/{detailClassification}")
public ResponseEntity<PageResponseDto<PublicScheduleAdminResDto>> publicScheduleAdminClassificationList(
@PathVariable DetailClassification detailClassification, @ModelAttribute PageRequestDto pageRequestDto) {
@PathVariable DetailClassification detailClassification, @ModelAttribute @Valid PageRequestDto pageRequestDto) {
int page = pageRequestDto.getPage();
int size = pageRequestDto.getSize();

Expand All @@ -45,4 +48,13 @@ public ResponseEntity<PageResponseDto<PublicScheduleAdminResDto>> publicSchedule

return ResponseEntity.ok(pageResponseDto);
}

@PutMapping("/{id}")
public ResponseEntity<PublicScheduleAdminUpdateResDto> publicScheduleUpdate(
@RequestBody @Valid PublicScheduleAdminUpdateReqDto publicScheduleAdminUpdateReqDto,
@PathVariable Long id) {
PublicScheduleAdminUpdateResDto publicScheduleAdminUpdateRes = publicScheduleAdminService.updatePublicSchedule(
publicScheduleAdminUpdateReqDto, id);
return ResponseEntity.ok(publicScheduleAdminUpdateRes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class PublicScheduleAdminCreateReqDto {

private String link;

@NotNull
private ScheduleStatus status;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
package gg.calendar.api.admin.schedule.publicschedule.controller.request;

import java.time.LocalDateTime;

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

import org.springframework.format.annotation.DateTimeFormat;

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 PublicScheduleAdminUpdateReqDto {

@NotNull
private DetailClassification classification;

private EventTag eventTag;

private JobTag jobTag;

private TechTag techTag;

@NotBlank
@Size(max = 50, message = "제목은 50자이하로 입력해주세요.")
private String title;

@Size(max = 2000, message = "내용은 2000자이하로 입력해주세요.")
private String content;

private String link;

@NotNull
private ScheduleStatus status;

@NotNull
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime startTime;

@NotNull
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime endTime;

@Builder
private PublicScheduleAdminUpdateReqDto(DetailClassification classification, EventTag eventTag, JobTag jobTag,
TechTag techTag, String title, String content, String link, ScheduleStatus status, LocalDateTime startTime,
LocalDateTime endTime) {

this.classification = classification;
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;

}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,83 @@
package gg.calendar.api.admin.schedule.publicschedule.controller.response;

import java.time.LocalDateTime;

import gg.data.calendar.PublicSchedule;
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 PublicScheduleAdminUpdateResDto {

private Long id;

private String classification;

private EventTag eventTag;

private JobTag jobTag;

private TechTag techTag;

private String author;

private String title;

private String content;

private String link;

private Integer sharedCount;

private ScheduleStatus status;

private LocalDateTime startTime;

private LocalDateTime endTime;

@Builder
private PublicScheduleAdminUpdateResDto(Long id, String classification, EventTag eventTag, JobTag jobTag,
TechTag techTag,
String author, String title, String content, String link, Integer sharedCount, ScheduleStatus status,
LocalDateTime startTime, LocalDateTime endTime) {
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.sharedCount = sharedCount;
this.status = status;
this.startTime = startTime;
this.endTime = endTime;

}

public static PublicScheduleAdminUpdateResDto toDto(PublicSchedule publicSchedule) {
return PublicScheduleAdminUpdateResDto.builder()
.id(publicSchedule.getId())
.classification(publicSchedule.getClassification().name())
.eventTag(publicSchedule.getEventTag())
.jobTag(publicSchedule.getJobTag())
.techTag(publicSchedule.getTechTag())
.author(publicSchedule.getAuthor())
.title(publicSchedule.getTitle())
.content(publicSchedule.getContent())
.link(publicSchedule.getLink())
.sharedCount(publicSchedule.getSharedCount())
.status(publicSchedule.getStatus())
.startTime(publicSchedule.getStartTime())
.endTime(publicSchedule.getEndTime())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

import gg.admin.repo.calendar.PublicScheduleAdminRepository;
import gg.calendar.api.admin.schedule.publicschedule.controller.request.PublicScheduleAdminCreateReqDto;
import gg.calendar.api.admin.schedule.publicschedule.controller.request.PublicScheduleAdminUpdateReqDto;
import gg.calendar.api.admin.schedule.publicschedule.controller.response.PublicScheduleAdminResDto;
import gg.calendar.api.admin.schedule.publicschedule.controller.response.PublicScheduleAdminUpdateResDto;
import gg.data.calendar.PublicSchedule;
import gg.data.calendar.type.DetailClassification;
import gg.utils.dto.PageResponseDto;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.CustomRuntimeException;
import gg.utils.exception.custom.InvalidParameterException;
import gg.utils.exception.custom.NotExistException;
import lombok.RequiredArgsConstructor;

@Service
Expand All @@ -38,8 +41,8 @@ public void createPublicSchedule(PublicScheduleAdminCreateReqDto publicScheduleA
publicScheduleAdminRepository.save(publicSchedule);
}

public PageResponseDto<PublicScheduleAdminResDto> findAllByClassification(
DetailClassification detailClassification, int page, int size) {
public PageResponseDto<PublicScheduleAdminResDto> findAllByClassification(DetailClassification detailClassification,
int page, int size) {

Pageable pageable = PageRequest.of(page - 1, size,
Sort.by(Sort.Order.asc("status"), Sort.Order.asc("startTime")));
Copy link
Contributor

Choose a reason for hiding this comment

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

벌써 정렬까지 대단하십니다.

Expand All @@ -53,9 +56,28 @@ public PageResponseDto<PublicScheduleAdminResDto> findAllByClassification(
return PageResponseDto.of(publicSchedules.getTotalElements(), publicScheduleList);
}

@Transactional
public PublicScheduleAdminUpdateResDto updatePublicSchedule(
PublicScheduleAdminUpdateReqDto publicScheduleAdminUpdateReqDto, Long id) {
dateTimeErrorCheck(publicScheduleAdminUpdateReqDto.getStartTime(),
publicScheduleAdminUpdateReqDto.getEndTime());

PublicSchedule publicSchedule = publicScheduleAdminRepository.findById(id)
.orElseThrow(() -> new NotExistException(ErrorCode.PUBLIC_SCHEDULE_NOT_FOUND));

publicSchedule.update(publicScheduleAdminUpdateReqDto.getClassification(),
publicScheduleAdminUpdateReqDto.getEventTag(), publicScheduleAdminUpdateReqDto.getJobTag(),
publicScheduleAdminUpdateReqDto.getTechTag(), publicScheduleAdminUpdateReqDto.getTitle(),
publicScheduleAdminUpdateReqDto.getContent(), publicScheduleAdminUpdateReqDto.getLink(),
publicScheduleAdminUpdateReqDto.getStartTime(), publicScheduleAdminUpdateReqDto.getEndTime(),
publicScheduleAdminUpdateReqDto.getStatus());

return PublicScheduleAdminUpdateResDto.toDto(publicSchedule);
}

private void dateTimeErrorCheck(LocalDateTime startTime, LocalDateTime endTime) {
if (startTime.isAfter(endTime)) {
throw new CustomRuntimeException(ErrorCode.CALENDAR_BEFORE_DATE);
throw new InvalidParameterException(ErrorCode.CALENDAR_BEFORE_DATE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public PublicSchedule createPublicSchedule() {
.title("취업설명회")
.content("취업설명회입니다.")
.link("https://gg.42seoul.kr")
.status(ScheduleStatus.ACTIVATE)
.startTime(LocalDateTime.now())
.endTime(LocalDateTime.now().plusDays(10))
.build();
Expand Down
Loading
Loading