Skip to content

Commit

Permalink
Merge pull request #185 from Team-Tiki/feat-#182-workspace-setting
Browse files Browse the repository at this point in the history
[FEAT] 워크스페이스 설정 기능들 추가
  • Loading branch information
paragon0107 authored Dec 2, 2024
2 parents 73fb9eb + a2dce31 commit eae4759
Show file tree
Hide file tree
Showing 20 changed files with 351 additions and 148 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 @@ -4,6 +4,7 @@
import static com.tiki.server.external.message.SuccessMessage.PRESIGNED_URL_GET_SUCCESS;
import static com.tiki.server.external.message.SuccessMessage.S3_FILE_DELETE_SUCCESS;

import com.tiki.server.external.service.S3Service;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -17,7 +18,6 @@
import com.tiki.server.external.controller.docs.S3ControllerDocs;
import com.tiki.server.external.dto.request.S3DeleteRequest;
import com.tiki.server.external.dto.response.PreSignedUrlResponse;
import com.tiki.server.external.util.S3Service;

import lombok.RequiredArgsConstructor;

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/tiki/server/external/service/S3Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tiki.server.external.service;

import com.tiki.server.external.dto.request.S3DeleteRequest;
import com.tiki.server.external.dto.response.PreSignedUrlResponse;
import com.tiki.server.external.util.S3Handler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class S3Service {

private final S3Handler s3Handler;

public PreSignedUrlResponse getUploadPreSignedUrl(String fileFormat) {
return s3Handler.getUploadPreSignedUrl(fileFormat);
}

public void deleteFile(S3DeleteRequest request) {
s3Handler.deleteFile(request.fileName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@Component
@RequiredArgsConstructor
public class S3Service {
public class S3Handler {

private final AWSConfig awsConfig;

Expand All @@ -46,12 +46,12 @@ public PreSignedUrlResponse getUploadPreSignedUrl(String fileFormat) {
}
}

public void deleteFile(S3DeleteRequest request) {
public void deleteFile(String request) {
try {
S3Client s3Client = awsConfig.getS3Client();
s3Client.deleteObject((DeleteObjectRequest.Builder builder) ->
builder.bucket(bucket)
.key(request.fileName())
.key(request)
.build()
);
} catch (RuntimeException e) {
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
@@ -0,0 +1,45 @@
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;
import com.tiki.server.memberteammanager.service.dto.response.MemberTeamPositionGetResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

import static com.tiki.server.common.dto.SuccessResponse.success;
import static com.tiki.server.memberteammanager.message.SuccessMessage.GET_POSITION;
import static com.tiki.server.memberteammanager.message.SuccessMessage.UPDATE_NAME;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/team-member")
public class MemberTeamController {

private final MemberTeamManagerService memberTeamManagerService;

@GetMapping("/teams/{teamId}/members/position")
public ResponseEntity<SuccessResponse<MemberTeamPositionGetResponse>> getMemberTeamPosition(
final Principal principal,
@PathVariable final long teamId
) {
long memberId = Long.parseLong(principal.getName());
MemberTeamPositionGetResponse response = memberTeamManagerService.getPosition(memberId, teamId);
return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), response));
}

@PatchMapping("/teams/{teamId}/members/name")
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(success(UPDATE_NAME.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.tiki.server.memberteammanager.controller.dto.request;

import jakarta.validation.constraints.NotNull;

public record UpdateTeamMemberNameRequest(
@NotNull String newName
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ public void checkMemberAccessible(Position accesiblePosition) {
throw new MemberTeamManagerException(INVALID_AUTHORIZATION);
}
}

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

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

public void updatePositionToAdmin(){
this.position = Position.ADMIN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@RequiredArgsConstructor
public enum SuccessMessage {

TEMP("컴파일 에러 방지용");
UPDATE_NAME("팀 내 이름 변경 성공"),
GET_POSITION("직책 불러오기 성공");

private final String message;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.tiki.server.memberteammanager.service;

import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder;
import com.tiki.server.memberteammanager.entity.MemberTeamManager;
import com.tiki.server.memberteammanager.service.dto.response.MemberTeamPositionGetResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -9,4 +12,17 @@
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MemberTeamManagerService {

private final MemberTeamManagerFinder memberTeamManagerFinder;

public MemberTeamPositionGetResponse getPosition(final long memberId, final long 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.findByMemberIdAndTeamId(memberId, teamId);
memberTeamManager.updateName(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tiki.server.memberteammanager.service.dto.response;

import com.tiki.server.common.entity.Position;

public record MemberTeamPositionGetResponse(
Position position
) {
public static MemberTeamPositionGetResponse from(Position position) {
return new MemberTeamPositionGetResponse(position);
}
}
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
Loading

0 comments on commit eae4759

Please sign in to comment.