This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
6219a14
commit fd86d1b
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/net/yogstation/api/controller/BanController.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,23 @@ | ||
package net.yogstation.api.controller; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import net.yogstation.api.jpa.entity.BanEntity; | ||
import net.yogstation.api.service.BanService; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
public class BanController { | ||
private BanService banService; | ||
|
||
@GetMapping("/api/v1/publicbans") | ||
public Page<BanEntity> getBans(@RequestParam(required = false, defaultValue = "0") int page, | ||
@RequestParam(required = false, defaultValue = "25") int size) { | ||
|
||
return banService.getBans(page, size); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/net/yogstation/api/jpa/entity/BanEntity.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,25 @@ | ||
package net.yogstation.api.jpa.entity; | ||
|
||
import lombok.Data; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Table(name = "erro_ban") | ||
@Data | ||
public class BanEntity { | ||
@Id | ||
@GeneratedValue | ||
private int id; | ||
|
||
private String ckey; | ||
private String a_ckey; | ||
@Column(columnDefinition="mediumtext") | ||
private String reason; | ||
private LocalDateTime expirationTime; | ||
private LocalDateTime unbannedDatetime; | ||
private LocalDateTime bantime; | ||
private String role; | ||
private int roundId; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/net/yogstation/api/jpa/repository/BanRepository.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,14 @@ | ||
package net.yogstation.api.jpa.repository; | ||
|
||
import net.yogstation.api.jpa.entity.BanEntity; | ||
import org.hibernate.Criteria; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface BanRepository extends PagingAndSortingRepository<BanEntity, Integer>, JpaSpecificationExecutor<BanEntity> { | ||
Page<BanEntity> findBy(Pageable pageable, Criteria criteria); | ||
} |
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,18 @@ | ||
package net.yogstation.api.service; | ||
|
||
import net.yogstation.api.jpa.entity.BanEntity; | ||
import net.yogstation.api.jpa.repository.BanRepository; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class BanService { | ||
private BanRepository banRepository; | ||
|
||
public BanService(BanRepository banRepository) { this.banRepository = banRepository;} | ||
|
||
public Page<BanEntity> getBans(int page, int size) { | ||
return banRepository.findAll(PageRequest.of(page, size)); | ||
} | ||
} |
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