Skip to content

Commit

Permalink
[TDC-106] naming 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yerimkoko committed Jun 25, 2024
1 parent 8788cce commit abcf193
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
// Spring
springBootVersion = "3.3.0"
springBootVersion = "3.3.1"
springDependencyManagementVersion = "1.1.5"

// Swagger
Expand Down
27 changes: 18 additions & 9 deletions threedollar-application/http/post.http
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
### Post
POST {{host_api}}/community/v1/post
### Post 추가
POST {{host_api}}/community/v1/post?accountId=USER222
X-Community-Api-Key: {{api_key}}
Content-Type: application/json

{
"postGroup": "BOSS_NEWS",
"postGroup": "NEWS_POST",
"title": "오늘은 휴일입니다",
"content": "정기적인 휴일입니다.",
"accountId": "USER222",
"postSectionRequests": [
"targetId": "3",
"workspaceId": "threedollar-dev",
"sections": [
{
"postType": "IMAGE",
"sectionType": "IMAGE",
"priority": "2",
"url": "image.jpg",
"width": "300",
"height": "400"
"ratio": 23.333,
"url": "www.naver.com"
}
]
}



### Post 조회
GET {{host_api}}/community/v1/posts?cursor=8&size=3&workspaceId=threedollar-dev&targetId=3&postGroup=NEWS_POST
X-Community-Api-Key: {{api_key}}
Content-Type: application/json


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.threedollar.config.advice;

import com.threedollar.common.dto.response.ApiResponse;
import com.threedollar.common.exception.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionControllerAdvice {

@ExceptionHandler(NotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ApiResponse<Object> handleNotFoundException(NotFoundException e) {
log.error(e.getErrorCode().getMessage(), e);
return ApiResponse.error(e.getErrorCode(), e.getMessage());
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
import com.threedollar.common.dto.response.ApiResponse;
import com.threedollar.config.interceptor.ApiKeyContext;
import com.threedollar.config.resolver.RequestApiKey;
import com.threedollar.domain.post.PostGroup;
import com.threedollar.service.post.PostFacadeService;
import com.threedollar.service.post.request.GetPostRequest;
import com.threedollar.service.post.request.PostAddRequest;
import com.threedollar.service.post.request.PostAndCursorRequest;
import com.threedollar.service.post.response.PostAndCursorResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -20,23 +26,25 @@ public class PostController {
private final PostFacadeService postFacadeService;

@PostMapping("/v1/post")
public ApiResponse<String> addPost(@RequestApiKey ApiKeyContext workspaceId,
@RequestParam String accountId,
@Valid @RequestBody PostAddRequest request) {
public ApiResponse<Long> addPost(@RequestApiKey ApiKeyContext workspaceId,
@RequestParam String accountId,
@Valid @RequestBody PostAddRequest request) {

postFacadeService.addPost(request, workspaceId.getWorkspaceId(), accountId);
return ApiResponse.OK;
return ApiResponse.success(postFacadeService.addPost(request, workspaceId.getWorkspaceId(), accountId));

}

@DeleteMapping("/v1/post")
public ApiResponse<String> deletePost(Long postId,
String accountId,
String workspaceId) {

postFacadeService.deletePost(workspaceId, accountId, postId);
@DeleteMapping("/v1/post/{postId}")
public ApiResponse<String> deletePost(@PathVariable Long postId,
GetPostRequest request) {
postFacadeService.deletePost(request.getWorkspaceId(), request.getAccountId(), postId, request.getPostGroup(), request.getTargetId());
return ApiResponse.OK;
}

@GetMapping("/v1/post-group/{postGroup}")
public ApiResponse<PostAndCursorResponse> getPosts(@Valid PostAndCursorRequest request,
@PathVariable PostGroup postGroup) {
return ApiResponse.success(postFacadeService.getPostAndCursor(request, postGroup));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class CursorResponse {

private boolean hasNext;

private Long next;
private Long nextCursor;

@Builder
public CursorResponse(boolean hasNext, Long next) {
public CursorResponse(boolean hasNext, Long nextCursor) {
this.hasNext = hasNext;
this.next = next;
this.nextCursor = nextCursor;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.threedollar.service.post;

import com.threedollar.domain.post.PostGroup;
import com.threedollar.service.post.request.PostAddRequest;
import com.threedollar.service.post.request.PostAndCursorRequest;
import com.threedollar.service.post.response.PostAndCursorResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
Expand All @@ -12,20 +16,32 @@ public class PostFacadeService {

private final PostService postService;

public void addPost(PostAddRequest request,
public Long addPost(PostAddRequest request,
@NotBlank String workspaceId,
@NotBlank String accountId) {
postService.addPost(request, workspaceId, accountId);
return postService.addPost(request, workspaceId, accountId);
}


public void deletePost(@NotBlank String workspaceId,
@NotBlank String accountId,
@NotNull Long postId) {
@NotNull Long postId,
@NotNull PostGroup postGroup,
@NotBlank String targetId) {

postService.deletePost(workspaceId, accountId, postId);
postService.deletePost(workspaceId, accountId, postId, postGroup, targetId);

}

public PostAndCursorResponse getPostAndCursor(@Valid PostAndCursorRequest request,
PostGroup postGroup) {
return postService.getPostsAndCursor(
postGroup,
request.getWorkspaceId(),
request.getTargetId(),
request.getCursor(),
request.getSize());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.threedollar.common.exception.NotFoundException;
import com.threedollar.domain.post.Post;
import com.threedollar.domain.post.PostGroup;
import com.threedollar.domain.post.repository.PostRepository;
import com.threedollar.service.post.request.PostAddRequest;
import com.threedollar.service.post.response.PostAndCursorResponse;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PostService {
Expand All @@ -17,20 +21,23 @@ public class PostService {


@Transactional
public void addPost(PostAddRequest request,
public Long addPost(PostAddRequest request,
@NotBlank String workspaceId,
String accountId) {

postRepository.save(request.toEntity(workspaceId, accountId));
Post post = postRepository.save(request.toEntity(workspaceId, accountId));
return post.getId();

}

@Transactional
public void deletePost(String workspaceId,
String accountId,
Long postId) {
Long postId,
PostGroup postGroup,
String targetId) {

Post post = postRepository.findByIdAndWorkspaceIdAndAccountId(postId, accountId, workspaceId);
Post post = postRepository.findByIdAndWorkspaceIdAndAccountIdAndGroupAndTargetId(postId, accountId, workspaceId, postGroup, targetId);
if (post == null) {
throw new NotFoundException(String.format("(%s)에 해당하는 postId 는 존재하지 않거나 잘못된 접근입니다", postId));
}
Expand All @@ -39,4 +46,19 @@ public void deletePost(String workspaceId,

}

@Transactional(readOnly = true)
public PostAndCursorResponse getPostsAndCursor(PostGroup postGroup,
String workspaceId,
String targetId,
Long cursor,
int size) {
List<Post> posts = postRepository.findByPostGroupAndWorkspaceIdAndTargetIdAndCursorAndSize(postGroup, workspaceId, targetId, cursor, size + 1);

if (posts.isEmpty() || posts.size() <= size) {
return PostAndCursorResponse.noMore(posts);
}
return PostAndCursorResponse.hasNext(posts);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.threedollar.service.post.request;


import jakarta.annotation.Nullable;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class CursorRequest {

@Nullable
private Long cursor;

@Min(0)
@Max(30)
private int size;

public CursorRequest(Long cursor, int size) {
this.cursor = cursor;
this.size = size;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.threedollar.service.post.request;

import com.threedollar.domain.post.PostGroup;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class GetPostRequest {

@NotBlank
private String accountId;

@NotBlank
private String workspaceId;

private PostGroup postGroup;

private String targetId;

public GetPostRequest(String accountId, String workspaceId, PostGroup postGroup, String targetId) {
this.accountId = accountId;
this.workspaceId = workspaceId;
this.postGroup = postGroup;
this.targetId = targetId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class PostAddRequest {

private String title;

private String workspaceId;

private String targetId;

@NotBlank
Expand All @@ -31,12 +33,13 @@ public class PostAddRequest {
private List<PostSectionRequest> sections;

@Builder
public PostAddRequest(PostGroup postGroup, Long parentId, String title, String content, String targetId, List<PostSectionRequest> sections) {
public PostAddRequest(PostGroup postGroup, Long parentId, String title, String targetId, String content, String workspaceId, List<PostSectionRequest> sections) {
this.postGroup = postGroup;
this.parentId = parentId;
this.title = title;
this.targetId =
this.workspaceId = workspaceId;
this.content = content;
this.targetId = targetId;
this.sections = sections;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.threedollar.service.post.request;

import jakarta.annotation.Nullable;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class PostAndCursorRequest {

@Nullable
private Long cursor;

@Min(0)
@Max(30)
private int size;

@NotBlank
private String workspaceId;

@NotBlank
private String targetId;

public PostAndCursorRequest(Long cursor, int size, String workspaceId, String targetId) {
this.cursor = cursor;
this.size = size;
this.workspaceId = workspaceId;
this.targetId = targetId;
}
}
Loading

0 comments on commit abcf193

Please sign in to comment.