Skip to content

Commit

Permalink
Merge pull request #152 from lemonssoju/develop-v2
Browse files Browse the repository at this point in the history
[develop-v2] main merge
  • Loading branch information
JoongHyun-Kim authored May 30, 2024
2 parents ad9bee9 + 6af8c62 commit f061179
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.lesso.neverland.album.application;

import com.lesso.neverland.album.domain.Album;
import com.lesso.neverland.album.dto.AlbumDetailResponse;
import com.lesso.neverland.album.dto.AlbumImageRequest;
import com.lesso.neverland.album.dto.*;
import com.lesso.neverland.album.repository.AlbumRepository;
import com.lesso.neverland.comment.dto.CommentDto;
import com.lesso.neverland.common.base.BaseException;
Expand Down Expand Up @@ -51,7 +50,21 @@ public BaseResponse<AlbumDetailResponse> getAlbumDetail(Long groupIdx, Long albu
comment.getContent())).toList();

AlbumDetailResponse albumDetailResponse = new AlbumDetailResponse(album.getPuzzle().getTitle(), album.getPuzzle().getPuzzleDate().toString(),
album.getPuzzle().getLocation(), memberList, album.getAlbumImage(), album.getContent(), album.getPuzzle().getPuzzleIdx(), commentList);
album.getPuzzle().getLocation().getLocation(), memberList, album.getAlbumImage(), album.getContent(), album.getPuzzle().getPuzzleIdx(), commentList);
return new BaseResponse<>(albumDetailResponse);
}

// 앨범 목록 조회(sortType="time", "location")
public BaseResponse<?> getAlbumList(Long groupIdx, String sortType) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
List<Album> albumList = albumRepository.findByTeamOrderByCreatedDateDesc(group);

if (sortType.equals("time")) {
List<AlbumByTimeDto> albumDtoList = albumList.stream().map(AlbumByTimeDto::from).toList();
return new BaseResponse<>(new AlbumListByTimeResponse(albumDtoList));
} else {
List<AlbumByLocationDto> albumDtoList = albumList.stream().map(AlbumByLocationDto::from).toList();
return new BaseResponse<>(new AlbumListByLocationResponse(albumDtoList));
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/lesso/neverland/album/domain/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lesso.neverland.comment.domain.Comment;
import com.lesso.neverland.common.base.BaseEntity;
import com.lesso.neverland.group.domain.Team;
import com.lesso.neverland.puzzle.domain.Puzzle;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand All @@ -26,6 +27,11 @@ public class Album extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "puzzle")
private Puzzle puzzle;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team")
private Team team;

private String albumImage;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lesso.neverland.album.dto;

import com.lesso.neverland.album.domain.Album;

