-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from studio-recoding/feat-schedule-bookmark
[🚀feat] bookmark 기능 개발
- Loading branch information
Showing
10 changed files
with
232 additions
and
21 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/Ness/Backend/domain/bookmark/BookmarkController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/main/java/Ness/Backend/domain/bookmark/BookmarkRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
src/main/java/Ness/Backend/domain/bookmark/BookmarkService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/Ness/Backend/domain/bookmark/dto/request/PostBookmarkDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/Ness/Backend/domain/bookmark/dto/response/GetBookmarkDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/Ness/Backend/domain/bookmark/dto/response/GetBookmarkListDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
src/main/java/Ness/Backend/domain/bookmark/entity/Bookmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/main/java/Ness/Backend/domain/schedule/entity/ScheduleDate.java
This file was deleted.
Oops, something went wrong.