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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package es.princip.ringus.application.bookmark;

import es.princip.ringus.domain.bookmark.Bookmark;
import es.princip.ringus.domain.bookmark.BookmarkRepository;
import es.princip.ringus.domain.exception.BookmarkErrorCode;
import es.princip.ringus.domain.exception.MenteeErrorCode;
import es.princip.ringus.domain.exception.MentorErrorCode;
import es.princip.ringus.domain.mentee.Mentee;
import es.princip.ringus.domain.mentee.MenteeRepository;
import es.princip.ringus.domain.mentor.Mentor;
import es.princip.ringus.domain.mentor.MentorRepository;
import es.princip.ringus.global.exception.CustomRuntimeException;
import es.princip.ringus.presentation.bookmark.dto.BookmarkRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class BookmarkService {
private final BookmarkRepository bookmarkRepository;
private final MentorRepository mentorRepository;
private final MenteeRepository menteeRepository;

@Transactional
public Long addBookmark(BookmarkRequest request){
Mentor mentor = findMentorById(request.mentorId());
Mentee mentee = findMenteeById(request.menteeId());

if(bookmarkRepository.findByMentorAndMentee(mentor, mentee).isPresent()){
throw new CustomRuntimeException(BookmarkErrorCode.BOOKMARK_ALREADY_EXIST);
}

Bookmark bookmark = request.toEntity(mentor, mentee);
mentee.addBookmark(bookmark);

return bookmarkRepository.save(bookmark).getId();
}

@Transactional
public void deleteBookmark(BookmarkRequest request){
Mentor mentor = findMentorById(request.mentorId());
Mentee mentee = findMenteeById(request.menteeId());

Bookmark bookmark = bookmarkRepository.findByMentorAndMentee(mentor, mentee)
.orElseThrow(() -> new CustomRuntimeException(BookmarkErrorCode.BOOKMARK_NOT_FOUND));

bookmarkRepository.delete(bookmark);
mentee.deleteBookmark(bookmark);
}

private Mentor findMentorById(Long mentorId) {
return mentorRepository.findById(mentorId)
.orElseThrow(() -> new CustomRuntimeException(MentorErrorCode.MENTOR_PROFILE_NOT_FOUND));
}

private Mentee findMenteeById(Long menteeId) {
return menteeRepository.findById(menteeId)
.orElseThrow(() -> new CustomRuntimeException(MenteeErrorCode.MENTEE_PROFILE_NOT_FOUND));
}
}
39 changes: 39 additions & 0 deletions src/main/java/es/princip/ringus/domain/bookmark/Bookmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package es.princip.ringus.domain.bookmark;

