-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/Team.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,51 @@ | ||
package de.tum.in.www1.hephaestus.codereview.team; | ||
|
||
import jakarta.persistence.Table; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.springframework.lang.NonNull; | ||
|
||
import de.tum.in.www1.hephaestus.codereview.user.User; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.JoinTable; | ||
import jakarta.persistence.ManyToMany; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@Table(name = "team") | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@ToString(callSuper = true) | ||
public class Team { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column | ||
private String name; | ||
|
||
@NonNull | ||
private String color; | ||
|
||
@ManyToMany(fetch = FetchType.EAGER) | ||
@JoinTable(name = "TEAM_MEMBERS", joinColumns = @JoinColumn(name = "team_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id")) | ||
@ToString.Exclude | ||
private Set<User> members = new HashSet<>(); | ||
|
||
public void addMember(User user) { | ||
members.add(user); | ||
user.addTeam(this); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...cation-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/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,11 @@ | ||
package de.tum.in.www1.hephaestus.codereview.team; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TeamRepository extends JpaRepository<Team, Long> { | ||
|
||
Optional<Team> findByName(String name); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...plication-server/src/main/java/de/tum/in/www1/hephaestus/codereview/team/TeamService.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,23 @@ | ||
package de.tum.in.www1.hephaestus.codereview.team; | ||
|
||
import java.util.Optional; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class TeamService { | ||
private static final Logger logger = LoggerFactory.getLogger(TeamService.class); | ||
|
||
private final TeamRepository teamRepository; | ||
|
||
public TeamService(TeamRepository teamRepository) { | ||
this.teamRepository = teamRepository; | ||
} | ||
|
||
public Optional<Team> getTeam(String name) { | ||
logger.info("Getting team with name: " + name); | ||
return teamRepository.findByName(name); | ||
} | ||
} |
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