Skip to content
Merged

S5 #150

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
b9991ed
* Edit db structure
LordRenDS Apr 21, 2023
7226375
* finished login and registration for sponsor
LordRenDS Apr 22, 2023
8cab03e
S3.2US2&4 (#103)
Maslyna Apr 23, 2023
f408263
S3.2 us3 (#105)
Denis973 Apr 25, 2023
a1cd2d4
Updated liquibase:
Maslyna Apr 25, 2023
1ddf4d1
BUGFIX: `GET(/api/v3/proofs/1/kudos)`` has problems after deleting a …
Maslyna Apr 25, 2023
1b4588d
Little update
Maslyna Apr 25, 2023
d4da2b9
Removed exception handler for Exception.class
Maslyna Apr 26, 2023
1bea5c8
Code refactor:
Maslyna Apr 26, 2023
631829b
bug fix
Denis973 Apr 26, 2023
8097335
aws update
Maslyna Apr 28, 2023
8410148
Created PhotoService
Maslyna Apr 29, 2023
1e9560e
minore update
Maslyna Apr 29, 2023
44b3666
refactored and optimized code
LordRenDS Apr 29, 2023
8605ed4
fix .findByLogin(authentication.getName()) - getTalentProofs
Denis973 Apr 29, 2023
0382ddc
fix !userInfo.getTalent().getId().equals(talentId)
Denis973 Apr 29, 2023
ae08a0c
Doc update
Maslyna May 1, 2023
a607b07
Merge remote-tracking branch 'origin/S3.2-refactor' into S3.2-refactor
Maslyna May 1, 2023
1a1f027
New test endpoint for images
Maslyna May 2, 2023
c840232
DB EDIT: SIZE UP
Maslyna May 3, 2023
98aa8a2
S3.2 refactor (#107)
Maslyna May 3, 2023
fdc5c11
AWS update: PresignedURL
Maslyna May 4, 2023
63b7c04
AWS update: Scheduler for presigned url
Maslyna May 4, 2023
372ba13
Merge branch 'S3.2-refactor' into S3.2
Maslyna May 4, 2023
64cdb36
* Create table:
LordRenDS May 4, 2023
0933751
* edit data.sql
LordRenDS May 4, 2023
b537a5e
* add entity for Skills
LordRenDS May 5, 2023
30156ca
S4.1T1-3 (#118)
LordRenDS May 6, 2023
d24784e
S4.1 tasks 4 5 (#119)
Denis973 May 7, 2023
a6268c6
S4.1S2T1 (#121)
Maslyna May 9, 2023
6593e5a
Merge branch 'dev' into S4.1
Maslyna May 9, 2023
28309df
S4.2US1T1 (#129)
LordRenDS May 11, 2023
3aeb5b1
S4.2US1T2-3 (#131)
Denis973 May 12, 2023
554a6bb
S4.2-FULL (#135)
Maslyna May 14, 2023
22accbc
Code refactor: JWT token update
Maslyna May 16, 2023
d2c1cef
feat: Add tables for talent and sponsorship data
LordRenDS May 17, 2023
58155cb
Add ProofSkill entity and refactor TalentProof entity to use it.
LordRenDS May 17, 2023
348b6ea
Refactor Kudos entity to use ProofSkill instead of TalentProof in the…
LordRenDS May 18, 2023
39a4dbb
fix bug
Denis973 May 19, 2023
6b13090
add data-V5.sql
Denis973 May 19, 2023
726c2e1
bug fix
Denis973 May 19, 2023
2c8a7a8
refactor TalentService.java addSkillOnTalent
Denis973 May 19, 2023
725e39a
refactor TalentService.java addSkillOnTalent
Denis973 May 19, 2023
1f5d67a
refactor TalentProofController: deleteProofById
Denis973 May 19, 2023
c9ca731
Code refactor:
Maslyna May 19, 2023
2749931
Code refactor:
Maslyna May 19, 2023
da61771
refactor
Denis973 May 19, 2023
c37ad87
Merge remote-tracking branch 'origin/S5-refactor-Maslyna' into S5_ref…
Maslyna May 19, 2023
dc85c7a
Refactor database schema for sprint 5
LordRenDS May 19, 2023
ca771aa
Code refactor: old method from KudosController now works
Maslyna May 19, 2023
eba1b78
Refactor SQL queries to use new table names and columns
LordRenDS May 19, 2023
6b03375
Refactor database column constraints and entity attributes
LordRenDS May 19, 2023
faab83d
Refactor code by changing table names and some class names to follow …
LordRenDS May 19, 2023
6237c6b
Restructure table names for talents' skill sets, attached files, cont…
LordRenDS May 19, 2023
8e1bed7
Refactor entity names and table names for consistency
LordRenDS May 19, 2023
a08be86
refactor: Rename Skills entity to Skill and update references in serv…
LordRenDS May 19, 2023
d0c7622
Refactor TalentService, Authority, and UserInfo entities
LordRenDS May 19, 2023
de29039
Merge remote-tracking branch 'origin/S5_refactor' into S5
LordRenDS May 20, 2023
1d43c33
Update project version to 0.5.0-SNAPSHOT in pom.xml file
LordRenDS May 20, 2023
329f086
Refactor data retrieval and management in KudosService
LordRenDS May 20, 2023
1ae5e6b
S5 us3 (#146)
Denis973 May 21, 2023
bd843e8
S5US1T3-4 (#147)
LordRenDS May 23, 2023
53113b6
S5-email (#149)
Maslyna May 24, 2023
d67e560
Merge remote-tracking branch 'origin/dev' into S5
Maslyna May 24, 2023
5f645fd
MERGE UPDATE
Maslyna May 24, 2023
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
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
</parent>
<groupId>com.provedcode</groupId>
<artifactId>demo</artifactId>
<version>0.1.1-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
<name>ProvedCode</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui -->
<dependency>
<groupId>org.springdoc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public class AWSS3BucketController {

@PostSetNewUserImageApiDoc
@PreAuthorize("hasRole('TALENT')")
@PostMapping("/image/upload")
@PostMapping("/talents/{talent-id}/image/upload")
public void setNewUserImage(@RequestParam("file") MultipartFile file,
Authentication authentication) {
fileService.setNewUserImage(file, authentication);
@PathVariable("talent-id") Long talentId,
Authentication authentication) {
fileService.setNewUserImage(file, talentId, authentication);
}

@GetAllAWSBucketFilesDevApiDoc
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/provedcode/aws/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface FileService {

List<String> listAllFiles();

void setNewUserImage(MultipartFile file, Authentication authentication);
void setNewUserImage(MultipartFile file, Long talentId, Authentication authentication);

URL generetePresingedUrlFor7Days(String fileFullPath);
}
8 changes: 7 additions & 1 deletion src/main/java/com/provedcode/aws/service/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.amazonaws.services.s3.model.*;
import com.amazonaws.util.IOUtils;
import com.provedcode.config.AWSProperties;
import com.provedcode.talent.model.entity.Talent;
import com.provedcode.talent.repo.TalentRepository;
import com.provedcode.user.model.entity.UserInfo;
import com.provedcode.user.repo.UserInfoRepository;
Expand Down Expand Up @@ -75,7 +76,7 @@ public List<String> listAllFiles() {
}

@Override
public void setNewUserImage(MultipartFile file, Authentication authentication) {
public void setNewUserImage(MultipartFile file, Long talentId, Authentication authentication) {
if (file.isEmpty()) {
throw new ResponseStatusException(BAD_REQUEST, "file must be not empty, actual file-size: %s".formatted(file.getSize()));
}
Expand All @@ -84,6 +85,11 @@ public void setNewUserImage(MultipartFile file, Authentication authentication) {
}
UserInfo user = userInfoRepository.findByLogin(authentication.getName())
.orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "user with login = {%s} not found".formatted(authentication.getName())));
Talent talent = talentRepository.findById(talentId)
.orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "talent with id = {%s} not found".formatted(talentId)));
if (!user.getTalent().equals(talent)) {
throw new ResponseStatusException(FORBIDDEN, "You cannot change another talent");
}

try {
String fileType = getFileType(file);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/provedcode/config/EmailConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.provedcode.config;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
@AllArgsConstructor
public class EmailConfig {
private Environment env;

public String getDefaultEmail() {
return env.getProperty("EMAIL_USER");
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/provedcode/config/EmailDefaultProps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.provedcode.config;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

@Validated
@ConfigurationProperties(prefix = "default-email")
@Slf4j
public record EmailDefaultProps(
String userDeleted,
String userDeletedSubject
) {
@PostConstruct
void logging() {
log.info("email-default-props = {}", this);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/provedcode/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
Expand Down Expand Up @@ -51,14 +52,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers("/actuator/health").permitAll() // for DevOps
.requestMatchers(antMatcher("/h2/**")).permitAll()
.requestMatchers(antMatcher("/api/*/talents/**")).permitAll()
.requestMatchers(antMatcher("/api/*/proofs/**")).permitAll()
.requestMatchers(antMatcher("/api/*/sponsors/**")).permitAll()
.requestMatchers(antMatcher("/api/*/login")).permitAll()
.requestMatchers(antMatcher("/api/*/skills")).permitAll()
.requestMatchers(antMatcher("/api/*/proofs/**")).permitAll()
.requestMatchers(antMatcher("/error")).permitAll()
.requestMatchers(antMatcher("/v3/api-docs/**")).permitAll() // for openAPI
.requestMatchers(antMatcher("/swagger-ui/**")).permitAll() // for openAPI
.requestMatchers(antMatcher("/swagger-ui.html")).permitAll() // for openAPI
.requestMatchers(antMatcher(HttpMethod.GET, "/api/v5/activate")).permitAll()// for email account recovery
.anyRequest().authenticated()
);

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/provedcode/config/ServerInfoConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.provedcode.config;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@AllArgsConstructor
@Configuration
public class ServerInfoConfig {
private Environment env;

public String getServerPort() {
return env.getProperty("server.port");
}
public String getIpAddress() {
InetAddress ip = null;
try {
return ip.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
public String getFullServerAddress() {
return getIpAddress() + ":" + getServerPort();
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/provedcode/handlers/GlobalControllerAdvice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.provedcode.handlers;

import com.provedcode.user.model.entity.UserInfo;
import com.provedcode.user.repo.UserInfoRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.server.ResponseStatusException;

import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.NOT_FOUND;

@ControllerAdvice
@AllArgsConstructor
@Slf4j
public class GlobalControllerAdvice {
UserInfoRepository userInfoRepository;

@ModelAttribute
public void handleAuthentication(Authentication authentication) {
if (authentication != null) {
String login = authentication.getName();
UserInfo user = userInfoRepository.findByLogin(login)
.orElseThrow(() -> new ResponseStatusException(NOT_FOUND,
"User with login {%s} not found".formatted(login)));
if (Boolean.TRUE.equals(user.getIsLocked())) {
throw new ResponseStatusException(FORBIDDEN, "your account is blocked");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.provedcode.handlers;

import com.provedcode.handlers.dto.ErrorDTO;
import jakarta.validation.ConstraintViolationException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -65,7 +66,7 @@ private ResponseEntity<?> responseStatusExceptionHandler(ResponseStatusException
@ResponseStatus(HttpStatus.BAD_REQUEST)
private ResponseEntity<?> responseStatusExceptionHandler(ConstraintViolationException exception) {
ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, exception.getMessage(), exception.toString());
return new ResponseEntity<>(apiError, new HttpHeaders(), apiError.getStatus());
return new ResponseEntity<>(new ErrorDTO(apiError.getMessage()), new HttpHeaders(), apiError.getStatus());
}

// @ExceptionHandler({ Exception.class })
Expand Down
35 changes: 26 additions & 9 deletions src/main/java/com/provedcode/kudos/controller/KudosController.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package com.provedcode.kudos.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.provedcode.kudos.model.request.SetAmountKudos;
import com.provedcode.kudos.model.response.KudosAmount;
import com.provedcode.kudos.model.response.KudosAmountWithSponsor;
import com.provedcode.kudos.service.KudosService;
import com.provedcode.util.annotations.doc.controller.kudos.GetAmountOfKudosApiDoc;
import com.provedcode.util.annotations.doc.controller.kudos.GetKudosForSponsorApiDoc;
import com.provedcode.util.annotations.doc.controller.kudos.PostAddKudosToProofApiDoc;

import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@AllArgsConstructor
@Validated
@RequestMapping("/api/v3/")
@RequestMapping("/api/v5/")
public class KudosController {
KudosService kudosService;

Expand All @@ -41,8 +46,20 @@ KudosAmountWithSponsor getProofKudos(@PathVariable("proof-id") long proofId, Aut
@PreAuthorize("hasRole('SPONSOR')")
@PostMapping("/proofs/{proof-id}/kudos")
void addKudosToProof(@PathVariable("proof-id") long proofId,
@RequestBody @Valid Optional<SetAmountKudos> amount,
Authentication authentication) {
@RequestBody @Valid SetAmountKudos amount,
Authentication authentication) {
kudosService.addKudosToProof(proofId, amount, authentication);
}

@PreAuthorize("hasRole('SPONSOR')")
@PostMapping("/proofs/{proof-id}/skills/{skill-id}/kudos")
void addKudosToSkill(@PathVariable("proof-id") long proofId, @PathVariable("skill-id") long skillId,
Authentication authentication, @RequestBody @Valid SetAmountKudos amount) {
kudosService.addKudosToSkill(proofId, skillId, amount, authentication);
}

@GetMapping("/proofs/{proof-id}/skills/{skill-id}/kudos")
KudosAmount getKudosForSkill(@PathVariable("proof-id") long proofId, @PathVariable("skill-id") long skillId) {
return kudosService.getSkillKudos(proofId, skillId);
}
}
28 changes: 21 additions & 7 deletions src/main/java/com/provedcode/kudos/model/entity/Kudos.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package com.provedcode.kudos.model.entity;

import com.provedcode.sponsor.model.entity.Sponsor;
import com.provedcode.talent.model.entity.TalentProof;
import jakarta.persistence.*;
import lombok.*;
import com.provedcode.talent.model.entity.ProofSkill;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Positive;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
Expand All @@ -15,14 +28,15 @@
public class Kudos {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
@Column(name = "id", nullable = false, updatable = false, insertable = false)
private Long id;
@Column(name = "amount")
@Positive
private Long amount;
@ManyToOne
@JoinColumn(name = "sponsor_id")
private Sponsor sponsor;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "proof_id")
private TalentProof proof;
@ManyToOne
@JoinColumn(name = "proof_skill_id")
private ProofSkill skill;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Builder
public record KudosAmountWithSponsor(
Long allKudosOnProof,
Map<Long, SponsorDTO> kudosFromSponsor
Map<String, Map<Long, SponsorDTO>> kudosFromSponsor
) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.provedcode.kudos.repository;

import com.provedcode.kudos.model.entity.Kudos;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

public interface KudosRepository extends JpaRepository<Kudos, Long> {
long countByProofId(Long id);
import com.provedcode.kudos.model.entity.Kudos;
import com.provedcode.talent.model.entity.ProofSkill;


boolean existsBySponsorIdAndProofId(Long sponsorId, Long proofId);
public interface KudosRepository extends JpaRepository<Kudos, Long> {
List<Kudos> findBySkill(ProofSkill skill);
}
Loading