Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package com.objectcomputing.checkins.services.guild;

import io.micronaut.core.annotation.Nullable;
import io.micronaut.data.annotation.AutoPopulated;
import io.micronaut.data.annotation.TypeDef;
import io.micronaut.data.jdbc.annotation.ColumnTransformer;
import io.micronaut.data.model.DataType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import io.micronaut.core.annotation.Nullable;

import javax.validation.constraints.NotNull;
import java.util.Objects;
import java.util.UUID;

@Entity
@Setter
@Getter
@NoArgsConstructor
@Table(name = "guild")
public class Guild {
@Id
Expand All @@ -35,7 +41,6 @@ public class Guild {
@Schema(description = "name of the guild")
private String name;


@Nullable
@Column(name="link", unique=true)
@ColumnTransformer(
Expand All @@ -54,50 +59,21 @@ public class Guild {
@Schema(description = "description of the guild")
private String description;

@NotNull
@Column(name = "community")
@Schema(description = "Is the guild a community")
private boolean community;


public Guild(String name, String description, @Nullable String link) {
this(null, name, description, link);
}

public Guild(UUID id, String name, String description, @Nullable String link) {
this.id = id;
this.name = name;
this.description = description;
this.link = link;
}

public UUID getId() {
return id;
public Guild(String name, String description, @Nullable String link, boolean community) {
this(null, name, description, link, community);
}

public void setId(UUID id) {
public Guild(UUID id, String name, String description, @Nullable String link, boolean community) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@Nullable
public String getLink() {
return this.link;
}

public void setLink(String link) {
this.link = link;
this.community = community;
}

@Override
Expand All @@ -108,13 +84,14 @@ public boolean equals(Object o) {
return Objects.equals(id, guild.id) &&
Objects.equals(name, guild.name) &&
Objects.equals(description, guild.description) &&
Objects.equals(link, this.link);
Objects.equals(link, guild.link) &&
Objects.equals(community, guild.community);

}

@Override
public int hashCode() {
return Objects.hash(id, name, description, link);
return Objects.hash(id, name, description, link, community);
}

@Override
Expand All @@ -124,6 +101,7 @@ public String toString() {
", name='" + name + '\'' +
", description='" + description + '\'' +
", link='" + link +
", community=" + community +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.objectcomputing.checkins.services.guild;

import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
Expand All @@ -9,8 +10,6 @@
import io.micronaut.security.rules.SecurityRule;
import io.netty.channel.EventLoopGroup;
import io.swagger.v3.oas.annotations.tags.Tag;

import io.micronaut.core.annotation.Nullable;
import jakarta.inject.Named;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
Expand All @@ -30,8 +29,8 @@
@Tag(name = "guilds")
public class GuildController {

private GuildServices guildService;
private EventLoopGroup eventLoopGroup;
private final GuildServices guildService;
private final EventLoopGroup eventLoopGroup;
private final Scheduler scheduler;

public GuildController(GuildServices guildService,
Expand Down Expand Up @@ -78,14 +77,14 @@ public Mono<HttpResponse<GuildResponseDTO>> readGuild(@NotNull UUID id) {
* Find guild(s) given a combination of the following parameters
*
* @param name, name of the guild
* @param memberid, {@link UUID} of the member you wish to inquire in to which guilds they are a part of
* @param memberId, {@link UUID} of the member you wish to inquire in to which guilds they are a part of
* @return {@link List < GuildResponseDTO > list of guilds}, return all guilds when no parameters filled in else
* return all guilds that match all of the filled in params
* return all guilds that match the filled in params
*/

@Get("/{?name,memberid}")
public Mono<HttpResponse<Set<GuildResponseDTO>>> findGuilds(@Nullable String name, @Nullable UUID memberid) {
return Mono.fromCallable(() -> guildService.findByFields(name, memberid))
public Mono<HttpResponse<Set<GuildResponseDTO>>> findGuilds(@Nullable String name, @Nullable UUID memberId) {
return Mono.fromCallable(() -> guildService.findByFields(name, memberId))
.publishOn(Schedulers.fromExecutor(eventLoopGroup))
.map(guilds -> (HttpResponse<Set<GuildResponseDTO>>) HttpResponse.ok(guilds))
.subscribeOn(scheduler);
Expand All @@ -95,16 +94,15 @@ public Mono<HttpResponse<Set<GuildResponseDTO>>> findGuilds(@Nullable String nam
* Update guild.
*
* @param guild, {@link GuildUpdateDTO}
* @return {@link HttpResponse< GuildResponseDTO >}
* @return {@link HttpResponse<GuildResponseDTO>}
*/
@Put()
public Mono<HttpResponse<GuildResponseDTO>> update(@Body @Valid GuildUpdateDTO guild, HttpRequest<GuildUpdateDTO> request) {
return Mono.fromCallable(() -> guildService.update(guild))
.publishOn(Schedulers.fromExecutor(eventLoopGroup))
.map(updated -> (HttpResponse<GuildResponseDTO>) HttpResponse
.ok()
.headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getUri(), guild.getId()))))
.body(updated))
.ok(updated)
.headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getUri(), guild.getId())))))
.subscribeOn(scheduler);

}
Expand All @@ -113,13 +111,13 @@ public Mono<HttpResponse<GuildResponseDTO>> update(@Body @Valid GuildUpdateDTO g
* Delete Guild
*
* @param id, id of {@link GuildUpdateDTO} to delete
* @return
* @return http ok response
*/
@Delete("/{id}")
public Mono<HttpResponse> deleteGuild(@NotNull UUID id) {
public Mono<HttpResponse<Object>> deleteGuild(@NotNull UUID id) {
return Mono.fromCallable(() -> guildService.delete(id))
.publishOn(Schedulers.fromExecutor(eventLoopGroup))
.map(success -> (HttpResponse) HttpResponse.ok())
.map(success -> (HttpResponse<Object>) HttpResponse.ok())
.subscribeOn(scheduler);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.objectcomputing.checkins.services.guild;

import io.micronaut.core.annotation.Introspected;
import io.micronaut.core.annotation.Nullable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;

import io.micronaut.core.annotation.Nullable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

@Data
@NoArgsConstructor
@Introspected
public class GuildCreateDTO {
@Setter
@NotBlank
@Schema(required = true, description = "name of the guild")
private String name;
Expand All @@ -26,65 +31,20 @@ public class GuildCreateDTO {
@Nullable
@Schema(description="link to the homepage of the guild")
private String link;


public GuildCreateDTO(String name, @Nullable String description, @Nullable String link) {
this.name = name;
this.description = description;
this.link =link;
}

public GuildCreateDTO() {
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
com.objectcomputing.checkins.services.guild.GuildCreateDTO that = (com.objectcomputing.checkins.services.guild.GuildCreateDTO) o;
return Objects.equals(name, that.name) &&
Objects.equals(description, that.description) && Objects.equals(link, that.link);
}

@Override
public int hashCode() {
return Objects.hash(name, description);
}

public List<GuildMemberCreateDTO> getGuildMembers() {
return guildMembers;
}

public void setGuildMembers(List<GuildMemberCreateDTO> guildMembers) {
this.guildMembers = guildMembers;
}

public String getName() {
return name;
}
@NotNull
@Schema(description = "Is the guild a community")
private boolean community;

public void setName(String name) {
public GuildCreateDTO(String name, @Nullable String description, @Nullable String link, boolean community) {
this.name = name;
}

@Nullable
public String getDescription() {
return description;
}

public void setDescription(@Nullable String description) {
this.description = description;
this.link =link;
this.community = community;
}

@Nullable
public String getLink() {
return this.link;
}

public void setLink(String link) {
this.link = link;
}

@Data
@NoArgsConstructor
@Introspected
public static class GuildMemberCreateDTO {

Expand All @@ -100,21 +60,5 @@ public GuildMemberCreateDTO(UUID memberId, Boolean lead) {
this.memberId = memberId;
this.lead = lead;
}

public Boolean getLead() {
return lead;
}

public void setLead(Boolean lead) {
this.lead = lead;
}

public UUID getMemberId() {
return memberId;
}

public void setMemberId(UUID memberId) {
this.memberId = memberId;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.objectcomputing.checkins.services.guild;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.data.annotation.Query;
import io.micronaut.data.jdbc.annotation.JdbcRepository;
import io.micronaut.data.model.query.builder.sql.Dialect;
import io.micronaut.data.repository.CrudRepository;
import io.micronaut.core.annotation.NonNull;

import io.micronaut.core.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
Expand All @@ -26,7 +26,10 @@ public interface GuildRepository extends CrudRepository<Guild, UUID> {
@Override
<S extends Guild> S save(@Valid @NotNull @NonNull S entity);

@Query(value = "SELECT t_.id, PGP_SYM_DECRYPT(cast(t_.name as bytea),'${aes.key}') as name, PGP_SYM_DECRYPT(cast(description as bytea),'${aes.key}') as description, PGP_SYM_DECRYPT(cast(link as bytea),'${aes.key}') as link " +
@Query(value = "SELECT t_.id, PGP_SYM_DECRYPT(cast(t_.name as bytea),'${aes.key}') as name, " +
"PGP_SYM_DECRYPT(cast(description as bytea),'${aes.key}') as description, " +
"PGP_SYM_DECRYPT(cast(link as bytea),'${aes.key}') as link, " +
"t_.community as community " +
"FROM guild t_ " +
"LEFT JOIN guild_member tm_ " +
" ON t_.id = tm_.guildid " +
Expand Down
Loading