Skip to content

Commit

Permalink
Merge branch 'develop' into feat/feed-userVoteStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoon9901 authored Nov 20, 2023
2 parents 02f3caa + aee84a5 commit 03695e2
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@

import jakarta.validation.constraints.NotBlank;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@Getter
@Setter
public class EventScheduleCreateDTO {

@NotBlank(message = "날짜 지정은 필수입니다.")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate eventDate;

@NotBlank(message = "시작시간은 필수입니다.")
@DateTimeFormat(pattern = "HH:mm")
@JsonFormat(pattern = "HH:mm")
private LocalTime startTime;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime startDateTime;

@NotBlank(message = "종료시간은 필수입니다.")
@DateTimeFormat(pattern = "HH:mm")
@JsonFormat(pattern = "HH:mm")
private LocalTime endTime;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime endDateTime;

@NotBlank(message = "장소는 필수입니다.")
private Long locationId;
Expand All @@ -36,7 +32,7 @@ public class EventScheduleCreateDTO {
private List<ParticipantInformationDTO> participants;

public void checkTimeValidity() {
if (this.startTime.equals(this.endTime)) {
if (this.startDateTime.equals(this.endDateTime)) {
throw new RuntimeException("시작시간과 종료시간이 같을 수 없습니다.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -28,17 +26,13 @@ public class EventScheduleResponseDTO {

private List<ParticipantInformationResponseDTO> participants;

@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate eventDate;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime startDateTime;

@DateTimeFormat(pattern = "HH:mm")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
private LocalTime startTime;

@DateTimeFormat(pattern = "HH:mm")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
private LocalTime endTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime endDateTime;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdTime;
Expand All @@ -48,20 +42,19 @@ public class EventScheduleResponseDTO {

public static EventScheduleResponseDTO from(EventSchedule eventSchedule) {
List<ParticipantInformationResponseDTO> participantInformationResponseDTO =
eventSchedule.getExhibitionParticipants().stream()
.map(ParticipantInformationResponseDTO::from)
.collect(Collectors.toList());
eventSchedule.getExhibitionParticipants().stream()
.map(ParticipantInformationResponseDTO::from)
.collect(Collectors.toList());
return EventScheduleResponseDTO.builder()
.id(eventSchedule.getId())
.locationName(eventSchedule.getLocation().getName())
.locationAddress(eventSchedule.getLocation().getAddress())
.detailLocation(eventSchedule.getDetailLocation())
.participants(participantInformationResponseDTO)
.eventDate(eventSchedule.getEventDate())
.startTime(eventSchedule.getStartTime())
.endTime(eventSchedule.getEndTime())
.createdTime(eventSchedule.getCreatedTime())
.updatedTime(eventSchedule.getUpdatedTime())
.build();
.id(eventSchedule.getId())
.locationName(eventSchedule.getLocation().getName())
.locationAddress(eventSchedule.getLocation().getAddress())
.detailLocation(eventSchedule.getDetailLocation())
.participants(participantInformationResponseDTO)
.startDateTime(eventSchedule.getStartDateTime())
.endDateTime(eventSchedule.getEndDateTime())
.createdTime(eventSchedule.getCreatedTime())
.updatedTime(eventSchedule.getUpdatedTime())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@Setter
Expand All @@ -15,17 +16,17 @@ public class ExhibitionSearchDTO {

@Builder.Default
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate = LocalDate.of(1900, 1, 1);
private LocalDateTime startDateTime = LocalDateTime.of(1900, 1, 1, 0, 0);

@Builder.Default
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate = LocalDate.of(2100, 12, 31);
private LocalDateTime endDateTime = LocalDateTime.of(2100, 12, 31, 23, 59);

@NotNull
private String eventType;

public void repeatTimeValidity() {
if (this.startDate.isAfter(this.endDate)) {
if (this.startDateTime.isAfter(this.endDateTime)) {
throw new RuntimeException("시작일은 종료일보다 이전에 있어야 합니다.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ public class ParticipantInformationDTO {

private String name;
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.NoArgsConstructor;

import jakarta.persistence.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand All @@ -27,14 +28,11 @@ public class EventSchedule {
@Column(name = "event_schedule_id")
private Long id;

@Column(name = "event_date")
private LocalDate eventDate;

@Column(name = "start_time")
private LocalTime startTime;
@Column(name = "start_date_time", nullable = false)
private LocalDateTime startDateTime;

@Column(name = "end_time")
private LocalTime endTime;
@Column(name = "end_date_time")
private LocalDateTime endDateTime;

@ManyToOne
@JoinColumn(name = "location_id", nullable = false)
Expand All @@ -59,34 +57,24 @@ public class EventSchedule {

public static EventSchedule from(EventScheduleCreateDTO scheduleDTO) {
return EventSchedule.builder()
.eventDate(scheduleDTO.getEventDate())
.startTime(scheduleDTO.getStartTime())
.endTime(scheduleDTO.getEndTime())
.detailLocation(scheduleDTO.getDetailLocation())
.createdTime(LocalDateTime.now())
.build();
.startDateTime(scheduleDTO.getStartDateTime())
.endDateTime(scheduleDTO.getEndDateTime())
.detailLocation(scheduleDTO.getDetailLocation())
.createdTime(LocalDateTime.now())
.build();
}

// Event 양방향 연관 메소드
public void setEvent(Exhibition exhibition) {
this.exhibition = exhibition;
exhibition.addEventSchedule(this);
}

public Location getLocation() {
return this.location;
}

// Location 단방향 연관 메소드
public void setLocation(Location location) {
this.location = location;
}

public void getDetailLocation(String detailLocation) {
this.detailLocation = detailLocation;
}

public void delete() {
this.exhibition.removeEventSchedule(this);
this.exhibition = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ public EventSchedule getFirstEventSchedule() {
public Boolean equalUsername(String username) {
return this.member.getUsername().equals(username);
}

public void removeEventSchedule(EventSchedule eventSchedule) {
this.eventSchedules.remove(eventSchedule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,4 @@
import java.time.LocalDateTime;

public interface EventScheduleRepository extends JpaRepository<EventSchedule, Long> {

@Query(
"SELECT es FROM EventSchedule es "
+ "INNER JOIN Exhibition e ON es.exhibition = e"
+ " WHERE es.eventDate BETWEEN :startDate AND :endDate"
+ " AND e.type = :eventType"
+ " AND e.enabled = true ")
Page<EventSchedule> findByStartAndEndDate(
LocalDateTime startDate, LocalDateTime endDate, EventType eventType, Pageable pageable);

@Query(
"SELECT es FROM EventSchedule es "
+ "INNER JOIN Exhibition e ON es.exhibition = e"
+ " WHERE es.eventDate BETWEEN :startDate AND :endDate"
+ " AND e.enabled = true ")
Page<EventSchedule> findByStartAndEndDate(
LocalDateTime startDate, LocalDateTime endDate, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDate;
import java.time.LocalDateTime;

public interface ExhibitionRepository extends JpaRepository<Exhibition, Long> {

@Query(
"SELECT e as exhibition, es as eventSchedule "
+ "FROM Exhibition e INNER JOIN EventSchedule es ON es.exhibition = e "
+ "WHERE es.eventDate BETWEEN :startDate AND :endDate "
+ "WHERE es.startDateTime>= :startDate "
+ "AND es.endDateTime <= :endDate "
+ "AND e.enabled = true "
+ "ORDER BY es.eventDate, es.startTime")
+ "ORDER BY es.startDateTime")
Page<ExhibitionWithEventSchedule> findExhibitionsWithEventSchedules(
LocalDate startDate, LocalDate endDate, Pageable pageable);
LocalDateTime startDate, LocalDateTime endDate, Pageable pageable);

@Query(
"SELECT e as exhibition, es as eventSchedule "
+ "FROM Exhibition e INNER JOIN EventSchedule es ON es.exhibition = e "
+ "WHERE es.eventDate BETWEEN :startDate AND :endDate "
+ "WHERE es.startDateTime >= :startDate "
+ "AND es.endDateTime <= :endDate "
+ "AND e.enabled = true AND e.type = :eventType "
+ "ORDER BY es.eventDate, es.startTime")
+ "ORDER BY es.startDateTime")
Page<ExhibitionWithEventSchedule> findExhibitionsWithEventSchedules(
LocalDate startDate, LocalDate endDate,
LocalDateTime startDate, LocalDateTime endDate,
EventType eventType,
Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ private Page<ExhibitionWithEventSchedule> findExhibitionsWithEventSchedules(
EventType eventType, ExhibitionSearchDTO exhibitionSearchDTO, PageRequest pageRequest) {
if (eventType == null) {
return exhibitionRepository.findExhibitionsWithEventSchedules(
exhibitionSearchDTO.getStartDate(),
exhibitionSearchDTO.getEndDate(),
exhibitionSearchDTO.getStartDateTime(),
exhibitionSearchDTO.getEndDateTime(),
pageRequest);
}
return exhibitionRepository.findExhibitionsWithEventSchedules(
exhibitionSearchDTO.getStartDate(),
exhibitionSearchDTO.getEndDate(),
exhibitionSearchDTO.getStartDateTime(),
exhibitionSearchDTO.getEndDateTime(),
eventType,
pageRequest);
}
Expand Down Expand Up @@ -242,7 +242,9 @@ public void deleteEventSchedule(Long exhibitionId, Long eventScheduleId, String
if (!SecurityUtil.isAdmin() && !exhibition.equalUsername(username)) {
throw new RuntimeException("해당 이벤트의 생성자가 아닙니다.");
}
eventScheduleRepository.deleteById(eventScheduleId);

eventSchedule.delete();
eventScheduleRepository.delete(eventSchedule);
}

@Transactional
Expand All @@ -260,6 +262,9 @@ public void deleteAllEventSchedules(Long exhibitionId, String username) {
}

List<EventSchedule> eventSchedules = exhibition.getEventSchedules();
for (EventSchedule eventSchedule : eventSchedules) {
eventSchedule.delete();
}
eventScheduleRepository.deleteAll(eventSchedules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

@Getter
Expand All @@ -22,12 +23,10 @@ public class FeedItemEventResponseDto {

private String detailLocation;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate eventDate;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime startDateTime;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
private LocalTime startTime;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime endDateTime;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
private LocalTime endTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ public static FeedItemResponseDto from(Exhibition exhibition) {
FeedItemEventResponseDto eventDto =
FeedItemEventResponseDto.builder()
.eventType(exhibition.getType())
.eventDate(exhibition.getFirstEventSchedule().getEventDate())
.startTime(exhibition.getFirstEventSchedule().getStartTime())
.endTime(exhibition.getFirstEventSchedule().getEndTime())
.startDateTime(exhibition.getFirstEventSchedule().getStartDateTime())
.endDateTime(exhibition.getFirstEventSchedule().getEndDateTime())
.locationName(exhibition.getFirstEventSchedule().getLocation().getName())
.locationAddress(exhibition.getFirstEventSchedule().getLocation().getAddress())
.detailLocation(exhibition.getFirstEventSchedule().getDetailLocation())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE event_schedule
CHANGE COLUMN start_time start_date_time DATETIME NOT NULL,
CHANGE COLUMN end_time end_date_time DATETIME NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE event_schedule SET event_schedule.start_date_time = DATE_ADD(event_date, INTERVAL TIME_TO_SEC(start_date_time) SECOND);
UPDATE event_schedule SET event_schedule.end_date_time = DATE_ADD(event_date, INTERVAL TIME_TO_SEC(end_date_time) SECOND);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
alter table event_schedule
drop foreign key event_schedule_ibfk_1; # event_scheudle -> (event_id, location_id)

alter table event_schedule
drop key uk_event_id_start_time;

alter table event_schedule
drop column event_date;

ALTER TABLE event_schedule
ADD FOREIGN KEY event_schedule(event_id) references exhibition(exhibition_id);

ALTER TABLE event_schedule
ADD unique key uk_event_id_start_date_time(event_id, start_date_time);
Loading

0 comments on commit 03695e2

Please sign in to comment.