Skip to content

Commit

Permalink
Merge pull request #406 from mash-up-kr/develop
Browse files Browse the repository at this point in the history
develop to master
  • Loading branch information
kh0712 authored Mar 6, 2024
2 parents 621dc59 + fb79ccf commit 622656d
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public ScheduleResponse create(Integer generationNumber, ScheduleCreateRequest r
generationService.getByNumberOrThrow(generationNumber);
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());
final Schedule schedule
= scheduleService.create(generation, ScheduleCreateDto.of(request.getName(), dateRange));
= scheduleService.create(generation, createDto);

doUpdateSchedule(schedule, request);

Expand Down Expand Up @@ -102,7 +104,9 @@ public ScheduleResponse updateSchedule(
final Generation generation
= generationService.getByNumberOrThrow(request.getGenerationNumber());

ScheduleCreateDto scheduleCreateDto = ScheduleCreateDto.of(request.getName(), DateRange.of(request.getStartedAt(), request.getEndedAt()));
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());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.time.LocalDateTime;
import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

Expand All @@ -23,6 +22,14 @@ public class ScheduleCreateRequest {
@NotNull
private LocalDateTime endedAt;

private Double latitude;

private Double longitude;

private String address;

private String placeName;

@NotEmpty
private List<EventCreateRequest> eventsCreateRequests;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public class ScheduleUpdateRequest {
@NotNull
private LocalDateTime endedAt;

private Double latitude;

private Double longitude;

private String address;

private String placeName;

@NotEmpty
private List<EventCreateRequest> eventsCreateRequests;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.ScheduleStatus;
import lombok.Getter;
Expand All @@ -23,6 +24,8 @@ public class ScheduleResponse {

Integer generationNumber;

Location location;

List<EventResponse> eventList;

ScheduleStatus status;
Expand All @@ -40,6 +43,7 @@ public static ScheduleResponse from(Schedule schedule) {
schedule.getStartedAt(),
schedule.getEndedAt(),
schedule.getGeneration().getNumber(),
schedule.getLocation() == null ? null : schedule.getLocation(),
schedule.getEventList()
.stream()
.map(EventResponse::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
import javax.persistence.Embeddable;

import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Embeddable
@Getter
public class Location {
private Double latitude;
private Double longitude;
private String address;
private String placeName; // 장소명

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

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

/**
* Haversine 공식을 사용하여 두 지점 간의 거리 계산
* <a href="https://en.wikipedia.org/wiki/Haversine_formula">Haversine Formula - Wikipedia</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ public class Schedule extends BaseEntity {
@LastModifiedBy
private String updatedBy;

public static Schedule of(Generation generation, String name, DateRange dateRange) {
return new Schedule(generation, name, dateRange);
public static Schedule of(Generation generation, String name, DateRange dateRange, Location location) {
return new Schedule(generation, name, dateRange, location);
}

public Schedule(Generation generation, String name, DateRange dateRange) {
public Schedule(Generation generation, String name, DateRange dateRange, Location location) {
checkStartBeforeOrEqualEnd(dateRange.getStart(), dateRange.getEnd());

this.generation = generation;
Expand All @@ -83,6 +83,7 @@ public Schedule(Generation generation, String name, DateRange dateRange) {
this.endedAt = dateRange.getEnd();
this.status = ScheduleStatus.ADMIN_ONLY;
this.isCounted = false; // 기본값은 false 로 설정(배치가 수행되지 않음)
this.location = location;
}

public void publishSchedule(){
Expand Down Expand Up @@ -128,6 +129,10 @@ public void changeDate(LocalDateTime startDate, LocalDateTime endDate) {
this.endedAt = endDate;
}

public void changeLocation(Location location) {
this.location = location;
}

public void changeStartDate(LocalDateTime newStartDate) {
checkStartBeforeOrEqualEnd(newStartDate, endedAt);
this.startedAt = newStartDate;
Expand All @@ -151,6 +156,6 @@ public void changeIsCounted(Boolean isCounted) {
public Boolean isShowable() { return this.status == ScheduleStatus.PUBLIC; }

public Boolean isOnline() {
return this.location == null;
return this.location == null || this.location.getLatitude() == null || this.location.getLongitude() == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
public class ScheduleCreateDto {
String name;
DateRange dateRange;
Double latitude;
Double longitude;
String address;
String placeName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ public class ScheduleService {
private final AttendanceCodeRepository attendanceCodeRepository;

public Schedule create(Generation generation, ScheduleCreateDto dto) {
Schedule schedule = Schedule.of(generation, dto.getName(), dto.getDateRange());
Location location = createLocation(dto);
Schedule schedule = Schedule.of(generation, dto.getName(), dto.getDateRange(), location);

return scheduleRepository.save(schedule);
}

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

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

public Schedule getByIdOrThrow(Long scheduleId) {
return scheduleRepository.findById(scheduleId)
.orElseThrow(() -> new NotFoundException(ResultCode.SCHEDULE_NOT_FOUND));
Expand Down Expand Up @@ -110,6 +120,9 @@ public Schedule updateSchedule(Schedule schedule, Generation generation, Schedul
schedule.changeGeneration(generation);
schedule.changeDate(scheduleCreateDto.getDateRange().getStart(), scheduleCreateDto.getDateRange().getEnd());

Location location = createLocation(scheduleCreateDto);
schedule.changeLocation(location);

return schedule;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import kr.mashup.branding.aop.cipher.CheckApiCipherTime;
import kr.mashup.branding.domain.member.Platform;
import kr.mashup.branding.facade.attendance.AttendanceFacadeService;
import kr.mashup.branding.security.MemberAuth;
Expand Down Expand Up @@ -45,10 +46,11 @@ public class AttendanceController {

)
@PostMapping("/check")
@CheckApiCipherTime
public ApiResponse<AttendanceCheckResponse> check(
@ApiIgnore MemberAuth auth,
@RequestBody AttendanceCheckRequest req,
@RequestHeader(value = "cipher", required = false) String cipher // for swagger, used in aop
@RequestHeader(value = "cipher") String cipher // for swagger, used in aop
) {

final AttendanceCheckResponse response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package kr.mashup.branding.ui.member.response;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import kr.mashup.branding.domain.member.MemberGeneration;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public class MemberGenerationsResponse {

private List<MemberGenerationResponse> memberGenerations;
private List<MemberGenerationResponse> memberGenerations;

public static MemberGenerationsResponse of(List<MemberGeneration> memberGenerations) {
List<MemberGenerationResponse> responses = memberGenerations.stream()
.map(MemberGenerationResponse::of)
.collect(Collectors.toList());
return new MemberGenerationsResponse(responses);
}
public static MemberGenerationsResponse of(List<MemberGeneration> memberGenerations) {
List<MemberGenerationResponse> responses = memberGenerations.stream()
.map(MemberGenerationResponse::of)
.sorted(Comparator.comparing(MemberGenerationResponse::getNumber).reversed())
.collect(Collectors.toList());
return new MemberGenerationsResponse(responses);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.mashup.branding.ui.member.response;

import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -23,7 +24,7 @@ public class MemberProfileResponse {

private String introduction; // 자기소개

private String residence; // 거주기
private String residence; // 거주지

private String socialNetworkServiceLink; // 인스타그램 링크

Expand Down Expand Up @@ -52,6 +53,7 @@ public static MemberProfileResponse from(MemberProfile memberProfile, List<Membe
memberProfile.getLinkedInLink(),
memberGenerations.stream()
.map(MemberGenerationResponse::of)
.sorted(Comparator.comparing(MemberGenerationResponse::getNumber).reversed())
.collect(Collectors.toList())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.stream.Collectors;

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

Integer generationNumber;

Location location;

List<EventResponse> eventList;

public static ScheduleResponse from(Schedule schedule, Integer dateCount) {
Expand All @@ -34,6 +37,7 @@ public static ScheduleResponse from(Schedule schedule, Integer dateCount) {
schedule.getStartedAt(),
schedule.getEndedAt(),
schedule.getGeneration().getNumber(),
schedule.getLocation() == null ? null : schedule.getLocation(),
schedule.getEventList()
.stream()
.map(EventResponse::from)
Expand Down

0 comments on commit 622656d

Please sign in to comment.