Skip to content

Commit

Permalink
Merge pull request #421 from mash-up-kr/develop
Browse files Browse the repository at this point in the history
develop to master
  • Loading branch information
eunjungL authored Jun 28, 2024
2 parents cda4549 + e34e021 commit a8456c8
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ScheduleResponse create(Integer generationNumber, ScheduleCreateRequest r
final DateRange dateRange
= DateRange.of(request.getStartedAt(), request.getEndedAt());
final ScheduleCreateDto createDto =
ScheduleCreateDto.of(request.getName(), dateRange, request.getLatitude(), request.getLongitude(), request.getAddress(), request.getPlaceName(), request.getScheduleType());
ScheduleCreateDto.of(request.getName(), dateRange, request.getLatitude(), request.getLongitude(), request.getRoadAddress(), request.getDetailAddress(), request.getScheduleType());
final Schedule schedule
= scheduleService.create(generation, createDto);

Expand All @@ -79,7 +79,7 @@ public void publishSchedule(Long scheduleId) {
scheduleService.publishSchedule(schedule);

pushNotiEventPublisher.publishPushNotiSendEvent(
new SeminarUpdatedVo(memberService.getPushNotiTargetableMembersBySchedule(schedule), schedule.getScheduleType())
new SeminarUpdatedVo(memberService.getPushNotiTargetableMembersBySchedule(schedule), schedule.getScheduleType())
);
}

Expand All @@ -94,7 +94,6 @@ public void hideSchedule(Long scheduleId) {
public ScheduleResponse updateSchedule(
final Long scheduleId,
final ScheduleUpdateRequest request) {

Schedule schedule
= scheduleService.getByIdOrThrow(scheduleId);

Expand All @@ -103,7 +102,8 @@ public ScheduleResponse updateSchedule(

final DateRange dateRange = DateRange.of(request.getStartedAt(), request.getEndedAt());
final ScheduleCreateDto scheduleCreateDto =
ScheduleCreateDto.of(request.getName(), dateRange, request.getLatitude(), request.getLongitude(), request.getAddress(), request.getPlaceName(), request.getScheduleType());
ScheduleCreateDto.of(request.getName(), dateRange, request.getLatitude(), request.getLongitude(),
request.getRoadAddress(), request.getDetailAddress(), request.getScheduleType());

schedule = scheduleService.updateSchedule(schedule, generation, scheduleCreateDto);

Expand Down Expand Up @@ -135,7 +135,7 @@ public QrCodeResponse updateQrCode(Long scheduleId, Long eventId, QrCodeGenerate

final DateRange lateTime = DateRange.of(request.getAttendanceCheckEndedAt(), request.getLatenessCheckEndedAt());

scheduleService.updateAttendanceTime(event, attendantTime,lateTime);
scheduleService.updateAttendanceTime(event, attendantTime, lateTime);

final String attendanceCode = event.getAttendanceCode().getCode();
final String qrCodeUrl = QrGenerator.generate(attendanceCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public ApiResponse<List<ScheduleResponse>> getSchedules(
@RequestParam(required = false) String searchWord,
@PageableDefault Pageable pageable
) {
final Page<ScheduleResponse> responses = scheduleFacadeService.getSchedules(generationNumber, searchWord, scheduleType, pageable);
final Page<ScheduleResponse> responses =
scheduleFacadeService.getSchedules(generationNumber, searchWord, scheduleType, pageable);

return ApiResponse.success(responses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class ScheduleCreateRequest {

private Double longitude;

private String address;
private String roadAddress;

private String placeName;
private String detailAddress;

private ScheduleType scheduleType = ScheduleType.ALL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class ScheduleUpdateRequest {

private Double longitude;

private String address;
private String roadAddress;

private String placeName;
private String detailAddress;

private ScheduleType scheduleType = ScheduleType.ALL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public enum ResultCode {
SCHEDULE_NOT_FOUND("스케줄이 존재하지 않습니다."),
SCHEDULE_STARTED_TIME_OVER("스케줄 시작 시간이 지났습니다."),
SCHEDULE_ALREADY_PUBLISHED("이미 발행된 스케줄입니다."),
SCHEDULE_NOT_UPDATABLE("이미 세션에 출석이 존재해 업데이트 할 수 없습니다."),

// Schedule (일정 내용)
CONTENT_NOT_FOUND("일정 내용이 존재하지 않습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
public class Location {
private Double latitude;
private Double longitude;
private String address;
private String placeName; // 장소명
private String roadAddress;
private String detailAddress; // 장소명

private static final double EARTH_RADIUS = 6371000; // 지구 반지름 (미터)

public Location(Double latitude, Double longitude, String address, String placeName) {
public Location(Double latitude, Double longitude, String roadAddress, String detailAddress) {
this.latitude = latitude;
this.longitude = longitude;
this.address = address;
this.placeName = placeName;
this.roadAddress = roadAddress;
this.detailAddress = detailAddress;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package kr.mashup.branding.domain.schedule;

import java.time.LocalDateTime;

import kr.mashup.branding.util.DateRange;
import lombok.Value;

Expand All @@ -11,7 +9,7 @@ public class ScheduleCreateDto {
DateRange dateRange;
Double latitude;
Double longitude;
String address;
String placeName;
String roadAddress;
String detailAddress;
ScheduleType scheduleType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kr.mashup.branding.domain.schedule.exception;

import kr.mashup.branding.domain.ResultCode;
import kr.mashup.branding.domain.exception.BadRequestException;

public class ScheduleNotUpdatableException extends BadRequestException {

public ScheduleNotUpdatableException() {
super(ResultCode.SCHEDULE_NOT_UPDATABLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import kr.mashup.branding.domain.schedule.Event;
import kr.mashup.branding.domain.member.Member;

public interface AttendanceRepository extends JpaRepository<Attendance, Long>, CustomAttendanceRepository{
public interface AttendanceRepository extends JpaRepository<Attendance, Long>, CustomAttendanceRepository {
boolean existsAttendanceByMemberAndEvent(Member member, Event event);

Optional<Attendance> findByMemberAndEvent(Member member, Event event);

List<Attendance> findAllByMember(Member member);

void deleteByMember(Member member);

boolean existsByEvent(Event event);
}
/**
* Attendance 연관관계
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ScheduleRepositoryCustomImpl implements ScheduleRepositoryCustom {

@Override
public Page<Schedule> retrieveByGenerationAndScheduleType(Generation _generation, String searchWord, ScheduleType scheduleType, ScheduleStatus status, Pageable pageable) {
final Sort sort = pageable.getSortOr(Sort.by(Sort.Direction.ASC, "startedAt"));
final Sort sort = pageable.getSortOr(Sort.by(Sort.Direction.DESC, "startedAt"));

final QueryResults<Schedule> queryResults = queryFactory
.selectFrom(schedule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import kr.mashup.branding.domain.generation.Generation;
import kr.mashup.branding.domain.schedule.*;
import kr.mashup.branding.domain.schedule.exception.*;
import kr.mashup.branding.repository.attendance.AttendanceRepository;
import kr.mashup.branding.repository.attendancecode.AttendanceCodeRepository;
import kr.mashup.branding.repository.schedule.ScheduleRepository;
import kr.mashup.branding.util.DateRange;
Expand All @@ -27,6 +28,7 @@
public class ScheduleService {
private final ScheduleRepository scheduleRepository;
private final AttendanceCodeRepository attendanceCodeRepository;
private final AttendanceRepository attendanceRepository;

public Schedule create(Generation generation, ScheduleCreateDto dto) {
try {
Expand All @@ -41,11 +43,11 @@ public Schedule create(Generation generation, ScheduleCreateDto dto) {

private Location createLocation(ScheduleCreateDto dto) {
if (dto.getLatitude() == null || dto.getLongitude() == null
|| dto.getAddress() == null || dto.getPlaceName() == null) {
|| dto.getRoadAddress() == null || dto.getDetailAddress() == null) {
return new Location(null, null, null, "ZOOM");
}

return new Location(dto.getLatitude(), dto.getLongitude(), dto.getAddress(), dto.getPlaceName());
return new Location(dto.getLatitude(), dto.getLongitude(), dto.getRoadAddress(), dto.getDetailAddress());
}

public Schedule getByIdOrThrow(Long scheduleId) {
Expand Down Expand Up @@ -119,8 +121,15 @@ public void deleteSchedule(Schedule schedule) {
scheduleRepository.delete(schedule);
}

private void passedScheduleMustNotBeDeleted(Schedule schedule) {
if (schedule.getStartedAt().isBefore(LocalDateTime.now())) {
throw new ScheduleNotDeletableException();
}
}

public Schedule updateSchedule(Schedule schedule, Generation generation, ScheduleCreateDto scheduleCreateDto) {
onlyHidingScheduleCanChanged(schedule);
validateAttendanceExists(schedule);

schedule.changeName(scheduleCreateDto.getName());
schedule.changeGeneration(generation);
Expand All @@ -134,14 +143,13 @@ public Schedule updateSchedule(Schedule schedule, Generation generation, Schedul
return schedule;
}

private void passedScheduleMustNotBeDeleted(Schedule schedule) {
if (schedule.getStartedAt().isBefore(LocalDateTime.now())) {
throw new ScheduleNotDeletableException();
}
}
private void validateAttendanceExists(Schedule schedule) {
boolean isAttendanceExists = schedule.getEventList().stream()
.anyMatch(attendanceRepository::existsByEvent);

public void hideSchedule(Schedule schedule) {
schedule.hide();
if (isAttendanceExists) {
throw new ScheduleNotUpdatableException();
}
}

private void onlyHidingScheduleCanChanged(Schedule schedule) {
Expand All @@ -150,6 +158,10 @@ private void onlyHidingScheduleCanChanged(Schedule schedule) {
}
}

public void hideSchedule(Schedule schedule) {
schedule.hide();
}


public List<Schedule> findEndedScheduleByIsCountedAndScheduleType(boolean isCounted, ScheduleType scheduleType) {
return scheduleRepository.findAllByIsCountedAndEndedAtIsBeforeAndScheduleType(isCounted, LocalDateTime.now(), scheduleType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package kr.mashup.branding.ui.schedule.response;

import kr.mashup.branding.domain.schedule.Location;
import lombok.Getter;

@Getter
public class LocationResponse {

private final Double latitude;
private final Double longitude;
private final String address;
private final String placeName;
private final String roadAddress;
private final String detailAddress;

public LocationResponse(Double latitude, Double longitude, String address, String placeName, String roadAddress, String detailAddress) {
this.latitude = latitude;
this.longitude = longitude;
this.address = address;
this.placeName = placeName;
this.roadAddress = roadAddress;
this.detailAddress = detailAddress;
}

public static LocationResponse from(Location location) {
return new LocationResponse(
location.getLatitude(),
location.getLongitude(),
location.getRoadAddress(),
location.getDetailAddress(),
location.getRoadAddress(),
location.getDetailAddress()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import java.util.stream.Collectors;

import kr.mashup.branding.domain.schedule.Location;
import kr.mashup.branding.domain.schedule.Schedule;
import kr.mashup.branding.domain.schedule.ScheduleType;
import lombok.Getter;
Expand All @@ -26,7 +25,8 @@ public class ScheduleResponse {

Integer generationNumber;

Location location;
// TODO: 앱 배포 완료 후 Location으로 type 변경
LocationResponse location;

ScheduleType scheduleType;

Expand All @@ -40,7 +40,7 @@ public static ScheduleResponse from(Schedule schedule, Integer dateCount) {
schedule.getStartedAt(),
schedule.getEndedAt(),
schedule.getGeneration().getNumber(),
schedule.getLocation() == null ? null : schedule.getLocation(),
schedule.getLocation() == null ? null : LocationResponse.from(schedule.getLocation()),
schedule.getScheduleType(),
schedule.getEventList()
.stream()
Expand Down

0 comments on commit a8456c8

Please sign in to comment.