From 463fc9c3e5f23671d36e0f6d8ac73431dc568e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Mon, 17 Apr 2023 21:01:01 +0900 Subject: [PATCH 01/18] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20unique=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sopt/app/domain/entity/User.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sopt/app/domain/entity/User.java b/src/main/java/org/sopt/app/domain/entity/User.java index b51ba658..70ff4872 100644 --- a/src/main/java/org/sopt/app/domain/entity/User.java +++ b/src/main/java/org/sopt/app/domain/entity/User.java @@ -39,21 +39,18 @@ public class User extends BaseEntity implements UserDetails { private String email; @Column private String clientToken; - @Column private String profileMessage; - @Column private Long points; - @Column @Enumerated(EnumType.STRING) private OsType osType; - @Column(name = "playground_id") + @Column(name = "playground_id", unique = true) private Long playgroundId; - @Column + @Column(name = "playground_token") private String playgroundToken; @Builder From 5572ef85b119a1ee0227faca81868dd2951f614c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Tue, 18 Apr 2023 00:43:40 +0900 Subject: [PATCH 02/18] refactor: stamp delete API #64 --- .../presentation/stamp/StampController.java | 25 --------- .../stamp/StampDeleteController.java | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampController.java b/src/main/java/org/sopt/app/presentation/stamp/StampController.java index 11fa75c7..f0a27b38 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampController.java @@ -15,7 +15,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -121,28 +120,4 @@ public ResponseEntity editStamp( val response = stampResponseMapper.of(stamp.getId()); return ResponseEntity.status(HttpStatus.OK).body(response); } - - @Operation(summary = "스탬프 삭제하기(개별)") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "success", content = @Content), - @ApiResponse(responseCode = "400", description = "no stamp / no mission", content = @Content), - @ApiResponse(responseCode = "500", description = "server error", content = @Content) - }) - @DeleteMapping("/{stampId}") - public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, - @PathVariable Long stampId) { - stampService.deleteStampById(user, stampId); - return ResponseEntity.status(HttpStatus.OK).body(null); - } - - @Operation(summary = "스탬프 삭제하기(전체)") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "success", content = @Content), - @ApiResponse(responseCode = "500", description = "server error", content = @Content) - }) - @DeleteMapping("/all") - public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { - stampService.deleteAllStamps(user); - return ResponseEntity.status(HttpStatus.OK).body(null); - } } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java new file mode 100644 index 00000000..00e50086 --- /dev/null +++ b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java @@ -0,0 +1,55 @@ +package org.sopt.app.presentation.stamp; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import lombok.AllArgsConstructor; +import org.sopt.app.application.s3.S3Service; +import org.sopt.app.application.stamp.StampService; +import org.sopt.app.domain.entity.User; +import org.sopt.app.presentation.stamp.StampResponse.StampMain; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +@RequestMapping("/api/v2/stamp") +@SecurityRequirement(name = "Authorization") +public class StampDeleteController { + + private final StampService stampService; + + private final S3Service s3Service; + + + @Operation(summary = "스탬프 삭제하기(개별)") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success", content = @Content), + @ApiResponse(responseCode = "400", description = "no stamp / no mission", content = @Content), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @DeleteMapping("/{stampId}") + public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, + @PathVariable Long stampId) { + stampService.deleteStampById(user, stampId); + return ResponseEntity.status(HttpStatus.OK).body(null); + } + + @Operation(summary = "스탬프 삭제하기(전체)") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success", content = @Content), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @DeleteMapping("/all") + public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { + stampService.deleteAllStamps(user); + return ResponseEntity.status(HttpStatus.OK).body(null); + } +} From 4f3c3aa8ddd1bc29fe7f98ea06415d8c5a7091fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Tue, 18 Apr 2023 01:32:20 +0900 Subject: [PATCH 03/18] =?UTF-8?q?feat:=20=EC=8A=A4=ED=83=AC=ED=94=84=20?= =?UTF-8?q?=EA=B0=9C=EB=B3=84=20S3=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20#64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/application/s3/S3Service.java | 21 +++++++++++++++++++ .../app/application/stamp/StampService.java | 3 ++- .../stamp/StampDeleteController.java | 9 ++++---- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sopt/app/application/s3/S3Service.java b/src/main/java/org/sopt/app/application/s3/S3Service.java index b6c6562f..1d99ce43 100644 --- a/src/main/java/org/sopt/app/application/s3/S3Service.java +++ b/src/main/java/org/sopt/app/application/s3/S3Service.java @@ -1,5 +1,6 @@ package org.sopt.app.application.s3; +import com.amazonaws.AmazonServiceException; import com.amazonaws.HttpMethod; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; @@ -9,11 +10,13 @@ import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @@ -125,4 +128,22 @@ public S3Info.PreSignedUrl getPreSignedUrl(String folderName) { .imageURL(imageURL) .build(); } + + public void deleteFiles(List fileUrls, String folderName) { + val folderURI = bucket + "/mainpage/makers-app-img/" + folderName; + val fileNameList = getFileNameList(fileUrls); + fileNameList.stream().forEach(file -> deleteFile(folderURI, file)); + } + + private List getFileNameList(List fileUrls) { + return fileUrls.stream().map(url -> Arrays.stream(url.split("/")).toList().get(6)).collect(Collectors.toList()); + } + + private void deleteFile(String folderURI, String fileName) { + try { + s3Client.deleteObject(folderURI, fileName.replace(File.separatorChar, '/')); + } catch (AmazonServiceException e) { + System.err.println(e.getErrorMessage()); + } + } } diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index 04705b99..86359ba0 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -119,7 +119,7 @@ public Stamp editStampImagesDeprecated(Stamp stamp, List imgPaths) { //Stamp 삭제 by stampId @Transactional - public void deleteStampById(User user, Long stampId) { + public List deleteStampById(User user, Long stampId) { val stamp = stampRepository.findById(stampId) .orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND.getMessage())); @@ -129,6 +129,7 @@ public void deleteStampById(User user, Long stampId) { user.minusPoints(mission.getLevel()); userRepository.save(user); stampRepository.deleteById(stampId); + return stamp.getImages(); } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java index 00e50086..6604d07b 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.AllArgsConstructor; +import lombok.val; import org.sopt.app.application.s3.S3Service; import org.sopt.app.application.stamp.StampService; import org.sopt.app.domain.entity.User; @@ -25,7 +26,7 @@ public class StampDeleteController { private final StampService stampService; - + private final S3Service s3Service; @@ -36,9 +37,9 @@ public class StampDeleteController { @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @DeleteMapping("/{stampId}") - public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, - @PathVariable Long stampId) { - stampService.deleteStampById(user, stampId); + public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, @PathVariable Long stampId) { + val fileUrls = stampService.deleteStampById(user, stampId); + s3Service.deleteFiles(fileUrls, "stamp"); return ResponseEntity.status(HttpStatus.OK).body(null); } From 2101d27b53521a5c9b4ea6d650c11f4d778f47c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Tue, 18 Apr 2023 01:53:12 +0900 Subject: [PATCH 04/18] =?UTF-8?q?feat:=20=EC=8A=A4=ED=83=AC=ED=94=84=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20S3=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20#64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sopt/app/application/s3/S3Service.java | 6 ++++-- .../java/org/sopt/app/application/stamp/StampService.java | 8 ++++++++ .../app/presentation/stamp/StampDeleteController.java | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/app/application/s3/S3Service.java b/src/main/java/org/sopt/app/application/s3/S3Service.java index 1d99ce43..7ff01049 100644 --- a/src/main/java/org/sopt/app/application/s3/S3Service.java +++ b/src/main/java/org/sopt/app/application/s3/S3Service.java @@ -16,7 +16,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @@ -136,7 +135,10 @@ public void deleteFiles(List fileUrls, String folderName) { } private List getFileNameList(List fileUrls) { - return fileUrls.stream().map(url -> Arrays.stream(url.split("/")).toList().get(6)).collect(Collectors.toList()); + return fileUrls.stream().map(url -> { + val fileNameSplit = url.split("/"); + return fileNameSplit[fileNameSplit.length - 1]; + }).collect(Collectors.toList()); } private void deleteFile(String folderURI, String fileName) { diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index 86359ba0..88b43828 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.val; import org.sopt.app.common.exception.BadRequestException; @@ -140,6 +141,13 @@ public void checkDuplicateStamp(Long userId, Long missionId) { } } + @Transactional(readOnly = true) + public List findAllStamps(User user) { + return stampRepository.findAllByUserId(user.getId()).stream().map(Stamp::getImages) + .flatMap(images -> images.stream()).collect(Collectors.toList()); + } + + @Transactional public void deleteAllStamps(User user) { stampRepository.deleteAllByUserId(user.getId()); diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java index 6604d07b..9badf545 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java @@ -50,7 +50,9 @@ public ResponseEntity deleteStampById(@AuthenticationPrincipal User u }) @DeleteMapping("/all") public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { + val fileUrls = stampService.findAllStamps(user); stampService.deleteAllStamps(user); + s3Service.deleteFiles(fileUrls, "stamp"); return ResponseEntity.status(HttpStatus.OK).body(null); } } From 715aa0873ecb225ec3b01ca7f5b28ed837544e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Wed, 19 Apr 2023 23:24:10 +0900 Subject: [PATCH 05/18] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98=20#64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/stamp/StampDeletedEvent.java | 20 +++++++++++++++++++ .../stamp/StampDeletedEventHandler.java | 18 +++++++++++++++++ .../sopt/app/common/config/EventsConfig.java | 20 +++++++++++++++++++ .../java/org/sopt/app/common/event/Event.java | 12 +++++++++++ .../org/sopt/app/common/event/Events.java | 18 +++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java create mode 100644 src/main/java/org/sopt/app/application/stamp/StampDeletedEventHandler.java create mode 100644 src/main/java/org/sopt/app/common/config/EventsConfig.java create mode 100644 src/main/java/org/sopt/app/common/event/Event.java create mode 100644 src/main/java/org/sopt/app/common/event/Events.java diff --git a/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java b/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java new file mode 100644 index 00000000..c667b551 --- /dev/null +++ b/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java @@ -0,0 +1,20 @@ +package org.sopt.app.application.stamp; + +import java.util.List; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.sopt.app.common.event.Event; + +@Getter +@Setter +@NoArgsConstructor +public class StampDeletedEvent extends Event { + + private List fileUrls; + + public StampDeletedEvent(List fileUrls) { + super(); + this.fileUrls = fileUrls; + } +} diff --git a/src/main/java/org/sopt/app/application/stamp/StampDeletedEventHandler.java b/src/main/java/org/sopt/app/application/stamp/StampDeletedEventHandler.java new file mode 100644 index 00000000..0a312173 --- /dev/null +++ b/src/main/java/org/sopt/app/application/stamp/StampDeletedEventHandler.java @@ -0,0 +1,18 @@ +package org.sopt.app.application.stamp; + +import lombok.RequiredArgsConstructor; +import org.sopt.app.application.s3.S3Service; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class StampDeletedEventHandler { + + private final S3Service s3Service; + + @EventListener(StampDeletedEvent.class) + public void handle(StampDeletedEvent event) { + s3Service.deleteFiles(event.getFileUrls(), "stamp"); + } +} \ No newline at end of file diff --git a/src/main/java/org/sopt/app/common/config/EventsConfig.java b/src/main/java/org/sopt/app/common/config/EventsConfig.java new file mode 100644 index 00000000..c80912e5 --- /dev/null +++ b/src/main/java/org/sopt/app/common/config/EventsConfig.java @@ -0,0 +1,20 @@ +package org.sopt.app.common.config; + +import lombok.RequiredArgsConstructor; +import org.sopt.app.common.event.Events; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@RequiredArgsConstructor +public class EventsConfig { + + private final ApplicationContext applicationContext; + + @Bean + public InitializingBean eventsInitializer() { + return () -> Events.setPublisher(applicationContext); + } +} \ No newline at end of file diff --git a/src/main/java/org/sopt/app/common/event/Event.java b/src/main/java/org/sopt/app/common/event/Event.java new file mode 100644 index 00000000..9749b56d --- /dev/null +++ b/src/main/java/org/sopt/app/common/event/Event.java @@ -0,0 +1,12 @@ +package org.sopt.app.common.event; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class Event { + +} diff --git a/src/main/java/org/sopt/app/common/event/Events.java b/src/main/java/org/sopt/app/common/event/Events.java new file mode 100644 index 00000000..ed1feeb1 --- /dev/null +++ b/src/main/java/org/sopt/app/common/event/Events.java @@ -0,0 +1,18 @@ +package org.sopt.app.common.event; + +import org.springframework.context.ApplicationEventPublisher; + +public class Events { + + private static ApplicationEventPublisher publisher; + + public static void setPublisher(ApplicationEventPublisher publisher) { + Events.publisher = publisher; + } + + public static void raise(Object event) { + if (publisher != null) { + publisher.publishEvent(event); + } + } +} From 66f7b17a69686971f18bd68633e5e97dca5ecd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Wed, 19 Apr 2023 23:33:55 +0900 Subject: [PATCH 06/18] =?UTF-8?q?refactor:=20stamp=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=20#64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/application/stamp/StampService.java | 31 +++++++------------ .../stamp/StampDeleteController.java | 10 +----- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index 88b43828..f6782305 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -76,7 +76,6 @@ public Stamp uploadStamp( return stampRepository.save(stamp); } - //스탬프 내용 수정 @Transactional public Stamp editStampContentsDeprecated( StampRequest.EditStampRequest editStampRequest, @@ -111,16 +110,21 @@ public Stamp editStampContents( return stampRepository.save(stamp); } - //스탬프 사진 수정 @Transactional public Stamp editStampImagesDeprecated(Stamp stamp, List imgPaths) { stamp.changeImages(imgPaths); return stampRepository.save(stamp); } - //Stamp 삭제 by stampId + @Transactional(readOnly = true) + public void checkDuplicateStamp(Long userId, Long missionId) { + if (stampRepository.findByUserIdAndMissionId(userId, missionId).isPresent()) { + throw new BadRequestException(ErrorCode.DUPLICATE_STAMP.getMessage()); + } + } + @Transactional - public List deleteStampById(User user, Long stampId) { + public void deleteStampById(User user, Long stampId) { val stamp = stampRepository.findById(stampId) .orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND.getMessage())); @@ -130,29 +134,16 @@ public List deleteStampById(User user, Long stampId) { user.minusPoints(mission.getLevel()); userRepository.save(user); stampRepository.deleteById(stampId); - return stamp.getImages(); - } - - - @Transactional(readOnly = true) - public void checkDuplicateStamp(Long userId, Long missionId) { - if (stampRepository.findByUserIdAndMissionId(userId, missionId).isPresent()) { - throw new BadRequestException(ErrorCode.DUPLICATE_STAMP.getMessage()); - } } - @Transactional(readOnly = true) - public List findAllStamps(User user) { - return stampRepository.findAllByUserId(user.getId()).stream().map(Stamp::getImages) - .flatMap(images -> images.stream()).collect(Collectors.toList()); - } - - @Transactional public void deleteAllStamps(User user) { stampRepository.deleteAllByUserId(user.getId()); user.initializePoints(); userRepository.save(user); + + val imageUrls = stampRepository.findAllByUserId(user.getId()).stream().map(Stamp::getImages) + .flatMap(images -> images.stream()).collect(Collectors.toList()); } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java index 9badf545..cab7ad11 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java @@ -6,8 +6,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.AllArgsConstructor; -import lombok.val; -import org.sopt.app.application.s3.S3Service; import org.sopt.app.application.stamp.StampService; import org.sopt.app.domain.entity.User; import org.sopt.app.presentation.stamp.StampResponse.StampMain; @@ -27,9 +25,6 @@ public class StampDeleteController { private final StampService stampService; - private final S3Service s3Service; - - @Operation(summary = "스탬프 삭제하기(개별)") @ApiResponses({ @ApiResponse(responseCode = "200", description = "success", content = @Content), @@ -38,8 +33,7 @@ public class StampDeleteController { }) @DeleteMapping("/{stampId}") public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, @PathVariable Long stampId) { - val fileUrls = stampService.deleteStampById(user, stampId); - s3Service.deleteFiles(fileUrls, "stamp"); + stampService.deleteStampById(user, stampId); return ResponseEntity.status(HttpStatus.OK).body(null); } @@ -50,9 +44,7 @@ public ResponseEntity deleteStampById(@AuthenticationPrincipal User u }) @DeleteMapping("/all") public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { - val fileUrls = stampService.findAllStamps(user); stampService.deleteAllStamps(user); - s3Service.deleteFiles(fileUrls, "stamp"); return ResponseEntity.status(HttpStatus.OK).body(null); } } From 4e2192bd0bb2f44a45b407553ab6f0c2d805cdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Wed, 19 Apr 2023 23:44:23 +0900 Subject: [PATCH 07/18] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=9A=94=EC=B2=AD=20=EB=B9=84=EB=8F=99?= =?UTF-8?q?=EA=B8=B0=20=EC=B2=98=EB=A6=AC=20#64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sopt/app/AppApplication.java | 8 +++++--- src/main/java/org/sopt/app/application/s3/S3Service.java | 2 ++ .../org/sopt/app/application/stamp/StampDeletedEvent.java | 2 -- .../java/org/sopt/app/application/stamp/StampService.java | 4 ++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sopt/app/AppApplication.java b/src/main/java/org/sopt/app/AppApplication.java index 2cdd2f2f..890c542d 100644 --- a/src/main/java/org/sopt/app/AppApplication.java +++ b/src/main/java/org/sopt/app/AppApplication.java @@ -3,13 +3,15 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableAsync; @EnableJpaAuditing // JPA Auditing(감시, 감사) 기능을 활성화 하는 어노테이션 createdDate, modifiedDate 저장 활성화 +@EnableAsync @SpringBootApplication public class AppApplication { - public static void main(String[] args) { - SpringApplication.run(AppApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(AppApplication.class, args); + } } diff --git a/src/main/java/org/sopt/app/application/s3/S3Service.java b/src/main/java/org/sopt/app/application/s3/S3Service.java index 7ff01049..3789a1f4 100644 --- a/src/main/java/org/sopt/app/application/s3/S3Service.java +++ b/src/main/java/org/sopt/app/application/s3/S3Service.java @@ -28,6 +28,7 @@ import org.sopt.app.common.exception.v1.ApiException; import org.sopt.app.common.response.ErrorCode; import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -128,6 +129,7 @@ public S3Info.PreSignedUrl getPreSignedUrl(String folderName) { .build(); } + @Async public void deleteFiles(List fileUrls, String folderName) { val folderURI = bucket + "/mainpage/makers-app-img/" + folderName; val fileNameList = getFileNameList(fileUrls); diff --git a/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java b/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java index c667b551..6f13d827 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java +++ b/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java @@ -2,13 +2,11 @@ import java.util.List; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.Setter; import org.sopt.app.common.event.Event; @Getter @Setter -@NoArgsConstructor public class StampDeletedEvent extends Event { private List fileUrls; diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index f6782305..63d904a4 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.val; +import org.sopt.app.common.event.Events; import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.common.response.ErrorCode; import org.sopt.app.domain.entity.Stamp; @@ -134,6 +135,8 @@ public void deleteStampById(User user, Long stampId) { user.minusPoints(mission.getLevel()); userRepository.save(user); stampRepository.deleteById(stampId); + + Events.raise(new StampDeletedEvent(stamp.getImages())); } @Transactional @@ -144,6 +147,7 @@ public void deleteAllStamps(User user) { val imageUrls = stampRepository.findAllByUserId(user.getId()).stream().map(Stamp::getImages) .flatMap(images -> images.stream()).collect(Collectors.toList()); + Events.raise(new StampDeletedEvent(imageUrls)); } From e941afb64da1958dfc9a772303026b33dba5cb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Wed, 19 Apr 2023 23:54:07 +0900 Subject: [PATCH 08/18] =?UTF-8?q?refactor:=20=EC=8A=A4=ED=83=AC=ED=94=84?= =?UTF-8?q?=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20#64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/stamp/StampController.java | 25 ++++++++++ .../stamp/StampDeleteController.java | 50 ------------------- 2 files changed, 25 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampController.java b/src/main/java/org/sopt/app/presentation/stamp/StampController.java index f0a27b38..03a87429 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampController.java @@ -12,9 +12,11 @@ import org.sopt.app.application.s3.S3Service; import org.sopt.app.application.stamp.StampService; import org.sopt.app.domain.entity.User; +import org.sopt.app.presentation.stamp.StampResponse.StampMain; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -120,4 +122,27 @@ public ResponseEntity editStamp( val response = stampResponseMapper.of(stamp.getId()); return ResponseEntity.status(HttpStatus.OK).body(response); } + + @Operation(summary = "스탬프 삭제하기(개별)") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success", content = @Content), + @ApiResponse(responseCode = "400", description = "no stamp / no mission", content = @Content), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @DeleteMapping("/{stampId}") + public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, @PathVariable Long stampId) { + stampService.deleteStampById(user, stampId); + return ResponseEntity.status(HttpStatus.OK).body(null); + } + + @Operation(summary = "스탬프 삭제하기(전체)") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success", content = @Content), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @DeleteMapping("/all") + public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { + stampService.deleteAllStamps(user); + return ResponseEntity.status(HttpStatus.OK).body(null); + } } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java b/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java deleted file mode 100644 index cab7ad11..00000000 --- a/src/main/java/org/sopt/app/presentation/stamp/StampDeleteController.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.sopt.app.presentation.stamp; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; -import lombok.AllArgsConstructor; -import org.sopt.app.application.stamp.StampService; -import org.sopt.app.domain.entity.User; -import org.sopt.app.presentation.stamp.StampResponse.StampMain; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@AllArgsConstructor -@RequestMapping("/api/v2/stamp") -@SecurityRequirement(name = "Authorization") -public class StampDeleteController { - - private final StampService stampService; - - @Operation(summary = "스탬프 삭제하기(개별)") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "success", content = @Content), - @ApiResponse(responseCode = "400", description = "no stamp / no mission", content = @Content), - @ApiResponse(responseCode = "500", description = "server error", content = @Content) - }) - @DeleteMapping("/{stampId}") - public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, @PathVariable Long stampId) { - stampService.deleteStampById(user, stampId); - return ResponseEntity.status(HttpStatus.OK).body(null); - } - - @Operation(summary = "스탬프 삭제하기(전체)") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "success", content = @Content), - @ApiResponse(responseCode = "500", description = "server error", content = @Content) - }) - @DeleteMapping("/all") - public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { - stampService.deleteAllStamps(user); - return ResponseEntity.status(HttpStatus.OK).body(null); - } -} From f5cf134bbd1b7cf2903b363c988e39cf50924fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Wed, 19 Apr 2023 23:56:38 +0900 Subject: [PATCH 09/18] refactor: parameter, response #64 --- .../org/sopt/app/presentation/stamp/StampController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampController.java b/src/main/java/org/sopt/app/presentation/stamp/StampController.java index 03a87429..423348b8 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampController.java @@ -12,7 +12,6 @@ import org.sopt.app.application.s3.S3Service; import org.sopt.app.application.stamp.StampService; import org.sopt.app.domain.entity.User; -import org.sopt.app.presentation.stamp.StampResponse.StampMain; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -130,7 +129,10 @@ public ResponseEntity editStamp( @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @DeleteMapping("/{stampId}") - public ResponseEntity deleteStampById(@AuthenticationPrincipal User user, @PathVariable Long stampId) { + public ResponseEntity deleteStampById( + @AuthenticationPrincipal User user, + @PathVariable Long stampId + ) { stampService.deleteStampById(user, stampId); return ResponseEntity.status(HttpStatus.OK).body(null); } From 30761546b96ec02e8823c1c30b5df723caed1de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Thu, 20 Apr 2023 00:38:27 +0900 Subject: [PATCH 10/18] =?UTF-8?q?del:=20sentry=20logging=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20UnknownExceptionHandler=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/common/response/CommonControllerAdvice.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java b/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java index b3372df7..5d952649 100644 --- a/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java +++ b/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java @@ -1,7 +1,6 @@ package org.sopt.app.common.response; import org.sopt.app.common.exception.BaseException; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -15,10 +14,4 @@ public ResponseEntity onKnownException(BaseException baseException) { baseException.getResponseMessage()), null, baseException.getStatusCode()); } - @ExceptionHandler(value = Exception.class) - public ResponseEntity onException(Exception exception) { - exception.printStackTrace(); - return new ResponseEntity<>(CommonResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR, - "서버 에러가 발생했습니다."), null, HttpStatus.INTERNAL_SERVER_ERROR); - } } \ No newline at end of file From 22fc186d481122ab3863c1e53b2a97cd9bec3dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Thu, 20 Apr 2023 00:38:27 +0900 Subject: [PATCH 11/18] =?UTF-8?q?del:=20sentry=20logging=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20UnknownExceptionHandler=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/common/response/CommonControllerAdvice.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java b/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java index b3372df7..5d952649 100644 --- a/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java +++ b/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java @@ -1,7 +1,6 @@ package org.sopt.app.common.response; import org.sopt.app.common.exception.BaseException; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -15,10 +14,4 @@ public ResponseEntity onKnownException(BaseException baseException) { baseException.getResponseMessage()), null, baseException.getStatusCode()); } - @ExceptionHandler(value = Exception.class) - public ResponseEntity onException(Exception exception) { - exception.printStackTrace(); - return new ResponseEntity<>(CommonResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR, - "서버 에러가 발생했습니다."), null, HttpStatus.INTERNAL_SERVER_ERROR); - } } \ No newline at end of file From d263897ca950e4a084017a6576d5491cd1a1e340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Sat, 22 Apr 2023 23:03:28 +0900 Subject: [PATCH 12/18] refactor: nonNull #64 --- src/main/java/org/sopt/app/common/event/Events.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/sopt/app/common/event/Events.java b/src/main/java/org/sopt/app/common/event/Events.java index ed1feeb1..d8ac2540 100644 --- a/src/main/java/org/sopt/app/common/event/Events.java +++ b/src/main/java/org/sopt/app/common/event/Events.java @@ -1,5 +1,7 @@ package org.sopt.app.common.event; +import static java.util.Objects.nonNull; + import org.springframework.context.ApplicationEventPublisher; public class Events { @@ -11,7 +13,7 @@ public static void setPublisher(ApplicationEventPublisher publisher) { } public static void raise(Object event) { - if (publisher != null) { + if (nonNull(publisher)) { publisher.publishEvent(event); } } From d14d8750416be9dd8f66b9fc5bba9cee938840ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Thu, 27 Apr 2023 21:30:54 +0900 Subject: [PATCH 13/18] =?UTF-8?q?=ED=94=84=EB=A1=A0=ED=8A=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9C=84=ED=95=9C=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/app/application/auth/JwtTokenService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sopt/app/application/auth/JwtTokenService.java b/src/main/java/org/sopt/app/application/auth/JwtTokenService.java index 8363dba2..bf39a224 100644 --- a/src/main/java/org/sopt/app/application/auth/JwtTokenService.java +++ b/src/main/java/org/sopt/app/application/auth/JwtTokenService.java @@ -51,7 +51,7 @@ private String encodeJwtToken(UserInfo.Id userId, Long playgroundId) { .setIssuer("sopt-makers") .setIssuedAt(now.toDate()) .setSubject(userId.getId().toString()) - .setExpiration(now.plusDays(1).toDate()) + .setExpiration(now.plusMinutes(1).toDate()) .claim("id", userId.getId()) .claim("playgroundId", playgroundId) .claim("roles", "USER") From 63e3292fd4f27f8093afa12d50749276bcd299be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Thu, 27 Apr 2023 21:56:42 +0900 Subject: [PATCH 14/18] refactor: stamp post,patch uri --- .../org/sopt/app/application/stamp/StampService.java | 12 +++++------- .../sopt/app/presentation/stamp/StampController.java | 12 +++++------- .../sopt/app/presentation/stamp/StampRequest.java | 6 ++++++ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index 63d904a4..fc48404f 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -59,16 +59,15 @@ public Stamp uploadStampDeprecated( @Transactional public Stamp uploadStamp( RegisterStampRequest stampRequest, - User user, - Long missionId) { + User user) { - val mission = missionRepository.findById(missionId) + val mission = missionRepository.findById(stampRequest.getMissionId()) .orElseThrow(() -> new BadRequestException(ErrorCode.MISSION_NOT_FOUND.getMessage())); val stamp = Stamp.builder() .contents(stampRequest.getContents()) .createdAt(LocalDateTime.now()) .images(List.of(stampRequest.getImage())) - .missionId(missionId) + .missionId(stampRequest.getMissionId()) .userId(user.getId()) .build(); user.addPoints(mission.getLevel()); @@ -96,10 +95,9 @@ public Stamp editStampContentsDeprecated( @Transactional public Stamp editStampContents( StampRequest.EditStampRequest editStampRequest, - Long userId, - Long missionId) { + Long userId) { - val stamp = stampRepository.findByUserIdAndMissionId(userId, missionId) + val stamp = stampRepository.findByUserIdAndMissionId(userId, editStampRequest.getMissionId()) .orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND.getMessage())); if (StringUtils.hasText(editStampRequest.getContents())) { stamp.changeContents(editStampRequest.getContents()); diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampController.java b/src/main/java/org/sopt/app/presentation/stamp/StampController.java index 423348b8..4ae10691 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampController.java @@ -93,14 +93,13 @@ public ResponseEntity editStampDeprecated( @ApiResponse(responseCode = "400", description = "no mission / duplicate stamp", content = @Content), @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) - @PostMapping("/mission/{missionId}") + @PostMapping("") public ResponseEntity registerStamp( @AuthenticationPrincipal User user, - @PathVariable Long missionId, @Valid @RequestBody StampRequest.RegisterStampRequest registerStampRequest ) { - stampService.checkDuplicateStamp(user.getId(), missionId); - val result = stampService.uploadStamp(registerStampRequest, user, missionId); + stampService.checkDuplicateStamp(user.getId(), registerStampRequest.getMissionId()); + val result = stampService.uploadStamp(registerStampRequest, user); val response = stampResponseMapper.of(result); return ResponseEntity.status(HttpStatus.OK).body(response); } @@ -111,13 +110,12 @@ public ResponseEntity registerStamp( @ApiResponse(responseCode = "400", description = "no stamp", content = @Content), @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) - @PutMapping("/mission/{missionId}") + @PutMapping("") public ResponseEntity editStamp( @AuthenticationPrincipal User user, - @PathVariable Long missionId, @Valid @RequestBody StampRequest.EditStampRequest editStampRequest ) { - val stamp = stampService.editStampContents(editStampRequest, user.getId(), missionId); + val stamp = stampService.editStampContents(editStampRequest, user.getId()); val response = stampResponseMapper.of(stamp.getId()); return ResponseEntity.status(HttpStatus.OK).body(response); } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java b/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java index 9c79c019..062c019a 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java @@ -13,6 +13,9 @@ public class StampRequest { @ToString public static class RegisterStampRequest { + @Schema(description = "미션 아이디", example = "1") + @NotNull(message = "missionId may not be null") + private Long missionId; @Schema(description = "스탬프 이미지", example = "https://s3.ap-northeast-2.amazonaws.com/example/283aab53-22e3-46da-85ec-146c99f82ed4.jpeg") @NotNull(message = "image may not be null") private String image; @@ -26,6 +29,9 @@ public static class RegisterStampRequest { @ToString public static class EditStampRequest { + @Schema(description = "미션 아이디", example = "1") + @NotNull(message = "missionId may not be null") + private Long missionId; @Schema(description = "스탬프 이미지", example = "https://s3.ap-northeast-2.amazonaws.com/example/283aab53-22e3-46da-85ec-146c99f82ed4") @NotNull(message = "image may not be null") private String image; From 6bc1b47fd974080fd969da63f31b382641fe33df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Thu, 27 Apr 2023 22:11:55 +0900 Subject: [PATCH 15/18] fix: stamp get uri, add username --- .../sopt/app/application/stamp/StampService.java | 6 ++++-- .../app/presentation/stamp/StampController.java | 8 ++++---- .../sopt/app/presentation/stamp/StampRequest.java | 13 +++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index fc48404f..711732cd 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -31,8 +31,10 @@ public class StampService { private final MissionRepository missionRepository; @Transactional(readOnly = true) - public Stamp findStamp(Long userId, Long missionId) { - return stampRepository.findByUserIdAndMissionId(userId, missionId) + public Stamp findStamp(StampRequest.FindStampRequest findStampRequest) { + val user = userRepository.findUserByNickname(findStampRequest.getNickname()) + .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); + return stampRepository.findByUserIdAndMissionId(user.getId(), findStampRequest.getMissionId()) .orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND.getMessage())); } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampController.java b/src/main/java/org/sopt/app/presentation/stamp/StampController.java index 4ae10691..7261c268 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampController.java @@ -17,6 +17,7 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -44,12 +45,11 @@ public class StampController { @ApiResponse(responseCode = "400", description = "no stamp", content = @Content), @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) - @GetMapping("/mission/{missionId}") + @GetMapping("") public ResponseEntity findStampByMissionAndUserId( - @AuthenticationPrincipal User user, - @PathVariable Long missionId + @Valid @ModelAttribute StampRequest.FindStampRequest findStampRequest ) { - val result = stampService.findStamp(user.getId(), missionId); + val result = stampService.findStamp(findStampRequest); val response = stampResponseMapper.of(result); return ResponseEntity.status(HttpStatus.OK).body(response); } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java b/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java index 062c019a..1a7f8fa5 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java @@ -8,6 +8,19 @@ public class StampRequest { + @Getter + @Setter + @ToString + public static class FindStampRequest { + + @Schema(description = "미션 아이디", example = "1") + @NotNull(message = "missionId may not be null") + private Long missionId; + @Schema(description = "닉네임", example = "스탬프왕") + @NotNull(message = "nickname may not be null") + private String nickname; + } + @Getter @Setter @ToString From 5c71509fc5e56e87a200d9e55fe9d44050d7e4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Fri, 28 Apr 2023 15:06:07 +0900 Subject: [PATCH 16/18] add: stamp get deprecated ver --- .../sopt/app/application/stamp/StampService.java | 6 ++++++ .../app/presentation/stamp/StampController.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index 711732cd..dec9d91e 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -38,6 +38,12 @@ public Stamp findStamp(StampRequest.FindStampRequest findStampRequest) { .orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND.getMessage())); } + @Transactional(readOnly = true) + public Stamp findStampDeprecated(Long userId, Long missionId) { + return stampRepository.findByUserIdAndMissionId(userId, missionId) + .orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND.getMessage())); + } + @Transactional public Stamp uploadStampDeprecated( RegisterStampRequest stampRequest, diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampController.java b/src/main/java/org/sopt/app/presentation/stamp/StampController.java index 7261c268..a031a240 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampController.java @@ -54,6 +54,22 @@ public ResponseEntity findStampByMissionAndUserId( return ResponseEntity.status(HttpStatus.OK).body(response); } + @Operation(summary = "스탬프 조회하기 - DEPRECATED") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success"), + @ApiResponse(responseCode = "400", description = "no stamp", content = @Content), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @GetMapping("/mission/{missionId}") + public ResponseEntity findStampByMissionAndUserIdDeprecated( + @AuthenticationPrincipal User user, + @PathVariable Long missionId + ) { + val result = stampService.findStampDeprecated(user.getId(), missionId); + val response = stampResponseMapper.of(result); + return ResponseEntity.status(HttpStatus.OK).body(response); + } + @Operation(summary = "스탬프 등록하기 - DEPRECATED") @PostMapping("/{missionId}") public ResponseEntity registerStampDeprecated( From 3212902cdac07c00c220f4825db0893cf31611c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Fri, 28 Apr 2023 15:08:43 +0900 Subject: [PATCH 17/18] version 2.1.0 --- .../presentation/firebase/FirebaseController.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sopt/app/presentation/firebase/FirebaseController.java b/src/main/java/org/sopt/app/presentation/firebase/FirebaseController.java index 44b4980c..54c54289 100644 --- a/src/main/java/org/sopt/app/presentation/firebase/FirebaseController.java +++ b/src/main/java/org/sopt/app/presentation/firebase/FirebaseController.java @@ -24,11 +24,18 @@ public class FirebaseController { public FirebaseResponse.Main getFirebaseInfo() { return FirebaseResponse.Main.builder() - .iosForceUpdateVersion("1.0.0") - .iosAppVersion("1.0.2") + .iosForceUpdateVersion("2.1.0") + .iosAppVersion("2.1.0") .androidForceUpdateVersion("1.0.0") .androidAppVersion("1.0.0") - .notice("안녕하세요, makers입니다. \n 현재 미션 수정/등록이 불가능한 이슈가 확인되어 원인 파악 중에 있습니다. \n 앱 이용에 불편을 드린 점 죄송합니다. \n 빠른 시일 내 복구 후 재공지 드리겠습니다.") + .notice("안녕하세요 32기 여러분들! 드디어 솝트 공식앱 안드로이드/iOS 공식 출시를 했습니다!\n" + + "iOS의 경우에는 기존의 \"솝탬프\" 앱을 업데이트 해주셔야 하고,\n" + + "안드로이드의 경우에는 \"SOPT\" 공식 앱을 구글플레이에서 받아주셔야 합니다.\n" + + "1차 행사때부터 활용 예정이라, **모든 분들이 반드시 솝트 앱을 미리 설치**해주시면 감사하겠습니다.\n" + + "(현재 솝트 앱 접속 후, 솝탬프에서 다른 분들의 솝탬프가 보이지 않는 이슈가 있습니다. 해당 부분은 빠르게 업데이트 예정입니다)\n" + + "또한, 정상적으로 활용하기 위해서는 플레이그라운드 회원 가입이 되어야합니다!\n" + + "혹시 아직 회원 가입이 되지 않았다면, 회원가입 후 플레이그라운드 프로필도 만들어주시길 부탁드리겠습니다.\n" + + "이용에 혹시 이슈가 있다면, 김나연(010-4519-0532)에게 연락주시면 감사하겠습니다") .imgUrl(null) .build(); } From fb47da6f26a3667d9f45615fc27bbf35145a62a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Fri, 28 Apr 2023 15:12:47 +0900 Subject: [PATCH 18/18] aT 1day reset --- .../java/org/sopt/app/application/auth/JwtTokenService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sopt/app/application/auth/JwtTokenService.java b/src/main/java/org/sopt/app/application/auth/JwtTokenService.java index bf39a224..8363dba2 100644 --- a/src/main/java/org/sopt/app/application/auth/JwtTokenService.java +++ b/src/main/java/org/sopt/app/application/auth/JwtTokenService.java @@ -51,7 +51,7 @@ private String encodeJwtToken(UserInfo.Id userId, Long playgroundId) { .setIssuer("sopt-makers") .setIssuedAt(now.toDate()) .setSubject(userId.getId().toString()) - .setExpiration(now.plusMinutes(1).toDate()) + .setExpiration(now.plusDays(1).toDate()) .claim("id", userId.getId()) .claim("playgroundId", playgroundId) .claim("roles", "USER")