Skip to content

Commit

Permalink
Merge pull request #47 from Familing/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JunHyeong-99 authored Aug 25, 2024
2 parents 00bf893 + 25d4a8e commit fd1cf86
Show file tree
Hide file tree
Showing 30 changed files with 858 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record FamilyUsersDto(

public static FamilyUsersDto fromEntity(List<User> users){
return new FamilyUsersDto(users.stream()
.map(user -> new FamilyUserDto(user.getNickname(), user.getImageUrl()))
.map(user -> new FamilyUserDto(user.getNickname(), user.getProfileImg()))
.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.pinu.familing.domain.snapshot.dto.CustomPage;
import com.pinu.familing.domain.snapshot.dto.SnapshotImageRequest;
import com.pinu.familing.domain.snapshot.dto.SnapshotResponse;
import com.pinu.familing.domain.snapshot.service.SnapshotAlarmService;
import com.pinu.familing.domain.snapshot.service.SnapshotService;
import com.pinu.familing.global.error.CustomException;
import com.pinu.familing.global.error.ExceptionCode;
Expand All @@ -16,44 +15,49 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.beans.PropertyEditorSupport;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import static com.pinu.familing.global.error.ExceptionCode.REQUIRE_IMG;

@RestController
@RequestMapping("/api/v1/snapshots")
@RequiredArgsConstructor
public class SnapshotController {

private final SnapshotService snapshotService;
private final SnapshotAlarmService snapshotAlarmService;


// 특정 날짜 스냅샷 조회
@GetMapping("/{day}")
public ApiUtils.ApiResult<?> provideSnapshot(@PathVariable("day") LocalDate day,
public ApiUtils.ApiResult<?> getSnapshotByDate(@PathVariable("day") LocalDate day,
@AuthenticationPrincipal CustomOAuth2User customOAuth2User) {
SnapshotResponse snapshot = snapshotService.provideSnapshot(day, customOAuth2User.getName());
SnapshotResponse snapshot = snapshotService.getSnapshotByDate(day, customOAuth2User.getName());
return ApiUtils.success(snapshot);
}

//스냅샷 페이지 조회
@GetMapping(value = "/{day}", params = "page")
public ApiUtils.ApiResult<?> changeSnapshot(@PathVariable("day") LocalDate day, Pageable pageable,
public ApiUtils.ApiResult<?> getSnapshotPage(@PathVariable("day") LocalDate day, Pageable pageable,
@AuthenticationPrincipal CustomOAuth2User customOAuth2User) {
Page<SnapshotResponse> snapshotPage = snapshotService.provideSnapshotPage(day, pageable, customOAuth2User.getName());
Page<SnapshotResponse> snapshotPage = snapshotService.getSnapshotPage(day, pageable, customOAuth2User.getName());
return ApiUtils.success(new CustomPage(snapshotPage));
}

//스냅샷 이미지 등록
@PostMapping("/{day}/users")
public ApiUtils.ApiResult<?> registerSnapshotImage(@PathVariable("day") LocalDate day,
@AuthenticationPrincipal CustomOAuth2User customOAuth2User,
@Valid @RequestBody SnapshotImageRequest snapshotImageRequest) {
snapshotService.registerSnapshotImage(day, customOAuth2User.getName(), snapshotImageRequest);
@RequestPart("snapshot_img") MultipartFile snapshotImage) {
if (snapshotImage.isEmpty()) {
throw new CustomException(REQUIRE_IMG);
}
snapshotService.registerSnapshotImage(day, customOAuth2User.getName(), snapshotImage);
return ApiUtils.success("Image has been registered successfully.");
}

Expand All @@ -63,16 +67,16 @@ public ApiUtils.ApiResult<?> registerSnapshotImage(@PathVariable("day") LocalDat
public ApiUtils.ApiResult<?> setSnapshotAlarmTime(@AuthenticationPrincipal CustomOAuth2User customOAuth2User,
@RequestParam(name = "time") String time) {
LocalTime targetTime = LocalTime.parse(time);
snapshotAlarmService.registerAlarmChangeRequest(customOAuth2User.getName(), targetTime);
snapshotService.changeAlarmTime(customOAuth2User.getName(), targetTime);
return ApiUtils.success("Snapshot alarm has been converted successfully.");
}


// 스냅샷 알람 조회
@GetMapping("/alarm")
public ApiUtils.ApiResult<?> getSnapshotAlarmTime(@AuthenticationPrincipal CustomOAuth2User customOAuth2User) {
LocalTime time = snapshotAlarmService.getSnapshotAlarmTime(customOAuth2User.getName());
return ApiUtils.success(time);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
return ApiUtils.success(snapshotService.getSnapshotAlarmTime(customOAuth2User.getName()).format(formatter));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record SnapshotResponse(String Title,
LocalDate date,
List<IndividualSnapshotImage> individualSnapshotImages) {
UserSnapshot me,
List<UserSnapshot> family) {

public SnapshotResponse(Snapshot snapshot) {
public SnapshotResponse(String username, Snapshot snapshot) {
this(
snapshot.getSnapshotTitle().getTitle(),
snapshot.getDate(),
snapshot.getSnapshotImages().stream()
.map(IndividualSnapshotImage::new)
.filter(snapshotImage -> snapshotImage.getUser().getUsername().equals(username))
.findFirst()
.map(UserSnapshot::new)
.orElse(null),
snapshot.getSnapshotImages().stream()
.filter(snapshotImage -> !snapshotImage.getUser().getUsername().equals(username))
.map(UserSnapshot::new)
.collect(Collectors.toList())
);
}

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
record IndividualSnapshotImage(String username,
String nickname,
String userProfile,
String snapshotImage) {
record UserSnapshot(String username,
String nickname,
String ProfileImg,
String snapshotImg) {

public IndividualSnapshotImage(SnapshotImage snapshotImage) {
this(snapshotImage.getUser().getUsername(), snapshotImage.getUser().getNickname(), snapshotImage.getUser().getImageUrl(), snapshotImage.getImageUrl());
public UserSnapshot(SnapshotImage snapshotImage) {
this(snapshotImage.getUser().getUsername(), snapshotImage.getUser().getNickname(), snapshotImage.getUser().getProfileImg(), snapshotImage.getSnapshotImg());
}
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public class Snapshot extends BaseEntity {
@OneToMany(orphanRemoval = true, mappedBy = "snapshot", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
private List<SnapshotImage> snapshotImages = new ArrayList<>();

public void addSnapshotImage(SnapshotImage snapshotImage) {
this.snapshotImages.add(snapshotImage);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.pinu.familing.domain.BaseEntity;
import com.pinu.familing.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -12,6 +13,7 @@
@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SnapshotImage extends BaseEntity {

@Id
Expand All @@ -29,19 +31,19 @@ public class SnapshotImage extends BaseEntity {
private LocalDate date;

@Column(nullable = false)
private String imageUrl;
private String snapshotImg;


@Builder
public SnapshotImage(Snapshot snapshot, User user, LocalDate date) {
public SnapshotImage(Snapshot snapshot, User user, String snapshotImg,LocalDate date) {
this.snapshot = snapshot;
this.user = user;
this.imageUrl = "EMPTY";
this.snapshotImg = snapshotImg;
this.date = date;
}

public void updateImage(String imageUrl) {
this.imageUrl = imageUrl;
public void updateImage(String snapshotImg) {
this.snapshotImg = snapshotImg;
}

@Override
Expand All @@ -51,7 +53,8 @@ public String toString() {
", snapshot=" + snapshot +
", user=" + user +
", date=" + date +
", imageUrl='" + imageUrl + '\'' +
", imageUrl='" + snapshotImg + '\'' +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@


import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SnapshotTitle {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;


@Column(length = 13)
private String title;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

public interface SnapshotImageRepository extends JpaRepository<SnapshotImage, Long> {
Optional<SnapshotImage> findByUserAndDate(User user, LocalDate day);

boolean existsByUserAndDate(User user, LocalDate currentDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.pinu.familing.domain.family.entity.Family;
import com.pinu.familing.domain.family.repository.FamilyRepository;
import com.pinu.familing.domain.snapshot.service.SnapshotAlarmService;
import com.pinu.familing.domain.snapshot.service.SnapshotService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
Expand All @@ -18,7 +17,6 @@
public class SnapshotScheduler {

private final FamilyRepository familyRepository;
private final SnapshotAlarmService snapshotAlarmService;
private final SnapshotService snapshotService;

/*
Expand All @@ -34,12 +32,6 @@ public class SnapshotScheduler {
*/


// 매 분마다 실행
@Scheduled(cron = "0 0 0 * * ?")
public void createSnapshotAlarmChangeInBatches() {
snapshotAlarmService.changeAllAlarmChangeRequest();
}

// 알람 보내기: 매 분마다 실행
@Scheduled(cron = "0 * * * * ?")
public void sendSnapshotAlarm() {
Expand All @@ -49,8 +41,6 @@ public void sendSnapshotAlarm() {
// 모든 가족을 가져옴
List<Family> families = familyRepository.findAllBySnapshotAlarmTime(currentTime);

//엔티티 생성
families.forEach((family) -> snapshotService.createFamilySnapshotEntity(family, currentDate));

for (Family family : families) {
System.out.println(family.getFamilyName() + ": 알람! ");
Expand Down

This file was deleted.

Loading

0 comments on commit fd1cf86

Please sign in to comment.