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 @@ -23,7 +23,7 @@ public class CocktailController {
@GetMapping("/{id}")
@Transactional
@Operation(summary = "칵테일 단건 조회")
public RsData<CocktailDetailDto> getCocktailDetailById(@PathVariable long id){
public RsData<CocktailDetailResponseDto> getCocktailDetailById(@PathVariable long id){

CocktailDetailResponseDto cocktailDetailResponseDto = cocktailService.getCocktailDetailById(id);
return RsData.successOf(cocktailDetailResponseDto);
Expand Down

This file was deleted.

51 changes: 0 additions & 51 deletions src/main/java/com/back/domain/history/service/HistoryService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.time.LocalDateTime;

@RestController
@RequestMapping("/me/bar")
@RequestMapping("/api/me/bar")
@RequiredArgsConstructor
@Validated
public class MyBarController {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.back.domain.myhistory.controller;

import com.back.domain.myhistory.dto.MyHistoryCommentGoResponseDto;
import com.back.domain.myhistory.dto.MyHistoryCommentListDto;
import com.back.domain.myhistory.dto.MyHistoryPostListDto;
import com.back.domain.myhistory.service.MyHistoryService;
import com.back.global.rsData.RsData;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/me")
@RequiredArgsConstructor
@Validated
public class MyHistoryController {

private final MyHistoryService myHistoryService;

@GetMapping("/posts")
public RsData<MyHistoryPostListDto> getMyPosts(
@AuthenticationPrincipal(expression = "id") Long userId,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime lastCreatedAt,
@RequestParam(required = false) Long lastId,
@RequestParam(defaultValue = "20") @Min(1) @Max(100) int limit
) {
MyHistoryPostListDto body = myHistoryService.getMyPosts(userId, lastCreatedAt, lastId, limit);
return RsData.successOf(body);
}

@GetMapping("/comments")
public RsData<MyHistoryCommentListDto> getMyComments(
@AuthenticationPrincipal(expression = "id") Long userId,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime lastCreatedAt,
@RequestParam(required = false) Long lastId,
@RequestParam(defaultValue = "20") @Min(1) @Max(100) int limit
) {
MyHistoryCommentListDto body = myHistoryService.getMyComments(userId, lastCreatedAt, lastId, limit);
return RsData.successOf(body);
}

@GetMapping("/comments/{id}")
public RsData<MyHistoryCommentGoResponseDto> goFromComment(
@AuthenticationPrincipal(expression = "id") Long userId,
@PathVariable("id") Long commentId
) {
var body = myHistoryService.getPostLinkFromMyComment(userId, commentId);
return RsData.successOf(body);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.back.domain.myhistory.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class MyHistoryCommentGoResponseDto {
private Long postId;
private String postApiUrl;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.back.domain.myhistory.dto;

import com.back.domain.post.comment.entity.Comment;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@Builder
public class MyHistoryCommentItemDto {
private Long id;
private Long postId;
private String postTitle;
private String content;
private LocalDateTime createdAt;

public static MyHistoryCommentItemDto from(Comment c) {
return MyHistoryCommentItemDto.builder()
.id(c.getId())
.postId(c.getPost().getId())
.postTitle(c.getPost().getTitle())
.content(c.getContent())
.createdAt(c.getCreatedAt())
.build();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.back.domain.myhistory.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.List;

@Getter
@AllArgsConstructor
public class MyHistoryCommentListDto {
private List<MyHistoryCommentItemDto> items;
private boolean hasNext;
private LocalDateTime nextCreatedAt;
private Long nextId;
}

Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.back.domain.history.dto;
package com.back.domain.myhistory.dto;

import com.back.domain.post.post.entity.Post;
import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@Builder
public class HistoryPostItemDto {
public class MyHistoryPostItemDto {
private Long id;
private String title;
private String imageUrl;
private LocalDateTime createdAt;
private Integer likeCount;
private Integer commentCount;

public static HistoryPostItemDto from(Post p) {
return HistoryPostItemDto.builder()
public static MyHistoryPostItemDto from(Post p) {
return MyHistoryPostItemDto.builder()
.id(p.getId())
.title(p.getTitle())
.imageUrl(p.getImageUrl())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.back.domain.history.dto;
package com.back.domain.myhistory.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -8,8 +8,8 @@

@Getter
@AllArgsConstructor
public class HistoryPostListDto {
private List<HistoryPostItemDto> items;
public class MyHistoryPostListDto {
private List<MyHistoryPostItemDto> items;
private boolean hasNext;
private LocalDateTime nextCreatedAt;
private Long nextId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.back.domain.myhistory.repository;

import com.back.domain.post.comment.entity.Comment;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface MyHistoryCommentRepository extends JpaRepository<Comment, Long> {

@Query("""
select c from Comment c
join fetch c.post p
where c.user.id = :userId
order by c.createdAt desc, c.id desc
""")
List<Comment> findMyCommentsFirstPage(@Param("userId") Long userId,
Pageable pageable);

@Query("""
select c from Comment c
join fetch c.post p
where c.user.id = :userId
and (c.createdAt < :lastCreatedAt or (c.createdAt = :lastCreatedAt and c.id < :lastId))
order by c.createdAt desc, c.id desc
""")
List<Comment> findMyCommentsAfter(@Param("userId") Long userId,
@Param("lastCreatedAt") LocalDateTime lastCreatedAt,
@Param("lastId") Long lastId,
Pageable pageable);

@Query("""
select c from Comment c
join fetch c.post p
where c.id = :id and c.user.id = :userId
""")
Comment findByIdAndUserId(@Param("id") Long id, @Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.back.domain.history.repository;
package com.back.domain.myhistory.repository;

import com.back.domain.post.post.entity.Post;
import com.back.domain.post.post.enums.PostStatus;
import jakarta.persistence.QueryHint;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface HistoryRepository extends JpaRepository<Post, Long> {
public interface MyHistoryPostRepository extends JpaRepository<Post, Long> {

@QueryHints(@QueryHint(name = "org.hibernate.readOnly", value = "true"))
@Query("""
select p from Post p
where p.user.id = :userId
Expand All @@ -27,7 +24,6 @@ List<Post> findMyPostsFirstPage(@Param("userId") Long userId,
@Param("deleted") PostStatus deleted,
Pageable pageable);

@QueryHints(@QueryHint(name = "org.hibernate.readOnly", value = "true"))
@Query("""
select p from Post p
where p.user.id = :userId
Expand Down
Loading