Skip to content
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.fixlog.controller.follow;
package com.example.fixlog.controller;

import com.example.fixlog.dto.Response;
import com.example.fixlog.dto.follow.request.FollowRequestDto;
import com.example.fixlog.dto.follow.request.UnfollowRequestDto;
import com.example.fixlog.dto.follow.response.FollowResponseDto;
import com.example.fixlog.dto.follow.response.FollowerListResponseDto;
import com.example.fixlog.dto.follow.response.FollowingListResponseDto;
import com.example.fixlog.service.follow.FollowService;
import com.example.fixlog.service.FollowService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/example/FixLog/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//package com.example.fixlog.controller;
//
//
//import com.example.fixlog.dto.Response;
//import com.example.fixlog.dto.member.SignupRequestDto;
//import com.example.fixlog.dto.member.DuplicateCheckResponseDto;
//import com.example.fixlog.service.MemberService;
//import lombok.RequiredArgsConstructor;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//@RestController
//@RequestMapping("/api/members")
//@RequiredArgsConstructor
//public class MemberController {
//
// private final MemberService memberService;
//
// @PostMapping("/signup")
// public ResponseEntity<Response<String>> signup(@RequestBody SignupRequestDto request) {
// memberService.signup(request);
// return ResponseEntity.ok(Response.success("회원가입이 완료되었습니다.", null));
// }
//
// @GetMapping("/check-email")
// public ResponseEntity<Response<DuplicateCheckResponseDto>> checkEmail(@RequestParam String email) {
// boolean exists = memberService.isEmailDuplicated(email);
// String msg = exists ? "이미 사용 중인 이메일입니다." : "사용 가능한 이메일입니다.";
// return ResponseEntity.ok(Response.success(msg, new DuplicateCheckResponseDto(exists)));
// }
//
// @GetMapping("/check-nickname")
// public ResponseEntity<Response<DuplicateCheckResponseDto>> checkNickname(@RequestParam String nickname) {
// boolean exists = memberService.isNicknameDuplicated(nickname);
// String msg = exists ? "이미 사용 중인 닉네임입니다." : "사용 가능한 닉네임입니다.";
// return ResponseEntity.ok(Response.success(msg, new DuplicateCheckResponseDto(exists)));
// }
//}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.fixlog.controller.post;
package com.example.fixlog.controller;

import com.example.fixlog.dto.UserIdDto;
import com.example.fixlog.dto.post.PostRequestDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.fixlog.domain.bookmark;


import com.example.fixlog.domain.member.Member;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand All @@ -14,18 +13,24 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BookmarkFolder {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "folderId")
private Long id;
@Column(name = "folder_id")
private Long folderId;

@Column(name = "folderName", nullable = false)
private String name; // 폴더 이름
@Column(name = "folder_name", nullable = false)
private String folderName;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId", nullable = false)
private Member owner;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private Member userId;

