Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0399c91
fix: ProfileService의 default메서드에 @Transactional 추가
dh0304 Jul 6, 2024
4faa471
feat: Cafe와 BusinessHour의 연관관계 cascade all, orphan 설정 추가
dh0304 Jul 6, 2024
47a8555
feat: member의 thumbnailImage cascade persist 제거
dh0304 Jul 6, 2024
4de8dff
refactor: helper 클래스 레벨에 @Transactional 추가 및 코드 수정
dh0304 Jul 6, 2024
8fca79f
refactor: @SpringBootTest, @Transactional 제거 후 ServiceTest에게 위임
dh0304 Jul 6, 2024
60695f2
refactor: ServiceTest, DbcleanUp 클래스 추가
dh0304 Jul 6, 2024
2cce2f0
feat: MicroTimeUtils 생성 및 테스트 추가
dh0304 Jul 8, 2024
be4ff0a
refactor: LocalTime LocalDateTime 관련 코드 마이크로초로 컨버팅하도록 수정
dh0304 Jul 8, 2024
12606bc
refactor: 카공 23시 시작 23:59:59초 종료시 가능하게 로직 추가
dh0304 Jul 10, 2024
3b77b10
refactor: 나노초 관련 테스트 수정
dh0304 Jul 10, 2024
2fb14dc
refactor: LocalDateTime.now()를 MicroTimeUtils 를 통해 변환
dh0304 Jul 10, 2024
2df5de3
refactor: LocalDateTime.now를 MicroTimeUtils의 상수로 변경
dh0304 Jul 10, 2024
7155584
refactor: microUtils 리팩토링
dh0304 Jul 10, 2024
fdb2301
refactor: 코드 정리
dh0304 Jul 12, 2024
baba15c
refactor: 사용하지 않는 메서드 제거
dh0304 Jul 12, 2024
adfbf42
docs: application-test.yml 수정
dh0304 Jul 12, 2024
de13aa6
docs: 테스트 패키지에 있는 application.yml 삭제
dh0304 Jul 12, 2024
a012e34
refactor: 시간관련 코드 micro단위에서 초단위로 변경
dh0304 Jul 12, 2024
6c6f02c
refactor: ServiceTest에 @Import 추가
dh0304 Jul 12, 2024
303353e
chore: 패키지 변경
dh0304 Jul 12, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ application-pub.yml
application-local.yml
application-*.yml
application_log
*.gz
*.gz
!**/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.controller;

import static com.example.demo.exception.ExceptionType.*;
import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.LocalDateTime;

Expand Down Expand Up @@ -96,7 +97,7 @@ public ResponseEntity<StudyOnceResponse> update(@PathVariable Long studyOnceId,
if (studyOnceService.doesOnlyStudyLeaderExist(studyOnceId)) {
studyOnceService.updateStudyOnce(leaderId, studyOnceId, request, LocalDateTime.now());
} else {
studyOnceService.updateStudyOncePartially(leaderId, studyOnceId, request, LocalDateTime.now());
studyOnceService.updateStudyOncePartially(leaderId, studyOnceId, request);
}
StudyOnceResponse response = studyOnceService.findStudyOnce(studyOnceId, LocalDateTime.now());
return ResponseEntity.ok(response);
Expand All @@ -106,9 +107,8 @@ public ResponseEntity<StudyOnceResponse> update(@PathVariable Long studyOnceId,
public ResponseEntity<StudyOnceJoinResult> tryJoin(@PathVariable Long studyOnceId,
@RequestHeader("Authorization") String authorization) {
long memberId = cafegoryTokenManager.getIdentityId(authorization);
LocalDateTime requestTime = LocalDateTime.now();
studyOnceService.tryJoin(memberId, studyOnceId);
return ResponseEntity.ok(new StudyOnceJoinResult(requestTime, true));
return ResponseEntity.ok(new StudyOnceJoinResult(LOCAL_DATE_TIME_NOW, true));
}

@DeleteMapping("/{studyOnceId:[0-9]+}")
Expand All @@ -117,7 +117,8 @@ public ResponseEntity<StudyOnceQuitResponse> tryQuit(@PathVariable Long studyOnc
long memberId = cafegoryTokenManager.getIdentityId(authorization);
LocalDateTime requestTime = LocalDateTime.now();
studyOnceService.tryQuit(memberId, studyOnceId);
return ResponseEntity.ok(new StudyOnceQuitResponse(requestTime, true));
return ResponseEntity.ok(
new StudyOnceQuitResponse(truncateDateTimeToSecond(requestTime), true));
}

@PatchMapping("/{studyOnceId:[0-9]+}/attendance")
Expand All @@ -126,7 +127,7 @@ public ResponseEntity<UpdateAttendanceResponse> takeAttendance(@PathVariable Lon
@RequestBody UpdateAttendanceRequest request) {
long leaderId = cafegoryTokenManager.getIdentityId(authorization);
UpdateAttendanceResponse response = studyOnceService.updateAttendances(leaderId, studyOnceId,
request, LocalDateTime.now());
request, LOCAL_DATE_TIME_NOW);
return ResponseEntity.ok(response);
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/example/demo/domain/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.demo.domain;

import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.LocalDateTime;

import javax.persistence.Column;
Expand All @@ -21,13 +23,13 @@ public class BaseEntity {

@PrePersist
public void prePersist() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime now = LOCAL_DATE_TIME_NOW;
createdDate = now;
lastModifiedDate = now;
}

@PreUpdate
public void preUpdate() {
lastModifiedDate = LocalDateTime.now();
lastModifiedDate = LOCAL_DATE_TIME_NOW;
}
}
4 changes: 0 additions & 4 deletions src/main/java/com/example/demo/domain/cafe/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public Address(final String fullAddress, final String region) {
this.region = region;
}

public boolean isInRegion(String region) {
return true;
}

public String showFullAddress() {
return getFullAddress();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/example/demo/domain/cafe/BusinessHour.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public class BusinessHour {
@Column(name = "days_of_week")
private String day;

/// columnDefinition 옵션은 나중에 DB에 직접 적용하고 삭제할 것
@Column(columnDefinition = "TIME(6)")
private LocalTime startTime;
@Column(columnDefinition = "TIME(6)")
private LocalTime endTime;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.demo.domain.cafe;

import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -40,7 +42,7 @@ private boolean isTodayBusinessDay(DayOfWeek businessDay, LocalDateTime now, boo
}

private boolean is24HourBusiness(LocalTime startTime, LocalTime endTime) {
return startTime.equals(LocalTime.MIN) && endTime.equals(LocalTime.MAX);
return startTime.equals(LocalTime.MIN) && endTime.equals(MAX_LOCAL_TIME);
}

private boolean isOpenOvernight(LocalTime startTime, LocalTime endTime) {
Expand All @@ -58,7 +60,7 @@ private boolean isOpenDuringDay(LocalTime startTime, LocalTime endTime, LocalTim

@Override
public boolean checkWithBusinessHours(List<BusinessHour> businessHours, LocalDateTime now) {
if (!hasMatchingDayOfWeek(businessHours, now)) {
if (!hasMatchingDayOfWeek(businessHours, truncateDateTimeToSecond(now))) {
throw new CafegoryException(ExceptionType.CAFE_NOT_FOUND_DAY_OF_WEEK);
}
return businessHours.stream()
Expand All @@ -68,33 +70,37 @@ public boolean checkWithBusinessHours(List<BusinessHour> businessHours, LocalDat

public boolean checkBetweenBusinessHours(LocalTime businessStartTime, LocalTime businessEndTime,
LocalTime chosenStartTime, LocalTime chosenEndTime) {
LocalTime truncatedStartTime = truncateTimeToSecond(chosenStartTime);
LocalTime truncatedEndTime = truncateTimeToSecond(chosenEndTime);

// 영업 시작시간이 당일, 영업 종료시간이 당일
if (businessStartTime.isBefore(businessEndTime)) {
return (businessStartTime.equals(chosenStartTime) || businessStartTime.isBefore(chosenStartTime)) && (
businessEndTime.equals(chosenEndTime) || businessEndTime.isAfter(chosenEndTime));
return (businessStartTime.equals(truncatedStartTime) || businessStartTime.isBefore(truncatedStartTime))
&& (
businessEndTime.equals(truncatedEndTime) || businessEndTime.isAfter(truncatedEndTime));
}
// 영업 시작시간이 당일, 영업 종료시간이 다음날
if (businessStartTime.isAfter(businessEndTime)) {
LocalDateTime businessStartDateTime = LocalDateTime.of(LocalDate.now(), businessStartTime);
LocalDateTime businessEndDateTime = LocalDateTime.of(LocalDate.now().plusDays(1), businessEndTime);
// 선택된 시작시간이 당일, 선택된 종료시간이 당일 || 선택된 시작시간이 다음날, 선택된 종료시간이 다음날
if (chosenStartTime.isBefore(chosenEndTime)) {
if (truncatedStartTime.isBefore(truncatedEndTime)) {
LocalDate chosenDate = LocalDate.now();

boolean isChosenTimeOvernight = businessStartTime.isAfter(chosenStartTime);
boolean isChosenTimeOvernight = businessStartTime.isAfter(truncatedStartTime);
LocalDate date = isChosenTimeOvernight ? chosenDate.plusDays(1) : chosenDate;
LocalDateTime chosenStartDateTime = LocalDateTime.of(date, chosenStartTime);
LocalDateTime chosenEndDateTime = LocalDateTime.of(date, chosenEndTime);
LocalDateTime chosenEndDateTime = LocalDateTime.of(date, truncatedEndTime);

return (businessStartDateTime.isBefore(chosenStartDateTime) || businessStartDateTime.equals(
chosenStartDateTime))
&& (businessEndDateTime.isAfter(chosenEndDateTime) || businessEndDateTime.equals(
chosenEndDateTime));
}
// 선택된 시작시간이 당일, 선택된 종료시간이 다음날
if (chosenStartTime.isAfter(chosenEndTime)) {
LocalDateTime chosenStartDateTime = LocalDateTime.of(LocalDate.now(), chosenStartTime);
LocalDateTime chosenEndDateTime = LocalDateTime.of(LocalDate.now().plusDays(1), chosenEndTime);
if (truncatedStartTime.isAfter(truncatedEndTime)) {
LocalDateTime chosenStartDateTime = LocalDateTime.of(LocalDate.now(), truncatedStartTime);
LocalDateTime chosenEndDateTime = LocalDateTime.of(LocalDate.now().plusDays(1), truncatedEndTime);
return (businessStartDateTime.equals(chosenStartDateTime) || businessStartDateTime.isBefore(
chosenStartDateTime)) && (businessEndDateTime.equals(chosenEndDateTime)
|| businessEndDateTime.isAfter(chosenEndDateTime));
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/example/demo/domain/cafe/Cafe.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.demo.domain.cafe;

import static com.example.demo.exception.ExceptionType.*;
import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalDouble;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class Cafe {
private boolean isAbleToStudy;
private int minBeveragePrice;

@OneToMany(mappedBy = "cafe")
@OneToMany(mappedBy = "cafe", cascade = CascadeType.ALL, orphanRemoval = true)
@Builder.Default
private List<BusinessHour> businessHours = new ArrayList<>();

Expand Down Expand Up @@ -83,7 +84,7 @@ public String getRegion() {
}

public boolean isOpen(OpenChecker<BusinessHour> openChecker) {
return openChecker.checkWithBusinessHours(this.businessHours, LocalDateTime.now());
return openChecker.checkWithBusinessHours(this.businessHours, LOCAL_DATE_TIME_NOW);
}

public OptionalDouble calcAverageRating() {
Expand All @@ -98,4 +99,8 @@ public BusinessHour findBusinessHour(DayOfWeek dayOfWeek) {
.findFirst()
.orElseThrow(() -> new CafegoryException(CAFE_NOT_FOUND_DAY_OF_WEEK));
}

public void changeBusinessHours(List<BusinessHour> businessHours) {
this.businessHours = businessHours;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.domain.cafe;

import static com.example.demo.exception.ExceptionType.*;
import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.LocalDateTime;
import java.time.LocalTime;
Expand Down Expand Up @@ -40,7 +41,7 @@ public static class Builder {
private MinMenuPrice minMenuPrice;
private LocalTime startTime;
private LocalTime endTime;
private LocalDateTime now = LocalDateTime.now();
private LocalDateTime now = LOCAL_DATE_TIME_NOW;

public Builder(boolean isAbleToStudy, String region) {
this.isAbleToStudy = isAbleToStudy;
Expand Down Expand Up @@ -80,7 +81,7 @@ public CafeSearchCondition build() {

private LocalTime calcLocalTime(int time) {
if (time == END_TIME) {
return LocalTime.MAX;
return MAX_LOCAL_TIME;
}
return LocalTime.of(time, 0);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/example/demo/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class Member {
private String email;
private String introduction;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "thumbnail_image_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private ThumbnailImage thumbnailImage;

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/example/demo/domain/study/StudyOnce.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.domain.study;

import static com.example.demo.exception.ExceptionType.*;
import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.Duration;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -96,7 +97,7 @@ private StudyOnce(Long id, String name, Cafe cafe, LocalDateTime startDateTime,
}

private void validateStartDateTime(LocalDateTime startDateTime) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime now = LOCAL_DATE_TIME_NOW;
Duration between = Duration.between(now, startDateTime);
if (between.toSeconds() < 3 * 60 * 60) {
throw new CafegoryException(ExceptionType.STUDY_ONCE_WRONG_START_TIME);
Expand All @@ -116,7 +117,9 @@ private void validateStudyOnceTime(LocalDateTime startDateTime, LocalDateTime en
}

private void validateStartAndEndTime(LocalTime startLocalTime, LocalTime endLocalTime) {
if (!(startLocalTime.equals(LocalTime.of(23, 0)) && endLocalTime.equals(LocalTime.MAX))) {
if (!(startLocalTime.equals(LocalTime.of(23, 0)) &&
(endLocalTime.equals(MAX_LOCAL_TIME) || endLocalTime.equals(LocalTime.of(23, 59, 59))))
) {
throw new CafegoryException(STUDY_ONCE_SHORT_DURATION);
}
}
Expand Down Expand Up @@ -199,7 +202,7 @@ public boolean isLeader(Member member) {
}

public boolean canJoin(LocalDateTime baseDateTime) {
Duration between = Duration.between(baseDateTime, startDateTime);
Duration between = Duration.between(truncateDateTimeToSecond(baseDateTime), startDateTime);
return between.toSeconds() >= 60 * 60;
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/example/demo/mapper/CafeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.example.demo.dto.cafe.CafeSearchListRequest;
import com.example.demo.dto.cafe.CafeSearchListResponse;
import com.example.demo.dto.cafe.CafeSearchResponse;
import com.example.demo.dto.cafe.CafeSearchReviewResponse;
import com.example.demo.dto.cafe.CafeSearchSnsResponse;
import com.example.demo.dto.cafe.CafeSearchStudyOnceResponse;
import com.example.demo.dto.cafe.SnsResponse;
Expand Down Expand Up @@ -90,7 +89,6 @@ public CafeSearchResponse toCafeSearchResponse(
Cafe findCafe,
List<CafeSearchBusinessHourResponse> cafeSearchBusinessHourResponses,
List<CafeSearchSnsResponse> cafeSearchSnsResponses,
List<CafeSearchReviewResponse> cafeSearchReviewResponses,
List<CafeSearchStudyOnceResponse> cafeSearchStudyOnceResponses,
OpenChecker<BusinessHour> openChecker) {
return CafeSearchResponse.builder()
Expand All @@ -117,7 +115,6 @@ public CafeSearchResponse toCafeSearchResponseWithEmptyInfo(
Cafe findCafe,
List<CafeSearchBusinessHourResponse> businessHourResponses,
List<CafeSearchSnsResponse> snsResponses,
List<CafeSearchReviewResponse> reviewResponses,
OpenChecker<BusinessHour> openChecker
) {
return CafeSearchResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.demo.repository.study;

import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.LocalDateTime;
import java.util.List;

Expand Down Expand Up @@ -54,7 +56,7 @@ public Long count(StudyOnceSearchRequest studyOnceSearchRequest) {
}

private BooleanExpression studyJoinAbleFilter(boolean onlyJoinAble) {
LocalDateTime base = LocalDateTime.now().plusHours(3);
LocalDateTime base = LOCAL_DATE_TIME_NOW.plusHours(3);
if (onlyJoinAble) {
return qStudyOnce.startDateTime.after(base)
.or(qStudyOnce.startDateTime.eq(base));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public CafeSearchResponse searchCafeForMemberByCafeId(Long cafeId, Long memberId
findCafe,
businessHourMapper.toCafeSearchBusinessHourResponses(findCafe.getBusinessHours()),
snsDetailMapper.toCafeSearchSnsResponses(findCafe.getSnsDetails()),
reviewMapper.toCafeSearchReviewResponses(findCafe.getReviews()),
studyOnceMapper.toCafeSearchStudyOnceResponse(findCafe),
openChecker
);
Expand All @@ -90,7 +89,6 @@ public CafeSearchResponse searchCafeForNotMemberByCafeId(Long cafeId) {
findCafe,
businessHourMapper.toCafeSearchBusinessHourResponses(findCafe.getBusinessHours()),
snsDetailMapper.toCafeSearchSnsResponses(findCafe.getSnsDetails()),
reviewMapper.toCafeSearchReviewResponses(findCafe.getReviews()),
openChecker
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.example.demo.service.profile;

import static com.example.demo.util.TruncatedTimeUtil.*;

import java.time.LocalDateTime;

import org.springframework.transaction.annotation.Transactional;

import com.example.demo.dto.profile.ProfileGetResponse;
import com.example.demo.dto.profile.ProfileUpdateRequest;
import com.example.demo.dto.profile.ProfileUpdateResponse;

public interface ProfileService {

@Transactional
default ProfileGetResponse get(Long requestMemberId, Long targetMemberId) {
return get(requestMemberId, targetMemberId, LocalDateTime.now());
return get(requestMemberId, targetMemberId, LOCAL_DATE_TIME_NOW);
}

ProfileGetResponse get(Long requestMemberId, Long targetMemberId, LocalDateTime baseDateTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ UpdateAttendanceResponse updateAttendances(long leaderId, long studyOnceId,

void updateStudyOnce(long requestedMemberId, long studyOnceId, StudyOnceUpdateRequest request, LocalDateTime now);

void updateStudyOncePartially(long requestedMemberId, long studyOnceId, StudyOnceUpdateRequest request,
LocalDateTime now);
void updateStudyOncePartially(long requestedMemberId, long studyOnceId, StudyOnceUpdateRequest request);
}
Loading