-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feature to like and/or save a post and get my saved courses
- Loading branch information
Showing
7 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/runningmate/backend/member/MemberRoute.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,47 @@ | ||
package com.runningmate.backend.member; | ||
|
||
import com.runningmate.backend.route.Route; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "member_route") | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Builder | ||
public class MemberRoute { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
private UUID id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "route_id") | ||
private Route route; | ||
|
||
private boolean liked; | ||
|
||
private boolean saved; | ||
|
||
public void saveRoute() { | ||
this.saved = true; | ||
} | ||
|
||
public void unsaveRoute() { | ||
this.saved = false; | ||
} | ||
|
||
public void likeRoute() { | ||
this.liked = true; | ||
} | ||
|
||
public void unlikeRoute() { | ||
this.liked = false; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/runningmate/backend/member/repository/MemberRouteRepository.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 com.runningmate.backend.member.repository; | ||
|
||
import com.runningmate.backend.member.Member; | ||
import com.runningmate.backend.member.MemberRoute; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface MemberRouteRepository extends JpaRepository<MemberRoute, UUID> { | ||
List<MemberRoute> findByMemberAndSavedTrue(Member member); | ||
List<MemberRoute> findByMemberAndLikedTrue(Member member); | ||
Optional<MemberRoute> findByMemberIdAndRouteId(Long memberId, Long routeId); | ||
} |
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: 21 additions & 0 deletions
21
src/main/java/com/runningmate/backend/route/dto/MemberRouteResponseDto.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,21 @@ | ||
package com.runningmate.backend.route.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.runningmate.backend.member.MemberRoute; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class MemberRouteResponseDto { | ||
private Long memberId; | ||
@JsonProperty("courseId") | ||
private Long routeId; | ||
private boolean liked; | ||
private boolean saved; | ||
|
||
public MemberRouteResponseDto(MemberRoute memberRoute) { | ||
this.memberId = memberRoute.getMember().getId(); | ||
this.routeId = memberRoute.getRoute().getId(); | ||
this.liked = memberRoute.isLiked(); | ||
this.saved = memberRoute.isSaved(); | ||
} | ||
} |
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