-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from connecSWUn/feature/upload-profile
[FIX] 사용자 프로필 사진 업로드 API 구현
- Loading branch information
Showing
6 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...m/swulab/eatswunee/domain/user/adapter/in/web/controller/UploadUserProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.swulab.eatswunee.domain.user.adapter.in.web.controller; | ||
|
||
import com.swulab.eatswunee.domain.user.application.port.in.UpdateUserUseCase; | ||
import com.swulab.eatswunee.global.common.adapter.web.in.dto.SuccessResponse; | ||
import com.swulab.eatswunee.global.common.application.port.in.AddImageUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class UploadUserProfileController { | ||
|
||
private final AddImageUseCase addImageUseCase; | ||
private final UpdateUserUseCase updateUserUseCase; | ||
|
||
@PostMapping(value="/user/profile",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
public ResponseEntity UploadUserProfile(@AuthenticationPrincipal UserDetails userDetails, @RequestParam(value="image") MultipartFile file) { | ||
|
||
long userId = Long.parseLong(userDetails.getUsername()); | ||
|
||
String fileName = addImageUseCase.uploadImage(file); | ||
log.info("{}", fileName); | ||
updateUserUseCase.updateUserProfileUrl(userId, fileName); | ||
|
||
return ResponseEntity.ok(SuccessResponse.create201SuccessResponse()); | ||
|
||
} | ||
|
||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/swulab/eatswunee/domain/user/application/port/in/UpdateUserUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.swulab.eatswunee.domain.user.application.port.in; | ||
|
||
public interface UpdateUserUseCase { | ||
|
||
void updateUserProfileUrl(Long userId, String fileName); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/swulab/eatswunee/domain/user/application/service/UpdateUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.swulab.eatswunee.domain.user.application.service; | ||
|
||
import com.swulab.eatswunee.domain.user.application.port.in.UpdateUserUseCase; | ||
import com.swulab.eatswunee.domain.user.application.port.out.FindUserPort; | ||
import com.swulab.eatswunee.domain.user.application.port.out.SaveUserPort; | ||
import com.swulab.eatswunee.domain.user.domain.model.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UpdateUserService implements UpdateUserUseCase { | ||
|
||
private final FindUserPort findUserPort; | ||
private final SaveUserPort saveUserPort; | ||
|
||
@Override | ||
public void updateUserProfileUrl(Long userId, String fileName) { | ||
User user = findUserPort.findUser(userId); | ||
user.changeProfileImage(fileName); | ||
saveUserPort.saveUser(user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/swulab/eatswunee/global/common/application/port/in/AddImageUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.swulab.eatswunee.global.common.application.port.in; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public interface AddImageUseCase { | ||
|
||
String uploadImage(MultipartFile multipartFile); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters