diff --git a/src/main/java/com/tiki/server/document/service/DocumentService.java b/src/main/java/com/tiki/server/document/service/DocumentService.java index 2acadc30..355b48fd 100644 --- a/src/main/java/com/tiki/server/document/service/DocumentService.java +++ b/src/main/java/com/tiki/server/document/service/DocumentService.java @@ -39,7 +39,7 @@ 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); @@ -47,7 +47,7 @@ public DocumentsGetResponse getAllDocuments(final long memberId, final long team @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); @@ -56,21 +56,21 @@ 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 documents = documentFinder.findByTeamIdAndFolderId(teamId, folderId); return DocumentsGetResponse.from(documents); } @Transactional public void delete(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List documents = documentFinder.findAllByIdAndTeamId(documentIds, teamId); deletedDocumentAdapter.save(documents); documentDeleter.deleteAll(documents); @@ -78,21 +78,21 @@ public void delete(final long memberId, final long teamId, final List docu @Transactional public void deleteTrash(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId); deletedDocumentAdapter.deleteAll(deletedDocuments); } @Transactional public void restore(final long memberId, final long teamId, final List documentIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List 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 deletedDocuments = deletedDocumentAdapter.get(teamId); return DeletedDocumentsGetResponse.from(deletedDocuments); } diff --git a/src/main/java/com/tiki/server/external/controller/S3Controller.java b/src/main/java/com/tiki/server/external/controller/S3Controller.java index 96b9b31a..8f32f5ac 100644 --- a/src/main/java/com/tiki/server/external/controller/S3Controller.java +++ b/src/main/java/com/tiki/server/external/controller/S3Controller.java @@ -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; @@ -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; diff --git a/src/main/java/com/tiki/server/external/service/S3Service.java b/src/main/java/com/tiki/server/external/service/S3Service.java new file mode 100644 index 00000000..c07eb796 --- /dev/null +++ b/src/main/java/com/tiki/server/external/service/S3Service.java @@ -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()); + } +} diff --git a/src/main/java/com/tiki/server/external/util/S3Service.java b/src/main/java/com/tiki/server/external/util/S3Handler.java similarity index 96% rename from src/main/java/com/tiki/server/external/util/S3Service.java rename to src/main/java/com/tiki/server/external/util/S3Handler.java index abbd5306..69cd42ce 100644 --- a/src/main/java/com/tiki/server/external/util/S3Service.java +++ b/src/main/java/com/tiki/server/external/util/S3Handler.java @@ -25,7 +25,7 @@ @Component @RequiredArgsConstructor -public class S3Service { +public class S3Handler { private final AWSConfig awsConfig; @@ -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) { diff --git a/src/main/java/com/tiki/server/folder/service/FolderService.java b/src/main/java/com/tiki/server/folder/service/FolderService.java index 2be875a0..5dfb46f6 100644 --- a/src/main/java/com/tiki/server/folder/service/FolderService.java +++ b/src/main/java/com/tiki/server/folder/service/FolderService.java @@ -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 folders = folderFinder.findByTeamIdAndPath(teamId, path); @@ -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); @@ -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 folderIds) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); List folders = folderFinder.findAllById(folderIds, teamId); deleteFolders(folders); } diff --git a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java index 84ff2bb4..38b726fa 100644 --- a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java +++ b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java @@ -10,7 +10,6 @@ import lombok.RequiredArgsConstructor; import java.util.List; -import java.util.Optional; @RepositoryAdapter @RequiredArgsConstructor @@ -18,15 +17,11 @@ 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 findByMemberIdAndTeamId(final long memberId, final long teamId) { - return memberTeamManagerRepository.findByMemberIdAndTeamId(memberId, teamId); - } - public List findBelongTeamByMemberId(long memberId) { return memberTeamManagerRepository.findAllBelongTeamByMemberId(memberId).stream().toList(); } diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java new file mode 100644 index 00000000..04d38414 --- /dev/null +++ b/src/main/java/com/tiki/server/memberteammanager/controller/MemberTeamController.java @@ -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> 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 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())); + } +} diff --git a/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java new file mode 100644 index 00000000..9b6fc655 --- /dev/null +++ b/src/main/java/com/tiki/server/memberteammanager/controller/dto/request/UpdateTeamMemberNameRequest.java @@ -0,0 +1,8 @@ +package com.tiki.server.memberteammanager.controller.dto.request; + +import jakarta.validation.constraints.NotNull; + +public record UpdateTeamMemberNameRequest( + @NotNull String newName +) { +} diff --git a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java index d8fe5302..c6e29230 100644 --- a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java +++ b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java @@ -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; + } } diff --git a/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java b/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java index d9a30836..e128e091 100644 --- a/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/memberteammanager/message/SuccessMessage.java @@ -7,7 +7,8 @@ @RequiredArgsConstructor public enum SuccessMessage { - TEMP("컴파일 에러 방지용"); + UPDATE_NAME("팀 내 이름 변경 성공"), + GET_POSITION("직책 불러오기 성공"); private final String message; } diff --git a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java index dde6e437..5ea3a791 100644 --- a/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java +++ b/src/main/java/com/tiki/server/memberteammanager/service/MemberTeamManagerService.java @@ -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; @@ -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); + } } diff --git a/src/main/java/com/tiki/server/memberteammanager/service/dto/response/MemberTeamPositionGetResponse.java b/src/main/java/com/tiki/server/memberteammanager/service/dto/response/MemberTeamPositionGetResponse.java new file mode 100644 index 00000000..8f102320 --- /dev/null +++ b/src/main/java/com/tiki/server/memberteammanager/service/dto/response/MemberTeamPositionGetResponse.java @@ -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); + } +} diff --git a/src/main/java/com/tiki/server/note/service/NoteService.java b/src/main/java/com/tiki/server/note/service/NoteService.java index 3888b4ef..a9be7efc 100644 --- a/src/main/java/com/tiki/server/note/service/NoteService.java +++ b/src/main/java/com/tiki/server/note/service/NoteService.java @@ -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; @@ -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; @@ -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()); @@ -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(), @@ -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(), @@ -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(), @@ -125,7 +123,7 @@ public void updateNoteTemplate(final NoteTemplateUpdateServiceRequest request) { @Transactional public void deleteNotes(final List noteIds, final long teamId, final long memberId) { - memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); noteDocumentManagerDeleter.deleteByNoteIds(noteIds); noteTimeBlockManagerDeleter.noteTimeBlockManagerDeleteByIds(noteIds); noteDeleter.deleteNoteByIds(noteIds); @@ -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 noteList = getNotes(createdAt, sortOrder, pageable, teamId); List noteGetResponses = noteList.stream() @@ -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 documentList = getDocumentListMappedByNote(noteId); List timeBlockList = getTimeBlocksMappedByNote(noteId); @@ -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("알 수 없음"); } diff --git a/src/main/java/com/tiki/server/team/controller/TeamController.java b/src/main/java/com/tiki/server/team/controller/TeamController.java index a39c4ba9..22a31e1e 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -6,6 +6,8 @@ import java.security.Principal; import com.tiki.server.common.dto.BaseResponse; +import com.tiki.server.team.controller.dto.request.UpdateTeamIconRequest; +import com.tiki.server.team.controller.dto.request.UpdateTeamNameRequest; import com.tiki.server.team.dto.response.CategoriesGetResponse; import com.tiki.server.team.dto.response.TeamsGetResponse; @@ -26,43 +28,76 @@ @RequestMapping("api/v1/teams") public class TeamController implements TeamControllerDocs { - private final TeamService teamService; + private final TeamService teamService; - @Override - @PostMapping - public ResponseEntity> createTeam( - Principal principal, - @RequestBody TeamCreateRequest request - ) { - long memberId = Long.parseLong(principal.getName()); - TeamCreateResponse response = teamService.createTeam(memberId, request); - return ResponseEntity.created( - UriGenerator.getUri("/api/v1/teams/" + response.teamId()) - ).body(success(SUCCESS_CREATE_TEAM.getMessage(), response)); - } + @Override + @PostMapping + public ResponseEntity> createTeam( + final Principal principal, + @RequestBody final TeamCreateRequest request + ) { + long memberId = Long.parseLong(principal.getName()); + TeamCreateResponse response = teamService.createTeam(memberId, request); + return ResponseEntity.created( + UriGenerator.getUri("/api/v1/teams/" + response.teamId()) + ).body(success(SUCCESS_CREATE_TEAM.getMessage(), response)); + } - @Override - @GetMapping - public ResponseEntity> getAllTeams(Principal principal) { - long memberId = Long.parseLong(principal.getName()); - TeamsGetResponse response = teamService.getAllTeams(memberId); - return ResponseEntity.ok().body(success(SUCCESS_GET_TEAMS.getMessage(), response)); - } + @Override + @GetMapping + public ResponseEntity> getAllTeams(final Principal principal) { + long memberId = Long.parseLong(principal.getName()); + TeamsGetResponse response = teamService.getAllTeams(memberId); + return ResponseEntity.ok().body(success(SUCCESS_GET_TEAMS.getMessage(), response)); + } - @Override - @GetMapping("/category") - public ResponseEntity> getCategories() { - CategoriesGetResponse response = teamService.getCategories(); - return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); - } + @Override + @GetMapping("/category") + public ResponseEntity> getCategories() { + CategoriesGetResponse response = teamService.getCategories(); + return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response)); + } - @DeleteMapping("/{teamId}") - public ResponseEntity deleteTeam( - Principal principal, - @PathVariable long teamId - ) { - long memberId = Long.parseLong(principal.getName()); - teamService.deleteTeam(memberId, teamId); - return ResponseEntity.noContent().build(); - } + @DeleteMapping("/{teamId}") + public ResponseEntity deleteTeam( + final Principal principal, + @PathVariable final long teamId + ) { + long memberId = Long.parseLong(principal.getName()); + teamService.deleteTeam(memberId, teamId); + return ResponseEntity.noContent().build(); + } + + @PatchMapping("/{teamId}/name") + public ResponseEntity 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(success(SUCCESS_UPDATE_TEAM_NAME.getMessage())); + } + + @PatchMapping("/{teamId}/icon") + public ResponseEntity 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(success(SUCCESS_UPDATE_TEAM_ICON.getMessage())); + } + + @PatchMapping("/{teamId}/member/{targetId}/admin") + public ResponseEntity 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(success(SUCCESS_ALTER_AUTHORITY.getMessage())); + } } diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java new file mode 100644 index 00000000..4a0e039a --- /dev/null +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamIconRequest.java @@ -0,0 +1,8 @@ +package com.tiki.server.team.controller.dto.request; + +import jakarta.validation.constraints.NotNull; + +public record UpdateTeamIconRequest( + @NotNull String iconImageUrl +) { +} diff --git a/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java new file mode 100644 index 00000000..278810df --- /dev/null +++ b/src/main/java/com/tiki/server/team/controller/dto/request/UpdateTeamNameRequest.java @@ -0,0 +1,8 @@ +package com.tiki.server.team.controller.dto.request; + +import jakarta.validation.constraints.NotNull; + +public record UpdateTeamNameRequest( + @NotNull String newTeamName +) { +} diff --git a/src/main/java/com/tiki/server/team/entity/Team.java b/src/main/java/com/tiki/server/team/entity/Team.java index 2ce5b3fe..aff50a76 100644 --- a/src/main/java/com/tiki/server/team/entity/Team.java +++ b/src/main/java/com/tiki/server/team/entity/Team.java @@ -26,31 +26,43 @@ @NoArgsConstructor(access = PROTECTED) public class Team extends BaseTime { - @Id - @GeneratedValue(strategy = IDENTITY) - @Column(name = "team_id") - private Long id; + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "team_id") + private Long id; - private String name; + private String name; - private String overview; + private String overview; - @Enumerated(value = STRING) - private Category category; + @Enumerated(value = STRING) + private Category category; - @Enumerated(value = STRING) - private University univ; + @Enumerated(value = STRING) + private University univ; - private String imageUrl; + private String imageUrl; - private String iconImageUrl; + private String iconImageUrl; - public static Team of(TeamCreateRequest request, University univ) { - return Team.builder() - .name(request.name()) - .category(request.category()) - .univ(univ) - .iconImageUrl(request.iconImageUrl()) - .build(); - } + public static Team of(TeamCreateRequest request, University univ) { + return Team.builder() + .name(request.name()) + .category(request.category()) + .univ(univ) + .iconImageUrl(request.iconImageUrl()) + .build(); + } + + public void updateName(final String name) { + this.name = name; + } + + public void setIconImageUrl(final String url) { + this.iconImageUrl = url; + } + + public boolean isDefaultImage() { + return this.getIconImageUrl().isBlank(); + } } diff --git a/src/main/java/com/tiki/server/team/message/SuccessMessage.java b/src/main/java/com/tiki/server/team/message/SuccessMessage.java index 407b5295..7454e072 100644 --- a/src/main/java/com/tiki/server/team/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/team/message/SuccessMessage.java @@ -8,6 +8,9 @@ public enum SuccessMessage { SUCCESS_CREATE_TEAM("팀 생성 성공"), + SUCCESS_UPDATE_TEAM_NAME("팀 이름 변경 성공"), + SUCCESS_UPDATE_TEAM_ICON("팀 아이콘 변경 성공"), + SUCCESS_ALTER_AUTHORITY("어드민 권한 위임 성공"), SUCCESS_GET_TEAMS("전체 팀 불러오기 성공"), SUCCESS_GET_CATEGORIES("카테고리 리스트 불러오기 성공"), SUCCESS_GET_JOINED_TEAM("소속 팀 불러오기 성공"); diff --git a/src/main/java/com/tiki/server/team/service/TeamService.java b/src/main/java/com/tiki/server/team/service/TeamService.java index 89b75c59..2f9724c7 100644 --- a/src/main/java/com/tiki/server/team/service/TeamService.java +++ b/src/main/java/com/tiki/server/team/service/TeamService.java @@ -8,6 +8,7 @@ import com.tiki.server.document.adapter.DocumentDeleter; import com.tiki.server.document.adapter.DocumentFinder; import com.tiki.server.document.entity.Document; +import com.tiki.server.external.util.S3Handler; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerDeleter; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; import com.tiki.server.team.adapter.TeamDeleter; @@ -40,61 +41,89 @@ @Transactional(readOnly = true) public class TeamService { - private final TeamSaver teamSaver; - private final TeamFinder teamFinder; - private final TeamDeleter teamDeleter; - private final MemberFinder memberFinder; - private final DocumentFinder documentFinder; - private final DocumentDeleter documentDeleter; - private final TimeBlockDeleter timeBlockDeleter; - private final MemberTeamManagerFinder memberTeamManagerFinder; - private final MemberTeamManagerDeleter memberTeamManagerDeleter; - private final MemberTeamManagerSaver memberTeamManagerSaver; - - @Transactional - public TeamCreateResponse createTeam(long memberId, TeamCreateRequest request) { - Member member = memberFinder.findById(memberId); - Team team = teamSaver.save(createTeam(request, member.getUniv())); - memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); - return TeamCreateResponse.from(team); - } - - public TeamsGetResponse getAllTeams(long memberId) { - Member member = memberFinder.findById(memberId); - University univ = member.getUniv(); - List team = teamFinder.findAllByUniv(univ); - return TeamsGetResponse.from(team); - } - - public CategoriesGetResponse getCategories() { - Category[] categories = Category.values(); - return CategoriesGetResponse.from(categories); - } - - @Transactional - public void deleteTeam(long memberId, long teamId) { - checkIsAdmin(memberId, teamId); - List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); - memberTeamManagerDeleter.deleteAll(memberTeamManagers); - List documents = documentFinder.findAllByTeamId(teamId); - documentDeleter.deleteAll(documents); - timeBlockDeleter.deleteAllByTeamId(teamId); - teamDeleter.deleteById(teamId); - } - - private Team createTeam(TeamCreateRequest request, University univ) { - return Team.of(request, univ); - } - - private MemberTeamManager createMemberTeamManager(Member member, Team team, Position position) { - return MemberTeamManager.of(member, team, position); - } - - private void checkIsAdmin(long memberId, long teamId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); - if (!memberTeamManager.getPosition().equals(ADMIN)) { - throw new TeamException(INVALID_AUTHORIZATION_DELETE); - } - memberTeamManagerDeleter.delete(memberTeamManager); - } + private final TeamSaver teamSaver; + private final TeamFinder teamFinder; + private final TeamDeleter teamDeleter; + private final MemberFinder memberFinder; + private final DocumentFinder documentFinder; + private final DocumentDeleter documentDeleter; + private final TimeBlockDeleter timeBlockDeleter; + private final MemberTeamManagerFinder memberTeamManagerFinder; + private final MemberTeamManagerDeleter memberTeamManagerDeleter; + private final MemberTeamManagerSaver memberTeamManagerSaver; + private final S3Handler s3Handler; + + @Transactional + public TeamCreateResponse createTeam(final long memberId, final TeamCreateRequest request) { + Member member = memberFinder.findById(memberId); + Team team = teamSaver.save(createTeam(request, member.getUniv())); + memberTeamManagerSaver.save(createMemberTeamManager(member, team, ADMIN)); + return TeamCreateResponse.from(team); + } + + public TeamsGetResponse getAllTeams(final long memberId) { + Member member = memberFinder.findById(memberId); + University univ = member.getUniv(); + List team = teamFinder.findAllByUniv(univ); + return TeamsGetResponse.from(team); + } + + public CategoriesGetResponse getCategories() { + Category[] categories = Category.values(); + return CategoriesGetResponse.from(categories); + } + + @Transactional + public void deleteTeam(final long memberId, final long teamId) { + checkIsAdmin(memberId, teamId); + List memberTeamManagers = memberTeamManagerFinder.findAllByTeamId(teamId); + memberTeamManagerDeleter.deleteAll(memberTeamManagers); + List documents = documentFinder.findAllByTeamId(teamId); + documentDeleter.deleteAll(documents); + timeBlockDeleter.deleteAllByTeamId(teamId); + teamDeleter.deleteById(teamId); + } + + @Transactional + public void updateTeamName(final long memberId, final long teamId, final String newTeamName) { + checkIsAdmin(memberId, teamId); + Team team = teamFinder.findById(teamId); + team.updateName(newTeamName); + } + + @Transactional + public void updateIconImage(final long memberId, final long teamId, final String iconImageUrl) { + checkIsAdmin(memberId, teamId); + Team team = teamFinder.findById(teamId); + deleteIconUrl(team); + team.setIconImageUrl(iconImageUrl); + } + + @Transactional + public void alterAdmin(final long memberId, final long teamId, final long targetId) { + MemberTeamManager oldAdmin = checkIsAdmin(memberId, teamId); + MemberTeamManager newAdmin = memberTeamManagerFinder.findByMemberIdAndTeamId(targetId, teamId); + oldAdmin.updatePositionToExecutive(); + newAdmin.updatePositionToAdmin(); + } + + private Team createTeam(final TeamCreateRequest request, final University univ) { + return Team.of(request, univ); + } + + private void deleteIconUrl(final Team team) { + if (!team.isDefaultImage()) { + s3Handler.deleteFile(team.getIconImageUrl()); + } + } + + private MemberTeamManager createMemberTeamManager(final Member member, final Team team, final Position position) { + return MemberTeamManager.of(member, team, position); + } + + private MemberTeamManager checkIsAdmin(final long memberId, final long teamId) { + MemberTeamManager accessMember = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); + accessMember.checkMemberAccessible(ADMIN); + return accessMember; + } } diff --git a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java index cf2262f7..66169dd6 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -54,7 +54,7 @@ public TimeBlockCreateResponse createTimeBlock( TimeBlockCreateRequest request ) { Team team = teamFinder.findById(teamId); - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); TimeBlock timeBlock = saveTimeBlock(team, accessiblePosition, request); @@ -64,7 +64,7 @@ public TimeBlockCreateResponse createTimeBlock( public TimelineGetResponse getTimeline(long memberId, long teamId, String type, String date) { Team team = teamFinder.findById(teamId); - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); Position accessiblePosition = Position.getAccessiblePosition(type); memberTeamManager.checkMemberAccessible(accessiblePosition); List timeBlocks = timeBlockFinder.findByTeamAndAccessiblePositionAndDate( @@ -73,7 +73,7 @@ public TimelineGetResponse getTimeline(long memberId, long teamId, String type, } public TimeBlockDetailGetResponse getTimeBlockDetail(long memberId, long teamId, long timeBlockId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); TimeBlock timeBlock = timeBlockFinder.findByIdOrElseThrow(timeBlockId); memberTeamManager.checkMemberAccessible(timeBlock.getAccessiblePosition()); List documents = documentFinder.findAllByTimeBlockId(timeBlockId); @@ -83,7 +83,7 @@ public TimeBlockDetailGetResponse getTimeBlockDetail(long memberId, long teamId, @Transactional public void deleteTimeBlock(long memberId, long teamId, long timeBlockId) { - MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); TimeBlock timeBlock = timeBlockFinder.findByIdOrElseThrow(timeBlockId); memberTeamManager.checkMemberAccessible(timeBlock.getAccessiblePosition()); documentDeleter.deleteAllByTimeBlockId(timeBlock.getId());