-
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.
[OING-300] feat: 콕 찌르기 API 구현 (#222)
* feat: implementing pick.. * feat: implement pick feature * feat: add picked members api * feat: implement picked api * feat: implement GET api * feat: check member exists * feat: update api specs * feat: concat sql queries * feat: seperate notification
- Loading branch information
Showing
11 changed files
with
298 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.oing.service; | ||
|
||
/** | ||
* no5ing-server | ||
* User: CChuYong | ||
* Date: 3/31/24 | ||
* Time: 5:47 PM | ||
*/ | ||
public interface PostBridge { | ||
boolean isUploadedToday(String familyId, String memberId); | ||
} |
12 changes: 12 additions & 0 deletions
12
gateway/src/main/resources/db/migration/V202404021150__create_memberPick_table.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE IF NOT EXISTS `member_pick` ( | ||
`pick_id` CHAR(26) NOT NULL COMMENT 'ULID', | ||
`family_id` CHAR(26) NOT NULL COMMENT 'ULID', | ||
`from_member_id` CHAR(26) NOT NULL COMMENT 'ULID', | ||
`date` DATE NOT NULL, | ||
`to_member_id` CHAR(26) NOT NULL COMMENT 'ULID', | ||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
INDEX `member_pick_idx1` (`family_id`, `from_member_id`, `date`, `to_member_id`), | ||
INDEX `member_pick_idx2` (`family_id`, `date`, `to_member_id`), | ||
PRIMARY KEY (`pick_id`) | ||
) DEFAULT CHARSET = utf8mb4 | ||
COLLATE = utf8mb4_unicode_ci comment '사용자콕찌르기'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.oing.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
|
||
/** | ||
* no5ing-server | ||
* User: CChuYong | ||
* Date: 2024/04/02 | ||
* Time: 11:31 AM | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(callSuper = false) | ||
@AllArgsConstructor | ||
@Getter | ||
@Entity(name = "member_pick") | ||
public class MemberPick extends BaseEntity { | ||
@Id | ||
@Column(name = "pick_id", length = 26, columnDefinition = "CHAR(26)") | ||
private String pickId; | ||
|
||
@Column(name = "family_id", length = 26, columnDefinition = "CHAR(26)") | ||
private String familyId; | ||
|
||
@Column(name = "from_member_id", length = 26, columnDefinition = "CHAR(26)") | ||
private String fromMemberId; | ||
|
||
@Column(name = "date", columnDefinition = "DATE") | ||
private LocalDate date; | ||
|
||
@Column(name = "to_member_id", columnDefinition = "CHAR(26)") | ||
private String toMemberId; | ||
} |
13 changes: 13 additions & 0 deletions
13
member/src/main/java/com/oing/exception/AlreadyPickedMemberException.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.oing.exception; | ||
|
||
/** | ||
* no5ing-server | ||
* User: CChuYong | ||
* Date: 4/2/24 | ||
* Time: 12:03 PM | ||
*/ | ||
public class AlreadyPickedMemberException extends DomainException{ | ||
public AlreadyPickedMemberException() { | ||
super(ErrorCode.ALREADY_PICKED_TODAY); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
member/src/main/java/com/oing/exception/PickFailedAlreadyUploadedException.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.oing.exception; | ||
|
||
/** | ||
* no5ing-server | ||
* User: CChuYong | ||
* Date: 4/2/24 | ||
* Time: 12:04 PM | ||
*/ | ||
public class PickFailedAlreadyUploadedException extends DomainException { | ||
public PickFailedAlreadyUploadedException() { | ||
super(ErrorCode.MEMBER_ALREADY_UPLOADED_POST); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
member/src/main/java/com/oing/repository/MemberPickRepository.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,19 @@ | ||
package com.oing.repository; | ||
|
||
import com.oing.domain.MemberPick; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
/** | ||
* no5ing-server | ||
* User: CChuYong | ||
* Date: 4/2/24 | ||
* Time: 11:54 AM | ||
*/ | ||
public interface MemberPickRepository extends JpaRepository<MemberPick, String> { | ||
MemberPick findByFamilyIdAndFromMemberIdAndDateAndToMemberId(String familyId, String fromMemberId, LocalDate date, String toMemberId); | ||
List<MemberPick> findAllByFamilyIdAndDateAndToMemberId(String familyId, LocalDate date, String toMemberId); | ||
List<MemberPick> findAllByFamilyIdAndDateAndFromMemberId(String familyId, LocalDate date, String fromMemberId); | ||
} |
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
54 changes: 54 additions & 0 deletions
54
member/src/main/java/com/oing/service/MemberPickService.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,54 @@ | ||
package com.oing.service; | ||
|
||
import com.oing.domain.MemberPick; | ||
import com.oing.exception.AlreadyPickedMemberException; | ||
import com.oing.repository.MemberPickRepository; | ||
import com.oing.util.IdentityGenerator; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
/** | ||
* no5ing-server | ||
* User: CChuYong | ||
* Date: 4/2/24 | ||
* Time: 11:58 AM | ||
*/ | ||
@RequiredArgsConstructor | ||
@Service | ||
public class MemberPickService { | ||
private final MemberPickRepository memberPickRepository; | ||
private final IdentityGenerator identityGenerator; | ||
|
||
@Transactional | ||
public MemberPick pickMember(String familyId, String fromMemberId, String toMemberId) { | ||
LocalDate today = LocalDate.now(); | ||
MemberPick priorMemberPick = memberPickRepository | ||
.findByFamilyIdAndFromMemberIdAndDateAndToMemberId(familyId, fromMemberId, today, toMemberId); | ||
if(priorMemberPick != null) { | ||
throw new AlreadyPickedMemberException(); | ||
} | ||
|
||
MemberPick newMemberPick = new MemberPick( | ||
identityGenerator.generateIdentity(), | ||
familyId, | ||
fromMemberId, | ||
today, | ||
toMemberId | ||
); | ||
return memberPickRepository.save(newMemberPick); | ||
} | ||
|
||
public List<MemberPick> getPickMembers(String familyId, String pickedMemberId) { | ||
LocalDate today = LocalDate.now(); | ||
return memberPickRepository.findAllByFamilyIdAndDateAndToMemberId(familyId, today, pickedMemberId); | ||
} | ||
|
||
public List<MemberPick> getPickedMembers(String familyId, String pickerMemberId) { | ||
LocalDate today = LocalDate.now(); | ||
return memberPickRepository.findAllByFamilyIdAndDateAndFromMemberId(familyId, today, pickerMemberId); | ||
} | ||
} |
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,25 @@ | ||
package com.oing.service; | ||
|
||
import com.oing.repository.PostRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
|
||
/** | ||
* no5ing-server | ||
* User: CChuYong | ||
* Date: 3/31/24 | ||
* Time: 5:48 PM | ||
*/ | ||
@RequiredArgsConstructor | ||
@Service | ||
public class PostBridgeImpl implements PostBridge { | ||
private final PostRepository postRepository; | ||
|
||
@Override | ||
public boolean isUploadedToday(String familyId, String memberId) { | ||
LocalDate today = LocalDate.now(); | ||
return postRepository.existsByMemberIdAndFamilyIdAndCreatedAt(memberId, familyId, today); | ||
} | ||
} |