import es.princip.ringus.domain.base.BaseTimeEntity;
import es.princip.ringus.domain.mentee.Mentee;
import es.princip.ringus.domain.mentor.Mentor;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Table(name = "bookmark")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Bookmark extends BaseTimeEntity {

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

@ManyToOne
@JoinColumn(name = "mentor_id", nullable = false)
private Mentor mentor;

@ManyToOne
@JoinColumn(name = "mentee_id", nullable = false)
private Mentee mentee;

@Builder
public Bookmark(
final Mentor mentor,
final Mentee mentee
){
this.mentor = mentor;
this.mentee = mentee;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package es.princip.ringus.domain.bookmark;

import es.princip.ringus.domain.mentee.Mentee;
import es.princip.ringus.domain.mentor.Mentor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {
Optional<Bookmark> findByMentorAndMentee(Mentor mentor, Mentee mentee);

Optional<Bookmark> findByMentee(Mentee mentee);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package es.princip.ringus.domain.exception;

import es.princip.ringus.global.exception.ErrorCode;
import org.springframework.http.HttpStatus;

public enum BookmarkErrorCode implements ErrorCode {

BOOKMARK_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 북마크된 멘토"),
BOOKMARK_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 북마크가 존재하지 않음");

BookmarkErrorCode(HttpStatus status, String message) {
this.status = status;
this.message = message;
}

private final HttpStatus status;
private final String message;

@Override
public HttpStatus status() {
return this.status;
}

@Override
public String message() {
return this.message;
}

@Override
public String code() {
return this.name();
}
}
16 changes: 16 additions & 0 deletions src/main/java/es/princip/ringus/domain/mentee/Mentee.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package es.princip.ringus.domain.mentee;

import es.princip.ringus.domain.bookmark.Bookmark;
import es.princip.ringus.domain.common.Education;
import es.princip.ringus.infra.storage.domain.ProfileImage;
import es.princip.ringus.presentation.mentee.dto.EditMenteeRequest;
Expand All @@ -9,6 +10,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

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

@Getter
@Entity
@Table(name = "mentee")
Expand Down Expand Up @@ -38,6 +42,10 @@ public class Mentee {
@Column(name = "member_id")
private Long memberId;

//북마크
@OneToMany(mappedBy = "mentee", cascade = CascadeType.ALL ,orphanRemoval = true, fetch = FetchType.LAZY)
private List<Bookmark> bookmarks = new ArrayList<>();

@Builder
public Mentee(
final String nickname,
Expand All @@ -59,4 +67,12 @@ public void edit(final EditMenteeRequest request) {
this.introduction = request.introduction();
this.profileImage = request.image().toEntity();
}

public void addBookmark(Bookmark bookmark){
bookmarks.add(bookmark);
}

public void deleteBookmark(Bookmark bookmark){
bookmarks.remove(bookmark);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package es.princip.ringus.presentation.bookmark;

import es.princip.ringus.application.bookmark.BookmarkService;
import es.princip.ringus.global.util.ApiResponseWrapper;
import es.princip.ringus.presentation.bookmark.dto.BookmarkRequest;
import es.princip.ringus.presentation.bookmark.dto.BookmarkResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/bookmark")
public class BookmarkController {
private final BookmarkService bookmarkService;

@PostMapping("/add")
public ResponseEntity<ApiResponseWrapper<BookmarkResponse>> addBookmark(@Valid @RequestBody BookmarkRequest request){
BookmarkResponse response = BookmarkResponse.from(bookmarkService.addBookmark(request));

return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "성공적으로 추가됨", response));
}

@PostMapping("/delete")
public ResponseEntity<ApiResponseWrapper<Void>> deleteBookmark(@Valid @RequestBody BookmarkRequest request){
bookmarkService.deleteBookmark(request);

return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "성공적으로 삭제됨"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package es.princip.ringus.presentation.bookmark.dto;

import es.princip.ringus.domain.bookmark.Bookmark;
import es.princip.ringus.domain.mentee.Mentee;
import es.princip.ringus.domain.mentor.Mentor;
import jakarta.validation.constraints.NotNull;

public record BookmarkRequest(
@NotNull Long mentorId,
@NotNull Long menteeId
) {
public Bookmark toEntity(Mentor mentor, Mentee mentee){
return Bookmark.builder()
.mentor(mentor)
.mentee(mentee)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package es.princip.ringus.presentation.bookmark.dto;

public record BookmarkResponse(
Long bookmarkId
) {
public static BookmarkResponse from(Long bookmarkId) {
return new BookmarkResponse(bookmarkId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package es.princip.ringus.presentation.bookmark.dto;

public record MenteeBookmarkResponse(
Long mentorId,
String mentorName
) {
public static MenteeBookmarkResponse from(Long mentorId, String mentorName){
return new MenteeBookmarkResponse(mentorId, mentorName);
}
}
106 changes: 106 additions & 0 deletions src/main/resources/db/migration/V2__addbookmarks.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

CREATE TABLE IF NOT EXISTS `file_member` (
`is_verified` bit(1) DEFAULT NULL,
`created_at` datetime(6) DEFAULT NULL,
`file_member_id` bigint NOT NULL AUTO_INCREMENT,
`member_id` bigint DEFAULT NULL,
`updated_at` datetime(6) DEFAULT NULL,
`file_path` varchar(255) DEFAULT NULL,
PRIMARY KEY (`file_member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `member` (
`is_file_verified` bit(1) NOT NULL,
`is_profile_registered` bit(1) NOT NULL,
`is_university_verified` bit(1) NOT NULL,
`created_at` datetime(6) DEFAULT NULL,
`member_id` bigint NOT NULL AUTO_INCREMENT,
`updated_at` datetime(6) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`member_type` enum('ADMIN','MENTEE','MENTOR') DEFAULT NULL,
PRIMARY KEY (`member_id`),
UNIQUE KEY `UKmbmcqelty0fbrvxp1q58dn57t` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mentee` (
`member_id` bigint DEFAULT NULL,
`mentee_id` bigint NOT NULL AUTO_INCREMENT,
`introduction` varchar(500) DEFAULT NULL,
`file_name` varchar(255) NOT NULL,
`file_path` varchar(255) NOT NULL,
`major` varchar(255) DEFAULT NULL,
`nickname` varchar(255) DEFAULT NULL,
`school_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`mentee_id`),
UNIQUE KEY `UK1esk9x4yr6uocrt4obtej4wie` (`nickname`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mentor` (
`end_time` time(6) DEFAULT NULL,
`experience` int DEFAULT NULL,
`start_time` time(6) DEFAULT NULL,
`member_id` bigint DEFAULT NULL,
`mentor_id` bigint NOT NULL AUTO_INCREMENT,
`message` varchar(50) DEFAULT NULL,
`introduction` varchar(500) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`file_name` varchar(255) NOT NULL,
`file_path` varchar(255) NOT NULL,
`major` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`nickname` varchar(255) DEFAULT NULL,
`role` varchar(255) DEFAULT NULL,
`school_name` varchar(255) DEFAULT NULL,
`url` varchar(255) DEFAULT NULL,
PRIMARY KEY (`mentor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mentor_hashtags` (
`mentor_id` bigint NOT NULL,
`value` varchar(255) DEFAULT NULL,
KEY `FKt3y0r48c7ok5lur8k568yt8kx` (`mentor_id`),
CONSTRAINT `FKt3y0r48c7ok5lur8k568yt8kx` FOREIGN KEY (`mentor_id`) REFERENCES `mentor` (`mentor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mentor_mentoring_fields` (
`mentor_id` bigint NOT NULL,
`mentoring_field` enum('INTERVIEW_PREPARATION','JOB_PREPARATION','PORTFOLIO','PRACTICAL_SKILLS') DEFAULT NULL,
KEY `FK97ao36m77up6wdjhov0y93pc2` (`mentor_id`),
CONSTRAINT `FK97ao36m77up6wdjhov0y93pc2` FOREIGN KEY (`mentor_id`) REFERENCES `mentor` (`mentor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `service_term` (
`required` bit(1) DEFAULT NULL,
`service_term_tag` varchar(255) NOT NULL,
PRIMARY KEY (`service_term_tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- `service_term` 테이블에 3개 데이터 삽입
INSERT INTO `service_term` (`service_term_tag`, `required`) VALUES
('TERMS_OF_SERVICE', 1),
('PRIVACY_POLICY', 1),
('MARKETING_CONSENT', 0);
CREATE TABLE IF NOT EXISTS `service_term_agreement` (
`agreed` bit(1) DEFAULT NULL,
`agreed_at` datetime(6) DEFAULT NULL,
`created_at` datetime(6) DEFAULT NULL,
`member_id` bigint NOT NULL,
`updated_at` datetime(6) DEFAULT NULL,
`tag` varchar(255) DEFAULT NULL,
KEY `FKl7bp8w5ehipkfnre066psfv7x` (`member_id`),
CONSTRAINT `FKl7bp8w5ehipkfnre066psfv7x` FOREIGN KEY (`member_id`) REFERENCES `member` (`member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `bookmark` (

`bookmark_id` BIGINT NOT NULL AUTO_INCREMENT,
`mentee_id` BIGINT NOT NULL,
`mentor_id` BIGINT NOT NULL,
`created_at` datetime(6) DEFAULT NULL,
`updated_at` datetime(6) DEFAULT NULL,

PRIMARY KEY (`bookmark_id`),
CONSTRAINT `FK_bookmark_mentee` FOREIGN KEY (`mentee_id`) REFERENCES `mentee` (`mentee_id`) ON DELETE CASCADE,
CONSTRAINT `FK_bookmark_mentor` FOREIGN KEY (`mentor_id`) REFERENCES `mentor` (`mentor_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Loading