Skip to content

Commit

Permalink
Merge pull request #83 from HongDam-org/feat/plan-name-update
Browse files Browse the repository at this point in the history
[FEAT] plan name 추가 및 저장, 수정, 조회 로직 수정
  • Loading branch information
ohksj77 authored Dec 26, 2023
2 parents baa93ed + 2f4b5cd commit 83f0037
Show file tree
Hide file tree
Showing 26 changed files with 272 additions and 90 deletions.
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ out/
/src/main/generated/

/src/main/resources/*.json

*.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import lombok.RequiredArgsConstructor;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Profile("!test")
@Configuration
@RequiredArgsConstructor
@EnableWebSocketMessageBroker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
public class FriendResponse {
private UUID memberId;
private String nickname;
private String profileImage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public interface FriendMapper {

@Mapping(target = "memberId", source = "fromMember.id")
@Mapping(target = "nickname", source = "fromMember.nickname")
@Mapping(target = "profileImage", source = "fromMember.profileImage")
FriendResponse toResponse(Friend friend);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public interface GroupMapper {
Group toGroupEntity(MakeGroupRequest groupDto, Member leader);

@Named("groupMemberToMemberResponse")
@Mapping(target = "id", source = "groupMember.member.id")
@Mapping(target = "memberId", source = "groupMember.member.id")
@Mapping(target = "nickname", source = "groupMember.member.nickname")
@Mapping(target = "profileImage", source = "groupMember.member.profileImage")
MemberResponse toGroupMemberResponse(GroupMember groupMember);

@Named("groupMemberToMemberResponseList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Builder
@AllArgsConstructor
public class MemberResponse {
private UUID id;
private UUID memberId;
private String nickname;
private String profileImage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ public interface MemberMapper {
@Mapping(target = "oauthInfo", source = "oauthRequest", qualifiedByName = "convertOauth")
Member toMemberEntity(MemberSaveRequest request);

@Mapping(target = "memberId", source = "member.id")
@Mapping(target = "nickname", source = "member.nickname")
@Mapping(target = "profileImage", source = "member.profileImage")
MemberResponse toMemberResponse(Member member);

default List<MemberResponse> toMemberResponses(List<Member> members) {
return members.stream().map(this::toMemberResponse).toList();
}

@Named("convertOauth")
default OAuth2Info convertOauth(OAuthRequest request) {
return new OAuth2Info(request.getToken(), request.getAuthType());
Expand All @@ -32,7 +39,8 @@ default OAuth2Info convertOauth(OAuthRequest request) {
@IterableMapping(elementTargetType = MemberResponse.class)
List<MemberResponse> toMemberResponses(Set<PlanMember> planMembers);

@Mapping(target = "id", source = "planMember.member.id")
@Mapping(target = "memberId", source = "planMember.member.id")
@Mapping(target = "nickname", source = "planMember.member.nickname")
@Mapping(target = "profileImage", source = "planMember.member.profileImage")
MemberResponse toMemberResponse(PlanMember planMember);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public MemberResponse getResponseByMember(Member member) {
return memberMapper.toMemberResponse(member);
}

public List<MemberResponse> getResponsesByMembers(final List<Member> members) {
return memberMapper.toMemberResponses(members);
}

public List<MemberResponse> getMemberResponses(final Plan plan) {
return memberMapper.toMemberResponses(plan.getPlanMembers());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import lombok.NoArgsConstructor;

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

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

@JsonFormat(
Expand All @@ -23,4 +25,6 @@ public class SavePlanRequest {
private LocalDateTime planDay;

private PlaceDetails placeDetails;

private List<UUID> memberIds;
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
package com.twtw.backend.domain.plan.dto.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;

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

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

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class UpdatePlanRequest {
private UUID planId;

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

private String name;
private String placeName;
private String placeUrl;
private CategoryGroupCode categoryGroupCode;
private String roadAddressName;
private Double longitude;
private Double latitude;
private List<UUID> memberIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public class PlanInfoResponse {
private UUID planId;
private UUID placeId;
private UUID planMakerId;
private String name;
private String planDay;
private PlaceDetails placeDetails;
private GroupInfoResponse groupInfo;
private List<MemberResponse> members;
private List<MemberResponse> notJoinedMembers;
}
37 changes: 26 additions & 11 deletions backend/src/main/java/com/twtw/backend/domain/plan/entity/Plan.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.twtw.backend.domain.plan.entity;

import com.twtw.backend.domain.group.entity.Group;
import com.twtw.backend.domain.group.entity.GroupMember;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;
import com.twtw.backend.domain.place.entity.Place;
Expand All @@ -11,15 +12,13 @@

import jakarta.persistence.*;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

import org.hibernate.annotations.Where;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
Expand All @@ -35,6 +34,9 @@ public class Plan implements Auditable {
@Column(columnDefinition = "BINARY(16)")
private UUID id;

@Column(nullable = false)
private String name;

@JoinColumn(columnDefinition = "BINARY(16)")
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST, orphanRemoval = true)
private Place place;
Expand All @@ -56,9 +58,11 @@ public class Plan implements Auditable {

private LocalDateTime planDay;

public Plan(Member member, Place place, Group group, LocalDateTime planDay) {
@Builder
public Plan(String name, Member member, Place place, Group group, LocalDateTime planDay) {
this.name = name;
this.planMembers.add(new PlanMember(this, member, true));
organizePlace(place);
this.place = place;
organizeGroup(group);
this.planDay = planDay;
}
Expand Down Expand Up @@ -90,22 +94,22 @@ private boolean hasNoPlanMaker() {
return this.planMembers.stream().noneMatch(PlanMember::getIsPlanMaker);
}

private void organizePlace(final Place place) {
this.place = place;
}

public void organizeGroup(final Group group) {
private void organizeGroup(final Group group) {
this.group = group;
this.group.addPlan(this);
}

public void updatePlace(
final String name,
final LocalDateTime planDay,
final String placeName,
final String placeUrl,
final CategoryGroupCode categoryGroupCode,
final String roadAddressName,
final Double longitude,
final Double latitude) {
this.name = name;
this.planDay = planDay;
this.place.update(
placeName, placeUrl, categoryGroupCode, roadAddressName, longitude, latitude);
}
Expand Down Expand Up @@ -138,4 +142,15 @@ public void acceptInvite(final Member member) {
public void deleteInvite(final Member member) {
this.planMembers.removeIf(planMember -> planMember.isSameMember(member));
}

public List<Member> getNotJoinedMembers() {
return this.group.getGroupMembers().stream()
.map(GroupMember::getMember)
.filter(member -> !hasSameMember(member))
.toList();
}

public void addMembers(final List<Member> membersByIds) {
membersByIds.forEach(this::addMember);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.twtw.backend.domain.plan.mapper;

import com.twtw.backend.domain.group.dto.response.GroupInfoResponse;
import com.twtw.backend.domain.group.entity.Group;
import com.twtw.backend.domain.member.dto.response.MemberResponse;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.place.entity.Place;
import com.twtw.backend.domain.plan.dto.client.PlaceClientDetails;
import com.twtw.backend.domain.plan.dto.client.SearchDestinationResponse;
import com.twtw.backend.domain.plan.dto.response.PlaceDetails;
Expand All @@ -16,6 +19,7 @@
import org.mapstruct.MappingConstants;
import org.mapstruct.Named;

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

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
Expand All @@ -29,6 +33,23 @@ public interface PlanMapper {
PlanDestinationResponse toPlanDestinationResponse(SearchDestinationResponse response);

@Mapping(target = "planId", source = "plan.id")
@Mapping(target = "name", source = "plan.name")
@Mapping(target = "placeId", source = "plan.place.id")
@Mapping(target = "planMakerId", source = "plan.planMakerId")
@Mapping(target = "groupInfo", source = "groupInfoResponse")
@Mapping(target = "members", source = "memberResponses")
@Mapping(target = "notJoinedMembers", source = "notJoinedMembers")
@Mapping(target = "planDay", source = "planDay")
PlanInfoResponse toPlanInfoResponse(
Plan plan,
PlaceClientDetails placeDetails,
String planDay,
GroupInfoResponse groupInfoResponse,
List<MemberResponse> memberResponses,
List<MemberResponse> notJoinedMembers);

@Mapping(target = "planId", source = "plan.id")
@Mapping(target = "name", source = "plan.name")
@Mapping(target = "placeId", source = "plan.place.id")
@Mapping(target = "planMakerId", source = "plan.planMakerId")
@Mapping(target = "groupInfo", source = "groupInfoResponse")
Expand All @@ -48,4 +69,8 @@ PlanInfoResponse toPlanInfoResponse(
@Mapping(target = "longitude", source = "x")
@Mapping(target = "latitude", source = "y")
PlaceDetails toPlaceDetail(PlaceClientDetails placeClientDetails);

@Mapping(target = "name", source = "name")
@Mapping(target = "group", source = "group")
Plan toEntity(String name, Member member, Place place, Group group, LocalDateTime planDay);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
@Transactional
@RequiredArgsConstructor
public class PlanService {
private static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
private final PlanRepository planRepository;
private final GroupService groupService;

Expand Down Expand Up @@ -75,13 +77,19 @@ private boolean hasNoSearchData(final List<PlaceClientDetails> documents) {
return documents == null || documents.isEmpty();
}

@Transactional
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, request.getPlanDay());

return planMapper.toPlanResponse(planRepository.save(plan));
final Plan plan =
planRepository.save(
planMapper.toEntity(
request.getName(), member, place, group, request.getPlanDay()));
plan.addMembers(memberService.getMembersByIds(request.getMemberIds()));

return planMapper.toPlanResponse(plan);
}

@Transactional
Expand All @@ -102,17 +110,29 @@ public void outPlan(PlanMemberRequest request) {
public PlanInfoResponse getPlanById(UUID id) {
Plan plan = getPlanEntity(id);

return getPlanInfoResponse(plan);
return getPlanInfoResponseWithNotJoinedMembers(plan);
}

private PlanInfoResponse getPlanInfoResponseWithNotJoinedMembers(final Plan plan) {
GroupInfoResponse groupInfo = groupService.getGroupInfoResponse(plan.getGroup());
PlaceClientDetails placeDetails = placeService.getPlaceDetails(plan.getPlace());
List<MemberResponse> notJoinedMembers =
memberService.getResponsesByMembers(plan.getNotJoinedMembers());
String planDay = plan.getPlanDay().format(DATE_TIME_FORMATTER);
List<MemberResponse> memberResponses = toMemberResponse(plan);

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

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);
String planDay = plan.getPlanDay().format(DATE_TIME_FORMATTER);
List<MemberResponse> memberResponses = toMemberResponse(plan);

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

public void deletePlan(UUID id) {
Expand All @@ -133,16 +153,21 @@ public List<PlanInfoResponse> getPlans() {
return plans.stream().map(this::getPlanInfoResponse).toList();
}

@Transactional
public void updatePlan(final UpdatePlanRequest updatePlanRequest) {
final Plan plan = getPlanEntity(updatePlanRequest.getPlanId());

plan.updatePlace(
updatePlanRequest.getName(),
updatePlanRequest.getPlanDay(),
updatePlanRequest.getPlaceName(),
updatePlanRequest.getPlaceUrl(),
updatePlanRequest.getCategoryGroupCode(),
updatePlanRequest.getRoadAddressName(),
updatePlanRequest.getLongitude(),
updatePlanRequest.getLatitude());

plan.addMembers(memberService.getMembersByIds(updatePlanRequest.getMemberIds()));
}

@Transactional
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ spring:
redis:
host: localhost
port: 6379
jackson:
default-property-inclusion: non_null
Loading

0 comments on commit 83f0037

Please sign in to comment.