Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 일정 메모 기능 추가 #941

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Lob;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -19,7 +18,6 @@ public class Content {
public static final int MAX_LENGTH = 10000;

@Column(name = "content", columnDefinition = "text")
@Lob
private String value;

public Content(final String value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package team.teamby.teambyteam.global.presentation;

import io.jsonwebtoken.ExpiredJwtException;
import java.time.DateTimeException;
import java.util.Random;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -24,6 +22,9 @@
import team.teamby.teambyteam.teamplace.exception.TeamPlaceInviteCodeException;
import team.teamby.teambyteam.token.exception.TokenException;

import java.time.DateTimeException;
import java.util.Random;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
Expand Down Expand Up @@ -124,6 +125,8 @@ public ResponseEntity<ErrorResponse> handleCustomForbiddenException(final Runtim
@ExceptionHandler(value = {
ScheduleException.SpanWrongOrderException.class,
ScheduleException.dateFormatException.class,
ScheduleException.TitleBlankException.class,
ScheduleException.DescriptionLengthException.class,
TeamPlaceInviteCodeException.LengthException.class,
TeamPlaceException.NameLengthException.class,
TeamPlaceException.NameBlankException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ICal4jParser implements IcalendarParser {
private static final String STANDARD_DT_START = "19700101T000000";
private static final String SEOUL_TZ_OFFSET = "+0900";

private final VEventParser vEventParser = new VEventParser();
private final VEventParser vEventParser = new VEventParser(new ScheduleUidGenerator());

@Override
public String parse(final TeamPlace teamPlace, final List<Schedule> schedules) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package team.teamby.teambyteam.icalendar.domain.ical4j;

import net.fortuna.ical4j.model.property.Uid;
import net.fortuna.ical4j.util.UidGenerator;
import team.teamby.teambyteam.schedule.domain.Schedule;

public class ScheduleUidGenerator implements UidGenerator {
public class ScheduleUidGenerator {

private static final String DELIMITER = "-";

private final Long teamPlaceId;
private final Long scheduleId;
public ScheduleUidGenerator(final Schedule schedule) {
this.teamPlaceId = schedule.getTeamPlaceId();
this.scheduleId = schedule.getId();
}

@Override
public Uid generateUid() {
final String uidString = String.join(DELIMITER, String.valueOf(teamPlaceId), String.valueOf(scheduleId));
public Uid generateUid(final Schedule schedule) {
final String uidString = String.join(DELIMITER, String.valueOf(schedule.getTeamPlaceId()), String.valueOf(schedule.getId()));
return new Uid(uidString);
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
package team.teamby.teambyteam.icalendar.domain.ical4j;

import lombok.RequiredArgsConstructor;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.util.UidGenerator;
import net.fortuna.ical4j.model.property.Description;
import team.teamby.teambyteam.schedule.domain.Schedule;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.util.TimeZone;

@RequiredArgsConstructor
public class VEventParser {

private static final String ASIA_SEOUL = "Asia/Seoul";
private static final long ONE_DAY_OFFSET = 1L;

private final ScheduleUidGenerator uidGenerator;

public VEvent parse(final Schedule schedule) {
final String title = schedule.getTitle().getValue();

final Temporal startTemporal = getStartTemporal(schedule);
final Temporal endTemporal = getEndTemporal(schedule);

final VEvent vEvent = new VEvent(startTemporal, endTemporal, title);
if (schedule.getDescription().isExist()) {
vEvent.withProperty(new Description(schedule.getDescription().getValue()));
}

final UidGenerator uidGenerator = new ScheduleUidGenerator(schedule);
vEvent.add(uidGenerator.generateUid());
vEvent.add(uidGenerator.generateUid(schedule));

return vEvent;
}
Expand All @@ -42,7 +48,7 @@ private Temporal getEndTemporal(final Schedule schedule) {
return convertToSeoulDateTime(schedule.getEndDateTime());
}

private ZonedDateTime convertToSeoulDateTime(final LocalDateTime startDateTime) {
return startDateTime.atZone(TimeZone.getTimeZone(ASIA_SEOUL).toZoneId());
private ZonedDateTime convertToSeoulDateTime(final LocalDateTime localDateTime) {
return localDateTime.atZone(TimeZone.getTimeZone(ASIA_SEOUL).toZoneId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import team.teamby.teambyteam.schedule.application.event.ScheduleCreateEvent;
import team.teamby.teambyteam.schedule.application.event.ScheduleDeleteEvent;
import team.teamby.teambyteam.schedule.application.event.ScheduleUpdateEvent;
import team.teamby.teambyteam.schedule.application.event.ScheduleUpdateEventDto;
import team.teamby.teambyteam.schedule.application.parser.LocalDateParser;
import team.teamby.teambyteam.schedule.domain.CalendarPeriod;
import team.teamby.teambyteam.schedule.domain.Schedule;
import team.teamby.teambyteam.schedule.domain.ScheduleRepository;
import team.teamby.teambyteam.schedule.domain.vo.Description;
import team.teamby.teambyteam.schedule.domain.vo.Span;
import team.teamby.teambyteam.schedule.domain.vo.Title;
import team.teamby.teambyteam.schedule.exception.ScheduleException;
Expand All @@ -26,6 +26,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@Slf4j
@Service
Expand All @@ -43,17 +44,13 @@ public Long register(final ScheduleRegisterRequest scheduleRegisterRequest, fina

final Title title = new Title(scheduleRegisterRequest.title());
final Span span = new Span(scheduleRegisterRequest.startDateTime(), scheduleRegisterRequest.endDateTime());
final Schedule schedule = new Schedule(teamPlaceId, title, span);
final Description description = new Description(scheduleRegisterRequest.description());
final Schedule schedule = new Schedule(teamPlaceId, title, description, span);

final Schedule savedSchedule = scheduleRepository.save(schedule);
log.info("일정 등록 - 팀플레이스 아이디 : {}, 일정 아이디 : {}", teamPlaceId, savedSchedule.getId());

applicationEventPublisher.publishEvent(new ScheduleCreateEvent(
savedSchedule.getId(),
teamPlaceId,
savedSchedule.getTitle(),
savedSchedule.getSpan()
));
applicationEventPublisher.publishEvent(new ScheduleCreateEvent(savedSchedule.getId(), teamPlaceId));

return savedSchedule.getId();
}
Expand Down Expand Up @@ -141,26 +138,23 @@ public void update(final ScheduleUpdateRequest scheduleUpdateRequest, final Long
.orElseThrow(() -> new ScheduleException.ScheduleNotFoundException(scheduleId));
validateScheduleOwnerTeam(teamPlaceId, schedule);

final Title previousTitle = schedule.getTitle();
final Span previousSpan = schedule.getSpan();
if (Objects.nonNull(scheduleUpdateRequest.title())) {
schedule.changeTitle(scheduleUpdateRequest.title());
}

if (Objects.nonNull(scheduleUpdateRequest.description())) {
schedule.changeDescription(scheduleUpdateRequest.description());
}

final String titleToUpdate = scheduleUpdateRequest.title();
final LocalDateTime startDateTimeToUpdate = scheduleUpdateRequest.startDateTime();
final LocalDateTime endDateTimeToUpdate = scheduleUpdateRequest.endDateTime();
if (Objects.nonNull(startDateTimeToUpdate) && Objects.nonNull(endDateTimeToUpdate)) {
schedule.changeSpan(startDateTimeToUpdate, endDateTimeToUpdate);
}

schedule.change(titleToUpdate, startDateTimeToUpdate, endDateTimeToUpdate);
log.info("일정 수정 - 팀플레이스 아이디 : {}, 일정 아이디 : {}", teamPlaceId, scheduleId);

final ScheduleUpdateEventDto updatedScheduleInfo =
ScheduleUpdateEventDto.of(titleToUpdate, startDateTimeToUpdate, endDateTimeToUpdate);

applicationEventPublisher.publishEvent(new ScheduleUpdateEvent(
scheduleId,
teamPlaceId,
previousTitle,
previousSpan,
updatedScheduleInfo
));
applicationEventPublisher.publishEvent(new ScheduleUpdateEvent(scheduleId, teamPlaceId));
}

public void delete(final Long teamPlaceId, final Long scheduleId) {
Expand All @@ -173,11 +167,6 @@ public void delete(final Long teamPlaceId, final Long scheduleId) {
scheduleRepository.deleteById(scheduleId);
log.info("일정 삭제 - 팀플레이스 아이디 : {}, 일정 아이디 : {}", teamPlaceId, scheduleId);

applicationEventPublisher.publishEvent(new ScheduleDeleteEvent(
scheduleId,
teamPlaceId,
schedule.getTitle(),
schedule.getSpan()
));
applicationEventPublisher.publishEvent(new ScheduleDeleteEvent(scheduleId, teamPlaceId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ public record ScheduleRegisterRequest(
@NotBlank(message = "제목은 빈 값일 수 없습니다.")
String title,

String description,

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

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

public ScheduleRegisterRequest(
final String title,
final LocalDateTime startDateTime,
final LocalDateTime endDateTime) {
this(title, null, startDateTime, endDateTime);
}
}
Loading