Skip to content

Commit

Permalink
merge : #114 한줄 자기소개 수정 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
amaran-th authored Jul 31, 2023
2 parents 7ab5930 + 6869a46 commit 7a69c4a
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 2,099 deletions.
11 changes: 11 additions & 0 deletions backend/emm-sale/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ include::{snippets}/update-open-profile-url/http-request.adoc[]
.HTTP response
include::{snippets}/update-open-profile-url/http-response.adoc[]

=== `PUT`: 사용자의 한줄 자기소개 업데이트

.HTTP request 설명
include::{snippets}/update-description/request-fields.adoc[]

.HTTP request
include::{snippets}/update-description/http-request.adoc[]

.HTTP response
include::{snippets}/update-description/http-response.adoc[]

=== `GET`: 특정 사용자의 프로필 정보 조회

.HTTP request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.emmsale.member.application.MemberActivityService;
import com.emmsale.member.application.MemberQueryService;
import com.emmsale.member.application.MemberUpdateService;
import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.MemberActivityAddRequest;
import com.emmsale.member.application.dto.MemberActivityDeleteRequest;
import com.emmsale.member.application.dto.MemberActivityInitialRequest;
Expand Down Expand Up @@ -72,6 +73,15 @@ public ResponseEntity<Void> updateOpenProfileUrl(
return ResponseEntity.noContent().build();
}

@PutMapping("/members/description")
public ResponseEntity<Void> updateDescription(
final Member member,
@RequestBody final DescriptionRequest descriptionRequest
) {
memberUpdateService.updateDescription(member, descriptionRequest);
return ResponseEntity.noContent().build();
}

@GetMapping("/members/{member-id}")
public ResponseEntity<MemberProfileResponse> findProfile(
@PathVariable("member-id") final Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.emmsale.member.application;

import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.OpenProfileUrlRequest;
import com.emmsale.member.domain.Member;
import com.emmsale.member.domain.MemberRepository;
import com.emmsale.member.exception.MemberException;
import com.emmsale.member.exception.MemberExceptionType;
import javax.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -18,9 +21,18 @@ public void updateOpenProfileUrl(
final Member member,
final OpenProfileUrlRequest openProfileUrlRequest
) {
final Member persistMember = memberRepository.findById(member.getId()).get();
final Member persistMember = memberRepository.findById(member.getId())
.orElseThrow(() -> new MemberException((MemberExceptionType.NOT_FOUND_MEMBER)));
final String openProfileUrl = openProfileUrlRequest.getOpenProfileUrl();

persistMember.updateOpenProfileUrl(openProfileUrl);
}

public void updateDescription(final Member member, final DescriptionRequest descriptionRequest) {
final String description = descriptionRequest.getDescription();

final Member persistMember = memberRepository.findById(member.getId())
.orElseThrow(() -> new MemberException((MemberExceptionType.NOT_FOUND_MEMBER)));
persistMember.updateDescription(description);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.emmsale.member.application.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class DescriptionRequest {

private String description;

public DescriptionRequest(final String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.emmsale.member.domain;

import com.emmsale.base.BaseEntity;
import com.emmsale.member.exception.MemberException;
import com.emmsale.member.exception.MemberExceptionType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -15,13 +17,16 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseEntity {

private static final int MAX_DESCRIPTION_LENGTH = 100;
private static final String DEFAULT_DESCRIPTION = "";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false)
private Long githubId;
private String name;
@Column
@Column(nullable = false)
private String description;
@Column
private String openProfileUrl;
Expand All @@ -33,11 +38,13 @@ public Member(final Long id, final Long githubId, final String imageUrl, final S
this.githubId = githubId;
this.imageUrl = imageUrl;
this.name = name;
this.description = DEFAULT_DESCRIPTION;
}

public Member(final Long githubId, final String imageUrl) {
this.githubId = githubId;
this.imageUrl = imageUrl;
this.description = DEFAULT_DESCRIPTION;
}

public void updateName(final String name) {
Expand All @@ -48,8 +55,30 @@ public void updateOpenProfileUrl(final String openProfileUrl) {
this.openProfileUrl = openProfileUrl;
}

public void updateDescription(final String description) {
validateDescriptionNull(description);
validateDescriptionLength(description);
if (description.isBlank()) {
this.description = DEFAULT_DESCRIPTION;
return;
}
this.description = description;
}

private void validateDescriptionNull(final String description) {
if (description == null) {
throw new MemberException(MemberExceptionType.NULL_DESCRIPTION);
}
}

private void validateDescriptionLength(final String description) {
if (description.length() > MAX_DESCRIPTION_LENGTH) {
throw new MemberException(MemberExceptionType.OVER_LENGTH_DESCRIPTION);
}
}

public boolean isNotMe(final Member member) {
return !member.getId().equals(id);
return isNotMe(member.getId());
}

public boolean isMe(final Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public enum MemberExceptionType implements BaseExceptionType {
INVALID_ACTIVITY_IDS(
HttpStatus.BAD_REQUEST,
"요청한 activity id들 중에 유효하지 않은 값이 존재합니다"
),
NULL_DESCRIPTION(
HttpStatus.BAD_REQUEST,
"한 줄 자기소개는 null이 될 수 없습니다."
),

OVER_LENGTH_DESCRIPTION(
HttpStatus.BAD_REQUEST,
"한줄 자기소개에 입력 가능한 글자 수를 초과했습니다."
);

private final HttpStatus httpStatus;
Expand Down
16 changes: 16 additions & 0 deletions backend/emm-sale/src/main/resources/http/member.http
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ Content-Type: application/json
"openProfileUrl": "https://open.kakao.com/profile"
}

### 사용자의 한줄 자기소개 업데이트
PUT http://localhost:8080/members/description
Content-Type: application/json

{
"description": "안녕하세요 김개발입니다."
}

### 사용자의 한줄 자기소개 100자 초과 업데이트
PUT http://localhost:8080/members/description
Content-Type: application/json

{
"description": "안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요안녕하세요!"
}

### 사용자의 프로필 정보 조회
GET http://localhost:8080/members/1
Content-Type: application/json
2 changes: 1 addition & 1 deletion backend/emm-sale/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ create table member
id bigint auto_increment primary key,
created_at datetime(6),
updated_at datetime(6),
description varchar(255) null,
description varchar(255) not null default '',
github_id bigint not null unique,
image_url varchar(255) not null,
name varchar(255) ,
Expand Down
Loading

0 comments on commit 7a69c4a

Please sign in to comment.