Skip to content

Commit

Permalink
[Feature] 전체일정 상세조회 API 추가, test 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
wonie committed Dec 31, 2024
1 parent 6746df0 commit f05c901
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -16,6 +17,7 @@
import gg.auth.argumentresolver.Login;
import gg.calendar.api.user.schedule.publicschedule.controller.request.PublicScheduleCreateReqDto;
import gg.calendar.api.user.schedule.publicschedule.controller.request.PublicScheduleUpdateReqDto;
import gg.calendar.api.user.schedule.publicschedule.controller.response.PublicScheduleDetailRetrieveResDto;
import gg.calendar.api.user.schedule.publicschedule.controller.response.PublicScheduleUpdateResDto;
import gg.calendar.api.user.schedule.publicschedule.service.PublicScheduleService;
import gg.data.calendar.PublicSchedule;
Expand Down Expand Up @@ -49,5 +51,12 @@ public ResponseEntity<Void> publicScheduleDelete(@PathVariable Long id,
publicScheduleService.deletePublicSchedule(id, userDto.getId());
return ResponseEntity.noContent().build();
}

@GetMapping("/{id}")
public ResponseEntity<PublicScheduleDetailRetrieveResDto> publicScheduleDetailRetriveGet(@PathVariable Long id,
@Login @Parameter(hidden = true) UserDto userDto) {
PublicSchedule publicSchedule = publicScheduleService.getPublicScheduleDetailRetrive(id, userDto.getId());
return ResponseEntity.ok(PublicScheduleDetailRetrieveResDto.toDto(publicSchedule));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package gg.calendar.api.user.schedule.publicschedule.controller.response;

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.TechTag;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PublicScheduleDetailRetrieveResDto {
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 String startTime;
private String endTime;
private Integer sharedCount;

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

public static PublicScheduleDetailRetrieveResDto toDto(PublicSchedule publicSchedule) {
return PublicScheduleDetailRetrieveResDto.builder()
.id(publicSchedule.getId())
.classification(publicSchedule.getClassification())
.eventTag(publicSchedule.getEventTag())
.jobTag(publicSchedule.getJobTag())
.techTag(publicSchedule.getTechTag())
.author(publicSchedule.getAuthor())
.title(publicSchedule.getTitle())
.content(publicSchedule.getContent())
.link(publicSchedule.getLink())
.startTime(publicSchedule.getStartTime().toString())
.endTime(publicSchedule.getEndTime().toString())
.sharedCount(publicSchedule.getSharedCount())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public void deletePublicSchedule(Long scheduleId, Long userId) {
existingSchedule.delete();
}

public PublicSchedule getPublicScheduleDetailRetrive(Long sheduleId, Long userId) {
User user = userRepository.getById(userId);
PublicSchedule publicRetriveSchedule = publicScheduleRepository.findById(sheduleId)
.orElseThrow(() -> new NotExistException(ErrorCode.PUBLIC_SCHEDULE_NOT_FOUND));
checkAuthor(publicRetriveSchedule.getAuthor(), user);
return publicRetriveSchedule;
}

private void duplicateDelete(PublicSchedule existingSchedule) {
if (existingSchedule.getStatus().isDelete()) {
throw new DuplicationException(ErrorCode.CALENDAR_ALREADY_DELETE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,4 +601,105 @@ void deletePublicScheduleFailWrongId() throws Exception {
}
}

@Nested
@DisplayName("공개일정:상세조회")
class RetrievePublicScheduleDetail {
@Test
@DisplayName("공개일정상세조회성공")
void retrievePublicScheduleDetailSuccess() throws Exception {
// given
PublicSchedule publicSchedule = PublicScheduleCreateReqDto.toEntity(user.getIntraId(),
PublicScheduleCreateReqDto.builder()
.classification(DetailClassification.EVENT)
.author(user.getIntraId())
.title("Original Title")
.content("Original Content")
.link("http://original.com")
.startTime(LocalDateTime.now())
.endTime(LocalDateTime.now().plusDays(1))
.build());
publicScheduleRepository.save(publicSchedule);
// when
mockMvc.perform(
get("/calendar/public/" + publicSchedule.getId()).header("Authorization", "Bearer " + accssToken))
.andExpect(status().isOk())
.andExpect(jsonPath("$.title").value("Original Title"))
.andExpect(jsonPath("$.content").value("Original Content"))
.andExpect(jsonPath("$.link").value("http://original.com"))
.andDo(print());
}

@Test
@DisplayName("공개일정상세조회실패-작성자가 다를 때")
void retrievePublicScheduleDetailFailNotMatchAuthor() throws Exception {
// given
PublicSchedule publicSchedule = PublicScheduleCreateReqDto.toEntity("another",
PublicScheduleCreateReqDto.builder()
.classification(DetailClassification.EVENT)
.author("another")
.title("Original Title")
.content("Original Content")
.link("http://original.com")
.startTime(LocalDateTime.now())
.endTime(LocalDateTime.now().plusDays(1))
.build());
publicScheduleRepository.save(publicSchedule);

// when
mockMvc.perform(
get("/calendar/public/" + publicSchedule.getId()).header("Authorization", "Bearer " + accssToken))
.andExpect(status().isForbidden())
.andDo(print());
}

@Test
@DisplayName("공개일정상세조회실패-잘못된 id일 때(숫자가 아닌 문자열)")
void retrievePublicScheduleDetailFailWrongId() throws Exception {
// given
PublicSchedule publicSchedule = PublicScheduleCreateReqDto.toEntity(user.getIntraId(),
PublicScheduleCreateReqDto.builder()
.classification(DetailClassification.EVENT)
.author(user.getIntraId())
.title("Original Title")
.content("Original Content")
.link("http://original.com")
.startTime(LocalDateTime.now())
.endTime(LocalDateTime.now().plusDays(1))
.build());
publicScheduleRepository.save(publicSchedule);

// when & then
mockMvc.perform(
get("/calendar/public/abc").header("Authorization", "Bearer " + accssToken))
.andExpect(status().isBadRequest())
.andDo(print());

}

@Test
@DisplayName("공개일정상세조회실패-없는 일정일 때")
void retrievePublicScheduleDetailFailNotExist() throws Exception {
//given
PublicSchedule publicSchedule = PublicScheduleCreateReqDto.toEntity(user.getIntraId(),
PublicScheduleCreateReqDto.builder()
.classification(DetailClassification.EVENT)
.author(user.getIntraId())
.title("Original Title")
.content("Original Content")
.link("http://original.com")
.startTime(LocalDateTime.now())
.endTime(LocalDateTime.now().plusDays(1))
.build());
publicScheduleRepository.save(publicSchedule);

//when & then
mockMvc.perform(
get("/calendar/public/9999").header("Authorization", "Bearer " + accssToken))
.andExpect(status().isNotFound())
.andDo(print());

}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package gg.calendar.api.user.schedule.publicschedule.controller.response;

import static org.junit.jupiter.api.Assertions.*;

import java.time.LocalDateTime;

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

import gg.data.calendar.PublicSchedule;
import gg.data.calendar.type.DetailClassification;
import gg.data.calendar.type.EventTag;
import gg.utils.annotation.UnitTest;

@UnitTest
public class PublicScheduleDetailRetrieveResDtoTest {

@Test
@DisplayName("PublicSchedule Entity를 ResponseDto로 변환 성공")
void toDto_Success() {
//given
LocalDateTime startTime = LocalDateTime.now().plusDays(1);
LocalDateTime endTime = LocalDateTime.now().plusDays(2);

PublicSchedule schedule = PublicSchedule.builder()
.classification(DetailClassification.JOB_NOTICE)
.eventTag(EventTag.INSTRUCTION)
.author("testUser")
.title("Test Title")
.content("Test Content")
.link("http://test.com")
.startTime(startTime)
.endTime(endTime)
.build();

//when
PublicScheduleDetailRetrieveResDto responseDto = PublicScheduleDetailRetrieveResDto.toDto(schedule);

//then
assertAll(
() -> assertEquals(null, responseDto.getId()),
() -> assertEquals(DetailClassification.JOB_NOTICE, responseDto.getClassification()),
() -> assertEquals(EventTag.INSTRUCTION, responseDto.getEventTag()),
() -> assertEquals("testUser", responseDto.getAuthor()),
() -> assertEquals("Test Title", responseDto.getTitle()),
() -> assertEquals("Test Content", responseDto.getContent()),
() -> assertEquals("http://test.com", responseDto.getLink()),
() -> assertEquals(startTime.toString(), responseDto.getStartTime()),
() -> assertEquals(endTime.toString(), responseDto.getEndTime()),
() -> assertEquals(schedule.getSharedCount(), responseDto.getSharedCount())
);
}

}

0 comments on commit f05c901

Please sign in to comment.