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

Deploy: Develop -> main #34

Merged
merged 15 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/main/java/com/beotkkot/qtudy/common/ResponseCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ResponseCode {
String NOT_EXISTED_USER = "NEU";
String NOT_EXISTED_POST = "NEP";
String NOT_EXISTED_COMMENT = "NEC";
String INVALID_FORMAT = "IF";

// HTTP Status 401
String SIGN_IN_FAIL = "SF";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ResponseMessage {
String NOT_EXISTED_USER = "This user does not exist.";
String NOT_EXISTED_POST = "This post does not exist.";
String NOT_EXISTED_COMMENT = "This comment does not exist.";
String INVALID_FORMAT = "Invalid Format";

// HTTP Status 401
String SIGN_IN_FAIL = "Login information mismatch.";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.beotkkot.qtudy.controller.mypage;

import com.beotkkot.qtudy.dto.response.mypage.GetMyInterestResponseDto;
import com.beotkkot.qtudy.dto.response.mypage.GetMyPageAllResponseDto;
import com.beotkkot.qtudy.dto.response.mypage.GetMyPageInfoResponseDto;
import com.beotkkot.qtudy.dto.response.mypage.MyInterestResponseDto;
import com.beotkkot.qtudy.service.auth.AuthService;
import com.beotkkot.qtudy.service.mypage.MyPageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
public class MyPageController {

private final AuthService authService;
private final MyPageService myPageService;

// 관심 분야 목록 초기 선택
@PostMapping("/my/interests")
public ResponseEntity<? super MyInterestResponseDto> saveMyInterests(@RequestParam("interests") List<Long> interests, @RequestHeader("Authorization") String token) {

Long kakao_uid;
try {
kakao_uid = authService.getKakaoUserInfo(token).getId();
if (kakao_uid == null)
return MyInterestResponseDto.noAuthentication();
} catch (Exception exception) {
log.info(exception.getMessage());
return MyInterestResponseDto.databaseError();
}

ResponseEntity<? super MyInterestResponseDto> response = myPageService.saveMyInterests(kakao_uid, interests);
return response;
}

// 내 관심 분야 목록 조회
@GetMapping("my/interests")
public ResponseEntity<? super GetMyInterestResponseDto> getMyInterests(@RequestHeader("Authorization") String token) {
Long kakao_uid;
try {
kakao_uid = authService.getKakaoUserInfo(token).getId();
if (kakao_uid == null)
return GetMyInterestResponseDto.noAuthentication();
} catch (Exception exception) {
log.info(exception.getMessage());
return GetMyInterestResponseDto.databaseError();
}
ResponseEntity<? super GetMyInterestResponseDto> response = myPageService.getMyInterests(kakao_uid);
return response;
}

// 내 관심 분야 목록 수정
@PatchMapping("my/interests")
public ResponseEntity<? super MyInterestResponseDto> patchMyInterests(@RequestParam("interests") List<Long> interests, @RequestHeader("Authorization") String token) {
Long kakao_uid;
try {
kakao_uid = authService.getKakaoUserInfo(token).getId();
if (kakao_uid == null)
return MyInterestResponseDto.noAuthentication();
} catch (Exception exception) {
log.info(exception.getMessage());
return MyInterestResponseDto.databaseError();
}
ResponseEntity<? super MyInterestResponseDto> response = myPageService.patchMyInterests(kakao_uid, interests);
return response;
}

// 사용자 프로필 조회
@GetMapping("/my")
public ResponseEntity<? super GetMyPageInfoResponseDto> getMyPageInfo(@RequestHeader("Authorization") String token) {

Long kakao_uid;
String email;
try {
kakao_uid = authService.getKakaoUserInfo(token).getId();
if (kakao_uid == null)
return GetMyPageInfoResponseDto.noAuthentication();
email = authService.getKakaoUserInfo(token).getEmail();
} catch (Exception exception) {
log.info(exception.getMessage());
return GetMyPageInfoResponseDto.databaseError();
}

ResponseEntity<? super GetMyPageInfoResponseDto> response = myPageService.getMyPageInfo(kakao_uid, email);

return response;
}

// 내가 작성한 게시글 확인
@GetMapping("my/posts")
public ResponseEntity<? super GetMyPageAllResponseDto> getAllPost(@RequestParam("page") int page, @RequestHeader("Authorization") String token) {
Long kakao_uid;
try {
kakao_uid = authService.getKakaoUserInfo(token).getId();
if (kakao_uid == null)
return GetMyPageAllResponseDto.noAuthentication();
} catch (Exception exception) {
log.info(exception.getMessage());
return GetMyPageAllResponseDto.databaseError();
}

ResponseEntity<? super GetMyPageAllResponseDto> response = myPageService.getAllPost(kakao_uid, page);
return response;
}

// 내가 스크랩한 글 확인
@GetMapping("/my/scrap")
public ResponseEntity<? super GetMyPageAllResponseDto> getAllScrapPost(@RequestParam("page") int page, @RequestHeader("Authorization") String token) {
Long kakao_uid;
try {
kakao_uid = authService.getKakaoUserInfo(token).getId();
if (kakao_uid == null)
return GetMyPageAllResponseDto.noAuthentication();
} catch (Exception exception) {
log.info(exception.getMessage());
return GetMyPageAllResponseDto.databaseError();
}

ResponseEntity<? super GetMyPageAllResponseDto> response = myPageService.getAllScrapPost(kakao_uid, page);
return response;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.beotkkot.qtudy.domain.category;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long categoryId;

private String name;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/beotkkot/qtudy/domain/interests/Interests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.beotkkot.qtudy.domain.interests;

import com.beotkkot.qtudy.domain.primaryKey.InterestsPK;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@IdClass(InterestsPK.class) // 복합 키 생성
public class Interests {
@Id
private Long userId;

@Id
private Long categoryId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.beotkkot.qtudy.domain.primaryKey;

import jakarta.persistence.Column;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class InterestsPK implements Serializable {
@Column(name = "user_id")
private Long userId;

@Column(name = "category_id")
private Long categoryId;
}
2 changes: 2 additions & 0 deletions src/main/java/com/beotkkot/qtudy/domain/user/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public class Users {
private String name;

private String profileImageUrl;

private boolean first;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class KakaoUserInfo {
private Long id;
private String name;
private String email;
private String profileImageUrl;
private String accessToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class GetAuthResponseDto extends ResponseDto {
private String accessToken;
private String name;
private String profileImageUrl;
private boolean first;

@Builder
private GetAuthResponseDto(Users user, String accessToken) {
Expand All @@ -27,6 +28,7 @@ private GetAuthResponseDto(Users user, String accessToken) {
this.accessToken = accessToken;
this.name = user.getName();
this.profileImageUrl = user.getProfileImageUrl();
this.first = user.isFirst();
}

public static ResponseEntity<GetAuthResponseDto> success(Users user, String accessToken) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.beotkkot.qtudy.dto.response.mypage;

import com.beotkkot.qtudy.common.ResponseCode;
import com.beotkkot.qtudy.common.ResponseMessage;
import com.beotkkot.qtudy.dto.response.ResponseDto;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.List;

@Getter
public class GetMyInterestResponseDto extends ResponseDto {

private List<Long> interests;

public GetMyInterestResponseDto(List<Long> interests) {
super(ResponseCode.SUCCESS, ResponseMessage.SUCCESS);
this.interests = interests;
}

public static ResponseEntity<GetMyInterestResponseDto> success(List<Long> interestIds) {
GetMyInterestResponseDto result = new GetMyInterestResponseDto(interestIds);
return ResponseEntity.status(HttpStatus.OK).body(result);
}

public static ResponseEntity<ResponseDto> noAuthentication() {
ResponseDto result = new ResponseDto(ResponseCode.AUTHORIZATION_FAIL, ResponseMessage.AUTHORIZATION_FAIL);
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
}

public static ResponseEntity<ResponseDto> notExistedUser() {
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_USER, ResponseMessage.NOT_EXISTED_USER);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.beotkkot.qtudy.dto.response.mypage;

import com.beotkkot.qtudy.common.ResponseCode;
import com.beotkkot.qtudy.common.ResponseMessage;
import com.beotkkot.qtudy.dto.object.PostListItem;
import com.beotkkot.qtudy.dto.response.ResponseDto;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.List;


@Getter
public class GetMyPageAllResponseDto extends ResponseDto {
private int page;
private int totalPages;
private List<PostListItem> postList;

public GetMyPageAllResponseDto(List<PostListItem> postListItem, int page, int totalPages) {
super(ResponseCode.SUCCESS, ResponseMessage.SUCCESS);
this.page = page;
this.totalPages = totalPages;
this.postList = postListItem;
}

public static ResponseEntity<GetMyPageAllResponseDto> success(List<PostListItem> postListItem, int page, int totalPages) {
GetMyPageAllResponseDto result = new GetMyPageAllResponseDto(postListItem, page, totalPages);
return ResponseEntity.status(HttpStatus.OK).body(result);
}

public static ResponseEntity<ResponseDto> notExistedPost(){
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_POST, ResponseMessage.NOT_EXISTED_POST);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}

public static ResponseEntity<ResponseDto> notExistedUser() {
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_USER, ResponseMessage.NOT_EXISTED_USER);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}

public static ResponseEntity<ResponseDto> noAuthentication() {
ResponseDto result = new ResponseDto(ResponseCode.AUTHORIZATION_FAIL, ResponseMessage.AUTHORIZATION_FAIL);
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.beotkkot.qtudy.dto.response.mypage;

import com.beotkkot.qtudy.common.ResponseCode;
import com.beotkkot.qtudy.common.ResponseMessage;
import com.beotkkot.qtudy.domain.user.Users;
import com.beotkkot.qtudy.dto.response.ResponseDto;
import lombok.Builder;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

@Getter
public class GetMyPageInfoResponseDto extends ResponseDto {

private String name;
private String profileImageUrl;
private String email;

@Builder
private GetMyPageInfoResponseDto(Users user, String email) {
super(ResponseCode.SUCCESS, ResponseMessage.SUCCESS);
this.name = user.getName();
this.email = email;
this.profileImageUrl = null;
}

public static ResponseEntity<GetMyPageInfoResponseDto> success(Users user, String email) {
GetMyPageInfoResponseDto result = new GetMyPageInfoResponseDto(user, email);
return ResponseEntity.status(HttpStatus.OK).body(result);
}

public static ResponseEntity<ResponseDto> noAuthentication() {
ResponseDto result = new ResponseDto(ResponseCode.AUTHORIZATION_FAIL, ResponseMessage.AUTHORIZATION_FAIL);
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
}

public static ResponseEntity<ResponseDto> notExistedUser() {
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_USER, ResponseMessage.NOT_EXISTED_USER);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}
}
Loading