Skip to content

Commit

Permalink
Merge pull request #80 from HongDam-org/feat/plan-day-fix
Browse files Browse the repository at this point in the history
[FIX] Plan에 planDay(yyyy-MM-dd HH:mm) 추가
  • Loading branch information
jinjoo-lab authored Dec 20, 2023
2 parents af2ea1c + 09d6488 commit 80505f0
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package com.twtw.backend.domain.plan.dto.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.twtw.backend.domain.plan.dto.response.PlaceDetails;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.UUID;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SavePlanRequest {
private UUID groupId;

@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm",
timezone = "Asia/Seoul")
private LocalDateTime planDay;

private PlaceDetails placeDetails;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class PlanInfoResponse {
private UUID planId;
private UUID placeId;
private UUID planMakerId;
private String planDay;
private PlaceDetails placeDetails;
private GroupInfoResponse groupInfo;
private List<MemberResponse> members;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.hibernate.annotations.Where;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -63,10 +64,13 @@ public class Plan implements Auditable {
@Column(nullable = false)
private BaseTime baseTime;

public Plan(Member member, Place place, Group group) {
private LocalDateTime planDay;

public Plan(Member member, Place place, Group group, LocalDateTime planDay) {
this.planMembers.add(new PlanMember(this, member, true));
organizePlace(place);
organizeGroup(group);
this.planDay = planDay;
}

public void addMember(final Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public interface PlanMapper {
@Mapping(target = "planMakerId", source = "plan.planMakerId")
@Mapping(target = "groupInfo", source = "groupInfoResponse")
@Mapping(target = "members", source = "memberResponses")
@Mapping(target = "planDay", source = "planDay")
PlanInfoResponse toPlanInfoResponse(
Plan plan,
PlaceClientDetails placeDetails,
String planDay,
GroupInfoResponse groupInfoResponse,
List<MemberResponse> memberResponses);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -77,7 +78,7 @@ public PlanResponse savePlan(final SavePlanRequest request) {
Member member = authService.getMemberByJwt();
Group group = groupService.getGroupEntity(request.getGroupId());
Place place = placeService.getEntityByDetail(request.getPlaceDetails());
Plan plan = new Plan(member, place, group);
Plan plan = new Plan(member, place, group, request.getPlanDay());

return planMapper.toPlanResponse(planRepository.save(plan));
}
Expand Down Expand Up @@ -105,10 +106,11 @@ public PlanInfoResponse getPlanById(UUID id) {
private PlanInfoResponse getPlanInfoResponse(final Plan plan) {
GroupInfoResponse groupInfo = groupService.getGroupInfoResponse(plan.getGroup());
PlaceClientDetails placeDetails = placeService.getPlaceDetails(plan.getPlace());

String planDay = plan.getPlanDay().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
List<MemberResponse> memberResponse = toMemberResponse(plan);

return planMapper.toPlanInfoResponse(plan, placeDetails, groupInfo, memberResponse);
return planMapper.toPlanInfoResponse(
plan, placeDetails, planDay, groupInfo, memberResponse);
}

public void deletePlan(UUID id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

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

@DisplayName("GroupRepository의")
Expand All @@ -41,7 +42,7 @@ void makeGroup() {

Place place = PlaceEntityFixture.FIRST_PLACE.toEntity();

Plan plan = new Plan(member1, place, group);
Plan plan = new Plan(member1, place, group, LocalDateTime.of(2023, 12, 25, 13, 30));
plan.addMember(member2);

// when
Expand Down Expand Up @@ -86,7 +87,7 @@ void getPlan() {

Place place = PlaceEntityFixture.FIRST_PLACE.toEntity();

Plan plan = new Plan(member1, place, group);
Plan plan = new Plan(member1, place, group, LocalDateTime.of(2023, 12, 25, 13, 30));
plan.addMember(member2);

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -106,6 +107,7 @@ void savePlan() throws Exception {
toRequestBody(
new SavePlanRequest(
UUID.randomUUID(),
LocalDateTime.of(2023, 12, 25, 15, 30),
new PlaceDetails(
"카페 온마이마인드",
"https://place.map.kakao.com/1625295668",
Expand Down Expand Up @@ -134,6 +136,7 @@ void getPlanById() throws Exception {
UUID.randomUUID(),
UUID.randomUUID(),
UUID.randomUUID(),
"2023-12-25 15:30",
new PlaceDetails(
"카페 온마이마인드",
"https://place.map.kakao.com/1625295668",
Expand Down Expand Up @@ -207,6 +210,7 @@ void joinPlan() throws Exception {
toRequestBody(
new SavePlanRequest(
UUID.randomUUID(),
LocalDateTime.of(2023, 12, 25, 13, 30),
new PlaceDetails(
"이디야커피 안성죽산점",
"http://place.map.kakao.com/1562566188",
Expand Down Expand Up @@ -259,6 +263,7 @@ void getPlans() throws Exception {
UUID.randomUUID(),
UUID.randomUUID(),
UUID.randomUUID(),
"2023-12-25 15:30",
new PlaceDetails(
"카페 온마이마인드",
"https://place.map.kakao.com/1625295668",
Expand All @@ -278,6 +283,7 @@ void getPlans() throws Exception {
UUID.randomUUID(),
UUID.randomUUID(),
UUID.randomUUID(),
"2023-12-26 15:30",
new PlaceDetails(
"카페 온유어마인드",
"https://place.map.kakao.com/1625295669",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

Expand All @@ -37,7 +38,9 @@ void saveAndFindById() {
final Member member = memberRepository.save(MemberEntityFixture.LOGIN_MEMBER.toEntity());
final Plan plan =
PlanEntityFixture.FIRST_PLACE.toEntity(
member, GroupEntityFixture.BTS_GROUP.toEntity(member));
member,
GroupEntityFixture.BTS_GROUP.toEntity(member),
LocalDateTime.of(2023, 12, 25, 13, 30));

// when
final UUID expected = planRepository.save(plan).getId();
Expand All @@ -58,7 +61,15 @@ void softDelete() {

final Group group = new Group("그룹", "http://abcdefg", member);

final UUID planId = planRepository.save(new Plan(member, place, group)).getId();
final UUID planId =
planRepository
.save(
new Plan(
member,
place,
group,
LocalDateTime.of(2023, 12, 25, 13, 30)))
.getId();

// when
planRepository.deleteById(planId);
Expand Down Expand Up @@ -88,8 +99,16 @@ void findAllPlanByMember() {

final Group group = new Group("그룹", "http://abcdefg", member);

final Plan plan = planRepository.save(new Plan(member, firstPlace, group));
planRepository.save(new Plan(member, secondPlace, new Group("1", "2", member)));
final Plan plan =
planRepository.save(
new Plan(
member, firstPlace, group, LocalDateTime.of(2023, 12, 25, 13, 30)));
planRepository.save(
new Plan(
member,
secondPlace,
new Group("1", "2", member),
LocalDateTime.of(2023, 12, 26, 13, 30)));
plan.addMember(firstMember);
plan.addMember(secondMember);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;

Expand Down Expand Up @@ -58,7 +59,9 @@ void savePlan() {
final PlanResponse planResponse =
planService.savePlan(
new SavePlanRequest(
groupId, PlaceDetailsFixture.FIRST_PLACE.toPlaceDetails()));
groupId,
LocalDateTime.of(2023, 12, 25, 15, 30),
PlaceDetailsFixture.FIRST_PLACE.toPlaceDetails()));

// then
final Optional<Plan> result = planRepository.findById(planResponse.getPlanId());
Expand All @@ -75,7 +78,8 @@ void joinPlan() {
new Plan(
member,
PlaceEntityFixture.FIRST_PLACE.toEntity(),
GroupEntityFixture.BTS_GROUP.toEntity(loginUser)));
GroupEntityFixture.BTS_GROUP.toEntity(loginUser),
LocalDateTime.of(2023, 12, 25, 15, 30)));
final UUID planId = plan.getId();

// when
Expand All @@ -92,7 +96,9 @@ void outPlan() {
// given
final Plan plan =
PlanEntityFixture.SECOND_PLACE.toEntity(
loginUser, GroupEntityFixture.HDJ_GROUP.toEntity(loginUser));
loginUser,
GroupEntityFixture.HDJ_GROUP.toEntity(loginUser),
LocalDateTime.of(2023, 12, 25, 13, 30));
final UUID planId = planRepository.save(plan).getId();

// when
Expand All @@ -113,7 +119,8 @@ void getPlanById() {
new Plan(
loginUser,
PlaceEntityFixture.SECOND_PLACE.toEntity(),
GroupEntityFixture.HDJ_GROUP.toEntity(loginUser)))
GroupEntityFixture.HDJ_GROUP.toEntity(loginUser),
LocalDateTime.of(2023, 12, 25, 15, 30)))
.getId();

// when
Expand All @@ -133,7 +140,8 @@ void deletePlan() {
new Plan(
loginUser,
PlaceEntityFixture.SECOND_PLACE.toEntity(),
GroupEntityFixture.HDJ_GROUP.toEntity(loginUser)))
GroupEntityFixture.HDJ_GROUP.toEntity(loginUser),
LocalDateTime.of(2023, 12, 25, 15, 30)))
.getId();

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;

@RequiredArgsConstructor
public enum PlanEntityFixture {
FIRST_PLACE(PlaceEntityFixture.FIRST_PLACE.toEntity()),
SECOND_PLACE(PlaceEntityFixture.SECOND_PLACE.toEntity());

private final Place place;

public Plan toEntity(final Member member, final Group group) {
return new Plan(member, place, group);
public Plan toEntity(final Member member, final Group group, final LocalDateTime planDay) {
return new Plan(member, place, group, planDay);
}
}

0 comments on commit 80505f0

Please sign in to comment.