Commit a3035925 authored by henrik.prangel's avatar henrik.prangel
Browse files

JUT-85 Add vote saving into DB

* Create new field to store vote value
* Add functionality to save vote
parent f71948d0
......@@ -82,7 +82,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.antMatchers("/api/account/reset-password/finish").permitAll()
.antMatchers("/api/conversation").permitAll()
.antMatchers("/api/conversation/user/commit").permitAll()
.antMatchers("/api/messages/approve/*").permitAll()
.antMatchers("/api/messages/vote").permitAll()
.antMatchers("/api/chats/intervention/*").permitAll()
.antMatchers("/api/feedbacks").permitAll()
.antMatchers("/api/**").authenticated()
......
......@@ -45,6 +45,9 @@ public class Message implements Serializable {
@Column(name = "interpreted_intent")
private String interpretedIntent;
@Column(name = "vote")
private String vote;
@ManyToOne
@JsonIgnoreProperties(value = "messages", allowSetters = true)
private Chat chat;
......@@ -174,6 +177,14 @@ public class Message implements Serializable {
this.interpretedIntent = interpretedIntent;
}
public String getVote() {
return vote;
}
public void setVote(String vote) {
this.vote = vote;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
......
......@@ -3,11 +3,14 @@ package com.netgroup.riigibot.service;
import com.netgroup.riigibot.domain.Message;
import com.netgroup.riigibot.repository.MessageRepository;
import com.netgroup.riigibot.service.dto.MessageDTO;
import com.netgroup.riigibot.service.enums.VoteValues;
import com.netgroup.riigibot.service.mapper.MessageMapper;
import java.time.Instant;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.EnumUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
......@@ -94,4 +97,14 @@ public class MessageService {
List<Message> byChat_id = messageRepository.findByChat_IdOrderByCreated(chatId);
return byChat_id.stream().map(messageMapper::toDto).collect(Collectors.toList());
}
public MessageDTO updateVote(MessageDTO messageWithVote) {
MessageDTO messageDTO = findOne(messageWithVote.getId()).orElseThrow(NoSuchElementException::new);
if(EnumUtils.isValidEnum(VoteValues.class, messageWithVote.getVote())) {
messageDTO.setVote(messageWithVote.getVote());
return save(messageDTO);
} else {
throw new IllegalArgumentException("No such vote value:" + messageWithVote.getVote());
}
}
}
......@@ -53,6 +53,9 @@ public class MessageDTO implements Serializable {
@Size(max = 255)
private String userDomain;
@Size(max = 50)
private String vote;
public Long getId() {
return id;
}
......@@ -181,6 +184,14 @@ public class MessageDTO implements Serializable {
this.authorLoginName = authorLoginName;
}
public String getVote() {
return vote;
}
public void setVote(String vote) {
this.vote = vote;
}
@Override
public boolean equals(Object o) {
if (this == o) {
......
package com.netgroup.riigibot.service.enums;
public enum VoteValues {
disapprove,
neutral,
approve
}
......@@ -137,14 +137,15 @@ public class MessageResource {
.build();
}
@PostMapping("/messages/approve/{id}")
public ResponseEntity<Void> updateUserApproval(@PathVariable Long id, @RequestBody String doesApprove) {
log.debug("REST request to update Message: {} with approval : {}", id, doesApprove);
throw new NotImplementedException();
// return ResponseEntity
// .noContent()
// .headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
// .build();
@PutMapping("/messages/vote")
public ResponseEntity<MessageDTO> updateUserApproval(@RequestBody MessageDTO messageWithVote) {
log.debug("REST request to update Message: {} with approval : {}", messageWithVote.getId(), messageWithVote.getVote());
MessageDTO result = messageService.updateVote(messageWithVote);
return ResponseEntity
.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, messageWithVote.getId().toString()))
.body(result);
}
@PostMapping("/messages/usergroup/{usergroup}")
......
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<!--
Added new field to chat
-->
<changeSet id="20201019140000-1" author="henrik_prangel">
<addColumn tableName="message">
<column name="vote" type="varchar(50)">
<constraints nullable="true"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
......@@ -24,6 +24,7 @@
<include file="config/liquibase/changelog/20200928151500_added_commitment_fields.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20201014152000_created_new_user_roles.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20201015101000_added_labeled_row_to_chat.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20201019140000_added_vote_field_to_message_entity.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
<!-- jhipster-needle-liquibase-add-incremental-changelog - JHipster will add incremental liquibase changelogs here -->
</databaseChangeLog>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment