Skip to content

Commit

Permalink
Merge pull request #149 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 29, 2024
2 parents 736bf93 + 458b132 commit ad9bee9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public BaseResponse<String> withdrawGroup(Long groupIdx) {

// 그룹 생성
@Transactional(rollbackFor = Exception.class)
public BaseResponse<String> createGroup(MultipartFile image, CreateGroupRequest createGroupRequest) throws IOException {
public BaseResponse<CreateGroupResponse> createGroup(MultipartFile image, CreateGroupRequest createGroupRequest) throws IOException {
User admin = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));

// upload image
Expand All @@ -192,14 +192,8 @@ public BaseResponse<String> createGroup(MultipartFile image, CreateGroupRequest
newUserTeam.setTeam(group);
userTeamRepository.save(newUserTeam);

// for (Long memberIdx : createGroupRequest.memberList()) {
// User member = userRepository.findById(memberIdx).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
// UserTeam userTeam = new UserTeam(member, group);
// userTeam.setUser(member);
// userTeam.setTeam(group);
// userTeamRepository.save(userTeam);
// }
return new BaseResponse<>(SUCCESS);
CreateGroupResponse createGroupResponse = new CreateGroupResponse(joinCode);
return new BaseResponse<>(createGroupResponse);
}

// [관리자] 그룹 초대하기
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lesso.neverland.group.dto;

public record CreateGroupResponse(Integer joinCode) {}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public BaseResponse<String> withdrawGroup(@PathVariable Long groupIdx) {

// 그룹 생성
@PostMapping("/create")
public BaseResponse<String> createGroup(@RequestPart MultipartFile image, @RequestPart CreateGroupRequest createGroupRequest) {
public BaseResponse<CreateGroupResponse> createGroup(@RequestPart MultipartFile image, @RequestPart CreateGroupRequest createGroupRequest) {
try {
return groupService.createGroup(image, createGroupRequest);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ private static List<GroupPuzzleDto> getGroupPuzzleDtos(List<Puzzle> groupPuzzleL
// 퍼즐 상세 조회
public BaseResponse<PuzzleDetailResponse> getPuzzleDetail(Long groupIdx, Long puzzleIdx) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
Puzzle puzzle = puzzleRepository.findById(puzzleIdx).orElseThrow(() -> new BaseException(INVALID_PUZZLE_IDX));

if (!puzzle.getTeam().equals(group)) throw new BaseException(NO_GROUP_PUZZLE);
if (puzzle.getStatus().equals(INACTIVE)) throw new BaseException(ALREADY_DELETED_PUZZLE);

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

PuzzleDetailResponse puzzleDetail = new PuzzleDetailResponse(puzzle.getLocation(), puzzle.getPuzzleImage(),
puzzle.getPuzzleDate().toString(), puzzle.getUser().getProfile().getNickname(), puzzle.getTitle(), puzzle.getContent(),
getMemberImageList(puzzle), puzzle.getPuzzleMembers().size(), getPuzzlePieceList(puzzle));
getMemberImageList(puzzle), puzzle.getPuzzleMembers().size(), puzzle.getPuzzlePieces().size()+1, isWriter, hasWrite,
getPuzzlePieceList(puzzle));
return new BaseResponse<>(puzzleDetail);
}

Expand Down Expand Up @@ -160,13 +166,12 @@ private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group,
}

// [작성자] 퍼즐 수정
public BaseResponse<String> editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile image, EditPuzzleRequest editPuzzleRequest) {
public BaseResponse<String> editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile newImage, EditPuzzleRequest editPuzzleRequest) {
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);



return new BaseResponse<>(SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ public record PuzzleDetailResponse(String location,
String content,
List<String> memberImageList, // 3명만
Integer memberCount,
Integer writeCount, // PuzzlePieceCount+1
boolean isWriter,
boolean hasWrite, // 해당 user가 퍼즐피스 작성했는지 여부
List<PuzzlePieceDto> puzzlePieces) {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.lesso.neverland.puzzle.repository;

import com.lesso.neverland.puzzle.domain.Puzzle;
import com.lesso.neverland.puzzle.domain.PuzzlePiece;
import com.lesso.neverland.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PuzzlePieceRepository extends JpaRepository<PuzzlePiece, Long> {
boolean existsByPuzzleAndUser(Puzzle puzzle, User user);
}

0 comments on commit ad9bee9

Please sign in to comment.