Skip to content

Commit

Permalink
Merge pull request #146 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 a5be896 + 0b05c0e commit 736bf93
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.repository.AlbumRepository;
import com.lesso.neverland.comment.dto.CommentDto;
import com.lesso.neverland.common.base.BaseException;
import com.lesso.neverland.common.base.BaseResponse;
import com.lesso.neverland.group.domain.Team;
import com.lesso.neverland.group.repository.GroupRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;

import static com.lesso.neverland.common.base.BaseResponseStatus.*;

@Service
@RequiredArgsConstructor
public class AlbumService {
private final GroupRepository groupRepository;
private final AlbumRepository albumRepository;

// 추억 이미지 등록
public BaseResponse<String> uploadAlbumImage(Long groupIdx, Long albumIdx, AlbumImageRequest albumImageRequest) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
Album album = albumRepository.findById(albumIdx).orElseThrow(() -> new BaseException(INVALID_ALBUM_IDX));
if (!album.getPuzzle().getTeam().equals(group)) throw new BaseException(NO_GROUP_ALBUM);

album.saveAlbumImage(albumImageRequest.albumImage());
albumRepository.save(album);

return new BaseResponse<>(SUCCESS);
}

// 앨범 상세 조회
public BaseResponse<AlbumDetailResponse> getAlbumDetail(Long groupIdx, Long albumIdx) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
Album album = albumRepository.findById(albumIdx).orElseThrow(() -> new BaseException(INVALID_ALBUM_IDX));
if (!album.getPuzzle().getTeam().equals(group)) throw new BaseException(NO_GROUP_ALBUM);

List<String> memberList = album.getPuzzle().getPuzzleMembers().stream()
.map(puzzleMember -> puzzleMember.getUser().getProfile().getNickname()).toList();

List<CommentDto> commentList = album.getComments().stream()
.map(comment -> new CommentDto(
comment.getCommentIdx(),
comment.getUser().getProfile().getNickname(),
comment.getUser().getProfile().getProfileImage(),
comment.getCreatedDate().toString(),
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);
return new BaseResponse<>(albumDetailResponse);
}
}
4 changes: 4 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 @@ -39,4 +39,8 @@ public Album(Puzzle puzzle, String content) {
this.puzzle = puzzle;
this.content = content;
}

