-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/DEAR-115' into DEAR-120-survey-d…
…atamodel-1
- Loading branch information
Showing
21 changed files
with
460 additions
and
15 deletions.
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,84 @@ | ||
-- Creat tables for PG-Adapter Auth.js | ||
------------------------------------------------------------------------------------------------------------------------ | ||
CREATE TABLE verification_token | ||
( | ||
identifier TEXT NOT NULL, | ||
expires TIMESTAMPTZ NOT NULL, | ||
token TEXT NOT NULL, | ||
|
||
PRIMARY KEY (identifier, token) | ||
); | ||
|
||
CREATE TABLE accounts | ||
( | ||
id SERIAL, | ||
"userId" INTEGER NOT NULL, | ||
type VARCHAR(255) NOT NULL, | ||
provider VARCHAR(255) NOT NULL, | ||
"providerAccountId" VARCHAR(255) NOT NULL, | ||
refresh_token TEXT, | ||
access_token TEXT, | ||
expires_at BIGINT, | ||
id_token TEXT, | ||
scope TEXT, | ||
session_state TEXT, | ||
token_type TEXT, | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE users | ||
( | ||
id SERIAL, | ||
name VARCHAR(255), | ||
email VARCHAR(255), | ||
"emailVerified" TIMESTAMPTZ, | ||
image TEXT, | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
ALTER TABLE users | ||
ADD COLUMN username VARCHAR(32); | ||
|
||
-- Create tables for DEAR-115-TEAM | ||
------------------------------------------------------------------------------------------------------------------------ | ||
CREATE TABLE team | ||
( | ||
id SERIAL, | ||
name VARCHAR(32), | ||
current_sprint_id INTEGER, | ||
config_id INTEGER, | ||
code VARCHAR(4) NOT NULL, | ||
created_by INTEGER NOT NULL, | ||
created_at TIMESTAMPTZ NOT NULL, | ||
active BOOLEAN DEFAULT TRUE NOT NULL, | ||
|
||
CONSTRAINT pk_team PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE team_member | ||
( | ||
id SERIAL, | ||
user_id INTEGER NOT NULL, | ||
team_id INTEGER NOT NULL, | ||
role VARCHAR(8) NOT NULL, | ||
active BOOLEAN DEFAULT TRUE NOT NULL, | ||
|
||
CONSTRAINT pk_team_member PRIMARY KEY (id), | ||
CONSTRAINT fk_team_member_user FOREIGN KEY (user_id) REFERENCES users (id), | ||
CONSTRAINT fk_team_member_team FOREIGN KEY (team_id) REFERENCES team (id), | ||
CONSTRAINT uq_team_member UNIQUE (user_id, team_id, role) | ||
); | ||
|
||
CREATE TABLE team_config | ||
( | ||
id SERIAL, | ||
work_kinds VARCHAR[], | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
-- Add constraints to the tables | ||
ALTER TABLE team | ||
ADD CONSTRAINT fk_team_team_config FOREIGN KEY (config_id) REFERENCES team_config (id); |
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,15 @@ | ||
INSERT INTO public.users (id, name, email, "emailVerified", image, username) | ||
VALUES (1, 'Hans Müller', 'hans@test.com', null, null, 'Hansi'); | ||
|
||
INSERT INTO public.team (id, name, current_sprint_id, config_id, code, created_by, created_at, active) | ||
VALUES (1, 'Team Alpha', null, null, 'ALF1', 1, '2024-07-13 15:19:11.164000 +00:00', true); | ||
INSERT INTO public.team (id, name, current_sprint_id, config_id, code, created_by, created_at, active) | ||
VALUES (2, 'Team Beta', null, null, 'BET2', 1, '2024-07-13 15:20:22.162000 +00:00', true); | ||
|
||
INSERT INTO public.team_member (id, user_id, team_id, role, active) | ||
VALUES (1, 1, 1, 'ADMIN', true); | ||
INSERT INTO public.team_member (id, user_id, team_id, role, active) | ||
VALUES (2, 1, 2, 'MEMBER', true); | ||
|
||
INSERT INTO public.team_config (id, work_kinds) | ||
VALUES (1, '{CODING,MEETING}'); |
36 changes: 36 additions & 0 deletions
36
src/main/java/ch/fhnw/deardevbackend/controller/TeamController.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,36 @@ | ||
package ch.fhnw.deardevbackend.controller; | ||
|
||
import ch.fhnw.deardevbackend.controller.exceptions.ErrorResponse; | ||
import ch.fhnw.deardevbackend.controller.exceptions.YappiException; | ||
import ch.fhnw.deardevbackend.dto.CreateTeamDTO; | ||
import ch.fhnw.deardevbackend.dto.JoinTeamDTO; | ||
import ch.fhnw.deardevbackend.entities.Team; | ||
import ch.fhnw.deardevbackend.services.TeamService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("v1/team") | ||
public class TeamController { | ||
|
||
@Autowired | ||
private TeamService teamService; | ||
|
||
@PostMapping("/create") | ||
public ResponseEntity<Team> createTeam(@RequestBody CreateTeamDTO request) { | ||
Team createdTeam = teamService.createTeam(request); | ||
return ResponseEntity.ok().body(createdTeam); | ||
} | ||
|
||
@PostMapping("/join") | ||
public ResponseEntity<Team> joinTeam(@RequestBody JoinTeamDTO request) { | ||
Team team = teamService.joinTeam(request); | ||
return ResponseEntity.ok().body(team); | ||
} | ||
|
||
@ExceptionHandler(YappiException.class) | ||
public ResponseEntity<ErrorResponse> handleYappiException(YappiException ex) { | ||
return ResponseEntity.badRequest().body(new ErrorResponse(ex.getMessage())); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/ch/fhnw/deardevbackend/controller/exceptions/ErrorResponse.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,10 @@ | ||
package ch.fhnw.deardevbackend.controller.exceptions; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class ErrorResponse { | ||
private String message; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/ch/fhnw/deardevbackend/controller/exceptions/YappiException.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,12 @@ | ||
package ch.fhnw.deardevbackend.controller.exceptions; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@Data | ||
@AllArgsConstructor | ||
public class YappiException extends RuntimeException { | ||
private final String message; | ||
} |
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,9 @@ | ||
package ch.fhnw.deardevbackend.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class CreateTeamDTO { | ||
private String name; | ||
private int userId; | ||
} |
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,9 @@ | ||
package ch.fhnw.deardevbackend.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class JoinTeamDTO { | ||
private String code; | ||
private int userId; | ||
} |
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
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,6 @@ | ||
package ch.fhnw.deardevbackend.entities; | ||
|
||
public enum Role { | ||
ADMIN, | ||
MEMBER | ||
} |
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 ch.fhnw.deardevbackend.entities; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.OffsetDateTime; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "team") | ||
@Builder | ||
@Data | ||
public class Team { | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Id | ||
private int id; | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
@Column(name = "current_sprint_id") | ||
private Integer currentSprintId; | ||
|
||
@Column(name = "config_id") | ||
private Integer configId; | ||
|
||
@Column(name = "code") | ||
private String code; | ||
|
||
@Column(name = "created_by") | ||
private Integer createdBy; | ||
|
||
@Column(name = "created_at") | ||
private OffsetDateTime createdAt; | ||
|
||
@Column(name = "active") | ||
private boolean active; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/ch/fhnw/deardevbackend/entities/TeamConfig.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,22 @@ | ||
package ch.fhnw.deardevbackend.entities; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "team_config") | ||
@Builder | ||
@Data | ||
public class TeamConfig { | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Id | ||
private int id; | ||
|
||
@Column(name = "work_kinds") | ||
private String workKinds; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/ch/fhnw/deardevbackend/entities/TeamMember.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,32 @@ | ||
package ch.fhnw.deardevbackend.entities; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "team_member") | ||
@Builder | ||
@Data | ||
public class TeamMember { | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Id | ||
private int id; | ||
|
||
@Column(name = "user_id") | ||
private int userId; | ||
|
||
@Column(name = "team_id") | ||
private int teamId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "role") | ||
private Role role; | ||
|
||
@Column(name = "active") | ||
private boolean active; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/ch/fhnw/deardevbackend/mapper/CreateTeamMapper.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,20 @@ | ||
package ch.fhnw.deardevbackend.mapper; | ||
|
||
import ch.fhnw.deardevbackend.dto.CreateTeamDTO; | ||
import ch.fhnw.deardevbackend.entities.Team; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
public interface CreateTeamMapper { | ||
CreateTeamMapper INSTANCE = Mappers.getMapper(CreateTeamMapper.class); | ||
|
||
@Mapping(target = "currentSprintId", ignore = true) | ||
@Mapping(target = "configId", ignore = true) | ||
@Mapping(target = "createdBy", source = "userId") | ||
@Mapping(target = "createdAt", expression = "java(java.time.OffsetDateTime.now())") | ||
@Mapping(target = "active", constant = "true") | ||
Team toTeam(CreateTeamDTO createTeamDTO); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/ch/fhnw/deardevbackend/mapper/UserMapper.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 ch.fhnw.deardevbackend.mapper; | ||
|
||
import ch.fhnw.deardevbackend.dto.UserDTO; | ||
import ch.fhnw.deardevbackend.entities.User; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
public interface UserMapper { | ||
UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); | ||
|
||
@Mapping(source = "user.id", target = "id") | ||
@Mapping(source = "user.name", target = "name") | ||
@Mapping(source = "user.email", target = "email") | ||
@Mapping(source = "user.username", target = "username") | ||
@Mapping(source = "provider", target = "loginProvider") | ||
@Mapping(source = "hasTeam", target = "hasTeam") | ||
UserDTO toDto(User user, String provider, Boolean hasTeam); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/ch/fhnw/deardevbackend/repositories/TeamMemberRepository.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,13 @@ | ||
package ch.fhnw.deardevbackend.repositories; | ||
|
||
import ch.fhnw.deardevbackend.entities.TeamMember; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface TeamMemberRepository extends JpaRepository<TeamMember, Integer> { | ||
@Query( | ||
value = "select count(*) > 0 from team_member where user_id =:userId", | ||
nativeQuery = true) | ||
Boolean userIsInTeam(@Param("userId") Integer userId); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/ch/fhnw/deardevbackend/repositories/TeamRepository.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,13 @@ | ||
package ch.fhnw.deardevbackend.repositories; | ||
|
||
import ch.fhnw.deardevbackend.entities.Team; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface TeamRepository extends JpaRepository<Team, Integer> { | ||
|
||
boolean existsByCode(String code); | ||
|
||
Optional<Team> findByCode(String code); | ||
} |
Oops, something went wrong.