Skip to content

[develop-v2] main merge #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 30, 2024
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;}
}
Loading