-
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
13 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/main/java/org/ioteatime/meonghanyangserver/common/type/ImageSuccessType.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
21 changes: 21 additions & 0 deletions
21
src/main/java/org/ioteatime/meonghanyangserver/image/controller/ImageApi.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,21 @@ | ||
package org.ioteatime.meonghanyangserver.image.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.ioteatime.meonghanyangserver.common.api.Api; | ||
import org.ioteatime.meonghanyangserver.common.utils.LoginMember; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.GroupDateImageResponse; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Tag(name = "Image Api", description = "Image 관련 API 목록입니다.") | ||
public interface ImageApi { | ||
@Operation( | ||
summary = "회원이 속한 그룹의 날짜별 객체 탐지 이미지 목록을 최근 시간 순서대로 조회합니다.", | ||
description = | ||
"담당자: 양원채\n\n달력의 날짜를 클릭했을 때 해당 날짜의 이미지 목록을 조회할 떄 사용합니다.\n\nURL QueryParameter로 날짜를 담아 요청 주시면 됩니다.") | ||
Api<GroupDateImageResponse> groupDateImageList( | ||
@LoginMember Long memberId, | ||
@RequestParam("year") Short year, | ||
@RequestParam("month") Byte month, | ||
@RequestParam("day") Byte day); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/ioteatime/meonghanyangserver/image/controller/ImageController.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,35 @@ | ||
package org.ioteatime.meonghanyangserver.image.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.ioteatime.meonghanyangserver.common.api.Api; | ||
import org.ioteatime.meonghanyangserver.common.type.ImageSuccessType; | ||
import org.ioteatime.meonghanyangserver.common.utils.LoginMember; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.GroupDateImageResponse; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.ImageSaveUrlResponse; | ||
import org.ioteatime.meonghanyangserver.image.service.ImageService; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/image") | ||
public class ImageController implements ImageApi { | ||
private final ImageService imageService; | ||
|
||
@GetMapping | ||
public Api<GroupDateImageResponse> groupDateImageList( | ||
@LoginMember Long memberId, | ||
@RequestParam("year") Short year, | ||
@RequestParam("month") Byte month, | ||
@RequestParam("day") Byte day) { | ||
GroupDateImageResponse response = | ||
imageService.findAllByMemberIdAndDate(memberId, year, month, day); | ||
return Api.success(ImageSuccessType.GET_LIST_OF_DATE, response); | ||
} | ||
|
||
@GetMapping("/{fileName}") | ||
public Api<ImageSaveUrlResponse> getImageSaveUrl( | ||
@LoginMember Long cctvId, @PathVariable String fileName) { | ||
ImageSaveUrlResponse imageSaveUrlResponse = imageService.getImageSaveUrl(cctvId, fileName); | ||
return Api.success(ImageSuccessType.CREATE_PRESIGNED_URL, imageSaveUrlResponse); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
...main/java/org/ioteatime/meonghanyangserver/image/dto/response/GroupDateImageResponse.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,8 @@ | ||
package org.ioteatime.meonghanyangserver.image.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
|
||
@Schema(description = "날짜에 해당하는 그룹의 이미지 목록 응답") | ||
public record GroupDateImageResponse( | ||
@Schema(description = "날짜에 해당하는 그룹의 이미지 목록") List<ImageResponse> images) {} |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/ioteatime/meonghanyangserver/image/dto/response/ImageResponse.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,42 @@ | ||
package org.ioteatime.meonghanyangserver.image.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Schema(description = "이미지 단일 응답") | ||
public class ImageResponse { | ||
@NotNull | ||
@Schema(description = "이미지 ID", example = "1") | ||
private final Long imageId; | ||
|
||
@NotNull | ||
@Schema(description = "이미지 원본 이름", example = "test-image.jpg") | ||
private final String imageName; | ||
|
||
@NotNull | ||
@Schema( | ||
description = "이미지 URL", | ||
example = "https://bucket.s3.ap-northeast-2.amazonaws.com/path/to/test-image.jpg") | ||
private String imagePath; | ||
|
||
@NotNull | ||
@Schema(description = "형식이 있는 이미지 생성 시각", example = "2024.10.22.13:00") | ||
private final String formattedCreatedAt; | ||
|
||
@Builder | ||
public ImageResponse( | ||
Long imageId, String imageName, String imagePath, String formattedCreatedAt) { | ||
this.imageId = imageId; | ||
this.imageName = imageName; | ||
this.imagePath = imagePath; | ||
this.formattedCreatedAt = formattedCreatedAt; | ||
} | ||
|
||
public ImageResponse updateToPresignedUrl(String imagePresignedPath) { | ||
this.imagePath = imagePresignedPath; | ||
return this; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/ioteatime/meonghanyangserver/image/mapper/ImageResponseMapper.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
6 changes: 6 additions & 0 deletions
6
src/main/java/org/ioteatime/meonghanyangserver/image/repository/ImageJpaRepository.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 org.ioteatime.meonghanyangserver.image.repository; | ||
|
||
import org.ioteatime.meonghanyangserver.image.domain.ImageEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ImageJpaRepository extends JpaRepository<ImageEntity, Long> {} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/ioteatime/meonghanyangserver/image/repository/ImageRepository.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,9 @@ | ||
package org.ioteatime.meonghanyangserver.image.repository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.ImageResponse; | ||
|
||
public interface ImageRepository { | ||
List<ImageResponse> findAllByGroupIdAndDate(Long groupId, LocalDateTime searchDate); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/org/ioteatime/meonghanyangserver/image/repository/ImageRepositoryImpl.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,50 @@ | ||
package org.ioteatime.meonghanyangserver.image.repository; | ||
|
||
import static org.ioteatime.meonghanyangserver.group.domain.QGroupEntity.groupEntity; | ||
import static org.ioteatime.meonghanyangserver.image.domain.QImageEntity.imageEntity; | ||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.ImageResponse; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ImageRepositoryImpl implements ImageRepository { | ||
private final JPAQueryFactory queryFactory; | ||
private final ImageJpaRepository imageJpaRepository; | ||
|
||
@Override | ||
public List<ImageResponse> findAllByGroupIdAndDate(Long groupId, LocalDateTime searchDate) { | ||
String dateFormat = "DATE_FORMAT({0}, '%Y.%m.%d.%H:%i')"; | ||
return queryFactory | ||
.select( | ||
Projections.constructor( | ||
ImageResponse.class, | ||
imageEntity.id.as("imageId"), | ||
imageEntity.imageName.as("imageName"), | ||
imageEntity.imagePath.as("imagePath"), | ||
Expressions.stringTemplate(dateFormat, imageEntity.createdAt) | ||
.as("formattedCreatedAt"))) | ||
.from(imageEntity) | ||
.join(imageEntity.group, groupEntity) | ||
.where( | ||
imageEntity | ||
.group | ||
.id | ||
.eq(groupId) | ||
.and(imageEntity.createdAt.year().eq(searchDate.getYear())) | ||
.and(imageEntity.createdAt.month().eq(searchDate.getMonthValue())) | ||
.and( | ||
imageEntity | ||
.createdAt | ||
.dayOfMonth() | ||
.eq(searchDate.getDayOfMonth()))) | ||
.orderBy(imageEntity.createdAt.desc()) | ||
.fetch(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ spring: | |
format_sql: true | ||
default_batch_fetch_size: 100 | ||
hibernate: | ||
ddl-auto: update | ||
ddl-auto: none |