public record AlbumByLocationDto(Long albumIdx,
String albumImage,
String x,
String y) {
public static AlbumByLocationDto from(Album album) {
return new AlbumByLocationDto(
album.getAlbumIdx(),
album.getAlbumImage(),
album.getPuzzle().getLocation().getX(),
album.getPuzzle().getLocation().getY());
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/lesso/neverland/album/dto/AlbumByTimeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lesso.neverland.album.dto;

import com.lesso.neverland.album.domain.Album;

import java.util.List;

public record AlbumByTimeDto(Long albumIdx,
String title,
String content,
String albumImage,
String puzzleDate,
Integer puzzlerCount,
List<String> puzzlerImageList) {
public static AlbumByTimeDto from(Album album) {
return new AlbumByTimeDto(
album.getAlbumIdx(),
album.getPuzzle().getTitle(),
album.getContent(),
album.getAlbumImage(),
album.getPuzzle().getPuzzleDate().toString(),
album.getPuzzle().getPuzzleMembers().size(),
album.getPuzzle().getPuzzleMembers().stream()
.map(puzzleMember -> puzzleMember.getUser().getProfile().getProfileImage()).toList()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lesso.neverland.album.dto;

import java.util.List;

public record AlbumListByLocationResponse(List<AlbumByLocationDto> albumList) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lesso.neverland.album.dto;

import java.util.List;

public record AlbumListByTimeResponse(List<AlbumByTimeDto> albumList) {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ public BaseResponse<String> uploadAlbumImage(@PathVariable("groupIdx") Long grou
public BaseResponse<AlbumDetailResponse> getAlbumDetail(@PathVariable("groupIdx") Long groupIdx, @PathVariable("albumIdx") Long albumIdx) {
return albumService.getAlbumDetail(groupIdx, albumIdx);
}

// 앨범 목록 조회
@GetMapping("")
public BaseResponse<?> getAlbumList(@PathVariable("groupIdx") Long groupIdx, @RequestParam String sortType) {
return albumService.getAlbumList(groupIdx, sortType);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.lesso.neverland.album.repository;

import com.lesso.neverland.album.domain.Album;
import com.lesso.neverland.group.domain.Team;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface AlbumRepository extends JpaRepository<Album, Long> {
List<Album> findByTeamOrderByCreatedDateDesc(Team team);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public BaseResponse<GroupListResponse> getGroupList() {

private String calculateRecentUpdate(Team group) {
Puzzle recentPuzzle = puzzleRepository.findTopByTeamAndStatusEqualsOrderByCreatedDateDesc(group, ACTIVE);

if (recentPuzzle == null) return "";
LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul"));
LocalDate puzzleCreatedDate = recentPuzzle.getCreatedDate();
long daysBetween = ChronoUnit.DAYS.between(puzzleCreatedDate, today);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.lesso.neverland.common.image.ImageService;
import com.lesso.neverland.gpt.application.GptService;
import com.lesso.neverland.gpt.dto.GptResponseDto;
import com.lesso.neverland.puzzle.domain.PuzzleLocation;
import com.lesso.neverland.puzzle.dto.CompletePuzzleRequest;
import com.lesso.neverland.puzzle.dto.CompletePuzzleResponse;
import com.lesso.neverland.gpt.dto.GptResponse;
Expand Down Expand Up @@ -73,7 +74,7 @@ private static List<GroupPuzzleDto> getGroupPuzzleDtos(List<Puzzle> groupPuzzleL
puzzle.getPuzzleImage(),
puzzle.getUser().getProfile().getNickname(),
puzzle.getCreatedDate().toString(),
puzzle.getLocation())).toList();
puzzle.getLocation().getLocation())).toList();
}

// 퍼즐 상세 조회
Expand All @@ -88,7 +89,7 @@ public BaseResponse<PuzzleDetailResponse> getPuzzleDetail(Long groupIdx, Long pu
boolean isWriter = puzzle.getUser().equals(user);
boolean hasWrite = puzzlePieceRepository.existsByPuzzleAndUser(puzzle, user);

PuzzleDetailResponse puzzleDetail = new PuzzleDetailResponse(puzzle.getLocation(), puzzle.getPuzzleImage(),
PuzzleDetailResponse puzzleDetail = new PuzzleDetailResponse(puzzle.getLocation().getLocation(), puzzle.getPuzzleImage(),
puzzle.getPuzzleDate().toString(), puzzle.getUser().getProfile().getNickname(), puzzle.getTitle(), puzzle.getContent(),
getMemberImageList(puzzle), puzzle.getPuzzleMembers().size(), puzzle.getPuzzlePieces().size()+1, isWriter, hasWrite,
getPuzzlePieceList(puzzle));
Expand Down Expand Up @@ -159,12 +160,13 @@ private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group,
.content(createPuzzleRequest.content())
.puzzleImage(imagePath)
.puzzleDate(puzzleDate)
.location(createPuzzleRequest.location()).build();
.location(new PuzzleLocation(createPuzzleRequest.location())).build();
puzzleRepository.save(puzzle);

return puzzle;
}

//TODO: 퍼즐 생성 시, String으로 받은 location값을 x, y 좌표로 변환해 함께 저장

// [작성자] 퍼즐 수정
public BaseResponse<String> editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile newImage, EditPuzzleRequest editPuzzleRequest) {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class Puzzle extends BaseEntity {
@Column(nullable = false)
private LocalDate puzzleDate; // 추억 날짜

@Column(nullable = false)
private String location; // 추억 장소
@Embedded
private PuzzleLocation location; // 추억 장소

@OneToMany(mappedBy = "puzzle")
private List<PuzzlePiece> puzzlePieces = new ArrayList<>();
Expand All @@ -55,7 +55,7 @@ public class Puzzle extends BaseEntity {
private List<PuzzleMember> puzzleMembers = new ArrayList<>(); // 해당 퍼즐에 참여한 멤버 목록

@Builder
public Puzzle(User user, Team team, String title, String content, String puzzleImage, LocalDate puzzleDate, String location, String backgroundMusic, String backgroundMusicUrl) {
public Puzzle(User user, Team team, String title, String content, String puzzleImage, LocalDate puzzleDate, PuzzleLocation location) {
this.user = user;
this.team = team;
this.title = title;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lesso.neverland.puzzle.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PuzzleLocation {

@Column(nullable = false)
private String location;

private String x;
private String y;

@Builder
public PuzzleLocation(String location) {this.location = location;}
}

0 comments on commit f061179

Please sign in to comment.