-
Notifications
You must be signed in to change notification settings - Fork 1
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 #13 from studio-recoding/feat-mypage-api
[feat][fix] mypage api 개발 및 구글 로그인 완료
- Loading branch information
Showing
11 changed files
with
164 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/Ness/Backend/domain/profile/ProfileController.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,33 @@ | ||
package Ness.Backend.domain.profile; | ||
|
||
|
||
import Ness.Backend.domain.auth.dto.LoginRequestDto; | ||
import Ness.Backend.domain.member.entity.Member; | ||
import Ness.Backend.domain.profile.dto.PatchNicknameRequestDto; | ||
import Ness.Backend.domain.profile.dto.ProfileResponseDto; | ||
import Ness.Backend.global.auth.AuthUser; | ||
import Ness.Backend.global.common.response.CommonResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ProfileController { | ||
private final ProfileService profileService; | ||
|
||
@GetMapping("/profile") | ||
@Operation(summary = "프로필 조회 API", description = "사용자의 ID로 프로필을 조회하는 API 입니다.") | ||
public ProfileResponseDto userLogin(@AuthUser Member member) { | ||
return profileService.getProfile(member.getId()); | ||
} | ||
|
||
@PatchMapping("/profile") | ||
@Operation(summary = "프로필 닉네임 변경 API", description = "사용자의 ID로 프로필 닉네임을 변경하는 API 입니다.") | ||
public ResponseEntity<Long> userLogin(@AuthUser Member member, PatchNicknameRequestDto patchNicknameRequestDto) { | ||
Long profileId = profileService.updateNickname(member.getId(), patchNicknameRequestDto.getNickname()); | ||
return new ResponseEntity<>(profileId, HttpStatusCode.valueOf(200)); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
src/main/java/Ness/Backend/domain/profile/ProfileRepository.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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package Ness.Backend.domain.profile; | ||
|
||
import Ness.Backend.domain.member.entity.Member; | ||
import Ness.Backend.domain.profile.entity.Profile; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProfileRepository extends JpaRepository<Profile, Long> { | ||
|
||
// 특정 맴버 ID로 프로필 반환 | ||
Profile findProfileByMember_Id(Long memberId); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/Ness/Backend/domain/profile/ProfileService.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,35 @@ | ||
package Ness.Backend.domain.profile; | ||
|
||
import Ness.Backend.domain.member.entity.Member; | ||
import Ness.Backend.domain.profile.dto.ProfileResponseDto; | ||
import Ness.Backend.domain.profile.entity.Profile; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ProfileService { | ||
private final ProfileRepository profileRepository; | ||
public Long updateNickname(Long id, String nickname) { | ||
//JPA 변경 감지 사용 | ||
Profile profile = profileRepository.findProfileByMember_Id(id); | ||
profile.updateNickname(nickname); | ||
|
||
//결과로 profile의 ID 반환 | ||
return profile.getId(); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ProfileResponseDto getProfile(Long id) { | ||
Profile profile = profileRepository.findProfileByMember_Id(id); | ||
ProfileResponseDto profileResponseDto = ProfileResponseDto.builder() | ||
.id(profile.getId()) | ||
.pictureUrl(profile.getPictureUrl()) | ||
.nickname(profile.getNickname()) | ||
.build(); | ||
|
||
return profileResponseDto; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/Ness/Backend/domain/profile/dto/PatchNicknameRequestDto.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,12 @@ | ||
package Ness.Backend.domain.profile.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class PatchNicknameRequestDto { | ||
@Schema(description = "업데이트할 사용자 닉네임", example = "홍길동") | ||
private String nickname; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/Ness/Backend/domain/profile/dto/ProfileResponseDto.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,29 @@ | ||
package Ness.Backend.domain.profile.dto; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class ProfileResponseDto { | ||
|
||
@Schema(description = "프로필 고유 아이디", example = "0") | ||
private Long id; | ||
|
||
@Schema(description = "사용자의 공유 프로필 URL", example = "https://lh3.googleusercontent.com/...") | ||
private String pictureUrl; | ||
|
||
@Schema(description = "사용자의 닉네임", example = "홍길동") | ||
private String nickname; | ||
|
||
@Builder | ||
public ProfileResponseDto(Long id, String pictureUrl, String nickname){ | ||
this.id = id; | ||
this.pictureUrl = pictureUrl; | ||
this.nickname = nickname; | ||
} | ||
} |
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
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