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

[#101] Feat : 초대 로직 수정 - 예외처리 #105

Merged
merged 7 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ sonarqube {
property "sonar.projectKey", "syncd"
property "sonar.projectName", "syncd"

property "sonar.gradle.skipCompile", "true"
property "sonar.modules", subprojects.collect { it.name }.join(',')
subprojects.forEach { subproject ->
property "sonar.${subproject.name}.coverage.jacoco.xmlReportPaths", "${subproject.layout.buildDirectory.get()}/$customJacocoReportDir/xml/jacoco.xml"
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/syncd/adapter/in/web/UserController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.syncd.adapter.in.web;

import com.syncd.application.port.in.GetUserInfoUsecase;
import com.syncd.application.port.in.UpdateUserInfoUsecase;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.syncd.application.service.JwtService;
Expand All @@ -11,6 +13,7 @@
@RequestMapping("/v1/user")
public class UserController {
private final GetUserInfoUsecase getUserInfoUsecase;
private final UpdateUserInfoUsecase updateUserInfoUsecase;
private final JwtService jwtService;

// @PostMapping("/register")
Expand All @@ -23,5 +26,12 @@ public GetUserInfoUsecase.GetUserInfoResponseDto getUserInfo(HttpServletRequest
String token = jwtService.resolveToken(request);
return getUserInfoUsecase.getUserInfo(jwtService.getUserIdFromToken(token));
}

@PostMapping("/update")
public UpdateUserInfoUsecase.UpdateUserInfoResponseDto updateUserInfo(HttpServletRequest request, @Valid @ModelAttribute UpdateUserInfoUsecase.UpdateUserInfoRequestDto requestDto){

String token = jwtService.resolveToken(request);
return updateUserInfoUsecase.updateUserInfo(jwtService.getUserIdFromToken(token), requestDto.name(), requestDto.img());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class S3UploaderAdaptor implements S3Port {
@Value("${cloud.aws.s3.bucket}")
private String bucket;

public Optional<String> uploadMultipartFileToS3(MultipartFile multipartFile, String name, String id) {
public Optional<String> uploadMultipartFileToS3(MultipartFile multipartFile) {
try {
String originalFilename = multipartFile.getOriginalFilename();
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.syncd.application.port.in;

import com.syncd.exceptions.ValidationMessages;
import jakarta.validation.constraints.NotBlank;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface UpdateUserInfoUsecase {
// ======================================
// METHOD
// ======================================
UpdateUserInfoResponseDto updateUserInfo(
@NotBlank(message = ValidationMessages.USER_ID_NOT_BLANK)
String userId,
String name,
MultipartFile img
);

// ======================================
// DTO
// ======================================
record UpdateUserInfoRequestDto(
String name,
MultipartFile img
) {
}

record UpdateUserInfoResponseDto(
String userId,
String name,
String img
) {
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.syncd.dto.UserId;

public interface WriteUserPort {
UserId createUser(String userName, String email,String img);
UserId createUser(String userName, String email, String img);

UserId updateUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

public interface S3Port {

public Optional<String> uploadMultipartFileToS3(MultipartFile multipartFile, String name, String id);
public Optional<String> uploadMultipartFileToS3(MultipartFile multipartFile);
public Optional<Boolean> deleteFileFromS3(String filename);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ public CreateProjectResponseDto createProject(String hostId, String hostName, St
String imgURL = "";
System.out.println(hostName);
if (img != null && !img.isEmpty()) {
Optional<String> optionalImgURL = s3Port.uploadMultipartFileToS3(img, hostName, projectName);
Optional<String> optionalImgURL = s3Port.uploadMultipartFileToS3(img);
imgURL = optionalImgURL.orElseThrow(() -> new IllegalStateException("Failed to upload image to S3"));
}

Project project = new Project();
project = project.createProjectDomain(projectName, description, imgURL, hostId);
project.addUsers(userInProjectFromEmail(userEmails));
if (userEmails != null && !userEmails.isEmpty()){
project.addUsers(userInProjectFromEmail(userEmails));
sendMailPort.sendIviteMailBatch(hostName, projectName, userEmails, project.getId());
}
CreateProjectResponseDto createProjectResponseDto = new CreateProjectResponseDto(writeProjectPort.CreateProject(project));

User host = readUserPort.findByUserId(hostId);
Expand All @@ -67,7 +70,6 @@ public CreateProjectResponseDto createProject(String hostId, String hostName, St
// .collect(Collectors.toList());
// }

sendMailPort.sendIviteMailBatch(hostName, projectName, userEmails, project.getId());
return createProjectResponseDto;
}

Expand Down
34 changes: 31 additions & 3 deletions src/main/java/com/syncd/application/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.syncd.application.port.in.GetAllRoomsByUserIdUsecase;
import com.syncd.application.port.in.GetUserInfoUsecase;
//import com.syncd.application.port.in.RegitsterUserUsecase;
import com.syncd.application.port.in.UpdateUserInfoUsecase;
import com.syncd.application.port.out.autentication.AuthenticationPort;
import com.syncd.application.port.out.persistence.user.ReadUserPort;
import com.syncd.application.port.out.persistence.user.WriteUserPort;
import com.syncd.application.port.out.s3.S3Port;
import com.syncd.domain.user.User;
//import com.syncd.dto.TokenDto;
//import com.syncd.dto.UserForTokenDto;
Expand All @@ -14,17 +16,19 @@
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Optional;


@Service
@Primary
@RequiredArgsConstructor
public class UserService implements GetUserInfoUsecase {
public class UserService implements GetUserInfoUsecase, UpdateUserInfoUsecase {
private final ReadUserPort readUserPort;
private final WriteUserPort writeUserPort;

private final AuthenticationPort authenticationPort;

private final S3Port s3Port;
private final GetAllRoomsByUserIdUsecase getAllRoomsByUserIdUsecase;

// @Override
Expand All @@ -48,6 +52,30 @@ public GetUserInfoResponseDto getUserInfo(String userId) {

}

@Override
public UpdateUserInfoResponseDto updateUserInfo(String userId, String name, MultipartFile img) {
User user = readUserPort.findByUserId(userId);

if (user == null) {
throw new RuntimeException("User not found with ID: " + userId);
}

if (name != null && !name.isEmpty()) {
user.setName(name);
}

String imgURL = "";
if (img != null && !img.isEmpty()) {
Optional<String> optionalImgURL = s3Port.uploadMultipartFileToS3(img);
imgURL = optionalImgURL.orElseThrow(() -> new IllegalStateException("Failed to upload image to S3"));
user.setProfileImg(imgURL);
}

writeUserPort.updateUser(user);

return new UpdateUserInfoResponseDto(userId, user.getName(), user.getProfileImg());
}

// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// // 데이터베이스에서 사용자 정보를 조회하는 로직을 구현합니다.
// User user = readUserPort.findByUsername(username);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/syncd/domain/project/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private List<UserInProject> userInProjectsFromUsers(String hostId){

public String getImgFileName() {
try {
URL url = new URL(img);
URL url = new URL("https://" + img);
String path = url.getPath();
return path.substring(path.lastIndexOf('/') + 1);
} catch (Exception e) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/Dummy/Stub/application/out/s3/StubS3Port.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

public class StubS3Port implements S3Port {


@Override
public Optional<String> uploadMultipartFileToS3(MultipartFile multipartFile, String name, String id) {
public Optional<String> uploadMultipartFileToS3(MultipartFile multipartFile) {
return Optional.of(Consistent.S3Link.getValue());
}

Expand Down