From d266b921d3b8788e6400e485f3ed20d9e105266f Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 03:03:39 +0900 Subject: [PATCH 01/35] =?UTF-8?q?[ADD]=20=ED=83=80=EC=9E=84=20=EB=B8=94?= =?UTF-8?q?=EB=A1=9D=20=EC=83=9D=EC=84=B1=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeblock/dto/request/TimeBlockCreationRequest.java | 4 ++++ .../timeblock/dto/response/TimeBlockCreationResponse.java | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java create mode 100644 src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java diff --git a/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java new file mode 100644 index 00000000..633f68dd --- /dev/null +++ b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java @@ -0,0 +1,4 @@ +package com.tiki.server.timeblock.dto.request; + +public record TimeBlockCreationRequest() { +} diff --git a/src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java b/src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java new file mode 100644 index 00000000..d7f22a58 --- /dev/null +++ b/src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java @@ -0,0 +1,4 @@ +package com.tiki.server.timeblock.dto.response; + +public record TimeBlockCreationResponse() { +} From 578a15e25d85405449a7f4e24879b162b8a579cf Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 03:03:47 +0900 Subject: [PATCH 02/35] =?UTF-8?q?[CHORE]=20=EC=9E=84=EC=8B=9C=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TimeBlockController.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java index b5a24987..292d0fd8 100644 --- a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java +++ b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java @@ -1,11 +1,20 @@ package com.tiki.server.timeblock.controller; +import java.security.Principal; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse; import com.tiki.server.timeblock.service.TimeBlockService; import lombok.RequiredArgsConstructor; +import lombok.val; @RestController @RequiredArgsConstructor @@ -13,4 +22,16 @@ public class TimeBlockController { private final TimeBlockService timeBlockService; + + @PostMapping("/team/{teamId}/time-block") + public ResponseEntity createTimeBlock( + Principal principal, + @PathVariable("teamId") long teamId, + @RequestParam String type, + @RequestBody + ) { + val memberId = Long.valueOf(principal.getName()); + val response = timeBlockService.createTimeBlock() + return ResponseEntity.created(URI); + } } From b83a62382f4562d6cefa4d8677d7671048f67785 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 20:42:54 +0900 Subject: [PATCH 03/35] =?UTF-8?q?[INIT]=20URI=20generator=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/support/UriGenerator.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/tiki/server/common/support/UriGenerator.java diff --git a/src/main/java/com/tiki/server/common/support/UriGenerator.java b/src/main/java/com/tiki/server/common/support/UriGenerator.java new file mode 100644 index 00000000..4c34d24e --- /dev/null +++ b/src/main/java/com/tiki/server/common/support/UriGenerator.java @@ -0,0 +1,26 @@ +package com.tiki.server.common.support; + +import java.net.URI; + +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +@Component +public class UriGenerator { + + public static URI getUri(String path, long id) { + return ServletUriComponentsBuilder + .fromCurrentRequest() + .path(path + id) + .buildAndExpand() + .toUri(); + } + + public static URI getUri(String path) { + return ServletUriComponentsBuilder + .fromCurrentRequest() + .path(path) + .buildAndExpand() + .toUri(); + } +} From e091064eecab1298b5aec0bc5d07c1c941786c8c Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 20:43:09 +0900 Subject: [PATCH 04/35] =?UTF-8?q?[FEAT]=20=EB=A9=A4=EB=B2=84=20=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tiki/server/member/adapter/MemberFinder.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/tiki/server/member/adapter/MemberFinder.java b/src/main/java/com/tiki/server/member/adapter/MemberFinder.java index 7371615b..70e06408 100644 --- a/src/main/java/com/tiki/server/member/adapter/MemberFinder.java +++ b/src/main/java/com/tiki/server/member/adapter/MemberFinder.java @@ -1,7 +1,14 @@ package com.tiki.server.member.adapter; +import static com.tiki.server.member.message.ErrorCode.INVALID_MEMBER; +import static com.tiki.server.team.message.ErrorCode.INVALID_TEAM; + import com.tiki.server.common.support.RepositoryAdapter; +import com.tiki.server.member.entity.Member; +import com.tiki.server.member.exception.MemberException; import com.tiki.server.member.repository.MemberRepository; +import com.tiki.server.team.entity.Team; +import com.tiki.server.team.exception.TeamException; import lombok.RequiredArgsConstructor; @@ -10,4 +17,9 @@ public class MemberFinder { private final MemberRepository memberRepository; + + public Member findById(long memberId) { + return memberRepository.findById(memberId) + .orElseThrow(() -> new MemberException(INVALID_MEMBER)); + } } From 34006f549dcdc37ed51d5d8829c40f35a4a63191 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 20:43:14 +0900 Subject: [PATCH 05/35] =?UTF-8?q?[FEAT]=20=ED=8C=80=20=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/team/adapter/TeamFinder.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/tiki/server/team/adapter/TeamFinder.java b/src/main/java/com/tiki/server/team/adapter/TeamFinder.java index 0c88eab6..bd4abf33 100644 --- a/src/main/java/com/tiki/server/team/adapter/TeamFinder.java +++ b/src/main/java/com/tiki/server/team/adapter/TeamFinder.java @@ -1,6 +1,10 @@ package com.tiki.server.team.adapter; +import static com.tiki.server.team.message.ErrorCode.INVALID_TEAM; + import com.tiki.server.common.support.RepositoryAdapter; +import com.tiki.server.team.entity.Team; +import com.tiki.server.team.exception.TeamException; import com.tiki.server.team.repository.TeamRepository; import lombok.RequiredArgsConstructor; @@ -10,4 +14,9 @@ public class TeamFinder { private final TeamRepository teamRepository; + + public Team findById(long teamId) { + return teamRepository.findById(teamId) + .orElseThrow(() -> new TeamException(INVALID_TEAM)); + } } From 46cb801d1ffe2c7146b5bfadc10c95a0b433080c Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 20:43:27 +0900 Subject: [PATCH 06/35] =?UTF-8?q?[FEAT]=20=EB=A9=A4=EB=B2=84=20=ED=8C=80?= =?UTF-8?q?=20=EA=B4=80=EB=A6=AC=EC=9E=90=20=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MemberTeamManagerRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/tiki/server/memberteammanager/repository/MemberTeamManagerRepository.java b/src/main/java/com/tiki/server/memberteammanager/repository/MemberTeamManagerRepository.java index 8ac15d84..58cf4be2 100644 --- a/src/main/java/com/tiki/server/memberteammanager/repository/MemberTeamManagerRepository.java +++ b/src/main/java/com/tiki/server/memberteammanager/repository/MemberTeamManagerRepository.java @@ -1,8 +1,11 @@ package com.tiki.server.memberteammanager.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import com.tiki.server.memberteammanager.entity.MemberTeamManager; public interface MemberTeamManagerRepository extends JpaRepository { + Optional findByMemberIdAndTeamId(Long memberId, Long teamId); } From 3e24e65ab6b80db399a25bdcfe9b62989b326993 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 20:43:44 +0900 Subject: [PATCH 07/35] =?UTF-8?q?[FEAT]=20=EB=A9=A4=EB=B2=84=20=ED=8C=80?= =?UTF-8?q?=20=EA=B4=80=EB=A6=AC=EC=9E=90=20=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/MemberTeamManagerFinder.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 70ad2a7b..d84ca318 100644 --- a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java +++ b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java @@ -1,6 +1,10 @@ package com.tiki.server.memberteammanager.adapter; +import static com.tiki.server.memberteammanager.message.ErrorCode.TEMP; + import com.tiki.server.common.support.RepositoryAdapter; +import com.tiki.server.memberteammanager.entity.MemberTeamManager; +import com.tiki.server.memberteammanager.exception.MemberTeamManagerException; import com.tiki.server.memberteammanager.repository.MemberTeamManagerRepository; import lombok.RequiredArgsConstructor; @@ -10,4 +14,9 @@ public class MemberTeamManagerFinder { private final MemberTeamManagerRepository teamManagerRepository; + + public MemberTeamManager findByMemberIdAndTeamId(long memberId, long teamId) { + return teamManagerRepository.findByMemberIdAndTeamId(memberId, teamId) + .orElseThrow(() -> new MemberTeamManagerException(TEMP)); + } } From 2e97285316d5b7c57a2009f983f537e9e5daf402 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 20:44:03 +0900 Subject: [PATCH 08/35] =?UTF-8?q?[CHORE]=20=EB=B3=91=ED=95=A9=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=9E=84=EC=8B=9C=20=EC=BB=A4=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TimeBlockController.java | 10 +++++--- .../timeblock/service/TimeBlockService.java | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java index 292d0fd8..581d3d6c 100644 --- a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java +++ b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java @@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.tiki.server.common.support.UriGenerator; +import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest; import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse; import com.tiki.server.timeblock.service.TimeBlockService; @@ -28,10 +30,12 @@ public ResponseEntity createTimeBlock( Principal principal, @PathVariable("teamId") long teamId, @RequestParam String type, - @RequestBody + @RequestBody TimeBlockCreationRequest request ) { val memberId = Long.valueOf(principal.getName()); - val response = timeBlockService.createTimeBlock() - return ResponseEntity.created(URI); + val response = timeBlockService.createTimeBlock(memberId, teamId, type, request); + return ResponseEntity.created( + UriGenerator.getUri("/api/v1/time-blocks/team/{teamId}/time-block", response.timeBlockId()) + ); } } 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 c4447358..748a68cb 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -3,10 +3,35 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.tiki.server.member.adapter.MemberFinder; +import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; +import com.tiki.server.team.adapter.TeamFinder; +import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest; +import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse; + import lombok.RequiredArgsConstructor; +import lombok.val; @Service @RequiredArgsConstructor @Transactional(readOnly = true) public class TimeBlockService { + + private final MemberFinder memberFinder; + private final TeamFinder teamFinder; + private final MemberTeamManagerFinder memberTeamManagerFinder; + + public TimeBlockCreationResponse createTimeBlock(long memberId, long teamId, String type, TimeBlockCreationRequest request) { + val member = memberFinder.findById(memberId); + val team = teamFinder.findById(teamId); + val position = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId).getPosition(); + } + + private TimeBlockCreationResponse createExecutiveTimeBlock() { + + } + + private TimeBlockCreationResponse createMemberTimeBlock() { + + } } From 8fe9f3402da4babde390adf1c98f2d0963168f42 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 10 Jul 2024 21:54:32 +0900 Subject: [PATCH 09/35] =?UTF-8?q?[FIX]=20Team=20=EC=B9=BC=EB=9F=BC=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tiki/server/team/entity/{TeamType.java => Group.java} | 2 +- src/main/java/com/tiki/server/team/entity/Team.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/com/tiki/server/team/entity/{TeamType.java => Group.java} (72%) diff --git a/src/main/java/com/tiki/server/team/entity/TeamType.java b/src/main/java/com/tiki/server/team/entity/Group.java similarity index 72% rename from src/main/java/com/tiki/server/team/entity/TeamType.java rename to src/main/java/com/tiki/server/team/entity/Group.java index 118df65b..c0f718b0 100644 --- a/src/main/java/com/tiki/server/team/entity/TeamType.java +++ b/src/main/java/com/tiki/server/team/entity/Group.java @@ -1,5 +1,5 @@ package com.tiki.server.team.entity; -public enum TeamType { +public enum Group { ALLIANCE, UNIVERSITY } 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 bcaf60c0..d90efe07 100644 --- a/src/main/java/com/tiki/server/team/entity/Team.java +++ b/src/main/java/com/tiki/server/team/entity/Team.java @@ -31,7 +31,7 @@ public class Team extends BaseTime { private Category category; @Enumerated(value = STRING) - private TeamType teamType; + private Group group; private String imageUrl; From ead0e2af34e3e6d7c28edea943acd3e9928cd896 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:08:18 +0900 Subject: [PATCH 10/35] =?UTF-8?q?[CHORE]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20import=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/team/controller/TeamController.java | 2 -- 1 file changed, 2 deletions(-) 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 113e80c9..e3df8838 100644 --- a/src/main/java/com/tiki/server/team/controller/TeamController.java +++ b/src/main/java/com/tiki/server/team/controller/TeamController.java @@ -1,7 +1,5 @@ package com.tiki.server.team.controller; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; From 5bfb04a0c86a365dc833f6ae68635e6ebb36c51e Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:09:35 +0900 Subject: [PATCH 11/35] =?UTF-8?q?[ADD]=20Position=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=88=9C=EC=9C=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/common/entity/Position.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tiki/server/common/entity/Position.java b/src/main/java/com/tiki/server/common/entity/Position.java index 4148eda9..c9d25f38 100644 --- a/src/main/java/com/tiki/server/common/entity/Position.java +++ b/src/main/java/com/tiki/server/common/entity/Position.java @@ -1,5 +1,14 @@ package com.tiki.server.common.entity; +import lombok.Getter; + +@Getter public enum Position { - ADMIN, EXECUTIVE, MEMBER, + ADMIN(1), EXECUTIVE(2), MEMBER(3); + + private final int authorization; + + Position(int authorization) { + this.authorization = authorization; + } } From 9eefa41a4b9488bd0e9108b97d140f1e95f925b4 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:10:07 +0900 Subject: [PATCH 12/35] =?UTF-8?q?[ADD]=20TimeBlock=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/timeblock/entity/TimeBlock.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java index 57622663..bdc86087 100644 --- a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java +++ b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java @@ -17,6 +17,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -30,18 +31,35 @@ public class TimeBlock extends BaseTime { @Column(name = "block_id") private Long id; - @ManyToOne(fetch = LAZY) - @JoinColumn(name = "team_id") - private Team team; + private String name; private String color; - private String name; - @Enumerated(value = STRING) private Position accessiblePosition; private LocalDate startDate; private LocalDate endDate; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "team_id") + private Team team; + + @Builder + public TimeBlock( + String name, + String color, + Position accessiblePosition, + LocalDate startDate, + LocalDate endDate, + Team team + ) { + this.name = name; + this.color = color; + this.accessiblePosition = accessiblePosition; + this.startDate = startDate; + this.endDate = endDate; + this.team = team; + } } From 89967488a0aadbd08f10943bd6b9c0d163cabffb Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:10:40 +0900 Subject: [PATCH 13/35] =?UTF-8?q?[ADD]=20TimeBlock=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/TimeBlockCreationRequest.java | 13 ++++++++++++- .../dto/response/TimeBlockCreationResponse.java | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java index 633f68dd..f7332680 100644 --- a/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java +++ b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java @@ -1,4 +1,15 @@ package com.tiki.server.timeblock.dto.request; -public record TimeBlockCreationRequest() { +import java.time.LocalDate; +import java.util.List; + +import lombok.NonNull; + +public record TimeBlockCreationRequest( + @NonNull String name, + @NonNull String color, + @NonNull LocalDate startDate, + @NonNull LocalDate endDate, + List filesUrl +) { } diff --git a/src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java b/src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java index d7f22a58..24a1bb7e 100644 --- a/src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java +++ b/src/main/java/com/tiki/server/timeblock/dto/response/TimeBlockCreationResponse.java @@ -1,4 +1,17 @@ package com.tiki.server.timeblock.dto.response; -public record TimeBlockCreationResponse() { +import static lombok.AccessLevel.PRIVATE; + +import lombok.Builder; + +@Builder(access = PRIVATE) +public record TimeBlockCreationResponse( + long timeBlockId +) { + + public static TimeBlockCreationResponse of(long timeBlockId) { + return TimeBlockCreationResponse.builder() + .timeBlockId(timeBlockId) + .build(); + } } From ae668d57091779fd722b81d19d75c79ec721d003 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:11:00 +0900 Subject: [PATCH 14/35] =?UTF-8?q?[ADD]=20TimeBlock=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tiki/server/timeblock/message/ErrorCode.java | 10 +++++++--- .../tiki/server/timeblock/message/SuccessMessage.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/tiki/server/timeblock/message/ErrorCode.java b/src/main/java/com/tiki/server/timeblock/message/ErrorCode.java index 6c062220..c3252820 100644 --- a/src/main/java/com/tiki/server/timeblock/message/ErrorCode.java +++ b/src/main/java/com/tiki/server/timeblock/message/ErrorCode.java @@ -1,6 +1,7 @@ package com.tiki.server.timeblock.message; -import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.FORBIDDEN; import org.springframework.http.HttpStatus; @@ -11,8 +12,11 @@ @AllArgsConstructor public enum ErrorCode { - /* 404 NOT_FOUND : 자원을 찾을 수 없음 */ - TEMP(NOT_FOUND, "컴파일 에러 방지용 에러입니다."); + /* 400 BAD_REQUEST : 잘못된 요청 */ + INVALID_TYPE(BAD_REQUEST, "유효한 타입이 아닙니다."), + + /* 403 FORBIDDEN : 권한 없음 */ + INVALID_AUTHORIZATION(FORBIDDEN, "타임블록에 대한 권한이 없습니다."); private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java b/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java index 8c74d2c5..44f1bcaa 100644 --- a/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java @@ -7,7 +7,7 @@ @RequiredArgsConstructor public enum SuccessMessage { - TEMP("컴파일 에러 방지용"); + SUCCESS_CREATE_TIME_BLOCK("타임 블록 생성 성공"); private final String message; } From 925828a65c4eed622250845a2f3ed19cede4efef Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:11:21 +0900 Subject: [PATCH 15/35] =?UTF-8?q?[ADD]=20TimeBlock=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=83=81=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/timeblock/constant/TimeBlockConstant.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/tiki/server/timeblock/constant/TimeBlockConstant.java diff --git a/src/main/java/com/tiki/server/timeblock/constant/TimeBlockConstant.java b/src/main/java/com/tiki/server/timeblock/constant/TimeBlockConstant.java new file mode 100644 index 00000000..8ea4fa9d --- /dev/null +++ b/src/main/java/com/tiki/server/timeblock/constant/TimeBlockConstant.java @@ -0,0 +1,7 @@ +package com.tiki.server.timeblock.constant; + +public class TimeBlockConstant { + + public static final String EXECUTIVE = "executive"; + public static final String MEMBER = "member"; +} From 8a8e2b54ec6ba569fd06f814339fc085a952bcc7 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:11:46 +0900 Subject: [PATCH 16/35] =?UTF-8?q?[FEAT]=20=ED=83=80=EC=9E=84=20=EB=B8=94?= =?UTF-8?q?=EB=A1=9D=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeblock/adapter/TimeBlockCreator.java | 18 +++++++ .../controller/TimeBlockController.java | 12 +++-- .../timeblock/service/TimeBlockService.java | 53 ++++++++++++++++--- 3 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/tiki/server/timeblock/adapter/TimeBlockCreator.java diff --git a/src/main/java/com/tiki/server/timeblock/adapter/TimeBlockCreator.java b/src/main/java/com/tiki/server/timeblock/adapter/TimeBlockCreator.java new file mode 100644 index 00000000..70f0ecc8 --- /dev/null +++ b/src/main/java/com/tiki/server/timeblock/adapter/TimeBlockCreator.java @@ -0,0 +1,18 @@ +package com.tiki.server.timeblock.adapter; + +import com.tiki.server.common.support.RepositoryAdapter; +import com.tiki.server.timeblock.entity.TimeBlock; +import com.tiki.server.timeblock.repository.TimeBlockRepository; + +import lombok.RequiredArgsConstructor; + +@RepositoryAdapter +@RequiredArgsConstructor +public class TimeBlockCreator { + + private final TimeBlockRepository timeBlockRepository; + + public TimeBlock createTimeBlock(TimeBlock timeBlock) { + return timeBlockRepository.save(timeBlock); + } +} diff --git a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java index 581d3d6c..fb7ed866 100644 --- a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java +++ b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java @@ -1,5 +1,8 @@ package com.tiki.server.timeblock.controller; +import static com.tiki.server.common.dto.SuccessResponse.*; +import static com.tiki.server.timeblock.message.SuccessMessage.SUCCESS_CREATE_TIME_BLOCK; + import java.security.Principal; import org.springframework.http.ResponseEntity; @@ -10,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.tiki.server.common.dto.SuccessResponse; import com.tiki.server.common.support.UriGenerator; import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest; import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse; @@ -26,16 +30,16 @@ public class TimeBlockController { private final TimeBlockService timeBlockService; @PostMapping("/team/{teamId}/time-block") - public ResponseEntity createTimeBlock( + public ResponseEntity> createTimeBlock( Principal principal, @PathVariable("teamId") long teamId, @RequestParam String type, @RequestBody TimeBlockCreationRequest request ) { - val memberId = Long.valueOf(principal.getName()); + val memberId = Long.parseLong(principal.getName()); val response = timeBlockService.createTimeBlock(memberId, teamId, type, request); return ResponseEntity.created( - UriGenerator.getUri("/api/v1/time-blocks/team/{teamId}/time-block", response.timeBlockId()) - ); + UriGenerator.getUri("/api/v1/time-blocks/team/" + teamId + "/time-block") + ).body(success(SUCCESS_CREATE_TIME_BLOCK.getMessage(), response)); } } 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 748a68cb..3a066226 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -1,13 +1,22 @@ package com.tiki.server.timeblock.service; +import static com.tiki.server.timeblock.message.ErrorCode.INVALID_AUTHORIZATION; +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 org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.tiki.server.member.adapter.MemberFinder; +import com.tiki.server.common.entity.Position; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; import com.tiki.server.team.adapter.TeamFinder; +import com.tiki.server.team.entity.Team; +import com.tiki.server.timeblock.adapter.TimeBlockCreator; import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest; import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse; +import com.tiki.server.timeblock.entity.TimeBlock; +import com.tiki.server.timeblock.exception.TimeBlockException; import lombok.RequiredArgsConstructor; import lombok.val; @@ -17,21 +26,51 @@ @Transactional(readOnly = true) public class TimeBlockService { - private final MemberFinder memberFinder; private final TeamFinder teamFinder; private final MemberTeamManagerFinder memberTeamManagerFinder; + private final TimeBlockCreator timeBlockCreator; - public TimeBlockCreationResponse createTimeBlock(long memberId, long teamId, String type, TimeBlockCreationRequest request) { - val member = memberFinder.findById(memberId); + public TimeBlockCreationResponse createTimeBlock( + long memberId, + long teamId, + String type, + TimeBlockCreationRequest request + ) { val team = teamFinder.findById(teamId); val position = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId).getPosition(); + return switch (type) { + case EXECUTIVE -> createTimeBlockByType(team, Position.EXECUTIVE, position, request); + case MEMBER -> createTimeBlockByType(team, Position.MEMBER, position, request); + default -> throw new TimeBlockException(INVALID_TYPE); + }; } - private TimeBlockCreationResponse createExecutiveTimeBlock() { - + private TimeBlockCreationResponse createTimeBlockByType( + Team team, + Position accessiblePosition, + Position memberPosition, + TimeBlockCreationRequest request + ) { + checkMemberAccessible(accessiblePosition, memberPosition); + val timeBlock = createTimeBlock(team, accessiblePosition, request); + val timeBlockId = timeBlockCreator.createTimeBlock(timeBlock).getId(); + return TimeBlockCreationResponse.of(timeBlockId); } - private TimeBlockCreationResponse createMemberTimeBlock() { + private void checkMemberAccessible(Position accessiblePosition, Position memberPosition) { + if (accessiblePosition.getAuthorization() < memberPosition.getAuthorization()) { + throw new TimeBlockException(INVALID_AUTHORIZATION); + } + } + private TimeBlock createTimeBlock(Team team, Position accessiblePosition, TimeBlockCreationRequest request) { + return TimeBlock.builder() + .name(request.name()) + .color(request.color()) + .accessiblePosition(accessiblePosition) + .startDate(request.startDate()) + .endDate(request.endDate()) + .team(team) + .build(); } } From e78e55c63b874ae473827b4b162ff6172f4c6f89 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:12:16 +0900 Subject: [PATCH 17/35] =?UTF-8?q?[ADD]=20s3=20PresignedUrl=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tiki/server/external/message/ErrorCode.java | 6 ++++-- .../server/external/message/SuccessMessage.java | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/tiki/server/external/message/SuccessMessage.java diff --git a/src/main/java/com/tiki/server/external/message/ErrorCode.java b/src/main/java/com/tiki/server/external/message/ErrorCode.java index 782cba3e..778f8e12 100644 --- a/src/main/java/com/tiki/server/external/message/ErrorCode.java +++ b/src/main/java/com/tiki/server/external/message/ErrorCode.java @@ -1,6 +1,7 @@ package com.tiki.server.external.message; import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import org.springframework.http.HttpStatus; @@ -11,8 +12,9 @@ @AllArgsConstructor public enum ErrorCode { - /* 400 BAD_REQUEST : 잘못된 요청 */ - INVALID_FILE_SIZE(BAD_REQUEST, "파일의 용량은 30MB를 초과할 수 없습니다."); + /* 500 INTERNAL_SERVER_ERROR : 서버 에러 */ + PRESIGNED_URL_GET_ERROR(INTERNAL_SERVER_ERROR, "S3 PRESIGNED URL 불러오기 실패"), + FILE_DELETE_ERROR(INTERNAL_SERVER_ERROR, "S3 버킷의 파일 삭제 실패"); private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/tiki/server/external/message/SuccessMessage.java b/src/main/java/com/tiki/server/external/message/SuccessMessage.java new file mode 100644 index 00000000..9a16e4b8 --- /dev/null +++ b/src/main/java/com/tiki/server/external/message/SuccessMessage.java @@ -0,0 +1,13 @@ +package com.tiki.server.external.message; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum SuccessMessage { + + PRESIGNED_URL_GET_SUCCESS("S3 PRESIGNED URL 불러오기 성공"); + + private final String message; +} From b4db18a9848f3ac51d4d91e4c46e96ddeb5bef42 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:12:43 +0900 Subject: [PATCH 18/35] =?UTF-8?q?[ADD]=20s3=20PresignedUrl=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/PreSignedUrlRequest.java | 8 ++++++++ .../dto/response/PreSignedUrlResponse.java | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/tiki/server/external/dto/request/PreSignedUrlRequest.java create mode 100644 src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java diff --git a/src/main/java/com/tiki/server/external/dto/request/PreSignedUrlRequest.java b/src/main/java/com/tiki/server/external/dto/request/PreSignedUrlRequest.java new file mode 100644 index 00000000..5b631ce9 --- /dev/null +++ b/src/main/java/com/tiki/server/external/dto/request/PreSignedUrlRequest.java @@ -0,0 +1,8 @@ +package com.tiki.server.external.dto.request; + +import lombok.NonNull; + +public record PreSignedUrlRequest( + @NonNull String fileFormat +) { +} diff --git a/src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java b/src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java new file mode 100644 index 00000000..ec51db22 --- /dev/null +++ b/src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java @@ -0,0 +1,19 @@ +package com.tiki.server.external.dto.response; + +import static lombok.AccessLevel.PRIVATE; + +import lombok.Builder; + +@Builder(access = PRIVATE) +public record PreSignedUrlResponse( + String fileName, + String url +) { + + public static PreSignedUrlResponse of(String fileName, String url) { + return PreSignedUrlResponse.builder() + .fileName(fileName) + .url(url) + .build(); + } +} From e0e448a2e4297e60b1bb05862fb25fcc75c3df5a Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:13:05 +0900 Subject: [PATCH 19/35] =?UTF-8?q?[ADD]=20s3=20PresignedUrl=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=83=81=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/external/constant/ExternalConstant.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/tiki/server/external/constant/ExternalConstant.java diff --git a/src/main/java/com/tiki/server/external/constant/ExternalConstant.java b/src/main/java/com/tiki/server/external/constant/ExternalConstant.java new file mode 100644 index 00000000..0c0fbd32 --- /dev/null +++ b/src/main/java/com/tiki/server/external/constant/ExternalConstant.java @@ -0,0 +1,7 @@ +package com.tiki.server.external.constant; + +public class ExternalConstant { + + public static final Long PRE_SIGNED_URL_EXPIRE_MINUTE = 10L; + public static final String FILE_SAVE_PREFIX = "file/"; +} From a4e52f981c94a0efa320c760da750d2b7796bb9f Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:13:39 +0900 Subject: [PATCH 20/35] =?UTF-8?q?[FEAT]=20s3=20PresignedUrl=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../external/controller/S3Controller.java | 31 +++++++++ .../tiki/server/external/util/S3Service.java | 69 ++++++++++--------- 2 files changed, 66 insertions(+), 34 deletions(-) create mode 100644 src/main/java/com/tiki/server/external/controller/S3Controller.java diff --git a/src/main/java/com/tiki/server/external/controller/S3Controller.java b/src/main/java/com/tiki/server/external/controller/S3Controller.java new file mode 100644 index 00000000..f8d36edd --- /dev/null +++ b/src/main/java/com/tiki/server/external/controller/S3Controller.java @@ -0,0 +1,31 @@ +package com.tiki.server.external.controller; + +import static com.tiki.server.common.dto.SuccessResponse.*; +import static com.tiki.server.external.message.SuccessMessage.PRESIGNED_URL_GET_SUCCESS; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.tiki.server.common.dto.SuccessResponse; +import com.tiki.server.external.dto.request.PreSignedUrlRequest; +import com.tiki.server.external.dto.response.PreSignedUrlResponse; +import com.tiki.server.external.util.S3Service; + +import lombok.RequiredArgsConstructor; +import lombok.val; + +@RestController +@RequestMapping("api/v1/file") +@RequiredArgsConstructor +public class S3Controller { + + private final S3Service s3Service; + + @GetMapping("/upload") + public ResponseEntity> getPreSignedUrl(PreSignedUrlRequest request) { + val response = s3Service.getUploadPreSignedUrl(request); + return ResponseEntity.ok(success(PRESIGNED_URL_GET_SUCCESS.getMessage(), response)); + } +} diff --git a/src/main/java/com/tiki/server/external/util/S3Service.java b/src/main/java/com/tiki/server/external/util/S3Service.java index c8e98e9e..72b260ff 100644 --- a/src/main/java/com/tiki/server/external/util/S3Service.java +++ b/src/main/java/com/tiki/server/external/util/S3Service.java @@ -1,8 +1,11 @@ package com.tiki.server.external.util; +import static com.tiki.server.external.constant.ExternalConstant.FILE_SAVE_PREFIX; +import static com.tiki.server.external.constant.ExternalConstant.PRE_SIGNED_URL_EXPIRE_MINUTE; import static com.tiki.server.external.message.ErrorCode.*; import java.io.IOException; +import java.time.Duration; import java.util.UUID; import org.springframework.beans.factory.annotation.Value; @@ -10,6 +13,8 @@ import org.springframework.web.multipart.MultipartFile; import com.tiki.server.external.config.AWSConfig; +import com.tiki.server.external.dto.request.PreSignedUrlRequest; +import com.tiki.server.external.dto.response.PreSignedUrlResponse; import com.tiki.server.external.exception.ExternalException; import com.tiki.server.external.message.ErrorCode; @@ -18,16 +23,13 @@ import software.amazon.awssdk.core.sync.RequestBody; import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; import software.amazon.awssdk.services.s3.model.PutObjectRequest; +import software.amazon.awssdk.services.s3.presigner.S3Presigner; +import software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest; @Component @RequiredArgsConstructor public class S3Service { - private static final Long MAX_FILE_SIZE = 30 * 1024 * 1024L; - private static final String FILE_NAME_START_POINT = "."; - private static final String CONTENT_DISPOSITION = "inline"; - private static final String DELIMITER = "/"; - private final AWSConfig awsConfig; @Value("${aws-property.bucket}") @@ -36,49 +38,48 @@ public class S3Service { @Value("${aws-property.s3-url}") private String s3URL; - public String uploadFile(String directoryPath, MultipartFile file) { - validateFileSize(file); + public PreSignedUrlResponse getUploadPreSignedUrl(PreSignedUrlRequest request) { try { - val key = directoryPath + DELIMITER + generateFileName(file); - val s3Client = awsConfig.getS3Client(); - val request = createRequest(key, file.getContentType()); - val requestBody = RequestBody.fromBytes(file.getBytes()); - s3Client.putObject(request, requestBody); - return s3URL + key; - } catch (IOException exception) { - throw new IllegalArgumentException(); + val fileName = generateFileName(request.fileFormat()); + val key = FILE_SAVE_PREFIX + fileName; + val preSigner = awsConfig.getS3PreSigner(); + val putObjectRequest = createPutObjectRequest(key); + val putObjectPresignRequest = createPutObjectPresignRequest(putObjectRequest); + val url = preSigner.presignPutObject(putObjectPresignRequest).url().toString(); + return PreSignedUrlResponse.of(fileName, url); + } catch (RuntimeException e) { + throw new ExternalException(PRESIGNED_URL_GET_ERROR); } } public void deleteFile(String key) throws IOException { - val s3Client = awsConfig.getS3Client(); - s3Client.deleteObject((DeleteObjectRequest.Builder builder) -> - builder.bucket(bucket) - .key(key) - .build() - ); + try { + val s3Client = awsConfig.getS3Client(); + s3Client.deleteObject((DeleteObjectRequest.Builder builder) -> + builder.bucket(bucket) + .key(key) + .build() + ); + } catch (RuntimeException e) { + throw new ExternalException(FILE_DELETE_ERROR); + } } - private PutObjectRequest createRequest(String key, String contentType) { + private PutObjectRequest createPutObjectRequest(String key) { return PutObjectRequest.builder() .bucket(bucket) .key(key) - .contentType(contentType) - .contentDisposition(CONTENT_DISPOSITION) .build(); } - private String generateFileName(MultipartFile file) { - return UUID.randomUUID() + getFileFormat(file.getName()); - } - - private String getFileFormat(String fileName) { - return fileName.substring(fileName.lastIndexOf(FILE_NAME_START_POINT)); + private PutObjectPresignRequest createPutObjectPresignRequest(PutObjectRequest putObjectRequest) { + return PutObjectPresignRequest.builder() + .signatureDuration(Duration.ofMinutes(PRE_SIGNED_URL_EXPIRE_MINUTE)) + .putObjectRequest(putObjectRequest) + .build(); } - private void validateFileSize(MultipartFile file) { - if (file.getSize() > MAX_FILE_SIZE) { - throw new ExternalException(INVALID_FILE_SIZE); - } + private String generateFileName(String fileFormat) { + return UUID.randomUUID() + fileFormat; } } From 6bc33c97dc7d02bc69f5c6abd7fc53da7fb8f9ba Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 00:13:46 +0900 Subject: [PATCH 21/35] =?UTF-8?q?[FEAT]=20=EB=AC=B8=EC=84=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../document/adapter/DocumentCreator.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/com/tiki/server/document/adapter/DocumentCreator.java diff --git a/src/main/java/com/tiki/server/document/adapter/DocumentCreator.java b/src/main/java/com/tiki/server/document/adapter/DocumentCreator.java new file mode 100644 index 00000000..5eb13a39 --- /dev/null +++ b/src/main/java/com/tiki/server/document/adapter/DocumentCreator.java @@ -0,0 +1,18 @@ +package com.tiki.server.document.adapter; + +import com.tiki.server.common.support.RepositoryAdapter; +import com.tiki.server.document.entity.Document; +import com.tiki.server.document.repository.DocumentRepository; + +import lombok.RequiredArgsConstructor; + +@RepositoryAdapter +@RequiredArgsConstructor +public class DocumentCreator { + + private final DocumentRepository documentRepository; + + public Document create(Document document) { + return documentRepository.save(document); + } +} From 43b1ddffb8d19c52c43200195cf31b1c63902618 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 01:22:16 +0900 Subject: [PATCH 22/35] =?UTF-8?q?[FIX]=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=A5=BC=20=EB=AA=BB=20=EB=B0=9B=EB=8A=94=20=EB=B2=84=EA=B7=B8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/external/controller/S3Controller.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 f8d36edd..993651d5 100644 --- a/src/main/java/com/tiki/server/external/controller/S3Controller.java +++ b/src/main/java/com/tiki/server/external/controller/S3Controller.java @@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -24,7 +25,7 @@ public class S3Controller { private final S3Service s3Service; @GetMapping("/upload") - public ResponseEntity> getPreSignedUrl(PreSignedUrlRequest request) { + public ResponseEntity> getPreSignedUrl(@RequestBody PreSignedUrlRequest request) { val response = s3Service.getUploadPreSignedUrl(request); return ResponseEntity.ok(success(PRESIGNED_URL_GET_SUCCESS.getMessage(), response)); } From 084f4082ffa433176aa898986f96401e3aed29cd Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 01:22:35 +0900 Subject: [PATCH 23/35] =?UTF-8?q?[ADD]=20Document=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/document/entity/Document.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/tiki/server/document/entity/Document.java b/src/main/java/com/tiki/server/document/entity/Document.java index 91e13950..97888fe0 100644 --- a/src/main/java/com/tiki/server/document/entity/Document.java +++ b/src/main/java/com/tiki/server/document/entity/Document.java @@ -1,5 +1,6 @@ package com.tiki.server.document.entity; +import static com.tiki.server.document.entity.DocumentStatus.BASIC; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; @@ -17,6 +18,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -40,4 +42,11 @@ public class Document extends BaseTime { private DocumentStatus status; private LocalDate deletedDate; + + @Builder + public Document(String fileUrl, TimeBlock timeBlock) { + this.fileUrl = fileUrl; + this.timeBlock = timeBlock; + this.status = BASIC; + } } From e02c0561a896f60d414d1fa06a27deaaa3665c44 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 01:22:45 +0900 Subject: [PATCH 24/35] =?UTF-8?q?[FEAT]=20=ED=83=80=EC=9E=84=20=EB=B8=94?= =?UTF-8?q?=EB=A1=9D=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeblock/service/TimeBlockService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 3a066226..005ddfbc 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -5,10 +5,14 @@ import static com.tiki.server.timeblock.constant.TimeBlockConstant.EXECUTIVE; import static com.tiki.server.timeblock.constant.TimeBlockConstant.MEMBER; +import java.util.List; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.tiki.server.common.entity.Position; +import com.tiki.server.document.adapter.DocumentCreator; +import com.tiki.server.document.entity.Document; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; import com.tiki.server.team.adapter.TeamFinder; import com.tiki.server.team.entity.Team; @@ -29,7 +33,9 @@ public class TimeBlockService { private final TeamFinder teamFinder; private final MemberTeamManagerFinder memberTeamManagerFinder; private final TimeBlockCreator timeBlockCreator; + private final DocumentCreator documentCreator; + @Transactional public TimeBlockCreationResponse createTimeBlock( long memberId, long teamId, @@ -54,6 +60,7 @@ private TimeBlockCreationResponse createTimeBlockByType( checkMemberAccessible(accessiblePosition, memberPosition); val timeBlock = createTimeBlock(team, accessiblePosition, request); val timeBlockId = timeBlockCreator.createTimeBlock(timeBlock).getId(); + saveDocuments(request.filesUrl(), timeBlock); return TimeBlockCreationResponse.of(timeBlockId); } @@ -73,4 +80,15 @@ private TimeBlock createTimeBlock(Team team, Position accessiblePosition, TimeBl .team(team) .build(); } + + private void saveDocuments(List filesUrl, TimeBlock timeBlock) { + filesUrl.forEach(fileUrl -> documentCreator.create(createDocument(fileUrl, timeBlock))); + } + + private Document createDocument(String fileUrl, TimeBlock timeBlock) { + return Document.builder() + .fileUrl(fileUrl) + .timeBlock(timeBlock) + .build(); + } } From d4ebc0aa1ee1af2caef94e4babd3e621df8100e8 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:02:40 +0900 Subject: [PATCH 25/35] =?UTF-8?q?[REFACTOR]=20=EC=83=9D=EC=84=B1,=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{DocumentCreator.java => DocumentSaver.java} | 4 ++-- .../{TimeBlockCreator.java => TimeBlockSaver.java} | 4 ++-- .../server/timeblock/service/TimeBlockService.java | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) rename src/main/java/com/tiki/server/document/adapter/{DocumentCreator.java => DocumentSaver.java} (84%) rename src/main/java/com/tiki/server/timeblock/adapter/{TimeBlockCreator.java => TimeBlockSaver.java} (82%) diff --git a/src/main/java/com/tiki/server/document/adapter/DocumentCreator.java b/src/main/java/com/tiki/server/document/adapter/DocumentSaver.java similarity index 84% rename from src/main/java/com/tiki/server/document/adapter/DocumentCreator.java rename to src/main/java/com/tiki/server/document/adapter/DocumentSaver.java index 5eb13a39..34872245 100644 --- a/src/main/java/com/tiki/server/document/adapter/DocumentCreator.java +++ b/src/main/java/com/tiki/server/document/adapter/DocumentSaver.java @@ -8,11 +8,11 @@ @RepositoryAdapter @RequiredArgsConstructor -public class DocumentCreator { +public class DocumentSaver { private final DocumentRepository documentRepository; - public Document create(Document document) { + public Document save(Document document) { return documentRepository.save(document); } } diff --git a/src/main/java/com/tiki/server/timeblock/adapter/TimeBlockCreator.java b/src/main/java/com/tiki/server/timeblock/adapter/TimeBlockSaver.java similarity index 82% rename from src/main/java/com/tiki/server/timeblock/adapter/TimeBlockCreator.java rename to src/main/java/com/tiki/server/timeblock/adapter/TimeBlockSaver.java index 70f0ecc8..f72bda9b 100644 --- a/src/main/java/com/tiki/server/timeblock/adapter/TimeBlockCreator.java +++ b/src/main/java/com/tiki/server/timeblock/adapter/TimeBlockSaver.java @@ -8,11 +8,11 @@ @RepositoryAdapter @RequiredArgsConstructor -public class TimeBlockCreator { +public class TimeBlockSaver { private final TimeBlockRepository timeBlockRepository; - public TimeBlock createTimeBlock(TimeBlock timeBlock) { + public TimeBlock save(TimeBlock timeBlock) { return timeBlockRepository.save(timeBlock); } } 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 005ddfbc..a517e806 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -11,12 +11,12 @@ import org.springframework.transaction.annotation.Transactional; import com.tiki.server.common.entity.Position; -import com.tiki.server.document.adapter.DocumentCreator; +import com.tiki.server.document.adapter.DocumentSaver; import com.tiki.server.document.entity.Document; import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder; import com.tiki.server.team.adapter.TeamFinder; import com.tiki.server.team.entity.Team; -import com.tiki.server.timeblock.adapter.TimeBlockCreator; +import com.tiki.server.timeblock.adapter.TimeBlockSaver; import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest; import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse; import com.tiki.server.timeblock.entity.TimeBlock; @@ -32,8 +32,8 @@ public class TimeBlockService { private final TeamFinder teamFinder; private final MemberTeamManagerFinder memberTeamManagerFinder; - private final TimeBlockCreator timeBlockCreator; - private final DocumentCreator documentCreator; + private final TimeBlockSaver timeBlockSaver; + private final DocumentSaver documentSaver; @Transactional public TimeBlockCreationResponse createTimeBlock( @@ -59,7 +59,7 @@ private TimeBlockCreationResponse createTimeBlockByType( ) { checkMemberAccessible(accessiblePosition, memberPosition); val timeBlock = createTimeBlock(team, accessiblePosition, request); - val timeBlockId = timeBlockCreator.createTimeBlock(timeBlock).getId(); + val timeBlockId = timeBlockSaver.save(timeBlock).getId(); saveDocuments(request.filesUrl(), timeBlock); return TimeBlockCreationResponse.of(timeBlockId); } @@ -82,7 +82,7 @@ private TimeBlock createTimeBlock(Team team, Position accessiblePosition, TimeBl } private void saveDocuments(List filesUrl, TimeBlock timeBlock) { - filesUrl.forEach(fileUrl -> documentCreator.create(createDocument(fileUrl, timeBlock))); + filesUrl.forEach(fileUrl -> documentSaver.save(createDocument(fileUrl, timeBlock))); } private Document createDocument(String fileUrl, TimeBlock timeBlock) { From 0e9755713819dcee8ffffb124a13489b92b1e45d Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:07:50 +0900 Subject: [PATCH 26/35] =?UTF-8?q?[FIX]=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memberteammanager/adapter/MemberTeamManagerFinder.java | 4 ++-- .../com/tiki/server/memberteammanager/message/ErrorCode.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 d84ca318..e9a5f438 100644 --- a/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java +++ b/src/main/java/com/tiki/server/memberteammanager/adapter/MemberTeamManagerFinder.java @@ -1,6 +1,6 @@ package com.tiki.server.memberteammanager.adapter; -import static com.tiki.server.memberteammanager.message.ErrorCode.TEMP; +import static com.tiki.server.memberteammanager.message.ErrorCode.INVALID_MEMBER_TEAM_MANAGER; import com.tiki.server.common.support.RepositoryAdapter; import com.tiki.server.memberteammanager.entity.MemberTeamManager; @@ -17,6 +17,6 @@ public class MemberTeamManagerFinder { public MemberTeamManager findByMemberIdAndTeamId(long memberId, long teamId) { return teamManagerRepository.findByMemberIdAndTeamId(memberId, teamId) - .orElseThrow(() -> new MemberTeamManagerException(TEMP)); + .orElseThrow(() -> new MemberTeamManagerException(INVALID_MEMBER_TEAM_MANAGER)); } } diff --git a/src/main/java/com/tiki/server/memberteammanager/message/ErrorCode.java b/src/main/java/com/tiki/server/memberteammanager/message/ErrorCode.java index deca373d..079ecc6f 100644 --- a/src/main/java/com/tiki/server/memberteammanager/message/ErrorCode.java +++ b/src/main/java/com/tiki/server/memberteammanager/message/ErrorCode.java @@ -12,7 +12,7 @@ public enum ErrorCode { /* 404 NOT_FOUND : 자원을 찾을 수 없음 */ - TEMP(NOT_FOUND, "컴파일 에러 방지용 에러입니다."); + INVALID_MEMBER_TEAM_MANAGER(NOT_FOUND, "팀에 존재하지 않는 회원입니다."); private final HttpStatus httpStatus; private final String message; From 02e635e2bc32814449764e32486c9a7aca08cd21 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:30:16 +0900 Subject: [PATCH 27/35] =?UTF-8?q?[REFACTOR]=20Response=EC=97=90=20null=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/external/dto/response/PreSignedUrlResponse.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java b/src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java index ec51db22..683ab43f 100644 --- a/src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java +++ b/src/main/java/com/tiki/server/external/dto/response/PreSignedUrlResponse.java @@ -3,11 +3,12 @@ import static lombok.AccessLevel.PRIVATE; import lombok.Builder; +import lombok.NonNull; @Builder(access = PRIVATE) public record PreSignedUrlResponse( - String fileName, - String url + @NonNull String fileName, + @NonNull String url ) { public static PreSignedUrlResponse of(String fileName, String url) { From 1501a60f87461f39f8ea1380244123d8ff8a9863 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:44:11 +0900 Subject: [PATCH 28/35] =?UTF-8?q?[REFACTOR]=20TimeBlock=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/timeblock/entity/TimeBlock.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java index bdc86087..ddabeaba 100644 --- a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java +++ b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java @@ -47,7 +47,7 @@ public class TimeBlock extends BaseTime { private Team team; @Builder - public TimeBlock( + public static TimeBlock of( String name, String color, Position accessiblePosition, @@ -55,11 +55,13 @@ public TimeBlock( LocalDate endDate, Team team ) { - this.name = name; - this.color = color; - this.accessiblePosition = accessiblePosition; - this.startDate = startDate; - this.endDate = endDate; - this.team = team; + return TimeBlock.builder() + .name(name) + .color(color) + .accessiblePosition(accessiblePosition) + .startDate(startDate) + .endDate(endDate) + .team(team) + .build(); } } From d3bf33ea8ca829f085301b701500861c645c4005 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:44:40 +0900 Subject: [PATCH 29/35] =?UTF-8?q?[REFACTOR]=20Document=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC=20=EB=B0=8F=20=EC=83=9D=EC=84=B1=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/document/entity/Document.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/tiki/server/document/entity/Document.java b/src/main/java/com/tiki/server/document/entity/Document.java index 97888fe0..603ed505 100644 --- a/src/main/java/com/tiki/server/document/entity/Document.java +++ b/src/main/java/com/tiki/server/document/entity/Document.java @@ -1,19 +1,13 @@ package com.tiki.server.document.entity; -import static com.tiki.server.document.entity.DocumentStatus.BASIC; -import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; -import java.time.LocalDate; -import java.time.LocalDateTime; - import com.tiki.server.common.entity.BaseTime; import com.tiki.server.timeblock.entity.TimeBlock; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -38,15 +32,11 @@ public class Document extends BaseTime { @JoinColumn(name = "block_id") private TimeBlock timeBlock; - @Enumerated(value = STRING) - private DocumentStatus status; - - private LocalDate deletedDate; - @Builder - public Document(String fileUrl, TimeBlock timeBlock) { - this.fileUrl = fileUrl; - this.timeBlock = timeBlock; - this.status = BASIC; + public static Document of(String fileUrl, TimeBlock timeBlock) { + return Document.builder() + .fileUrl(fileUrl) + .timeBlock(timeBlock) + .build(); } } From ea1e0bbc7b2ee445e2ba7108e37c84b5a909d00c Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:44:58 +0900 Subject: [PATCH 30/35] =?UTF-8?q?[DEL]=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/document/entity/DocumentStatus.java | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/main/java/com/tiki/server/document/entity/DocumentStatus.java diff --git a/src/main/java/com/tiki/server/document/entity/DocumentStatus.java b/src/main/java/com/tiki/server/document/entity/DocumentStatus.java deleted file mode 100644 index a55db05b..00000000 --- a/src/main/java/com/tiki/server/document/entity/DocumentStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.tiki.server.document.entity; - -public enum DocumentStatus { - BASIC, DELETED -} From 5ff3401ad65a4613d7096a181e5669c970b60490 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:45:15 +0900 Subject: [PATCH 31/35] =?UTF-8?q?[REFACTOR]=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=97=90=20=EC=9D=98=ED=95=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeblock/service/TimeBlockService.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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 a517e806..d75c2a71 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -71,14 +71,14 @@ private void checkMemberAccessible(Position accessiblePosition, Position memberP } private TimeBlock createTimeBlock(Team team, Position accessiblePosition, TimeBlockCreationRequest request) { - return TimeBlock.builder() - .name(request.name()) - .color(request.color()) - .accessiblePosition(accessiblePosition) - .startDate(request.startDate()) - .endDate(request.endDate()) - .team(team) - .build(); + return TimeBlock.of( + request.name(), + request.color(), + accessiblePosition, + request.startDate(), + request.endDate(), + team + ); } private void saveDocuments(List filesUrl, TimeBlock timeBlock) { @@ -86,9 +86,6 @@ private void saveDocuments(List filesUrl, TimeBlock timeBlock) { } private Document createDocument(String fileUrl, TimeBlock timeBlock) { - return Document.builder() - .fileUrl(fileUrl) - .timeBlock(timeBlock) - .build(); + return Document.of(fileUrl, timeBlock); } } From e970725264c918882360ee7b0817c94aa2cae52f Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:45:39 +0900 Subject: [PATCH 32/35] =?UTF-8?q?[INIT]=20=EC=82=AD=EC=A0=9C=EB=90=9C=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=20=EA=B4=80=EB=A6=AC=20entity=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../document/entity/DeletedDocument.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/com/tiki/server/document/entity/DeletedDocument.java diff --git a/src/main/java/com/tiki/server/document/entity/DeletedDocument.java b/src/main/java/com/tiki/server/document/entity/DeletedDocument.java new file mode 100644 index 00000000..527cd2f0 --- /dev/null +++ b/src/main/java/com/tiki/server/document/entity/DeletedDocument.java @@ -0,0 +1,40 @@ +package com.tiki.server.document.entity; + +import static jakarta.persistence.GenerationType.IDENTITY; + +import java.time.LocalDate; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor +public class DeletedDocument { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "deleted_document_id") + private Long id; + + private String fileUrl; + + @Column(name = "block_id") + private long timeBlockId; + + private LocalDate deletedDate; + + @Builder + public static DeletedDocument of(String fileUrl, long timeBlockId, LocalDate deletedDate) { + return DeletedDocument.builder() + .fileUrl(fileUrl) + .timeBlockId(timeBlockId) + .deletedDate(deletedDate) + .build(); + } +} From 724438df5c584284edda1039d5b41f165a730b28 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 19:45:52 +0900 Subject: [PATCH 33/35] =?UTF-8?q?[REFACTOR]=20save=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/document/adapter/DocumentSaver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tiki/server/document/adapter/DocumentSaver.java b/src/main/java/com/tiki/server/document/adapter/DocumentSaver.java index 34872245..2b27c951 100644 --- a/src/main/java/com/tiki/server/document/adapter/DocumentSaver.java +++ b/src/main/java/com/tiki/server/document/adapter/DocumentSaver.java @@ -12,7 +12,7 @@ public class DocumentSaver { private final DocumentRepository documentRepository; - public Document save(Document document) { - return documentRepository.save(document); + public void save(Document document) { + documentRepository.save(document); } } From 7269d1d6997d809a4de9f59416dd6aa6e5244cfd Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 20:14:25 +0900 Subject: [PATCH 34/35] =?UTF-8?q?[REFACTOR]=20Document=EC=97=90=20fileName?= =?UTF-8?q?=20=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/document/entity/DeletedDocument.java | 5 ++++- .../com/tiki/server/document/entity/Document.java | 5 ++++- .../dto/request/TimeBlockCreationRequest.java | 4 ++-- .../server/timeblock/service/TimeBlockService.java | 12 ++++++------ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/tiki/server/document/entity/DeletedDocument.java b/src/main/java/com/tiki/server/document/entity/DeletedDocument.java index 527cd2f0..dcf7da07 100644 --- a/src/main/java/com/tiki/server/document/entity/DeletedDocument.java +++ b/src/main/java/com/tiki/server/document/entity/DeletedDocument.java @@ -22,6 +22,8 @@ public class DeletedDocument { @Column(name = "deleted_document_id") private Long id; + private String fileName; + private String fileUrl; @Column(name = "block_id") @@ -30,8 +32,9 @@ public class DeletedDocument { private LocalDate deletedDate; @Builder - public static DeletedDocument of(String fileUrl, long timeBlockId, LocalDate deletedDate) { + public static DeletedDocument of(String fileName, String fileUrl, long timeBlockId, LocalDate deletedDate) { return DeletedDocument.builder() + .fileName(fileName) .fileUrl(fileUrl) .timeBlockId(timeBlockId) .deletedDate(deletedDate) diff --git a/src/main/java/com/tiki/server/document/entity/Document.java b/src/main/java/com/tiki/server/document/entity/Document.java index 603ed505..9ce00b0f 100644 --- a/src/main/java/com/tiki/server/document/entity/Document.java +++ b/src/main/java/com/tiki/server/document/entity/Document.java @@ -26,6 +26,8 @@ public class Document extends BaseTime { @Column(name = "document_id") private Long id; + private String fileName; + private String fileUrl; @ManyToOne(fetch = LAZY) @@ -33,8 +35,9 @@ public class Document extends BaseTime { private TimeBlock timeBlock; @Builder - public static Document of(String fileUrl, TimeBlock timeBlock) { + public static Document of(String fileName, String fileUrl, TimeBlock timeBlock) { return Document.builder() + .fileName(fileName) .fileUrl(fileUrl) .timeBlock(timeBlock) .build(); diff --git a/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java index f7332680..16bea0be 100644 --- a/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java +++ b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockCreationRequest.java @@ -1,7 +1,7 @@ package com.tiki.server.timeblock.dto.request; import java.time.LocalDate; -import java.util.List; +import java.util.Map; import lombok.NonNull; @@ -10,6 +10,6 @@ public record TimeBlockCreationRequest( @NonNull String color, @NonNull LocalDate startDate, @NonNull LocalDate endDate, - List filesUrl + Map files ) { } 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 d75c2a71..c6ef376e 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -5,7 +5,7 @@ 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; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -60,7 +60,7 @@ private TimeBlockCreationResponse createTimeBlockByType( checkMemberAccessible(accessiblePosition, memberPosition); val timeBlock = createTimeBlock(team, accessiblePosition, request); val timeBlockId = timeBlockSaver.save(timeBlock).getId(); - saveDocuments(request.filesUrl(), timeBlock); + saveDocuments(request.files(), timeBlock); return TimeBlockCreationResponse.of(timeBlockId); } @@ -81,11 +81,11 @@ private TimeBlock createTimeBlock(Team team, Position accessiblePosition, TimeBl ); } - private void saveDocuments(List filesUrl, TimeBlock timeBlock) { - filesUrl.forEach(fileUrl -> documentSaver.save(createDocument(fileUrl, timeBlock))); + private void saveDocuments(Map files, TimeBlock timeBlock) { + files.forEach((fileName, fileUrl) -> documentSaver.save(createDocument(fileName, fileUrl, timeBlock))); } - private Document createDocument(String fileUrl, TimeBlock timeBlock) { - return Document.of(fileUrl, timeBlock); + private Document createDocument(String fileName, String fileUrl, TimeBlock timeBlock) { + return Document.of(fileName, fileUrl, timeBlock); } } From ce8dc191a9465a84ac357b191da555d1e563813f Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 11 Jul 2024 22:26:35 +0900 Subject: [PATCH 35/35] =?UTF-8?q?[REFACTOR]=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiki/server/document/entity/Document.java | 8 ++++-- .../server/timeblock/entity/TimeBlock.java | 26 +++++++++---------- .../timeblock/service/TimeBlockService.java | 9 +------ 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/tiki/server/document/entity/Document.java b/src/main/java/com/tiki/server/document/entity/Document.java index 9ce00b0f..1c9de49b 100644 --- a/src/main/java/com/tiki/server/document/entity/Document.java +++ b/src/main/java/com/tiki/server/document/entity/Document.java @@ -2,6 +2,8 @@ import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PRIVATE; +import static lombok.AccessLevel.PROTECTED; import com.tiki.server.common.entity.BaseTime; import com.tiki.server.timeblock.entity.TimeBlock; @@ -12,13 +14,16 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @Getter -@NoArgsConstructor +@Builder(access = PRIVATE) +@AllArgsConstructor(access = PRIVATE) +@NoArgsConstructor(access = PROTECTED) public class Document extends BaseTime { @Id @@ -34,7 +39,6 @@ public class Document extends BaseTime { @JoinColumn(name = "block_id") private TimeBlock timeBlock; - @Builder public static Document of(String fileName, String fileUrl, TimeBlock timeBlock) { return Document.builder() .fileName(fileName) diff --git a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java index ddabeaba..4ab18e37 100644 --- a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java +++ b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java @@ -3,12 +3,15 @@ import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PRIVATE; +import static lombok.AccessLevel.PROTECTED; import java.time.LocalDate; import com.tiki.server.common.entity.BaseTime; import com.tiki.server.common.entity.Position; import com.tiki.server.team.entity.Team; +import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -17,13 +20,16 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @Getter -@NoArgsConstructor +@Builder(access = PRIVATE) +@AllArgsConstructor(access = PRIVATE) +@NoArgsConstructor(access = PROTECTED) public class TimeBlock extends BaseTime { @Id @@ -46,21 +52,13 @@ public class TimeBlock extends BaseTime { @JoinColumn(name = "team_id") private Team team; - @Builder - public static TimeBlock of( - String name, - String color, - Position accessiblePosition, - LocalDate startDate, - LocalDate endDate, - Team team - ) { + public static TimeBlock of(Team team, Position accessiblePosition, TimeBlockCreationRequest request) { return TimeBlock.builder() - .name(name) - .color(color) + .name(request.name()) + .color(request.color()) .accessiblePosition(accessiblePosition) - .startDate(startDate) - .endDate(endDate) + .startDate(request.startDate()) + .endDate(request.endDate()) .team(team) .build(); } 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 c6ef376e..fb360327 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -71,14 +71,7 @@ private void checkMemberAccessible(Position accessiblePosition, Position memberP } private TimeBlock createTimeBlock(Team team, Position accessiblePosition, TimeBlockCreationRequest request) { - return TimeBlock.of( - request.name(), - request.color(), - accessiblePosition, - request.startDate(), - request.endDate(), - team - ); + return TimeBlock.of(team, accessiblePosition, request); } private void saveDocuments(Map files, TimeBlock timeBlock) {