Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Deploy] 운영서버 v1.0.3 배포 #254

Merged
merged 15 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
357de03
[Fix] #248 - Objective 삭제 시 해당 Objective 뒤의 Index를 가지는 Objective들의 In…
its-sky Mar 12, 2024
7884c77
[Fix] #248 - KeyResult 생성 시 기존 KeyResult Index 수정 로직 bulk로 변경
its-sky Mar 12, 2024
5a6fc28
[Fix] #248 - KeyResult 삭제 시 기존 KeyResult Index 수정 로직 적용
its-sky Mar 12, 2024
9786782
[Fix] #248 - Task 생성 및 삭제 시 기존 KeyResult Index 수정 로직 적용 및 최적화
its-sky Mar 12, 2024
52c0baa
[Del] #248 - ObjectiveJpaRepository 사용하지 않는 시그니처 삭제
its-sky Mar 12, 2024
4a4edd5
Merge pull request #249 from MOONSHOT-Team/feature/#248
its-sky Mar 12, 2024
88abe6b
[Fix] #250 - Criteria 조건 워딩 변경
its-sky Mar 12, 2024
769dbdf
Merge pull request #251 from MOONSHOT-Team/feature/#250
its-sky Mar 12, 2024
92c63e4
[Refactor] #252 - User profileImage 필드명 imageUrl로 변경 및 Flyway 파일 추가 설정
its-sky Mar 13, 2024
902260e
[Feat] #252 - S3 Presigned Url 이미지 등록 및 Notification을 통한 유저 프로필 이미지 업…
its-sky Mar 13, 2024
b307540
[Fix] #252 - Google, Kakao API DTO 스펙 롤백
its-sky Mar 13, 2024
db1b9b1
[Fix] #252 - JsonCreator Exception BadRequest로 변경
its-sky Mar 13, 2024
10e9146
[Fix] #252 - Presigned Url 획득 시 이미지 타입 body에 받도록 변경
its-sky Mar 13, 2024
fc841a5
[Fix] #252 - Google, Kakao API DTO 스펙 롤백 후 UserService 캐스팅 변경
its-sky Mar 13, 2024
20f90a8
Merge pull request #253 from MOONSHOT-Team/feature/#252
its-sky Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ public void createKeyResult(final KeyResultCreateRequestDto request, final Long
validateActiveKRSizeExceeded(krList.size());
validateIndexUnderMaximum(request.idx(), krList.size());

for (int i = request.idx(); i < krList.size(); i++) {
krList.get(i).incrementIdx();
}
keyResultRepository.bulkUpdateIdxIncrease(request.idx(), krList.size(), objective.getId(), -1L);

KeyResult keyResult = keyResultRepository.save(KeyResult.builder()
.objective(objective)
.title(request.title())
Expand All @@ -113,6 +112,7 @@ public void deleteKeyResult(final Long keyResultId, final Long userId) {
logRepository.deleteAllInBatch(logRepository.findAllByKeyResult(keyResult));
taskRepository.deleteAllInBatch(taskRepository.findAllByKeyResult(keyResult));
keyResultRepository.delete(keyResult);
keyResultRepository.bulkUpdateIdxDecrease(keyResult.getIdx(), 3, keyResult.getObjective().getId(), -1L);
}

public void deleteKeyResult(final Objective objective) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public DashboardResponseDto deleteObjective(final Long userId, final Long object

keyResultService.deleteKeyResult(objective);
objectiveRepository.delete(objective);
objectiveRepository.bulkUpdateIdxDecreaseAfter(objective.getIdx(), userId);

return getObjectiveInDashboard(userId, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ public void createTask(final TaskSingleCreateRequestDto request, final Long user
validateActiveTaskSizeExceeded(taskList.size());
validateIndexUnderMaximum(request.idx(), taskList.size());

for (int i = request.idx(); i < taskList.size(); i++) {
taskList.get(i).incrementIdx();
}
taskRepository.bulkUpdateTaskIdxIncrease(request.idx(), taskList.size(), keyResult.getId(), -1L);

saveTask(keyResult, request);
}

Expand Down Expand Up @@ -90,6 +89,7 @@ public void deleteTask(final Long userId, Long taskId) {
validateUserAuthorization(task.getKeyResult().getObjective().getUser().getId(), userId);

taskRepository.deleteById(taskId);
taskRepository.bulkUpdateTaskIdxDecrease(task.getIdx(), 3, task.getKeyResult().getId(), -1L);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.moonshot.user.controller;

import lombok.RequiredArgsConstructor;
import org.moonshot.model.Logging;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.response.SuccessType;
import org.moonshot.s3.S3Service;
import org.moonshot.s3.dto.request.GetPresignedUrlRequestDto;
import org.moonshot.s3.dto.request.NotifyImageSaveSuccessRequestDto;
import org.moonshot.s3.dto.response.PresignedUrlVO;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -15,27 +18,23 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1")
@RequestMapping("/v1/image")
@RequiredArgsConstructor
public class ImageController {

private final S3Service s3Service;

//TODO
// 추후 로그인 유저를 확인하여 해당 유저에 대한 데이터로 getUploadPreSignedUrl로 username을 넘기는 로직으로 변경해야 함.
@GetMapping("/image")
public ResponseEntity<MoonshotResponse<PresignedUrlVO>> getPresignedUrl() {
return ResponseEntity.status(HttpStatus.OK).body(
MoonshotResponse.success(
SuccessType.GET_PRESIGNED_URL_SUCCESS, s3Service.getUploadPreSignedUrl("test", "SMC")));
@GetMapping
@Logging(item = "Image", action = "Get")
public ResponseEntity<MoonshotResponse<PresignedUrlVO>> getPresignedUrl(@LoginUser Long userId, @RequestBody GetPresignedUrlRequestDto request) {
return ResponseEntity.status(HttpStatus.OK)
.body(MoonshotResponse.success(SuccessType.GET_PRESIGNED_URL_SUCCESS, s3Service.getUploadPreSignedUrl(request, userId)));
}

//TODO
// 해당 API도 username을 @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : username")
// 등을 이용하여 Annotation화 하여 바로 username을 넘길 수 있도록 변경해야 함.
@PostMapping("/image")
public ResponseEntity<MoonshotResponse<?>> notifyImageSaveSuccess(@RequestBody final NotifyImageSaveSuccessRequestDto request) {
s3Service.notifyImageSaveSuccess(request);
@PostMapping
@Logging(item = "Image", action = "Post")
public ResponseEntity<MoonshotResponse<?>> notifyImageSaveSuccess(@LoginUser Long userId, @RequestBody final NotifyImageSaveSuccessRequestDto request) {
s3Service.notifyImageSaveSuccess(userId, request);
return ResponseEntity.status(HttpStatus.CREATED).body(MoonshotResponse.success(SuccessType.POST_NOTIFY_IMAGE_SAVE_SUCCESS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record UserInfoResponse(
public static UserInfoResponse of(User user) {
return new UserInfoResponse(
user.getSocialPlatform().getValue(),
user.getProfileImage(),
user.getImageUrl(),
user.getNickname(),
user.getDescription());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.moonshot.user.service;

import lombok.RequiredArgsConstructor;
import org.moonshot.s3.ImageEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
public class ImageEventListener {

private final UserService userService;

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handleImageEvent(ImageEvent imageEvent) {
userService.updateUserProfileImage(imageEvent.userId(), imageEvent.imageUrl());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public SocialLoginResponse googleLogin(final SocialLoginRequest request) {
.socialId(userResponse.sub())
.socialPlatform(request.socialPlatform())
.name(userResponse.name())
.profileImage(userResponse.picture())
.imageUrl(userResponse.picture())
.email(userResponse.email())
.build());
user = newUser;
Expand Down Expand Up @@ -121,7 +121,7 @@ public SocialLoginResponse kakaoLogin(final SocialLoginRequest request) {
.socialId(userResponse.id())
.socialPlatform(request.socialPlatform())
.name(userResponse.kakaoAccount().profile().nickname())
.profileImage(userResponse.kakaoAccount().profile().profileImageUrl())
.imageUrl(userResponse.kakaoAccount().profile().profileImageUrl())
.email(null)
.build());
user = newUser;
Expand Down Expand Up @@ -176,14 +176,19 @@ public UserInfoResponse getMyProfile(final Long userId) {
return UserInfoResponse.of(user);
}

public void updateUserProfileImage(final Long userId, final String imageUrl) {
User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(NOT_FOUND_USER));
user.modifyProfileImage(imageUrl);
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void publishSignUpEvent(final User user) {
eventPublisher.publishEvent(SignUpEvent.of(
user.getName(),
user.getEmail() == null ? "" : user.getEmail(),
user.getSocialPlatform().toString(),
LocalDateTime.now(),
user.getProfileImage()
user.getImageUrl()
));
}

Expand Down
2 changes: 1 addition & 1 deletion moonshot-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spring:

flyway:
baseline-on-migrate: false
baseline-version: 1
baseline-version: 2
enabled: false

google:
Expand Down
1 change: 1 addition & 0 deletions moonshot-api/src/main/resources/db/migration/V3__DDL.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE user CHANGE profile_image image_url varchar(255);
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.moonshot.exception.MoonshotException;
import org.moonshot.exception.BadRequestException;
import org.moonshot.response.ErrorType;

@Getter
Expand All @@ -31,7 +31,7 @@ public static KRState fromValue(String value) {
return krState;
}
}
throw new MoonshotException(ErrorType.INVALID_TYPE);
throw new BadRequestException(ErrorType.INVALID_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.moonshot.exception.MoonshotException;
import org.moonshot.exception.BadRequestException;
import org.moonshot.response.ErrorType;

@Getter
Expand Down Expand Up @@ -33,7 +33,7 @@ public static Category fromValue(String value) {
return category;
}
}
throw new MoonshotException(ErrorType.INVALID_TYPE);
throw new BadRequestException(ErrorType.INVALID_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.moonshot.exception.MoonshotException;
import org.moonshot.exception.BadRequestException;
import org.moonshot.response.ErrorType;

@Getter
Expand All @@ -14,7 +14,7 @@ public enum Criteria {

LATEST("최신순"),
OLDEST("오래된 순"),
ACCOMPLISH("달성률");
ACCOMPLISH("달성률");

private final String value;

Expand All @@ -30,7 +30,7 @@ public static Criteria fromValue(String value) {
return criteria;
}
}
throw new MoonshotException(ErrorType.INVALID_TYPE);
throw new BadRequestException(ErrorType.INVALID_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

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

import org.moonshot.keyresult.model.KeyResult;
import org.moonshot.objective.model.Objective;
import org.moonshot.user.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.moonshot.user.model.User;

public interface ObjectiveJpaRepository extends JpaRepository<Objective, Long> {

Long countAllByUserAndIsClosed(User user, boolean isClosed);
@Query("select o from Objective o join fetch o.user where o.id = :objective_id")
Optional<Objective> findObjectiveAndUserById(@Param("objective_id") Long objectiveId);
@Query("select distinct o from Objective o left join fetch o.keyResultList kr left join kr.taskList t where o.id = :objectiveId and o.isClosed = false")
Expand All @@ -23,13 +20,16 @@ public interface ObjectiveJpaRepository extends JpaRepository<Objective, Long> {
@Modifying(clearAutomatically = true)
@Query("UPDATE Objective o SET o.idx = o.idx + 1 WHERE o.user.id = :userId")
void bulkUpdateIdxIncrease(@Param("userId") Long userId);
Long countAllByUserId(Long userId);
@Modifying(clearAutomatically = true)
@Query("UPDATE Objective o SET o.idx = o.idx + 1 WHERE o.idx >= :lBound AND o.idx < :uBound AND o.user.id = :userId AND o.id != :targetId")
void bulkUpdateIdxIncrease(@Param("lBound") int lowerBound, @Param("uBound") int upperBound, @Param("userId") Long userId, @Param("targetId") Long targetId);
@Modifying(clearAutomatically = true)
@Query("UPDATE Objective o SET o.idx = o.idx - 1 WHERE o.idx >= :lBound AND o.idx <= :uBound AND o.user.id = :userId AND o.id != :targetId")
void bulkUpdateIdxDecrease(@Param("lBound") int lowerBound, @Param("uBound") int upperBound, @Param("userId") Long userId, @Param("targetId") Long targetId);
@Modifying(clearAutomatically = true)
@Query("UPDATE Objective o SET o.idx = o.idx - 1 WHERE o.idx >= :lBound AND o.user.id = :userId")
void bulkUpdateIdxDecreaseAfter(@Param("lBound") int lowerBound, @Param("userId") Long userId);
List<Objective> findAllByUserIn(List<User> userList);
Long countAllByUserId(Long userId);

}
31 changes: 22 additions & 9 deletions moonshot-domain/src/main/java/org/moonshot/user/model/User.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package org.moonshot.user.model;

import jakarta.persistence.*;
import lombok.*;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
Expand Down Expand Up @@ -32,7 +40,7 @@ public class User {
private String name;

@Column(nullable = false)
private String profileImage;
private String imageUrl;

private String email;

Expand All @@ -43,24 +51,24 @@ public class User {
private LocalDateTime deleteAt;

@Builder
private User(String socialId, SocialPlatform socialPlatform, String name, String profileImage, String email,
private User(String socialId, SocialPlatform socialPlatform, String name, String imageUrl, String email,
String nickname, String description) {
this.socialId = socialId;
this.socialPlatform = socialPlatform;
this.name = name;
this.profileImage = profileImage;
this.imageUrl = imageUrl;
this.email = email;
this.nickname = nickname;
this.description = description;
}

@Builder(builderMethodName = "builderWithSignIn")
public static User of(String socialId, SocialPlatform socialPlatform, String name, String profileImage, String email) {
public static User of(String socialId, SocialPlatform socialPlatform, String name, String imageUrl, String email) {
return builder()
.socialId(socialId)
.socialPlatform(socialPlatform)
.name(name)
.profileImage(profileImage)
.imageUrl(imageUrl)
.email(email)
.build();
}
Expand All @@ -69,9 +77,14 @@ public static User of(String socialId, SocialPlatform socialPlatform, String nam

public void modifyDescription(String description) { this.description = description; }

public void modifyProfileImage(String imageUrl) {
this.imageUrl = imageUrl;
}

public void resetDeleteAt() {
this.deleteAt = null;
}

public void setDeleteAt(){
this.deleteAt = LocalDateTime.now().plusDays(USER_RETENTION_PERIOD);
}
Expand Down
7 changes: 6 additions & 1 deletion moonshot-external/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'

// JWT
// Transaction Retry
implementation 'org.springframework.retry:spring-retry'
implementation 'org.springframework:spring-aspects'

// JWT
implementation group: "io.jsonwebtoken", name: "jjwt-api", version: "0.11.2"
implementation group: "io.jsonwebtoken", name: "jjwt-impl", version: "0.11.2"
implementation group: "io.jsonwebtoken", name: "jjwt-jackson", version: "0.11.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.moonshot.s3;

public record ImageEvent(Long userId, String imageUrl, ImageType imageType) {

public static ImageEvent of(Long userId, String imageUrl, ImageType imageType) {
return new ImageEvent(userId, imageUrl, imageType);
}

}
Loading
Loading