Skip to content
Merged
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 src/main/java/com/provedcode/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.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
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/com/provedcode/kudos/controller/KudosController.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
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
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 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);
}
}
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;

import com.provedcode.kudos.model.entity.Kudos;
import com.provedcode.talent.model.entity.ProofSkill;


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