-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(track): re-design habit tracking entity
Logic is now encapsulated in an entity that contains all tracking dates instead of leaking into the controller layer. An entity now contains all tracked dates for a given habit instead of one entity per tracked date.
- Loading branch information
1 parent
ab3ecde
commit 8e1ac1c
Showing
11 changed files
with
174 additions
and
129 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
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
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
9 changes: 3 additions & 6 deletions
9
.../track/src/main/java/de/codecentric/habitcentric/track/habit/HabitTrackingRepository.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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
package de.codecentric.habitcentric.track.habit; | ||
|
||
import de.codecentric.habitcentric.track.habit.HabitTracking.Id; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface HabitTrackingRepository extends JpaRepository<HabitTracking, Id> { | ||
import java.util.Optional; | ||
|
||
List<HabitTracking> findByIdUserIdAndIdHabitId(String userId, Long habitId); | ||
|
||
void deleteByIdHabitId(Long habitId); | ||
public interface HabitTrackingRepository extends JpaRepository<HabitTracking, HabitTracking.Id> { | ||
Optional<HabitTracking> findByIdUserIdAndIdHabitId(String userId, Long habitId); | ||
} |
7 changes: 5 additions & 2 deletions
7
services/track/src/main/resources/db/migration/V1__create-schema.sql
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
CREATE TABLE habit_tracking (user_id VARCHAR(64) NOT NULL, habit_id BIGINT NOT NULL, track_date DATE NOT NULL); | ||
ALTER TABLE habit_tracking ADD PRIMARY KEY (user_id, habit_id, track_date); | ||
CREATE TABLE habit_tracking (user_id VARCHAR(64) NOT NULL, habit_id BIGINT NOT NULL); | ||
ALTER TABLE habit_tracking ADD PRIMARY KEY (user_id, habit_id); | ||
|
||
CREATE TABLE tracked_dates(tracking_date DATE NOT NULL, user_id VARCHAR(64) NOT NULL, habit_id BIGINT NOT NULL); | ||
ALTER TABLE tracked_dates ADD FOREIGN KEY (user_id, habit_id) REFERENCES habit_tracking(user_id, habit_id); |
47 changes: 0 additions & 47 deletions
47
...ck/src/test/java/de/codecentric/habitcentric/track/habit/HabitTrackingControllerTest.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.