Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface CommentRepository extends JpaRepository<Comment, Long>, Comment
@Modifying
@Query("delete from Comment c where c.comment.id = :parentId")
void deleteReplies(Long parentId);

long countByHistoryIdAndBannedFalse(Long historyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import org.clokey.code.GlobalBaseSuccessCode;
import org.clokey.domain.history.dto.request.HistoryCreateRequest;
import org.clokey.domain.history.dto.request.HistoryUpdateRequest;
import org.clokey.domain.history.dto.response.DailyHistoryResponse;
import org.clokey.domain.history.dto.response.HistoryClothTagListResponse;
import org.clokey.domain.history.dto.response.HistoryCreateResponse;
import org.clokey.domain.history.dto.response.HistoryOwnershipCheckResponse;
import org.clokey.domain.history.dto.response.MonthlyHistoryResponse;
import org.clokey.domain.history.dto.response.SituationListResponse;
import org.clokey.domain.history.dto.response.StyleListResponse;
import org.clokey.domain.history.service.HistoryService;
Expand Down Expand Up @@ -65,4 +69,47 @@ public BaseResponse<SituationListResponse> getAllSituations() {
SituationListResponse response = historyService.getAllSituations();
return BaseResponse.onSuccess(GlobalBaseSuccessCode.OK, response);
}

@GetMapping("/{historyId}")
@Operation(
operationId = "History_getHistoryDetails",
summary = "일별 기록 조회",
description = "기록 ID를 통해 일별 기록의 정보를 조회합니다.")
public BaseResponse<DailyHistoryResponse> getDailyHistory(@PathVariable Long historyId) {
DailyHistoryResponse response = historyService.getDailyHistory(historyId);
return BaseResponse.onSuccess(GlobalBaseSuccessCode.OK, response);
}

@GetMapping("/cloth-tag/{historyImageId}")
@Operation(
operationId = "History_getHistoryClothTags",
summary = "기록 이미지의 옷 태그 조회",
description = "기록 이미지 ID를 통해 해당 이미지에 태그된 옷들의 정보와 위치를 조회합니다.")
public BaseResponse<HistoryClothTagListResponse> getHistoryClothTags(
@PathVariable Long historyImageId) {
HistoryClothTagListResponse response = historyService.getHistoryClothTags(historyImageId);
return BaseResponse.onSuccess(GlobalBaseSuccessCode.OK, response);
}

@GetMapping("/monthly/{memberId}")
@Operation(
operationId = "History_getMonthlyHistory",
summary = "월별 기록 조회",
description = "특정 회원의 특정 년도/월에 해당하는 모든 기록의 ID와 첫 번째 이미지 URL을 조회합니다.")
public BaseResponse<MonthlyHistoryResponse> getMonthlyHistory(
@PathVariable Long memberId, @RequestParam int year, @RequestParam int month) {
MonthlyHistoryResponse response = historyService.getMonthlyHistory(memberId, year, month);
return BaseResponse.onSuccess(GlobalBaseSuccessCode.OK, response);
}

@GetMapping("/{historyId}/ownership")
@Operation(
operationId = "History_checkHistoryOwnership",
summary = "나의 기록 여부 확인",
description = "기록 ID를 통해 해당 기록이 현재 사용자의 기록인지 확인합니다.")
public BaseResponse<HistoryOwnershipCheckResponse> checkHistoryOwnership(
@PathVariable Long historyId) {
HistoryOwnershipCheckResponse response = historyService.checkHistoryOwnership(historyId);
return BaseResponse.onSuccess(GlobalBaseSuccessCode.OK, response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.clokey.domain.history.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.util.List;

public record DailyHistoryResponse(
@Schema(description = "회원 ID", example = "1") Long memberId,
@Schema(description = "프로필 이미지 URL", example = "https://example.com/profile.jpg")
String profileImageUrl,
@Schema(description = "닉네임", example = "포테토남") String nickname,
@Schema(description = "기록 이미지 목록") List<DailyHistoryResponse.ImagePayload> images,
@Schema(description = "좋아요 개수", example = "10") Long likeCount,
@Schema(description = "댓글 개수", example = "5") Long commentCount,
@Schema(description = "기록 날짜", example = "2025-01-01") LocalDate historyDate,
@Schema(description = "상황 ID", example = "1") Long situationId,
@Schema(description = "상황 이름", example = "데일리") String situationName,
@Schema(description = "스타일 목록") List<DailyHistoryResponse.StylePayload> styles) {

public static DailyHistoryResponse of(
Long memberId,
String profileImageUrl,
String nickname,
List<ImagePayload> images,
Long likeCount,
Long commentCount,
LocalDate historyDate,
Long situationId,
String situationName,
List<StylePayload> styles) {
return new DailyHistoryResponse(
memberId,
profileImageUrl,
nickname,
images,
likeCount,
commentCount,
historyDate,
situationId,
situationName,
styles);
}

@Schema(name = "DailyHistoryResponseImagePayload", description = "기록 이미지 정보")
public record ImagePayload(
@Schema(description = "이미지 ID", example = "1") Long imageId,
@Schema(description = "이미지 URL", example = "https://example.com/image.jpg")
String imageUrl) {}

@Schema(name = "DailyHistoryResponseStylePayload", description = "스타일 정보")
public record StylePayload(
@Schema(description = "스타일 ID", example = "1") Long styleId,
@Schema(description = "스타일 이름", example = "캐주얼") String styleName) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.clokey.domain.history.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

public record HistoryClothTagListResponse(
@Schema(description = "옷 태그 목록") List<HistoryClothTagListResponse.Payload> payloads) {

public static HistoryClothTagListResponse of(List<Payload> payloads) {
return new HistoryClothTagListResponse(payloads);
}

@Schema(name = "HistoryClothTagListResponsePayload", description = "옷 태그 정보")
public record Payload(
@Schema(description = "옷 태그 ID", example = "1") Long historyClothTagId,
@Schema(description = "옷 ID", example = "1") Long clothId,
@Schema(description = "옷 이미지 URL", example = "https://example.com/image.jpg")
String clothImageUrl,
@Schema(description = "옷 이름", example = "맨투맨") String name,
@Schema(description = "옷 브랜드", example = "나이키") String brand,
@Schema(description = "X 좌표", example = "0.5") Double locationX,
@Schema(description = "Y 좌표", example = "0.7") Double locationY) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.clokey.domain.history.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

public record HistoryOwnershipCheckResponse(
@Schema(description = "내 기록 여부", example = "true") boolean isOwner) {
public static HistoryOwnershipCheckResponse of(boolean isOwner) {
return new HistoryOwnershipCheckResponse(isOwner);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.clokey.domain.history.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

public record MonthlyHistoryResponse(
@Schema(description = "기록 목록") List<MonthlyHistoryResponse.Payload> payloads) {

public static MonthlyHistoryResponse of(List<Payload> payloads) {
return new MonthlyHistoryResponse(payloads);
}

@Schema(name = "MonthlyHistoryResponsePayload", description = "월별 기록 정보")
public record Payload(
@Schema(description = "기록 ID", example = "1") Long historyId,
@Schema(description = "첫 번째 이미지 URL", example = "https://example.com/image.jpg")
String firstImageUrl) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
@Getter
@AllArgsConstructor
public enum HistoryErrorCode implements BaseErrorCode {
BANNED_HISTORY(400, "HISTORY_4001", "신고당한 기록은 조회할 수 없습니다."),

LIMITED_AUTHORITY(403, "HISTORY_4031", "기록에 대한 접근 권한이 없습니다."),
BLOCKED_AUTHORITY(403, "HISTORY_4032", "기록 작성자를 차단했거나 차단 당했습니다"),

HISTORY_NOT_FOUND(404, "HISTORY_4041", "존재하지 않는 기록입니다."),
LIMITED_AUTHORITY(403, "HISTORY_4031", "기록에 대한 접근 권한이 없습니다.");
HISTORY_IMAGE_NOT_FOUND(404, "HISTORY_4042", "존재하지 않는 기록 이미지입니다.");

private final int status;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ public interface HistoryClothTagRepository
@Modifying
@Query("DELETE FROM HistoryClothTag hct WHERE hct.cloth.id = :clothId")
void deleteAllByClothId(Long clothId);

@Query(
"select hct from HistoryClothTag hct "
+ "join fetch hct.cloth "
+ "where hct.historyImage.id = :historyImageId")
List<HistoryClothTag> findAllByHistoryImageIdWithCloth(Long historyImageId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
import java.util.List;
import org.clokey.history.entity.HistoryImage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface HistoryImageRepository extends JpaRepository<HistoryImage, Long> {
@Query(
"""
SELECT hi.history.id, hi.imageUrl
FROM HistoryImage hi
WHERE hi.history.id IN :historyIds
AND hi.id = (
SELECT MIN(h2.id)
FROM HistoryImage h2
WHERE h2.history.id = hi.history.id
)
""")
List<Object[]> getFirstImageUrlsWithHistoryId(@Param("historyIds") List<Long> historyIds);

List<HistoryImage> findByHistoryId(Long historyId);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
package org.clokey.domain.history.repository;

import java.util.List;
import java.util.Optional;
import org.clokey.history.entity.History;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface HistoryRepository extends JpaRepository<History, Long> {
@Query("SELECT h FROM History h JOIN FETCH h.member m WHERE h.id = :id")
Optional<History> findByIdWithMember(Long id);

boolean existsByMemberId(Long memberId);

@Query(
"""
select h from History h
where h.member.id = :memberId
and FUNCTION('YEAR', h.historyDate) = :year
and FUNCTION('MONTH', h.historyDate) = :month
and h.banned = false
order by h.historyDate asc
""")
List<History> findByMemberIdAndYearAndMonthNotBanned(Long memberId, int year, int month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import org.clokey.domain.history.dto.request.HistoryCreateRequest;
import org.clokey.domain.history.dto.request.HistoryUpdateRequest;
import org.clokey.domain.history.dto.response.HistoryCreateResponse;
import org.clokey.domain.history.dto.response.SituationListResponse;
import org.clokey.domain.history.dto.response.StyleListResponse;
import org.clokey.domain.history.dto.response.*;

public interface HistoryService {
HistoryCreateResponse createHistory(HistoryCreateRequest request);
Expand All @@ -14,4 +12,12 @@ public interface HistoryService {
StyleListResponse getAllStyles();

SituationListResponse getAllSituations();

DailyHistoryResponse getDailyHistory(Long historyId);

HistoryClothTagListResponse getHistoryClothTags(Long historyImageId);

MonthlyHistoryResponse getMonthlyHistory(Long memberId, int year, int month);

HistoryOwnershipCheckResponse checkHistoryOwnership(Long historyId);
}
Loading