Merge branch '68-ping-conf' into 'dev'
Resolve "Ping конференции в списке конференций" Closes #68 See merge request romanov73/ng-tracker!69environments/staging/deployments/43
commit
88ec35faa0
@ -0,0 +1,73 @@
|
||||
package ru.ulstu.ping.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.core.model.BaseEntity;
|
||||
import ru.ulstu.user.model.User;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "ping")
|
||||
public class Ping extends BaseEntity {
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date date;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "users_id")
|
||||
private User user;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "conference_id")
|
||||
private Conference conference;
|
||||
|
||||
public Ping() {
|
||||
}
|
||||
|
||||
public Ping(Date date, User user) {
|
||||
this.date = date;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Ping(@JsonProperty("id") Integer id,
|
||||
@JsonProperty("date") Date date,
|
||||
@JsonProperty("user") User user,
|
||||
@JsonProperty("conference") Conference conference) {
|
||||
setId(id);
|
||||
this.date = date;
|
||||
this.user = user;
|
||||
this.conference = conference;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Conference getConference() {
|
||||
return conference;
|
||||
}
|
||||
|
||||
public void setConference(Conference conference) {
|
||||
this.conference = conference;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package ru.ulstu.ping.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.ping.model.Ping;
|
||||
|
||||
public interface PingRepository extends JpaRepository<Ping, Integer> {
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package ru.ulstu.ping.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.ping.model.Ping;
|
||||
import ru.ulstu.ping.repository.PingRepository;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class PingService {
|
||||
private final PingRepository pingRepository;
|
||||
private final UserService userService;
|
||||
|
||||
public PingService(PingRepository pingRepository,
|
||||
UserService userService) {
|
||||
this.pingRepository = pingRepository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addPing(Conference conference) throws IOException {
|
||||
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
||||
newPing.setConference(conference);
|
||||
pingRepository.save(newPing);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
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.1.xsd">
|
||||
<changeSet author="vova" id="20190424_000000-1">
|
||||
<createTable tableName="ping">
|
||||
<column name="id" type="integer">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="date" type="timestamp">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="users_id" type="integer">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="conference_id" type="integer"/>
|
||||
<column name="version" type="integer"/>
|
||||
</createTable>
|
||||
<addPrimaryKey columnNames="id" constraintName="pk_ping" tableName="ping"/>
|
||||
<addForeignKeyConstraint baseTableName="ping" baseColumnNames="users_id"
|
||||
constraintName="fk_ping_users_id" referencedTableName="users"
|
||||
referencedColumnNames="id"/>
|
||||
<addForeignKeyConstraint baseTableName="ping" baseColumnNames="conference_id"
|
||||
constraintName="fk_ping_conference_id" referencedTableName="conference"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
Loading…
Reference in New Issue