Skip to content

Commit

Permalink
feature : add Reservation color field
Browse files Browse the repository at this point in the history
- 예약 색상 필드 추가
- entity ,create, update, respones DTO color 필드 추가
- add update null check validation
  • Loading branch information
chanyoung1998 committed Jul 27, 2024
1 parent 932d4cc commit 340ae9b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class Create {
private String title;
private String usage;
private boolean sharing;
private String color = "A294DB";
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
private LocalDateTime startDateTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
Expand All @@ -43,6 +44,7 @@ public Reservation toEntity(ClubMember clubMember, Resource resource) {
.title(title)
.usage(usage)
.sharing(sharing)
.color(color)
.build();
}
}
Expand All @@ -57,6 +59,7 @@ public static class Update {
private Long resourceId;
private String title;
private String usage;
private String color;
private boolean sharing;
@Builder.Default
private List<Long> reservationInvitees = new ArrayList<>();
Expand Down Expand Up @@ -137,6 +140,7 @@ public static class Response {
private boolean isReturned;
private String returnMessage;
private String rejectMessage;
private String color;
private List<String> attachmentsUrl;
@Builder.Default
private List<ReservationInviteeDto> invitees = new ArrayList<>();
Expand Down Expand Up @@ -166,6 +170,7 @@ public static Response of(Reservation reservation) {
.isReturned(reservation.isReturned())
.returnMessage(reservation.getReturnMessage())
.rejectMessage(reservation.getRejectMessage())
.color(reservation.getColor())
.attachmentsUrl(reservation.getAttachments().stream().map(Attachment::getUrl).collect(Collectors.toList()))
.invitees(
reservation.getReservationInvitees().stream().map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ public class Reservation extends BaseEntity{
private boolean isReturned = false;
private String title;
private String usage;
private String color;
@Enumerated(EnumType.STRING)
private ReservationStatus status;

@Builder
public Reservation(Resource resource, ClubMember clubMember, Period period, boolean sharing, String title, String usage) {
public Reservation(Resource resource, ClubMember clubMember, Period period, boolean sharing, String title, String usage,String color) {
setResource(resource);
this.clubMember = clubMember;
this.period = period;
this.sharing = sharing;
this.title = title;
this.usage = usage;
this.color = color;
this.status = REQUEST;
}

Expand All @@ -75,11 +77,11 @@ public void update(String title, String usage, LocalDateTime startDateTime, Loca
this.status = REQUEST;
}

public void updateNotChangeStatus(String title, String usage, LocalDateTime startDateTime, LocalDateTime endDateTime, boolean sharing) {
public void updateNotChangeStatus(String title, String usage,boolean sharing, String color) {
this.title = title;
this.usage = usage;
this.sharing = sharing;
this.period = new Period(startDateTime, endDateTime);
this.color = color;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.time.Clock;
import java.time.LocalDate;
Expand Down Expand Up @@ -113,14 +114,13 @@ public ReservationDto.Response updateReservation(Long clubMemberId, ReservationD
.orElseThrow(() -> new ServiceException(RESERVATION_NOT_FOUND));

checkIsReservationOwner(clubMemberId, reservation);

checkUpdateDTONullValidation(reservation, updateDto);
if (reservation.getPeriod().equals(new Period(start, end))) {
reservation.updateNotChangeStatus(
updateDto.getTitle(),
updateDto.getUsage(),
updateDto.getStartDateTime(),
updateDto.getEndDateTime(),
updateDto.isSharing()
updateDto.isSharing(),
updateDto.getColor()
);
// 양방향 관계 reservation.invitees clear 필요
reservation.clearInvitee();
Expand Down Expand Up @@ -491,6 +491,25 @@ private void checkIsSameClubMember(Long clubMemberId, Long reservationOwnerId) {
}
}

private void checkUpdateDTONullValidation(Reservation reservation, ReservationDto.Update updateDto) {

if (ObjectUtils.isEmpty(updateDto.isSharing())) {
updateDto.setSharing(reservation.isSharing());
}

if (ObjectUtils.isEmpty(updateDto.getTitle())) {
updateDto.setTitle(reservation.getTitle());
}

if (ObjectUtils.isEmpty(updateDto.getUsage())) {
updateDto.setUsage(reservation.getUsage());
}

if (ObjectUtils.isEmpty(updateDto.getColor())) {
updateDto.setColor(reservation.getColor());
}
}

/**
* @param clubMemberIds : invitee ids
* @param inviter : inviter
Expand Down

0 comments on commit 340ae9b

Please sign in to comment.