Skip to content
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

[develop-v2] main merge #165

Merged
merged 18 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e59275f
#87 fix: 퍼즐 상세 쑰회 μ‹œ μž‘μ„±μΌμžλ„ ν•¨κ»˜ λ°˜ν™˜ν•˜λ„λ‘ μˆ˜μ •
JoongHyun-Kim Jun 3, 2024
7114935
Merge pull request #164 from lemonssoju/fix/87-getPuzzleDetail
JoongHyun-Kim Jun 3, 2024
39ad9b9
#87 fix: 퍼즐 상세 쑰회 μ‹œ 멀버 이미지 λ¦¬μŠ€νŠΈμ— μž‘μ„±μž 이미지λ₯Ό λ°˜λ“œμ‹œ ν¬ν•¨ν•˜λ„λ‘ μˆ˜μ •
JoongHyun-Kim Jun 3, 2024
d268627
Merge pull request #166 from lemonssoju/fix/87-getPuzzleDetail
JoongHyun-Kim Jun 3, 2024
69de47b
#103 fix: κ·Έλ£Ή λ‚˜κ°€κΈ° μˆ˜ν–‰ μ‹œ userTeam도 ν•¨κ»˜ μ‚­μ œ
JoongHyun-Kim Jun 3, 2024
4f2ff5a
Merge pull request #167 from lemonssoju/fix/103-getPuzzlerList
JoongHyun-Kim Jun 3, 2024
ffe2c47
#103 fix: 퍼즐 상세 쑰회 μ‹œ 멀버 λ‹‰λ„€μž„ λͺ©λ‘λ„ ν•¨κ»˜ λ°˜ν™˜ν•˜λ„λ‘ μˆ˜μ •
JoongHyun-Kim Jun 3, 2024
a0bf3e0
Merge pull request #168 from lemonssoju/fix/87-getPuzzleDetail
JoongHyun-Kim Jun 3, 2024
5e29760
#105 fix: 퍼즐 μ™„μ„±ν•˜κΈ° APIμ—μ„œ DB의 퍼즐 λ°μ΄ν„°λ‘œ μš”μ²­μ„ 보내도둝 μˆ˜μ •
JoongHyun-Kim Jun 3, 2024
37d8827
Merge pull request #169 from lemonssoju/fix/105-completePuzzle
JoongHyun-Kim Jun 3, 2024
1316734
#122 fix: κ·Έλ£Ή ν”„λ‘œν•„ 쑰회 μ‹œ κ΄€λ¦¬μž λ‹‰λ„€μž„λ„ ν•¨κ»˜ λ°˜ν™˜ν•˜λ„λ‘ μˆ˜μ •
JoongHyun-Kim Jun 3, 2024
6ef84c7
Merge pull request #170 from lemonssoju/fix/122-getGroupProfile
JoongHyun-Kim Jun 3, 2024
1fd9db7
#122 fix: λ©€λ²„λ‘œ μ°Έμ—¬ 쀑인 κ·Έλ£Ή λͺ©λ‘ 쑰회 μ‹œ μ‚­μ œλœ 그룹은 μ œμ™Έν•˜λ„λ‘ μˆ˜μ •
JoongHyun-Kim Jun 3, 2024
cba99a4
Merge pull request #171 from lemonssoju/fix/122-getGroupList
JoongHyun-Kim Jun 3, 2024
99519f4
#87 fix: 퍼즐 생성 ν›„ puzzleIdx λ°˜ν™˜ν•˜λ„λ‘ μˆ˜μ •
JoongHyun-Kim Jun 3, 2024
66b24d7
Merge pull request #172 from lemonssoju/fix/87-createPuzzle
JoongHyun-Kim Jun 3, 2024
67cf9d1
#87 fix: 퍼즐 상세 쑰회 μ‹œ 앨범 생성 여뢀도 ν•¨κ»˜ λ°˜ν™˜
JoongHyun-Kim Jun 3, 2024
c5b3686
Merge pull request #173 from lemonssoju/fix/87-getPuzzleDetail
JoongHyun-Kim Jun 3, 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
6 changes: 4 additions & 2 deletions src/main/java/com/lesso/neverland/album/domain/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ public class Album extends BaseEntity {

private String albumImage;

@Column(nullable = false)
@Column(nullable = false, length = 1000)
private String content;

@OneToMany(mappedBy = "album")
private List<Comment> comments = new ArrayList<>();

@Builder
public Album(Puzzle puzzle, String content) {
public Album(Puzzle puzzle, String albumImage, Team team, String content) {
this.puzzle = puzzle;
this.albumImage = albumImage;
this.team = team;
this.content = content;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

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

import java.util.List;

public interface AlbumRepository extends JpaRepository<Album, Long> {
List<Album> findByTeamOrderByCreatedDateDesc(Team team);
boolean existsByPuzzle(Puzzle puzzle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public BaseResponse<GroupListResponse> getGroupList() {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));

List<Team> groupList_admin = groupRepository.findByAdminAndStatusEquals(user, ACTIVE);
List<Team> groupList_member = user.getUserTeams().stream().map(UserTeam::getTeam).toList();
List<Team> groupList_member = user.getUserTeams().stream()
.filter(userTeam -> "active".equals(userTeam.getStatus()))
.map(UserTeam::getTeam).toList();
List<Team> combinedGroupList = Stream.concat(groupList_admin.stream(), groupList_member.stream()).distinct().toList();

List<GroupListDto> groupListDto = combinedGroupList.stream()
Expand Down Expand Up @@ -99,7 +101,7 @@ public BaseResponse<GroupProfileResponse> getGroupProfile(Long groupIdx) {

long dayCount = ChronoUnit.DAYS.between(startLocalDate, today);

GroupProfileResponse profile = new GroupProfileResponse(group.getName(), group.getStartDate().getYear(), memberImageList,
GroupProfileResponse profile = new GroupProfileResponse(group.getName(), group.getAdmin().getProfile().getNickname(), group.getStartDate().getYear(), memberImageList,
group.getUserTeams().size(), puzzleCount, dayCount);
return new BaseResponse<>(profile);
}
Expand Down Expand Up @@ -186,6 +188,8 @@ public BaseResponse<String> withdrawGroup(Long groupIdx) {

UserTeam userTeam = validateMember(user, group);
userTeam.delete();
userTeam.removeTeam(group);
userTeam.removeUser(user);
userTeamRepository.save(userTeam);

return new BaseResponse<>(SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

public record GroupProfileResponse(String groupName,
String admin,
Integer startYear,
List<String> memberImageList, // 3개만 쑰회
Integer memberCount, // λ©€λ²„μˆ˜
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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;
import com.lesso.neverland.group.domain.Team;
Expand Down Expand Up @@ -42,8 +41,10 @@
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

import static com.lesso.neverland.common.base.BaseResponseStatus.*;
import static com.lesso.neverland.common.constants.Constants.ACTIVE;
Expand Down Expand Up @@ -101,10 +102,11 @@ public BaseResponse<PuzzleDetailResponse> getPuzzleDetail(Long groupIdx, Long pu

boolean isWriter = puzzle.getUser().equals(user);
boolean hasWrite = puzzlePieceRepository.existsByPuzzleAndUser(puzzle, user);
boolean hasAlbum = albumRepository.existsByPuzzle(puzzle);

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,
puzzle.getPuzzleDate().toString(), puzzle.getCreatedDate().toString(), puzzle.getUser().getProfile().getNickname(), puzzle.getTitle(), puzzle.getContent(),
getMemberImageList(puzzle), getMemberNicknameList(puzzle), puzzle.getPuzzleMembers().size(), puzzle.getPuzzlePieces().size()+1, isWriter, hasWrite, hasAlbum,
getPuzzlePieceList(puzzle));
return new BaseResponse<>(puzzleDetail);
}
Expand All @@ -121,15 +123,24 @@ private List<PuzzlePieceDto> getPuzzlePieceList(Puzzle puzzle) {

// puzzleMember 3λͺ…μ˜ ν”„λ‘œν•„ 이미지 쑰회
private List<String> getMemberImageList(Puzzle puzzle) {
return puzzle.getPuzzleMembers().stream()
List<String> imageList = new ArrayList<>();
imageList.add(puzzle.getUser().getProfile().getProfileImage());

List<String> memberImages = puzzle.getPuzzleMembers().stream()
.map(puzzleMember -> puzzleMember.getUser().getProfile().getProfileImage())
.limit(3)
.toList();
.limit(2).toList();
imageList.addAll(memberImages);
return imageList;
}

private List<String> getMemberNicknameList(Puzzle puzzle) {
return puzzle.getPuzzleMembers().stream()
.map(puzzleMember -> puzzleMember.getUser().getProfile().getNickname()).toList();
}

// 퍼즐 생성
@Transactional(rollbackFor = Exception.class)
public BaseResponse<String> createPuzzle(Long groupIdx, MultipartFile image, CreatePuzzleRequest createPuzzleRequest) throws IOException {
public BaseResponse<CreatePuzzleResponse> createPuzzle(Long groupIdx, MultipartFile image, CreatePuzzleRequest createPuzzleRequest) throws IOException {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
User writer = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));

Expand All @@ -139,7 +150,7 @@ public BaseResponse<String> createPuzzle(Long groupIdx, MultipartFile image, Cre
Puzzle newPuzzle = createPuzzle(createPuzzleRequest, group, writer, imagePath, puzzleDate);
addPuzzleMember(createPuzzleRequest, newPuzzle);

return new BaseResponse<>(SUCCESS);
return new BaseResponse<>(new CreatePuzzleResponse(newPuzzle.getPuzzleIdx()));
}

// Puzzle 생성 μ‹œ PuzzleMember entity ν•¨κ»˜ 생성
Expand Down Expand Up @@ -278,18 +289,24 @@ private void validatePuzzler(User user, Puzzle puzzle) {

// [μž‘μ„±μž] 퍼즐 μ™„μ„±ν•˜κΈ°
@Transactional(rollbackFor = Exception.class)
public BaseResponse<CompletePuzzleResponse> completePuzzle(Long groupIdx, Long puzzleIdx, CompletePuzzleRequest completePuzzleRequest) {
public BaseResponse<CompletePuzzleResponse> completePuzzle(Long groupIdx, Long puzzleIdx) {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
Puzzle puzzle = puzzleRepository.findById(puzzleIdx).orElseThrow(() -> new BaseException(INVALID_PUZZLE_IDX));
validateWriter(user, puzzle);

List<String> puzzleTextList = puzzle.getPuzzlePieces().stream()
.map(PuzzlePiece::getContent).collect(Collectors.toList());
puzzleTextList.add(puzzle.getContent());

// GPT μš”μ•½ μˆ˜ν–‰
GptResponse response = gptService.completion(gptService.toText(completePuzzleRequest.puzzleTextList()));
GptResponse response = gptService.completion(gptService.toText(puzzleTextList));
GptResponseDto gptResponseDto = gptService.parseResponse(response.messages().get(0).message());

// Album 생성
Album newAlbum = Album.builder()
.puzzle(puzzle)
.albumImage("")
.team(puzzle.getTeam())
.content(gptResponseDto.description()).build();
albumRepository.save(newAlbum);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.lesso.neverland.puzzle.dto;

public record CreatePuzzleResponse(Long puzzleIdx) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
public record PuzzleDetailResponse(String location,
String puzzleImage,
String puzzleDate,
String createdDate,
String writer,
String title,
String content,
List<String> memberImageList, // 3λͺ…λ§Œ
List<String> memberNicknameList,
Integer memberCount,
Integer writeCount, // PuzzlePieceCount+1
boolean isWriter,
boolean hasWrite, // ν•΄λ‹Ή userκ°€ νΌμ¦ν”ΌμŠ€ μž‘μ„±ν–ˆλŠ”μ§€ μ—¬λΆ€
boolean hasAlbum,
List<PuzzlePieceDto> puzzlePieces) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.lesso.neverland.common.base.BaseException;
import com.lesso.neverland.common.base.BaseResponse;
import com.lesso.neverland.gpt.application.GptService;
import com.lesso.neverland.puzzle.dto.CompletePuzzleRequest;
import com.lesso.neverland.puzzle.dto.CompletePuzzleResponse;
import com.lesso.neverland.group.dto.GroupPuzzleListResponse;
import com.lesso.neverland.puzzle.application.PuzzleService;
Expand All @@ -22,7 +20,6 @@
@RequestMapping(puzzle)
public class PuzzleController {
private final PuzzleService puzzleService;
private final GptService gptService;

// 퍼즐 λͺ©λ‘ 쑰회
@GetMapping("")
Expand All @@ -38,7 +35,7 @@ public BaseResponse<PuzzleDetailResponse> getPuzzleDetail(@PathVariable("groupId

// 퍼즐 생성
@PostMapping("")
public BaseResponse<String> createPuzzle(@PathVariable Long groupIdx, @RequestPart MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) {
public BaseResponse<CreatePuzzleResponse> createPuzzle(@PathVariable Long groupIdx, @RequestPart MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) {
try {
return puzzleService.createPuzzle(groupIdx, image, createPuzzleRequest);
} catch (IOException e) {
Expand Down Expand Up @@ -72,11 +69,8 @@ public BaseResponse<String> addPuzzlePiece(@PathVariable("groupIdx") Long groupI

// [μž‘μ„±μž] 퍼즐 μ™„μ„±ν•˜κΈ°
@PostMapping("/{puzzleIdx}")
public BaseResponse<CompletePuzzleResponse> completePuzzle(@PathVariable("groupIdx") Long groupIdx,
@PathVariable("puzzleIdx") Long puzzleIdx,
@RequestBody CompletePuzzleRequest completePuzzleRequest)
{
return puzzleService.completePuzzle(groupIdx, puzzleIdx, completePuzzleRequest);
public BaseResponse<CompletePuzzleResponse> completePuzzle(@PathVariable("groupIdx") Long groupIdx, @PathVariable("puzzleIdx") Long puzzleIdx) {
return puzzleService.completePuzzle(groupIdx, puzzleIdx);
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/lesso/neverland/user/domain/UserTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public void setTeam(Team team) {
team.getUserTeams().add(this);
}

public void removeUser(User user) {
this.user = user;
user.getUserTeams().remove(this);
}

public void removeTeam(Team team) {
this.team = team;
team.getUserTeams().remove(this);
}

@Builder
public UserTeam(User user, Team team) {
this.user = user;
Expand Down
Loading