Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] User 관련 API 구현 완료 #111

Merged
merged 43 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
78e9154
feat: getMe API 구현
simta1 Aug 8, 2024
d8c9626
refactor: userService 함수명 변경
simta1 Aug 9, 2024
ecc3cef
feat: updateMe api 구현
simta1 Aug 9, 2024
08648cb
feat: deleteMe api 구현
simta1 Aug 9, 2024
e8c67da
feat: getMe test, restDocs 추가
simta1 Aug 9, 2024
da1a64d
feat: updateMe test, restDocs 추가
simta1 Aug 9, 2024
3563c53
feat: deleteMe test, restDocs 추가
simta1 Aug 9, 2024
be21975
feat: restDocs 추가
simta1 Aug 11, 2024
8282e39
feat: UpdateUserRequest validation 추가
simta1 Aug 14, 2024
a7bf211
fix: 회원가입 시 연관 엔티티 삭제되는 문제 해결
simta1 Aug 15, 2024
1583db0
fix: INACTIVE 유저 포함
simta1 Aug 16, 2024
1d98039
fix: getMe에서 학과정보 확인할 때 오류나는 문제 해결
simta1 Aug 16, 2024
ae767c7
fix: updateMe 공백 방지, 버그 수정
simta1 Aug 16, 2024
a98a8cd
feat: updateMe patch에서 put으로 변경
simta1 Aug 17, 2024
3b747ef
feat: getUserInquiries, getUserProposals 구현
simta1 Aug 22, 2024
4d5180d
feat: getUserInquiries, getUserProposals restDocs 추가
simta1 Aug 22, 2024
6ff147b
feat: getDepartments api 구현
simta1 Aug 22, 2024
9e085a7
feat: getDepartments restdocs 추가
simta1 Aug 22, 2024
032db9f
refactor: userUpdateRequest dto 변수명 auth/register과 통일
simta1 Aug 22, 2024
24f30cd
feat: userResponse dto에서 socialLoginId 필드 제거
simta1 Aug 22, 2024
4105a41
fix: updateMe에서 소속, 직책을 빈 문자열로 바꿀 수 있도록 수정
simta1 Aug 22, 2024
b522d13
feat: 유저 삭제 시 좋아요 정보도 삭제되도록 변경
simta1 Aug 22, 2024
5319d2e
feat: getUserFavorites api 구현
simta1 Aug 23, 2024
5b96b52
chore: restdocs 중복정보 제외
simta1 Aug 28, 2024
1b507a3
fix: 소속, 직책 업데이트 로직 수정
simta1 Aug 28, 2024
e01996e
Merge pull request #60 from SystemConsultantGroup/feat/43-user-api/2
simta1 Aug 28, 2024
1f20d69
Merge branch 'feat/43-user-api/base' into feat/43-user-api/3
simta1 Aug 28, 2024
02c8e16
chore: restdocs 중복정보 제외
simta1 Aug 28, 2024
60ca860
chore: department restdocs 수정
simta1 Aug 28, 2024
3aebc9c
feat: transactional 설정 추가
simta1 Aug 28, 2024
d507e3a
feat: getUserFavorites response dto 통일
simta1 Aug 31, 2024
dbacd68
feat: getUserFavorites restdocs 추가
simta1 Aug 31, 2024
ebb721f
fix: getUserInquiries, getUserProposals dto에 답변 여부 필드 추가
simta1 Nov 2, 2024
d28170a
refactor: 답변 엔티티명 reply로 수정
simta1 Nov 3, 2024
1cdadda
merge from develop
simta1 Nov 5, 2024
d2a1cd8
머지 충돌 해결
simta1 Nov 12, 2024
72abc54
feat: getUserFavorites 수정
simta1 Nov 12, 2024
d4c8dd0
Merge pull request #76 from SystemConsultantGroup/feat/43-user-api/3
simta1 Nov 12, 2024
aa577fa
fix: user.adoc 수정
simta1 Nov 19, 2024
4904f0f
docs: .html파일들 삭제
simta1 Nov 19, 2024
b885cb4
merge from develop
simta1 Nov 19, 2024
14b813c
docs: static/docs 생성
simta1 Nov 19, 2024
07e8996
Merge pull request #116 from SystemConsultantGroup/feat/43-user-api/4
simta1 Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/docs/asciidoc/department.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
== 학과 API
:source-highlighter: highlightjs

---

=== 학과 리스트 조회 (GET /departments)
====
operation::department-controller-test/get-departments[snippets="http-request,http-response,response-fields"]
====
4 changes: 3 additions & 1 deletion src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ include::application.adoc[]
include::inquiry.adoc[]
include::project.adoc[]
include::aihub-controller-test.adoc[]
include::jobInfo-controller-test.adoc[]
include::jobInfo-controller-test.adoc[]
include::user.adoc[]
include::department.adoc[]
44 changes: 44 additions & 0 deletions src/docs/asciidoc/user.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
== 유저 API
:source-highlighter: highlightjs

---

