-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/search
- Loading branch information
Showing
16 changed files
with
599 additions
and
46 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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/savvato/tribeapp/controllers/dto/PhraseSequenceDataRequest.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,13 @@ | ||
package com.savvato.tribeapp.controllers.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class PhraseSequenceDataRequest { | ||
public Long phraseId; | ||
public Integer sequence; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/savvato/tribeapp/controllers/dto/PhraseSequenceRequest.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.savvato.tribeapp.controllers.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class PhraseSequenceRequest { | ||
public Long userId; | ||
public List<PhraseSequenceDataRequest> phrases; | ||
|
||
} | ||
|
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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/savvato/tribeapp/entities/PhraseSequence.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,57 @@ | ||
package com.savvato.tribeapp.entities; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EmbeddedId; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
|
||
|
||
@Entity | ||
@Table(name = "phrase_sequence") | ||
public class PhraseSequence { | ||
|
||
@EmbeddedId | ||
private PhraseSequenceKey id; | ||
|
||
@Column(name = "position") | ||
private Integer position; | ||
|
||
public PhraseSequence() {} | ||
|
||
public PhraseSequence(Long userId, Long phraseId, Integer position) { | ||
this.id = new PhraseSequenceKey(userId, phraseId); | ||
this.position = position; | ||
} | ||
|
||
public PhraseSequenceKey getId() { | ||
return id; | ||
} | ||
|
||
public void setId(PhraseSequenceKey id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getUserId() { | ||
return id.getUserId(); | ||
} | ||
|
||
public void setUserId(Long userId) { | ||
id.setUserId(userId); | ||
} | ||
|
||
public Long getPhraseId() { | ||
return id.getPhraseId(); | ||
} | ||
|
||
public void setPhraseId(Long phraseId) { | ||
id.setPhraseId(phraseId); | ||
} | ||
|
||
public Integer getPosition() { | ||
return position; | ||
} | ||
|
||
public void setPosition(Integer position) { | ||
this.position = position; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/savvato/tribeapp/entities/PhraseSequenceKey.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,48 @@ | ||
package com.savvato.tribeapp.entities; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
@Embeddable | ||
public class PhraseSequenceKey implements Serializable { | ||
private Long userId; | ||
private Long phraseId; | ||
|
||
public PhraseSequenceKey() {} | ||
|
||
public PhraseSequenceKey(Long userId, Long phraseId) { | ||
this.userId = userId; | ||
this.phraseId = phraseId; | ||
} | ||
|
||
public Long getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(Long userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public Long getPhraseId() { | ||
return phraseId; | ||
} | ||
|
||
public void setPhraseId(Long phraseId) { | ||
this.phraseId = phraseId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
PhraseSequenceKey that = (PhraseSequenceKey) o; | ||
return Objects.equals(userId, that.userId) && | ||
Objects.equals(phraseId, that.phraseId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(userId, phraseId); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/savvato/tribeapp/repositories/PhraseSequenceRepository.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,27 @@ | ||
package com.savvato.tribeapp.repositories; | ||
|
||
import com.savvato.tribeapp.entities.PhraseSequence; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface PhraseSequenceRepository extends JpaRepository<PhraseSequence, Long> { | ||
@Query(nativeQuery = true, value = "SELECT * FROM phrase_sequence WHERE user_id = ?1 ORDER BY position") | ||
List<PhraseSequence> findByUserIdOrderByPosition(Long userId); | ||
|
||
@Modifying | ||
@Transactional | ||
@Query(nativeQuery = true, value = "INSERT INTO phrase_sequence (user_id, phrase_id, position) VALUES (:userId, :phraseId, :position) " + | ||
"ON DUPLICATE KEY UPDATE position = VALUES(position)") | ||
void storeOrUpdatePhrases(@Param("userId") Long userId, @Param("phraseId") Long phraseId, @Param("position") Integer position); | ||
|
||
@Query(nativeQuery = true, value = "SELECT COALESCE(MAX(position), 0) + 1 FROM phrase_sequence WHERE user_id = ?1") | ||
Integer findNextAvailableSequence(Long userId); | ||
|
||
} |
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
Oops, something went wrong.