Skip to content

Commit

Permalink
[FEAT] 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
paragon0107 committed Dec 2, 2024
1 parent ca97bd3 commit a2dce31
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public class DocumentService {
private final DeletedDocumentAdapter deletedDocumentAdapter;

public DocumentsGetResponse getAllDocuments(final long memberId, final long teamId, final String type) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Position accessiblePosition = Position.getAccessiblePosition(type);
memberTeamManager.checkMemberAccessible(accessiblePosition);
return getAllDocumentsByType(teamId, accessiblePosition);
}

@Transactional
public void deleteDocument(final long memberId, final long teamId, final long documentId) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Document document = documentFinder.findByIdWithTimeBlock(documentId);
memberTeamManager.checkMemberAccessible(document.getTimeBlock().getAccessiblePosition());
documentDeleter.delete(document);
Expand All @@ -56,43 +56,43 @@ public void deleteDocument(final long memberId, final long teamId, final long do
@Transactional
public void createDocuments(final long memberId, final long teamId,
final Long folderId, final DocumentsCreateRequest request) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
validateFolder(folderId, teamId);
validateFileName(folderId, teamId, request);
saveDocuments(teamId, folderId, request);
}

public DocumentsGetResponse get(final long memberId, final long teamId, final Long folderId) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<Document> documents = documentFinder.findByTeamIdAndFolderId(teamId, folderId);
return DocumentsGetResponse.from(documents);
}

@Transactional
public void delete(final long memberId, final long teamId, final List<Long> documentIds) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<Document> documents = documentFinder.findAllByIdAndTeamId(documentIds, teamId);
deletedDocumentAdapter.save(documents);
documentDeleter.deleteAll(documents);
}

@Transactional
public void deleteTrash(final long memberId, final long teamId, final List<Long> documentIds) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<DeletedDocument> deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId);
deletedDocumentAdapter.deleteAll(deletedDocuments);
}

@Transactional
public void restore(final long memberId, final long teamId, final List<Long> documentIds) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<DeletedDocument> deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId);
documentSaver.restore(deletedDocuments);
deletedDocumentAdapter.deleteAll(deletedDocuments);
}

