Skip to content

Commit

Permalink
Merge pull request #140 from studio-recoding/feat-schedule-bookmark
Browse files Browse the repository at this point in the history
[🚀feat] bookmark 기능 개발
  • Loading branch information
JeonHaeseung committed Jul 14, 2024
2 parents ed459e5 + 51a4070 commit 950cf7d
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 21 deletions.
33 changes: 33 additions & 0 deletions src/main/java/Ness/Backend/domain/bookmark/BookmarkController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package Ness.Backend.domain.bookmark;

import Ness.Backend.domain.bookmark.dto.request.PostBookmarkDto;
import Ness.Backend.domain.bookmark.dto.response.GetBookmarkListDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

@PostMapping("")
public ResponseEntity<?> createBookmark(@RequestBody PostBookmarkDto postBookmarkDto){
bookmarkService.createBookmark(postBookmarkDto);
return new ResponseEntity<>(HttpStatusCode.valueOf(200));
}

@GetMapping("")
public ResponseEntity<GetBookmarkListDto> getBookmark(@RequestParam Long scheduleId){
GetBookmarkListDto listDto = bookmarkService.getBookmark(scheduleId);
return new ResponseEntity<>(listDto, HttpStatusCode.valueOf(200));
}

@DeleteMapping("")
public ResponseEntity<?> deleteBookmark(@RequestParam Long bookmarkId){
bookmarkService.deleteBookmark(bookmarkId);
return new ResponseEntity<>(HttpStatusCode.valueOf(200));
}
}
12 changes: 12 additions & 0 deletions src/main/java/Ness/Backend/domain/bookmark/BookmarkRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Ness.Backend.domain.bookmark;

import Ness.Backend.domain.bookmark.entity.Bookmark;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {
List<Bookmark> findBookmarksBySchedule_Id(Long scheduleId);
}
58 changes: 58 additions & 0 deletions src/main/java/Ness/Backend/domain/bookmark/BookmarkService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package Ness.Backend.domain.bookmark;

import Ness.Backend.domain.bookmark.dto.request.PostBookmarkDto;
import Ness.Backend.domain.bookmark.dto.response.GetBookmarkDto;
import Ness.Backend.domain.bookmark.dto.response.GetBookmarkListDto;
import Ness.Backend.domain.bookmark.entity.Bookmark;
import Ness.Backend.domain.schedule.ScheduleRepository;
import Ness.Backend.domain.schedule.entity.Schedule;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
public class BookmarkService {
private final BookmarkRepository bookmarkRepository;
private final ScheduleRepository scheduleRepository;

@Transactional
public void createBookmark(PostBookmarkDto postBookmarkDto){
Schedule schedule = scheduleRepository.findScheduleById(postBookmarkDto.getScheduleId());

Bookmark bookmark = Bookmark.builder()
.contents(postBookmarkDto.getContents())
.title(postBookmarkDto.getTitle())
.datetime(postBookmarkDto.getDatetime())
.url(postBookmarkDto.getUrl())
.schedule(schedule)
.build();

bookmarkRepository.save(bookmark);
}

@Transactional(readOnly = true)
public GetBookmarkListDto getBookmark(Long scheduleId){
List<Bookmark> bookmarks = bookmarkRepository.findBookmarksBySchedule_Id(scheduleId);

List<GetBookmarkDto> bookmarkDtos = bookmarks.stream()
.map(bookmark -> GetBookmarkDto.builder()
.id(bookmark.getId())
.contents(bookmark.getContents())
.title(bookmark.getTitle())
.url(bookmark.getUrl())
.datetime(bookmark.getDatetime())
.build())
.toList();

return new GetBookmarkListDto(bookmarkDtos);
}

@Transactional
public void deleteBookmark(Long bookmarkId) {
bookmarkRepository.findById(bookmarkId)
.ifPresent(bookmark -> bookmarkRepository.delete(bookmark));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Ness.Backend.domain.bookmark.dto.request;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.ZonedDateTime;

@Data
@NoArgsConstructor
public class PostBookmarkDto {
private Long scheduleId;

private String contents;

private ZonedDateTime datetime;

private String title;

private String url;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Ness.Backend.domain.bookmark.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.ZonedDateTime;

@Data
public class GetBookmarkDto {
private Long id;

private String contents;

private ZonedDateTime datetime;

private String title;

private String url;

@Builder
public GetBookmarkDto(Long id, String contents, ZonedDateTime datetime, String title, String url){
this.id = id;
this.contents = contents;
this.datetime = datetime;
this.title = title;
this.url = url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Ness.Backend.domain.bookmark.dto.response;

import Ness.Backend.domain.chat.dto.response.GetChatDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetBookmarkListDto {
private List<GetBookmarkDto> bookmarkList;
}
40 changes: 40 additions & 0 deletions src/main/java/Ness/Backend/domain/bookmark/entity/Bookmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package Ness.Backend.domain.bookmark.entity;

import Ness.Backend.domain.schedule.entity.Schedule;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.ZonedDateTime;

@Entity
@Getter
@NoArgsConstructor
public class Bookmark {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "bookmark_id")
private Long id;

private String contents;

private ZonedDateTime datetime;

private String title;

private String url;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "schedule_id")
private Schedule schedule;

@Builder
public Bookmark(String contents, ZonedDateTime datetime, String title, String url, Schedule schedule){
this.contents = contents;
this.datetime = datetime;
this.title = title;
this.url = url;
this.schedule = schedule;
}
}
16 changes: 16 additions & 0 deletions src/main/java/Ness/Backend/domain/category/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ public void putUserCategory(Long memberId, PutCategoryDto putCategoryDto){
//중복되지 않은 카테고리일 경우는 변경사항 저장 가능
log.info(putCategoryDto.getId() + "번 카테고리 " + changeCategory.getName() + " 수정");
changeCategory.changeCategory(putCategoryDto.getName(), putCategoryDto.getColor());

//카테고리 이름 또는 컬러 변경 사항을 VectorDB에도 저장
List<Schedule> changeScheduleList = scheduleRepository.findSchedulesByCategory_Id(putCategoryDto.getId());
changeScheduleList.forEach(schedule -> {
scheduleService.putAiSchedule(
schedule.getInfo(),
schedule.getLocation(),
schedule.getPerson(),
schedule.getStartTime(),
schedule.getEndTime(),
putCategoryDto.getName(),
schedule.getCategory().getId(),
putCategoryDto.getColor(),
schedule.getMember().getId(),
schedule.getId());
});
}
else {
throw new DuplicateCategoryException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Ness.Backend.domain.schedule.entity;

import Ness.Backend.domain.bookmark.entity.Bookmark;
import Ness.Backend.domain.category.entity.Category;
import Ness.Backend.domain.chat.entity.Chat;
import Ness.Backend.domain.member.entity.Member;
Expand All @@ -9,6 +10,8 @@
import lombok.NoArgsConstructor;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
Expand Down Expand Up @@ -43,6 +46,9 @@ public class Schedule {
@JoinColumn(name = "chat_id")
private Chat chat;

@OneToMany(mappedBy = "schedule")
private List<Bookmark> bookmarks = new ArrayList<>();

@Builder
public Schedule(Long id, String info, String location, String person, ZonedDateTime startTime, ZonedDateTime endTime,
Member member, Category category, Chat chat) {
Expand Down

This file was deleted.

0 comments on commit 950cf7d

Please sign in to comment.