Skip to content

Commit

Permalink
[REFACTOR] type을 통한 Position 체크 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Chan531 committed Aug 20, 2024
1 parent 54363d3 commit eb6e909
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/tiki/server/common/entity/Position.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.tiki.server.common.entity;

import static com.tiki.server.timeblock.message.ErrorCode.INVALID_TYPE;

import com.tiki.server.timeblock.exception.TimeBlockException;

import lombok.Getter;

@Getter
Expand All @@ -11,4 +15,12 @@ public enum Position {
Position(int authorization) {
this.authorization = authorization;
}

public static Position getAccessiblePosition(String type) {
return switch (type) {
case "executive" -> EXECUTIVE;
case "member" -> MEMBER;
default -> throw new TimeBlockException(INVALID_TYPE);
};
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.tiki.server.document.service;

import static com.tiki.server.document.message.ErrorCode.INVALID_DOCUMENT;
import static com.tiki.server.document.message.ErrorCode.INVALID_TYPE;
import static com.tiki.server.timeblock.constant.TimeBlockConstant.EXECUTIVE;
import static com.tiki.server.timeblock.constant.TimeBlockConstant.MEMBER;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -33,7 +30,7 @@ public class DocumentService {

public DocumentsGetResponse getAllDocuments(long memberId, long teamId, String type) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Position accessiblePosition = getAccessiblePosition(type);
Position accessiblePosition = Position.getAccessiblePosition(type);
memberTeamManager.checkMemberAccessible(accessiblePosition);
return getAllDocumentsByType(teamId, accessiblePosition);
}
Expand All @@ -47,14 +44,6 @@ public void deleteDocument(long memberId, long teamId, long documentId) {
documentDeleter.delete(document);
}

private Position getAccessiblePosition(String type) {
return switch (type) {
case EXECUTIVE -> Position.EXECUTIVE;
case MEMBER -> Position.MEMBER;
default -> throw new DocumentException(INVALID_TYPE);
};
}

private DocumentsGetResponse getAllDocumentsByType(long teamId, Position accessiblePosition) {
List<Document> documents = documentFinder.findAllByTeamIdAndAccessiblePosition(teamId, accessiblePosition);
return DocumentsGetResponse.from(documents);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.tiki.server.timeblock.service;

import static com.tiki.server.timeblock.message.ErrorCode.INVALID_TYPE;
import static com.tiki.server.timeblock.constant.TimeBlockConstant.EXECUTIVE;
import static com.tiki.server.timeblock.constant.TimeBlockConstant.MEMBER;

import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -57,7 +53,7 @@ public TimeBlockCreateResponse createTimeBlock(
) {
Team team = teamFinder.findById(teamId);
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Position accessiblePosition = getAccessiblePosition(type);
Position accessiblePosition = Position.getAccessiblePosition(type);
memberTeamManager.checkMemberAccessible(accessiblePosition);
TimeBlock timeBlock = saveTimeBlock(team, accessiblePosition, request);
saveDocuments(request.files(), timeBlock);
Expand All @@ -67,7 +63,7 @@ public TimeBlockCreateResponse createTimeBlock(
public TimelineGetResponse getTimeline(long memberId, long teamId, String type, String date) {
Team team = teamFinder.findById(teamId);
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Position accessiblePosition = getAccessiblePosition(type);
Position accessiblePosition = Position.getAccessiblePosition(type);
memberTeamManager.checkMemberAccessible(accessiblePosition);
List<TimeBlockVO> timeBlocks = timeBlockFinder.findByTeamAndAccessiblePositionAndDate(
team.getId(), accessiblePosition.name(), date);
Expand All @@ -91,14 +87,6 @@ public void deleteTimeBlock(long memberId, long teamId, long timeBlockId) {
timeBlockDeleter.deleteById(timeBlock.timeBlockId());
}

private Position getAccessiblePosition(String type) {
return switch (type) {
case EXECUTIVE -> Position.EXECUTIVE;
case MEMBER -> Position.MEMBER;
default -> throw new TimeBlockException(INVALID_TYPE);
};
}

private TimeBlock saveTimeBlock(Team team, Position accessiblePosition, TimeBlockCreateRequest request) {
return timeBlockSaver.save(TimeBlock.of(team, accessiblePosition, request));
}
Expand Down

0 comments on commit eb6e909

Please sign in to comment.