=== 로그인 유저 기본 정보 조회 (GET /users/me)
====
operation::user-controller-test/get-me[snippets="http-request,http-response,response-fields"]
====

=== 로그인 유저 기본 정보 수정 (PUT /users/me)
====
operation::user-controller-test/update-me[snippets="http-request,request-fields,http-response,response-fields"]
====

=== 유저 탈퇴 (DELETE /users/me)
====
operation::user-controller-test/delete-me[snippets="http-request,http-response"]
====

=== 유저 관심 프로젝트 리스트 조회 (GET /users/favorites/projects)
====
operation::user-controller-test/get-user-favorite-projects[snippets="http-request,http-response,response-fields"]
====

=== 유저 관심 대담영상 리스트 조회 (GET /users/favorites/talks)
====
operation::user-controller-test/get-user-favorite-talks[snippets="http-request,http-response,response-fields"]
====

=== 유저 관심 잡페어인터뷰영상 리스트 조회 (GET /users/favorites/jobInterviews)
====
operation::user-controller-test/get-user-favorite-interviews[snippets="http-request,http-response,response-fields"]
====

=== 유저 문의 리스트 조회 (GET /users/inquiries)
====
operation::user-controller-test/get-user-inquiries[snippets="http-request,http-response,response-fields"]
====