public DeletedDocumentsGetResponse getTrash(final long memberId, final long teamId) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<DeletedDocument> deletedDocuments = deletedDocumentAdapter.get(teamId);
return DeletedDocumentsGetResponse.from(deletedDocuments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class FolderService {

public FoldersGetResponse get(final long memberId, final long teamId,
final Long folderId) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Folder folder = getFolder(teamId, folderId);
String path = getChildFolderPath(folder);
List<Folder> folders = folderFinder.findByTeamIdAndPath(teamId, path);
Expand All @@ -49,7 +49,7 @@ public FoldersGetResponse get(final long memberId, final long teamId,
@Transactional
public FolderCreateResponse create(final long memberId, final long teamId,
final Long folderId, final FolderCreateRequest request) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Folder parentFolder = getFolder(teamId, folderId);
String path = getChildFolderPath(parentFolder);
validateFolderName(teamId, path, request);
Expand All @@ -59,7 +59,7 @@ public FolderCreateResponse create(final long memberId, final long teamId,

@Transactional
public void delete(final long memberId, final long teamId, final List<Long> folderIds) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<Folder> folders = folderFinder.findAllById(folderIds, teamId);
deleteFolders(folders);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,18 @@
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.Optional;

@RepositoryAdapter
@RequiredArgsConstructor
public class MemberTeamManagerFinder {

private final MemberTeamManagerRepository memberTeamManagerRepository;

public MemberTeamManager findByMemberIdAndTeamIdOrElseThrow(long memberId, long teamId) {
public MemberTeamManager findByMemberIdAndTeamId(long memberId, long teamId) {
return memberTeamManagerRepository.findByMemberIdAndTeamId(memberId, teamId)
.orElseThrow(() -> new MemberTeamManagerException(INVALID_MEMBER_TEAM_MANAGER));
}

public Optional<MemberTeamManager> findByMemberIdAndTeamId(final long memberId, final long teamId) {
return memberTeamManagerRepository.findByMemberIdAndTeamId(memberId, teamId);
}

public List<MemberTeamManager> findBelongTeamByMemberId(long memberId) {
return memberTeamManagerRepository.findAllBelongTeamByMemberId(memberId).stream().toList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tiki.server.memberteammanager.controller;

import com.tiki.server.common.dto.BaseResponse;
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.memberteammanager.controller.dto.request.UpdateTeamMemberNameRequest;
import com.tiki.server.memberteammanager.service.MemberTeamManagerService;
Expand All @@ -23,7 +24,7 @@ public class MemberTeamController {

@GetMapping("/teams/{teamId}/members/position")
public ResponseEntity<SuccessResponse<MemberTeamPositionGetResponse>> getMemberTeamPosition(
Principal principal,
final Principal principal,
@PathVariable final long teamId
) {
long memberId = Long.parseLong(principal.getName());
Expand All @@ -32,13 +33,13 @@ public ResponseEntity<SuccessResponse<MemberTeamPositionGetResponse>> getMemberT
}

@PatchMapping("/teams/{teamId}/members/name")
public ResponseEntity<SuccessResponse<Void>> updateTeamMemberName(
Principal principal,
public ResponseEntity<BaseResponse> updateTeamMemberName(
final Principal principal,
@PathVariable final long teamId,
@RequestBody final UpdateTeamMemberNameRequest request
) {
long memberId = Long.parseLong(principal.getName());
memberTeamManagerService.updateTeamMemberName(memberId, teamId, request.newName());
return ResponseEntity.ok().body(success(UPDATE_NAME.getMessage(), null));
return ResponseEntity.ok(success(UPDATE_NAME.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tiki.server.memberteammanager.controller.dto.request;

import jakarta.validation.constraints.NotNull;

public record UpdateTeamMemberNameRequest(
String newName
@NotNull String newName
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public void checkMemberAccessible(Position accesiblePosition) {
}
}

public void setName(final String name){
public void updateName(final String name){
this.name = name;
}

public void setPositionToExecutive(){
public void updatePositionToExecutive(){
this.position = Position.EXECUTIVE;
}

public void setPositionToAdmin(){
public void updatePositionToAdmin(){
this.position = Position.ADMIN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class MemberTeamManagerService {
private final MemberTeamManagerFinder memberTeamManagerFinder;

public MemberTeamPositionGetResponse getPosition(final long memberId, final long teamId) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
return MemberTeamPositionGetResponse.from(memberTeamManager.getPosition());
}

@Transactional
public void updateTeamMemberName(final long memberId, final long teamId, final String name) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManager.setName(name);
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
memberTeamManager.updateName(name);
}
}
18 changes: 8 additions & 10 deletions src/main/java/com/tiki/server/note/service/NoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.tiki.server.document.entity.Document;
import com.tiki.server.member.adapter.MemberFinder;
import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder;
import com.tiki.server.memberteammanager.entity.MemberTeamManager;
import com.tiki.server.note.adapter.NoteDeleter;
import com.tiki.server.note.adapter.NoteFinder;
import com.tiki.server.note.adapter.NoteSaver;
Expand All @@ -32,7 +31,6 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.tiki.server.common.Constants.INIT_NUM;
import static com.tiki.server.note.constants.NoteConstants.PAGE_SIZE;
Expand All @@ -57,7 +55,7 @@ public class NoteService {

@Transactional
public NoteCreateServiceResponse createNoteFree(final NoteFreeCreateServiceRequest request) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId());
memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId());
String encryptedContents = ContentEncoder.encodeNoteFree(request.contents());
Note note = createNote(NoteBase.of(request), encryptedContents, NoteType.FREE);
createNoteTimeBlockManagers(request.timeBlockIds(), note.getId());
Expand All @@ -67,7 +65,7 @@ public NoteCreateServiceResponse createNoteFree(final NoteFreeCreateServiceReque

@Transactional
public NoteCreateServiceResponse createNoteTemplate(final NoteTemplateCreateServiceRequest request) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId());
memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId());
String encryptedContents = ContentEncoder.encodeNoteTemplate(
request.answerWhatActivity(),
request.answerHowToPrepare(),
Expand All @@ -83,7 +81,7 @@ public NoteCreateServiceResponse createNoteTemplate(final NoteTemplateCreateServ
@Transactional
public void updateNoteFree(final NoteFreeUpdateServiceRequest request) {
Note note = noteFinder.findById(request.noteId());
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId());
memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId());
String encryptedContents = ContentEncoder.encodeNoteFree(request.contents());
note.updateValue(
request.memberId(),
Expand All @@ -102,7 +100,7 @@ public void updateNoteFree(final NoteFreeUpdateServiceRequest request) {
@Transactional
public void updateNoteTemplate(final NoteTemplateUpdateServiceRequest request) {
Note note = noteFinder.findById(request.noteId());
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(request.memberId(), request.teamId());
memberTeamManagerFinder.findByMemberIdAndTeamId(request.memberId(), request.teamId());
String encryptedContents = ContentEncoder.encodeNoteTemplate(
request.answerWhatActivity(),
request.answerHowToPrepare(),
Expand All @@ -125,7 +123,7 @@ public void updateNoteTemplate(final NoteTemplateUpdateServiceRequest request) {

@Transactional
public void deleteNotes(final List<Long> noteIds, final long teamId, final long memberId) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
noteDocumentManagerDeleter.deleteByNoteIds(noteIds);
noteTimeBlockManagerDeleter.noteTimeBlockManagerDeleteByIds(noteIds);
noteDeleter.deleteNoteByIds(noteIds);
Expand All @@ -137,7 +135,7 @@ public NoteListGetServiceResponse getNote(
final LocalDateTime createdAt,
final SortOrder sortOrder
) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
PageRequest pageable = PageRequest.of(INIT_NUM, PAGE_SIZE);
List<Note> noteList = getNotes(createdAt, sortOrder, pageable, teamId);
List<NoteGetResponse> noteGetResponses = noteList.stream()
Expand All @@ -147,7 +145,7 @@ public NoteListGetServiceResponse getNote(
}

public NoteDetailGetServiceResponse getNoteDetail(final long teamId, final long memberId, final long noteId) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Note note = noteFinder.findById(noteId);
List<Document> documentList = getDocumentListMappedByNote(noteId);
List<TimeBlock> timeBlockList = getTimeBlocksMappedByNote(noteId);
Expand All @@ -159,7 +157,7 @@ public NoteDetailGetServiceResponse getNoteDetail(final long teamId, final long

private String getMemberName(final Long noteMemberId, final long teamId) {
return Optional.ofNullable(noteMemberId)
.map(id -> memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(id, teamId).getName())
.map(id -> memberTeamManagerFinder.findByMemberIdAndTeamId(id, teamId).getName())
.orElse("알 수 없음");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,35 @@ public ResponseEntity<BaseResponse> deleteTeam(
}

@PatchMapping("/{teamId}/name")
public ResponseEntity<SuccessResponse<Void>> updateTeamName(
public ResponseEntity<BaseResponse> updateTeamName(
final Principal principal,
@PathVariable final long teamId,
@RequestBody final UpdateTeamNameRequest request
) {
long memberId = Long.parseLong(principal.getName());
teamService.updateTeamName(memberId, teamId, request.newTeamName());
return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_NAME.getMessage(), null));
return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_NAME.getMessage()));
}

@PatchMapping("/{teamId}/icon")
public ResponseEntity<SuccessResponse<Void>> updateIconImage(
public ResponseEntity<BaseResponse> updateIconImage(
final Principal principal,
@PathVariable final long teamId,
@RequestBody final UpdateTeamIconRequest request
) {
long memberId = Long.parseLong(principal.getName());
teamService.updateIconImage(memberId, teamId, request.iconImageUrl());
return ResponseEntity.ok().body(success(SUCCESS_UPDATE_TEAM_ICON.getMessage(), null));
return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_ICON.getMessage()));
}

@PatchMapping("/{teamId}/member/{targetId}/admin")
public ResponseEntity<SuccessResponse<Void>> alterAdmin(
public ResponseEntity<BaseResponse> alterAdmin(
final Principal principal,
@PathVariable final long teamId,
@PathVariable final long targetId
) {
long memberId = Long.parseLong(principal.getName());
teamService.alterAdmin(memberId, teamId, targetId);
return ResponseEntity.ok().body(success(SUCCESS_ALTER_AUTHORITY.getMessage(), null));
return ResponseEntity.ok(success(SUCCESS_ALTER_AUTHORITY.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tiki.server.team.controller.dto.request;

import jakarta.validation.constraints.NotNull;

public record UpdateTeamIconRequest(
String iconImageUrl
@NotNull String iconImageUrl
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tiki.server.team.controller.dto.request;

import jakarta.validation.constraints.NotNull;

public record UpdateTeamNameRequest(
String newTeamName
@NotNull String newTeamName
) {
}
Loading

0 comments on commit a2dce31

Please sign in to comment.