Skip to content

Commit

Permalink
Merge pull request TeamMajorLink#27 from kchaeeun/feat#26
Browse files Browse the repository at this point in the history
  • Loading branch information
kchaeeun authored Aug 15, 2024
2 parents 89edde1 + dfe6cf1 commit 538e0a2
Show file tree
Hide file tree
Showing 24 changed files with 744 additions and 46 deletions.
2 changes: 0 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.example.majorLink.controller;

import com.example.majorLink.domain.User;
import com.example.majorLink.dto.request.ProfileCardRequest;
import com.example.majorLink.dto.response.ProfileCardResponse;
import com.example.majorLink.global.auth.AuthUser;
import com.example.majorLink.service.ProfileCardService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequiredArgsConstructor
@RequestMapping("/profile-card")
public class ProfileCardController {
private final ProfileCardService profileCardService;

/**
* 프로필 카드 등록 API
* [POST] /profile-card
* @param authUser
* @param request
* @return
*/
@PostMapping
public ResponseEntity<?> createProfileCard(
@AuthenticationPrincipal AuthUser authUser,
@RequestBody ProfileCardRequest request
) {
User user = authUser.getUser();
profileCardService.createProfileCard(user, request);

return ResponseEntity.status(HttpStatus.CREATED).build();
}

/**
* 프로필 카드 수정 API
* [PATCH] /profile-card
* @param authUser
* @param request
* @return
*/
@PatchMapping
public ResponseEntity<?> modifyProfileCard(
@AuthenticationPrincipal AuthUser authUser,
@RequestBody ProfileCardRequest request
) {
User user = authUser.getUser();
profileCardService.modifyProfileCard(user, request);

return ResponseEntity.status(HttpStatus.OK).build();
}

/**
* 프로필 카드 조회 API
* [GET] /profile-card?userId={userId}
* @param authUser
* @param nickname
* @return
*/
@GetMapping
public ResponseEntity<ProfileCardResponse> getProfileCard(
@AuthenticationPrincipal AuthUser authUser,
@RequestParam(name = "nickname", required = false) String nickname // nickname이 빈 경우를 대비해 쿼리 파라미터 사용
) {
User user = null;
if (authUser != null) {
user = authUser.getUser();
}
ProfileCardResponse profileCardResponse = profileCardService.getProfileCard(user, nickname);
return ResponseEntity.ok()
.body(profileCardResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.example.majorLink.domain.User;
import com.example.majorLink.dto.request.SignInRequest;
import com.example.majorLink.dto.request.SignUpRequest;
import com.example.majorLink.dto.request.UpdateProfileRequest;
import com.example.majorLink.dto.response.ProfileResponse;
import com.example.majorLink.dto.request.UpdateMyPageRequest;
import com.example.majorLink.dto.response.MyPageResponse;
import com.example.majorLink.global.auth.AuthUser;
import com.example.majorLink.global.auth.Tokens;
import com.example.majorLink.global.oauth2.OAuthLoginService;
Expand Down Expand Up @@ -65,31 +65,31 @@ public ResponseEntity<?> signIn(@RequestBody SignInRequest signInRequest) {

/**
* 마이페이지 조회 API
* [GET] /users/profile
* [GET] /users/my-page
* @param authUser
* @return
*/
@GetMapping("/profile")
public ResponseEntity<ProfileResponse> getProfile(@AuthenticationPrincipal AuthUser authUser) {
ProfileResponse profileResponse = userService.getProfile(authUser.getUser());
@GetMapping("/my-page")
public ResponseEntity<MyPageResponse> getMyPage(@AuthenticationPrincipal AuthUser authUser) {
MyPageResponse myPageResponse = userService.getMyPage(authUser.getUser());

return ResponseEntity.ok()
.body(profileResponse);
.body(myPageResponse);
}

/**
* 마이페이지 수정 API
* [PATCH] /users/profile
* [PATCH] /users/my-page
* @param authUser
* @param updateProfileRequest
* @param updateMyPageRequest
* @return
*/
@PatchMapping("/profile")
public ResponseEntity<?> modifyProfile(
@PatchMapping("/my-page")
public ResponseEntity<?> modifyMyPage(
@AuthenticationPrincipal AuthUser authUser,
@RequestBody UpdateProfileRequest updateProfileRequest) {
@RequestBody UpdateMyPageRequest updateMyPageRequest) {
User user = authUser.getUser();
userService.modifyProfile(user, updateProfileRequest);
userService.modifyMyPage(user, updateMyPageRequest);

return ResponseEntity.status(HttpStatus.OK)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.majorLink.domain;

import com.example.majorLink.domain.enums.CheckStatus;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Education extends BaseEntity{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 50)
private String eduName;
@Column(nullable = false, length = 100)
private String process;
private String start;
private String end;
@Enumerated(EnumType.STRING)
private CheckStatus checkStatus = CheckStatus.UNCHECK;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public void updateEduName(String eduName) {
this.eduName = eduName;
}
public void updateProcess(String process) {
this.process = process;
}
public void updateStart(String start) {
this.start = start;
}
public void updateEnd(String end) {
this.end = end;
}
public void updateCheckStatus(CheckStatus checkStatus) {
this.checkStatus = checkStatus;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import jakarta.persistence.*;
import lombok.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
Expand All @@ -13,18 +17,36 @@ public class ProfileCard extends BaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String info;

private String grade;

private String career;

private String lineInfo;
private String selfInfo;
private String portfolio;

private String link;

@OneToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

// 스킬 종속 컬렉션 테이블 생성
@ElementCollection(fetch = FetchType.LAZY)
@JoinTable(name = "skills")
private List<String> skills = new ArrayList<>();

public void updateLineInfo(String lineInfo) {
this.lineInfo = lineInfo;
}
public void updateSelfInfo(String selfInfo) {
this.selfInfo = selfInfo;
}
public void updateSkills(List<String> skills) {
this.skills.clear(); // 기존 기술 삭제
if (skills != null) {
this.skills.addAll(skills);
}
}
public void updatePortfolio(String portfolio) {
this.portfolio = portfolio;
}
public void updateLink(String link) {
this.link = link;
}
}
36 changes: 34 additions & 2 deletions majorLink/src/main/java/com/example/majorLink/domain/Project.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.majorLink.domain;

import com.example.majorLink.domain.enums.CheckStatus;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.*;

@Entity
Expand All @@ -14,8 +16,38 @@ public class Project extends BaseEntity{
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 100)
@Column(nullable = false, length = 50)
private String projectName;

@Column(nullable = false, length = 50)
private String space;
private String start;
private String end;
@Enumerated(EnumType.STRING)
private CheckStatus checkStatus = CheckStatus.UNCHECK;
@Column(nullable = false, length = 255)
private String projectDescript;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public void updateProjectName(String projectName) {
this.projectName = projectName;
}
public void updateSpace(String space) {
this.space = space;
}
public void updateStart(String start) {
this.start = start;
}
public void updateEnd(String end) {
this.end = end;
}
public void updateCheckStatus(CheckStatus checkStatus) {
this.checkStatus = checkStatus;
}
public void updateProjectDescript(String projectDescript) {
this.projectDescript = projectDescript;
}

}
18 changes: 12 additions & 6 deletions majorLink/src/main/java/com/example/majorLink/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class User extends BaseEntity{
@Column(name = "username", nullable = false, length = 20)
private String username;

@Column(nullable = false, length = 20)
private String nickname;
@Column(nullable = false, length = 8)
private String birth;

@Column(nullable = false)
private String password;

Expand All @@ -54,13 +59,8 @@ public class User extends BaseEntity{
@Column(length = 40)
private String favorite;

@Enumerated(EnumType.STRING)
@Column(nullable = false, columnDefinition = "VARCHAR(10) DEFAULT 'TUTEE'")
private Role role;

@Enumerated(EnumType.STRING)
@Column(name = "learnPart", nullable = false, columnDefinition = "VARCHAR(20)")
private LearnPart learnPart;
private String learnPart;

@Column(nullable = false, columnDefinition = "INT DEFAULT 0")
private Integer point;
Expand All @@ -75,6 +75,12 @@ public void updateProfileImg(String profileImage) {
public void updateUsername(String username) {
this.username = username;
}
public void updateNickname(String nickname) {
this.nickname = nickname;
}
public void updateBirth(String birth) {
this.birth = birth;
}
public void updateEmail(String email) {
this.email = email;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.majorLink.dto.request;

import com.example.majorLink.domain.enums.CheckStatus;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;

@Getter
public class EducationRequest {
@NotNull(message = "교육의 id 값을 알아야 수정할 수 있습니다.")
private Long id;
private String eduName;
private String process;
@Size(max = 10, message = "시작일은 10글자를 넘을 수 없습니다.")
private String start;
@Size(max = 10, message = "종료일은 10글자를 넘을 수 없습니다.")
private String end;
private Boolean checkStatus = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.majorLink.dto.request;

import com.example.majorLink.domain.Education;
import com.example.majorLink.domain.Project;
import jakarta.validation.constraints.Size;
import lombok.Getter;

import java.util.List;

@Getter
public class ProfileCardRequest {
@Size(max=100, message = "한 줄 소개는 100자를 초과할 수 없습니다.")
private String lineInfo;
@Size(max=1000, message = "자기소개는 1000자를 초과할 수 없습니다.")
private String selfInfo;
private List<EducationRequest> educations;
private List<ProjectRequest> projects;
private List<String> skills;
private String portfolio;
private String link;
}
Loading

0 comments on commit 538e0a2

Please sign in to comment.