-
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.
- Loading branch information
Showing
13 changed files
with
185 additions
and
40 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/com/staketab/minanames/controller/ActivityController.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,36 @@ | ||
package com.staketab.minanames.controller; | ||
|
||
import com.staketab.minanames.dto.ActivityDTO; | ||
import com.staketab.minanames.dto.request.BaseRequest; | ||
import com.staketab.minanames.dto.request.sort.ActivitySortColumn; | ||
import com.staketab.minanames.service.ActivityService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springdoc.core.annotations.ParameterObject; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/activities") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ActivityController { | ||
|
||
private final ActivityService activityService; | ||
|
||
@GetMapping("/{address}") | ||
@Operation(summary = "getActivities", description = "Get a page of all activities.") | ||
public Page<ActivityDTO> getActivities(@Valid @ParameterObject BaseRequest request, | ||
@RequestParam @Schema(defaultValue = "TIMESTAMP", allowableValues = {"TIMESTAMP"}, | ||
description = "Select sorting parameter.") ActivitySortColumn sortBy, | ||
@PathVariable String address) { | ||
return activityService.findAllByPageable(request.withSortColumn(sortBy), address); | ||
} | ||
} |
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.staketab.minanames.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class ActivityDTO { | ||
|
||
private String id; | ||
private String domainName; | ||
private String ownerAddress; | ||
private String transaction; | ||
private String activity; | ||
private String details; | ||
private long timestamp; | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/staketab/minanames/dto/request/sort/ActivitySortColumn.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,12 @@ | ||
package com.staketab.minanames.dto.request.sort; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ActivitySortColumn implements DbColumnProvider { | ||
TIMESTAMP("timestamp"); | ||
|
||
private final String dbColumn; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/staketab/minanames/repository/ActivityRepository.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,10 +1,20 @@ | ||
package com.staketab.minanames.repository; | ||
|
||
import com.staketab.minanames.entity.ActivityEntity; | ||
import com.staketab.minanames.entity.DomainEntity; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ActivityRepository extends JpaRepository<ActivityEntity, String> { | ||
|
||
@Query(nativeQuery = true, | ||
value = """ | ||
select * | ||
from activity | ||
where owner_address = :address and is_show is true""") | ||
Page<ActivityEntity> findAllActivities(Pageable buildPageable, String address); | ||
} |
10 changes: 8 additions & 2 deletions
10
src/main/java/com/staketab/minanames/service/ActivityService.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,13 +1,19 @@ | ||
package com.staketab.minanames.service; | ||
|
||
import com.staketab.minanames.dto.ActivityDTO; | ||
import com.staketab.minanames.dto.request.BaseRequest; | ||
import com.staketab.minanames.entity.DomainEntity; | ||
import com.staketab.minanames.entity.ActivityStatus; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface ActivityService { | ||
|
||
void saveActivity(DomainEntity domainEntity, ActivityStatus status); | ||
Page<ActivityDTO> findAllByPageable(BaseRequest baseRequest, String address); | ||
|
||
void saveAllActivities(List<DomainEntity> domainEntities, ActivityStatus status); | ||
void saveActivity(DomainEntity domainEntity, ActivityStatus status, String details); | ||
|
||
void saveAllActivities(List<DomainEntity> domainEntities, ActivityStatus status, String details); | ||
} |
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
Oops, something went wrong.