-
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.
* feat: add api to set pr ofile image * fix: add validation of nickname duplication * feat: add api to change nickname * feat: add api to resign * feat: add api to delete profile image * fix: add validation of file extension * fix: add validation logic at api to resign * feat: add profileImage * feat: add api to see my page * fix: rename default filename * fix: fix response * fix: fix add file extension * fix: fix file extension
- Loading branch information
Showing
29 changed files
with
709 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package gymmi.controller; | ||
|
||
import gymmi.entity.User; | ||
import gymmi.global.Logined; | ||
import gymmi.request.EditingMyPageRequest; | ||
import gymmi.response.MyPageResponse; | ||
import gymmi.service.MyPageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class MyPageController { | ||
|
||
private final MyPageService myPageService; | ||
|
||
@PutMapping(value = "/my/profile-image", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
public ResponseEntity<Void> editProfileImage( | ||
@Logined User user, | ||
@RequestParam("profileImage") MultipartFile profileImageFile | ||
) { | ||
myPageService.setProfileImage(user, profileImageFile); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@DeleteMapping("/my/profile-image") | ||
public ResponseEntity<Void> deleteProfileImage( | ||
@Logined User user | ||
) { | ||
myPageService.deleteProfileImage(user); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PutMapping("/my/nickname/edit") | ||
public ResponseEntity<Void> editMyPage( | ||
@Logined User user, | ||
@RequestBody @Validated EditingMyPageRequest request | ||
) { | ||
myPageService.editMyPage(user, request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@GetMapping("/my") | ||
public ResponseEntity<MyPageResponse> seeMyPage( | ||
@Logined User user | ||
) { | ||
MyPageResponse response = myPageService.getMyInfo(user); | ||
return ResponseEntity.ok().body(response); | ||
} | ||
|
||
|
||
} |
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,46 @@ | ||
package gymmi.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ProfileImage { | ||
|
||
public static final String EMPTY_NAME = "default.png"; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@JoinColumn(name = "user_id", nullable = false, unique = true, updatable = false) | ||
@OneToOne(fetch = FetchType.LAZY) | ||
private User owner; | ||
|
||
@Column(nullable = false) | ||
private String originName; | ||
|
||
@Column(nullable = false) | ||
private String storedName; | ||
|
||
@Builder | ||
public ProfileImage(User owner, String originName, String storedName) { | ||
this.owner = owner; | ||
this.originName = originName; | ||
this.storedName = storedName; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getOriginName() { | ||
return originName; | ||
} | ||
|
||
public String getStoredName() { | ||
return storedName; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package gymmi.exception; | ||
|
||
public class InvalidFileException extends BadRequestException { | ||
|
||
public static final String ERROR_CODE = "INVALID_FILE"; | ||
public static final String ERROR_DESCRIPTION = "잘못된 파일의 요청인 경우"; | ||
|
||
public InvalidFileException(String message) { | ||
super(message, ERROR_CODE, ERROR_DESCRIPTION); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/gymmi/repository/ProfileImageRepository.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,20 @@ | ||
package gymmi.repository; | ||
|
||
import gymmi.entity.ProfileImage; | ||
import gymmi.exception.NotFoundResourcesException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ProfileImageRepository extends JpaRepository<ProfileImage, Long> { | ||
|
||
@Query("select p from ProfileImage p where p.owner.id =:userId") | ||
Optional<ProfileImage> findByUserId(Long userId); | ||
|
||
default ProfileImage getByUserId(Long userId) { | ||
return findByUserId(userId) | ||
.orElseThrow(() -> new NotFoundResourcesException("프로필 이미지가 존재하지 않습니다.")); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package gymmi.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.validator.constraints.Length; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class EditingMyPageRequest { | ||
|
||
@NotBlank(message = "닉네임을 입력해주세요.") | ||
@Length(min = 2, max = 5, message = "닉네임은 2~5자까지 가능합니다.") | ||
private String nickname; | ||
|
||
public EditingMyPageRequest(String nickname) { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package gymmi.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class ResignRequest { | ||
|
||
@NotBlank | ||
private String password; | ||
|
||
public ResignRequest(String password) { | ||
this.password = password; | ||
} | ||
} |
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
Oops, something went wrong.