-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: 대문자 연속 허용하도록 수정 * refactor: 세부 구현 코드 캡슐화 * feat: PICK-O 프렌즈 생성 API 개발 * feat: PICK-O 프렌즈 이미지 목록 조회 API 개발 * style: 사용되지 않는 import문 제거 * chore: swagger dto description 수정 Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: swagger 메서드 description 변경 Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * refactor: 기본 생성자 접근제어자를 private으로 변경 * fix: 메서드 네이밍 수정 * fix: 누락된 메서드 추가 --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4407085
commit e6410df
Showing
10 changed files
with
218 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/balancetalk/friends/application/FriendsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package balancetalk.friends.application; | ||
|
||
import static balancetalk.friends.dto.FriendsDto.FriendsImageResponse; | ||
|
||
import balancetalk.file.domain.File; | ||
import balancetalk.file.domain.FileHandler; | ||
import balancetalk.file.domain.FileType; | ||
import balancetalk.file.domain.repository.FileRepository; | ||
import balancetalk.friends.domain.Friends; | ||
import balancetalk.friends.domain.FriendsRepository; | ||
import balancetalk.friends.dto.FriendsDto.CreateFriendsRequest; | ||
import balancetalk.global.exception.BalanceTalkException; | ||
import balancetalk.global.exception.ErrorCode; | ||
import balancetalk.member.domain.Member; | ||
import balancetalk.member.domain.MemberRepository; | ||
import balancetalk.member.dto.ApiMember; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FriendsService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final FriendsRepository friendsRepository; | ||
private final FileRepository fileRepository; | ||
private final FileHandler fileHandler; | ||
|
||
@Transactional | ||
public void createFriends(CreateFriendsRequest request, ApiMember apiMember) { | ||
Member member = apiMember.toMember(memberRepository); | ||
if (member.isRoleUser()) { | ||
throw new BalanceTalkException(ErrorCode.FORBIDDEN_PICK_O_FRIENDS_OPERATION); | ||
} | ||
Friends savedFriends = friendsRepository.save(request.toEntity()); | ||
|
||
File file = fileRepository.findById(request.getImgId()) | ||
.orElseThrow(() -> new BalanceTalkException(ErrorCode.NOT_FOUND_FILE)); | ||
fileHandler.relocateFile(file, savedFriends.getId(), FileType.FRIENDS); | ||
} | ||
|
||
public List<FriendsImageResponse> findAllFriendsImages() { | ||
return fileRepository.findAllById(getFriendsImgIds()) | ||
.stream() | ||
.map(FriendsImageResponse::from) | ||
.toList(); | ||
} | ||
|
||
private List<Long> getFriendsImgIds() { | ||
return friendsRepository.findAll() | ||
.stream() | ||
.map(Friends::getImgId) | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package balancetalk.friends.domain; | ||
|
||
import balancetalk.global.common.BaseTimeEntity; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Friends extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotBlank | ||
private String name; | ||
|
||
@NotNull | ||
private Long imgId; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/balancetalk/friends/domain/FriendsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package balancetalk.friends.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FriendsRepository extends JpaRepository<Friends, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package balancetalk.friends.dto; | ||
|
||
import balancetalk.file.domain.File; | ||
import balancetalk.friends.domain.Friends; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class FriendsDto { | ||
|
||
@Schema(description = "PICK-O 프렌즈 캐릭터 생성 요청") | ||
@Data | ||
@AllArgsConstructor | ||
public static class CreateFriendsRequest { | ||
|
||
@Schema(description = "프렌즈 이름", example = "꺼북이") | ||
@NotBlank(message = "프렌즈 이름은 필수입니다.") | ||
private String name; | ||
|
||
@Schema(description = "첨부한 이미지 파일 ID", example = "41") | ||
@NotNull(message = "프렌즈 이미지 ID는 필수입니다.") | ||
private Long imgId; | ||
|
||
public Friends toEntity() { | ||
return Friends.builder() | ||
.name(name) | ||
.imgId(imgId) | ||
.build(); | ||
} | ||
} | ||
|
||
@Schema(description = "PICK-O 프렌즈 이미지 응답") | ||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public static class FriendsImageResponse { | ||
|
||
@Schema(description = "프렌즈 이미지 파일 ID", example = "3") | ||
private Long fileId; | ||
|
||
@Schema(description = "프렌즈 이미지 URL", | ||
example = "https://picko-image.amazonaws.com/friends/ad80-a94e08-3301d2_대해파리.png") | ||
private String imgUrl; | ||
|
||
public static FriendsImageResponse from(File file) { | ||
return FriendsImageResponse.builder() | ||
.fileId(file.getId()) | ||
.imgUrl(file.getImgUrl()) | ||
.build(); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/balancetalk/friends/presentation/FriendsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package balancetalk.friends.presentation; | ||
|
||
import static balancetalk.friends.dto.FriendsDto.FriendsImageResponse; | ||
|
||
import balancetalk.friends.application.FriendsService; | ||
import balancetalk.friends.dto.FriendsDto.CreateFriendsRequest; | ||
import balancetalk.global.utils.AuthPrincipal; | ||
import balancetalk.member.dto.ApiMember; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/friends") | ||
@Tag(name = "friends", description = "PICK-O 프렌즈 API") | ||
public class FriendsController { | ||
|
||
private final FriendsService friendsService; | ||
|
||
@Operation(summary = "PICK-O 프렌즈 캐릭터 생성", description = "PICK-O 프렌즈 캐릭터를 생성합니다.") | ||
@PostMapping | ||
public void createCharacter(@RequestBody final CreateFriendsRequest request, | ||
@Parameter(hidden = true) @AuthPrincipal final ApiMember apiMember) { | ||
friendsService.createFriends(request, apiMember); | ||
} | ||
|
||
@Operation(summary = "PICK-O 프렌즈 이미지 목록 조회", description = "PICK-O 프렌즈 이미지 목록을 조회합니다.") | ||
@GetMapping("/images") | ||
public List<FriendsImageResponse> findAllFriendsImages() { | ||
return friendsService.findAllFriendsImages(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters