Skip to content
Draft

20.4 #186

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ src/main/resources/application-local.properties
/logs/
/sampleDB.mv.db
/sampleDB.trace.db
*.env
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM maven:3.9-amazoncorretto-19 AS MAVEN_BUILD

MAINTAINER Serhii Kushnerov

COPY pom.xml /build/
COPY src /build/src/

WORKDIR /build/
RUN mvn package

FROM openjdk:19-alpine
WORKDIR /app
COPY --from=MAVEN_BUILD /build/target/backend-0.1.0.jar /app/
EXPOSE 8080
CMD ["java", "-jar", "backend-0.1.0.jar"]
63 changes: 63 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: '3.1'
services:
backend:
container_name: "Starlight_Prod"
image: starlight_prod:latest
volumes:
- backend:/data/backend
ports:
- '8082:8082'
networks:
- postgres
secrets:
- backend_secrets
env_file:
- .env
depends_on:
- postgres

restart: unless-stopped

postgres:
container_name: "PSQL_PROD"
image: postgres
environment:
POSTGRES_DB: postgres
POSTGRES_USERNAME: postgres
POSTGRES_PASSWORD: 123456
PGGATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- '5432:5432'
networks:
- postgres
restart: unless-stopped

pgadmin:
container_name: pgadmin_prod
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: sekret7d@gmail.com
PGADMIN_DEFAULT_PASSWORD: serg12345
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- pgadmin:/var/lib/pgadmin
ports:
- "5050:80"
networks:
- postgres
restart: unless-stopped

networks:
postgres:
driver: bridge

volumes:
postgres:
backend:
pgadmin:

secrets:
backend_secrets:
file: .env
9 changes: 9 additions & 0 deletions src/main/java/starlight/backend/admin/AdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package starlight.backend.admin;

import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

@AllArgsConstructor
@RestController
public class AdminController {
}
10 changes: 10 additions & 0 deletions src/main/java/starlight/backend/admin/AdminRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package starlight.backend.admin;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import starlight.backend.admin.model.emtity.AdminEntity;

