Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
@@ -1,17 +1,18 @@
package gg.calendar.api.admin.schedule.privateschedule.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.calendar.api.admin.schedule.privateschedule.service.PrivateScheduleAdminService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/calendar")
@RequestMapping("/admin/calendar/private")
public class PrivateScheduleAdminController {

private final PrivateScheduleAdminService privateScheduleAdminService;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -19,9 +18,6 @@
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;
import gg.utils.dto.PageResponseDto;
import lombok.RequiredArgsConstructor;

@RestController
Expand All @@ -38,18 +34,6 @@ public ResponseEntity<Void> publicScheduleCreate(
return ResponseEntity.status(HttpStatus.CREATED).build();
}

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

PageResponseDto<PublicScheduleAdminResDto> pageResponseDto = publicScheduleAdminService.findAllByClassification(
detailClassification, page, size);

return ResponseEntity.ok(pageResponseDto);
}

@PutMapping("/{id}")
public ResponseEntity<PublicScheduleAdminUpdateResDto> publicScheduleUpdate(
@RequestBody @Valid PublicScheduleAdminUpdateReqDto publicScheduleAdminUpdateReqDto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,4 @@ public PublicScheduleAdminResDto(PublicSchedule publicSchedule) {
this.sharedCount = publicSchedule.getSharedCount();
this.status = publicSchedule.getStatus();
}

@Override
public String toString() {
return "PublicScheduleAdminResDto{" + "id=" + id + ", classification=" + classification + ", eventTag="
+ eventTag + ", jobTag=" + jobTag + ", techTag=" + techTag + ", author='" + author + '\'' + ", title='"
+ title + '\'' + ", startTime=" + startTime + ", endTime=" + endTime + ", link='" + link + '\''
+ ", sharedCount=" + sharedCount + ", status=" + status + '}';
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package gg.calendar.api.admin.schedule.publicschedule.service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -17,9 +11,7 @@
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.data.calendar.type.ScheduleStatus;
import gg.utils.dto.PageResponseDto;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.InvalidParameterException;
import gg.utils.exception.custom.NotExistException;
Expand All @@ -42,21 +34,6 @@ public void createPublicSchedule(PublicScheduleAdminCreateReqDto publicScheduleA
publicScheduleAdminRepository.save(publicSchedule);
}

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")));

Page<PublicSchedule> publicSchedules = publicScheduleAdminRepository.findAllByClassification(
detailClassification, pageable);

List<PublicScheduleAdminResDto> publicScheduleList = publicSchedules.stream()
.map(PublicScheduleAdminResDto::new)
.collect(Collectors.toList());
return PageResponseDto.of(publicSchedules.getTotalElements(), publicScheduleList);
}

@Transactional
public PublicScheduleAdminUpdateResDto updatePublicSchedule(
PublicScheduleAdminUpdateReqDto publicScheduleAdminUpdateReqDto, Long id) {
Expand All @@ -80,10 +57,14 @@ public PublicScheduleAdminUpdateResDto updatePublicSchedule(
public void deletePublicSchedule(Long id) {
PublicSchedule publicSchedule = publicScheduleAdminRepository.findById(id)
.orElseThrow(() -> new NotExistException(ErrorCode.PUBLIC_SCHEDULE_NOT_FOUND));
isDeleted(publicSchedule);
publicSchedule.delete();
}

private void isDeleted(PublicSchedule publicSchedule) {
if (publicSchedule.getStatus().equals(ScheduleStatus.DELETE)) {
throw new InvalidParameterException(ErrorCode.PUBLIC_SCHEDULE_ALREADY_DELETED);
}
publicSchedule.delete();
}

public PublicScheduleAdminResDto detailPublicSchedule(Long id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gg.calendar.api.admin.schedule.totalschedule.controller;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.calendar.api.admin.schedule.totalschedule.controller.response.TotalScheduleAdminResDto;
import gg.calendar.api.admin.schedule.totalschedule.service.TotalScheduleAdminService;
import gg.data.calendar.type.DetailClassification;
import gg.utils.dto.PageRequestDto;
import gg.utils.dto.PageResponseDto;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/calendar")
public class TotalScheduleAdminController {

private final TotalScheduleAdminService totalScheduleAdminService;

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

PageResponseDto<TotalScheduleAdminResDto> pageResponseDto = totalScheduleAdminService.findAllByClassification(
detailClassification, page, size);

return ResponseEntity.ok(pageResponseDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package gg.calendar.api.admin.schedule.totalschedule.controller.response;

import java.time.LocalDateTime;

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

private Long id;

private DetailClassification classification;

private EventTag eventTag;

private JobTag jobTag;

private TechTag techTag;

private String author;

private String title;

private LocalDateTime startTime;

private LocalDateTime endTime;

private String link;

private Integer sharedCount;

private ScheduleStatus status;

@Builder
public TotalScheduleAdminResDto(PublicSchedule publicSchedule) {
this.id = publicSchedule.getId();
this.classification = publicSchedule.getClassification();
this.eventTag = publicSchedule.getEventTag();
this.jobTag = publicSchedule.getJobTag();
this.techTag = publicSchedule.getTechTag();
this.author = publicSchedule.getAuthor();
this.title = publicSchedule.getTitle();
this.startTime = publicSchedule.getStartTime();
this.endTime = publicSchedule.getEndTime();
this.link = publicSchedule.getLink();
this.sharedCount = publicSchedule.getSharedCount();
this.status = publicSchedule.getStatus();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gg.calendar.api.admin.schedule.totalschedule.service;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.admin.repo.calendar.PublicScheduleAdminRepository;
import gg.calendar.api.admin.schedule.totalschedule.controller.response.TotalScheduleAdminResDto;
import gg.data.calendar.PublicSchedule;
import gg.data.calendar.type.DetailClassification;
import gg.utils.dto.PageResponseDto;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class TotalScheduleAdminService {

private final PublicScheduleAdminRepository publicScheduleAdminRepository;

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

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

Page<PublicSchedule> publicSchedules = publicScheduleAdminRepository.findAllByClassification(
detailClassification, pageable);

List<TotalScheduleAdminResDto> publicScheduleList = publicSchedules.stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

자바 11버전 collects

.map(TotalScheduleAdminResDto::new)
.collect(Collectors.toList());
return PageResponseDto.of(publicSchedules.getTotalElements(), publicScheduleList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Stream;

import javax.persistence.EntityManager;
import javax.transaction.Transactional;
Expand All @@ -16,18 +15,11 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import gg.admin.repo.calendar.PublicScheduleAdminRepository;
Expand All @@ -46,7 +38,6 @@
import gg.data.user.User;
import gg.utils.TestDataUtils;
import gg.utils.annotation.IntegrationTest;
import gg.utils.dto.PageResponseDto;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down Expand Up @@ -184,57 +175,10 @@ public void createPublicScheduleContentMax() throws Exception {
}
}

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Nested
@DisplayName("Admin PublicSchedule 조회 테스트")
class GetPublicScheduleAdminTest {

private Stream<Arguments> inputParams() {
return Stream.of(Arguments.of("EVENT", 2, 10), Arguments.of("JOB_NOTICE", 1, 10),
Arguments.of("PRIVATE_SCHEDULE", 1, 2));
}

@ParameterizedTest
@MethodSource("inputParams")
@DisplayName("Admin PublicSchedule 태그 조회 테스트 - 성공")
void getPublicScheduleAdminClassificationListTestSuccess(String tags, int page, int size) throws Exception {
// given
publicScheduleAdminMockData.createPublicScheduleEvent(20);
publicScheduleAdminMockData.createPublicScheduleJob(10);
publicScheduleAdminMockData.createPublicSchedulePrivate(5);

MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("page", String.valueOf(page));
params.add("size", String.valueOf(size));

// when
// multivalue map 을 통해서 값이 넘어옴
String response = mockMvc.perform(
get("/admin/calendar/public/list/{detailClassification}", tags).header("Authorization",
"Bearer " + accessToken).params(params))
.andDo(print())
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();

// then
PageResponseDto<PublicScheduleAdminResDto> pageResponseDto = objectMapper.readValue(response,
new TypeReference<>() {
});
List<PublicScheduleAdminResDto> result = pageResponseDto.getContent();

if (DetailClassification.valueOf(tags) == DetailClassification.PRIVATE_SCHEDULE) {
assertThat(result.size()).isEqualTo(2);
} else {
assertThat(result.size()).isEqualTo(10);
}

for (PublicScheduleAdminResDto dto : result) {
System.out.println(dto.toString());
}
}

@Test
@DisplayName("Admin PublicSchedule 상세 조회 테스트 - 성공")
void getPublicScheduleAdminDetailTestSuccess() throws Exception {
Expand Down
Loading
Loading