Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#434 [feat] 글 삭제/수정 권한 조회 변경 #435

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 25 additions & 4 deletions module-domain/src/main/java/com/mile/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.mile.post.service.dto.PostPutRequest;
import com.mile.post.service.dto.TemporaryPostCreateRequest;
import com.mile.post.service.dto.TemporaryPostGetResponse;
import com.mile.post.service.dto.WriterAuthenticateResponse;
import com.mile.post.service.dto.PostAuthenticateResponse;
import com.mile.topic.domain.Topic;
import com.mile.topic.service.TopicRetriever;
import com.mile.topic.service.TopicService;
Expand Down Expand Up @@ -52,6 +52,11 @@ public class PostService {

private static final boolean CURIOUS_FALSE = false;
private static final boolean CURIOUS_TRUE = true;
private static final String ROLE_WRITER = "writer";
private static final String ROLE_ANONYMOUS = "anonymous";
private static final String ROLE_MEMBER = "member";
private static final String ROLE_OWNER = "owner";


@Transactional
public void createCommentOnPost(
Expand Down Expand Up @@ -119,12 +124,28 @@ public void updatePost(
}


public WriterAuthenticateResponse getAuthenticateWriter(
public PostAuthenticateResponse getAuthenticateWriter(
final Long postId,
final Long userId
) {
return WriterAuthenticateResponse.of(postRetriever.existsPostByWriterWithPost(postId,
writerNameRetriever.getWriterNameByPostAndUserId(postRetriever.findById(postId), userId).getId()));
Post post = postRetriever.findById(postId);
Moim moim = post.getTopic().getMoim();
WriterName postWriterName = post.getWriterName();

if (!writerNameRetriever.isUserInMoim(moim.getId(), userId)) {
return PostAuthenticateResponse.of(ROLE_ANONYMOUS);
}

WriterName userWriterName = writerNameRetriever.findByMoimAndUser(moim.getId(), userId);
if (postWriterName.equals(userWriterName)) {
return PostAuthenticateResponse.of(ROLE_WRITER);
}

if (moim.getOwner().equals(userWriterName)) {
return PostAuthenticateResponse.of(ROLE_OWNER);
}

return PostAuthenticateResponse.of(ROLE_MEMBER);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mile.post.service.dto;

public record PostAuthenticateResponse(
String role
) {
public static PostAuthenticateResponse of(
final String role
) {
return new PostAuthenticateResponse(role);
}
}

This file was deleted.

Loading