From 9fa9630e5d47c2cd69b50697df810a4fc0a1d613 Mon Sep 17 00:00:00 2001 From: Guams Date: Wed, 25 Dec 2024 20:33:48 +0100 Subject: [PATCH] maj du script avec des roles pour les users --- .../java/com/guams/review/controller/AuthorController.java | 3 ++- src/main/resources/script.sql | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/guams/review/controller/AuthorController.java b/src/main/java/com/guams/review/controller/AuthorController.java index 2c27513..57c0662 100644 --- a/src/main/java/com/guams/review/controller/AuthorController.java +++ b/src/main/java/com/guams/review/controller/AuthorController.java @@ -103,7 +103,8 @@ public class AuthorController { throw new AlreadyExistsException("Author already exists"); } author.setPassword(passwordEncoder.encode(author.getPassword())); - return new ResponseEntity<>(authorRepository.save(author.setRole("USER")).setPassword(""), HttpStatus.CREATED); + return new ResponseEntity<>(authorRepository.save(author.setRole("READER")).setPassword(""), HttpStatus.CREATED); + } @GetMapping(value = "/me", produces = "application/json") diff --git a/src/main/resources/script.sql b/src/main/resources/script.sql index 9ec81f0..d627c59 100644 --- a/src/main/resources/script.sql +++ b/src/main/resources/script.sql @@ -1,6 +1,9 @@ drop table if exists publication; drop table if exists post; drop table if exists author; +drop type if exists author_role; + +create type author_role as enum ('READER', 'WRITER', 'ADMIN'); create table author ( @@ -8,7 +11,7 @@ create table author name varchar(255) unique not null, password text not null, profile_picture bytea, - role varchar(50) default 'USER' not null + role author_role default 'READER' not null ); create table post