Skip to content

Commit

Permalink
feat: 프로필 API (#45)
Browse files Browse the repository at this point in the history
* add: 1번 기능 추가

* fix: 관심사 설정 변경 (엔티티 수정 필요)

* fix: 기존의 '직접 입력할게요' 내용 삭제, subCategory엔티티 수정

* add: 멤버 기본 설정 바꾸기 추가
  • Loading branch information
YamYamee authored Aug 11, 2024
1 parent 0fb7395 commit 016a656
Show file tree
Hide file tree
Showing 73 changed files with 446 additions and 217 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/umc/owncast/RootController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.umc.owncast;

import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.umc.owncast.common.config;

import com.umc.owncast.common.jwt.*;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -10,12 +9,10 @@
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
Expand All @@ -27,7 +24,7 @@
@Configuration
@EnableWebSecurity //기본적인 웹보안 활성화
@RequiredArgsConstructor
public class SecurityConfig{
public class SecurityConfig {

private final AuthenticationConfiguration authenticationConfiguration;
private final JwtUtil jwtUtil;
Expand Down Expand Up @@ -58,6 +55,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
.addFilterBefore(new LogoutFilter(loginService), org.springframework.security.web.authentication.logout.LogoutFilter.class)
.build();
}

@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
Expand All @@ -66,7 +64,7 @@ public BCryptPasswordEncoder bCryptPasswordEncoder() {
CorsConfigurationSource apiConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("*")); // 이후 수정
configuration.setAllowedMethods(Arrays.asList("GET","POST"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.umc.owncast.common.entity;


import java.time.LocalDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
Expand All @@ -13,6 +12,8 @@
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.umc.owncast.common.exception;

import com.umc.owncast.common.response.ErrorReasonDTO;
import com.umc.owncast.common.response.ApiResponse;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

import com.umc.owncast.common.response.ErrorReasonDTO;
import com.umc.owncast.common.response.status.ErrorCode;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.ConstraintViolationException;
Expand All @@ -23,6 +18,10 @@
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

@Slf4j
@RestControllerAdvice(annotations = {RestController.class})
public class ExceptionAdvice extends ResponseEntityExceptionHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ErrorReasonDTO getErrorReason() {
return this.code.getReason();
}

public ErrorReasonDTO getErrorReasonHttpStatus(){
public ErrorReasonDTO getErrorReasonHttpStatus() {
return this.code.getReasonHttpStatus();
}
}
7 changes: 3 additions & 4 deletions src/main/java/com/umc/owncast/common/jwt/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import com.umc.owncast.domain.member.dto.CustomUserDetails;
import com.umc.owncast.domain.member.entity.Member;
import io.jsonwebtoken.ExpiredJwtException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/umc/owncast/common/jwt/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/umc/owncast/common/jwt/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import io.jsonwebtoken.ExpiredJwtException;
import jakarta.servlet.http.Cookie;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -32,13 +32,13 @@ public class LoginService {
private Long refreshExpirationTime;

public String issueAccessToken(Long userId) {
String accessToken = jwtUtil.createJwt("access", userId, accessExpirationTime*1000L);
String accessToken = jwtUtil.createJwt("access", userId, accessExpirationTime * 1000L);
return "Bearer " + accessToken;
}

@Transactional
public String issueRefreshToken(Long userId) {
String refreshToken = jwtUtil.createJwt("refresh", userId, refreshExpirationTime*1000L);
String refreshToken = jwtUtil.createJwt("refresh", userId, refreshExpirationTime * 1000L);
saveRefreshToken(userId, refreshToken, refreshExpirationTime);
return refreshToken;
}
Expand All @@ -47,7 +47,7 @@ public String issueRefreshToken(Long userId) {
@Transactional
public String reissueRefreshToken(Long userId, String refreshToken) {
refreshRepository.deleteByRefreshToken(refreshToken);
String newRefreshToken = jwtUtil.createJwt("refresh", userId, refreshExpirationTime*1000L);
String newRefreshToken = jwtUtil.createJwt("refresh", userId, refreshExpirationTime * 1000L);
saveRefreshToken(userId, newRefreshToken, refreshExpirationTime);
return newRefreshToken;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static <T> ApiResponse<T> of(BaseCode code, T result) {
public static <T> ApiResponse<T> onFailure(String code, String message, T data) {
return new ApiResponse<>(false, code, message, data);
}

public static <T> ApiResponse<T> ofFailure(BaseErrorCode code, T result) {
return new ApiResponse<>(false, code.getReasonHttpStatus().getCode(), code.getReasonHttpStatus().getMessage(), result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class ErrorReasonDTO {
private final String code;
private final String message;

public boolean getIsSuccess(){return isSuccess;}
public boolean getIsSuccess() {
return isSuccess;
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/umc/owncast/common/response/ReasonDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class ReasonDTO {
private final String code;
private final String message;

public boolean getIsSuccess(){return isSuccess;}
public boolean getIsSuccess() {
return isSuccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum ErrorCode implements BaseErrorCode {

//Playlist 관련 에러
PLAYLIST_NOT_FOUND(HttpStatus.BAD_REQUEST, "PLAYLIST4001", "해당 플레이리스트가 없습니다."),
PLAYLIST_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "PLAYLIST4002", "이미 존재하는 플레이리스트입니다.");
PLAYLIST_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "PLAYLIST4002", "이미 존재하는 플레이리스트입니다."),
// 기타 에러는 아래에 추가
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum SuccessCode implements BaseCode {
// 회원가입 응답
_SIGNUP_SUCCESS(HttpStatus.OK, "SIGNUP200", "회원가입 성공입니다."),
_LOGIN_SUCCESS(HttpStatus.OK, "LOGIN200", "로그인 성공입니다."),

// 기타 응답은 아래에 추가
;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/owncast/common/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Objects;

public class StringUtil {
public static boolean isBlank(String s){
public static boolean isBlank(String s) {
return Objects.isNull(s) || s.isBlank();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {
@Query("SELECT b.sentence FROM Bookmark b WHERE b.castPlaylist.playlist.id = :playlistId")
List<Sentence> findSentencesByPlaylistId(@Param("playlistId") Long playlistId);

Optional<Bookmark> findBookmarkBySentenceIdAndCastPlaylist_Playlist_Member_id(@Param("sentenceId") Long sentenceId , @Param("memberId") Long memberId);
Optional<Bookmark> findBookmarkBySentenceIdAndCastPlaylist_Playlist_Member_id(@Param("sentenceId") Long sentenceId, @Param("memberId") Long memberId);

List<Bookmark> findBookmarksByCastPlaylist_Cast_Id(@Param("castId") Long castId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import com.umc.owncast.domain.castplaylist.entity.CastPlaylist;
import com.umc.owncast.domain.sentence.entity.Sentence;
import jakarta.persistence.*;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@Entity
@Table(name = "bookmark")
@AllArgsConstructor
public class Bookmark extends BaseTimeEntity{
public class Bookmark extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BookMarkServiceImpl {
private final SentenceRepository sentenceRepository;
private final CastRepository castRepository;

public List<BookMarkDTO.BookMarkResultDTO> getMyCastBookmarks(){
public List<BookMarkDTO.BookMarkResultDTO> getMyCastBookmarks() {

List<Cast> castList = castRepository.findCastsByMember_Id(1L);
List<BookMarkDTO.BookMarkResultDTO> sentenceList = new ArrayList<>(List.of());
Expand All @@ -53,7 +53,7 @@ public List<BookMarkDTO.BookMarkResultDTO> getMyCastBookmarks(){
return sentenceList;
}

public List<BookMarkDTO.BookMarkResultDTO> getSavedBookmarks(){
public List<BookMarkDTO.BookMarkResultDTO> getSavedBookmarks() {

List<Cast> castList = castPlaylistRepository.findSavedCast(1L);

Expand All @@ -77,7 +77,7 @@ public List<BookMarkDTO.BookMarkResultDTO> getSavedBookmarks(){
return sentenceList;
}

public List<BookMarkDTO.BookMarkResultDTO> getBookmarks(Long playlistId){
public List<BookMarkDTO.BookMarkResultDTO> getBookmarks(Long playlistId) {

List<Sentence> sentenceList = bookmarkRepository.findSentencesByPlaylistId(playlistId);

Expand All @@ -95,20 +95,20 @@ public BookMarkDTO.BookMarkSaveResultDTO saveBookmark(Long sentenceId) {
Optional<CastPlaylist> optionalCastPlaylist = castPlaylistRepository.findBySentenceId(sentenceId, 1L);
CastPlaylist castPlaylist;

if(optionalCastPlaylist.isPresent()){
if (optionalCastPlaylist.isPresent()) {
castPlaylist = optionalCastPlaylist.get();
} else {
throw new UserHandler(ErrorCode._BAD_REQUEST);
}

if(bookmarkRepository.findBookmarkBySentenceIdAndCastPlaylist_Playlist_Member_id(sentenceId, 1L).isPresent()) {
if (bookmarkRepository.findBookmarkBySentenceIdAndCastPlaylist_Playlist_Member_id(sentenceId, 1L).isPresent()) {
throw new UserHandler(ErrorCode.BOOKMARK_ALREADY_EXIST);
}

Bookmark newBookmarks = Bookmark.builder()
.castPlaylist(castPlaylist)
.sentence(sentenceRepository.findById(sentenceId).get())
.build();
.castPlaylist(castPlaylist)
.sentence(sentenceRepository.findById(sentenceId).get())
.build();

bookmarkRepository.save(newBookmarks);

Expand All @@ -121,7 +121,7 @@ public BookMarkDTO.BookMarkSaveResultDTO deleteBookmark(Long sentenceId) {

Optional<Bookmark> optionalBookmark = bookmarkRepository.findBookmarkBySentenceIdAndCastPlaylist_Playlist_Member_id(sentenceId, 1L);

if(optionalBookmark.isPresent()){
if (optionalBookmark.isPresent()) {
bookmarkRepository.delete(optionalBookmark.get());
return BookMarkDTO.BookMarkSaveResultDTO.builder()
.bookmarkId(optionalBookmark.get().getId())
Expand Down
Loading

0 comments on commit 016a656

Please sign in to comment.