-
Notifications
You must be signed in to change notification settings - Fork 0
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 #375 from Team-Ampersand/develop
Develop
- Loading branch information
Showing
5 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/server/Dotori/domain/massage/MassageCount.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,29 @@ | ||
package com.server.Dotori.domain.massage; | ||
|
||
import lombok.*; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity @Table(name = "massage_count") | ||
@Getter @Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class MassageCount { | ||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "massage_count") | ||
private Long count; | ||
|
||
public void addCount() { | ||
this.count++; | ||
} | ||
|
||
public void deductionCount() { | ||
this.count--; | ||
} | ||
|
||
public void clearCount() { | ||
this.count = 0L; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/server/Dotori/domain/massage/config/MassageCountConfig.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.server.Dotori.domain.massage.config; | ||
|
||
import com.server.Dotori.domain.massage.MassageCount; | ||
import com.server.Dotori.domain.massage.repository.MassageCountRepository; | ||
import com.server.Dotori.domain.massage.repository.MassageRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MassageCountConfig { | ||
private final MassageCountRepository massageCountRepository; | ||
private final MassageRepository massageRepository; | ||
|
||
@PostConstruct | ||
private void generateMassageCount() { | ||
massageCountRepository.deleteAll(); | ||
massageCountRepository.save( | ||
MassageCount.builder() | ||
.id(1L) | ||
.count(massageRepository.count()) | ||
.build() | ||
); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/server/Dotori/domain/massage/repository/MassageCountRepository.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.server.Dotori.domain.massage.repository; | ||
|
||
import com.server.Dotori.domain.massage.MassageCount; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Lock; | ||
|
||
import javax.persistence.LockModeType; | ||
|
||
public interface MassageCountRepository extends JpaRepository<MassageCount, Long> { | ||
|
||
@Lock(LockModeType.PESSIMISTIC_WRITE) | ||
MassageCount findMassageCountById(Long id); | ||
} |
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 |
---|---|---|
|
@@ -123,4 +123,4 @@ public void findMassageStatusAndCountTest() { | |
assertEquals("1", find.get("count")); | ||
|
||
} | ||
} | ||
} |