From 9917e4f5127f193b83f04d688095d4890383a4ce Mon Sep 17 00:00:00 2001 From: KWY Date: Tue, 10 Oct 2023 03:15:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?#233=20[test]=20test=20case=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/MeetingConfirmRequestDto.java | 4 + .../dto/request/UserRequestDto.java | 4 + .../java/com/asap/server/domain/Meeting.java | 2 +- .../java/com/asap/server/domain/User.java | 2 +- .../meeting/ConfirmMeetingMethodTest.java | 83 +++++++++++++++++++ 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java diff --git a/src/main/java/com/asap/server/controller/dto/request/MeetingConfirmRequestDto.java b/src/main/java/com/asap/server/controller/dto/request/MeetingConfirmRequestDto.java index b082cd56..b5ad3c61 100644 --- a/src/main/java/com/asap/server/controller/dto/request/MeetingConfirmRequestDto.java +++ b/src/main/java/com/asap/server/controller/dto/request/MeetingConfirmRequestDto.java @@ -4,11 +4,15 @@ import java.util.List; import javax.validation.constraints.NotNull; import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter +@Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class MeetingConfirmRequestDto { @NotNull(message = "회의 진행 월이 입력되지 않았습니다.") private String month; diff --git a/src/main/java/com/asap/server/controller/dto/request/UserRequestDto.java b/src/main/java/com/asap/server/controller/dto/request/UserRequestDto.java index d9b5c4cd..c439d096 100644 --- a/src/main/java/com/asap/server/controller/dto/request/UserRequestDto.java +++ b/src/main/java/com/asap/server/controller/dto/request/UserRequestDto.java @@ -1,11 +1,15 @@ package com.asap.server.controller.dto.request; import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter +@Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class UserRequestDto { private Long id; private String name; diff --git a/src/main/java/com/asap/server/domain/Meeting.java b/src/main/java/com/asap/server/domain/Meeting.java index cc03ab9c..1d4221be 100644 --- a/src/main/java/com/asap/server/domain/Meeting.java +++ b/src/main/java/com/asap/server/domain/Meeting.java @@ -22,7 +22,7 @@ @Entity @Getter @Builder -@AllArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Meeting extends AuditingTimeEntity { @Id diff --git a/src/main/java/com/asap/server/domain/User.java b/src/main/java/com/asap/server/domain/User.java index d7a674db..aa15491b 100644 --- a/src/main/java/com/asap/server/domain/User.java +++ b/src/main/java/com/asap/server/domain/User.java @@ -23,7 +23,7 @@ @Getter @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class User extends AuditingTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java b/src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java new file mode 100644 index 00000000..16110281 --- /dev/null +++ b/src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java @@ -0,0 +1,83 @@ +package com.asap.server.service.meeting; + +import com.asap.server.controller.dto.request.MeetingConfirmRequestDto; +import com.asap.server.controller.dto.request.UserRequestDto; +import com.asap.server.domain.Meeting; +import com.asap.server.domain.Place; +import com.asap.server.domain.User; +import com.asap.server.domain.enums.Duration; +import com.asap.server.domain.enums.PlaceType; +import com.asap.server.domain.enums.Role; +import com.asap.server.domain.enums.TimeSlot; +import com.asap.server.repository.MeetingRepository; +import com.asap.server.service.MeetingService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.persistence.EntityManager; +import javax.transaction.Transactional; +import java.util.List; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@SpringBootTest +@Transactional +public class ConfirmMeetingMethodTest { + @Autowired + private MeetingService meetingService; + @Autowired + private MeetingRepository meetingRepository; + @Autowired + private EntityManager em; + + @Test + @DisplayName("회의 확정시 ConfirmedDateTime 은 Update 된다.") + void setConfirmDateTimeTest() { + // given + final Place place = Place.builder() + .placeType(PlaceType.OFFLINE) + .build(); + final Meeting meeting = Meeting.builder() + .title("회의 테스트") + .password("0000") + .additionalInfo("") + .duration(Duration.HALF) + .place(place) + .build(); + final User user = User.builder() + .meeting(meeting) + .name("강원용") + .role(Role.HOST) + .isFixed(false) + .build(); + meeting.setHost(user); + + em.persist(meeting); + em.persist(user); + em.flush(); + em.clear(); + + final UserRequestDto userDto = UserRequestDto.builder() + .id(user.getId()) + .name(user.getName()) + .build(); + final MeetingConfirmRequestDto body = MeetingConfirmRequestDto.builder() + .month("09") + .day("07") + .dayOfWeek("월") + .startTime(TimeSlot.SLOT_6_00) + .endTime(TimeSlot.SLOT_6_30) + .users(List.of(userDto)) + .build(); + + // when + meetingService.confirmMeeting(body, meeting.getId(), user.getId()); + + // then + final Meeting result = meetingRepository.findById(meeting.getId()).get(); + assertThat(result.isConfirmedMeeting()).isTrue(); + } + +} From c411935c31e106b67a101959d1f678524b17f07b Mon Sep 17 00:00:00 2001 From: KWY Date: Tue, 10 Oct 2023 03:16:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?#233=20[feat]=20save=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=ED=86=B5=ED=95=B4=20update=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/asap/server/service/MeetingService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/asap/server/service/MeetingService.java b/src/main/java/com/asap/server/service/MeetingService.java index 037f280f..a1a6444e 100644 --- a/src/main/java/com/asap/server/service/MeetingService.java +++ b/src/main/java/com/asap/server/service/MeetingService.java @@ -98,17 +98,17 @@ public void confirmMeeting( userService.setFixedUsers(meeting, meetingConfirmRequestDto.getUsers()); - LocalDate fixedDate = DateUtil.transformLocalDate(meetingConfirmRequestDto.getMonth(), meetingConfirmRequestDto.getDay()); + deleteMeetingTimes(meeting); + LocalDate fixedDate = DateUtil.transformLocalDate(meetingConfirmRequestDto.getMonth(), meetingConfirmRequestDto.getDay()); LocalTime startTime = DateUtil.parseLocalTime(meetingConfirmRequestDto.getStartTime().getTime()); LocalTime endTime = DateUtil.parseLocalTime(meetingConfirmRequestDto.getEndTime().getTime()); LocalDateTime fixedStartDateTime = LocalDateTime.of(fixedDate, startTime); LocalDateTime fixedEndDateTime = LocalDateTime.of(fixedDate, endTime); - meeting.setConfirmedDateTime(fixedStartDateTime, fixedEndDateTime); - deleteMeetingTimes(meeting); + meetingRepository.save(meeting); } private void deleteMeetingTimes(final Meeting meeting) { From 5f778bfe2e8d11958a2e3c2cfb486c453731e155 Mon Sep 17 00:00:00 2001 From: KWY Date: Tue, 10 Oct 2023 09:27:30 +0900 Subject: [PATCH 3/3] =?UTF-8?q?#233=20[fix]=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8B=9C=20entity=20manager=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/meeting/ConfirmMeetingMethodTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java b/src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java index 16110281..c81d1b6d 100644 --- a/src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java +++ b/src/test/java/com/asap/server/service/meeting/ConfirmMeetingMethodTest.java @@ -9,7 +9,6 @@ import com.asap.server.domain.enums.PlaceType; import com.asap.server.domain.enums.Role; import com.asap.server.domain.enums.TimeSlot; -import com.asap.server.repository.MeetingRepository; import com.asap.server.service.MeetingService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -28,8 +27,6 @@ public class ConfirmMeetingMethodTest { @Autowired private MeetingService meetingService; @Autowired - private MeetingRepository meetingRepository; - @Autowired private EntityManager em; @Test @@ -76,7 +73,7 @@ void setConfirmDateTimeTest() { meetingService.confirmMeeting(body, meeting.getId(), user.getId()); // then - final Meeting result = meetingRepository.findById(meeting.getId()).get(); + final Meeting result = em.find(Meeting.class, meeting.getId()); assertThat(result.isConfirmedMeeting()).isTrue(); }