=== 유저 과제 제안 리스트 조회 (GET /users/proposals)
====
operation::user-controller-test/get-user-proposals[snippets="http-request,http-response,response-fields"]
====
2 changes: 2 additions & 0 deletions src/main/java/com/scg/stop/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ public RegisterResponse finishRegister(User user, RegisterRequest registerReques
user
, department);
studentRepository.save(student);
user.updateStudentInfo(student);
}
else if (Arrays.asList(UserType.INACTIVE_PROFESSOR, UserType.INACTIVE_COMPANY)
.contains(registerRequest.getUserType())) {
Application application = new Application(registerRequest.getDivision(), registerRequest.getPosition(),
user);
applicationRepository.save(application);
user.updateApplication(application);
}
user.register(registerRequest.getName(),
registerRequest.getEmail(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ public class Proposal extends BaseTimeEntity {
private User user;

@OneToOne(fetch = LAZY, mappedBy = "proposal")
private ProposalResponse proposalResponse;
private ProposalReply reply;

public void setUser(User user) {
this.user = user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Entity
@Getter
@NoArgsConstructor(access = PROTECTED)
public class ProposalResponse extends BaseTimeEntity {
public class ProposalReply extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.scg.stop.domain.proposal.repository;

import com.scg.stop.domain.proposal.domain.Proposal;
import com.scg.stop.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ProposalRepository extends JpaRepository<Proposal, Long> {
List<Proposal> findByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public enum ExceptionCode {
INVALID_USERTYPE(4005, "회원 가입 이용이 불가능한 회원 유형입니다."),
NOT_FOUND_APPLICATION_ID(4010, "ID에 해당하는 인증 신청 정보가 존재하지 않습니다."),
ALREADY_VERIFIED_USER(4011, "이미 인증 된 회원입니다."),
UNABLE_TO_EDIT_USER_TYPE(4100, "회원 유형은 수정할 수 없습니다."),
DIVISION_OR_POSITION_REQUIRED(4101, "소속 또는 직책의 형식이 잘못되었습니다."),

// project domain
NOT_FOUND_PROJECT(77000, "프로젝트를 찾을 수 없습니다."),
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/scg/stop/project/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public class Comment extends BaseTimeEntity {
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "user_id")
private User user;

public void setUser(User user) {
this.user = user;
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/scg/stop/project/domain/Inquiry.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Inquiry extends BaseTimeEntity {
@JoinColumn(name = "user_id")
private User user;

@OneToOne(fetch = LAZY, mappedBy = "inquiry", cascade = CascadeType.ALL, orphanRemoval = true)
@OneToOne(fetch = LAZY, mappedBy = "inquiry")
private InquiryReply reply;

private Inquiry(String title, String content, Project project, User user) {
Expand All @@ -55,4 +55,8 @@ public void updateInquiry(String title, String content) {
public void deleteReply() {
this.reply = null;
}

public void setUser(User user) {
this.user = user;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/scg/stop/project/domain/Likes.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public class Likes extends BaseTimeEntity {
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "user_id")
private User user;

public void setUser(User user) {
this.user = user;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.scg.stop.project.repository;

import com.scg.stop.project.domain.FavoriteProject;
import com.scg.stop.project.domain.Project;
import com.scg.stop.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface FavoriteProjectRepository extends JpaRepository<FavoriteProject, Long> {
Optional<FavoriteProject> findByProjectIdAndUserId(Long projectId, Long userId);

@Query("SELECT f.project FROM FavoriteProject f WHERE f.user = :user")
List<Project> findAllByUser(@Param("user") User user);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.scg.stop.project.repository;

import com.scg.stop.project.domain.Inquiry;
import com.scg.stop.user.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface InquiryRepository extends JpaRepository<Inquiry, Long> {
@Query("SELECT i FROM Inquiry i WHERE :title IS NULL OR i.title LIKE %:title%")
Page<Inquiry> findInquiries(@Param("title") String title, Pageable pageable);

List<Inquiry> findByUser(User user);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.scg.stop.user.controller;

import com.scg.stop.user.dto.response.DepartmentResponse;
import com.scg.stop.user.service.DepartmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/departments")
public class DepartmentController {

private final DepartmentService departmentService;

@GetMapping
public ResponseEntity<List<DepartmentResponse>> getDepartments() {
List<DepartmentResponse> departments = departmentService.getDepartments();
return ResponseEntity.ok(departments);
}
}
79 changes: 79 additions & 0 deletions src/main/java/com/scg/stop/user/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.scg.stop.user.controller;

import com.scg.stop.auth.annotation.AuthUser;
import com.scg.stop.project.dto.response.ProjectResponse;
import com.scg.stop.user.domain.AccessType;
import com.scg.stop.user.domain.User;
import com.scg.stop.user.dto.request.UserUpdateRequest;
import com.scg.stop.user.dto.response.FavoriteResponse;
import com.scg.stop.user.dto.response.UserInquiryResponse;
import com.scg.stop.user.dto.response.UserProposalResponse;
import com.scg.stop.user.dto.response.UserResponse;
import com.scg.stop.user.service.UserService;
import com.scg.stop.video.dto.response.JobInterviewUserResponse;
import com.scg.stop.video.dto.response.TalkUserResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/users")
public class UserController {

private final UserService userService;

@GetMapping("/me")
public ResponseEntity<UserResponse> getMe(@AuthUser(accessType = {AccessType.ALL}) User user) {
UserResponse userResponse = userService.getMe(user);
return ResponseEntity.ok(userResponse);
}

@PutMapping("/me")
public ResponseEntity<UserResponse> updateMe(
@AuthUser(accessType = {AccessType.ALL}) User user,
@RequestBody @Valid UserUpdateRequest request
) {
UserResponse updatedUserResponse = userService.updateMe(user, request);
return ResponseEntity.ok(updatedUserResponse);
}

@DeleteMapping("/me")
public ResponseEntity<Void> deleteMe(@AuthUser(accessType = {AccessType.ALL}) User user) {
userService.deleteMe(user);
return ResponseEntity.noContent().build();
}

@GetMapping("/inquiries")
public ResponseEntity<List<UserInquiryResponse>> getUserInquiries(@AuthUser(accessType = {AccessType.ALL}) User user) {
List<UserInquiryResponse> inquiries = userService.getUserInquiries(user);
return ResponseEntity.ok(inquiries);
}

@GetMapping("/proposals")
public ResponseEntity<List<UserProposalResponse>> getUserProposals(@AuthUser(accessType = {AccessType.ALL}) User user) {
List<UserProposalResponse> proposals = userService.getUserProposals(user);
return ResponseEntity.ok(proposals);
}

@GetMapping("/favorites/projects")
public ResponseEntity<List<ProjectResponse>> getUserFavoriteProjects(@AuthUser(accessType = {AccessType.ALL}) User user) {
List<ProjectResponse> userFavoriteProjects = userService.getUserFavoriteProjects(user);
return ResponseEntity.ok(userFavoriteProjects);
}

@GetMapping("/favorites/talks")
public ResponseEntity<List<TalkUserResponse>> getUserFavoriteTalks(@AuthUser(accessType = {AccessType.ALL}) User user) {
List<TalkUserResponse> userFavoriteTalks = userService.getUserFavoriteTalks(user);
return ResponseEntity.ok(userFavoriteTalks);
}

@GetMapping("/favorites/jobInterviews")
public ResponseEntity<List<JobInterviewUserResponse>> getUserFavoriteInterviews(@AuthUser(accessType = {AccessType.ALL}) User user) {
List<JobInterviewUserResponse> userFavoriteInterviews = userService.getUserFavoriteInterviews(user);
return ResponseEntity.ok(userFavoriteInterviews);
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/scg/stop/user/domain/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ public void activate() {
public void reject() {
status = ApplicationStatus.REJECTED;
}

public void updateDivision(String newDivision) {
this.division = newDivision;
}

public void updatePosition(String newPosition) {
this.position = newPosition;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/scg/stop/user/domain/Department.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public class Department extends BaseTimeEntity {

@OneToMany(fetch = LAZY, mappedBy = "department")
private List<Student> students = new ArrayList<>();

public void updateName(String newName) {
this.name = newName;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/scg/stop/user/domain/FavoriteType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.scg.stop.user.domain;

public enum FavoriteType {
PROJECT, // 프로젝트
TALK, // 대담영상
JOBINTERVIEW // 잡페어영상
}
8 changes: 8 additions & 0 deletions src/main/java/com/scg/stop/user/domain/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ public static Student of(String studentNumber, User user, Department department)
.department(department)
.build();
}

public void updateStudentNumber(String newStudentNumber) {
this.studentNumber = newStudentNumber;
}

public void updateDepartment(Department newDepartment) {
this.department = newDepartment;
}
}
Loading
Loading