@OneToMany(mappedBy = "folder", cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(mappedBy = "folderId", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Bookmark> bookmarks = new ArrayList<>();

public BookmarkFolder(Member userId){
this.userId = userId;
this.folderName = "default folder";
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/example/FixLog/mock/TagTestDataInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.fixlog.mock;

import com.example.fixlog.domain.tag.Tag;
import com.example.fixlog.domain.tag.TagCategory;
import com.example.fixlog.repository.tag.TagRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.example.fixlog.domain.tag.TagCategory.*;

@Component
@RequiredArgsConstructor
public class TagTestDataInitializer implements CommandLineRunner {

private final TagRepository tagRepository;

@Override
public void run(String... args) {
if (tagRepository.count() == 0) {
Tag tag1 = Tag.of(MAJOR_CATEGORY, "101");
Tag tag2 = Tag.of(MAJOR_CATEGORY, "101");
Tag tag3 = Tag.of(MIDDLE_CATEGORY, "201");
Tag tag4 = Tag.of(MINOR_CATEGORY, "301");
tagRepository.saveAll(List.of(tag1, tag2, tag3, tag4));
System.out.println("임시 태그 4개 삽입 완료");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.fixlog.repository.bookmark;

import com.example.fixlog.domain.bookmark.BookmarkFolder;
import com.example.fixlog.domain.member.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BookmarkFolderRepository extends JpaRepository<BookmarkFolder, Long> {
BookmarkFolder findByUserId(Member userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.fixlog.repository.post;

import com.example.fixlog.domain.post.PostTag;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PostTagRepository extends JpaRepository<PostTag, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.fixlog.repository.tag;

import com.example.fixlog.domain.tag.Tag;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TagRepository extends JpaRepository<Tag, Long> {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.fixlog.service.follow;
package com.example.fixlog.service;

import com.example.fixlog.dto.follow.response.FollowResponseDto;
import com.example.fixlog.dto.follow.response.FollowerListResponseDto;
Expand Down Expand Up @@ -26,42 +26,42 @@ public class FollowService {
@Transactional
public FollowResponseDto follow(String requesterEmail, Long targetMemberId){
Member follower = memberRepository.findByEmail(requesterEmail)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBEREMAIL_NOT_FOUNT));
.orElseThrow(() -> new CustomException(ErrorCode.USER_EMAIL_NOT_FOUNT));
Member following = memberRepository.findById(targetMemberId)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBERID_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_ID_NOT_FOUND));

// 자기 자신은 팔로우 불가
if (follower.getId().equals(following.getId())) {
throw new CustomException(ErrorCode.CANNOT_FOLLOW_SELF);
if (follower.getUserId().equals(following.getUserId())) {
throw new CustomException(ErrorCode.SELF_FOLLOW_NOT_ALLOWED);
}

// 중복 팔로우 방지
if (followRepository.existsByFollowerAndFollowing(follower, following)) {
if (followRepository.existsByFollowerIdAndFollowingId(follower, following)) {
throw new CustomException(ErrorCode.ALREADY_FOLLOWING);
}

Follow follow = new Follow(follower, following);
Follow saved = followRepository.save(follow);

return new FollowResponseDto(saved.getId(), following.getId(), following.getNickname());
return new FollowResponseDto(saved.getFollowId(), following.getUserId(), following.getNickname());
}

// 언팔로우하기
@Transactional
public void unfollow(String requesterEmail, Long targetMemberId) {
Member follower = memberRepository.findByEmail(requesterEmail)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBEREMAIL_NOT_FOUNT));
.orElseThrow(() -> new CustomException(ErrorCode.USER_EMAIL_NOT_FOUNT));

Member following = memberRepository.findById(targetMemberId)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBERID_NOT_FOUND));
.orElseThrow(() -> new CustomException(ErrorCode.USER_ID_NOT_FOUND));

// 자기 자신은 팔로우 불가
if (follower.getId().equals(following.getId())) {
throw new CustomException(ErrorCode.CANNOT_FOLLOW_SELF);
if (follower.getUserId().equals(following.getUserId())) {
throw new CustomException(ErrorCode.SELF_FOLLOW_NOT_ALLOWED);
}

Follow follow = followRepository.findByFollowerAndFollowing(follower, following)
.orElseThrow(() -> new CustomException(ErrorCode.CANNOT_UNFOLLOW_SELF));
Follow follow = followRepository.findByFollowerIdAndFollowingId(follower, following)
.orElseThrow(() -> new CustomException(ErrorCode.SELF_UNFOLLOW_NOT_ALLOWED));

followRepository.delete(follow);
}
Expand All @@ -70,15 +70,15 @@ public void unfollow(String requesterEmail, Long targetMemberId) {
@Transactional(readOnly = true)
public List<FollowerListResponseDto> getMyFollowers(String requesterEmail) {
Member me = memberRepository.findByEmail(requesterEmail)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBEREMAIL_NOT_FOUNT));
.orElseThrow(() -> new CustomException(ErrorCode.USER_EMAIL_NOT_FOUNT));

List<Follow> follows = followRepository.findByFollowing(me);
List<Follow> follows = followRepository.findByFollowingId(me);

return follows.stream()
.map(follow -> new FollowerListResponseDto(
follow.getId(),
follow.getFollower().getId(),
follow.getFollower().getNickname()
follow.getFollowId(),
follow.getFollowerId().getUserId(),
follow.getFollowerId().getNickname()
))
.toList();
}
Expand All @@ -87,15 +87,15 @@ public List<FollowerListResponseDto> getMyFollowers(String requesterEmail) {
@Transactional(readOnly = true)
public List<FollowingListResponseDto> getMyFollowings(String requesterEmail) {
Member me = memberRepository.findByEmail(requesterEmail)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBEREMAIL_NOT_FOUNT));
.orElseThrow(() -> new CustomException(ErrorCode.USER_EMAIL_NOT_FOUNT));

List<Follow> follows = followRepository.findByFollower(me);
List<Follow> follows = followRepository.findByFollowerId(me);

return follows.stream()
.map(follow -> new FollowingListResponseDto(
follow.getId(),
follow.getFollowing().getId(),
follow.getFollowing().getNickname()
follow.getFollowId(),
follow.getFollowingId().getUserId(),
follow.getFollowingId().getNickname()
))
.toList();
}
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/example/FixLog/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//package com.example.fixlog.service;
//
//import com.example.fixlog.domain.bookmark.BookmarkFolder;
//import com.example.fixlog.domain.member.Member;
//import com.example.fixlog.domain.member.SocialType;
//import com.example.fixlog.dto.member.SignupRequestDto;
//import com.example.fixlog.exception.CustomException;
//import com.example.fixlog.exception.ErrorCode;
//import com.example.fixlog.repository.MemberRepository;
//import com.example.fixlog.repository.bookmark.BookmarkFolderRepository;
//import lombok.RequiredArgsConstructor;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.stereotype.Service;
//
//@Service
//@RequiredArgsConstructor
//public class MemberService {
//
// private final MemberRepository memberRepository;
// private final PasswordEncoder passwordEncoder;
// private final BookmarkFolderRepository bookmarkFolderRepository;
//
// public void signup(SignupRequestDto request) {
// // 이메일 중복 검사
// if (isEmailDuplicated(request.getEmail())) {
// throw new CustomException(ErrorCode.EMAIL_DUPLICATED);
// }
//
// // 닉네임 중복 검사
// if (isNicknameDuplicated(request.getNickname())) {
// throw new CustomException(ErrorCode.NICKNAME_DUPLICATED);
// }
//
// // 문제 없으면 저장
// Member member = Member.of(
// request.getEmail(),
// passwordEncoder.encode(request.getPassword()),
// request.getNickname(),
// SocialType.EMAIL
// );
//
// // 기본 폴더 생성
// BookmarkFolder newFolder = new BookmarkFolder(member);
// bookmarkFolderRepository.save(newFolder);
//
// memberRepository.save(member);
// }
//
// public boolean isEmailDuplicated(String email) {
// return memberRepository.findByEmail(email).isPresent();
// }
//
// public boolean isNicknameDuplicated(String nickname) {
// return memberRepository.findByNickname(nickname).isPresent();
// }
//}
62 changes: 31 additions & 31 deletions src/main/java/com/example/fixlog/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package com.example.fixlog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers(HttpMethod.POST, "/api/members/signup").permitAll()
.requestMatchers(HttpMethod.GET, "/api/members/check-email").permitAll()
.requestMatchers(HttpMethod.GET, "/api/members/check-nickname").permitAll()
.anyRequest().authenticated()
);
return http.build();
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
//package com.example.fixlog.config;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpMethod;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.web.SecurityFilterChain;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//@Configuration
//public class SecurityConfig {
//
// @Bean
// public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// http
// .csrf(csrf -> csrf.disable())
// .authorizeHttpRequests(auth -> auth
// .requestMatchers(HttpMethod.POST, "/api/members/signup").permitAll()
// .requestMatchers(HttpMethod.GET, "/api/members/check-email").permitAll()
// .requestMatchers(HttpMethod.GET, "/api/members/check-nickname").permitAll()
// .anyRequest().authenticated()
// );
// return http.build();
// }
//
// @Bean
// public PasswordEncoder passwordEncoder() {
// return new BCryptPasswordEncoder();
// }
//}
Loading