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 작성 #1089 #1090

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -6,6 +6,7 @@
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;
import org.springframework.web.bind.annotation.PutMapping;
Expand Down Expand Up @@ -58,9 +59,16 @@ public ResponseEntity<PublicScheduleAdminUpdateResDto> publicScheduleUpdate(
return ResponseEntity.ok(publicScheduleAdminUpdateRes);
}

@PatchMapping("/{id}")
public ResponseEntity<Void> publicScheduleDelete(@PathVariable Long id) {
publicScheduleAdminService.deletePublicSchedule(id);
return ResponseEntity.status(HttpStatus.OK).build();
}

@GetMapping("/{id}")
public ResponseEntity<PublicScheduleAdminResDto> publicScheduleDetail(@PathVariable Long id) {
PublicScheduleAdminResDto publicScheduleAdminResDto = publicScheduleAdminService.detailPublicSchedule(id);
return ResponseEntity.ok(publicScheduleAdminResDto);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -75,6 +76,16 @@ public PublicScheduleAdminUpdateResDto updatePublicSchedule(
return PublicScheduleAdminUpdateResDto.toDto(publicSchedule);
}

@Transactional
public void deletePublicSchedule(Long id) {
PublicSchedule publicSchedule = publicScheduleAdminRepository.findById(id)
.orElseThrow(() -> new NotExistException(ErrorCode.PUBLIC_SCHEDULE_NOT_FOUND));
if (publicSchedule.getStatus().equals(ScheduleStatus.DELETE)) {
throw new InvalidParameterException(ErrorCode.PUBLIC_SCHEDULE_ALREADY_DELETED);
}
publicSchedule.delete();
}

public PublicScheduleAdminResDto detailPublicSchedule(Long id) {
PublicSchedule publicSchedule = publicScheduleAdminRepository.findById(id)
.orElseThrow(() -> new NotExistException(ErrorCode.PUBLIC_SCHEDULE_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ private Stream<Arguments> inputParams() {
@ParameterizedTest
@MethodSource("inputParams")
@DisplayName("Admin PublicSchedule 태그 조회 테스트 - 성공")
void getPublicScheduleAdminClassificationListTestSuccess(String tags, int page, int size) throws
Exception {
void getPublicScheduleAdminClassificationListTestSuccess(String tags, int page, int size) throws Exception {
// given
publicScheduleAdminMockData.createPublicScheduleEvent(20);
publicScheduleAdminMockData.createPublicScheduleJob(10);
Expand All @@ -212,14 +211,16 @@ void getPublicScheduleAdminClassificationListTestSuccess(String tags, int page,
// multivalue map 을 통해서 값이 넘어옴
String response = mockMvc.perform(
get("/admin/calendar/public/list/{detailClassification}", tags).header("Authorization",
"Bearer " + accessToken)
.params(params))
"Bearer " + accessToken).params(params))
.andDo(print())
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();

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

Expand Down Expand Up @@ -322,13 +323,15 @@ void updatePublicScheduleAdminTestSuccess() throws Exception {

// when
String response = mockMvc.perform(
put("/admin/calendar/public/{id}", publicSchedule.getId())
.header("Authorization", "Bearer " + accessToken)
put("/admin/calendar/public/{id}", publicSchedule.getId()).header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(publicScheduleAdminUpdateReqDto)))
.andDo(print())
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
.andReturn()
.getResponse()
.getContentAsString();

PublicScheduleAdminUpdateResDto result = objectMapper.readValue(response,
PublicScheduleAdminUpdateResDto.class);
Expand Down Expand Up @@ -367,13 +370,15 @@ void updatePublicScheduleAdminTestFailEndBeforeStart() throws Exception {

// when
String response = mockMvc.perform(
put("/admin/calendar/public/{id}", publicSchedule.getId())
.header("Authorization", "Bearer " + accessToken)
put("/admin/calendar/public/{id}", publicSchedule.getId()).header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(publicScheduleAdminUpdateReqDto)))
.andDo(print())
.andExpect(status().isBadRequest())
.andReturn().getResponse().getContentAsString();
.andReturn()
.getResponse()
.getContentAsString();

List<PublicSchedule> schedules = publicScheduleAdminRepository.findAll();
PublicSchedule result = schedules.get(0);
Expand Down Expand Up @@ -406,13 +411,15 @@ void updatePublicScheduleAdminTestFailTitleMax() throws Exception {

// when
String response = mockMvc.perform(
put("/admin/calendar/public/{id}", publicSchedule.getId())
.header("Authorization", "Bearer " + accessToken)
put("/admin/calendar/public/{id}", publicSchedule.getId()).header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(publicScheduleAdminUpdateReqDto)))
.andDo(print())
.andExpect(status().isBadRequest())
.andReturn().getResponse().getContentAsString();
.andReturn()
.getResponse()
.getContentAsString();

List<PublicSchedule> schedules = publicScheduleAdminRepository.findAll();
PublicSchedule result = schedules.get(0);
Expand Down Expand Up @@ -445,13 +452,15 @@ void updatePublicScheduleAdminTestFailContentMax() throws Exception {

// when
String response = mockMvc.perform(
put("/admin/calendar/public/{id}", publicSchedule.getId())
.header("Authorization", "Bearer " + accessToken)
put("/admin/calendar/public/{id}", publicSchedule.getId()).header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(publicScheduleAdminUpdateReqDto)))
.andDo(print())
.andExpect(status().isBadRequest())
.andReturn().getResponse().getContentAsString();
.andReturn()
.getResponse()
.getContentAsString();

List<PublicSchedule> schedules = publicScheduleAdminRepository.findAll();
PublicSchedule result = schedules.get(0);
Expand Down Expand Up @@ -484,13 +493,14 @@ void updatePublicScheduleAdminTestFailNotExist() throws Exception {

// when
String response = mockMvc.perform(
put("/admin/calendar/public/100")
.header("Authorization", "Bearer " + accessToken)
put("/admin/calendar/public/100").header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(publicScheduleAdminUpdateReqDto)))
.andDo(print())
.andExpect(status().isNotFound())
.andReturn().getResponse().getContentAsString();
.andReturn()
.getResponse()
.getContentAsString();

List<PublicSchedule> schedules = publicScheduleAdminRepository.findAll();
PublicSchedule result = schedules.get(0);
Expand Down Expand Up @@ -523,13 +533,14 @@ void updatePublicScheduleAdminTestFailBadArgument() throws Exception {

// when
String response = mockMvc.perform(
put("/admin/calendar/public/asdasdasd")
.header("Authorization", "Bearer " + accessToken)
put("/admin/calendar/public/asdasdasd").header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(publicScheduleAdminUpdateReqDto)))
.andDo(print())
.andExpect(status().isBadRequest())
.andReturn().getResponse().getContentAsString();
.andReturn()
.getResponse()
.getContentAsString();

List<PublicSchedule> schedules = publicScheduleAdminRepository.findAll();
PublicSchedule result = schedules.get(0);
Expand All @@ -542,5 +553,77 @@ void updatePublicScheduleAdminTestFailBadArgument() throws Exception {
assertThat(result.getStartTime()).isEqualTo(publicSchedule.getStartTime());
assertThat(result.getEndTime()).isEqualTo(publicSchedule.getEndTime());
}

@Test
@DisplayName("Admin PublicSchedule 삭제 테스트 - 성공")
void deletePublicScheduleAdminTestSuccess() throws Exception {
// given
PublicSchedule publicSchedule = publicScheduleAdminMockData.createPublicSchedule();

// when
mockMvc.perform(patch("/admin/calendar/public/{id}", publicSchedule.getId()).header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk());

PublicSchedule result = publicScheduleAdminRepository.findById(publicSchedule.getId()).get();
assertThat(result.getStatus()).isEqualTo(ScheduleStatus.DELETE);
System.out.println("PublicSchedule Status : " + result.getStatus());
}

@Test
@DisplayName("Admin PublicSchedule 삭제 테스트 - 실패 : 잘못된 id형식이 들어왔을 경우")
void deletePublicScheduleAdminTestFailNotBadArgument() throws Exception {
// given
PublicSchedule publicSchedule = publicScheduleAdminMockData.createPublicSchedule();

// when
mockMvc.perform(patch("/admin/calendar/public/qwe1asdv").header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest());

PublicSchedule result = publicScheduleAdminRepository.findById(publicSchedule.getId()).get();
assertThat(result.getStatus()).isEqualTo(ScheduleStatus.ACTIVATE);
System.out.println("PublicSchedule Status : " + result.getStatus());
}

@Test
@DisplayName("Admin PublicSchedule 삭제 테스트 - 실패 : 없는 id가 들어왔을 경우")
void deletePublicScheduleAdminTestFailNotFound() throws Exception {
// given
PublicSchedule publicSchedule = publicScheduleAdminMockData.createPublicSchedule();

// when
mockMvc.perform(patch("/admin/calendar/public/50123125").header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isNotFound());

PublicSchedule result = publicScheduleAdminRepository.findById(publicSchedule.getId()).get();
assertThat(result.getStatus()).isEqualTo(ScheduleStatus.ACTIVATE);
System.out.println("PublicSchedule Status : " + result.getStatus());
}

@Test
@DisplayName("Admin PublicSchedule 삭제 테스트 - 실패 : 이미 삭제된 일정을 삭제하는 경우")
void deletePublicScheduleAdminTestFailAlreadyDelete() throws Exception {
// given
PublicSchedule publicSchedule = publicScheduleAdminMockData.createPublicSchedule();
publicSchedule.delete();
// when
mockMvc.perform(patch("/admin/calendar/public/{id}", publicSchedule.getId()).header("Authorization",
"Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest());

PublicSchedule result = publicScheduleAdminRepository.findById(publicSchedule.getId()).get();
assertThat(result.getStatus()).isEqualTo(ScheduleStatus.DELETE);
System.out.println("PublicSchedule Status : " + result.getStatus());
}
}
}
4 changes: 4 additions & 0 deletions gg-data/src/main/java/gg/data/calendar/PublicSchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,9 @@
this.endTime = endTime;
this.status = status;
}

public void delete() {
this.status = ScheduleStatus.DELETE;
}

Check warning on line 106 in gg-data/src/main/java/gg/data/calendar/PublicSchedule.java

View check run for this annotation

Codecov / codecov/patch

gg-data/src/main/java/gg/data/calendar/PublicSchedule.java#L105-L106

Added lines #L105 - L106 were not covered by tests
}

1 change: 1 addition & 0 deletions gg-utils/src/main/java/gg/utils/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public enum ErrorCode {
CALENDAR_AUTHOR_NOT_MATCH(403, "CA205", "잘못된 사용자입니다."),
PRIVATE_SCHEDULE_NOT_FOUND(404, "CA101", "개인 일정을 찾을 수 없습니다."),
PUBLIC_SCHEDULE_NOT_FOUND(404, "CA102", "공유 일정을 찾을 수 없습니다."),
PUBLIC_SCHEDULE_ALREADY_DELETED(409, "CA104", "이미 삭제된 개인 일정입니다."),
SCHEDULE_GROUP_NOT_FOUND(404, "CA103", "스캐줄 그룹을 찾을 수 없습니다.");

private final int status;
Expand Down
Loading