@Repository
public interface AdminRepository extends JpaRepository<AdminEntity, Long> {
boolean existsByEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package starlight.backend.admin.model.emtity;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.*;
import org.springframework.validation.annotation.Validated;
import starlight.backend.user.model.entity.UserEntity;

import static jakarta.persistence.GenerationType.IDENTITY;

@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Validated
@Table(name = "admin")
public class AdminEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long adminId;
@NotBlank
private String fullName;
@NotBlank
@Email
private String email;
@NotBlank
private String password;
@OneToOne(mappedBy = "admin")
private UserEntity user;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@NoArgsConstructor
@Entity
@Validated
@Table(name = "delayed_delete")
public class DelayedDeleteEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void deleteAccounts() {
.orElseThrow(() -> new SponsorNotFoundException(accountEntityID));
//Чистим связи с другими таблицами.
//Чистим роли
sponsor.getAuthorities().clear();
if (!sponsor.getKudos().isEmpty()) {
//Если есть кудосы, то очищяем владельцев каждого из них
for (var kudos : sponsor.getKudos()) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/starlight/backend/kudos/model/DisableKudos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package starlight.backend.kudos.model;

import lombok.Builder;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Builder
@ConfigurationProperties(prefix = "disable-kudos")
public record DisableKudos(
int count
) {
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "kudos")
public class KudosEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import starlight.backend.kudos.service.KudosServiceInterface;
import starlight.backend.proof.ProofRepository;
import starlight.backend.proof.model.entity.ProofEntity;
import starlight.backend.security.model.enums.Role;
import starlight.backend.user.model.enums.Role;
import starlight.backend.security.service.SecurityServiceInterface;
import starlight.backend.sponsor.SponsorRepository;
import starlight.backend.sponsor.model.entity.SponsorEntity;
import starlight.backend.user.model.entity.UserEntity;
import starlight.backend.user.repository.UserRepository;
import starlight.backend.talent.model.entity.TalentEntity;
import starlight.backend.talent.repository.TalentRepository;

import java.time.Instant;
import java.util.stream.Collectors;
Expand All @@ -37,7 +37,7 @@
public class KudosServiceImpl implements KudosServiceInterface {
private KudosRepository kudosRepository;
private ProofRepository proofRepository;
private UserRepository userRepository;
private TalentRepository talentRepository;
private SponsorRepository sponsorRepository;
private SecurityServiceInterface securityService;

Expand Down Expand Up @@ -111,7 +111,7 @@ public KudosEntity addKudosOnProof(long proofId, int kudosRequest, Authenticatio
if (kudosRequest > owner.getUnusedKudos()) {
throw new NotEnoughKudosException();
}
var follower = userRepository.findById(proof.getUser().getUserId())
var follower = talentRepository.findById(proof.getTalent().getTalentId())
.orElseThrow(() -> new UserNotFoundException(auth.getName()));
updateSponsorUnusedKudos(owner, kudosRequest);
return updateSponsorKudosField(proof, follower, owner, kudosRequest, proofId);
Expand All @@ -125,14 +125,14 @@ private void updateSponsorUnusedKudos(SponsorEntity owner, int kudosRequest) {
});
}

private KudosEntity updateSponsorKudosField(ProofEntity proof, UserEntity follower, SponsorEntity owner,
private KudosEntity updateSponsorKudosField(ProofEntity proof, TalentEntity follower, SponsorEntity owner,
int kudosRequest, long proofId) {
if (proof.getKudos().stream()
.filter(kudos1 -> kudos1.getOwner().getSponsorId().equals(owner.getSponsorId()))
.collect(Collectors.toSet()).isEmpty()) {
if (kudosRequest < 0) throw new YouCanNotReturnMoreKudosThanGaveException();
var kudosBuild = KudosEntity.builder()
.followerId(follower.getUserId())
.followerId(follower.getTalentId())
.createData(Instant.now())
.proof(proof)
.owner(owner)
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/starlight/backend/proof/ProofRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@

@Repository
public interface ProofRepository extends JpaRepository<ProofEntity, Long> {
boolean existsByUser_UserIdAndSkills_SkillId(Long userId, Long skillId);

List<ProofEntity> findByUser_UserIdAndSkills_SkillId(Long userId, Long skillId);
boolean existsByTalent_TalentIdAndSkills_SkillId(Long talentId, Long skillId);

List<ProofEntity> findByUser_UserIdAndSkills_SkillIdAndStatus(Long userId, Long skillId, Status status);
List<ProofEntity> findByTalent_TalentIdAndSkills_SkillId(Long talentId, Long skillId);

Page<ProofEntity> findByUser_UserIdAndStatus(Long userId, Status status, Pageable pageable);
List<ProofEntity> findByTalent_TalentIdAndSkills_SkillIdAndStatus(Long talentId, Long skillId, Status status);

Page<ProofEntity> findByTalent_TalentIdAndStatus(Long talentId, Status status, Pageable pageable);

Page<ProofEntity> findByStatus(Status status, Pageable pageable);

boolean existsByUser_UserIdAndProofId(Long userId, Long proofId);
boolean existsByTalent_TalentIdAndProofId(Long talentId, Long proofId);

Page<ProofEntity> findByUser_UserId(long talentId, PageRequest of);
Page<ProofEntity> findByTalent_TalentId(long talentId, PageRequest of);

List<ProofEntity> findByUser_UserId(long talentId);
List<ProofEntity> findByTalent_TalentId(Long talentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ProofPagePagination pagination(@RequestParam(defaultValue = "0") @Min(0)
@ApiResponse(responseCode = "401", description = "Unauthorized")
})

@PreAuthorize("hasRole('TALENT')")
@PreAuthorize("hasRole('TALENT') or hasRole('ADMIN')")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/talents/{talent-id}/proofs")
public ResponseEntity<?> addProofFullInfo(@PathVariable("talent-id") long talentId,
Expand All @@ -96,7 +96,7 @@ public ResponseEntity<?> addProofFullInfo(@PathVariable("talent-id") long talent
@ApiResponse(responseCode = "403", description = "Forbidden"),
@ApiResponse(responseCode = "409", description = "Conflict")
})
@PreAuthorize("hasRole('TALENT')")
@PreAuthorize("hasRole('TALENT') or hasRole('ADMIN')")
@DeleteMapping("/talents/{talent-id}/proofs/{proof-id}")
public void deleteTalent(@PathVariable("talent-id") long talentId,
@PathVariable("proof-id") long proofId,
Expand Down Expand Up @@ -129,7 +129,7 @@ public void deleteTalent(@PathVariable("talent-id") long talentId,
@ApiResponse(responseCode = "404", description = "Not found")
})
@PatchMapping("/talents/{talent-id}/proofs/{proof-id}")
@PreAuthorize("hasRole('TALENT')")
@PreAuthorize("hasRole('TALENT') or hasRole('ADMIN')")
public ProofFullInfo updateProofFullInfo(@PathVariable("talent-id") long talentId,
@PathVariable("proof-id") long proofId,
@RequestBody ProofUpdateRequest proofUpdateRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public ProofFullInfoWithSkills getFullProof(@PathVariable("proof-id") long proof
)
)
})
@PreAuthorize("hasRole('TALENT')")
@PreAuthorize("hasRole('TALENT') or hasRole('ADMIN')")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/talents/{talent-id}/proofs")
public ResponseEntity<?> addProofFullInfo(@PathVariable("talent-id") long talentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import starlight.backend.kudos.model.entity.KudosEntity;
import starlight.backend.proof.model.enums.Status;
import starlight.backend.skill.model.entity.SkillEntity;
import starlight.backend.user.model.entity.UserEntity;
import starlight.backend.talent.model.entity.TalentEntity;

import java.time.Instant;
import java.util.List;
Expand All @@ -26,6 +26,7 @@
@NoArgsConstructor
@Entity
@Validated
@Table(name = "proof")
public class ProofEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
Expand All @@ -47,8 +48,8 @@ public class ProofEntity {
private Status status;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private UserEntity user;
@JoinColumn(name = "talent_id", nullable = false)
private TalentEntity talent;

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
@JoinTable(
Expand Down
Loading