-
Notifications
You must be signed in to change notification settings - Fork 7
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
99c76fa
commit dfde7b2
Showing
7 changed files
with
255 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.damap.base.domain; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
import jakarta.persistence.*; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
|
||
/** Banner class. */ | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@ToString | ||
@Entity | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
public class Banner extends PanacheEntity { | ||
|
||
@Column(name = "title") | ||
private String title; | ||
|
||
@Column(name = "description") | ||
private String description; | ||
|
||
@Column(name = "dismissible") | ||
private Boolean dismissible; | ||
|
||
@Column(name = "color") | ||
private String color; | ||
} |
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 org.damap.base.rest; | ||
|
||
import io.quarkus.security.Authenticated; | ||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.inject.Inject; | ||
import jakarta.validation.Valid; | ||
import jakarta.ws.rs.*; | ||
import jakarta.ws.rs.core.MediaType; | ||
import lombok.extern.jbosslog.JBossLog; | ||
import org.damap.base.rest.admin.domain.BannerDO; | ||
import org.damap.base.rest.admin.service.AdminService; | ||
|
||
/** AdminResource class. */ | ||
@Path("/api/admin") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Authenticated | ||
@JBossLog | ||
public class AdminResource { | ||
|
||
@Inject AdminService adminService; | ||
|
||
@GET | ||
@Path("/banner") | ||
public BannerDO getAppBanner() { | ||
log.info("GET /admin/banner"); | ||
return this.adminService.getAppBanner(); | ||
} | ||
|
||
@POST | ||
@Path("/banner") | ||
@RolesAllowed("Damap Admin") | ||
public BannerDO createAppBanner(@Valid BannerDO bannerDO) { | ||
log.info("POST /admin/banner"); | ||
log.info(bannerDO); | ||
return this.adminService.createAppBanner(bannerDO); | ||
} | ||
|
||
@PUT | ||
@Path("/banner") | ||
@RolesAllowed("Damap Admin") | ||
public BannerDO updateAppBanner(@Valid BannerDO bannerDO) { | ||
log.info("PUT /admin/banner"); | ||
log.info(bannerDO); | ||
return this.adminService.updateAppBanner(bannerDO); | ||
} | ||
|
||
@DELETE | ||
@Path("/banner") | ||
@RolesAllowed("Damap Admin") | ||
public void deleteAppBanner() { | ||
log.info("DELETE /admin/banner"); | ||
this.adminService.deleteAppBanner(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/damap/base/rest/admin/domain/BannerDO.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,21 @@ | ||
package org.damap.base.rest.admin.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Data; | ||
|
||
@Data | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class BannerDO { | ||
|
||
@Size(max = 255) | ||
private String title; | ||
|
||
@Size(max = 255) | ||
private String description; | ||
|
||
private Boolean dismissible; | ||
|
||
@Size(max = 255) | ||
private String color; | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/damap/base/rest/admin/mapper/BannerDOMapper.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,42 @@ | ||
package org.damap.base.rest.admin.mapper; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.damap.base.domain.Banner; | ||
import org.damap.base.rest.admin.domain.BannerDO; | ||
|
||
/** BannerDOMapper class. */ | ||
@UtilityClass | ||
public class BannerDOMapper { | ||
|
||
/** | ||
* mapEntityToDO. | ||
* | ||
* @param banner a {@link Banner} object | ||
* @param bannerDO a {@link BannerDO} object | ||
* @return a {@link BannerDO} object | ||
*/ | ||
public BannerDO mapEntityToDO(Banner banner, BannerDO bannerDO) { | ||
bannerDO.setTitle(banner.getTitle()); | ||
bannerDO.setDescription(banner.getDescription()); | ||
bannerDO.setDismissible(banner.getDismissible()); | ||
bannerDO.setColor(banner.getColor()); | ||
|
||
return bannerDO; | ||
} | ||
|
||
/** | ||
* mapDOtoEntity. | ||
* | ||
* @param bannerDO a {@link BannerDO} object | ||
* @param banner a {@link Banner} object | ||
* @return a {@link BannerDO} object | ||
*/ | ||
public Banner mapDOtoEntity(BannerDO bannerDO, Banner banner) { | ||
banner.setTitle(bannerDO.getTitle()); | ||
banner.setDescription(bannerDO.getDescription()); | ||
banner.setDismissible(bannerDO.getDismissible()); | ||
banner.setColor(bannerDO.getColor()); | ||
|
||
return banner; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/org/damap/base/rest/admin/service/AdminService.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,60 @@ | ||
package org.damap.base.rest.admin.service; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.validation.Valid; | ||
import java.util.*; | ||
import lombok.extern.jbosslog.JBossLog; | ||
import org.damap.base.domain.Banner; | ||
import org.damap.base.rest.admin.domain.BannerDO; | ||
import org.damap.base.rest.admin.mapper.BannerDOMapper; | ||
import org.damap.base.rest.dmp.mapper.*; | ||
|
||
@ApplicationScoped | ||
@JBossLog | ||
public class AdminService { | ||
|
||
public BannerDO getAppBanner() { | ||
Banner banner = Banner.findAll().firstResult(); | ||
if (banner == null) { | ||
return null; | ||
} | ||
return BannerDOMapper.mapEntityToDO(banner, new BannerDO()); | ||
} | ||
|
||
@Transactional | ||
public BannerDO createAppBanner(@Valid BannerDO bannerDO) { | ||
long existingBannerCount = Banner.count(); | ||
if (existingBannerCount > 0) { | ||
throw new IllegalStateException("There is already a banner in the database"); | ||
} | ||
|
||
Banner banner = BannerDOMapper.mapDOtoEntity(bannerDO, new Banner()); | ||
banner.persist(); | ||
|
||
return bannerDO; | ||
} | ||
|
||
@Transactional | ||
public BannerDO updateAppBanner(@Valid BannerDO bannerDO) { | ||
Banner banner = Banner.findAll().firstResult(); | ||
if (banner == null) { | ||
throw new IllegalStateException("There is no banner in the database"); | ||
} | ||
|
||
banner = BannerDOMapper.mapDOtoEntity(bannerDO, banner); | ||
banner.persist(); | ||
|
||
return bannerDO; | ||
} | ||
|
||
@Transactional | ||
public void deleteAppBanner() { | ||
Banner banner = Banner.findAll().firstResult(); | ||
if (banner == null) { | ||
throw new IllegalStateException("There is no banner in the database"); | ||
} | ||
|
||
banner.delete(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/resources/org/damap/base/db/changeLog-4.x/changeLog-4.3.0_3.yaml
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,47 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: 17 | ||
author: Geoffrey Karnbach | ||
changes: | ||
- createSequence: | ||
sequenceName: banner_seq | ||
startValue: 1 | ||
incrementBy: 1 | ||
|
||
- createTable: | ||
tableName: banner | ||
columns: | ||
- column: | ||
name: id | ||
type: BIGINT | ||
defaultValueComputed: "nextval('banner_seq')" | ||
constraints: | ||
primaryKey: true | ||
nullable: false | ||
unique: true | ||
- column: | ||
name: title | ||
type: VARCHAR(255) | ||
constraints: | ||
nullable: true | ||
- column: | ||
name: description | ||
type: VARCHAR(255) | ||
constraints: | ||
nullable: true | ||
- column: | ||
name: dismissible | ||
type: BOOLEAN | ||
constraints: | ||
nullable: true | ||
- column: | ||
name: color | ||
type: VARCHAR(255) | ||
constraints: | ||
nullable: true | ||
|
||
rollback: | ||
- dropTable: | ||
tableName: banner | ||
- dropSequence: | ||
sequenceName: banner_seq |
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