public void saveAlbumImage(String albumImage) {
this.albumImage = albumImage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.lesso.neverland.album.dto;

import com.lesso.neverland.comment.dto.CommentDto;

import java.util.List;

public record AlbumDetailResponse(String title,
String puzzleDate,
String location,
List<String> memberList,
String albumImage,
String description,
Long puzzleIdx,
List<CommentDto> commentList) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lesso.neverland.album.dto;

public record AlbumImageRequest(String albumImage) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.lesso.neverland.album.presentation;

import com.lesso.neverland.album.application.AlbumService;
import com.lesso.neverland.album.dto.AlbumDetailResponse;
import com.lesso.neverland.album.dto.AlbumImageRequest;
import com.lesso.neverland.common.base.BaseResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import static com.lesso.neverland.common.constants.RequestURI.album;

@RestController
@RequiredArgsConstructor
@RequestMapping(album)
public class AlbumController {

private final AlbumService albumService;

// 추억 이미지 등록
@PostMapping("/{albumIdx}/image")
public BaseResponse<String> uploadAlbumImage(@PathVariable("groupIdx") Long groupIdx, @PathVariable("albumIdx") Long albumIdx, @RequestBody AlbumImageRequest albumImageRequest) {
return albumService.uploadAlbumImage(groupIdx, albumIdx, albumImageRequest);
}

// 앨범 상세 조회
@GetMapping("/{albumIdx}")
public BaseResponse<AlbumDetailResponse> getAlbumDetail(@PathVariable("groupIdx") Long groupIdx, @PathVariable("albumIdx") Long albumIdx) {
return albumService.getAlbumDetail(groupIdx, albumIdx);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.lesso.neverland.comment.dto;

import java.time.LocalDate;

public record CommentDto(Long commentIdx,
String writer,
String profileImage,
LocalDate createdDate,
String createdDate,
String content) {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum BaseResponseStatus {
/**
* 2000: Request 오류
*/
// user(2000-2049)
// user
INVALID_USER_IDX(false, HttpStatus.BAD_REQUEST, "잘못된 user idx 입니다."),
INVALID_PASSWORD(false, HttpStatus.BAD_REQUEST, "형식이 잘못된 비밀번호입니다."),
NO_MATCH_USER(false, HttpStatus.BAD_REQUEST, "일치하는 user가 없습니다."),
Expand All @@ -33,24 +33,18 @@ public enum BaseResponseStatus {
DUPLICATED_NICKNAME(false, HttpStatus.CONFLICT, "중복된 닉네임입니다."),
DUPLICATED_LOGIN_ID(false, HttpStatus.CONFLICT, "중복된 아이디입니다."),


// userprofile(2050-2099)
// userprofile
BLANK_NICKNAME(false, HttpStatus.BAD_REQUEST, "nickname이 비었습니다."),


// interest(2100-2199)
WRONG_CONTENTS_NAME(false, HttpStatus.BAD_REQUEST, "콘텐츠 이름이 잘못되었습니다."),
WRONG_PREFERENCE_NAME(false, HttpStatus.BAD_REQUEST, "취향 이름이 잘못되었습니다."),

// puzzle(2200-2299)
// puzzle
INVALID_PUZZLE_IDX(false, HttpStatus.BAD_REQUEST, "잘못된 puzzle idx 입니다."),
NO_PUZZLE_WRITER(false, HttpStatus.BAD_REQUEST, "해당 post의 작성자가 아닙니다."),
ALREADY_DELETED_PUZZLE(false, HttpStatus.CONFLICT, "이미 삭제된 puzzle 입니다."),
NO_PUZZLER(false, HttpStatus.FORBIDDEN, "해당 퍼즐의 퍼즐러가 아닙니다."),
TOO_LONG_CONTENT(false, HttpStatus.BAD_REQUEST, "퍼즐피스의 길이는 100자 이하여야 합니다."),


// group(2300-2399)
// group
INVALID_GROUP_IDX(false, HttpStatus.BAD_REQUEST, "잘못된 group idx 입니다."),
NO_GROUP_PUZZLE(false, HttpStatus.BAD_REQUEST, "이 글은 해당 그룹의 글이 아닙니다."),
BLANK_GROUP_NAME(false, HttpStatus.BAD_REQUEST, "그룹명이 비었습니다."),
Expand All @@ -63,29 +57,30 @@ public enum BaseResponseStatus {
BLANK_GROUP_START_DATE(false, HttpStatus.BAD_REQUEST, "시작 일자가 비었습니다."),
NO_MATCH_GROUP(false, HttpStatus.BAD_REQUEST, "참여 코드와 일치하는 그룹이 없습니다."),

// image(2400-2499)
// image
IMAGE_DELETE_FAIL(false, HttpStatus.CONFLICT, "이미지 삭제에 실패했습니다."),
IMAGE_UPLOAD_FAIL(false, HttpStatus.CONFLICT, "이미지 업로드에 실패했습니다."),

// comment(2500-2599)
// comment
INVALID_COMMENT_IDX(false, HttpStatus.BAD_REQUEST, "잘못된 comment idx 입니다."),
BLANK_COMMENT_CONTENT(false, HttpStatus.BAD_REQUEST, "댓글 내용이 비었습니다."),
NO_COMMENT_WRITER(false, HttpStatus.FORBIDDEN, "댓글 작성자가 아닙니다."),
ALREADY_DELETED_COMMENT(false, HttpStatus.CONFLICT, "이미 삭제된 댓글입니다."),

// album(2500-2599)
// album
INVALID_ALBUM_IDX(false, HttpStatus.BAD_REQUEST, "잘못된 album idx 입니다."),
NO_GROUP_ALBUM(false, HttpStatus.CONFLICT, "해당 그룹의 앨범이 아닙니다."),


/**
* 3000: Response 오류
* Response 오류
*/
// user(3000-3099)
// user
INVALID_NICKNAME(false, HttpStatus.BAD_REQUEST, "해당 닉네임으로 유저를 찾을 수 없습니다."),


/**
* 4000: DB, Server 오류
* DB, Server 오류
*/
DATABASE_ERROR(false, HttpStatus.INTERNAL_SERVER_ERROR, "데이터베이스 연결에 실패했습니다."),
DUPLICATE_RESOURCE(false, HttpStatus.CONFLICT, "데이터가 이미 존재합니다");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class RequestURI {
public final static String group = "/groups";
public final static String puzzle = "/groups/{groupIdx}/puzzles";
public final static String comment = "/comments";
public final static String album = "/groups/{groupIdx}/albums";
}
52 changes: 0 additions & 52 deletions src/main/java/com/lesso/neverland/common/enums/Contents.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public BaseResponse<String> createPuzzle(@PathVariable Long groupIdx, @RequestPa

// [작성자] 퍼즐 수정
@GetMapping("/{puzzleIdx}/edit")
public BaseResponse<String> editPuzzle(@PathVariable("groupIdx") Long groupIdx, @PathVariable("puzzleIdx") Long puzzleIdx, @RequestPart MultipartFile image, @RequestPart EditPuzzleRequest editPuzzleRequest) {
return puzzleService.editPuzzle(groupIdx, puzzleIdx, image, editPuzzleRequest);
public BaseResponse<String> editPuzzle(@PathVariable("groupIdx") Long groupIdx, @PathVariable("puzzleIdx") Long puzzleIdx, @RequestPart MultipartFile newImage, @RequestPart EditPuzzleRequest editPuzzleRequest) {
return puzzleService.editPuzzle(groupIdx, puzzleIdx, newImage, editPuzzleRequest);
}

// [작성자] 퍼즐 삭제
Expand All @@ -71,7 +71,7 @@ public BaseResponse<String> addPuzzlePiece(@PathVariable("groupIdx") Long groupI
}

// [작성자] 퍼즐 완성하기
@PostMapping("/{puzzleIdx}}")
@PostMapping("/{puzzleIdx}")
public BaseResponse<CompletePuzzleResponse> completePuzzle(@PathVariable("groupIdx") Long groupIdx,
@PathVariable("puzzleIdx") Long puzzleIdx,
@RequestBody CompletePuzzleRequest completePuzzleRequest)
Expand Down

0 comments on commit 736bf93

Please sign in to comment.