-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
photo-service/src/main/java/kr/mafoo/photo/api/AlbumAdminApi.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,80 @@ | ||
package kr.mafoo.photo.api; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import kr.mafoo.photo.annotation.RequestMemberId; | ||
import kr.mafoo.photo.annotation.ULID; | ||
import kr.mafoo.photo.controller.dto.request.AlbumCreateRequest; | ||
import kr.mafoo.photo.controller.dto.request.AlbumUpdateDisplayIndexRequest; | ||
import kr.mafoo.photo.controller.dto.request.AlbumUpdateRequest; | ||
import kr.mafoo.photo.controller.dto.response.AlbumRawResponse; | ||
import kr.mafoo.photo.controller.dto.response.AlbumResponse; | ||
import kr.mafoo.photo.controller.dto.response.PageResponse; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Validated | ||
@Tag(name = "앨범 어드민 관련 API", description = "앨범 조회, 생성, 수정, 삭제 등 API") | ||
@RequestMapping("/v1/admin/albums") | ||
public interface AlbumAdminApi { | ||
@Operation(summary = "앨범 n건 조회", description = "앨범 목록을 조회합니다.") | ||
@GetMapping | ||
Mono<PageResponse<AlbumRawResponse>> queryAlbums( | ||
@Parameter(description = "페이지 번호", example = "1") | ||
@RequestParam(defaultValue = "1") | ||
int page, | ||
|
||
@Parameter(description = "페이지 크기", example = "10") | ||
@RequestParam(defaultValue = "10") | ||
int size, | ||
|
||
@RequestParam(required = false) | ||
String name, | ||
|
||
@RequestParam(required = false) | ||
String type, | ||
|
||
@RequestParam(required = false) | ||
String ownerMemberId | ||
); | ||
|
||
// @Operation(summary = "앨범 생성", description = "앨범을 생성합니다.") | ||
// @PostMapping | ||
// Mono<AlbumResponse> createAlbum( | ||
// @Valid | ||
// @RequestBody | ||
// AlbumCreateRequest request | ||
// ); | ||
// | ||
// @Operation(summary = "앨범 변경", description = "앨범의 속성을 변경합니다.") | ||
// @PutMapping("/{albumId}") | ||
// Mono<AlbumResponse> updateAlbum( | ||
// @RequestMemberId | ||
// String memberId, | ||
// | ||
// @ULID | ||
// @Parameter(description = "앨범 ID", example = "test_album_id") | ||
// @PathVariable | ||
// String albumId, | ||
// | ||
// @Valid | ||
// @RequestBody | ||
// AlbumUpdateRequest request | ||
// ); | ||
// | ||
// @Operation(summary = "앨범 삭제", description = "앨범을 삭제합니다.") | ||
// @DeleteMapping("/{albumId}") | ||
// Mono<Void> deleteAlbum( | ||
// @RequestMemberId | ||
// String memberId, | ||
// | ||
// @ULID | ||
// @Parameter(description = "앨범 ID", example = "test_album_id") | ||
// @PathVariable | ||
// String albumId | ||
// ); | ||
} |
22 changes: 22 additions & 0 deletions
22
photo-service/src/main/java/kr/mafoo/photo/controller/AlbumAdminController.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,22 @@ | ||
package kr.mafoo.photo.controller; | ||
|
||
import kr.mafoo.photo.api.AlbumAdminApi; | ||
import kr.mafoo.photo.controller.dto.response.AlbumRawResponse; | ||
import kr.mafoo.photo.controller.dto.response.PageResponse; | ||
import kr.mafoo.photo.service.AlbumAdminService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class AlbumAdminController implements AlbumAdminApi { | ||
private final AlbumAdminService albumAdminService; | ||
|
||
@Override | ||
public Mono<PageResponse<AlbumRawResponse>> queryAlbums(int page, int size, String name, String type, String ownerMemberId) { | ||
return albumAdminService | ||
.queryAlbums(page, size, name, type, ownerMemberId) | ||
.map(pageResponse -> pageResponse.map(AlbumRawResponse::fromEntity)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/AlbumRawResponse.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,41 @@ | ||
package kr.mafoo.photo.controller.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import kr.mafoo.photo.domain.AlbumEntity; | ||
import kr.mafoo.photo.domain.AlbumType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Schema(description = "앨범 응답") | ||
public record AlbumRawResponse( | ||
@Schema(description = "앨범 ID", example = "test_album_id") | ||
String albumId, | ||
|
||
@Schema(description = "앨범 이름", example = "야뿌들") | ||
String name, | ||
|
||
@Schema(description = "앨범 종류", example = "TYPE_B") | ||
AlbumType type, | ||
|
||
@Schema(description = "앨범 내 사진 수", example = "6") | ||
String photoCount, | ||
|
||
@Schema(description = "앨범 주인 ID", example = "6") | ||
String ownerMemberId, | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") | ||
@Schema(description = "생성 시간", example = "2021-08-01 00:00:00") | ||
LocalDateTime createdAt | ||
) { | ||
public static AlbumRawResponse fromEntity(AlbumEntity entity) { | ||
return new AlbumRawResponse( | ||
entity.getAlbumId(), | ||
entity.getName(), | ||
entity.getType(), | ||
entity.getPhotoCount().toString(), | ||
entity.getOwnerMemberId(), | ||
entity.getCreatedAt() | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PageResponse.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,20 @@ | ||
package kr.mafoo.photo.controller.dto.response; | ||
|
||
import java.util.Collection; | ||
import java.util.function.Function; | ||
|
||
public record PageResponse<T>( | ||
Collection<T> results, | ||
Integer page, | ||
Integer size, | ||
Integer totalElement | ||
) { | ||
public <R> PageResponse<R> map(Function<T, R> mapper) { | ||
return new PageResponse<>( | ||
results.stream().map(mapper).toList(), | ||
page, | ||
size, | ||
totalElement | ||
); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
photo-service/src/main/java/kr/mafoo/photo/service/AlbumAdminService.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 kr.mafoo.photo.service; | ||
|
||
import kr.mafoo.photo.controller.dto.response.PageResponse; | ||
import kr.mafoo.photo.domain.AlbumEntity; | ||
import kr.mafoo.photo.domain.AlbumType; | ||
import kr.mafoo.photo.repository.AlbumRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AlbumAdminService { | ||
private final AlbumRepository albumRepository; | ||
|
||
public Mono<PageResponse<AlbumEntity>> queryAlbums(int page, int size, String name, String type, String ownerMemberId) { | ||
Flux<AlbumEntity> publisher; | ||
if(name != null) { | ||
publisher = albumRepository.findAllByNameOrderByAlbumIdDesc(name, PageRequest.of(page, size)); | ||
} else if(type != null) { | ||
AlbumType albumType; | ||
try { | ||
albumType = AlbumType.valueOf(type); | ||
publisher = albumRepository.findAllByTypeOrderByAlbumIdDesc(albumType, PageRequest.of(page, size)); | ||
} catch (IllegalArgumentException e) { | ||
publisher = albumRepository.findAllByOrderByAlbumIdDesc(PageRequest.of(page, size)); | ||
} | ||
} else if(ownerMemberId != null) { | ||
publisher = albumRepository.findAllByOwnerMemberIdOrderByAlbumIdDesc(ownerMemberId, PageRequest.of(page, size)); | ||
} else { | ||
publisher = albumRepository.findAllByOrderByAlbumIdDesc(PageRequest.of(page, size)); | ||
} | ||
return publisher | ||
.collectList() | ||
.zipWith(albumRepository.count()) | ||
.map(tuple -> new PageResponse<>(tuple.getT1(), page, size, tuple.getT2().intValue())); | ||
} | ||
} |