-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
202 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/nadoyagsa/pillaroid/dto/AlarmTimeDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.nadoyagsa.pillaroid.dto; | ||
|
||
import java.time.LocalTime; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import com.nadoyagsa.pillaroid.entity.AlarmTime; | ||
import com.nadoyagsa.pillaroid.entity.User; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class AlarmTimeDto { | ||
@NotNull | ||
private LocalTime morning; | ||
@NotNull | ||
private LocalTime lunch; | ||
@NotNull | ||
private LocalTime dinner; | ||
|
||
public AlarmTime toEntity(User user) { | ||
return AlarmTime.builder() | ||
.user(user) | ||
.morning(this.morning) | ||
.lunch(this.lunch) | ||
.dinner(this.dinner) | ||
.build(); | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/nadoyagsa/pillaroid/dto/AlarmTimeResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.nadoyagsa.pillaroid.dto; | ||
|
||
import java.time.LocalTime; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@Builder | ||
public class AlarmTimeResponse { | ||
private long userIdx; // 사용자 번호 | ||
private LocalTime morning; // 아침 식사 시간 | ||
private LocalTime lunch; // 점심 식사 시간 | ||
private LocalTime dinner; // 저녁 식사 시간 | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/nadoyagsa/pillaroid/entity/AlarmTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.nadoyagsa.pillaroid.entity; | ||
|
||
import java.time.LocalTime; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.MapsId; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
|
||
import com.nadoyagsa.pillaroid.dto.AlarmTimeDto; | ||
import com.nadoyagsa.pillaroid.dto.AlarmTimeResponse; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Builder | ||
@Entity | ||
@Table(name = "alarm_time") | ||
public class AlarmTime { | ||
@Id | ||
@Column(name = "user_idx") | ||
private Long userIdx; | ||
|
||
@OneToOne | ||
@MapsId | ||
@JoinColumn(name = "user_idx", referencedColumnName = "user_idx") | ||
private User user; | ||
|
||
@Column(nullable = false) | ||
private LocalTime morning; | ||
|
||
@Column(nullable = false) | ||
private LocalTime lunch; | ||
|
||
@Column(nullable = false) | ||
private LocalTime dinner; | ||
|
||
public void updateAlarmTime(AlarmTimeDto alarmTimeDto) { | ||
this.morning = alarmTimeDto.getMorning(); | ||
this.lunch = alarmTimeDto.getLunch(); | ||
this.dinner = alarmTimeDto.getDinner(); | ||
} | ||
|
||
public AlarmTimeResponse toAlarmTimeResponse() { | ||
return AlarmTimeResponse.builder() | ||
.userIdx(this.userIdx) | ||
.morning(this.morning) | ||
.lunch(this.lunch) | ||
.dinner(this.dinner) | ||
.build(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/nadoyagsa/pillaroid/repository/AlarmTimeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.nadoyagsa.pillaroid.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.nadoyagsa.pillaroid.entity.AlarmTime; | ||
|
||
public interface AlarmTimeRepository extends JpaRepository<AlarmTime, Long> { | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/nadoyagsa/pillaroid/service/AlarmTimeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.nadoyagsa.pillaroid.service; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.nadoyagsa.pillaroid.dto.AlarmTimeDto; | ||
import com.nadoyagsa.pillaroid.entity.AlarmTime; | ||
import com.nadoyagsa.pillaroid.entity.User; | ||
import com.nadoyagsa.pillaroid.repository.AlarmTimeRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AlarmTimeService { | ||
|
||
private final AlarmTimeRepository alarmTimeRepository; | ||
|
||
// 알림 시간대 | ||
public Optional<AlarmTime> findAlarmTimeByUserIdx(Long userIdx) { | ||
return alarmTimeRepository.findById(userIdx); | ||
} | ||
|
||
// 알림 시간대 저장 | ||
@Transactional | ||
public AlarmTime saveAlarmTime(User user, AlarmTimeDto alarmTimeDto) { | ||
// 사용자의 알림 시간대 조회 | ||
Optional<AlarmTime> optAlarmTime = alarmTimeRepository.findById(user.getUserIdx()); | ||
|
||
AlarmTime alarmTime; | ||
if (optAlarmTime.isPresent()) { // 조회 O | ||
alarmTime = optAlarmTime.get(); | ||
alarmTime.updateAlarmTime(alarmTimeDto); // 알림 시간대 업데이트 | ||
} else { // 조회 X | ||
alarmTime = alarmTimeDto.toEntity(user); // 알림 시간대 생성 | ||
} | ||
|
||
alarmTimeRepository.save(alarmTime); | ||
|
||
return alarmTime; | ||
} | ||
} |