Skip to content

Commit

Permalink
feat: created api for updating profile picture
Browse files Browse the repository at this point in the history
  • Loading branch information
peageon committed Jun 20, 2024
1 parent c04f26d commit d10fb9f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/runningmate/backend/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@AllArgsConstructor
@Builder
public class Member extends BaseTimeEntity {
//https://cobbybb.tistory.com/14
public static final String DEFAULT_PROFILE_PIC = "https://storage.googleapis.com/runningmate-bucket/Screenshot%202024-06-20%20at%203.46.14%E2%80%AFPM.png";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down Expand Up @@ -53,7 +53,7 @@ public class Member extends BaseTimeEntity {

@Column
@Builder.Default
private String profilePicture = "https://storage.googleapis.com/runningmate-bucket/Screenshot%202024-06-20%20at%203.46.14%E2%80%AFPM.png";
private String profilePicture = DEFAULT_PROFILE_PIC;

public void updateRefreshToken(String token) {
this.refreshtoken = token;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package com.runningmate.backend.member.controller;

import com.runningmate.backend.member.Member;
import com.runningmate.backend.member.dto.MemberDto;
import com.runningmate.backend.member.dto.MemberListResponseDto;
import com.runningmate.backend.member.service.MemberService;
import com.runningmate.backend.posts.service.GcsFileStorageService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/member")
@RequiredArgsConstructor
public class MemberController {
private final MemberService memberService;
private final GcsFileStorageService gcsFileStorageService;

@ResponseStatus(value = HttpStatus.CREATED)
@PostMapping("/{memberId}/follow")
Expand Down Expand Up @@ -44,4 +50,13 @@ public MemberListResponseDto getFollowerList(@PathVariable(name = "memberId") Lo
public MemberListResponseDto getFollowingList(@PathVariable(name = "memberId") Long memberId) {
return memberService.getFollowingList(memberId);
}

@ResponseStatus(value = HttpStatus.CREATED)
@PostMapping("/update/profile-picture")
public MemberDto updateProfilePicture(@RequestParam(name = "image") MultipartFile image,
@AuthenticationPrincipal UserDetails userDetails) throws IOException {
Member member = memberService.getMemberByUsername(userDetails.getUsername());
String imageUrl = gcsFileStorageService.storeFile(image);
return MemberDto.fromEntity(memberService.updateMemberProfilePicture(member, imageUrl));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -74,6 +75,11 @@ public MemberListResponseDto getFollowingList(Long memberId) {
return createMemberListResponseDto("followings", follows);
}

public Member updateMemberProfilePicture(Member member, String url) {
member.updateProfilePicture(url != null ? url : Member.DEFAULT_PROFILE_PIC);
return memberRepository.save(member);
}

private MemberListResponseDto createMemberListResponseDto(String type, List<Follow> follows) {
List<MemberDto> memberList = new ArrayList<>();
for (Follow follow: follows) {
Expand Down

0 comments on commit d10fb9f

Please sign in to comment.